chore: ensure module deps in ct-core (#24056)

Fixes https://github.com/microsoft/playwright/issues/23823
This commit is contained in:
Pavel Feldman 2023-07-06 12:01:45 -07:00 committed by GitHub
parent 608e336dba
commit 0409bfca56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 50 additions and 63 deletions

2
package-lock.json generated
View File

@ -6234,6 +6234,7 @@
"license": "Apache-2.0",
"dependencies": {
"@playwright/test": "1.36.0-next",
"playwright-core": "1.36.0-next",
"vite": "^4.3.9"
},
"bin": {
@ -7260,6 +7261,7 @@
"version": "file:packages/playwright-ct-core",
"requires": {
"@playwright/test": "1.36.0-next",
"playwright-core": "1.36.0-next",
"vite": "^4.3.9"
}
},

View File

@ -1,3 +1,15 @@
[*]
@playwright/experimental-ct-react
@web/**
[chip.spec.tsx]
***
[headerView.spec.tsx]
***
[imageDiffView.spec.tsx]
***
[testCaseView.spec.tsx]
***

View File

@ -16,7 +16,7 @@
import fs from 'fs';
import path from 'path';
import { isUnderTest } from 'playwright-core/lib/utils';
import { isUnderTest } from '../../utils';
import type { Page } from '../page';
import { registryDirectory } from '../registry';
import type { CRPage } from './crPage';

View File

@ -15,8 +15,8 @@
*/
import type * as channels from '@protocol/channels';
import { eventsHelper } from 'playwright-core/lib/utils';
import type { RegisteredListener } from 'playwright-core/lib/utils/eventsHelper';
import { eventsHelper } from '../../utils';
import type { RegisteredListener } from '../../utils/eventsHelper';
import { DebugController } from '../debugController';
import type { DispatcherConnection, RootDispatcher } from './dispatcher';
import { Dispatcher } from './dispatcher';

View File

@ -1,3 +1,2 @@
[*]
../../../**
@trace-viewer/**
***

View File

@ -3,4 +3,5 @@
../../registry/
../../../generated/
../../../utils/
../../../utilsBundle.ts
../../chromium/crApp.ts

View File

@ -23,7 +23,7 @@ import { installAppIcon, syncLocalStorageWithSettings } from '../../chromium/crA
import { serverSideCallMetadata } from '../../instrumentation';
import { createPlaywright } from '../../playwright';
import { ProgressController } from '../../progress';
import { open, wsServer } from 'playwright-core/lib/utilsBundle';
import { open, wsServer } from '../../../utilsBundle';
import type { Page } from '../../page';
export type Transport = {

View File

@ -21,6 +21,7 @@
"./lib/vitePlugin": "./lib/vitePlugin.js"
},
"dependencies": {
"playwright-core": "1.36.0-next",
"vite": "^4.3.9",
"@playwright/test": "1.36.0-next"
},

View File

@ -19,9 +19,5 @@
"@vitejs/plugin-react": "^3.1.0",
"typescript": "^4.5.4",
"vite": "^4.2.1"
},
"@standaloneDevDependencies": {
"@playwright/experimental-ct-react": "^1.22.0",
"@playwright/test": "^1.22.2"
}
}

View File

@ -14,10 +14,6 @@
"react-scripts": "5.0.1",
"typescript": "^4.6.2"
},
"@standaloneDevDependencies": {
"@playwright/experimental-ct-react17": "^1.2.2",
"@playwright/test": "^1.22.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",

View File

@ -18,9 +18,5 @@
"typescript": "^4.7.4",
"vite": "^4.2.1",
"vite-plugin-solid": "^2.6.1"
},
"@standaloneDevDependencies": {
"@playwright/experimental-ct-solid": "^1.22.2",
"@playwright/test": "^1.22.2"
}
}

View File

@ -18,10 +18,6 @@
"typescript": "^4.5.4",
"vite": "^4.2.1"
},
"@standaloneDevDependencies": {
"@playwright/experimental-ct-svelte": "^1.22.2",
"@playwright/test": "^1.22.2"
},
"dependencies": {
"svelte": "^3.49.0",
"svelte-navigator": "^3.2.2"

View File

@ -18,10 +18,6 @@
"rollup-plugin-terser": "^7.0.0",
"sirv-cli": "^2.0.0"
},
"@standaloneDevDependencies": {
"@playwright/experimental-ct-svelte": "^1.22.2",
"@playwright/test": "^1.22.2"
},
"dependencies": {
"svelte": "^3.0.0",
"svelte-navigator": "^3.2.2"

View File

@ -24,10 +24,6 @@
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3"
},
"@standaloneDevDependencies": {
"@playwright/experimental-ct-vue": "^1.22.2",
"@playwright/test": "^1.22.2"
},
"eslintConfig": {
"root": true,
"env": {

View File

@ -16,9 +16,5 @@
"@vue/tsconfig": "^0.1.3",
"vite": "^4.2.1",
"vue-tsc": "^1.0.0"
},
"@standaloneDevDependencies": {
"@playwright/experimental-ct-vue": "^1.22.2",
"@playwright/test": "^1.22.2"
}
}

View File

@ -23,10 +23,6 @@
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3"
},
"@standaloneDevDependencies": {
"@playwright/experimental-ct-vue2": "^1.22.2",
"@playwright/test": "^1.22.2"
},
"eslintConfig": {
"root": true,
"env": {

View File

@ -21,12 +21,12 @@
const fs = require('fs');
const ts = require('typescript');
const path = require('path').posix;
const Module = require('module');
const builtins = new Set(Module.builtinModules);
const packagesDir = path.resolve(path.join(__dirname, '..', 'packages'));
const packages = new Map();
for (const package of fs.readdirSync(packagesDir))
packages.set(package, packagesDir + '/' + package + '/src/');
packages.set('web', packagesDir + '/web/src/');
packages.set('injected', packagesDir + '/playwright-core/src/server/injected/');
packages.set('isomorphic', packagesDir + '/playwright-core/src/utils/isomorphic/');
packages.set('testIsomorphic', packagesDir + '/playwright-test/src/isomorphic/');
@ -36,12 +36,13 @@ const peerDependencies = ['electron', 'react', 'react-dom', '@zip.js/zip.js'];
const depsCache = {};
async function checkDeps() {
await innerCheckDeps(path.join(packagesDir, 'protocol'));
await innerCheckDeps(path.join(packagesDir, 'trace'));
await innerCheckDeps(path.join(packagesDir, 'web'));
await innerCheckDeps(path.join(packagesDir, 'html-reporter'));
await innerCheckDeps(path.join(packagesDir, 'playwright-ct-core'));
await innerCheckDeps(path.join(packagesDir, 'protocol'));
await innerCheckDeps(path.join(packagesDir, 'recorder'));
await innerCheckDeps(path.join(packagesDir, 'trace-viewer'));
await innerCheckDeps(path.join(packagesDir, 'trace'));
await innerCheckDeps(path.join(packagesDir, 'web'));
const corePackageJson = await innerCheckDeps(path.join(packagesDir, 'playwright-core'));
const testPackageJson = await innerCheckDeps(path.join(packagesDir, 'playwright-test'));
@ -132,6 +133,9 @@ async function innerCheckDeps(root) {
importPath = packages.get(package) + tokens.slice(1).join('/');
}
const mergedDeps = calculateDeps(fileName);
if (mergedDeps.includes('***'))
return;
if (importPath) {
if (!fs.existsSync(importPath)) {
if (fs.existsSync(importPath + '.ts'))
@ -142,7 +146,7 @@ async function innerCheckDeps(root) {
importPath = importPath + '.d.ts';
}
if (!allowImport(fileName, importPath))
if (!allowImport(fileName, importPath, mergedDeps))
errors.push(`Disallowed import ${path.relative(root, importPath)} in ${path.relative(root, fileName)}`);
return;
}
@ -158,17 +162,13 @@ async function innerCheckDeps(root) {
ts.forEachChild(node, x => visit(x, fileName));
}
function allowImport(from, to) {
function calculateDeps(from) {
const fromDirectory = path.dirname(from);
const toDirectory = isDirectory(to) ? to : path.dirname(to);
if (to === toDirectory)
to = path.join(to, 'index.ts');
if (fromDirectory === toDirectory)
return true;
let depsDirectory = fromDirectory;
while (depsDirectory.startsWith(packagesDir) && !depsCache[depsDirectory] && !fs.existsSync(path.join(depsDirectory, 'DEPS.list')))
depsDirectory = path.dirname(depsDirectory);
if (!depsDirectory.startsWith(packagesDir))
return [];
let deps = depsCache[depsDirectory];
if (!deps) {
@ -192,7 +192,17 @@ async function innerCheckDeps(root) {
depsCache[depsDirectory] = deps;
}
const mergedDeps = [...(deps['*'] || []), ...(deps[path.relative(depsDirectory, from)] || [])]
return [...(deps['*'] || []), ...(deps[path.relative(depsDirectory, from)] || [])]
}
function allowImport(from, to, mergedDeps) {
const fromDirectory = path.dirname(from);
const toDirectory = isDirectory(to) ? to : path.dirname(to);
if (to === toDirectory)
to = path.join(to, 'index.ts');
if (fromDirectory === toDirectory)
return true;
for (const dep of mergedDeps) {
if (dep === '***')
return true;
@ -209,22 +219,16 @@ async function innerCheckDeps(root) {
function allowExternalImport(importName, packageJSON) {
// Only external imports are relevant. Files in src/web are bundled via webpack.
if (importName.startsWith('.') || importName.startsWith('@'))
if (importName.startsWith('.') || (importName.startsWith('@') && !importName.startsWith('@playwright/')))
return true;
if (peerDependencies.includes(importName))
return true;
try {
const resolvedImport = require.resolve(importName);
if (!resolvedImport.includes('node_modules'))
return true;
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND')
throw error;
}
if (!packageJSON)
return false;
const match = importName.match(/(@[\w-]+\/)?([^/]+)/);
const dependency = match[1] ? match[1] + '/' + match[2] : match[2];
const dependency = match[1] ? match[1] + match[2] : match[2];
if (builtins.has(dependency))
return true;
return !!(packageJSON.dependencies || {})[dependency];
}
}