CodeVetter · Repo Unpack · Extension points
nodejs/node
This codebase is unusually explicit about where new code plugs in, because adding a feature is a repeated four-part ritual. New native capability goes in the `NODE_BUILTIN_*_BINDINGS` macro lists; new CLI surface goes in `src/node_options.cc` with a field in `node_options.h`; new run modes go in the `StartExecution` if-chain plus a file in `lib/internal/main/`; new user-visible builtins are gated by a `setupX()` in `pre_execution.js` calling `BuiltinModule.allowRequireByUsers()`. Beyond core, the VFS provider registry, the CJS `Module._extensions` table, the loader-override map, and the SQLite virtual-table module are genuine runtime plugin surfaces.
- `BuiltinModule.allowRequireByUsers(id)` is the runtime gate that makes a `lib/*.js` module requirable by user code; it adds to `canBeRequiredByUsersList` and conditionally to `canBeRequiredByUsersWithoutSchemeList` (new experimental modules are added `node:`-scheme-only).
- `vfs.registerProvider({ name, canHandle, create })` is the public plugin interface for `--vfs-mount` sources; registrations are unshifted ahead of the built-in `zip` and `dir` providers, so a custom provider outranks both.
- `VirtualProvider` in `lib/internal/vfs/provider.js` is the base class a custom provider subclasses; the shipped implementations (`MemoryProvider`, `RealFSProvider`, `ZipProvider`, and the internal SEA provider) are the reference shapes.
- `setLoaderOverrides(overrides)` installs per-key replacements for the module loader's fs and package.json operations; passing a nullish field restores the native fast path, which is how unmount cheaply reverts loader interception.
- `Module._extensions` is the classic CJS extension table (`.js`, `.json`, `.node` assigned in `cjs/loader.js`) and `findLongestRegisteredExtension` supports multi-dot extensions, so a loader plugin can register e.g. `.test.ts`.
- `Module._load`, `Module._resolveFilename`, and `Module._findPath` remain intentionally monkey-patchable — `resolveMainPath()` comments that `Module._findPath` 'is monkey-patchable here', and the repo's own `eslint.config.mjs` patches `Module._resolveFilename` to resolve vendored ESLint plugins.
- Adding a native binding means adding `V(name)` to the appropriate macro list in `src/node_binding.h` — `NODE_BUILTIN_STANDARD_BINDINGS` for unconditional ones, or a new `#if`-guarded `NODE_BUILTIN_X_BINDINGS(V)` block for optional subsystems.
- Adding a CLI flag is a paired edit: `AddOption("--flag", help, BOOL_FIELD(field), kAllowedInEnvvar-style)` in `src/node_options.cc` and the field declaration in `src/node_options.h`; `Implies()` links derived bools (as `--vfs-load` implies `[vfs_load_set]`).
- Adding an execution mode requires a branch in the `StartExecution` chain in `src/node.cc` and a corresponding script in `lib/internal/main/`; `bench_runner` is the most recent instance of this pattern and mirrors `test_runner` line for line.
- `sqlite.createModule()` backed by `VirtualTableModule` lets user JS supply `xBestIndex`/`xOpen`/`xClose` behaviour into SQLite's `sqlite3_module` vtable — a genuine C++-level plugin surface reachable from JS.
- Permission scopes are extended by adding a `V(Name, "dotted.name", Parent, "--allow-flag")` entry to the `PERMISSIONS(V)` macro in `permission_base.h`; the enum, the diagnostics channel names, and the string mapping are all generated from it.
- Test suites are pluggable: each `test/<suite>/` may carry a `testcfg.py` and a `<suite>.status` file that `tools/test.py` discovers, as `test/ffi/` does.
- Lint is composed from per-directory partial configs (`lib/eslint.config_partial.mjs`, `test/`, `doc/`, `benchmark/`, `tools/eslint/`) assembled by the root `eslint.config.mjs`, plus a custom `tools/eslint-rules` plugin directory — the place to add core-specific rules.
- The internal binding type surface is extended by adding a `typings/internalBinding/<name>.d.ts` file; recent commits ('typings: wire up quic internal binding types', 'typings: add mksnapshot internal binding types') show this is expected alongside the C++ change. (inferred)