Skip to content

Commit 12e8d85

Browse files
committed
feat: add onSuccess function hook
1 parent 107dac1 commit 12e8d85

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function build(
3737
minify,
3838
watch,
3939
unused,
40+
onSuccess,
4041
} = resolved
4142

4243
if (clean) await cleanOutDir(outDir, clean)
@@ -96,6 +97,7 @@ export async function build(
9697
performance.now() - startTime,
9798
)}ms`,
9899
)
100+
await onSuccess?.()
99101
}
100102
}
101103

src/options.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface Options {
5252
options: OutputOptions,
5353
format: Format,
5454
) => MaybePromise<OutputOptions | void | null>)
55+
onSuccess?: () => void | Promise<void>
5556
}
5657

5758
/**
@@ -63,7 +64,12 @@ export type ResolvedOptions = Omit<
6364
Overwrite<
6465
MarkPartial<
6566
Options,
66-
'inputOptions' | 'outputOptions' | 'minify' | 'alias' | 'external'
67+
| 'inputOptions'
68+
| 'outputOptions'
69+
| 'minify'
70+
| 'alias'
71+
| 'external'
72+
| 'onSuccess'
6773
>,
6874
{ format: Format[]; clean: string[] | false }
6975
>,
@@ -96,6 +102,7 @@ export async function normalizeOptions(
96102
watch = false,
97103
inputOptions,
98104
outputOptions,
105+
onSuccess,
99106
} = options
100107

101108
entry = await resolveEntry(entry)
@@ -120,6 +127,7 @@ export async function normalizeOptions(
120127
watch,
121128
inputOptions,
122129
outputOptions,
130+
onSuccess,
123131
}
124132
}
125133

tsdown.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export default defineConfig({
77
platform: 'node',
88
dts: true,
99
unused: { level: 'error' },
10+
onSuccess() {
11+
console.info('🙏 Build succeeded!')
12+
},
1013

1114
// TODO
1215
// target: 'node18',

0 commit comments

Comments
 (0)