swc icon indicating copy to clipboard operation
swc copied to clipboard

rootMode upward not working correctly

Open axyz opened this issue 4 years ago • 2 comments

Describe the bug

I'm trying to migrate to swc in a monorepo that uses lerna and yarn workspaces, as there are many nested packages in various level of subfolders, for the setup to work we need to be able to get configs from the root of the monorepo. The way this is achieved with babel (both for babelrc and other settings like browserlistrc) is to pass the --root-mode upward option when calling babel from a nested project folder.

Trying to do the same with swc resulted on 3 main issues:

  1. --root-mode is not recognized as an option in the swc cli. The only way I found to pass the option is -C rootMode=upward, this is a minor issue, but is hard to figure out from the documentation and --root-mode should ideally work in order to be compatible with babel API
  2. Even when the option is passed, .swcrc files in parent folders are ignored. It seems that only the on in the current folder works, this makes the option useless and makes it impossible to use swc in a monorepo without duplicating the swcrc everywhere or rely on a known number of ../../ to use.
  3. using a js file swc.config.js as mentioned here: https://github.com/swc-project/swc/blob/master/node-swc/src/types.ts#L67 does not seem to work. That makes it harder to have dynamic config (e.g. using a different preset env for cjs and esm).

Expected behavior

  • the --root-mode option should work on the cli
  • when --root-mode is set to upward swc should read the swcrc as well as browserlist config (from rc file or package json) from the first parent package that defines them
  • config can be provided via a js file swc.config.js to enable dynamic config, or alternative should be provided and documented (e.g. different keyed env fields in the swcrc?)

Version The version of @swc/core: latest (1.2.60)

Additional context See: https://github.com/swc-project/swc/discussions/178

axyz avatar Jun 08 '21 10:06 axyz

It appears to only be checking for .swcrc files: https://github.com/swc-project/swc/blob/6dc6d8a8474f17a1064a9da2d7744bf518f72660/src/lib.rs#L406-L427

sachinraja avatar Jul 24 '21 01:07 sachinraja

I also have a similar issue with monorepos, can someone help to fix it?

sylvesteraswin avatar Feb 02 '22 14:02 sylvesteraswin