Skip to content

Commit 4db2046

Browse files
authored
feat: add abort controller for onSuccess (#282)
1 parent d08fcd0 commit 4db2046

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export async function buildSingle(
9999
clean: () => Promise<void>,
100100
): Promise<(() => Promise<void>) | undefined> {
101101
const { format: formats, dts, watch, onSuccess } = config
102-
let onSuccessCleanup: (() => any) | undefined
102+
let ab: AbortController | undefined
103103

104104
const { hooks, context } = await createHooks(config)
105105

@@ -112,7 +112,7 @@ export async function buildSingle(
112112
const startTime = performance.now()
113113

114114
await hooks.callHook('build:prepare', context)
115-
onSuccessCleanup?.()
115+
ab?.abort()
116116

117117
await clean()
118118

@@ -165,19 +165,19 @@ export async function buildSingle(
165165
prettyName(config.name),
166166
`${first ? 'Build' : 'Rebuild'} complete in ${green(`${Math.round(performance.now() - startTime)}ms`)}`,
167167
)
168-
168+
ab = new AbortController()
169169
if (typeof onSuccess === 'string') {
170170
const p = exec(onSuccess, [], {
171171
nodeOptions: { shell: true, stdio: 'inherit' },
172+
signal: ab.signal,
172173
})
173174
p.then(({ exitCode }) => {
174175
if (exitCode) {
175176
process.exitCode = exitCode
176177
}
177178
})
178-
onSuccessCleanup = () => p.kill('SIGTERM')
179179
} else {
180-
await onSuccess?.(config)
180+
await onSuccess?.(config, ab.signal)
181181
}
182182
}
183183
}

src/options/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export interface Options {
228228
/**
229229
* You can specify command to be executed after a successful build, specially useful for Watch mode
230230
*/
231-
onSuccess?: string | ((config: ResolvedOptions) => void | Promise<void>)
231+
onSuccess?: string | ((config: ResolvedOptions, signal: AbortSignal) => void | Promise<void>)
232232

233233
/**
234234
* Skip bundling `node_modules`.

0 commit comments

Comments
 (0)