chore: dont throw errors about deviceDescriptors.js on first watch (#9469)

This commit is contained in:
Joel Einbinder 2021-10-13 16:35:50 -04:00 committed by GitHub
parent cd99ad0da2
commit 74bb75ce03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,13 +46,17 @@ function filePath(relative) {
return path.join(ROOT, ...relative.split('/')); return path.join(ROOT, ...relative.split('/'));
} }
function runWatch() { async function runWatch() {
function runOnChanges(paths, nodeFile) { function runOnChanges(paths, mustExist = [], nodeFile) {
nodeFile = filePath(nodeFile); nodeFile = filePath(nodeFile);
function callback() { function callback() {
for (const fileMustExist of mustExist) {
if (!fs.existsSync(filePath(fileMustExist)))
return;
}
child_process.spawnSync('node', [nodeFile], { stdio: 'inherit' }); 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(); callback();
} }
@ -72,7 +76,7 @@ function runWatch() {
})); }));
process.on('exit', () => spawns.forEach(s => s.kill())); process.on('exit', () => spawns.forEach(s => s.kill()));
for (const onChange of onChanges) for (const onChange of onChanges)
runOnChanges(onChange.inputs, onChange.script); runOnChanges(onChange.inputs, onChange.mustExist, onChange.script);
} }
async function runBuild() { async function runBuild() {
@ -167,6 +171,10 @@ onChanges.push({
'utils/generate_types/exported.json', 'utils/generate_types/exported.json',
'packages/playwright-core/src/server/chromium/protocol.d.ts', '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', script: 'utils/generate_types/index.js',
}); });