From 4741fd5e55fcaddcccea552192c404e519452de7 Mon Sep 17 00:00:00 2001 From: adamscybot Date: Wed, 6 Mar 2024 17:41:36 +0000 Subject: [PATCH] Fix errors not being propagated in watch mode (#380) --- src/index.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index e3a3aa0..ab50c75 100644 --- a/src/index.js +++ b/src/index.js @@ -80,14 +80,34 @@ const createBundler = (esBuildUserOptions = {}) => { const customBuildPlugin = { name: 'cypress-esbuild-watch-plugin', setup(build) { - build.onEnd(result => { + build.onEnd((result) => { + if (result.errors.length > 0) { + debug( + 'watch on %s build failed, errors %o', + filePath, + result.errors, + ) + + bundled[filePath] = new Promise((resolve, reject) => { + esbuild + .formatMessages(result.errors, { + kind: 'error', + color: false, + }) + .then((messages) => reject(new Error(messages.join('\n\n')))) + }) + + file.emit('rerun') + return + } + debug( 'watch on %s build succeeded, warnings %o', filePath, result.warnings, ) file.emit('rerun') - }); + }) }, } const plugins = esBuildOptions.plugins ? [...esBuildOptions.plugins, customBuildPlugin] : [customBuildPlugin];