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
5 changes: 5 additions & 0 deletions .changeset/large-kids-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Normalize the configs after merging them with the defaults and CLI overrides
20 changes: 15 additions & 5 deletions packages/repack/src/commands/common/config/makeCompilerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,27 @@ export async function makeCompilerConfig<C extends ConfigurationObject>(
// load the project config
const rawConfig = await loadProjectConfig<C>(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[];
}
35 changes: 12 additions & 23 deletions packages/repack/src/commands/common/config/normalizeConfig.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -14,33 +13,23 @@ function normalizeDevServerHost(host?: string): string | undefined {
}
}

export async function normalizeConfig<C extends ConfigurationObject>(
config: Configuration<C>,
env: EnvOptions
): Promise<C> {
/* 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<C extends ConfigurationObject>(
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;
}