Skip to content

module: centralize builtin exposure policies - #66292

Open
sjungwon03 wants to merge 1 commit into
nodejs:mainfrom
sjungwon03:refactor/module-builtin-policy
Open

sjungwon03 wants to merge 1 commit into
nodejs:mainfrom
sjungwon03:refactor/module-builtin-policy

Conversation

@sjungwon03

Copy link
Copy Markdown
Contributor

Builtin exposure rules are currently split between realm.js and
separate setup functions in pre_execution.js for each option-gated
builtin.

Move the JavaScript loader's scheme and option-gating policies into one
table, and let pre-execution apply them after option initialization.

This intentionally keeps the policy in the JavaScript loader instead of
deriving it from native option registration. Native options do not
describe which builtins they expose: one option may enable multiple
builtins, while other options are unrelated to builtin exposure.
Code-cache categorization also has a separate responsibility. Adding
exposure metadata there would duplicate loader policy across the native
and JavaScript boundaries.

The policy test validates every declared builtin ID and option, as well
as defaults, --no-experimental-*, NODE_OPTIONS, and command-line
precedence. It also covers CommonJS, ESM, Workers, child processes, and
process.getBuiltinModule().

A builtin omitted entirely from the policy table cannot be detected
automatically because there is no independent native mapping between
options and builtins. Centralizing the loader-owned policy reduces that
risk without introducing a second source of truth in C++.

Refs: #65418
Refs: #65964
Refs: #65920
Refs: #65840

Tests:

  • make -C out -j4 node
  • python3 tools/test.py -j4 parallel/test-module-builtin-policies parallel/test-module-builtin-experimental parallel/test-sqlite

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. test Issues and PRs related to Node.js core tests and test infrastructure. labels Sep 25, 2026
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.37%. Comparing base (96ee81c) to head (b2e6b82).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66292      +/-   ##
==========================================
+ Coverage   90.35%   90.37%   +0.01%     
==========================================
  Files         790      790              
  Lines      273814   274230     +416     
  Branches    52382    52490     +108     
==========================================
+ Hits       247409   247823     +414     
+ Misses      16906    16888      -18     
- Partials     9499     9519      +20     
Files with missing lines Coverage Δ
lib/internal/bootstrap/realm.js 97.09% <100.00%> (+0.10%) ⬆️
lib/internal/process/pre_execution.js 96.76% <100.00%> (+0.09%) ⬆️
lib/internal/test/binding.js 89.74% <100.00%> (+1.86%) ⬆️

... and 54 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Keep scheme-only and option-gated builtin exposure rules in the
JavaScript loader. Leave option registration and code-cache
categorization with their native owners.

Assisted-by: Codex
Signed-off-by: sjungwon03 <sjungwon03@gmail.com>
@sjungwon03
sjungwon03 force-pushed the refactor/module-builtin-policy branch from 767bbfb to b2e6b82 Compare September 25, 2026 22:23
Comment on lines +65 to +67
// Cover shared flags, both scheme rules, and an option enabled by default.
const workerPolicyIds = new Set([
'bench', 'bench/reporters', 'stream/iter', 'zlib/iter', 'sqlite',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list could become stale as policies change. For example, if these modules no longer need experimental flags while other modules still do, the test could pass without the coverage described above.

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

Labels

lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. test Issues and PRs related to Node.js core tests and test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants