diff --git a/packages/solutions/module-tools/src/build.ts b/packages/solutions/module-tools/src/build.ts index 05419b09874a..7152fafba2f2 100644 --- a/packages/solutions/module-tools/src/build.ts +++ b/packages/solutions/module-tools/src/build.ts @@ -15,24 +15,38 @@ export const build = async ( const runner = api.useHookRunners(); - debug('normalize build config'); + debug('merge build config'); - const { normalizeBuildConfig } = await import('./config/normalize'); - const resolvedBuildConfig = await normalizeBuildConfig(api, context, options); + const { mergeBuildConfig, normalizeBuildConfig } = await import( + './config/normalize' + ); + const mergedConfig = await mergeBuildConfig(api); - debug('normalize build config done'); + debug('merge build config done'); - debug('normalizedBuildConfig', resolvedBuildConfig); + debug('mergedConfig', mergedConfig); debug('run beforeBuild hooks'); await runner.beforeBuild({ - config: resolvedBuildConfig, + config: mergedConfig, cliOptions: options, }); debug('run beforeBuild hooks done'); + debug('normalize build config'); + + const resolvedBuildConfig = await normalizeBuildConfig( + mergedConfig, + context, + options, + ); + + debug('normalize build config done'); + + debug('normalizedBuildConfig', resolvedBuildConfig); + const builder = await import('./builder'); await builder.run({ cmdOptions: options, resolvedBuildConfig, context }, api); }; diff --git a/packages/solutions/module-tools/src/config/normalize.ts b/packages/solutions/module-tools/src/config/normalize.ts index 62bb43eae645..3de83b029740 100644 --- a/packages/solutions/module-tools/src/config/normalize.ts +++ b/packages/solutions/module-tools/src/config/normalize.ts @@ -67,25 +67,10 @@ export const mergeConfig = ( }; export const normalizeBuildConfig = async ( - api: PluginAPI, + mergedConfig: PartialBaseBuildConfig[], context: ModuleContext, buildCmdOptions: BuildCommandOptions, ): Promise => { - let config = api.useConfigContext() as unknown as ModuleUserConfig; - - if (isLegacyUserConfig(config as { legacy?: boolean })) { - const { createUserConfigFromLegacy } = await import( - './transformLegacyConfig' - ); - config = await createUserConfigFromLegacy(config as ModuleLegacyUserConfig); - } - - const { buildConfig, buildPreset } = config; - - const configFromPreset = await presetToConfig(buildPreset); - - const mergedConfig = mergeConfig(configFromPreset, buildConfig ?? {}); - validPartialBuildConfig(mergedConfig, context.appDirectory); const normalizedConfig = await Promise.all( @@ -105,6 +90,27 @@ export const normalizeBuildConfig = async ( return normalizedConfig; }; +export const mergeBuildConfig = async ( + api: PluginAPI, +): Promise => { + let config = api.useConfigContext() as unknown as ModuleUserConfig; + + if (isLegacyUserConfig(config as { legacy?: boolean })) { + const { createUserConfigFromLegacy } = await import( + './transformLegacyConfig' + ); + config = await createUserConfigFromLegacy(config as ModuleLegacyUserConfig); + } + + const { buildConfig, buildPreset } = config; + + const configFromPreset = await presetToConfig(buildPreset); + + const mergedConfig = mergeConfig(configFromPreset, buildConfig ?? {}); + + return mergedConfig; +}; + export const transformToAbsPath = async ( baseConfig: BaseBuildConfig, options: { context: ModuleContext; buildCmdOptions: BuildCommandOptions }, diff --git a/packages/solutions/module-tools/src/hooks/build.ts b/packages/solutions/module-tools/src/hooks/build.ts index cc8a454c476d..729e37067ade 100644 --- a/packages/solutions/module-tools/src/hooks/build.ts +++ b/packages/solutions/module-tools/src/hooks/build.ts @@ -10,13 +10,13 @@ import type { BuildPlatformResult, WatchDtsHookContext, WatchJsHookContext, - BuildConfig, BaseBuildConfig, + PartialBaseBuildConfig, } from '../types'; export const buildHooks = { beforeBuild: createParallelWorkflow< - { config: BuildConfig; cliOptions: BuildCommandOptions }, + { config: PartialBaseBuildConfig[]; cliOptions: BuildCommandOptions }, void >(), beforeBuildTask: createAsyncWaterfall(),