Skip to content

Commit a6ab280

Browse files
fix: don't abort previous package's onSuccess in workspace builds (#118)
1 parent 68cb2fb commit a6ab280

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

packages/bunup/src/build.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,14 @@ import { cleanOutDir, getFilesFromGlobs, isJavascriptFile } from "./utils/file";
4747
import { formatListWithAnd } from "./utils/format";
4848
import { cleanPath } from "./utils/path";
4949

50-
let ac: AbortController | null = null;
51-
5250
export async function build(
5351
userOptions: Partial<BuildOptions>,
5452
rootDir: string = process.cwd(),
53+
ac?: AbortController,
5554
): Promise<BuildResult> {
5655
ensureMinimumBunVersion();
5756

58-
if (ac) {
59-
ac.abort();
60-
}
61-
62-
ac = new AbortController();
57+
const localAc = ac ?? new AbortController();
6358

6459
const options = resolveBuildOptions(userOptions);
6560

@@ -221,17 +216,22 @@ export async function build(
221216
!options.compile
222217
) {
223218
try {
224-
const { entry, splitting, resolve: userDtsResolve, ...dtsOptions } =
225-
typeof options.dts === "object" ? options.dts : {};
219+
const {
220+
entry,
221+
splitting,
222+
resolve: userDtsResolve,
223+
...dtsOptions
224+
} = typeof options.dts === "object" ? options.dts : {};
226225

227226
const bundledDeps = getBundledDepsForDtsResolve(options, packageJson.data);
228-
const dtsResolve = userDtsResolve === false
229-
? false
230-
: !bundledDeps?.length
231-
? userDtsResolve
232-
: userDtsResolve === true
233-
? true
234-
: [...bundledDeps, ...(Array.isArray(userDtsResolve) ? userDtsResolve : [])];
227+
const dtsResolve =
228+
userDtsResolve === false
229+
? false
230+
: !bundledDeps?.length
231+
? userDtsResolve
232+
: userDtsResolve === true
233+
? true
234+
: [...bundledDeps, ...(Array.isArray(userDtsResolve) ? userDtsResolve : [])];
235235

236236
const dtsResult = await generateDts(ensureArray(entry ?? entrypoints), {
237237
cwd: rootDir,
@@ -301,7 +301,7 @@ export async function build(
301301
});
302302

303303
if (options.onSuccess) {
304-
await executeOnSuccess(options.onSuccess, options, ac.signal);
304+
await executeOnSuccess(options.onSuccess, options, localAc.signal);
305305
}
306306

307307
logger.log("");

packages/bunup/src/watch.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export async function watch(
4040
let isRebuilding = false;
4141
let buildCount = 0;
4242
let lastChangedFile: string | undefined;
43+
let ac: AbortController | null = null;
4344

4445
const triggerRebuild = async (initial: boolean, changed?: string) => {
4546
if (isRebuilding) {
@@ -68,9 +69,15 @@ export async function watch(
6869
);
6970
}
7071

72+
if (ac) {
73+
ac.abort();
74+
}
75+
76+
ac = new AbortController();
77+
7178
const start = performance.now();
7279

73-
const buildResult = await build(userOptions, rootDir);
80+
const buildResult = await build(userOptions, rootDir, ac);
7481

7582
await printBuildReport(buildResult);
7683

packages/bunup/test/bunup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { defineConfig } from "../src";
22

33
export default defineConfig({
44
entry: ["fixtures/main.ts"],
5-
noExternal: ["ora"]
5+
noExternal: ["ora"],
66
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { type Color } from "ora";
22

3-
export type {Color};
3+
export type { Color };

0 commit comments

Comments
 (0)