Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: move transform to its own folder (for loader worker) (#23247)

Pavel Feldman76b4b9dbaf52
diff --git a/packages/playwright-ct-core/src/tsxTransform.ts b/packages/playwright-ct-core/src/tsxTransform.ts
index 5c6acd7889..edbaa3e05b 100644
--- a/packages/playwright-ct-core/src/tsxTransform.ts
+++ b/packages/playwright-ct-core/src/tsxTransform.ts
@@ -15,8 +15,8 @@
*/
import path from 'path';
-import type { T, BabelAPI } from '../../playwright-test/src/common/babelBundle';
-import { types, declare, traverse } from '@playwright/test/lib/common/babelBundle';
+import type { T, BabelAPI } from '@playwright/test/src/transform/babelBundle';
+import { types, declare, traverse } from '@playwright/test/lib/transform/babelBundle';
import { resolveImportSpecifierExtension } from '@playwright/test/lib/util';
const t: typeof T = types;
diff --git a/packages/playwright-ct-core/src/vitePlugin.ts b/packages/playwright-ct-core/src/vitePlugin.ts
index ea4b940fd9..03a3e6a199 100644
--- a/packages/playwright-ct-core/src/vitePlugin.ts
+++ b/packages/playwright-ct-core/src/vitePlugin.ts
@@ -25,11 +25,11 @@ import type { PluginContext } from 'rollup';
import fs from 'fs';
import path from 'path';
-import { parse, traverse, types as t } from '@playwright/test/lib/common/babelBundle';
+import { parse, traverse, types as t } from '@playwright/test/lib/transform/babelBundle';
import { stoppable } from '@playwright/test/lib/utilsBundle';
import { assert, calculateSha1 } from 'playwright-core/lib/utils';
import { getPlaywrightVersion } from 'playwright-core/lib/utils';
-import { setExternalDependencies } from '@playwright/test/lib/common/compilationCache';
+import { setExternalDependencies } from '@playwright/test/lib/transform/compilationCache';
import { collectComponentUsages, componentInfo } from './tsxTransform';
let stoppableServer: any;
diff --git a/packages/playwright-test/bundles/babel/package.json b/packages/playwright-test/bundles/babel/package.json
index 329b24eb08..dc9edb2fdd 100644
--- a/packages/playwright-test/bundles/babel/package.json
+++ b/packages/playwright-test/bundles/babel/package.json
@@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"scripts": {
- "esbuild": "esbuild ./src/babelBundleImpl.ts --bundle --outdir=../../lib/common --format=cjs --platform=node --target=ES2019",
+ "esbuild": "esbuild ./src/babelBundleImpl.ts --bundle --outdir=../../lib/transform --format=cjs --platform=node --target=ES2019",
"build": "npm run esbuild -- --minify",
"watch": "npm run esbuild -- --watch --sourcemap",
"generate-license": "node ../../../../utils/generate_third_party_notice.js"
diff --git a/packages/playwright-test/package.json b/packages/playwright-test/package.json
index cfaef06f7f..6afc5b894a 100644
--- a/packages/playwright-test/package.json
+++ b/packages/playwright-test/package.json
@@ -18,8 +18,8 @@
"./cli": "./cli.js",
"./package.json": "./package.json",
"./lib/cli": "./lib/cli.js",
- "./lib/common/babelBundle": "./lib/common/babelBundle.js",
- "./lib/common/compilationCache": "./lib/common/compilationCache.js",
+ "./lib/transform/babelBundle": "./lib/transform/babelBundle.js",
+ "./lib/transform/compilationCache": "./lib/transform/compilationCache.js",
"./lib/internalsForTest": "./lib/internalsForTest.js",
"./lib/experimentalLoader": "./lib/experimentalLoader.js",
"./lib/plugins": "./lib/plugins/index.js",
diff --git a/packages/playwright-test/src/DEPS.list b/packages/playwright-test/src/DEPS.list
index 863c838067..09354b5b0f 100644
--- a/packages/playwright-test/src/DEPS.list
+++ b/packages/playwright-test/src/DEPS.list
@@ -8,3 +8,9 @@ common/
[index.ts]
@testIsomorphic/**
+
+[experimentalLoader.ts]
+./transform/
+
+[internalsForTest.ts]
+**
diff --git a/packages/playwright-test/src/common/DEPS.list b/packages/playwright-test/src/common/DEPS.list
index 926458602b..ab654c7f90 100644
--- a/packages/playwright-test/src/common/DEPS.list
+++ b/packages/playwright-test/src/common/DEPS.list
@@ -1,9 +1,8 @@
[*]
../util.ts
../utilsBundle.ts
-
-[transform.ts]
-../third_party/tsconfig-loader.ts
+../transform
[testType.ts]
../matchers/expect.ts
+
diff --git a/packages/playwright-test/src/common/configLoader.ts b/packages/playwright-test/src/common/configLoader.ts
index c0252e1ee3..a3e614c2df 100644
--- a/packages/playwright-test/src/common/configLoader.ts
+++ b/packages/playwright-test/src/common/configLoader.ts
@@ -18,7 +18,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { isRegExp } from 'playwright-core/lib/utils';
import type { ConfigCLIOverrides, SerializedConfig } from './ipc';
-import { requireOrImport, setBabelPlugins } from './transform';
+import { requireOrImport, setBabelPlugins } from '../transform/transform';
import type { Config, Project } from '../../types/test';
import { errorWithFile } from '../util';
import { setCurrentConfig } from './globals';
diff --git a/packages/playwright-test/src/common/ipc.ts b/packages/playwright-test/src/common/ipc.ts
index 1be9668bdb..aee8d5b639 100644
--- a/packages/playwright-test/src/common/ipc.ts
+++ b/packages/playwright-test/src/common/ipc.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { serializeCompilationCache } from './compilationCache';
+import { serializeCompilationCache } from '../transform/compilationCache';
import type { FullConfigInternal } from './config';
import type { ReporterDescription, TestInfoError, TestStatus } from '../../types/test';
diff --git a/packages/playwright-test/src/common/testLoader.ts b/packages/playwright-test/src/common/testLoader.ts
index da152f2ab8..ddeef0f084 100644
--- a/packages/playwright-test/src/common/testLoader.ts
+++ b/packages/playwright-test/src/common/testLoader.ts
@@ -19,9 +19,9 @@ import util from 'util';
import type { TestError } from '../../reporter';
import { isWorkerProcess, setCurrentlyLoadingFileSuite } from './globals';
import { Suite } from './test';
-import { requireOrImport } from './transform';
+import { requireOrImport } from '../transform/transform';
import { filterStackTrace } from '../util';
-import { startCollectingFileDeps, stopCollectingFileDeps } from './compilationCache';
+import { startCollectingFileDeps, stopCollectingFileDeps } from '../transform/compilationCache';
export const defaultTimeout = 30000;
diff --git a/packages/playwright-test/src/common/testType.ts b/packages/playwright-test/src/common/testType.ts
index 5f8d429691..3c51c8f106 100644
--- a/packages/playwright-test/src/common/testType.ts
+++ b/packages/playwright-test/src/common/testType.ts
@@ -17,7 +17,7 @@
import { expect } from '../matchers/expect';
import { currentlyLoadingFileSuite, currentTestInfo, setCurrentlyLoadingFileSuite } from './globals';
import { TestCase, Suite } from './test';
-import { wrapFunctionWithLocation } from './transform';
+import { wrapFunctionWithLocation } from '../transform/transform';
import type { FixturesWithLocation } from './config';
import type { Fixtures, TestType } from '../../types/test';
import type { Location } from '../../types/testReporter';
diff --git a/packages/playwright-test/src/experimentalLoader.ts b/packages/playwright-test/src/experimentalLoader.ts
index 3f7244a335..b4617d918b 100644
--- a/packages/playwright-test/src/experimentalLoader.ts
+++ b/packages/playwright-test/src/experimentalLoader.ts
@@ -16,8 +16,8 @@
import fs from 'fs';
import url from 'url';
-import { belongsToNodeModules, currentFileDepsCollector } from './common/compilationCache';
-import { transformHook, resolveHook } from './common/transform';
+import { belongsToNodeModules, currentFileDepsCollector } from './transform/compilationCache';
+import { transformHook, resolveHook } from './transform/transform';
// Node < 18.6: defaultResolve takes 3 arguments.
// Node >= 18.6: nextResolve from the chain takes 2 arguments.
diff --git a/packages/playwright-test/src/internalsForTest.ts b/packages/playwright-test/src/internalsForTest.ts
index 0b45178627..c0d2cbd95f 100644
--- a/packages/playwright-test/src/internalsForTest.ts
+++ b/packages/playwright-test/src/internalsForTest.ts
@@ -15,7 +15,7 @@
*/
import path from 'path';
-import { fileDependenciesForTest } from './common/compilationCache';
+import { fileDependenciesForTest } from './transform/compilationCache';
export function fileDependencies() {
return Object.fromEntries([...fileDependenciesForTest().entries()].map(entry => (
diff --git a/packages/playwright-test/src/loader/DEPS.list b/packages/playwright-test/src/loader/DEPS.list
index c0a39450ff..1e987ef87c 100644
--- a/packages/playwright-test/src/loader/DEPS.list
+++ b/packages/playwright-test/src/loader/DEPS.list
@@ -1,2 +1,3 @@
[*]
../common/
+../transform/
\ No newline at end of file
diff --git a/packages/playwright-test/src/loader/loaderMain.ts b/packages/playwright-test/src/loader/loaderMain.ts
index 01ac96dc4b..cea150b2a8 100644
--- a/packages/playwright-test/src/loader/loaderMain.ts
+++ b/packages/playwright-test/src/loader/loaderMain.ts
@@ -20,7 +20,7 @@ import { ProcessRunner } from '../common/process';
import type { FullConfigInternal } from '../common/config';
import { loadTestFile } from '../common/testLoader';
import type { TestError } from '../../reporter';
-import { addToCompilationCache, serializeCompilationCache } from '../common/compilationCache';
+import { addToCompilationCache, serializeCompilationCache } from '../transform/compilationCache';
import { PoolBuilder } from '../common/poolBuilder';
export class LoaderMain extends ProcessRunner {
diff --git a/packages/playwright-test/src/reporters/DEPS.list b/packages/playwright-test/src/reporters/DEPS.list
index cce2c15d62..b5f5ed31c5 100644
--- a/packages/playwright-test/src/reporters/DEPS.list
+++ b/packages/playwright-test/src/reporters/DEPS.list
@@ -6,3 +6,9 @@
[merge.ts]
../runner/reporters.ts
+
+[internalReporter.ts]
+../transform/babelBundle.ts
+
+[raw.ts]
+../transform/babelBundle.ts
diff --git a/packages/playwright-test/src/reporters/internalReporter.ts b/packages/playwright-test/src/reporters/internalReporter.ts
index c61ba4e051..4358a59f5b 100644
--- a/packages/playwright-test/src/reporters/internalReporter.ts
+++ b/packages/playwright-test/src/reporters/internalReporter.ts
@@ -16,7 +16,7 @@
import fs from 'fs';
import { colors } from 'playwright-core/lib/utilsBundle';
-import { codeFrameColumns } from '../common/babelBundle';
+import { codeFrameColumns } from '../transform/babelBundle';
import type { FullConfig, TestCase, TestError, TestResult, FullResult, TestStep, Reporter } from '../../types/testReporter';
import { Suite } from '../common/test';
import type { FullConfigInternal } from '../common/config';
diff --git a/packages/playwright-test/src/reporters/raw.ts b/packages/playwright-test/src/reporters/raw.ts
index 24f8357139..030389f67a 100644
--- a/packages/playwright-test/src/reporters/raw.ts
+++ b/packages/playwright-test/src/reporters/raw.ts
@@ -22,7 +22,7 @@ import { sanitizeForFilePath } from '../util';
import { formatResultFailure } from './base';
import { toPosixPath, serializePatterns } from './json';
import { MultiMap } from 'playwright-core/lib/utils';
-import { codeFrameColumns } from '../common/babelBundle';
+import { codeFrameColumns } from '../transform/babelBundle';
import type { Metadata } from '../../types/test';
import type { SuitePrivate } from '../../types/reporterPrivate';
diff --git a/packages/playwright-test/src/runner/DEPS.list b/packages/playwright-test/src/runner/DEPS.list
index c5f0d18fbf..eee9ede928 100644
--- a/packages/playwright-test/src/runner/DEPS.list
+++ b/packages/playwright-test/src/runner/DEPS.list
@@ -3,6 +3,7 @@
../common/
../reporters/
../third_party/
+../transform/
../plugins/
../util.ts
../utilsBundle.ts
diff --git a/packages/playwright-test/src/runner/loadUtils.ts b/packages/playwright-test/src/runner/loadUtils.ts
index 202c7ad403..1af701d461 100644
--- a/packages/playwright-test/src/runner/loadUtils.ts
+++ b/packages/playwright-test/src/runner/loadUtils.ts
@@ -25,10 +25,10 @@ import { createFileMatcherFromArguments, createFileFiltersFromArguments, createT
import type { Matcher, TestFileFilter } from '../util';
import { buildProjectsClosure, collectFilesForProject, filterProjects } from './projectUtils';
import type { TestRun } from './tasks';
-import { requireOrImport } from '../common/transform';
+import { requireOrImport } from '../transform/transform';
import { buildFileSuiteForProject, filterByFocusedLine, filterByTestIds, filterOnly, filterTestsRemoveEmptySuites } from '../common/suiteUtils';
import { createTestGroups, filterForShard, type TestGroup } from './testGroups';
-import { dependenciesForTestFile } from '../common/compilationCache';
+import { dependenciesForTestFile } from '../transform/compilationCache';
import { sourceMapSupport } from '../utilsBundle';
import type { RawSourceMap } from 'source-map';
diff --git a/packages/playwright-test/src/runner/loaderHost.ts b/packages/playwright-test/src/runner/loaderHost.ts
index 4bbade6ecb..060a31905f 100644
--- a/packages/playwright-test/src/runner/loaderHost.ts
+++ b/packages/playwright-test/src/runner/loaderHost.ts
@@ -21,8 +21,8 @@ import { Suite } from '../common/test';
import { loadTestFile } from '../common/testLoader';
import type { FullConfigInternal } from '../common/config';
import { PoolBuilder } from '../common/poolBuilder';
-import { addToCompilationCache } from '../common/compilationCache';
-import { setBabelPlugins } from '../common/transform';
+import { addToCompilationCache } from '../transform/compilationCache';
+import { setBabelPlugins } from '../transform/transform';
export class InProcessLoaderHost {
private _config: FullConfigInternal;
diff --git a/packages/playwright-test/src/runner/uiMode.ts b/packages/playwright-test/src/runner/uiMode.ts
index 317d43a7fe..2df0ddfb03 100644
--- a/packages/playwright-test/src/runner/uiMode.ts
+++ b/packages/playwright-test/src/runner/uiMode.ts
@@ -18,7 +18,7 @@ import { showTraceViewer } from 'playwright-core/lib/server';
import type { Page } from 'playwright-core/lib/server/page';
import { isUnderTest, ManualPromise } from 'playwright-core/lib/utils';
import type { FullResult } from '../../reporter';
-import { clearCompilationCache, collectAffectedTestFiles, dependenciesForTestFile } from '../common/compilationCache';
+import { clearCompilationCache, collectAffectedTestFiles, dependenciesForTestFile } from '../transform/compilationCache';
import type { FullConfigInternal } from '../common/config';
import { InternalReporter } from '../reporters/internalReporter';
import { TeleReporterEmitter } from '../reporters/teleEmitter';
diff --git a/packages/playwright-test/src/runner/watchMode.ts b/packages/playwright-test/src/runner/watchMode.ts
index 48ba73f8a6..1bb79174d2 100644
--- a/packages/playwright-test/src/runner/watchMode.ts
+++ b/packages/playwright-test/src/runner/watchMode.ts
@@ -22,7 +22,7 @@ import { createFileMatcher, createFileMatcherFromArguments } from '../util';
import type { Matcher } from '../util';
import { TestRun, createTaskRunnerForWatch, createTaskRunnerForWatchSetup } from './tasks';
import { buildProjectsClosure, filterProjects } from './projectUtils';
-import { clearCompilationCache, collectAffectedTestFiles } from '../common/compilationCache';
+import { clearCompilationCache, collectAffectedTestFiles } from '../transform/compilationCache';
import type { FullResult } from 'packages/playwright-test/reporter';
import { chokidar } from '../utilsBundle';
import type { FSWatcher as CFSWatcher } from 'chokidar';
diff --git a/packages/playwright-test/src/transform/DEPS.list b/packages/playwright-test/src/transform/DEPS.list
new file mode 100644
index 0000000000..8c7c26d27f
--- /dev/null
+++ b/packages/playwright-test/src/transform/DEPS.list
@@ -0,0 +1,4 @@
+[*]
+../util.ts
+../utilsBundle.ts
+../third_party/tsconfig-loader.ts
diff --git a/packages/playwright-test/src/common/babelBundle.ts b/packages/playwright-test/src/transform/babelBundle.ts
similarity index 92%
rename from packages/playwright-test/src/common/babelBundle.ts
rename to packages/playwright-test/src/transform/babelBundle.ts
index 632e9e3d9d..1f711ee95f 100644
--- a/packages/playwright-test/src/common/babelBundle.ts
+++ b/packages/playwright-test/src/transform/babelBundle.ts
@@ -19,7 +19,7 @@ export const codeFrameColumns: typeof import('../../bundles/babel/node_modules/@
export const declare: typeof import('../../bundles/babel/node_modules/@types/babel__helper-plugin-utils').declare = require('./babelBundleImpl').declare;
export const types: typeof import('../../bundles/babel/node_modules/@types/babel__core').types = require('./babelBundleImpl').types;
export const parse: typeof import('../../bundles/babel/node_modules/@babel/parser/typings/babel-parser').parse = require('./babelBundleImpl').parse;
-export const traverse: typeof import('../../bundles/babel/node_modules/@types/babel__traverse').default = require('./babelBundleImpl').traverse;
+export const traverse: typeof import('@babel/traverse').default = require('./babelBundleImpl').traverse;
export type BabelPlugin = [string, any?];
export type BabelTransformFunction = (code: string, filename: string, isTypeScript: boolean, isModule: boolean, pluginsPrefix: BabelPlugin[], pluginsSuffix: BabelPlugin[]) => BabelFileResult;
export const babelTransform: BabelTransformFunction = require('./babelBundleImpl').babelTransform;
diff --git a/packages/playwright-test/src/common/compilationCache.ts b/packages/playwright-test/src/transform/compilationCache.ts
similarity index 100%
rename from packages/playwright-test/src/common/compilationCache.ts
rename to packages/playwright-test/src/transform/compilationCache.ts
diff --git a/packages/playwright-test/src/common/transform.ts b/packages/playwright-test/src/transform/transform.ts
similarity index 100%
rename from packages/playwright-test/src/common/transform.ts
rename to packages/playwright-test/src/transform/transform.ts
diff --git a/packages/playwright-test/src/worker/DEPS.list b/packages/playwright-test/src/worker/DEPS.list
index bfce245fbb..fb352ac389 100644
--- a/packages/playwright-test/src/worker/DEPS.list
+++ b/packages/playwright-test/src/worker/DEPS.list
@@ -1,4 +1,5 @@
[*]
../common/
+../transform/
../util.ts
../utilBundle.ts
diff --git a/packages/playwright-test/src/worker/workerMain.ts b/packages/playwright-test/src/worker/workerMain.ts
index 5338596ff8..3284dd3cd4 100644
--- a/packages/playwright-test/src/worker/workerMain.ts
+++ b/packages/playwright-test/src/worker/workerMain.ts
@@ -30,7 +30,7 @@ import { ProcessRunner } from '../common/process';
import { loadTestFile } from '../common/testLoader';
import { buildFileSuiteForProject, filterTestsRemoveEmptySuites } from '../common/suiteUtils';
import { PoolBuilder } from '../common/poolBuilder';
-import { addToCompilationCache } from '../common/compilationCache';
+import { addToCompilationCache } from '../transform/compilationCache';
import type { TestInfoError } from '../../types/test';
const removeFolderAsync = util.promisify(rimraf);