fix(compile): resolve JSON requires from ESM module paths - #10874
proggeramlug wants to merge 1 commit into
Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe compiler now replaces selected static relative JSON ChangesStatic JSON require resolution
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant collect_module_one
participant static_require_transform
participant package_json
collect_module_one->>static_require_transform: transform unwrapped ESM module
static_require_transform->>package_json: resolve relative JSON target
static_require_transform->>static_require_transform: generate default import binding
static_require_transform-->>collect_module_one: return source with replaced binding
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings
🧪 Generate unit tests (beta)
🛠️ Fix failing CI checks 💡
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. Comment |
34f8a0e to
b7081db
Compare
The file was at exactly 2000 on main, so any PR adding a line fails the gate; #10874/#10867 add one between them. collect_module_one is a single ~1890-line walk under 15 already-peeled siblings, so the next split is phase surgery, not a move of independent arms -- same rationale as the #1435 allowlist block.
|
Landed via merge train 252 (#10892) as v0.5.1632 — merge commit Carried with #10866, #10876, #10867, #10874 and #10862, which all touch overlapping surfaces. Train-side work: #10867 and #10874 each add a module declaration to the same regression-test index (additive — both kept, sorted by issue); #10862's version-bump commits were excluded, since contributor PRs do not bump; and Validation: 173 gap fixtures across seven areas, zero regressions, re-run against the current base after v0.5.1631 changed Closing here rather than merging — a train lands the commits directly. |
Closes #10758
MongoDB is compiled from its ESM-shaped TypeScript source, but
client_metadata.tsretains a literalrequire("../../../package.json"). Perry previously added the JSON file to the graph while leaving the call to the entry-relative global require, producingMODULE_NOT_FOUND.This replaces resolved JSON requires with the JSON loader default binding only for unwrapped ESM modules. CJS-wrapped modules retain their per-module require/cache path.
Tests:
cargo test -p perry --bin perry replaces_resolved_json_require_in_unwrapped_esm_modulecargo test -p perry --test source_graph_export_regressions esm_module_resolves_static_json_require_from_its_own_directory -- --nocapture(remote Linux, matching static runtime)package.jsonresolution failure; final linking was blocked by an unrelated stale optional runtime archive on the shared remote host.Summary by CodeRabbit
require()calls in ESM-shaped TypeScript so they resolve from the requiring module’s directory.package.jsonmetadata without encounteringMODULE_NOT_FOUNDduring setup.