@@ -841,6 +841,7 @@ const composeExternalsConfig = (
841841
842842const composeAutoExtensionConfig = (
843843 config : LibConfig ,
844+ format : Format ,
844845 autoExtension : boolean ,
845846 pkgJson ?: PkgJson ,
846847) : {
@@ -849,7 +850,7 @@ const composeAutoExtensionConfig = (
849850 dtsExtension : string ;
850851} => {
851852 const { jsExtension, dtsExtension } = getDefaultExtension ( {
852- format : config . format ! ,
853+ format,
853854 pkgJson,
854855 autoExtension,
855856 } ) ;
@@ -1307,9 +1308,10 @@ const composeBundlelessExternalConfig = (
13071308
13081309const composeDtsConfig = async (
13091310 libConfig : LibConfig ,
1311+ format : Format ,
13101312 dtsExtension : string ,
13111313) : Promise < EnvironmentConfig > => {
1312- const { format , autoExternal, banner, footer, redirect } = libConfig ;
1314+ const { autoExternal, banner, footer, redirect } = libConfig ;
13131315
13141316 let { dts } = libConfig ;
13151317
@@ -1332,7 +1334,7 @@ const composeDtsConfig = async (
13321334 build : dts ?. build ,
13331335 abortOnError : dts ?. abortOnError ,
13341336 dtsExtension : dts ?. autoExtension ? dtsExtension : '.d.ts' ,
1335- autoExternal : getAutoExternalDefaultValue ( format ! , autoExternal ) ,
1337+ autoExternal : getAutoExternalDefaultValue ( format , autoExternal ) ,
13361338 banner : banner ?. dts ,
13371339 footer : footer ?. dts ,
13381340 redirect : redirect ?. dts ,
@@ -1454,7 +1456,7 @@ async function composeLibRsbuildConfig(
14541456 const cssModulesAuto = config . output ?. cssModules ?. auto ?? true ;
14551457
14561458 const {
1457- format,
1459+ format = 'esm' ,
14581460 shims,
14591461 bundle = true ,
14601462 banner = { } ,
@@ -1466,11 +1468,11 @@ async function composeLibRsbuildConfig(
14661468 umdName,
14671469 } = config ;
14681470 const { rsbuildConfig : shimsConfig , enabledShims } = composeShimsConfig (
1469- format ! ,
1471+ format ,
14701472 shims ,
14711473 ) ;
14721474 const formatConfig = composeFormatConfig ( {
1473- format : format ! ,
1475+ format : format ,
14741476 pkgJson : pkgJson ! ,
14751477 bundle,
14761478 umdName,
@@ -1480,14 +1482,14 @@ async function composeLibRsbuildConfig(
14801482 pkgJson ,
14811483 ) ;
14821484 const userExternalsConfig = composeExternalsConfig (
1483- format ! ,
1485+ format ,
14841486 config . output ?. externals ,
14851487 ) ;
14861488 const {
14871489 config : autoExtensionConfig ,
14881490 jsExtension,
14891491 dtsExtension,
1490- } = composeAutoExtensionConfig ( config , autoExtension , pkgJson ) ;
1492+ } = composeAutoExtensionConfig ( config , format , autoExtension , pkgJson ) ;
14911493 const { entryConfig, outBase } = await composeEntryConfig (
14921494 config . source ?. entry ! ,
14931495 config . bundle ,
@@ -1506,11 +1508,11 @@ async function composeLibRsbuildConfig(
15061508 config : targetConfig ,
15071509 externalsConfig : targetExternalsConfig ,
15081510 target,
1509- } = composeTargetConfig ( config . output ?. target , format ! ) ;
1511+ } = composeTargetConfig ( config . output ?. target , format ) ;
15101512 const syntaxConfig = composeSyntaxConfig ( target , config ?. syntax ) ;
15111513 const autoExternalConfig = composeAutoExternalConfig ( {
15121514 bundle,
1513- format : format ! ,
1515+ format : format ,
15141516 autoExternal,
15151517 pkgJson,
15161518 userExternals : config . output ?. externals ,
@@ -1522,15 +1524,15 @@ async function composeLibRsbuildConfig(
15221524 banner ?. css ,
15231525 footer ?. css ,
15241526 ) ;
1525- const assetConfig = composeAssetConfig ( bundle , format ! ) ;
1527+ const assetConfig = composeAssetConfig ( bundle , format ) ;
15261528
15271529 const entryChunkConfig = composeEntryChunkConfig ( {
15281530 enabledImportMetaUrlShim : enabledShims . cjs [ 'import.meta.url' ] ,
15291531 contextToWatch : outBase ,
15301532 } ) ;
1531- const dtsConfig = await composeDtsConfig ( config , dtsExtension ) ;
1533+ const dtsConfig = await composeDtsConfig ( config , format , dtsExtension ) ;
15321534 const externalsWarnConfig = composeExternalsWarnConfig (
1533- format ! ,
1535+ format ,
15341536 userExternalsConfig ?. output ?. externals ,
15351537 autoExternalConfig ?. output ?. externals ,
15361538 ) ;
@@ -1619,7 +1621,7 @@ export async function composeCreateRsbuildConfig(
16191621 delete userConfig . output . externals ;
16201622
16211623 const config : RsbuildConfigWithLibInfo = {
1622- format : libConfig . format ! ,
1624+ format : libConfig . format ?? 'esm' ,
16231625 // The merge order represents the priority of the configuration
16241626 // The priorities from high to low are as follows:
16251627 // 1 - userConfig: users can configure any Rsbuild and Rspack config
0 commit comments