Skip to content

Commit f83baf8

Browse files
authored
fix(dts): ensure chunks conform to bundle format (#1034)
1 parent 51b5a00 commit f83baf8

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

src/rollup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ const getRollupConfig = async (
165165
banner: dtsOptions.banner,
166166
footer: dtsOptions.footer,
167167
entryFileNames: `[name]${outputExtension}`,
168+
chunkFileNames: `[name]-[hash]${outputExtension}`,
168169
plugins: [
169170
format === 'cjs' && options.cjsInterop && fixCjsExport,
170171
].filter(Boolean),

test/index.test.ts

+87
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,93 @@ test('should emit a declaration file per format (type: module)', async () => {
13981398
])
13991399
})
14001400

1401+
test('should emit dts chunks per format', async () => {
1402+
const { outFiles } = await run(
1403+
getTestName(),
1404+
{
1405+
'src/input1.ts': `
1406+
import type { InternalType } from './shared.js'
1407+
1408+
export function getValue(value: InternalType) {
1409+
return value;
1410+
}
1411+
`,
1412+
'src/input2.ts': `
1413+
import type { InternalType } from './shared.js'
1414+
1415+
export function getValue(value: InternalType) {
1416+
return value;
1417+
}
1418+
`,
1419+
'src/shared.ts': `export type InternalType = 'foo'`,
1420+
'tsup.config.ts': `
1421+
export default {
1422+
entry: ['./src/input1.ts', './src/input2.ts'],
1423+
format: ['esm', 'cjs'],
1424+
dts: true
1425+
}`,
1426+
},
1427+
{ entry: [] }
1428+
)
1429+
expect(outFiles).toEqual([
1430+
'input1.d.mts',
1431+
'input1.d.ts',
1432+
'input1.js',
1433+
'input1.mjs',
1434+
'input2.d.mts',
1435+
'input2.d.ts',
1436+
'input2.js',
1437+
'input2.mjs',
1438+
'shared-qBqaX8Tr.d.mts',
1439+
'shared-qBqaX8Tr.d.ts',
1440+
])
1441+
})
1442+
1443+
test('should emit dts chunks per format (type: module)', async () => {
1444+
const { outFiles } = await run(
1445+
getTestName(),
1446+
{
1447+
'src/input1.ts': `
1448+
import type { InternalType } from './shared.js'
1449+
1450+
export function getValue(value: InternalType) {
1451+
return value;
1452+
}
1453+
`,
1454+
'src/input2.ts': `
1455+
import type { InternalType } from './shared.js'
1456+
1457+
export function getValue(value: InternalType) {
1458+
return value;
1459+
}
1460+
`,
1461+
'src/shared.ts': `export type InternalType = 'foo'`,
1462+
'tsup.config.ts': `
1463+
export default {
1464+
entry: ['./src/input1.ts', './src/input2.ts'],
1465+
format: ['esm', 'cjs'],
1466+
dts: true
1467+
}`,
1468+
'package.json': `{
1469+
"type": "module"
1470+
}`,
1471+
},
1472+
{ entry: [] }
1473+
)
1474+
expect(outFiles).toEqual([
1475+
'input1.cjs',
1476+
'input1.d.cts',
1477+
'input1.d.ts',
1478+
'input1.js',
1479+
'input2.cjs',
1480+
'input2.d.cts',
1481+
'input2.d.ts',
1482+
'input2.js',
1483+
'shared-qBqaX8Tr.d.cts',
1484+
'shared-qBqaX8Tr.d.ts',
1485+
])
1486+
})
1487+
14011488
test('should emit declaration files with experimentalDts', async () => {
14021489
const files = {
14031490
'package.json': `

0 commit comments

Comments
 (0)