mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore(build): fix MaxListenersExceededWarning during build (#35905)
This commit is contained in:
parent
d3a67559e8
commit
64c553bb71
@ -57,6 +57,8 @@ const { build, context } = require('esbuild');
|
||||
* @typedef {CommandOnChange|ScriptOnChange} OnChange
|
||||
*/
|
||||
|
||||
/** @type {(() => void)[]} */
|
||||
const disposables = [];
|
||||
/** @type {Step[]} */
|
||||
const steps = [];
|
||||
/** @type {OnChange[]} */
|
||||
@ -130,7 +132,10 @@ class ProgramStep extends Step {
|
||||
},
|
||||
cwd: step.cwd,
|
||||
});
|
||||
process.on('exit', () => child.kill());
|
||||
disposables.push(() => {
|
||||
if (child.exitCode === null)
|
||||
child.kill();
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
child.on('close', (code, signal) => {
|
||||
if (code || signal)
|
||||
@ -299,6 +304,7 @@ class EsbuildStep extends Step {
|
||||
if (this._context)
|
||||
return;
|
||||
this._context = await context(this._options);
|
||||
disposables.push(() => this._context?.dispose());
|
||||
|
||||
const watcher = chokidar.watch(this._options.entryPoints);
|
||||
await new Promise(x => watcher.once('ready', x));
|
||||
@ -540,4 +546,20 @@ if (lintMode) {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
process.on('SIGINT', cleanup);
|
||||
|
||||
watchMode ? runWatch() : runBuild();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user