Skip to content

Commit c8c1726

Browse files
authored
fix(dts): disable autoExtension for dts by default (#264)
1 parent 15be6b3 commit c8c1726

File tree

8 files changed

+50
-9
lines changed

8 files changed

+50
-9
lines changed

packages/core/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ const composeDtsConfig = async (
746746
bundle: dts?.bundle ?? bundle,
747747
distPath: dts?.distPath ?? output?.distPath?.root ?? './dist',
748748
abortOnError: dts?.abortOnError ?? true,
749-
dtsExtension,
749+
dtsExtension: dts?.autoExtension ? dtsExtension : '.d.ts',
750750
autoExternal,
751751
banner: banner?.dts,
752752
footer: footer?.dts,

packages/core/src/types/config/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { RsbuildConfig } from '@rsbuild/core';
2+
import type { PluginDtsOptions } from 'rsbuild-plugin-dts';
23

34
export type Format = 'esm' | 'cjs' | 'umd';
45

@@ -28,11 +29,9 @@ export type Syntax =
2829
| string[];
2930

3031
export type Dts =
31-
| {
32-
bundle: boolean;
33-
distPath?: string;
34-
abortOnError?: boolean;
35-
}
32+
| (Pick<PluginDtsOptions, 'bundle' | 'distPath' | 'abortOnError'> & {
33+
autoExtension?: boolean;
34+
})
3635
| false;
3736

3837
export type AutoExternal =

tests/integration/dts/__snapshots__/index.test.ts.snap

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

3-
exports[`dts when bundle: false > basic 2`] = `
3+
exports[`dts when bundle: false > basic 3`] = `
44
{
55
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/esm/index.d.ts": "export * from './utils/numbers';
66
export * from './utils/strings';
@@ -20,8 +20,26 @@ export declare const str3 = "str3";
2020
}
2121
`;
2222

23-
exports[`dts when bundle: true > basic 2`] = `
23+
exports[`dts when bundle: true > basic 3`] = `
2424
{
25+
"cjs": "export declare const num1 = 1;
26+
27+
export declare const num2 = 2;
28+
29+
export declare const num3 = 3;
30+
31+
export declare const numSum: number;
32+
33+
export declare const str1 = "str1";
34+
35+
export declare const str2 = "str2";
36+
37+
export declare const str3 = "str3";
38+
39+
export declare const strSum: string;
40+
41+
export { }
42+
",
2543
"esm": "export declare const num1 = 1;
2644
2745
export declare const num2 = 2;

tests/integration/dts/bundle-false/auto-extension/rslib.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default defineConfig({
99
generateBundleCjsConfig({
1010
bundle: false,
1111
dts: {
12+
autoExtension: true,
1213
bundle: false,
1314
},
1415
}),

tests/integration/dts/bundle-false/basic/rslib.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export default defineConfig({
1111
}),
1212
generateBundleCjsConfig({
1313
bundle: false,
14+
dts: {
15+
bundle: false,
16+
},
1417
}),
1518
],
1619
source: {

tests/integration/dts/bundle/auto-extension/rslib.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default defineConfig({
77
generateBundleCjsConfig({
88
dts: {
99
bundle: true,
10+
autoExtension: true,
1011
},
1112
}),
1213
],

tests/integration/dts/bundle/basic/rslib.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export default defineConfig({
88
bundle: true,
99
},
1010
}),
11-
generateBundleCjsConfig(),
11+
generateBundleCjsConfig({
12+
dts: {
13+
bundle: true,
14+
},
15+
}),
1216
],
1317
source: {
1418
entry: {

tests/integration/dts/index.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ describe('dts when bundle: false', () => {
1515
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/esm/utils/strings.d.ts",
1616
]
1717
`);
18+
19+
expect(files.cjs).toMatchInlineSnapshot(`
20+
[
21+
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/cjs/index.d.ts",
22+
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/cjs/sum.d.ts",
23+
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/cjs/utils/numbers.d.ts",
24+
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/cjs/utils/strings.d.ts",
25+
]
26+
`);
27+
1828
expect(contents.esm).toMatchSnapshot();
1929
});
2030

@@ -72,6 +82,11 @@ describe('dts when bundle: true', () => {
7282
expect(entryFiles.esm).toMatchInlineSnapshot(
7383
`"<ROOT>/tests/integration/dts/bundle/basic/dist/esm/index.d.ts"`,
7484
);
85+
86+
expect(entryFiles.cjs).toMatchInlineSnapshot(
87+
`"<ROOT>/tests/integration/dts/bundle/basic/dist/cjs/index.d.ts"`,
88+
);
89+
7590
expect(entries).toMatchSnapshot();
7691
});
7792

0 commit comments

Comments
 (0)