From 5a8ff00e388851949918ee24d19e32b3d5c3a643 Mon Sep 17 00:00:00 2001 From: ckohen Date: Thu, 16 Nov 2023 00:27:25 -0800 Subject: [PATCH 1/2] fix(dts): ensure chunks conform to bundle format --- src/rollup.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rollup.ts b/src/rollup.ts index 35fdea1e1..be82f5d83 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -207,6 +207,7 @@ const getRollupConfig = async ( banner: dtsOptions.banner, footer: dtsOptions.footer, entryFileNames: `[name]${outputExtension}`, + chunkFileNames: `[name]-[hash]${outputExtension}`, plugins: [ format === 'cjs' && options.cjsInterop && fixCjsExport, ].filter(Boolean), From ebfd61232bc8292fdbd098d7630fa6c78afeb46e Mon Sep 17 00:00:00 2001 From: ckohen Date: Fri, 17 Nov 2023 17:28:50 -0800 Subject: [PATCH 2/2] test: add tests for dts chunks --- test/index.test.ts | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index 0228d643a..63254fefd 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1375,6 +1375,93 @@ test('should emit a declaration file per format (type: module)', async () => { ]) }) +test('should emit dts chunks per format', async () => { + const { outFiles } = await run( + getTestName(), + { + 'src/input1.ts': ` + import type { InternalType } from './shared.js' + + export function getValue(value: InternalType) { + return value; + } + `, + 'src/input2.ts': ` + import type { InternalType } from './shared.js' + + export function getValue(value: InternalType) { + return value; + } + `, + 'src/shared.ts': `export type InternalType = 'foo'`, + 'tsup.config.ts': ` + export default { + entry: ['./src/input1.ts', './src/input2.ts'], + format: ['esm', 'cjs'], + dts: true + }`, + }, + { entry: [] } + ) + expect(outFiles).toEqual([ + 'input1.d.mts', + 'input1.d.ts', + 'input1.js', + 'input1.mjs', + 'input2.d.mts', + 'input2.d.ts', + 'input2.js', + 'input2.mjs', + 'shared-qBqaX8Tr.d.mts', + 'shared-qBqaX8Tr.d.ts', + ]) +}) + +test('should emit dts chunks per format (type: module)', async () => { + const { outFiles } = await run( + getTestName(), + { + 'src/input1.ts': ` + import type { InternalType } from './shared.js' + + export function getValue(value: InternalType) { + return value; + } + `, + 'src/input2.ts': ` + import type { InternalType } from './shared.js' + + export function getValue(value: InternalType) { + return value; + } + `, + 'src/shared.ts': `export type InternalType = 'foo'`, + 'tsup.config.ts': ` + export default { + entry: ['./src/input1.ts', './src/input2.ts'], + format: ['esm', 'cjs'], + dts: true + }`, + 'package.json': `{ + "type": "module" + }`, + }, + { entry: [] } + ) + expect(outFiles).toEqual([ + 'input1.cjs', + 'input1.d.cts', + 'input1.d.ts', + 'input1.js', + 'input2.cjs', + 'input2.d.cts', + 'input2.d.ts', + 'input2.js', + 'shared-qBqaX8Tr.d.cts', + 'shared-qBqaX8Tr.d.ts', + ]) +}) + test('should emit declaration files with experimentalDts', async () => { const files = { 'package.json': `