From 874aa58e35d7e81ae4c89a5a02ec8ba3256912ea Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Thu, 13 Feb 2025 13:38:57 +0100 Subject: [PATCH 1/2] fix: normalize the configs at the end --- .../common/config/makeCompilerConfig.ts | 20 ++++++++--- .../commands/common/config/normalizeConfig.ts | 35 +++++++------------ 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/packages/repack/src/commands/common/config/makeCompilerConfig.ts b/packages/repack/src/commands/common/config/makeCompilerConfig.ts index d3f3d9668..84e117c37 100644 --- a/packages/repack/src/commands/common/config/makeCompilerConfig.ts +++ b/packages/repack/src/commands/common/config/makeCompilerConfig.ts @@ -47,17 +47,27 @@ export async function makeCompilerConfig( // load the project config const rawConfig = await loadProjectConfig(configPath); - // normalize config to ensure it's a static config object - const normalizedConfigs = await Promise.all( + // inject env and create platform-specific configs + const projectConfigs: C[] = await Promise.all( options.platforms.map((platform) => { - return normalizeConfig(rawConfig, { ...env, platform }); + // eval the config and inject the platform + if (typeof rawConfig === 'function') { + return rawConfig({ ...env, platform }, {}); + } + // shallow copy to avoid mutating the original config + return { ...rawConfig }; }) ); // merge in reverse order to create final configs - const configs = normalizedConfigs.map((config) => + const configs = projectConfigs.map((config) => merge([repackConfig, commandConfig, config, cliConfigOverrides]) ); - return configs as C[]; + // normalize the configs + const normalizedConfigs = configs.map((config, index) => + normalizeConfig(config, options.platforms[index]) + ); + + return normalizedConfigs as C[]; } diff --git a/packages/repack/src/commands/common/config/normalizeConfig.ts b/packages/repack/src/commands/common/config/normalizeConfig.ts index a957b3171..475827f93 100644 --- a/packages/repack/src/commands/common/config/normalizeConfig.ts +++ b/packages/repack/src/commands/common/config/normalizeConfig.ts @@ -1,5 +1,4 @@ -import type { EnvOptions } from '../../../types.js'; -import type { Configuration, ConfigurationObject } from '../../types.js'; +import type { ConfigurationObject } from '../../types.js'; function normalizeDevServerHost(host?: string): string | undefined { switch (host) { @@ -14,33 +13,23 @@ function normalizeDevServerHost(host?: string): string | undefined { } } -export async function normalizeConfig( - config: Configuration, - env: EnvOptions -): Promise { - /* normalize the config into object */ - let configObject: C; - if (typeof config === 'function') { - configObject = await config(env, {}); - } else { - /* shallow copy to avoid mutating the original config */ - configObject = { ...config }; - } - +export function normalizeConfig( + config: C, + platform: string +): C { /* normalize compiler name to be equal to platform */ - configObject.name = env.platform; + config.name = platform; /* normalize dev server host by resolving special values */ - if (configObject.devServer) { - configObject.devServer.host = normalizeDevServerHost( - configObject.devServer.host - ); + if (config.devServer) { + config.devServer.host = normalizeDevServerHost(config.devServer.host); } + /* unset public path if it's using the deprecated `getPublicPath` function */ - if (configObject.output?.publicPath === 'DEPRECATED_GET_PUBLIC_PATH') { - configObject.output.publicPath = undefined; + if (config.output?.publicPath === 'DEPRECATED_GET_PUBLIC_PATH') { + config.output.publicPath = undefined; } /* return the normalized config object */ - return configObject; + return config; } From 1330947bae84ddb32f33165a8316c9b999bfb91b Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Thu, 13 Feb 2025 13:44:49 +0100 Subject: [PATCH 2/2] chore: changeset --- .changeset/large-kids-kneel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/large-kids-kneel.md diff --git a/.changeset/large-kids-kneel.md b/.changeset/large-kids-kneel.md new file mode 100644 index 000000000..7f7b629ce --- /dev/null +++ b/.changeset/large-kids-kneel.md @@ -0,0 +1,5 @@ +--- +"@callstack/repack": patch +--- + +Normalize the configs after merging them with the defaults and CLI overrides