File tree Expand file tree Collapse file tree 6 files changed +89
-3
lines changed
type-commonjs/config-override
type-module/config-override Expand file tree Collapse file tree 6 files changed +89
-3
lines changed Original file line number Diff line number Diff line change @@ -33,3 +33,23 @@ describe('autoExtension: false', () => {
33
33
expect ( extname ( entryFiles . cjs ! ) ) . toEqual ( '.js' ) ;
34
34
} ) ;
35
35
} ) ;
36
+
37
+ describe ( 'should respect output.filename.js to override builtin logic' , ( ) => {
38
+ test ( 'type is commonjs' , async ( ) => {
39
+ const fixturePath = join ( __dirname , 'type-commonjs' , 'config-override' ) ;
40
+ const { entryFiles } = await buildAndGetResults ( fixturePath ) ;
41
+ expect ( extname ( entryFiles . esm ! ) ) . toEqual ( '.mjs' ) ;
42
+ expect ( entryFiles . cjs ) . toMatchInlineSnapshot (
43
+ `"<ROOT>/e2e/cases/auto-extension/type-commonjs/config-override/dist/cjs/index.babf05f8.js"` ,
44
+ ) ;
45
+ } ) ;
46
+
47
+ test ( 'type is module' , async ( ) => {
48
+ const fixturePath = join ( __dirname , 'type-module' , 'config-override' ) ;
49
+ const { entryFiles } = await buildAndGetResults ( fixturePath ) ;
50
+ expect ( entryFiles . esm ) . toMatchInlineSnapshot (
51
+ `"<ROOT>/e2e/cases/auto-extension/type-module/config-override/dist/esm/index.4ca64135.js"` ,
52
+ ) ;
53
+ expect ( extname ( entryFiles . cjs ! ) ) . toEqual ( '.cjs' ) ;
54
+ } ) ;
55
+ } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " auto-extension-config-override-commonjs-test" ,
3
+ "version" : " 1.0.0" ,
4
+ "private" : true
5
+ }
Original file line number Diff line number Diff line change
1
+ import { generateBundleCjsConfig , generateBundleEsmConfig } from '@e2e/helper' ;
2
+ import { defineConfig } from '@rslib/core' ;
3
+
4
+ export default defineConfig ( {
5
+ lib : [
6
+ generateBundleEsmConfig ( {
7
+ autoExtension : false ,
8
+ output : {
9
+ filename : {
10
+ js : '[name].mjs' ,
11
+ } ,
12
+ } ,
13
+ } ) ,
14
+ generateBundleCjsConfig ( {
15
+ output : {
16
+ filename : {
17
+ js : '[name].[contenthash:8].js' ,
18
+ } ,
19
+ } ,
20
+ } ) ,
21
+ ] ,
22
+ source : {
23
+ entry : {
24
+ index : '../../__fixtures__/src/index.ts' ,
25
+ } ,
26
+ } ,
27
+ } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " auto-extension-config-override-module-test" ,
3
+ "version" : " 1.0.0" ,
4
+ "private" : true ,
5
+ "type" : " module"
6
+ }
Original file line number Diff line number Diff line change
1
+ import { generateBundleCjsConfig , generateBundleEsmConfig } from '@e2e/helper' ;
2
+ import { defineConfig } from '@rslib/core' ;
3
+
4
+ export default defineConfig ( {
5
+ lib : [
6
+ generateBundleEsmConfig ( {
7
+ output : {
8
+ filename : {
9
+ js : '[name].[contenthash:8].js' ,
10
+ } ,
11
+ } ,
12
+ } ) ,
13
+ generateBundleCjsConfig ( {
14
+ autoExtension : false ,
15
+ output : {
16
+ filename : {
17
+ js : '[name].cjs' ,
18
+ } ,
19
+ } ,
20
+ } ) ,
21
+ ] ,
22
+ source : {
23
+ entry : {
24
+ index : '../../__fixtures__/src/index.ts' ,
25
+ } ,
26
+ } ,
27
+ } ) ;
Original file line number Diff line number Diff line change @@ -240,7 +240,7 @@ const composeFormatConfig = (format: Format): RsbuildConfig => {
240
240
} ;
241
241
242
242
const composeAutoExtensionConfig = (
243
- format : Format ,
243
+ config : LibConfig ,
244
244
autoExtension : boolean ,
245
245
pkgJson ?: PkgJson ,
246
246
) : {
@@ -249,7 +249,7 @@ const composeAutoExtensionConfig = (
249
249
dtsExtension : string ;
250
250
} => {
251
251
const { jsExtension, dtsExtension } = getDefaultExtension ( {
252
- format,
252
+ format : config . format ! ,
253
253
pkgJson,
254
254
autoExtension,
255
255
} ) ;
@@ -259,6 +259,7 @@ const composeAutoExtensionConfig = (
259
259
output : {
260
260
filename : {
261
261
js : `[name]${ jsExtension } ` ,
262
+ ...config . output ?. filename ,
262
263
} ,
263
264
} ,
264
265
} ,
@@ -494,7 +495,7 @@ async function composeLibRsbuildConfig(
494
495
config : autoExtensionConfig ,
495
496
jsExtension,
496
497
dtsExtension,
497
- } = composeAutoExtensionConfig ( format ! , autoExtension , pkgJson ) ;
498
+ } = composeAutoExtensionConfig ( config , autoExtension , pkgJson ) ;
498
499
const bundleConfig = composeBundleConfig ( jsExtension , config . bundle ) ;
499
500
const targetConfig = composeTargetConfig ( config . output ?. target ) ;
500
501
const syntaxConfig = composeSyntaxConfig (
You can’t perform that action at this time.
0 commit comments