Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rootMode upward not working correctly #1801

Open
axyz opened this issue Jun 8, 2021 · 2 comments
Open

rootMode upward not working correctly #1801

axyz opened this issue Jun 8, 2021 · 2 comments
Labels

Comments

@axyz
Copy link

axyz commented Jun 8, 2021

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: #178

@axyz axyz added the C-bug label Jun 8, 2021
@sachinraja
Copy link

It appears to only be checking for .swcrc files:

swc/src/lib.rs

Lines 406 to 427 in 6dc6d8a

while let Some(dir) = parent {
let swcrc = dir.join(".swcrc");
if swcrc.exists() {
let config = load_swcrc(&swcrc)?;
let mut config = config
.into_config(Some(path))
.context("failed to process config file")?;
if let Some(config_file) = config_file {
config.merge(&config_file.into_config(Some(path))?)
}
return Ok(config);
}
if dir == root && *root_mode == RootMode::Root {
break;
}
parent = dir.parent();
}

@sylvesteraswin

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants