From 74bb75ce031844c87b8a6f89bc6207db4a5b106b Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Wed, 13 Oct 2021 16:35:50 -0400 Subject: [PATCH] chore: dont throw errors about deviceDescriptors.js on first watch (#9469) --- utils/build/build.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/utils/build/build.js b/utils/build/build.js index a6f3f7d4a5..69cd458c01 100644 --- a/utils/build/build.js +++ b/utils/build/build.js @@ -46,13 +46,17 @@ function filePath(relative) { return path.join(ROOT, ...relative.split('/')); } -function runWatch() { - function runOnChanges(paths, nodeFile) { +async function runWatch() { + function runOnChanges(paths, mustExist = [], nodeFile) { nodeFile = filePath(nodeFile); function callback() { + for (const fileMustExist of mustExist) { + if (!fs.existsSync(filePath(fileMustExist))) + return; + } child_process.spawnSync('node', [nodeFile], { stdio: 'inherit' }); } - chokidar.watch([...paths, nodeFile].map(filePath)).on('all', callback); + chokidar.watch([...paths, ...mustExist, nodeFile].map(filePath)).on('all', callback); callback(); } @@ -72,7 +76,7 @@ function runWatch() { })); process.on('exit', () => spawns.forEach(s => s.kill())); for (const onChange of onChanges) - runOnChanges(onChange.inputs, onChange.script); + runOnChanges(onChange.inputs, onChange.mustExist, onChange.script); } async function runBuild() { @@ -167,6 +171,10 @@ onChanges.push({ 'utils/generate_types/exported.json', 'packages/playwright-core/src/server/chromium/protocol.d.ts', ], + mustExist: [ + 'packages/playwright-core/lib/server/deviceDescriptors.js', + 'packages/playwright-core/lib/server/deviceDescriptorsSource.json', + ], script: 'utils/generate_types/index.js', });