chore: add validations into check_deps (#10661)
This commit is contained in:
parent
045cf1a56e
commit
b9731a904e
|
|
@ -36,7 +36,7 @@ import { CallMetadata } from '../instrumentation';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
import { registry } from '../../utils/registry';
|
import { registry } from '../../utils/registry';
|
||||||
import { ManualPromise } from 'playwright-core/lib/utils/async';
|
import { ManualPromise } from '../../utils/async';
|
||||||
|
|
||||||
const ARTIFACTS_FOLDER = path.join(os.tmpdir(), 'playwright-artifacts-');
|
const ARTIFACTS_FOLDER = path.join(os.tmpdir(), 'playwright-artifacts-');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,11 @@
|
||||||
"@babel/preset-typescript": "^7.14.5",
|
"@babel/preset-typescript": "^7.14.5",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"commander": "^8.2.0",
|
"commander": "^8.2.0",
|
||||||
|
"debug": "^4.1.1",
|
||||||
"expect": "=27.2.5",
|
"expect": "=27.2.5",
|
||||||
"jest-matcher-utils": "=27.2.5",
|
"jest-matcher-utils": "=27.2.5",
|
||||||
"jpeg-js": "^0.4.2",
|
"jpeg-js": "^0.4.2",
|
||||||
|
"mime": "^2.4.6",
|
||||||
"minimatch": "^3.0.3",
|
"minimatch": "^3.0.3",
|
||||||
"ms": "^2.1.2",
|
"ms": "^2.1.2",
|
||||||
"open": "^8.3.0",
|
"open": "^8.3.0",
|
||||||
|
|
@ -59,6 +61,6 @@
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"source-map-support": "^0.4.18",
|
"source-map-support": "^0.4.18",
|
||||||
"stack-utils": "^2.0.3",
|
"stack-utils": "^2.0.3",
|
||||||
"debug": "^4.1.1"
|
"yazl": "^2.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
|
|
||||||
import colors from 'colors/safe';
|
import colors from 'colors/safe';
|
||||||
import { ExpectedTextValue } from 'playwright-core/lib/protocol/channels';
|
import type { ExpectedTextValue } from 'playwright-core/lib/protocol/channels';
|
||||||
import { isRegExp, isString } from 'playwright-core/lib/utils/utils';
|
import { isRegExp, isString } from 'playwright-core/lib/utils/utils';
|
||||||
import { currentTestInfo } from '../globals';
|
import { currentTestInfo } from '../globals';
|
||||||
import type { Expect } from '../types';
|
import type { Expect } from '../types';
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,24 @@ const ts = require('typescript');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
async function checkDeps() {
|
async function checkDeps() {
|
||||||
const root = path.normalize(path.join(__dirname, '..', 'packages', 'playwright-core'));
|
const packages = path.normalize(path.join(__dirname, '..', 'packages'));
|
||||||
const src = path.normalize(path.join(__dirname, '..', 'packages', 'playwright-core', 'src'));
|
const corePackageJson = await innerCheckDeps(path.join(packages, 'playwright-core'), true);
|
||||||
|
const testPackageJson = await innerCheckDeps(path.join(packages, 'playwright-test'), false);
|
||||||
|
|
||||||
|
let hasVersionMismatch = false;
|
||||||
|
for (const [key, value] of Object.entries(corePackageJson.dependencies)) {
|
||||||
|
const value2 = testPackageJson.dependencies[key];
|
||||||
|
if (value2 && value2 !== value) {
|
||||||
|
hasVersionMismatch = true;
|
||||||
|
console.log(`Dependency version mismatch ${key}: ${value} != ${value2}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
process.exit(hasVersionMismatch ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function innerCheckDeps(root, checkDepsFile) {
|
||||||
|
const deps = new Set();
|
||||||
|
const src = path.join(root, 'src');
|
||||||
const packageJSON = require(path.join(root, 'package.json'));
|
const packageJSON = require(path.join(root, 'package.json'));
|
||||||
const program = ts.createProgram({
|
const program = ts.createProgram({
|
||||||
options: {
|
options: {
|
||||||
|
|
@ -40,23 +56,46 @@ async function checkDeps() {
|
||||||
if (!usedDeps.has(key) && DEPS[key].length)
|
if (!usedDeps.has(key) && DEPS[key].length)
|
||||||
errors.push(`Stale DEPS entry "${key}"`);
|
errors.push(`Stale DEPS entry "${key}"`);
|
||||||
}
|
}
|
||||||
for (const error of errors)
|
if (checkDepsFile && errors.length) {
|
||||||
console.log(error);
|
for (const error of errors)
|
||||||
if (errors.length) {
|
console.log(error);
|
||||||
console.log(`--------------------------------------------------------`);
|
console.log(`--------------------------------------------------------`);
|
||||||
console.log(`Changing the project structure or adding new components?`);
|
console.log(`Changing the project structure or adding new components?`);
|
||||||
console.log(`Update DEPS in ./${path.relative(root, __filename)}`);
|
console.log(`Update DEPS in ./${path.relative(root, __filename)}`);
|
||||||
console.log(`--------------------------------------------------------`);
|
console.log(`--------------------------------------------------------`);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
process.exit(errors.length ? 1 : 0);
|
|
||||||
|
for (const dep of deps) {
|
||||||
|
const resolved = require.resolve(dep);
|
||||||
|
if (dep === resolved || !resolved.includes('node_modules'))
|
||||||
|
deps.delete(dep);
|
||||||
|
}
|
||||||
|
for (const dep of Object.keys(packageJSON.dependencies))
|
||||||
|
deps.delete(dep);
|
||||||
|
|
||||||
|
if (deps.size) {
|
||||||
|
console.log('Dependencies are not declared in package.json:');
|
||||||
|
for (const dep of deps)
|
||||||
|
console.log(` ${dep}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return packageJSON;
|
||||||
|
|
||||||
function visit(node, fileName) {
|
function visit(node, fileName) {
|
||||||
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
||||||
const importName = node.moduleSpecifier.text;
|
const importName = node.moduleSpecifier.text;
|
||||||
|
if (!importName.startsWith('.') && !node.importClause.isTypeOnly && !fileName.includes(path.sep + 'web' + path.sep)) {
|
||||||
|
if (importName.startsWith('@'))
|
||||||
|
deps.add(importName.split('/').slice(0, 2).join('/'));
|
||||||
|
else
|
||||||
|
deps.add(importName.split('/')[0]);
|
||||||
|
}
|
||||||
const importPath = path.resolve(path.dirname(fileName), importName) + '.ts';
|
const importPath = path.resolve(path.dirname(fileName), importName) + '.ts';
|
||||||
if (!allowImport(fileName, importPath))
|
if (checkDepsFile && !allowImport(fileName, importPath))
|
||||||
errors.push(`Disallowed import from ${path.relative(root, fileName)} to ${path.relative(root, importPath)}`);
|
errors.push(`Disallowed import from ${path.relative(root, fileName)} to ${path.relative(root, importPath)}`);
|
||||||
if (!allowExternalImport(fileName, importPath, importName))
|
if (checkDepsFile && !allowExternalImport(fileName, importPath, importName))
|
||||||
errors.push(`Disallowed external dependency ${importName} from ${path.relative(root, fileName)}`);
|
errors.push(`Disallowed external dependency ${importName} from ${path.relative(root, fileName)}`);
|
||||||
}
|
}
|
||||||
ts.forEachChild(node, x => visit(x, fileName));
|
ts.forEachChild(node, x => visit(x, fileName));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue