Skip to content

Commit da085ae

Browse files
authored
Update to esbuild 0.17 (#52238)
1 parent 10c7c45 commit da085ae

File tree

3 files changed

+213
-192
lines changed

3 files changed

+213
-192
lines changed

Herebyfile.mjs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async function runDtsBundler(entrypoint, output) {
163163
* @typedef BundlerTaskOptions
164164
* @property {boolean} [exportIsTsObject]
165165
* @property {boolean} [treeShaking]
166-
* @property {esbuild.WatchMode} [watchMode]
166+
* @property {() => void} [onWatchRebuild]
167167
*/
168168
function createBundler(entrypoint, outfile, taskOptions = {}) {
169169
const getOptions = memoize(async () => {
@@ -220,7 +220,30 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
220220

221221
return {
222222
build: async () => esbuild.build(await getOptions()),
223-
watch: async () => esbuild.build({ ...await getOptions(), watch: taskOptions.watchMode ?? true, logLevel: "info" }),
223+
watch: async () => {
224+
/** @type {esbuild.BuildOptions} */
225+
const options = { ...await getOptions(), logLevel: "info" };
226+
if (taskOptions.onWatchRebuild) {
227+
const onRebuild = taskOptions.onWatchRebuild;
228+
options.plugins = (options.plugins?.slice(0) ?? []).concat([{
229+
name: "watch",
230+
setup: (build) => {
231+
let firstBuild = true;
232+
build.onEnd(() => {
233+
if (firstBuild) {
234+
firstBuild = false;
235+
}
236+
else {
237+
onRebuild();
238+
}
239+
});
240+
}
241+
}]);
242+
}
243+
244+
const ctx = await esbuild.context(options);
245+
ctx.watch();
246+
},
224247
};
225248
}
226249

@@ -426,10 +449,8 @@ const { main: tests, watch: watchTests } = entrypointBuildTask({
426449
bundlerOptions: {
427450
// Ensure we never drop any dead code, which might be helpful while debugging.
428451
treeShaking: false,
429-
watchMode: {
430-
onRebuild() {
431-
watchTestsEmitter.emit("rebuild");
432-
}
452+
onWatchRebuild() {
453+
watchTestsEmitter.emit("rebuild");
433454
}
434455
},
435456
});

0 commit comments

Comments
 (0)