@@ -44,9 +44,10 @@ function resolveJsOutputExtension(
4444}
4545
4646export function resolveChunkFilename (
47- { outExtensions, fixedExtension, pkg, hash } : ResolvedConfig ,
47+ { outExtensions, fixedExtension, pkg, hash, dts } : ResolvedConfig ,
4848 inputOptions : InputOptions ,
4949 format : NormalizedFormat ,
50+ cjsDts : boolean ,
5051) : [ entry : ChunkFileName , chunk : ChunkFileName ] {
5152 const packageType = getPackageType ( pkg )
5253
@@ -66,13 +67,23 @@ export function resolveChunkFilename(
6667
6768 jsExtension ??= `.${ resolveJsOutputExtension ( packageType , format , fixedExtension ) } `
6869
70+ // Every chunk is a declaration in dts-only builds, but entry chunk names no
71+ // longer end with `.d`, so the extension can't be inferred from the name.
72+ // User dts-only options only apply to the ESM pass, which has the dts plugin.
73+ const dtsOnly =
74+ cjsDts ||
75+ ( format === 'es' &&
76+ ! ! dts &&
77+ ! ! ( dts . dtsOnly || dts . emitDtsOnly || dts . dtsInput ) )
78+
6979 const suffix = format === 'iife' || format === 'umd' ? `.${ format } ` : ''
7080 return [
71- createChunkFilename ( `[name]${ suffix } ` , jsExtension , dtsExtension ) ,
81+ createChunkFilename ( `[name]${ suffix } ` , jsExtension , dtsExtension , dtsOnly ) ,
7282 createChunkFilename (
7383 `[name]${ suffix } ${ hash ? '-[hash]' : '' } ` ,
7484 jsExtension ,
7585 dtsExtension ,
86+ dtsOnly ,
7687 ) ,
7788 ]
7889}
@@ -82,8 +93,10 @@ function createChunkFilename(
8293 basename : string ,
8394 jsExtension : string ,
8495 dtsExtension ?: string ,
96+ dtsOnly ?: boolean ,
8597) : ChunkFileName {
8698 if ( dtsExtension === undefined ) return `${ basename } ${ jsExtension } `
99+ if ( dtsOnly ) return `${ basename } ${ dtsExtension } `
87100 return ( chunk : PreRenderedChunk ) => {
88101 return `${ basename } ${ chunk . name . endsWith ( '.d' ) ? dtsExtension : jsExtension } `
89102 }
0 commit comments