Skip to content

Commit 3024834

Browse files
committed
fix: don't add . when autoAddExts is disabled
1 parent 7d49728 commit 3024834

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

src/core/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ export function guessSuffix(id: string, resolved: string): string {
6969
.extname(resolved)
7070
.slice(1)
7171
.replace(/^([cm]?)ts/, (_, $1) => `${$1}js`)
72-
suffix += `.${ext}`
72+
if (ext) suffix += `.${ext}`
7373
return suffix
7474
}

tests/__snapshots__/rollup.test.ts.snap

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`rollup > autoAddExts 1`] = `
4+
"// main.js
5+
function Component() {
6+
return /* @__PURE__ */ React.createElement("div", null, "I'm a div in a tsx component!");
7+
}
8+
9+
function hello(s) {
10+
return "hello" + s;
11+
}
12+
let c = Component;
13+
let num = 1;
14+
15+
export { c, hello, num };
16+
17+
// temp/component.d.ts
18+
export declare function Component(): React.JSX.Element;
19+
20+
// temp/main.d.ts
21+
import { type Num } from '../temp/types.js';
22+
export type Str = string;
23+
export declare function hello(s: Str): Str;
24+
export declare let c: React.JSX.Element;
25+
export declare let num: Num;
26+
27+
// temp/types.d.ts
28+
import type { Num2 } from '../temp/types2.js';
29+
export type Num = Num2;
30+
31+
// temp/types2.d.ts
32+
export type Num2 = number;
33+
"
34+
`;
35+
336
exports[`rollup > custom rewriter 1`] = `
437
"// index.d.ts
538
export type * from './test.js';
@@ -30,14 +63,14 @@ export { c, hello, num };
3063
export declare function Component(): React.JSX.Element;
3164
3265
// temp/main.d.ts
33-
import { type Num } from '../temp/types.js';
66+
import { type Num } from '../temp/types';
3467
export type Str = string;
3568
export declare function hello(s: Str): Str;
3669
export declare let c: React.JSX.Element;
3770
export declare let num: Num;
3871
3972
// temp/types.d.ts
40-
import type { Num2 } from '../temp/types2.js';
73+
import type { Num2 } from '../temp/types2';
4174
export type Num = Num2;
4275
4376
// temp/types2.d.ts

tests/rollup.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ describe('rollup', () => {
1515
const dir = 'basic'
1616
const input = path.resolve(fixtures, dir, 'main.ts')
1717

18+
const bundle = await rollup({
19+
input,
20+
plugins: [UnpluginIsolatedDecl({ extraOutdir: 'temp' }), esbuild()],
21+
logLevel: 'silent',
22+
})
23+
const result = await bundle.generate({})
24+
25+
expect(outputToSnapshot(result.output)).toMatchSnapshot()
26+
})
27+
28+
test('autoAddExts', async () => {
29+
const dir = 'basic'
30+
const input = path.resolve(fixtures, dir, 'main.ts')
31+
1832
const bundle = await rollup({
1933
input,
2034
plugins: [

0 commit comments

Comments
 (0)