swc
swc copied to clipboard
rootMode upward not working correctly
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:
--root-modeis 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-modeshould ideally work in order to be compatible with babel API- Even when the option is passed,
.swcrcfiles 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. - using a js file
swc.config.jsas 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-modeoption should work on the cli - when
--root-modeis set toupwardswc should read theswcrcas 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.jsto enable dynamic config, or alternative should be provided and documented (e.g. different keyed env fields in theswcrc?)
Version The version of @swc/core: latest (1.2.60)
Additional context See: https://github.com/swc-project/swc/discussions/178
It appears to only be checking for .swcrc files:
https://github.com/swc-project/swc/blob/6dc6d8a8474f17a1064a9da2d7744bf518f72660/src/lib.rs#L406-L427
I also have a similar issue with monorepos, can someone help to fix it?