Skip to content

fix(compiler): emit native package re-export getters - #11069

Closed
proggeramlug wants to merge 2 commits into
PerryTS:mainfrom
proggeramlug:fix/11044-ethers-websocket-wrapper
Closed

proggeramlug wants to merge 2 commits into
PerryTS:mainfrom
proggeramlug:fix/11044-ethers-websocket-wrapper

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • lower named re-exports from bundled native packages as synthetic native imports
  • classify those forwarded values as getter-backed exports during cross-module analysis
  • emit the native export getter instead of an unresolved function wrapper stub
  • add HIR and LLVM IR regressions for the export { WebSocket } from "ws" shape

Validation

  • cargo test -p perry-hir
  • cargo test -p perry-codegen --lib
  • cargo test -p perry-hir --test node_named_export_hygiene
  • cargo test -p perry-codegen native_package_reexport_emits_a_value_getter --lib
  • cargo fmt --all -- --check
  • scripts/check_file_size.sh
  • full 153-module ethers@6.17.0 reproduction now links and writes the executable without the missing __perry_wrap_perry_fn_...ws_ts__WebSocket symbol

Closes #11044

Summary by CodeRabbit

  • Bug Fixes

    • Fixed named re-exports from bundled native packages so they resolve to live exported values correctly.
    • Improved compatibility with packages such as ethers, including WebSocket-related exports from ws.
    • Native package exports now link successfully instead of producing unresolved references or wrapper-related errors.
  • Tests

    • Added regression coverage for native package re-exports and aliased exports.

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 26018aeb-63c2-468f-97bf-50db5f294fe9

📥 Commits

Reviewing files that changed from the base of the PR and between b77aba6 and 6bd0f21.

📒 Files selected for processing (7)
  • changelog.d/11069-native-package-reexports.md
  • crates/perry-codegen/src/codegen/artifacts.rs
  • crates/perry-codegen/src/codegen/mod.rs
  • crates/perry-codegen/src/lower_call/named_import_install_tests.rs
  • crates/perry-hir/src/lower/module_decl.rs
  • crates/perry-hir/tests/node_named_export_hygiene.rs
  • crates/perry/src/commands/compile/run_pipeline.rs
💤 Files with no reviewable changes (1)
  • crates/perry-codegen/src/codegen/mod.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Native named re-exports from bundled packages now lower through synthetic native imports. Compilation recognizes all native sources for export classification and emits value getters for forwarded bindings. Regression tests cover the ws WebSocket re-export path.

Changes

Native named re-exports

Layer / File(s) Summary
Native re-export lowering
crates/perry-hir/src/lower/module_decl.rs, crates/perry-hir/tests/node_named_export_hygiene.rs
Native named re-exports, including bundled npm shims such as ws, now use synthetic native-import bindings. The HIR test verifies the WebSocket import and exported alias.
Native export classification and getters
crates/perry/src/commands/compile/run_pipeline.rs, crates/perry-codegen/src/codegen/mod.rs, crates/perry-codegen/src/codegen/artifacts.rs
Forwarded named exports from any native import are classified as exported variables. Export stubs are excluded for matching imports, and native value getters are emitted for the re-exported bindings.
Native re-export code generation tests
crates/perry-codegen/src/lower_call/named_import_install_tests.rs, changelog.d/11069-native-package-reexports.md
The codegen test verifies that the ws re-export emits a getter calling js_native_module_named_esm_export_value. The changelog records the fix.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 6bd0f

The native package re-export change has no identified merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: emitting native package re-export getters.
Description check ✅ Passed The description provides the change summary, linked issue, validation commands, regression coverage, and reproduction result. It does not use the template headings for Changes or Test plan and omits t…
Linked Issues check ✅ Passed The changes satisfy the coding objective in issue [#11044]. module_decl.rs lowers named re-exports from any recognized native module, including ws, to synthetic native imports. run_pipeline.rs, …
Out of Scope Changes check ✅ Passed The reviewed changes stay within issue [#11044]. The broader native-module handling is required to support bundled native packages such as ws, not only Node core modules. The HIR and LLVM IR tests, …
Full details: Docstring Coverage

Explanation

Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🧪 Generate unit tests (beta)
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main in merge train 259 (#11079), released as v0.5.1642 at 7f4417b5a1.

Your commits are on main — cherry-picked from this PR's head 6bd0f21865 and validated as one tree, CI 22/22 green including all 6 gap-suite shards. GitHub cannot auto-close a PR whose commits land under new SHAs via a train rebase, which is why I'm closing this by hand rather than it happening on merge.

Nothing is lost and nothing is needed from you. Thanks.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ethers: link fails with undefined reference to __perry_wrap_perry_fn_..._ws_ts__WebSocket

1 participant