swc
swc copied to clipboard
Make Stacker an optional dependency (transitively)
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
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:
- Remove
stackerfrom default features. Easy, but may not be the best for users which expect it to be there. - Patch all crates in
swcwhich depend onswc_ecma_parserto avoid the default dependency onstacker.- And then perhaps make
swc_core/ecma_parserenablestackerby default and provideswc_core/ecma_parser_no_stackerto disable default features?
- And then perhaps make