2021-01-06 12:41:17 -08:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-08-05 12:07:43 -07:00
|
|
|
// @ts-check
|
|
|
|
|
2021-01-06 12:41:17 -08:00
|
|
|
const child_process = require('child_process');
|
|
|
|
const path = require('path');
|
2021-01-07 13:26:34 -08:00
|
|
|
const chokidar = require('chokidar');
|
2021-06-23 18:01:48 -07:00
|
|
|
const fs = require('fs');
|
2022-02-08 11:35:00 -07:00
|
|
|
const { workspace } = require('../workspace');
|
2025-05-07 14:33:50 -07:00
|
|
|
const { build, context } = require('esbuild');
|
2021-01-06 12:41:17 -08:00
|
|
|
|
2021-08-05 12:07:43 -07:00
|
|
|
/**
|
2021-10-22 10:13:05 +02:00
|
|
|
* @typedef {{
|
|
|
|
* files: string,
|
|
|
|
* from: string,
|
|
|
|
* to: string,
|
|
|
|
* ignored?: string[],
|
|
|
|
* }} CopyFile
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {{
|
|
|
|
* inputs: string[],
|
|
|
|
* mustExist?: string[],
|
2022-03-25 13:12:00 -08:00
|
|
|
* cwd?: string,
|
2025-05-07 09:54:26 -07:00
|
|
|
* }} BaseOnChange
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {BaseOnChange & {
|
|
|
|
* command: string,
|
|
|
|
* args?: string[],
|
|
|
|
* }} CommandOnChange
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {BaseOnChange & {
|
|
|
|
* script: string,
|
|
|
|
* }} ScriptOnChange
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {CommandOnChange|ScriptOnChange} OnChange
|
2021-08-05 12:07:43 -07:00
|
|
|
*/
|
2021-10-22 10:13:05 +02:00
|
|
|
|
2025-05-09 17:01:03 +02:00
|
|
|
/** @type {(() => void)[]} */
|
|
|
|
const disposables = [];
|
2021-10-22 10:13:05 +02:00
|
|
|
/** @type {Step[]} */
|
2021-01-06 12:41:17 -08:00
|
|
|
const steps = [];
|
2021-10-22 10:13:05 +02:00
|
|
|
/** @type {OnChange[]} */
|
2021-01-06 12:41:17 -08:00
|
|
|
const onChanges = [];
|
2021-10-22 10:13:05 +02:00
|
|
|
/** @type {CopyFile[]} */
|
2021-06-23 18:01:48 -07:00
|
|
|
const copyFiles = [];
|
2021-01-06 12:41:17 -08:00
|
|
|
|
|
|
|
const watchMode = process.argv.slice(2).includes('--watch');
|
2025-05-09 12:19:44 -07:00
|
|
|
const withSourceMaps = watchMode;
|
2025-04-17 05:19:48 -07:00
|
|
|
const installMode = process.argv.slice(2).includes('--install');
|
2021-01-06 12:41:17 -08:00
|
|
|
const ROOT = path.join(__dirname, '..', '..');
|
|
|
|
|
2021-10-22 10:13:05 +02:00
|
|
|
/**
|
2022-01-30 01:56:58 +08:00
|
|
|
* @param {string} relative
|
2021-10-22 10:13:05 +02:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2021-01-06 12:41:17 -08:00
|
|
|
function filePath(relative) {
|
|
|
|
return path.join(ROOT, ...relative.split('/'));
|
|
|
|
}
|
|
|
|
|
2022-01-30 01:56:58 +08:00
|
|
|
/**
|
|
|
|
* @param {string} path
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
function quotePath(path) {
|
|
|
|
return "\"" + path + "\"";
|
|
|
|
}
|
|
|
|
|
2025-05-07 09:54:26 -07:00
|
|
|
class Step {
|
|
|
|
/**
|
|
|
|
* @param {{
|
|
|
|
* concurrent?: boolean,
|
|
|
|
* }} options
|
|
|
|
*/
|
|
|
|
constructor(options) {
|
|
|
|
this.concurrent = options.concurrent;
|
|
|
|
}
|
|
|
|
|
2025-05-08 08:29:01 -07:00
|
|
|
async run() {
|
2025-05-07 09:54:26 -07:00
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProgramStep extends Step {
|
|
|
|
/**
|
|
|
|
* @param {{
|
|
|
|
* command: string,
|
|
|
|
* args: string[],
|
|
|
|
* shell: boolean,
|
|
|
|
* env?: NodeJS.ProcessEnv,
|
|
|
|
* cwd?: string,
|
|
|
|
* concurrent?: boolean,
|
|
|
|
* }} options
|
|
|
|
*/
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
this._options = options;
|
|
|
|
}
|
|
|
|
|
2025-05-07 14:33:50 -07:00
|
|
|
/** @override */
|
2025-05-08 08:29:01 -07:00
|
|
|
async run() {
|
2025-05-07 09:54:26 -07:00
|
|
|
const step = this._options;
|
|
|
|
console.log(`==== Running ${step.command} ${step.args.join(' ')} in ${step.cwd || process.cwd()}`);
|
|
|
|
const child = child_process.spawn(step.command, step.args, {
|
|
|
|
stdio: 'inherit',
|
|
|
|
shell: step.shell,
|
|
|
|
env: {
|
|
|
|
...process.env,
|
2025-05-08 08:29:01 -07:00
|
|
|
...step.env
|
2025-05-07 09:54:26 -07:00
|
|
|
},
|
|
|
|
cwd: step.cwd,
|
|
|
|
});
|
2025-05-09 17:01:03 +02:00
|
|
|
disposables.push(() => {
|
|
|
|
if (child.exitCode === null)
|
|
|
|
child.kill();
|
|
|
|
});
|
2025-05-08 08:29:01 -07:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
child.on('close', (code, signal) => {
|
|
|
|
if (code || signal)
|
|
|
|
reject(new Error(`'${step.command} ${step.args.join(' ')}' exited with code ${code}, signal ${signal}`));
|
|
|
|
else
|
|
|
|
resolve({ });
|
|
|
|
});
|
|
|
|
});
|
2025-05-07 09:54:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-23 11:46:20 -08:00
|
|
|
/**
|
2025-05-07 09:54:26 -07:00
|
|
|
* @param {OnChange} onChange
|
2023-02-23 11:46:20 -08:00
|
|
|
*/
|
2025-05-08 08:29:01 -07:00
|
|
|
async function runOnChangeStep(onChange) {
|
2025-05-07 09:54:26 -07:00
|
|
|
const step = ('script' in onChange)
|
|
|
|
? new ProgramStep({ command: 'node', args: [filePath(onChange.script)], shell: false })
|
|
|
|
: new ProgramStep({ command: onChange.command, args: onChange.args || [], shell: true, cwd: onChange.cwd });
|
2025-05-08 08:29:01 -07:00
|
|
|
await step.run();
|
2023-02-23 11:46:20 -08:00
|
|
|
}
|
|
|
|
|
2021-10-13 16:35:50 -04:00
|
|
|
async function runWatch() {
|
2022-03-25 13:12:00 -08:00
|
|
|
/** @param {OnChange} onChange */
|
|
|
|
function runOnChange(onChange) {
|
|
|
|
const paths = onChange.inputs;
|
|
|
|
const mustExist = onChange.mustExist || [];
|
2022-03-24 16:38:03 -08:00
|
|
|
let timeout;
|
2022-03-25 13:12:00 -08:00
|
|
|
function callback() {
|
2022-03-24 16:38:03 -08:00
|
|
|
timeout = undefined;
|
2021-10-13 16:35:50 -04:00
|
|
|
for (const fileMustExist of mustExist) {
|
|
|
|
if (!fs.existsSync(filePath(fileMustExist)))
|
|
|
|
return;
|
|
|
|
}
|
2025-05-08 08:29:01 -07:00
|
|
|
runOnChangeStep(onChange).catch(e => console.error(e));
|
2022-03-25 13:12:00 -08:00
|
|
|
}
|
2022-03-24 16:38:03 -08:00
|
|
|
// chokidar will report all files as added in a sync loop, throttle those.
|
|
|
|
const reschedule = () => {
|
|
|
|
if (timeout)
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = setTimeout(callback, 500);
|
|
|
|
};
|
2022-03-25 13:12:00 -08:00
|
|
|
chokidar.watch([...paths, ...mustExist, onChange.script].filter(Boolean).map(filePath)).on('all', reschedule);
|
2021-01-07 13:26:34 -08:00
|
|
|
callback();
|
2021-01-06 12:41:17 -08:00
|
|
|
}
|
|
|
|
|
2021-10-11 10:52:17 -04:00
|
|
|
for (const { files, from, to, ignored } of copyFiles) {
|
|
|
|
const watcher = chokidar.watch([filePath(files)], { ignored });
|
|
|
|
watcher.on('all', (event, file) => {
|
|
|
|
copyFile(file, from, to);
|
|
|
|
});
|
|
|
|
}
|
2023-02-23 11:46:20 -08:00
|
|
|
|
|
|
|
for (const step of steps) {
|
|
|
|
if (!step.concurrent)
|
2025-05-08 08:29:01 -07:00
|
|
|
await step.run();
|
2023-02-23 11:46:20 -08:00
|
|
|
}
|
|
|
|
|
2022-04-18 10:31:58 -08:00
|
|
|
for (const step of steps) {
|
2025-05-07 09:54:26 -07:00
|
|
|
if (step.concurrent)
|
2025-05-08 08:29:01 -07:00
|
|
|
step.run().catch(e => console.error(e));
|
2022-04-18 10:31:58 -08:00
|
|
|
}
|
2021-01-06 12:41:17 -08:00
|
|
|
for (const onChange of onChanges)
|
2022-03-25 13:12:00 -08:00
|
|
|
runOnChange(onChange);
|
2021-01-06 12:41:17 -08:00
|
|
|
}
|
|
|
|
|
2021-06-23 18:01:48 -07:00
|
|
|
async function runBuild() {
|
2021-10-11 10:52:17 -04:00
|
|
|
for (const { files, from, to, ignored } of copyFiles) {
|
2021-06-23 18:01:48 -07:00
|
|
|
const watcher = chokidar.watch([filePath(files)], {
|
|
|
|
ignored
|
|
|
|
});
|
|
|
|
watcher.on('add', file => {
|
|
|
|
copyFile(file, from, to);
|
|
|
|
});
|
|
|
|
await new Promise(x => watcher.once('ready', x));
|
|
|
|
watcher.close();
|
|
|
|
}
|
2021-10-11 10:52:17 -04:00
|
|
|
for (const step of steps)
|
2025-05-08 08:29:01 -07:00
|
|
|
await step.run();
|
2025-05-07 09:54:26 -07:00
|
|
|
for (const onChange of onChanges)
|
2025-05-08 08:29:01 -07:00
|
|
|
runOnChangeStep(onChange);
|
2021-06-23 18:01:48 -07:00
|
|
|
}
|
|
|
|
|
2021-10-22 10:13:05 +02:00
|
|
|
/**
|
2022-01-30 01:56:58 +08:00
|
|
|
* @param {string} file
|
|
|
|
* @param {string} from
|
|
|
|
* @param {string} to
|
2021-10-22 10:13:05 +02:00
|
|
|
*/
|
2021-06-23 18:01:48 -07:00
|
|
|
function copyFile(file, from, to) {
|
|
|
|
const destination = path.resolve(filePath(to), path.relative(filePath(from), file));
|
|
|
|
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
|
|
fs.copyFileSync(file, destination);
|
2021-01-06 12:41:17 -08:00
|
|
|
}
|
|
|
|
|
2025-05-12 19:22:14 -07:00
|
|
|
/**
|
|
|
|
* @typedef {{
|
|
|
|
* modulePath: string,
|
|
|
|
* entryPoints: string[],
|
|
|
|
* external?: string[],
|
|
|
|
* outdir?: string,
|
|
|
|
* outfile?: string,
|
|
|
|
* minify?: boolean,
|
|
|
|
* }} BundleOptions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @type {BundleOptions[]} */
|
2023-01-11 18:36:04 -08:00
|
|
|
const bundles = [];
|
2025-05-12 19:22:14 -07:00
|
|
|
|
|
|
|
bundles.push({
|
|
|
|
modulePath: 'packages/playwright/bundles/babel',
|
|
|
|
outdir: 'packages/playwright/lib/transform',
|
|
|
|
entryPoints: ['src/babelBundleImpl.ts'],
|
|
|
|
external: ['playwright'],
|
|
|
|
});
|
|
|
|
|
|
|
|
bundles.push({
|
|
|
|
modulePath: 'packages/playwright/bundles/expect',
|
|
|
|
outdir: 'packages/playwright/lib/common',
|
|
|
|
entryPoints: ['src/expectBundleImpl.ts'],
|
|
|
|
});
|
|
|
|
|
|
|
|
bundles.push({
|
|
|
|
modulePath: 'packages/playwright/bundles/utils',
|
|
|
|
outdir: 'packages/playwright/lib',
|
|
|
|
entryPoints: ['src/utilsBundleImpl.ts'],
|
|
|
|
external: ['fsevents'],
|
|
|
|
});
|
|
|
|
|
|
|
|
bundles.push({
|
|
|
|
modulePath: 'packages/playwright-core/bundles/utils',
|
|
|
|
outfile: 'packages/playwright-core/lib/utilsBundleImpl/index.js',
|
|
|
|
entryPoints: ['src/utilsBundleImpl.ts'],
|
|
|
|
});
|
|
|
|
|
|
|
|
bundles.push({
|
|
|
|
modulePath: 'packages/playwright-core/bundles/zip',
|
|
|
|
outdir: 'packages/playwright-core/lib',
|
|
|
|
entryPoints: ['src/zipBundleImpl.ts'],
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// @playwright/client
|
|
|
|
bundles.push({
|
|
|
|
modulePath: 'packages/playwright-client',
|
|
|
|
outdir: 'packages/playwright-client/lib',
|
|
|
|
entryPoints: ['src/index.ts'],
|
|
|
|
minify: false,
|
|
|
|
});
|
2023-01-11 18:36:04 -08:00
|
|
|
|
2025-05-12 09:40:16 -07:00
|
|
|
class GroupStep extends Step {
|
|
|
|
/** @param {Step[]} steps */
|
|
|
|
constructor(steps) {
|
|
|
|
super({ concurrent: false });
|
|
|
|
this._steps = steps;
|
|
|
|
if (steps.some(s => !s.concurrent))
|
|
|
|
throw new Error('Composite step cannot contain non-concurrent steps');
|
|
|
|
}
|
|
|
|
async run() {
|
|
|
|
console.log('==== Starting parallel group');
|
|
|
|
const start = Date.now();
|
|
|
|
await Promise.all(this._steps.map(step => step.run()));
|
|
|
|
console.log('==== Parallel group finished in', Date.now() - start, 'ms');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {Step[]} */
|
|
|
|
const updateSteps = [];
|
|
|
|
|
2022-01-24 11:25:24 -08:00
|
|
|
// Update test runner.
|
2025-05-12 09:40:16 -07:00
|
|
|
updateSteps.push(new ProgramStep({
|
2022-01-24 11:25:24 -08:00
|
|
|
command: 'npm',
|
|
|
|
args: ['ci', '--save=false', '--fund=false', '--audit=false'],
|
|
|
|
shell: true,
|
|
|
|
cwd: path.join(__dirname, '..', '..', 'tests', 'playwright-test', 'stable-test-runner'),
|
2025-05-12 09:40:16 -07:00
|
|
|
concurrent: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2022-01-24 11:25:24 -08:00
|
|
|
|
2023-01-11 18:36:04 -08:00
|
|
|
// Update bundles.
|
|
|
|
for (const bundle of bundles) {
|
2025-05-12 19:22:14 -07:00
|
|
|
// Do not update @playwright/client, it has not its own deps.
|
|
|
|
if (bundle.modulePath === 'packages/playwright-client')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const packageJson = path.join(filePath(bundle.modulePath), 'package.json');
|
|
|
|
if (!fs.existsSync(packageJson))
|
|
|
|
throw new Error(`${packageJson} does not exist`);
|
2025-05-12 09:40:16 -07:00
|
|
|
updateSteps.push(new ProgramStep({
|
2023-01-11 18:36:04 -08:00
|
|
|
command: 'npm',
|
2023-02-09 08:40:27 -08:00
|
|
|
args: ['ci', '--save=false', '--fund=false', '--audit=false', '--omit=optional'],
|
2023-01-11 18:36:04 -08:00
|
|
|
shell: true,
|
2025-05-12 19:22:14 -07:00
|
|
|
cwd: filePath(bundle.modulePath),
|
2025-05-12 09:40:16 -07:00
|
|
|
concurrent: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2023-01-11 18:36:04 -08:00
|
|
|
}
|
|
|
|
|
2025-05-12 09:40:16 -07:00
|
|
|
steps.push(new GroupStep(updateSteps));
|
|
|
|
|
2023-01-11 18:36:04 -08:00
|
|
|
// Generate third party licenses for bundles.
|
2025-05-07 09:54:26 -07:00
|
|
|
steps.push(new ProgramStep({
|
2023-01-11 18:36:04 -08:00
|
|
|
command: 'node',
|
|
|
|
args: [path.resolve(__dirname, '../generate_third_party_notice.js')],
|
|
|
|
shell: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2024-04-23 15:33:12 +01:00
|
|
|
|
|
|
|
// Build injected icons.
|
2025-05-07 09:54:26 -07:00
|
|
|
steps.push(new ProgramStep({
|
2024-04-23 15:33:12 +01:00
|
|
|
command: 'node',
|
|
|
|
args: ['utils/generate_clip_paths.js'],
|
|
|
|
shell: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2023-01-11 18:36:04 -08:00
|
|
|
|
2021-01-06 12:41:17 -08:00
|
|
|
// Build injected scripts.
|
2025-05-07 09:54:26 -07:00
|
|
|
steps.push(new ProgramStep({
|
2022-03-28 22:10:17 -08:00
|
|
|
command: 'node',
|
|
|
|
args: ['utils/generate_injected.js'],
|
|
|
|
shell: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2021-01-06 12:41:17 -08:00
|
|
|
|
2025-05-07 14:33:50 -07:00
|
|
|
class EsbuildStep extends Step {
|
|
|
|
/** @type {import('esbuild').BuildOptions} */
|
|
|
|
constructor(options) {
|
2025-05-08 08:29:01 -07:00
|
|
|
// Starting esbuild steps in parallel showed longer overall time.
|
|
|
|
super({ concurrent: false });
|
2025-05-07 14:33:50 -07:00
|
|
|
this._options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @override */
|
2025-05-08 08:29:01 -07:00
|
|
|
async run() {
|
2025-05-07 14:33:50 -07:00
|
|
|
if (watchMode) {
|
|
|
|
await this._ensureWatching();
|
|
|
|
} else {
|
2025-05-09 12:19:44 -07:00
|
|
|
console.log('==== Running esbuild:', this._relativeEntryPoints().join(', '));
|
2025-05-07 14:33:50 -07:00
|
|
|
const start = Date.now();
|
|
|
|
await build(this._options);
|
2025-05-08 08:29:01 -07:00
|
|
|
console.log('==== Done in', Date.now() - start, 'ms');
|
2025-05-07 14:33:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async _ensureWatching() {
|
|
|
|
const start = Date.now();
|
|
|
|
if (this._context)
|
|
|
|
return;
|
|
|
|
this._context = await context(this._options);
|
2025-05-09 17:01:03 +02:00
|
|
|
disposables.push(() => this._context?.dispose());
|
2025-05-07 14:33:50 -07:00
|
|
|
|
|
|
|
const watcher = chokidar.watch(this._options.entryPoints);
|
|
|
|
await new Promise(x => watcher.once('ready', x));
|
|
|
|
watcher.on('all', () => this._rebuild());
|
|
|
|
|
|
|
|
await this._rebuild();
|
2025-05-09 12:19:44 -07:00
|
|
|
console.log('==== Esbuild watching:', this._relativeEntryPoints().join(', '), `(started in ${Date.now() - start}ms)`);
|
2025-05-07 14:33:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
async _rebuild() {
|
|
|
|
if (this._rebuilding) {
|
|
|
|
this._sourcesChanged = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
this._sourcesChanged = false;
|
|
|
|
this._rebuilding = true;
|
2025-05-09 14:08:50 +02:00
|
|
|
try {
|
|
|
|
await this._context?.rebuild();
|
|
|
|
} catch (e) {
|
2025-05-09 14:40:02 -07:00
|
|
|
// Ignore. Esbuild inherits stderr and already logs nicely formatted errors
|
|
|
|
// before throwing.
|
2025-05-09 14:08:50 +02:00
|
|
|
}
|
|
|
|
|
2025-05-07 14:33:50 -07:00
|
|
|
this._rebuilding = false;
|
|
|
|
} while (this._sourcesChanged);
|
|
|
|
}
|
2025-05-09 12:19:44 -07:00
|
|
|
|
|
|
|
_relativeEntryPoints() {
|
|
|
|
return this._options.entryPoints.map(e => path.relative(ROOT, e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CustomCallbackStep extends Step {
|
|
|
|
constructor(callback) {
|
|
|
|
super({ concurrent: false });
|
|
|
|
this._callback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
async run() {
|
|
|
|
await this._callback();
|
|
|
|
}
|
2025-05-07 14:33:50 -07:00
|
|
|
}
|
|
|
|
|
2025-04-03 22:40:35 -07:00
|
|
|
// Run esbuild.
|
2022-02-08 11:35:00 -07:00
|
|
|
for (const pkg of workspace.packages()) {
|
|
|
|
if (!fs.existsSync(path.join(pkg.path, 'src')))
|
2021-10-11 10:52:17 -04:00
|
|
|
continue;
|
2025-05-12 19:22:14 -07:00
|
|
|
// playwright-client is built as a bundle.
|
|
|
|
if (['@playwright/client'].includes(pkg.name))
|
2025-04-02 11:31:15 +01:00
|
|
|
continue;
|
2025-05-07 14:33:50 -07:00
|
|
|
|
|
|
|
steps.push(new EsbuildStep({
|
|
|
|
entryPoints: [path.join(pkg.path, 'src/**/*.ts')],
|
|
|
|
outdir: `${path.join(pkg.path, 'lib')}`,
|
|
|
|
sourcemap: withSourceMaps ? 'linked' : false,
|
|
|
|
platform: 'node',
|
|
|
|
format: 'cjs',
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2023-01-11 18:36:04 -08:00
|
|
|
}
|
2022-04-18 12:47:23 -08:00
|
|
|
|
2025-05-12 19:22:14 -07:00
|
|
|
function copyXdgOpen() {
|
|
|
|
const outdir = filePath('packages/playwright-core/lib/utilsBundleImpl');
|
|
|
|
if (!fs.existsSync(outdir))
|
|
|
|
fs.mkdirSync(outdir, { recursive: true });
|
|
|
|
|
|
|
|
// 'open' package requires 'xdg-open' binary to be present, which does not get bundled by esbuild.
|
|
|
|
fs.copyFileSync(filePath('packages/playwright-core/bundles/utils/node_modules/open/xdg-open'), path.join(outdir, 'xdg-open'));
|
|
|
|
console.log('==== Copied xdg-open to', path.join(outdir, 'xdg-open'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy xdg-open after bundles 'npm ci' has finished.
|
|
|
|
steps.push(new CustomCallbackStep(copyXdgOpen));
|
|
|
|
|
2023-01-11 18:36:04 -08:00
|
|
|
// Build/watch bundles.
|
2025-05-12 19:22:14 -07:00
|
|
|
for (const bundle of bundles) {
|
|
|
|
/** @type {import('esbuild').BuildOptions} */
|
|
|
|
const options = {
|
|
|
|
bundle: true,
|
|
|
|
format: 'cjs',
|
|
|
|
platform: 'node',
|
|
|
|
target: 'ES2019',
|
|
|
|
sourcemap: watchMode,
|
|
|
|
minify: !watchMode,
|
|
|
|
|
|
|
|
entryPoints: bundle.entryPoints.map(e => path.join(filePath(bundle.modulePath), e)),
|
|
|
|
...(bundle.outdir ? { outdir: filePath(bundle.outdir) } : {}),
|
|
|
|
...(bundle.outfile ? { outfile: filePath(bundle.outfile) } : {}),
|
|
|
|
...(bundle.external ? { external: bundle.external } : {}),
|
|
|
|
...(bundle.minify !== undefined ? { minify: bundle.minify } : {}),
|
|
|
|
};
|
2025-05-09 12:19:44 -07:00
|
|
|
steps.push(new EsbuildStep(options));
|
2021-10-11 10:52:17 -04:00
|
|
|
}
|
|
|
|
|
2024-11-08 15:08:58 +01:00
|
|
|
// Build/watch trace viewer service worker.
|
2025-05-07 09:54:26 -07:00
|
|
|
steps.push(new ProgramStep({
|
2024-11-08 15:08:58 +01:00
|
|
|
command: 'npx',
|
|
|
|
args: [
|
|
|
|
'vite',
|
|
|
|
'--config',
|
|
|
|
'vite.sw.config.ts',
|
|
|
|
'build',
|
|
|
|
...(watchMode ? ['--watch', '--minify=false'] : []),
|
|
|
|
...(withSourceMaps ? ['--sourcemap=inline'] : []),
|
|
|
|
],
|
|
|
|
shell: true,
|
|
|
|
cwd: path.join(__dirname, '..', '..', 'packages', 'trace-viewer'),
|
|
|
|
concurrent: watchMode, // feeds into trace-viewer's `public` directory, so it needs to be finished before trace-viewer build starts
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2024-11-08 15:08:58 +01:00
|
|
|
|
2024-11-18 16:04:12 +01:00
|
|
|
if (watchMode) {
|
|
|
|
// the build above outputs into `packages/trace-viewer/public`, where the `vite build` for `packages/trace-viewer` is supposed to pick it up.
|
|
|
|
// there's a bug in `vite build --watch` though where the public dir is only copied over initially, but its not watched.
|
|
|
|
// to work around this, we run a second watch build of the service worker into the final output.
|
|
|
|
// bug: https://github.com/vitejs/vite/issues/18655
|
2025-05-07 09:54:26 -07:00
|
|
|
steps.push(new ProgramStep({
|
2024-11-18 16:04:12 +01:00
|
|
|
command: 'npx',
|
|
|
|
args: [
|
|
|
|
'vite', '--config', 'vite.sw.config.ts',
|
|
|
|
'build', '--watch', '--minify=false',
|
2024-11-19 10:02:41 +01:00
|
|
|
'--outDir', path.join(__dirname, '..', '..', 'packages', 'playwright-core', 'lib', 'vite', 'traceViewer'),
|
2025-05-09 14:40:02 -07:00
|
|
|
'--emptyOutDir=false',
|
|
|
|
'--clearScreen=false',
|
2024-11-18 16:04:12 +01:00
|
|
|
],
|
|
|
|
shell: true,
|
|
|
|
cwd: path.join(__dirname, '..', '..', 'packages', 'trace-viewer'),
|
|
|
|
concurrent: true
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2024-11-18 16:04:12 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 18:36:04 -08:00
|
|
|
// Build/watch web packages.
|
|
|
|
for (const webPackage of ['html-reporter', 'recorder', 'trace-viewer']) {
|
2025-05-07 09:54:26 -07:00
|
|
|
steps.push(new ProgramStep({
|
2023-01-11 18:36:04 -08:00
|
|
|
command: 'npx',
|
2023-07-31 13:53:28 -07:00
|
|
|
args: [
|
|
|
|
'vite',
|
|
|
|
'build',
|
|
|
|
...(watchMode ? ['--watch', '--minify=false'] : []),
|
2024-10-22 16:36:03 -07:00
|
|
|
...(withSourceMaps ? ['--sourcemap=inline'] : []),
|
2025-05-09 14:40:02 -07:00
|
|
|
'--clearScreen=false',
|
2023-07-31 13:53:28 -07:00
|
|
|
],
|
2023-01-11 18:36:04 -08:00
|
|
|
shell: true,
|
|
|
|
cwd: path.join(__dirname, '..', '..', 'packages', webPackage),
|
2023-02-23 11:46:20 -08:00
|
|
|
concurrent: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2023-01-11 18:36:04 -08:00
|
|
|
}
|
2022-04-18 10:31:58 -08:00
|
|
|
|
2024-11-08 15:08:58 +01:00
|
|
|
// web packages dev server
|
|
|
|
if (watchMode) {
|
2025-05-07 09:54:26 -07:00
|
|
|
steps.push(new ProgramStep({
|
2024-11-08 15:08:58 +01:00
|
|
|
command: 'npx',
|
2025-05-09 14:40:02 -07:00
|
|
|
args: ['vite', '--port', '44223', '--base', '/trace/', '--clearScreen=false'],
|
2024-11-08 15:08:58 +01:00
|
|
|
shell: true,
|
|
|
|
cwd: path.join(__dirname, '..', '..', 'packages', 'trace-viewer'),
|
|
|
|
concurrent: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
|
|
|
steps.push(new ProgramStep({
|
2024-11-12 11:11:50 +01:00
|
|
|
command: 'npx',
|
2025-05-09 14:40:02 -07:00
|
|
|
args: ['vite', '--port', '44224', '--clearScreen=false'],
|
2024-11-12 11:11:50 +01:00
|
|
|
shell: true,
|
|
|
|
cwd: path.join(__dirname, '..', '..', 'packages', 'html-reporter'),
|
|
|
|
concurrent: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
|
|
|
steps.push(new ProgramStep({
|
2024-11-18 18:23:29 +01:00
|
|
|
command: 'npx',
|
2025-05-09 14:40:02 -07:00
|
|
|
args: ['vite', '--port', '44225', '--clearScreen=false'],
|
2024-11-18 18:23:29 +01:00
|
|
|
shell: true,
|
|
|
|
cwd: path.join(__dirname, '..', '..', 'packages', 'recorder'),
|
|
|
|
concurrent: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2024-11-08 15:08:58 +01:00
|
|
|
}
|
2023-01-11 18:36:04 -08:00
|
|
|
|
2022-03-28 22:10:17 -08:00
|
|
|
// Generate injected.
|
|
|
|
onChanges.push({
|
|
|
|
inputs: [
|
2025-04-03 16:09:03 -07:00
|
|
|
'packages/injected/src/**',
|
2024-06-05 09:25:12 -07:00
|
|
|
'packages/playwright-core/src/third_party/**',
|
2024-01-17 20:43:28 -08:00
|
|
|
'packages/playwright-ct-core/src/injected/**',
|
2023-03-06 18:49:14 -08:00
|
|
|
'packages/playwright-core/src/utils/isomorphic/**',
|
2025-04-29 19:07:06 +00:00
|
|
|
'utils/generate_injected_builtins.js',
|
2022-03-28 22:10:17 -08:00
|
|
|
'utils/generate_injected.js',
|
|
|
|
],
|
|
|
|
script: 'utils/generate_injected.js',
|
|
|
|
});
|
2021-01-06 12:41:17 -08:00
|
|
|
|
|
|
|
// Generate channels.
|
|
|
|
onChanges.push({
|
|
|
|
inputs: [
|
2022-09-21 12:43:18 -07:00
|
|
|
'packages/protocol/src/protocol.yml'
|
2021-01-06 12:41:17 -08:00
|
|
|
],
|
|
|
|
script: 'utils/generate_channels.js',
|
|
|
|
});
|
|
|
|
|
|
|
|
// Generate types.
|
|
|
|
onChanges.push({
|
|
|
|
inputs: [
|
2021-01-07 13:26:34 -08:00
|
|
|
'docs/src/api/',
|
2021-07-29 14:33:47 -07:00
|
|
|
'docs/src/test-api/',
|
|
|
|
'docs/src/test-reporter-api/',
|
2021-01-06 12:41:17 -08:00
|
|
|
'utils/generate_types/overrides.d.ts',
|
2021-07-29 14:33:47 -07:00
|
|
|
'utils/generate_types/overrides-test.d.ts',
|
|
|
|
'utils/generate_types/overrides-testReporter.d.ts',
|
2021-01-06 12:41:17 -08:00
|
|
|
'utils/generate_types/exported.json',
|
2021-10-11 10:52:17 -04:00
|
|
|
'packages/playwright-core/src/server/chromium/protocol.d.ts',
|
2021-01-06 12:41:17 -08:00
|
|
|
],
|
2021-10-13 16:35:50 -04:00
|
|
|
mustExist: [
|
|
|
|
'packages/playwright-core/lib/server/deviceDescriptorsSource.json',
|
|
|
|
],
|
2021-01-06 12:41:17 -08:00
|
|
|
script: 'utils/generate_types/index.js',
|
|
|
|
});
|
|
|
|
|
2025-04-17 05:19:48 -07:00
|
|
|
if (installMode) {
|
|
|
|
// Keep browser installs up to date.
|
|
|
|
onChanges.push({
|
|
|
|
inputs: ['packages/playwright-core/browsers.json'],
|
|
|
|
command: 'npx',
|
|
|
|
args: ['playwright', 'install'],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-01 17:05:14 -07:00
|
|
|
// The recorder and trace viewer have an app_icon.png that needs to be copied.
|
2021-06-23 18:01:48 -07:00
|
|
|
copyFiles.push({
|
2021-10-11 10:52:17 -04:00
|
|
|
files: 'packages/playwright-core/src/server/chromium/*.png',
|
|
|
|
from: 'packages/playwright-core/src',
|
|
|
|
to: 'packages/playwright-core/lib',
|
2021-06-23 18:01:48 -07:00
|
|
|
});
|
|
|
|
|
2025-04-03 22:40:35 -07:00
|
|
|
// esbuild doesn't touch JS files, so copy them manually.
|
2021-06-23 18:01:48 -07:00
|
|
|
// For example: diff_match_patch.js
|
|
|
|
copyFiles.push({
|
2022-09-22 16:38:54 -04:00
|
|
|
files: 'packages/playwright-core/src/**/*.js',
|
2021-10-11 10:52:17 -04:00
|
|
|
from: 'packages/playwright-core/src',
|
|
|
|
to: 'packages/playwright-core/lib',
|
2023-08-19 16:16:44 -07:00
|
|
|
ignored: ['**/.eslintrc.js', '**/injected/**/*']
|
2021-01-31 16:37:13 -08:00
|
|
|
});
|
|
|
|
|
2025-04-03 22:40:35 -07:00
|
|
|
// Sometimes we require JSON files that esbuild ignores.
|
2021-06-23 18:01:48 -07:00
|
|
|
// For example, deviceDescriptorsSource.json
|
|
|
|
copyFiles.push({
|
2021-10-11 10:52:17 -04:00
|
|
|
files: 'packages/playwright-core/src/**/*.json',
|
2021-06-23 18:01:48 -07:00
|
|
|
ignored: ['**/injected/**/*'],
|
2021-10-11 10:52:17 -04:00
|
|
|
from: 'packages/playwright-core/src',
|
|
|
|
to: 'packages/playwright-core/lib',
|
2021-06-23 18:01:48 -07:00
|
|
|
});
|
|
|
|
|
2025-05-09 12:19:44 -07:00
|
|
|
if (watchMode) {
|
2022-03-25 13:12:00 -08:00
|
|
|
// Run TypeScript for type checking.
|
2025-05-07 09:54:26 -07:00
|
|
|
steps.push(new ProgramStep({
|
2021-06-23 18:01:48 -07:00
|
|
|
command: 'npx',
|
2025-05-09 14:40:02 -07:00
|
|
|
args: ['tsc', ...(watchMode ? ['-w'] : []), '--preserveWatchOutput', '-p', quotePath(filePath('.'))],
|
2021-06-23 18:01:48 -07:00
|
|
|
shell: true,
|
2023-02-23 11:46:20 -08:00
|
|
|
concurrent: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2022-03-28 17:21:19 -08:00
|
|
|
for (const webPackage of ['html-reporter', 'recorder', 'trace-viewer']) {
|
2025-05-07 09:54:26 -07:00
|
|
|
steps.push(new ProgramStep({
|
2022-03-28 17:21:19 -08:00
|
|
|
command: 'npx',
|
2025-05-09 14:40:02 -07:00
|
|
|
args: ['tsc', ...(watchMode ? ['-w'] : []), '--preserveWatchOutput', '-p', quotePath(filePath(`packages/${webPackage}`))],
|
2022-03-28 17:21:19 -08:00
|
|
|
shell: true,
|
2023-02-23 11:46:20 -08:00
|
|
|
concurrent: true,
|
2025-05-07 09:54:26 -07:00
|
|
|
}));
|
2022-03-28 17:21:19 -08:00
|
|
|
}
|
2021-06-23 18:01:48 -07:00
|
|
|
}
|
|
|
|
|
2025-05-09 17:01:03 +02:00
|
|
|
let cleanupCalled = false;
|
|
|
|
function cleanup() {
|
|
|
|
if (cleanupCalled)
|
|
|
|
return;
|
|
|
|
cleanupCalled = true;
|
|
|
|
for (const disposable of disposables) {
|
|
|
|
try {
|
|
|
|
disposable();
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Error during cleanup:', e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
process.on('exit', cleanup);
|
2025-05-09 18:06:00 +02:00
|
|
|
process.on('SIGINT', () => {
|
|
|
|
cleanup();
|
|
|
|
process.exit(0);
|
|
|
|
});
|
2025-05-09 17:01:03 +02:00
|
|
|
|
2021-01-06 12:41:17 -08:00
|
|
|
watchMode ? runWatch() : runBuild();
|