Skip to content

Commit

Permalink
fix(experimental-dts): don't clean .d.ts files when experimentalDts i…
Browse files Browse the repository at this point in the history
…s enabled
  • Loading branch information
ocavue committed Nov 20, 2023
1 parent 731f43f commit c6237b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -297,7 +297,7 @@ export async function build(_options: Options) {
: []
// .d.ts files are removed in the `dtsTask` instead
// `dtsTask` is a separate process, which might start before `mainTasks`
if (options.dts) {
if (options.dts || options.experimentalDts) {
extraPatterns.unshift('!**/*.d.{ts,cts,mts}')
}
await removeFiles(['**/*', ...extraPatterns], options.outDir)
Expand Down
33 changes: 33 additions & 0 deletions test/index.test.ts
Expand Up @@ -1668,3 +1668,36 @@ test('should only include exported declarations with experimentalDts', async ()
expect(entry2dts).toContain('declare2')
expect(entry2dts).not.toContain('declare1')
})

test('should only include exported declarations with experimentalDts', async () => {
const files = {
'package.json': `{ "name": "tsup-playground", "private": true }`,
'tsconfig.json': `{ "compilerOptions": { "skipLibCheck": true } }`,
'src/index.ts': `export const foo = 1`,
}
const withoutClean = await run(getTestName(), files, {
entry: ['src/index.ts'],
flags: ['--experimental-dts'],
})

const withClean = await run(getTestName(), files, {
entry: ['src/index.ts'],
flags: ['--experimental-dts', '--clean'],
})

expect(withoutClean.outFiles).toMatchInlineSnapshot(`
[
"_tsup-dts-rollup.d.ts",
"index.js",
"src/index.d.ts",
]
`)
expect(withClean.outFiles).toMatchInlineSnapshot(`
[
"_tsup-dts-rollup.d.ts",
"index.js",
"src/index.d.ts",
]
`)
expect(withClean.outFiles).toEqual(withoutClean.outFiles)
})

0 comments on commit c6237b8

Please sign in to comment.