From 76dc18b7036c408e6fc5254e3eeb3430f65c7866 Mon Sep 17 00:00:00 2001 From: Jun <33900216+boqingren@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:41:44 +0800 Subject: [PATCH] fix: fix `experimentalDts` file cleaning and watching (#1199) --- src/api-extractor.ts | 6 +++--- src/index.ts | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/api-extractor.ts b/src/api-extractor.ts index 5255648c7..03ad339e5 100644 --- a/src/api-extractor.ts +++ b/src/api-extractor.ts @@ -136,9 +136,9 @@ async function rollupDtsFiles( } } -function cleanDtsFiles(options: NormalizedOptions) { +async function cleanDtsFiles(options: NormalizedOptions) { if (options.clean) { - removeFiles(['**/*.d.{ts,mts,cts}'], options.outDir) + await removeFiles(['**/*.d.{ts,mts,cts}'], options.outDir) } } @@ -156,7 +156,7 @@ export async function runDtsRollup( if (!exports) { throw new Error('Unexpected internal error: dts exports is not define') } - cleanDtsFiles(options) + await cleanDtsFiles(options) for (const format of options.format) { await rollupDtsFiles(options, exports, format) } diff --git a/src/index.ts b/src/index.ts index d6987881a..828bcd1ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -207,6 +207,13 @@ export async function build(_options: Options) { logger.info('CLI', 'Running in watch mode') } + const experimentalDtsTask = async () => { + if (!options.dts && options.experimentalDts) { + const exports = runTypeScriptCompiler(options); + await runDtsRollup(options, exports); + } + } + const dtsTask = async () => { if (options.dts && options.experimentalDts) { throw new Error( @@ -214,10 +221,7 @@ export async function build(_options: Options) { ) } - if (options.experimentalDts) { - const exports = runTypeScriptCompiler(options) - await runDtsRollup(options, exports) - } + experimentalDtsTask(); if (options.dts) { await new Promise((resolve, reject) => { @@ -351,6 +355,8 @@ export async function build(_options: Options) { }), ]) + experimentalDtsTask() + if (options.onSuccess) { if (typeof options.onSuccess === 'function') { onSuccessCleanup = await options.onSuccess()