Skip to content

refactor(ext/node): merge 02_init.js into 01_require.js#34035

Merged
bartlomieju merged 1 commit into
mainfrom
refactor/merge-node-init-into-require
May 13, 2026
Merged

refactor(ext/node): merge 02_init.js into 01_require.js#34035
bartlomieju merged 1 commit into
mainfrom
refactor/merge-node-init-into-require

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

The Node polyfill init was split across two files for historical
reasons: 01_require.js defined Module and the require machinery,
then handed a requireImpl bridge object over to 02_init.js, which
did the actual nodeBootstrap setup. Inspecting the bridge shows that
most of it was either dead (the loadCjsModule helper had no callers,
which made the Module and setInspectBrk keys it depended on dead
too) or pure indirection (setUsesLocalNodeModulesDir flipping a
module-level boolean, nativeModuleExports getting passed through).

This collapses the two files into one. internals.requireImpl is
gone, the dead helper and handles are gone, the nested
internals.node = { closeIdleConnections } (whose sole consumer is
the test runner) flattens to internals.closeIdleConnections, and
the top-level bindStreamsLazy call moves into the non-warmup branch
of initialize — only node:console consumers observe it and they
can't run until after bootstrap. The extension's esm_entry_point
now points at node:module since 02_init.js no longer exists.

Drop the separate `02_init.js` module by inlining its content into
`01_require.js`. Along the way:

- Remove the `internals.requireImpl` bridge namespace — both files now
  live in the same module, so `setUsesLocalNodeModulesDir` collapses
  to a direct assignment and `nativeModuleExports` is a local
  reference. The dead `setInspectBrk` and `Module` keys go away too.
- Remove the unused `loadCjsModule` helper.
- Replace the nested `internals.node = { closeIdleConnections }`
  handle with a flat `internals.closeIdleConnections`, and update the
  test runner script string accordingly. `closeIdleConnections` is the
  only consumer of that namespace.
- Move the top-level `bindStreamsLazy(console, process)` call into
  `initialize`'s non-warmup branch. It only matters for `node:console`
  consumers, which can't run until after bootstrap anyway.
- Update `esm_entry_point` to `node:module` and drop `02_init.js`
  from the esm list.
@bartlomieju bartlomieju merged commit 46c1566 into main May 13, 2026
268 of 270 checks passed
@bartlomieju bartlomieju deleted the refactor/merge-node-init-into-require branch May 13, 2026 23:51
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.

1 participant