Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ const composeDtsConfig = async (
bundle: dts?.bundle ?? bundle,
distPath: dts?.distPath ?? output?.distPath?.root ?? './dist',
abortOnError: dts?.abortOnError ?? true,
dtsExtension,
dtsExtension: dts?.autoExtension ? dtsExtension : '.d.ts',
autoExternal,
banner: banner?.dts,
footer: footer?.dts,
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/types/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { RsbuildConfig } from '@rsbuild/core';
import type { PluginDtsOptions } from 'rsbuild-plugin-dts';

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

Expand Down Expand Up @@ -28,11 +29,9 @@ export type Syntax =
| string[];

export type Dts =
| {
bundle: boolean;
distPath?: string;
abortOnError?: boolean;
}
| (Pick<PluginDtsOptions, 'bundle' | 'distPath' | 'abortOnError'> & {
autoExtension?: boolean;
})
| false;

export type AutoExternal =
Expand Down
22 changes: 20 additions & 2 deletions tests/integration/dts/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

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

exports[`dts when bundle: true > basic 2`] = `
exports[`dts when bundle: true > basic 3`] = `
{
"cjs": "export declare const num1 = 1;

export declare const num2 = 2;

export declare const num3 = 3;

export declare const numSum: number;

export declare const str1 = "str1";

export declare const str2 = "str2";

export declare const str3 = "str3";

export declare const strSum: string;

export { }
",
"esm": "export declare const num1 = 1;

export declare const num2 = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
generateBundleCjsConfig({
bundle: false,
dts: {
autoExtension: true,
bundle: false,
},
}),
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/dts/bundle-false/basic/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default defineConfig({
}),
generateBundleCjsConfig({
bundle: false,
dts: {
bundle: false,
},
}),
],
source: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
generateBundleCjsConfig({
dts: {
bundle: true,
autoExtension: true,
},
}),
],
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/dts/bundle/basic/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export default defineConfig({
bundle: true,
},
}),
generateBundleCjsConfig(),
generateBundleCjsConfig({
dts: {
bundle: true,
},
}),
],
source: {
entry: {
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/dts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ describe('dts when bundle: false', () => {
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/esm/utils/strings.d.ts",
]
`);

expect(files.cjs).toMatchInlineSnapshot(`
[
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/cjs/index.d.ts",
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/cjs/sum.d.ts",
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/cjs/utils/numbers.d.ts",
"<ROOT>/tests/integration/dts/bundle-false/basic/dist/cjs/utils/strings.d.ts",
]
`);

expect(contents.esm).toMatchSnapshot();
});

Expand Down Expand Up @@ -72,6 +82,11 @@ describe('dts when bundle: true', () => {
expect(entryFiles.esm).toMatchInlineSnapshot(
`"<ROOT>/tests/integration/dts/bundle/basic/dist/esm/index.d.ts"`,
);

expect(entryFiles.cjs).toMatchInlineSnapshot(
`"<ROOT>/tests/integration/dts/bundle/basic/dist/cjs/index.d.ts"`,
);

expect(entries).toMatchSnapshot();
});

Expand Down
Loading