Skip to content

Commit b9d85fe

Browse files
authored
fix: Fix errors not being propagated in watch mode (#380) (#381)
- closes #380
1 parent d999100 commit b9d85fe

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,34 @@ const createBundler = (esBuildUserOptions = {}) => {
8080
const customBuildPlugin = {
8181
name: 'cypress-esbuild-watch-plugin',
8282
setup(build) {
83-
build.onEnd(result => {
83+
build.onEnd((result) => {
84+
if (result.errors.length > 0) {
85+
debug(
86+
'watch on %s build failed, errors %o',
87+
filePath,
88+
result.errors,
89+
)
90+
91+
bundled[filePath] = new Promise((resolve, reject) => {
92+
esbuild
93+
.formatMessages(result.errors, {
94+
kind: 'error',
95+
color: false,
96+
})
97+
.then((messages) => reject(new Error(messages.join('\n\n'))))
98+
})
99+
100+
file.emit('rerun')
101+
return
102+
}
103+
84104
debug(
85105
'watch on %s build succeeded, warnings %o',
86106
filePath,
87107
result.warnings,
88108
)
89109
file.emit('rerun')
90-
});
110+
})
91111
},
92112
}
93113
const plugins = esBuildOptions.plugins ? [...esBuildOptions.plugins, customBuildPlugin] : [customBuildPlugin];

0 commit comments

Comments
 (0)