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
@@ -19,7 +19,7 @@ The smallest module and route that shows it:
|
||||
## Environment
|
||||
|
||||
- green-tea version:
|
||||
- Runtime and version: <!-- Node 20.11 / Deno 2.1 / Bun 1.1 / Cloudflare Workers -->
|
||||
- Runtime and version: <!-- Node 22.12 / Deno 2.1 / Bun 1.1 / Cloudflare Workers -->
|
||||
- OS:
|
||||
|
||||
<!--
|
||||
|
||||
@@ -41,7 +41,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
node-version: '22'
|
||||
- run: npm ci
|
||||
- run: npm run lint
|
||||
- run: npm run format:check
|
||||
|
||||
@@ -10,6 +10,11 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
|
||||
### Breaking
|
||||
|
||||
- **Node 18 and Node 20 are no longer supported; the minimum is Node 22.** Both are end-of-life
|
||||
and receive no security patches, so `engines.node` is now `>=22`, CI runs Node 22 only, and the
|
||||
build targets `node22`. Node 22 is the oldest line still maintained. The `node:crypto` fallback
|
||||
for Node 18's missing global `crypto` is removed with it.
|
||||
|
||||
- **Inbound WebSocket messages are capped at 1 MiB by default** (#107). Node used `ws`'s own
|
||||
default of 100 MiB, and Deno, Bun and the edge applied no cap of their own, so one client could
|
||||
make the server hold a message of any size the runtime would accept. A larger message now closes
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ Follow [Conventional Commits](https://www.conventionalcommits.org/): `feat:`, `f
|
||||
|
||||
## Local setup
|
||||
|
||||
Node 18 or newer, which is what `engines` requires and what CI runs.
|
||||
Node 22 or newer, which is what `engines` requires and what CI runs. Node 18 and 20 are end-of-life and no longer supported.
|
||||
|
||||
```bash
|
||||
npm install
|
||||
|
||||
@@ -284,7 +284,7 @@ green-tea is **beta**, on the road to a release candidate. Express and Fastify h
|
||||
|
||||
**What is not here:** no metrics registry, and **no OpenTelemetry exporter in core** — that is a separate package, because core has one runtime dependency and intends to keep it. A `traceparent` header is carried through untouched for an exporter to interpret; core implements no propagation spec. If your definition of production-ready includes shipping traces on day one, you are writing the exporter, and the stream it needs is the part that now exists.
|
||||
|
||||
**Runtimes differ in what they can offer.** Node ≥ 18, Deno, and Bun run everything. On the edge (Cloudflare Workers) there is no `app.listen()`, no filesystem — so `@Html` file/template modes and `static` serving are unavailable — and mesh does not run there at all (the teapot's secret comparison needs `node:crypto`'s `timingSafeEqual`, which `nodejs_compat` doesn't provide). Workers also require the `nodejs_compat` flag.
|
||||
**Runtimes differ in what they can offer.** Node ≥ 22, Deno, and Bun run everything. On the edge (Cloudflare Workers) there is no `app.listen()`, no filesystem — so `@Html` file/template modes and `static` serving are unavailable — and mesh does not run there at all (the teapot's secret comparison needs `node:crypto`'s `timingSafeEqual`, which `nodejs_compat` doesn't provide). Workers also require the `nodejs_compat` flag.
|
||||
|
||||
**mesh is alpha.** Distributed DI works, but discovery, load-balancing, and failover are not built, and its API and wire protocol may change between releases. It is gated behind an explicit opt-in — `createApp({ mesh, experimental: true })` — and `createApp` throws if you configure `mesh` without it. Don't ship mesh to production yet.
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"npm:@types/autocannon@^7.12.7",
|
||||
"npm:@types/busboy@^1.5.4",
|
||||
"npm:@types/express@^5.0.6",
|
||||
"npm:@types/node@^18.19.0",
|
||||
"npm:@types/node@^22.20.5",
|
||||
"npm:@types/ws@^8.18.1",
|
||||
"npm:autocannon@8",
|
||||
"npm:busboy@^1.6.0",
|
||||
|
||||
Generated
+9
-9
@@ -21,7 +21,7 @@
|
||||
"@types/autocannon": "^7.12.7",
|
||||
"@types/busboy": "^1.5.4",
|
||||
"@types/express": "^5.0.6",
|
||||
"@types/node": "^18.19.0",
|
||||
"@types/node": "^22.20.5",
|
||||
"@types/ws": "^8.18.1",
|
||||
"autocannon": "^8.0.0",
|
||||
"busboy": "^1.6.0",
|
||||
@@ -43,7 +43,7 @@
|
||||
"ws": "^8.21.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
"node": ">=22"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"busboy": "^1.6.0",
|
||||
@@ -2460,13 +2460,13 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.19.130",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.130.tgz",
|
||||
"integrity": "sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg==",
|
||||
"version": "22.20.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.5.tgz",
|
||||
"integrity": "sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~5.26.4"
|
||||
"undici-types": "~6.21.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/qs": {
|
||||
@@ -7876,9 +7876,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "5.26.5",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
|
||||
"version": "6.21.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
||||
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@
|
||||
"node"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
"node": ">=22"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
@@ -142,7 +142,7 @@
|
||||
"@types/autocannon": "^7.12.7",
|
||||
"@types/busboy": "^1.5.4",
|
||||
"@types/express": "^5.0.6",
|
||||
"@types/node": "^18.19.0",
|
||||
"@types/node": "^22.20.5",
|
||||
"@types/ws": "^8.18.1",
|
||||
"autocannon": "^8.0.0",
|
||||
"busboy": "^1.6.0",
|
||||
|
||||
+2
-2
@@ -1513,8 +1513,8 @@ function closeApp(
|
||||
timeoutMs,
|
||||
});
|
||||
|
||||
// closeAllConnections() requires Node >=18.2, same floor as closeIdleConnections()
|
||||
// below — `engines` in package.json only guarantees >=18, so this matters.
|
||||
// closeAllConnections() and closeIdleConnections() below both arrived in Node 18.2;
|
||||
// `engines` guarantees >=22, so both are always present.
|
||||
server.closeAllConnections();
|
||||
finish();
|
||||
}, drainBudget);
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ import { eventSocket, toWsRequest, upgradeSafely, type EventfulSocket } from './
|
||||
import { closeWithDeadline } from './http/shutdown';
|
||||
import { setPeer } from './http/peer';
|
||||
|
||||
// The project tsconfig's `lib` doesn't include `DOM`, and the installed `@types/node` (18.x)
|
||||
// doesn't declare a global `WebSocket` either — so we ambient-declare just the shape we use.
|
||||
// The project tsconfig's `lib` doesn't include `DOM`, so we ambient-declare just the shape of
|
||||
// Deno's `WebSocket` we use rather than rely on whichever global `@types/node` happens to declare.
|
||||
interface WebSocket extends EventfulSocket {
|
||||
binaryType: string;
|
||||
}
|
||||
|
||||
+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
|
||||
|
||||
@@ -56,11 +56,11 @@ function startSkewedTeapot() {
|
||||
|
||||
/**
|
||||
* Both client implementations, exercised on whatever Node runs the suite. `ws` is always in the
|
||||
* list: it is the Node 18-21 path, and on a modern CI the platform global would otherwise be the
|
||||
* only one ever covered — the fallback would rot unnoticed until someone ran the declared floor.
|
||||
* list: it is the fallback for a Node run with the global WebSocket switched off, and every
|
||||
* supported Node has the global, so it would otherwise never be covered and rot unnoticed.
|
||||
*/
|
||||
const platform = (globalThis as { WebSocket?: SocketCtor }).WebSocket;
|
||||
const CTORS: [string, SocketCtor][] = [['the ws package (Node < 22 path)', WS as unknown as SocketCtor]];
|
||||
const CTORS: [string, SocketCtor][] = [['the ws package (fallback path)', WS as unknown as SocketCtor]];
|
||||
if (platform) CTORS.push(['the platform global WebSocket', platform]);
|
||||
|
||||
describe('WebSocket client implementations', () => {
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
// The `engines` floor is `>=18`, and the global `crypto` only arrived unflagged in Node 19. That gap
|
||||
// shipped once: `correlateRequest` compiled cleanly against an ambient declaration and then threw
|
||||
// `ReferenceError: crypto is not defined` on the first request of every Node 18 process.
|
||||
//
|
||||
// CI's Node 18 job is what caught it, and this test is what makes it catchable without one — every
|
||||
// developer machine and every other runtime has the global, so the bug is invisible where it is
|
||||
// written. Stubbing the global away reproduces the floor's condition on any Node.
|
||||
//
|
||||
// If the floor ever moves above 18, this test and the fallback it guards can both go.
|
||||
describe('correlateRequest without a global crypto (Node 18)', () => {
|
||||
it('falls back to node:crypto instead of throwing ReferenceError', async () => {
|
||||
vi.stubGlobal('crypto', undefined);
|
||||
vi.resetModules();
|
||||
|
||||
const { correlateRequest } = await import('../src/http/core');
|
||||
const a = correlateRequest({});
|
||||
const b = correlateRequest({});
|
||||
|
||||
expect(a.requestId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
||||
expect(a.requestId).not.toBe(b.requestId);
|
||||
expect(correlateRequest({ 'x-request-id': 'from-gateway' }).requestId).toBe('from-gateway');
|
||||
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
});
|
||||
@@ -46,7 +46,7 @@ function runHarness(signal: NodeJS.Signals, env: NodeJS.ProcessEnv = {}, sendTwi
|
||||
// `process.execPath -r tsx/cjs`, not `npx tsx`: a wrapper puts the app one process further
|
||||
// down, and on Linux the signal then lands on the wrapper while the app never hears it — which
|
||||
// is exactly how this passed locally and failed in CI. `-r` rather than `--import`/`--loader`
|
||||
// because it is the one form that works on both the Node 18 floor CI builds against and the
|
||||
// because it is the one form that works on both the Node 22 floor CI builds against and the
|
||||
// current release.
|
||||
const proc = spawn(process.execPath, ['-r', 'tsx/cjs', 'test/interop/_signal-app.ts'], {
|
||||
env: { ...process.env, ...env },
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ export default defineConfig({
|
||||
dts: true,
|
||||
clean: true,
|
||||
sourcemap: true,
|
||||
target: 'node18',
|
||||
target: 'node22',
|
||||
// Give the ESM output a real `require` (via createRequire) so the lazy require('ws') / require('busboy')
|
||||
// (optional peer deps) resolve instead of hitting esbuild's "Dynamic require not supported" stub.
|
||||
esbuildOptions(options, context) {
|
||||
|
||||
Reference in new issue
Block a user