build!: require Node 22
Node 18 and Node 20 are end-of-life and receive no security patches, so supporting them before RC.1 would mean promising a runtime nobody can patch. Node 22 is the oldest line still maintained. engines.node moves to >=22, @types/node to ^22, the tsup target to node22, and CI's build job from Node 18 to 22, so every workflow now runs Node 22 only. The docs, the bug report example and the comments that stated 18 as the floor follow. The node:crypto fallback in the HTTP core existed only for Node 18, which lacked the global crypto; it goes with its regression test, which said as much. The ws fallback for the WebSocket client stays: Node 22 has the global, but it can still be switched off with a flag. Moving off Node 18 and 20 also unblocks vitest 4, which the remaining dev audit advisories need. BREAKING CHANGE: Node 18 and Node 20 are no longer supported. The minimum is Node 22. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
16 files changed
+39
-75
No files matched your search
+5
-21
@@ -9,31 +9,15 @@ import { acquireBody, type BodyReader } from './body';
|
||||
import type { RouteDef, HttpOptions } from './types';
|
||||
import type { StreamEncoder } from '../encoders';
|
||||
import type { Bus } from '../bus';
|
||||
import { nodeRequire } from '../node-require';
|
||||
|
||||
/**
|
||||
* `randomUUID`, from wherever this runtime keeps it. Resolved once, at import.
|
||||
* `randomUUID` from the web-standard global, which every supported runtime exposes without a flag:
|
||||
* Node (the `engines` floor is 22; the global arrived unflagged in 19), Deno, Bun and workerd.
|
||||
*
|
||||
* The web-standard global stays the primary path, and that is deliberate rather than stylistic:
|
||||
* this file is the runtime-neutral core, and Deno, Bun and workerd all expose `crypto` without a
|
||||
* compatibility flag, while `node:crypto` is unavailable to at least one of them.
|
||||
*
|
||||
* Node is the exception. The global arrived **unflagged in 19**, and `engines` promises `>=18`,
|
||||
* where it does not exist at all — so the previous `declare const crypto` compiled cleanly and then
|
||||
* threw `ReferenceError: crypto is not defined` on the first request of every Node 18 process. Only
|
||||
* CI's Node 18 job caught it; every newer Node and every other runtime hides it, which is exactly
|
||||
* why that job is pinned to the floor rather than to the current release.
|
||||
*
|
||||
* The fallback is reached only by a runtime that lacks the global, so workerd never evaluates it.
|
||||
* It goes through {@link nodeRequire} rather than a bare `require`, which is what makes it work on
|
||||
* every distribution of this package and not just the bundled ones.
|
||||
* Node 18 lacked it, and this used to fall back to `node:crypto` there. That fallback went with the
|
||||
* Node 18 floor.
|
||||
*/
|
||||
const randomUUID: () => string = (() => {
|
||||
const webCrypto = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto;
|
||||
if (typeof webCrypto?.randomUUID === 'function') return () => webCrypto.randomUUID!();
|
||||
|
||||
return nodeRequire<{ randomUUID: () => string }>('node:crypto').randomUUID;
|
||||
})();
|
||||
const randomUUID = (): string => crypto.randomUUID();
|
||||
|
||||
/**
|
||||
* A runtime-neutral inbound request.
|
||||
|
||||
@@ -124,8 +124,10 @@ export function neutralSocket(
|
||||
export type SocketCtor = new (url: string) => EventfulSocket;
|
||||
|
||||
/**
|
||||
* The WebSocket client implementation: the platform global where it exists (Deno, Bun, and
|
||||
* Node >= 22), else the `ws` optional peer — Node 18-21, our declared floor, has no global.
|
||||
* The WebSocket client implementation: the platform global where it exists, else the `ws`
|
||||
* optional peer. Every supported runtime has the global — Deno, Bun, and Node from 22, the
|
||||
* declared floor — so the fallback is reached only when Node runs with the global switched off
|
||||
* (`--no-experimental-websocket`). `ws` is installed anyway for the server side.
|
||||
*
|
||||
* Both expose the same `addEventListener` API and deliver text frames as `event.data` strings,
|
||||
* so one bridge covers both. That is verified rather than assumed: `ws` implements the
|
||||
|
||||
Reference in new issue
Block a user