From 23b720b2ecb5642c7ccaecac14cddb8492cd6a45 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Sat, 21 Jun 2025 21:25:34 +0200 Subject: [PATCH] Prevent `yarn watch` to exit if TypeScript plugin is unable to compile --- bin/build_package.js | 15 ++++++++++----- bin/rollup.js | 5 +++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/build_package.js b/bin/build_package.js index ed83b079a82..01bcf80c436 100644 --- a/bin/build_package.js +++ b/bin/build_package.js @@ -22,6 +22,7 @@ const args = parseArgs({ async function main() { const packageRoot = path.resolve(process.cwd(), args.positionals[0]); + const isWatch = args.values.watch || false; if (!fs.existsSync(packageRoot)) { console.error(`The package directory "${packageRoot}" does not exist.`); @@ -86,9 +87,9 @@ async function main() { process.exit(1); } - const rollupConfig = getRollupConfiguration({ packageRoot, inputFiles: inputScriptFiles }); + const rollupConfig = getRollupConfiguration({ packageRoot, inputFiles: inputScriptFiles, isWatch }); - if (args.values.watch) { + if (isWatch) { console.log( `Watching for JavaScript${inputStyleFile ? ' and CSS' : ''} files modifications in "${srcDir}" directory...` ); @@ -103,9 +104,13 @@ async function main() { } const watcher = rollup.watch(rollupConfig); - watcher.on('event', ({ result }) => { - if (result) { - result.close(); + watcher.on('event', (event) => { + if (event.code === 'ERROR') { + console.error('Error during build:', event.error); + } + + if (event.result) { + event.result.close(); } }); watcher.on('change', async (id, { event }) => { diff --git a/bin/rollup.js b/bin/rollup.js index e002bd414b4..62b0010457b 100644 --- a/bin/rollup.js +++ b/bin/rollup.js @@ -72,8 +72,9 @@ const moveTypescriptDeclarationsPlugin = (packageRoot) => ({ /** * @param {String} packageRoot * @param {Array} inputFiles + * @param {Boolean} isWatch */ -function getRollupConfiguration({ packageRoot, inputFiles }) { +function getRollupConfiguration({ packageRoot, inputFiles, isWatch }) { const packagePath = path.join(packageRoot, 'package.json'); const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8')); const peerDependencies = [ @@ -108,7 +109,7 @@ function getRollupConfiguration({ packageRoot, inputFiles }) { typescript({ filterRoot: '.', tsconfig: path.join(__dirname, '..', 'tsconfig.json'), - noEmitOnError: true, + noEmitOnError: !isWatch, include: [ 'src/**/*.ts', // TODO: Remove for the next major release