Skip to content

Commit f802c27

Browse files
committed
cherry-pick(#10661): chore: add validations into check_deps
1 parent be460a9 commit f802c27

File tree

5 files changed

+58
-13
lines changed

5 files changed

+58
-13
lines changed

package-lock.json

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/playwright-core/src/server/chromium/chromium.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { CallMetadata } from '../instrumentation';
3636
import http from 'http';
3737
import https from 'https';
3838
import { registry } from '../../utils/registry';
39-
import { ManualPromise } from 'playwright-core/lib/utils/async';
39+
import { ManualPromise } from '../../utils/async';
4040

4141
const ARTIFACTS_FOLDER = path.join(os.tmpdir(), 'playwright-artifacts-');
4242

packages/playwright-test/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
"@babel/preset-typescript": "^7.14.5",
4646
"colors": "^1.4.0",
4747
"commander": "^8.2.0",
48+
"debug": "^4.1.1",
4849
"expect": "=27.2.5",
4950
"jest-matcher-utils": "=27.2.5",
5051
"jpeg-js": "^0.4.2",
52+
"mime": "^2.4.6",
5153
"minimatch": "^3.0.3",
5254
"ms": "^2.1.2",
5355
"open": "^8.3.0",
@@ -58,6 +60,6 @@
5860
"rimraf": "^3.0.2",
5961
"source-map-support": "^0.4.18",
6062
"stack-utils": "^2.0.3",
61-
"debug": "^4.1.1"
63+
"yazl": "^2.5.1"
6264
}
6365
}

packages/playwright-test/src/matchers/toMatchText.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
import colors from 'colors/safe';
19-
import { ExpectedTextValue } from 'playwright-core/lib/protocol/channels';
19+
import type { ExpectedTextValue } from 'playwright-core/lib/protocol/channels';
2020
import { isRegExp, isString } from 'playwright-core/lib/utils/utils';
2121
import { currentTestInfo } from '../globals';
2222
import type { Expect } from '../types';

utils/check_deps.js

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,24 @@ const ts = require('typescript');
2121
const path = require('path');
2222

2323
async function checkDeps() {
24-
const root = path.normalize(path.join(__dirname, '..', 'packages', 'playwright-core'));
25-
const src = path.normalize(path.join(__dirname, '..', 'packages', 'playwright-core', 'src'));
24+
const packages = path.normalize(path.join(__dirname, '..', 'packages'));
25+
const corePackageJson = await innerCheckDeps(path.join(packages, 'playwright-core'), true);
26+
const testPackageJson = await innerCheckDeps(path.join(packages, 'playwright-test'), false);
27+
28+
let hasVersionMismatch = false;
29+
for (const [key, value] of Object.entries(corePackageJson.dependencies)) {
30+
const value2 = testPackageJson.dependencies[key];
31+
if (value2 && value2 !== value) {
32+
hasVersionMismatch = true;
33+
console.log(`Dependency version mismatch ${key}: ${value} != ${value2}`);
34+
}
35+
}
36+
process.exit(hasVersionMismatch ? 1 : 0);
37+
}
38+
39+
async function innerCheckDeps(root, checkDepsFile) {
40+
const deps = new Set();
41+
const src = path.join(root, 'src');
2642
const packageJSON = require(path.join(root, 'package.json'));
2743
const program = ts.createProgram({
2844
options: {
@@ -40,23 +56,46 @@ async function checkDeps() {
4056
if (!usedDeps.has(key) && DEPS[key].length)
4157
errors.push(`Stale DEPS entry "${key}"`);
4258
}
43-
for (const error of errors)
44-
console.log(error);
45-
if (errors.length) {
59+
if (checkDepsFile && errors.length) {
60+
for (const error of errors)
61+
console.log(error);
4662
console.log(`--------------------------------------------------------`);
4763
console.log(`Changing the project structure or adding new components?`);
4864
console.log(`Update DEPS in ./${path.relative(root, __filename)}`);
4965
console.log(`--------------------------------------------------------`);
66+
process.exit(1);
5067
}
51-
process.exit(errors.length ? 1 : 0);
68+
69+
for (const dep of deps) {
70+
const resolved = require.resolve(dep);
71+
if (dep === resolved || !resolved.includes('node_modules'))
72+
deps.delete(dep);
73+
}
74+
for (const dep of Object.keys(packageJSON.dependencies))
75+
deps.delete(dep);
76+
77+
if (deps.size) {
78+
console.log('Dependencies are not declared in package.json:');
79+
for (const dep of deps)
80+
console.log(` ${dep}`);
81+
process.exit(1);
82+
}
83+
84+
return packageJSON;
5285

5386
function visit(node, fileName) {
5487
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
5588
const importName = node.moduleSpecifier.text;
89+
if (!importName.startsWith('.') && !node.importClause.isTypeOnly && !fileName.includes(path.sep + 'web' + path.sep)) {
90+
if (importName.startsWith('@'))
91+
deps.add(importName.split('/').slice(0, 2).join('/'));
92+
else
93+
deps.add(importName.split('/')[0]);
94+
}
5695
const importPath = path.resolve(path.dirname(fileName), importName) + '.ts';
57-
if (!allowImport(fileName, importPath))
96+
if (checkDepsFile && !allowImport(fileName, importPath))
5897
errors.push(`Disallowed import from ${path.relative(root, fileName)} to ${path.relative(root, importPath)}`);
59-
if (!allowExternalImport(fileName, importPath, importName))
98+
if (checkDepsFile && !allowExternalImport(fileName, importPath, importName))
6099
errors.push(`Disallowed external dependency ${importName} from ${path.relative(root, fileName)}`);
61100
}
62101
ts.forEachChild(node, x => visit(x, fileName));

0 commit comments

Comments
 (0)