fix(fs): route named promises import to the fs/promises submodule namespace - #7006
Conversation
|
Warning Review limit reached
Next review available in: 32 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis change routes Node ChangesPromise submodule routing
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
81532df to
03aa1ae
Compare
03aa1ae to
cb6cdc8
Compare
import { promises } from "node:fs"silently gives back the wrong API: every call likepromises.realpath(p)resolvesundefinedinstead of a value.Background on the mechanism: Node exposes the promise-based fs API two ways — the
node:fs/promisessubmodule, and apromisesnamed export onnode:fsthat is the same namespace object. Soimport { promises } from "node:fs"must bind a namespace whose members are promise-returning functions, exactly asimport * as promises from "node:fs/promises"would. The compiler's named-import lowering instead treatedpromiseslike any other named export offs: a native method reference (fs.promises). A laterpromises.realpath(p)therefore dispatched the callback-APIfs.realpath— whose return value isundefinedby design (the result arrives via callback) — so the awaited call quietly producedundefined, and everything downstream of the "resolved path" broke.Minimal repro
Root cause (two layers)
crates/perry-hir/src/lower/module_decl.rs:221— the named-import table's generic arm mapped{ promises }fromfs/dns/streamto a native method<mod>.promisesinstead of the<mod>/promisessubmodule namespace.crates/perry-codegen/src/lower_call/native/mod.rs:383— once the HIR routes the binding to the submodule, the call arrives as a receiver-lessNativeMethodCall { module: "fs/promises", method }, and codegen had no arm for that shape: it fell to theTAG_UNDEFINEDsentinel, so even a correctly-routed binding still resolvedundefined.The fix is one arm per layer: module_decl routes
{ promises }fromfs/dns/streamto the<mod>/promisessubmodule (exactly like the star-import), and codegen dispatches the receiver-less submodule call on the populated submodule namespace singleton (js_node_submodule_namespace), whose members are the real promise-returning thunks.Test plan
Verified end-to-end on the repro above:
promises.realpath(".")returns the resolved path where it previously resolvedundefined. (The failing shape needs a full compile-and-run of a program importing{ promises }; the existing fs integration corpus covers the star-import path this change reuses.)Found while compiling a manifest generation CLI — a real-world TypeScript CLI with a deep pnpm dependency graph. Independent of the other fixes from that effort; lands standalone.
Summary by CodeRabbit
fs,dns, andstream.realpathnow correctly return promises instead of producing undefined results.