SIGN IN SIGN UP
denoland / deno UNCLAIMED

A modern runtime for JavaScript and TypeScript.

0 0 3 Rust

fix(ext/node): implement Module._stat (#34157)

## Summary

Implements the internal-but-public `Module._stat(path)` accessor on the
`node:module` `Module` constructor, matching Node's
`lib/internal/modules/cjs/loader.js`:

- Returns `0` if `path` is a file
- Returns `1` if `path` is a directory
- Returns a negative value if the path does not exist or stat fails
- Synchronous

The default implementation is backed by the existing `op_require_stat`
op
(which Deno's internal `stat()` helper already used). Assigning
`Module._stat = fn` emits an `ExperimentalWarning` (matching Node) and
swaps the underlying function so the module loader's internal stat
lookups
also pick it up, which is what `patch-package`, certain bundlers, and
the
Node test suite rely on.

## Test plan

- [x] `cargo test --test node_compat -- test-module-stat` passes
- [ ] Manual: `Module._stat(<file>) === 0`, `Module._stat(<dir>) === 1`,
      `Module._stat(<nonexistent>) < 0`
- [ ] CI

`parallel/test-vfs.js` still fails after this change but at a later
point:
it expects the CJS loader to use the (user-patched) `fs.realpathSync`
and
`fs.readFileSync`. Deno's loader currently calls `op_require_real_path`
/
`op_require_read_file` directly, which bypass user monkey-patching.
Making
the loader patchable is a larger architectural change worth handling in
a
follow-up.

Closes denoland/orchid#114

---------

Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>
E
em committed
565302b589aca96f0968e2cb9dfbd6f2bd9600a1
Parent: b85d40c
Committed by GitHub <noreply@github.com> on 5/17/2026, 5:28:31 AM