From df576c66047ebf1b6f22b89101bdf93d90ac8bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Wed, 30 Apr 2025 13:15:34 +0200 Subject: [PATCH] normalize properly the modern config to ensure defaults even on scenarios of partial configs --- packages/babel-compiler/babel-compiler.js | 20 ++++++++++++++++++++ tools/cli/commands.js | 23 +++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/packages/babel-compiler/babel-compiler.js b/packages/babel-compiler/babel-compiler.js index 28b679ab49..0a592c3ec6 100644 --- a/packages/babel-compiler/babel-compiler.js +++ b/packages/babel-compiler/babel-compiler.js @@ -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); diff --git a/tools/cli/commands.js b/tools/cli/commands.js index ed2ece09db..3bb3c72de4 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -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) {