normalize properly the modern config to ensure defaults even on scenarios of partial configs

This commit is contained in:
Nacho Codoñer
2025-04-30 13:15:34 +02:00
parent 4a232d10ef
commit df576c6604
2 changed files with 41 additions and 2 deletions

View File

@@ -97,6 +97,22 @@ function compileWithSwc(source, swcOptions = {}, { inputFilePath, features, arch
};
});
}
const DEFAULT_MODERN = {
transpiler: true,
};
const normalizeModern = r => Object.fromEntries(
Object.entries(DEFAULT_MODERN).map(([k, def]) => [
k,
r === true
? def
: r === false || r?.[k] === false
? false
: typeof r?.[k] === 'object'
? { ...r[k] }
: def,
]),
);
let lastModifiedMeteorConfig;
let lastModifiedMeteorConfigTime;
@@ -110,6 +126,10 @@ BCp.initializeMeteorAppConfig = function () {
if (currentLastModifiedConfigTime !== lastModifiedMeteorConfigTime) {
lastModifiedMeteorConfigTime = currentLastModifiedConfigTime;
lastModifiedMeteorConfig = getMeteorAppPackageJson()?.meteor;
lastModifiedMeteorConfig = {
...lastModifiedMeteorConfig,
modern: normalizeModern(lastModifiedMeteorConfig?.modern),
};
if (lastModifiedMeteorConfig?.modern?.transpiler?.verbose) {
logConfigBlock('Meteor Config', lastModifiedMeteorConfig);

View File

@@ -261,6 +261,25 @@ export function parseRunTargets(targets) {
});
};
const DEFAULT_MODERN = {
transpiler: true,
webArchsOnly: true,
watcher: true,
};
const normalizeModern = r => Object.fromEntries(
Object.entries(DEFAULT_MODERN).map(([k, def]) => [
k,
r === true
? def
: r === false || r?.[k] === false
? false
: typeof r?.[k] === 'object'
? { ...r[k] }
: def,
]),
);
function isModernArchsOnlyEnabled(appDir) {
const packageJsonPath = files.pathJoin(appDir, 'package.json');
if (!files.exists(packageJsonPath)) {
@@ -268,7 +287,7 @@ function isModernArchsOnlyEnabled(appDir) {
}
const packageJsonFile = files.readFile(packageJsonPath, 'utf8');
const packageJson = JSON.parse(packageJsonFile);
return packageJson?.meteor?.modern?.webArchsOnly === true || packageJson?.meteor?.modern === true;
return normalizeModern(packageJson?.meteor?.modern).webArchOnly === true;
}
function filterWebArchs(webArchs, excludeArchsOption, appDir, options) {
@@ -292,7 +311,7 @@ function filterWebArchs(webArchs, excludeArchsOption, appDir, options) {
const hasExcludeArchsOptions = (excludeArchsOptions?.length || 0) > 0;
const hasModernArchsOnlyEnabled = appDir && isModernArchsOnlyEnabled(appDir);
if (hasExcludeArchsOptions && hasModernArchsOnlyEnabled) {
console.warn('modernWebArchsOnly and --exclude-archs are both active. If both are set, --exclude-archs takes priority.');
console.warn('modern.webArchsOnly and --exclude-archs are both active. If both are set, --exclude-archs takes priority.');
}
const automaticallyIgnoredLegacyArchs = (!hasExcludeArchsOptions && hasModernArchsOnlyEnabled) ? ['web.browser.legacy', 'web.cordova'] : [];
if (hasExcludeArchsOptions || automaticallyIgnoredLegacyArchs.length) {