From 2bf3b1300cfd6971901aea95e8e5c4b0d96f12be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Wed, 14 May 2025 10:50:35 +0200 Subject: [PATCH 1/8] ensure get meteor config only returns proper filtered config --- tools/project-context.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/project-context.js b/tools/project-context.js index 0dce0164eb..23d3ba50f2 100644 --- a/tools/project-context.js +++ b/tools/project-context.js @@ -1819,14 +1819,16 @@ export class MeteorConfig { // TODO Implement an API for setting these values? get(...keys) { let config = this._ensureInitialized(); + let filteredConfig = keys.length ? undefined : config; if (config) { keys.every(key => { if (config && _.has(config, key)) { - config = config[key]; + filteredConfig = config[key]; return true; } + return false; }); - return config; + return filteredConfig; } } @@ -1908,6 +1910,8 @@ export class MeteorConfig { _getEntryModulesByArch(...keys) { const configEntryModule = this.get(...keys); + console.log("--> (project-context.js-Line: 1911)\n configEntryModule: ", configEntryModule); + console.log("--> (project-context.js-Line: 1911)\n keys: ", keys); const entryModulesByArch = Object.create(null); if (typeof configEntryModule === "string" || @@ -1927,6 +1931,7 @@ export class MeteorConfig { }); } + console.log("--> (project-context.js-Line: 1931)\n entryModulesByArch: ", entryModulesByArch); return entryModulesByArch; } @@ -1936,9 +1941,13 @@ export class MeteorConfig { ) { const entryMatch = archinfo.mostSpecificMatch( arch, Object.keys(entryModulesByArch)); + // console.log("--> (project-context.js-Line: 1939)\n archinfo: ", archinfo); + // console.log("--> (project-context.js-Line: 1939)\n Object.keys(entryModulesByArch): ", Object.keys(entryModulesByArch)); if (entryMatch) { const entryModule = entryModulesByArch[entryMatch]; + console.log("--> (project-context.js-Line: 1944)\n entryModulesByArch: ", entryModulesByArch); + console.log("--> (project-context.js-Line: 1942)\n entryModule: ", entryModule); if (entryModule === false) { // If meteor.{main,test}Module.{client,server,...} === false, no @@ -1967,6 +1976,7 @@ export class MeteorConfig { "./" + files.pathNormalize(entryModule), this.packageJsonPath ); + console.log("--> (project-context.js-Line: 1970)\n res: ", res); if (res && typeof res === "object") { return files.pathRelative(this.appDirectory, res.path); From 1b293c26dbf8b8af776887a4314872da182c0ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Wed, 14 May 2025 10:55:30 +0200 Subject: [PATCH 2/8] ensure get meteor config only returns proper filtered config --- tools/project-context.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/project-context.js b/tools/project-context.js index 23d3ba50f2..53ab02b915 100644 --- a/tools/project-context.js +++ b/tools/project-context.js @@ -1819,7 +1819,7 @@ export class MeteorConfig { // TODO Implement an API for setting these values? get(...keys) { let config = this._ensureInitialized(); - let filteredConfig = keys.length ? undefined : config; + let filteredConfig = keys.length ? {} : config; if (config) { keys.every(key => { if (config && _.has(config, key)) { From fd04f1473e4fc9d01b3ab074ce6d90e3bc874d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Wed, 14 May 2025 10:57:23 +0200 Subject: [PATCH 3/8] clean --- tools/project-context.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tools/project-context.js b/tools/project-context.js index 53ab02b915..c14dce5cfa 100644 --- a/tools/project-context.js +++ b/tools/project-context.js @@ -1910,8 +1910,6 @@ export class MeteorConfig { _getEntryModulesByArch(...keys) { const configEntryModule = this.get(...keys); - console.log("--> (project-context.js-Line: 1911)\n configEntryModule: ", configEntryModule); - console.log("--> (project-context.js-Line: 1911)\n keys: ", keys); const entryModulesByArch = Object.create(null); if (typeof configEntryModule === "string" || @@ -1931,7 +1929,6 @@ export class MeteorConfig { }); } - console.log("--> (project-context.js-Line: 1931)\n entryModulesByArch: ", entryModulesByArch); return entryModulesByArch; } @@ -1941,13 +1938,9 @@ export class MeteorConfig { ) { const entryMatch = archinfo.mostSpecificMatch( arch, Object.keys(entryModulesByArch)); - // console.log("--> (project-context.js-Line: 1939)\n archinfo: ", archinfo); - // console.log("--> (project-context.js-Line: 1939)\n Object.keys(entryModulesByArch): ", Object.keys(entryModulesByArch)); if (entryMatch) { const entryModule = entryModulesByArch[entryMatch]; - console.log("--> (project-context.js-Line: 1944)\n entryModulesByArch: ", entryModulesByArch); - console.log("--> (project-context.js-Line: 1942)\n entryModule: ", entryModule); if (entryModule === false) { // If meteor.{main,test}Module.{client,server,...} === false, no @@ -1976,7 +1969,6 @@ export class MeteorConfig { "./" + files.pathNormalize(entryModule), this.packageJsonPath ); - console.log("--> (project-context.js-Line: 1970)\n res: ", res); if (res && typeof res === "object") { return files.pathRelative(this.appDirectory, res.path); From 5324f41443ce39367a6ee3574c8af8fe3766b58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Wed, 14 May 2025 15:18:59 +0200 Subject: [PATCH 4/8] add more SWC migration topics on the section --- .../modern-transpiler-swc.md | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md b/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md index b800f99b74..8112fbf12e 100644 --- a/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md +++ b/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md @@ -142,7 +142,7 @@ This overrides Meteor's internal SWC config to apply your settings, ensuring SWC - `modern.transpiler.verbose: [true|false]` If true, the transpilation process for files is shown when running the app. This helps understand which transpiler is used for each file, what fallbacks are applied, and gives a chance to either exclude files to always use Babel or migrate fully to SWC. -## Related Topics +## Migration guide ### Nested imports @@ -171,6 +171,43 @@ For background, see: [Why nested import](https://github.com/benjamn/reify/blob/m With `"modern.transpiler": true`, if SWC finds one, it silently falls back to Babel (only shows in `"verbose": true`). Nested imports isn’t standard, most modern projects use other deferred loading methods. You might want to move imports to the top or use require instead, letting SWC handle the file and speeding up builds. Still, this decision is up to the devs, some Meteor devs use them for valid reasons. +### Import Aliases + +Meteor Babel lets you define aliases for import paths with [babel-plugin-module-resolver](https://www.npmjs.com/package/babel-plugin-module-resolver). + +To use the same aliases in SWC, add them to your [.swcrc](#custom-swcrc): + +```json +{ + "jsc": { + "baseUrl": "./", + "paths": { + "@ui/*": ["ui/*"] + } + } +} +``` + +This enables you to use `@ui/components` instead of `./ui/components` in your imports. + +### React runtime + +Meteor Babel lets you skip importing React in your files by using the [`@babel/plugin-transform-react-jsx`](https://www.npmjs.com/package/@babel/plugin-transform-react-jsx) runtime config. + +To use the same config in SWC, add it to your [.swcrc](#custom-swcrc): + +```json +{ + "jsc": { + "transform": { + "react": { + "runtime": "automatic" + } + } + } +} +``` + ## Troubleshotting If you run into issues, try `meteor reset` or delete the `.meteor/local` folder in the project root. From decada77f9909f71ffd0179aa5391716c5659d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Wed, 14 May 2025 15:48:21 +0200 Subject: [PATCH 5/8] Update modern-transpiler-swc.md --- v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md b/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md index 8112fbf12e..585339214a 100644 --- a/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md +++ b/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md @@ -142,7 +142,7 @@ This overrides Meteor's internal SWC config to apply your settings, ensuring SWC - `modern.transpiler.verbose: [true|false]` If true, the transpilation process for files is shown when running the app. This helps understand which transpiler is used for each file, what fallbacks are applied, and gives a chance to either exclude files to always use Babel or migrate fully to SWC. -## Migration guide +## Migration Topics ### Nested imports From 34bf4c1dea7e22f75c5d41d7d765daccf06f732c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Wed, 14 May 2025 15:51:09 +0200 Subject: [PATCH 6/8] Update modern-transpiler-swc.md --- .../docs/about/modern-build-stack/modern-transpiler-swc.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md b/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md index 585339214a..118457df76 100644 --- a/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md +++ b/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md @@ -144,7 +144,7 @@ This overrides Meteor's internal SWC config to apply your settings, ensuring SWC ## Migration Topics -### Nested imports +### Nested Imports Nested imports are a Meteor-specific feature in its bundler, unlike standard bundlers. Meteor introduced them during a time when bundling standards were still evolving and experimented with its own approach. This feature comes from the [`reify` module](https://github.com/benjamn/reify/tree/main) and works with Babel transpilation. SWC doesn't support them since they were never standardized. @@ -190,7 +190,7 @@ To use the same aliases in SWC, add them to your [.swcrc](#custom-swcrc): This enables you to use `@ui/components` instead of `./ui/components` in your imports. -### React runtime +### React Runtime Meteor Babel lets you skip importing React in your files by using the [`@babel/plugin-transform-react-jsx`](https://www.npmjs.com/package/@babel/plugin-transform-react-jsx) runtime config. From ff5372357641716d5ec96cde9c7c34efecb7f5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Wed, 14 May 2025 15:52:30 +0200 Subject: [PATCH 7/8] Update modern-transpiler-swc.md --- v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md b/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md index 118457df76..911fa7b5ec 100644 --- a/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md +++ b/v3-docs/docs/about/modern-build-stack/modern-transpiler-swc.md @@ -48,7 +48,7 @@ This shows each file being processed, its context, cache usage, and whether it f ## Adapt your code to benefit from SWC -If all your code uses SWC, you're good and can turn off verbosity. But if you see logs like: +If all your code uses SWC, you're good and can turn off verbosity. But if you [see logs like](https://forums.meteor.com/uploads/default/original/3X/e/1/e1a2c285284f82ab736bcada647d88bd4fa8d3ec.png): ``` shell [Transpiler] Used Babel for () Fallback From 08001799b48505bbf826ee395c2ee91cb52e9d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Wed, 14 May 2025 17:25:53 +0200 Subject: [PATCH 8/8] add missing buildCommand options --- tools/cli/commands.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/cli/commands.js b/tools/cli/commands.js index d9efdf9d5c..240dbdcd3a 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -3507,6 +3507,7 @@ main.registerCommand( name: 'profile', maxArgs: Infinity, options: { + ...buildCommands.options || {}, ...runCommandOptions.options || {}, 'size': { type: Boolean }, 'size-only': { type: Boolean },