Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix experimentalDts file cleaning and watching #1199

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading