Skip to content

Commit b191904

Browse files
committed
feat: add afterBootstrap hook
fix #326
1 parent ab64386 commit b191904

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,13 @@ export interface PluginOptions {
530530
*/
531531
declarationOnly?: boolean,
532532

533+
/**
534+
* Hook called after the runtime is created.
535+
*
536+
* @default () => {}
537+
*/
538+
afterBootstrap?: (runtime: Runtime) => MaybePromise<void>,
539+
533540
/**
534541
* Hook called after diagnostic is emitted.
535542
*

README.zh-CN.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ export interface PluginOptions {
547547
*/
548548
declarationOnly?: boolean,
549549

550+
/**
551+
* 运行时创建完毕后的钩子
552+
*
553+
* @default () => {}
554+
*/
555+
afterBootstrap?: (runtime: Runtime) => MaybePromise<void>,
556+
550557
/**
551558
* 获取诊断信息后的钩子
552559
*

packages/unplugin-dts/src/plugin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const pluginFactory: UnpluginFactory<PluginOptions | undefined> = /* #__P
4040
copyDtsFiles = meta.framework !== 'vite',
4141
declarationOnly = false,
4242
strictOutput = true,
43+
afterBootstrap,
4344
afterDiagnostic,
4445
beforeWriteFile,
4546
afterRollup,
@@ -214,6 +215,10 @@ export const pluginFactory: UnpluginFactory<PluginOptions | undefined> = /* #__P
214215
}
215216
}
216217

218+
if (typeof afterBootstrap === 'function') {
219+
await unwrapPromise(afterBootstrap(runtime))
220+
}
221+
217222
handleDebug('create ts program')
218223
timeRecord += Date.now() - startTime
219224
},

packages/unplugin-dts/src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import type {
66
MaybePromise,
77
Resolver,
88
RollupConfig,
9+
Runtime,
910
} from './core'
1011

11-
export type { Resolver, RollupConfig }
12+
export type { Resolver, RollupConfig, Runtime }
1213

1314
export interface PluginOptions
1415
extends Omit<
@@ -24,6 +25,12 @@ export interface PluginOptions
2425
* @default false
2526
*/
2627
declarationOnly?: boolean,
28+
/**
29+
* Hook called after the runtime is created.
30+
*
31+
* @default () => {}
32+
*/
33+
afterBootstrap?: (runtime: Runtime) => MaybePromise<void>,
2734
/**
2835
* Hook called after diagnostic is emitted.
2936
*

0 commit comments

Comments
 (0)