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

Commit
13 days ago
fix(ext/node): single source of truth for emulated Node version (#35273) `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.
Author
Parents
Loading