Merge pull request 'chore!: require Node 22 and clear dev audit advisories' (#122) from chore/audit-dev-deps into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 14s
CI / build (push) Successful in 26s
CI / runtimes (edge) (push) Successful in 13s
CI / runtimes (deno) (push) Successful in 30s
Promote → GitHub / push-github (push) Successful in 6s
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 14s
CI / build (push) Successful in 26s
CI / runtimes (edge) (push) Successful in 13s
CI / runtimes (deno) (push) Successful in 30s
Promote → GitHub / push-github (push) Successful in 6s
This commit was merged in pull request #122.
This commit is contained in:
commit
ed47836c98
17 files changed
+431
-601
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",
|
||||
@@ -35,7 +35,7 @@
|
||||
"npm:esbuild@0.27.2",
|
||||
"npm:eslint@^9.39.5",
|
||||
"npm:express@^5.2.1",
|
||||
"npm:fastify@^5.11.0",
|
||||
"npm:fastify@^5.12.5",
|
||||
"npm:graphql@^16.9.0",
|
||||
"npm:miniflare@^4.20260730.0",
|
||||
"npm:prettier@^3.9.6",
|
||||
@@ -46,7 +46,7 @@
|
||||
"npm:typescript-eslint@^8.65.0",
|
||||
"npm:typescript@^5.5.0",
|
||||
"npm:vite@^6.4.3",
|
||||
"npm:vitest@^3.2.7",
|
||||
"npm:vitest@^4.1.11",
|
||||
"npm:ws@^8.21.1"
|
||||
],
|
||||
"overrides": {
|
||||
@@ -56,7 +56,9 @@
|
||||
"uuid": "11.1.1"
|
||||
}
|
||||
},
|
||||
"undici": "7.29.0"
|
||||
"undici": "7.29.1",
|
||||
"sharp": "0.35.5",
|
||||
"fastify": "$fastify"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+387
-525
File diff suppressed because it is too large.
Load diff
+7
-5
@@ -26,7 +26,7 @@
|
||||
"node"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
"node": ">=22"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
@@ -128,7 +128,9 @@
|
||||
"uuid": "11.1.1"
|
||||
}
|
||||
},
|
||||
"undici": "7.29.0"
|
||||
"undici": "7.29.1",
|
||||
"sharp": "0.35.5",
|
||||
"fastify": "$fastify"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.5",
|
||||
@@ -140,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",
|
||||
@@ -148,7 +150,7 @@
|
||||
"eslint": "^9.39.5",
|
||||
"esbuild": "0.27.2",
|
||||
"express": "^5.2.1",
|
||||
"fastify": "^5.11.0",
|
||||
"fastify": "^5.12.5",
|
||||
"graphql": "^16.9.0",
|
||||
"miniflare": "^4.20260730.0",
|
||||
"prettier": "^3.9.6",
|
||||
@@ -158,7 +160,7 @@
|
||||
"typescript": "^5.5.0",
|
||||
"typescript-eslint": "^8.65.0",
|
||||
"vite": "^6.4.3",
|
||||
"vitest": "^3.2.7",
|
||||
"vitest": "^4.1.11",
|
||||
"ws": "^8.21.1"
|
||||
}
|
||||
}
|
||||
+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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
import { once } from 'node:events';
|
||||
@@ -39,7 +39,7 @@ function get(port: number, path: string, headers: Record<string, string> = {}):
|
||||
});
|
||||
}
|
||||
|
||||
function spyLogger(): Logger & { error: ReturnType<typeof vi.fn> } {
|
||||
function spyLogger(): Logger & { error: Mock<(...args: unknown[]) => void> } {
|
||||
return { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() };
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ async function expectServerStillServes(port: number): Promise<void> {
|
||||
|
||||
const settle = () => new Promise((r) => setTimeout(r, 20));
|
||||
|
||||
let unhandled: ReturnType<typeof vi.fn>;
|
||||
let uncaught: ReturnType<typeof vi.fn>;
|
||||
let unhandled: Mock<(...args: unknown[]) => void>;
|
||||
let uncaught: Mock<(...args: unknown[]) => void>;
|
||||
|
||||
beforeEach(() => {
|
||||
unhandled = vi.fn();
|
||||
|
||||
@@ -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