Skip to content

fix(cli): honor externalHelpers=false in rust binary#11693

Merged
kdy1 merged 2 commits intomainfrom
kdy1/fix-11643-external-helpers-cli
Mar 16, 2026
Merged

fix(cli): honor externalHelpers=false in rust binary#11693
kdy1 merged 2 commits intomainfrom
kdy1/fix-11643-external-helpers-cli

Conversation

@kdy1
Copy link
Copy Markdown
Member

@kdy1 kdy1 commented Mar 16, 2026

Summary

  • Enable inline helper support in the Rust CLI build by adding swc_core/ecma_helpers_inline to swc_cli_impl.
  • Fix behavior where jsc.externalHelpers: false was ignored and @swc/helpers was still emitted.
  • Add a regression test for issue externalHelpers broken in published rust binary #11643.

Changes

  • crates/swc_cli_impl/Cargo.toml
    • Add ecma_helpers_inline to the swc_core feature list.
  • crates/swc_cli_impl/tests/issues.rs
    • Add issue_11643_external_helpers_false_respected.
    • Verify output does not reference @swc/helpers.
    • Verify inline _export_star helper is emitted.

Verification

  • git submodule update --init --recursive
  • cargo test -p swc_cli_impl issue_11643
  • cargo test -p swc_cli_impl
  • cargo fmt --all
  • cargo clippy --all --all-targets -- -D warnings

Closes #11643

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 16, 2026

🦋 Changeset detected

Latest commit: aa93151

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@socket-security
Copy link
Copy Markdown

socket-security Bot commented Mar 16, 2026

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm js-beautify is 100.0% likely obfuscated

Confidence: 1.00

Location: Package overview

From: package.jsonnpm/js-beautify@1.14.7

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/js-beautify@1.14.7. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@kdy1 kdy1 marked this pull request as ready for review March 16, 2026 14:35
@kdy1 kdy1 requested a review from a team as a code owner March 16, 2026 14:35
Copilot AI review requested due to automatic review settings March 16, 2026 14:35
@kdy1 kdy1 enabled auto-merge (squash) March 16, 2026 14:35
kodiakhq[bot]
kodiakhq Bot previously approved these changes Mar 16, 2026
@claude

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the Rust swc CLI binary so that jsc.externalHelpers: false is honored by enabling inline helper emission, aligning behavior with @swc/cli / @swc/core and preventing unwanted @swc/helpers requires.

Changes:

  • Enable inline ECMA helpers in the Rust CLI build by adding the swc_core/ecma_helpers_inline feature.
  • Add a regression test covering issue #11643, asserting no @swc/helpers reference and presence of an inline _export_star helper.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/swc_cli_impl/Cargo.toml Enables inline helper support in the CLI build via ecma_helpers_inline.
crates/swc_cli_impl/tests/issues.rs Adds a regression test ensuring externalHelpers: false no longer emits @swc/helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

"Expected inline _export_star helper when externalHelpers is false. Got: {output}",
);
assert!(
output.contains("_export_star(require(\"./my-file\"), exports);"),
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 16, 2026

Binary Sizes

File Size
swc.linux-x64-gnu.node 28M (28752968 bytes)

Commit: f8b1bee

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 16, 2026

Merging this PR will not alter performance

✅ 219 untouched benchmarks


Comparing kdy1/fix-11643-external-helpers-cli (aa93151) with main (588577c)

Open in CodSpeed

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Mar 16, 2026

PR Review: fix(cli): honor externalHelpers=false in rust binary

Summary

Clean, minimal fix. The root cause is that swc_cli_impl was missing the ecma_helpers_inline feature on swc_core, so inline helper injection was never compiled in for the Rust CLI binary. Without it, externalHelpers: false was silently ignored and @swc/helpers imports were emitted regardless.

Code Quality

Looks good. The fix is a single feature flag addition in Cargo.toml — exactly the right scope for this kind of bug. No unnecessary changes.

The test is well-structured and follows the existing patterns in issues.rs:

  • Creates a temp sandbox with a .swcrc and input files
  • Runs the CLI binary
  • Asserts on the output content with clear error messages

The three assertions cover the important invariants:

  1. No @swc/helpers references (the bug)
  2. Inline _export_star function is present (the fix)
  3. The re-export call uses the inline helper (correctness)

Minor Observations

  • my-file.ts isn't strictly needed — the test only compiles index.ts and checks the output of that single file. However, having it present makes the test more realistic since export * from "./my-file" would be a real module graph, so this is fine.

  • The test asserts a specific function name (_export_star) and call pattern. This is slightly brittle if the helper naming ever changes, but it's consistent with how other tests in this file work, and the alternative (only checking absence of @swc/helpers) would be a weaker test. Good tradeoff.

Verdict

LGTM. Minimal, correct fix with good regression test coverage. The changeset is properly included.

@kdy1 kdy1 disabled auto-merge March 16, 2026 15:08
@kdy1 kdy1 merged commit 1be052e into main Mar 16, 2026
45 checks passed
@kdy1 kdy1 deleted the kdy1/fix-11643-external-helpers-cli branch March 16, 2026 15:09
@github-actions github-actions Bot modified the milestones: Planned, 1.15.21 Mar 16, 2026
@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

externalHelpers broken in published rust binary

2 participants