Skip to content

Commit

Permalink
feat: update rollup-plugin-dts to support custom tsconfig and preserv…
Browse files Browse the repository at this point in the history
…e export {} for file that have no exports (#807)

Co-authored-by: EGOIST <[email protected]>
close egoist/tsup#762
close egoist/tsup#791
  • Loading branch information
SeanZellmer authored Feb 12, 2025
1 parent f927d10 commit 7a7fcaa
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"postcss-simple-vars": "6.0.3",
"prettier": "2.5.1",
"resolve": "1.20.0",
"rollup-plugin-dts": "5.0.0",
"rollup-plugin-dts": "5.1.0",
"rollup-plugin-hashbang": "2.2.2",
"strip-json-comments": "4.0.0",
"svelte": "3.46.4",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const getRollupConfig = async (
jsonPlugin(),
ignoreFiles,
dtsPlugin.default({
tsconfig: options.tsconfig,
compilerOptions: {
...compilerOptions,
baseUrl: compilerOptions.baseUrl || '.',
Expand Down
55 changes: 55 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1191,4 +1191,59 @@ test('override target in tsconfig.json', async () => {
}
)
).rejects.toThrowError(`Top-level await is not available in the configured target environment ("es2018")`)
})

test(`custom tsconfig should pass to dts plugin`, async () => {
const { outFiles } = await run(
getTestName(),
{
'input.ts': `export const foo = { name: 'foo'}`,
'tsconfig.json': `{
"compilerOptions": {
"baseUrl":".",
"target": "esnext",
"incremental": true
}
}`,
'tsconfig.build.json': `{
"compilerOptions": {
"baseUrl":".",
"target": "esnext"
}
}`,
'tsup.config.ts': `
export default {
entry: ['src/input.ts'],
format: 'esm',
tsconfig: './tsconfig.build.json',
dts: {
only: true
}
}
`,
})
expect(outFiles).toEqual(['input.d.ts'])
})

test(`should generate export {} when there are no exports in source file`, async () => {
const { outFiles, getFileContent } = await run(
getTestName(),
{
'input.ts': `const a = 'a'`,
'tsconfig.json': `{
"compilerOptions": {
"baseUrl":".",
"target": "esnext",
}
}`,
'tsup.config.ts': `
export default {
entry: ['src/input.ts'],
format: 'esm',
dts: true
}
`,
})
expect(outFiles).toEqual(['input.d.ts', 'input.mjs'])
expect(await getFileContent('dist/input.d.ts')).toContain('export { }')
})

0 comments on commit 7a7fcaa

Please sign in to comment.