swc-project / swc

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

Make Stacker an optional dependency (transitively) #8422

Open 71 opened 6 months ago

71 commented 6 months ago

Describe the feature

7719 requested for stacker to be made an optional dependency, and #7720 implemented it.

Unfortunately, Cargo features are additive so importing any package which depends on swc_ecma_parser and does not set default-features = false (such as swc_core and swc_ecma_transforms_base) will enable default features in swc_ecma_parser, and thus import stacker as a dependency.

Maybe my Cargo-fu is failing me, but AFAIK there is no workaround for this with [patch] and whatnot.

Babel plugin or link to the feature description

No response

Additional context

No response

71 commented 6 months ago

EDIT: the reason why I filed this issue is that I could not build swc on macOS due to iconv not being found, which appears to be a Nix problem, not a swc problem. This issue is still valid (in that, disabling stacker cannot be done when using swc_core or swc_ecma_transforms_base), but less blocking on my end.


I tried to add a disable_stacker feature to swc_ecma_parser, so if any dependent sets that feature we can avoid stacker with a cfg(not(feature = "disable_stack")). This works at the source-code level.

Unfortunately, by keeping stacker as a dependency (which seems inevitable; Cargo allows adding dependencies based on a feature, but not removing dependencies based on them), we still need to build that crate, and therefore the dependency on stacker remains.

I see two other possible approaches:

  1. Remove stacker from default features. Easy, but may not be the best for users which expect it to be there.
  2. Patch all crates in swc which depend on swc_ecma_parser to avoid the default dependency on stacker.
    • And then perhaps make swc_core/ecma_parser enable stacker by default and provide swc_core/ecma_parser_no_stacker to disable default features?