mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-08 12:28:46 +03:00
chore: ensure module deps in ct-core (#24056)
Fixes https://github.com/microsoft/playwright/issues/23823
This commit is contained in:
parent
608e336dba
commit
0409bfca56
2
package-lock.json
generated
2
package-lock.json
generated
@ -6234,6 +6234,7 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@playwright/test": "1.36.0-next",
|
"@playwright/test": "1.36.0-next",
|
||||||
|
"playwright-core": "1.36.0-next",
|
||||||
"vite": "^4.3.9"
|
"vite": "^4.3.9"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
@ -7260,6 +7261,7 @@
|
|||||||
"version": "file:packages/playwright-ct-core",
|
"version": "file:packages/playwright-ct-core",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@playwright/test": "1.36.0-next",
|
"@playwright/test": "1.36.0-next",
|
||||||
|
"playwright-core": "1.36.0-next",
|
||||||
"vite": "^4.3.9"
|
"vite": "^4.3.9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
[*]
|
[*]
|
||||||
@playwright/experimental-ct-react
|
@playwright/experimental-ct-react
|
||||||
@web/**
|
@web/**
|
||||||
|
|
||||||
|
[chip.spec.tsx]
|
||||||
|
***
|
||||||
|
|
||||||
|
[headerView.spec.tsx]
|
||||||
|
***
|
||||||
|
|
||||||
|
[imageDiffView.spec.tsx]
|
||||||
|
***
|
||||||
|
|
||||||
|
[testCaseView.spec.tsx]
|
||||||
|
***
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { isUnderTest } from 'playwright-core/lib/utils';
|
import { isUnderTest } from '../../utils';
|
||||||
import type { Page } from '../page';
|
import type { Page } from '../page';
|
||||||
import { registryDirectory } from '../registry';
|
import { registryDirectory } from '../registry';
|
||||||
import type { CRPage } from './crPage';
|
import type { CRPage } from './crPage';
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type * as channels from '@protocol/channels';
|
import type * as channels from '@protocol/channels';
|
||||||
import { eventsHelper } from 'playwright-core/lib/utils';
|
import { eventsHelper } from '../../utils';
|
||||||
import type { RegisteredListener } from 'playwright-core/lib/utils/eventsHelper';
|
import type { RegisteredListener } from '../../utils/eventsHelper';
|
||||||
import { DebugController } from '../debugController';
|
import { DebugController } from '../debugController';
|
||||||
import type { DispatcherConnection, RootDispatcher } from './dispatcher';
|
import type { DispatcherConnection, RootDispatcher } from './dispatcher';
|
||||||
import { Dispatcher } from './dispatcher';
|
import { Dispatcher } from './dispatcher';
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
[*]
|
[*]
|
||||||
../../../**
|
***
|
||||||
@trace-viewer/**
|
|
||||||
|
@ -3,4 +3,5 @@
|
|||||||
../../registry/
|
../../registry/
|
||||||
../../../generated/
|
../../../generated/
|
||||||
../../../utils/
|
../../../utils/
|
||||||
|
../../../utilsBundle.ts
|
||||||
../../chromium/crApp.ts
|
../../chromium/crApp.ts
|
||||||
|
@ -23,7 +23,7 @@ import { installAppIcon, syncLocalStorageWithSettings } from '../../chromium/crA
|
|||||||
import { serverSideCallMetadata } from '../../instrumentation';
|
import { serverSideCallMetadata } from '../../instrumentation';
|
||||||
import { createPlaywright } from '../../playwright';
|
import { createPlaywright } from '../../playwright';
|
||||||
import { ProgressController } from '../../progress';
|
import { ProgressController } from '../../progress';
|
||||||
import { open, wsServer } from 'playwright-core/lib/utilsBundle';
|
import { open, wsServer } from '../../../utilsBundle';
|
||||||
import type { Page } from '../../page';
|
import type { Page } from '../../page';
|
||||||
|
|
||||||
export type Transport = {
|
export type Transport = {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
"./lib/vitePlugin": "./lib/vitePlugin.js"
|
"./lib/vitePlugin": "./lib/vitePlugin.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"playwright-core": "1.36.0-next",
|
||||||
"vite": "^4.3.9",
|
"vite": "^4.3.9",
|
||||||
"@playwright/test": "1.36.0-next"
|
"@playwright/test": "1.36.0-next"
|
||||||
},
|
},
|
||||||
|
0
packages/playwright-ct-core/src/DEPS.list
Normal file
0
packages/playwright-ct-core/src/DEPS.list
Normal file
@ -19,9 +19,5 @@
|
|||||||
"@vitejs/plugin-react": "^3.1.0",
|
"@vitejs/plugin-react": "^3.1.0",
|
||||||
"typescript": "^4.5.4",
|
"typescript": "^4.5.4",
|
||||||
"vite": "^4.2.1"
|
"vite": "^4.2.1"
|
||||||
},
|
|
||||||
"@standaloneDevDependencies": {
|
|
||||||
"@playwright/experimental-ct-react": "^1.22.0",
|
|
||||||
"@playwright/test": "^1.22.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,6 @@
|
|||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"typescript": "^4.6.2"
|
"typescript": "^4.6.2"
|
||||||
},
|
},
|
||||||
"@standaloneDevDependencies": {
|
|
||||||
"@playwright/experimental-ct-react17": "^1.2.2",
|
|
||||||
"@playwright/test": "^1.22.2"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
"build": "react-scripts build",
|
"build": "react-scripts build",
|
||||||
|
@ -18,9 +18,5 @@
|
|||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"vite": "^4.2.1",
|
"vite": "^4.2.1",
|
||||||
"vite-plugin-solid": "^2.6.1"
|
"vite-plugin-solid": "^2.6.1"
|
||||||
},
|
|
||||||
"@standaloneDevDependencies": {
|
|
||||||
"@playwright/experimental-ct-solid": "^1.22.2",
|
|
||||||
"@playwright/test": "^1.22.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,6 @@
|
|||||||
"typescript": "^4.5.4",
|
"typescript": "^4.5.4",
|
||||||
"vite": "^4.2.1"
|
"vite": "^4.2.1"
|
||||||
},
|
},
|
||||||
"@standaloneDevDependencies": {
|
|
||||||
"@playwright/experimental-ct-svelte": "^1.22.2",
|
|
||||||
"@playwright/test": "^1.22.2"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"svelte": "^3.49.0",
|
"svelte": "^3.49.0",
|
||||||
"svelte-navigator": "^3.2.2"
|
"svelte-navigator": "^3.2.2"
|
||||||
|
@ -18,10 +18,6 @@
|
|||||||
"rollup-plugin-terser": "^7.0.0",
|
"rollup-plugin-terser": "^7.0.0",
|
||||||
"sirv-cli": "^2.0.0"
|
"sirv-cli": "^2.0.0"
|
||||||
},
|
},
|
||||||
"@standaloneDevDependencies": {
|
|
||||||
"@playwright/experimental-ct-svelte": "^1.22.2",
|
|
||||||
"@playwright/test": "^1.22.2"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"svelte": "^3.0.0",
|
"svelte": "^3.0.0",
|
||||||
"svelte-navigator": "^3.2.2"
|
"svelte-navigator": "^3.2.2"
|
||||||
|
@ -24,10 +24,6 @@
|
|||||||
"eslint": "^7.32.0",
|
"eslint": "^7.32.0",
|
||||||
"eslint-plugin-vue": "^8.0.3"
|
"eslint-plugin-vue": "^8.0.3"
|
||||||
},
|
},
|
||||||
"@standaloneDevDependencies": {
|
|
||||||
"@playwright/experimental-ct-vue": "^1.22.2",
|
|
||||||
"@playwright/test": "^1.22.2"
|
|
||||||
},
|
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"root": true,
|
"root": true,
|
||||||
"env": {
|
"env": {
|
||||||
|
@ -16,9 +16,5 @@
|
|||||||
"@vue/tsconfig": "^0.1.3",
|
"@vue/tsconfig": "^0.1.3",
|
||||||
"vite": "^4.2.1",
|
"vite": "^4.2.1",
|
||||||
"vue-tsc": "^1.0.0"
|
"vue-tsc": "^1.0.0"
|
||||||
},
|
|
||||||
"@standaloneDevDependencies": {
|
|
||||||
"@playwright/experimental-ct-vue": "^1.22.2",
|
|
||||||
"@playwright/test": "^1.22.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,6 @@
|
|||||||
"eslint": "^7.32.0",
|
"eslint": "^7.32.0",
|
||||||
"eslint-plugin-vue": "^8.0.3"
|
"eslint-plugin-vue": "^8.0.3"
|
||||||
},
|
},
|
||||||
"@standaloneDevDependencies": {
|
|
||||||
"@playwright/experimental-ct-vue2": "^1.22.2",
|
|
||||||
"@playwright/test": "^1.22.2"
|
|
||||||
},
|
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"root": true,
|
"root": true,
|
||||||
"env": {
|
"env": {
|
||||||
|
@ -21,12 +21,12 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const ts = require('typescript');
|
const ts = require('typescript');
|
||||||
const path = require('path').posix;
|
const path = require('path').posix;
|
||||||
|
const Module = require('module');
|
||||||
|
const builtins = new Set(Module.builtinModules);
|
||||||
const packagesDir = path.resolve(path.join(__dirname, '..', 'packages'));
|
const packagesDir = path.resolve(path.join(__dirname, '..', 'packages'));
|
||||||
|
|
||||||
const packages = new Map();
|
const packages = new Map();
|
||||||
for (const package of fs.readdirSync(packagesDir))
|
packages.set('web', packagesDir + '/web/src/');
|
||||||
packages.set(package, packagesDir + '/' + package + '/src/');
|
|
||||||
packages.set('injected', packagesDir + '/playwright-core/src/server/injected/');
|
packages.set('injected', packagesDir + '/playwright-core/src/server/injected/');
|
||||||
packages.set('isomorphic', packagesDir + '/playwright-core/src/utils/isomorphic/');
|
packages.set('isomorphic', packagesDir + '/playwright-core/src/utils/isomorphic/');
|
||||||
packages.set('testIsomorphic', packagesDir + '/playwright-test/src/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 = {};
|
const depsCache = {};
|
||||||
|
|
||||||
async function checkDeps() {
|
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, '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, 'recorder'));
|
||||||
await innerCheckDeps(path.join(packagesDir, 'trace-viewer'));
|
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 corePackageJson = await innerCheckDeps(path.join(packagesDir, 'playwright-core'));
|
||||||
const testPackageJson = await innerCheckDeps(path.join(packagesDir, 'playwright-test'));
|
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('/');
|
importPath = packages.get(package) + tokens.slice(1).join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mergedDeps = calculateDeps(fileName);
|
||||||
|
if (mergedDeps.includes('***'))
|
||||||
|
return;
|
||||||
if (importPath) {
|
if (importPath) {
|
||||||
if (!fs.existsSync(importPath)) {
|
if (!fs.existsSync(importPath)) {
|
||||||
if (fs.existsSync(importPath + '.ts'))
|
if (fs.existsSync(importPath + '.ts'))
|
||||||
@ -142,7 +146,7 @@ async function innerCheckDeps(root) {
|
|||||||
importPath = importPath + '.d.ts';
|
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)}`);
|
errors.push(`Disallowed import ${path.relative(root, importPath)} in ${path.relative(root, fileName)}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -158,17 +162,13 @@ async function innerCheckDeps(root) {
|
|||||||
ts.forEachChild(node, x => visit(x, fileName));
|
ts.forEachChild(node, x => visit(x, fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
function allowImport(from, to) {
|
function calculateDeps(from) {
|
||||||
const fromDirectory = path.dirname(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;
|
let depsDirectory = fromDirectory;
|
||||||
while (depsDirectory.startsWith(packagesDir) && !depsCache[depsDirectory] && !fs.existsSync(path.join(depsDirectory, 'DEPS.list')))
|
while (depsDirectory.startsWith(packagesDir) && !depsCache[depsDirectory] && !fs.existsSync(path.join(depsDirectory, 'DEPS.list')))
|
||||||
depsDirectory = path.dirname(depsDirectory);
|
depsDirectory = path.dirname(depsDirectory);
|
||||||
|
if (!depsDirectory.startsWith(packagesDir))
|
||||||
|
return [];
|
||||||
|
|
||||||
let deps = depsCache[depsDirectory];
|
let deps = depsCache[depsDirectory];
|
||||||
if (!deps) {
|
if (!deps) {
|
||||||
@ -192,7 +192,17 @@ async function innerCheckDeps(root) {
|
|||||||
depsCache[depsDirectory] = deps;
|
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) {
|
for (const dep of mergedDeps) {
|
||||||
if (dep === '***')
|
if (dep === '***')
|
||||||
return true;
|
return true;
|
||||||
@ -209,22 +219,16 @@ async function innerCheckDeps(root) {
|
|||||||
|
|
||||||
function allowExternalImport(importName, packageJSON) {
|
function allowExternalImport(importName, packageJSON) {
|
||||||
// Only external imports are relevant. Files in src/web are bundled via webpack.
|
// 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;
|
return true;
|
||||||
if (peerDependencies.includes(importName))
|
if (peerDependencies.includes(importName))
|
||||||
return true;
|
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)
|
if (!packageJSON)
|
||||||
return false;
|
return false;
|
||||||
const match = importName.match(/(@[\w-]+\/)?([^/]+)/);
|
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];
|
return !!(packageJSON.dependencies || {})[dependency];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user