Skip to content

Commit

Permalink
fix(bundling): fix esbuild build watch (nrwl#12448)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored and Jack Hsu committed Oct 6, 2022
1 parent 2405a2e commit 73a491a
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions packages/esbuild/src/executors/esbuild/esbuild.impl.ts
Expand Up @@ -57,46 +57,45 @@ export async function* esbuildExecutor(
options,
context
);
const result = await esbuild.build({
...esbuildOptions,
watch:
// Only emit info on one of the watch processes.
idx === 0
? {
onRebuild: async (
error: esbuild.BuildFailure,
result: esbuild.BuildResult
) => {
if (!options.skipTypeCheck) {
const { errors } = await runTypeCheck(
options,
context
);
hasTypeErrors = errors.length > 0;
}
const success = !error && !hasTypeErrors;

if (!success) {
logger.info(BUILD_WATCH_FAILED);
} else {
logger.info(BUILD_WATCH_SUCCEEDED);
}

next({
success: !!error && !hasTypeErrors,
outfile: esbuildOptions.outfile,
});
},
}
: true,
});

next({
success,
outfile: esbuildOptions.outfile,
});

return result;
const watch =
// Only emit info on one of the watch processes.
idx === 0
? {
onRebuild: async (
error: esbuild.BuildFailure,
result: esbuild.BuildResult
) => {
if (!options.skipTypeCheck) {
const { errors } = await runTypeCheck(options, context);
hasTypeErrors = errors.length > 0;
}
const success = !error && !hasTypeErrors;

if (!success) {
logger.info(BUILD_WATCH_FAILED);
} else {
logger.info(BUILD_WATCH_SUCCEEDED);
}

next({
success: !!error && !hasTypeErrors,
outfile: esbuildOptions.outfile,
});
},
}
: true;
try {
const result = await esbuild.build({ ...esbuildOptions, watch });

next({
success: true,
outfile: esbuildOptions.outfile,
});

return result;
} catch {
next({ success: false });
}
})
);
const processOnExit = () => {
Expand Down

0 comments on commit 73a491a

Please sign in to comment.