diff --git a/packages/babel-compiler/babel-compiler.js b/packages/babel-compiler/babel-compiler.js index 3bb046af8e..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); @@ -277,7 +297,7 @@ BCp.processOneFileForTarget = function (inputFile, source) { const config = lastModifiedMeteorConfig?.modern?.transpiler; const hasModernTranspiler = - lastModifiedMeteorConfig?.modern?.transpiler === true || + lastModifiedMeteorConfig?.modern?.transpiler !== false || lastModifiedMeteorConfig?.modern === true; const shouldSkipSwc = !hasModernTranspiler || diff --git a/tools/cli/commands.js b/tools/cli/commands.js index 017dbab8d6..73fa0715c8 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, + ]), +); + let meteorConfig; function getMeteorConfig(appDir) { @@ -277,12 +296,12 @@ function getMeteorConfig(appDir) { function isModernArchsOnlyEnabled(appDir) { const meteorConfig = getMeteorConfig(appDir); - return meteorConfig?.modern?.webArchsOnly === true || meteorConfig?.modern === true; + return normalizeModern(meteorConfig?.modern).webArchOnly === true; } export function isModernWatcherEnabled(appDir) { const meteorConfig = getMeteorConfig(appDir); - return meteorConfig?.modern?.watcher === true || meteorConfig?.modern === true; + return normalizeModern(meteorConfig?.modern).watcher === true; } function filterWebArchs(webArchs, excludeArchsOption, appDir, options) { @@ -306,7 +325,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) {