swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.01k stars 1.21k forks source link

rootMode upward not working correctly #1801

Open axyz opened 3 years ago

axyz commented 3 years ago

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

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

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

sachinraja commented 3 years ago

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

sylvesteraswin commented 2 years ago

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