Skip to content

Commit

Permalink
fix: fix experimentalDts file cleaning and watching (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
boqingren authored Sep 17, 2024
1 parent ec811b3 commit 76dc18b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/api-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
Expand Down
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,21 @@ 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(
"You can't use both `dts` and `experimentalDts` at the same time",
)
}

if (options.experimentalDts) {
const exports = runTypeScriptCompiler(options)
await runDtsRollup(options, exports)
}
experimentalDtsTask();

if (options.dts) {
await new Promise<void>((resolve, reject) => {
Expand Down Expand Up @@ -351,6 +355,8 @@ export async function build(_options: Options) {
}),
])

experimentalDtsTask()

if (options.onSuccess) {
if (typeof options.onSuccess === 'function') {
onSuccessCleanup = await options.onSuccess()
Expand Down

0 comments on commit 76dc18b

Please sign in to comment.