Skip to content

Commit 621a30d

Browse files
authored
fix: handle empty string outExtensions (#494)
1 parent f26e0c7 commit 621a30d

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/features/output.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function resolveChunkFilename(
5858
dtsExtension = dts
5959
}
6060

61-
jsExtension ||= `.${resolveJsOutputExtension(packageType, format, fixedExtension)}`
61+
jsExtension ??= `.${resolveJsOutputExtension(packageType, format, fixedExtension)}`
6262

6363
const suffix = format === 'iife' || format === 'umd' ? `.${format}` : ''
6464
return [
@@ -77,7 +77,7 @@ function createChunkFilename(
7777
jsExtension: string,
7878
dtsExtension?: string,
7979
): ChunkFileName {
80-
if (!dtsExtension) return `${basename}${jsExtension}`
80+
if (dtsExtension === undefined) return `${basename}${jsExtension}`
8181
return (chunk: PreRenderedChunk) => {
8282
return `${basename}${chunk.name.endsWith('.d') ? dtsExtension : jsExtension}`
8383
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## index
2+
3+
```
4+
//#region index.ts
5+
var custom_extension_with_empty_string_default = 10;
6+
7+
//#endregion
8+
export { custom_extension_with_empty_string_default as default };
9+
```
10+
## index.d
11+
12+
```d
13+
//#region index.d.ts
14+
var _default = [0];
15+
16+
//#endregion
17+
export { _default as default };
18+
```

tests/index.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,26 @@ test('custom extension', async (context) => {
124124
`)
125125
})
126126

127+
test('custom extension with empty string', async (context) => {
128+
const files = {
129+
'index.ts': `export default 10`,
130+
}
131+
const { outputFiles } = await testBuild({
132+
context,
133+
files,
134+
options: {
135+
dts: true,
136+
outExtensions: () => ({ js: '', dts: '' }),
137+
},
138+
})
139+
expect(outputFiles).toMatchInlineSnapshot(`
140+
[
141+
"index",
142+
"index.d",
143+
]
144+
`)
145+
})
146+
127147
test('noExternal', async (context) => {
128148
const files = {
129149
'index.ts': `export * from 'cac'`,

0 commit comments

Comments
 (0)