Skip to content

fix(ext/node): single source of truth for emulated Node version#35273

Merged
bartlomieju merged 2 commits into
mainfrom
fix/node-version-single-source
Jun 17, 2026
Merged

fix(ext/node): single source of truth for emulated Node version#35273
bartlomieju merged 2 commits into
mainfrom
fix/node-version-single-source

Conversation

@bartlomieju

@bartlomieju bartlomieju commented Jun 16, 2026

Copy link
Copy Markdown
Member

process.version / process.versions.node were hard coded as string
literals in the node:process polyfill, with no value the rest of the
runtime could reference, so the reported Node version had to be kept in sync
by hand whenever it was bumped.

This defines the emulated Node version once as NODE_VERSION in
ext/node/lib.rs, and has the polyfill carry a __NODE_VERSION__ token that
is substituted with that constant at snapshot build time (in
maybe_transpile_source). The substitution runs for both the snapshot build
and any non-snapshot runtime, and _process/process.ts is a lazy-loaded
script that passes through the transpiler, so the baked value is correct
everywhere. Rust code can now read the same constant directly instead of
duplicating the literal, so the reported version can no longer drift.

napi_get_node_version, exposed to native addons through the Node-API C
ABI, previously returned a hard coded 20.11.1 that was unrelated to and far
behind the emulated version. It now derives its major/minor/patch from the
same NODE_VERSION constant at compile time, so addons calling it observe
the same version as process.versions.node. The napi test asserts the two
agree.

process.version / process.versions.node were hard coded as string literals
in the node:process polyfill, separate from any value the rest of the runtime
could reference, so the reported Node version had to be kept in sync by hand.

Define the emulated Node version once as NODE_VERSION in ext/node, and have the
polyfill carry a __NODE_VERSION__ token that is substituted with that constant
at snapshot build time. Rust code can now read the same constant directly, so
the reported version no longer needs hand-syncing with a duplicated literal.
bartlomieju added a commit that referenced this pull request Jun 16, 2026
The NODE_VERSION constant, the process.version polyfill token, and the
snapshot-time substitution are factored out into #35273 so this PR stays
focused on the engines.node/engines.deno warning. This branch now only
consumes deno_node::NODE_VERSION (re-exported as deno_lib::version::NODE_VERSION)
for the engines check, and depends on #35273 landing first.
@bartlomieju bartlomieju changed the title fix(node): single source of truth for emulated Node version fix(ext/node): single source of truth for emulated Node version Jun 16, 2026
napi_get_node_version() hardcoded 20.11.1, so native addons calling it
saw a Node version unrelated to (and far behind) the one reported through
process.version / process.versions.node. Derive major/minor/patch at
compile time from deno_node::NODE_VERSION, the single source of truth, so
the C-ABI value can no longer drift from the JS-visible version.

The napi test now asserts napi_get_node_version() equals
process.versions.node instead of just checking major >= 1.
@bartlomieju
bartlomieju enabled auto-merge (squash) June 16, 2026 21:16
@bartlomieju
bartlomieju merged commit 82e8ca0 into main Jun 17, 2026
269 of 271 checks passed
@bartlomieju
bartlomieju deleted the fix/node-version-single-source branch June 17, 2026 07:37
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