7 Commits
Author SHA1 Message Date
chrnx b7a852ac92 fix(build): let the npm ESM build load on workerd (#93)
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 19s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 23s
CI / runtimes (deno) (pull_request) Successful in 33s
tsup.config.ts gives every ESM output a banner that calls
createRequire(import.meta.url) at module scope, so the lazy
require('ws') / require('busboy') resolve. On workerd import.meta.url
is not a file URL: createRequire throws during module evaluation and
the worker fails to start. dist/edge.mjs, and the chunk it shares with
the other entry points, could therefore not be loaded from npm at all.
test/edge/run.ts bundles src/, which has no banner, so it never saw it.

The banner now wraps the call in a try and leaves `require` undefined
when it throws. esbuild's __require shim and src/node-require.ts
already handle an undefined require: the latter falls back to
process.getBuiltinModule, and its callers report a missing module in
their own terms. The static node:module import is kept: edge already
requires nodejs_compat, which provides it, and dropping it for
getBuiltinModule would lose Node 22.0-22.2, which lack that API.
Building edge separately was ruled out because it would duplicate
module state (MARK_EDGE) between @green-tea/core and its /edge entry.

test/edge/dist.ts bundles a worker that imports dist/index.mjs and
dist/edge.mjs, as wrangler does with the installed package, and serves
a request on Miniflare. It fails with the old banner and passes now.
npm run test:edge builds before running it, so CI's edge job covers it.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-24 22:52:07 -05:00
chrnx dd3a74afcd Merge pull request 'fix(transformers)!: answer 204 when a handler returns undefined (GitHub #38)' (#172) from fix/undefined-return-204 into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 20s
CI / build (push) Successful in 32s
CI / runtimes (edge) (push) Successful in 20s
CI / runtimes (deno) (push) Successful in 32s
Promote → GitHub / push-github (push) Successful in 6s
2026-10-25 03:51:58 +00:00
chrnx 40702aef2a fix(transformers)!: answer 204 when a handler returns undefined (GitHub #38)
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 21s
CI / runtimes (deno) (pull_request) Successful in 33s
JsonTransformer passed the handler's value to JSON.stringify, which
returns undefined for undefined, while TransformerFn promises a string
body. The Node server wrote that as an empty 200 with content-type
application/json; the fetch adapter's toBodyInit read `body.buffer` on
it and threw, so Deno, Bun and the edge answered 500 for a handler with
no `return`.

JsonTransformer now returns status 204 and an empty body (no headers)
for undefined. outcomeToResponse already sends a null body for 204 and
the Node server ends with the empty string, so all four runtimes give
the same answer. null is a JSON value and still renders as 200 `null`.
Routes with their own @Transformer are unchanged.

BREAKING CHANGE: a handler with no return value now answers 204 instead
of an empty 200 on Node (and instead of 500 elsewhere). Return a value
to keep a 200.

test/undefined-return.test.ts covers app.fetch and the Node server
(both fail without the fix) and pins null to 200.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-24 22:49:46 -05:00
chrnx 3fc43eb7ad Merge pull request 'fix(params): match @header names without case (GitHub #37)' (#171) from fix/header-decorator-case into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Failing after 12s
CI / build (push) Successful in 29s
CI / runtimes (deno) (push) Successful in 34s
CI / runtimes (edge) (push) Successful in 18s
Promote → GitHub / push-github (push) Successful in 6s
2026-10-25 03:49:42 +00:00
chrnx bc04330a27 fix(params): match @header names without case (GitHub #37)
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 30s
CI / runtimes (edge) (pull_request) Successful in 19s
CI / runtimes (deno) (pull_request) Successful in 34s
Node's IncomingHttpHeaders and the fetch adapter's headersToRecord
both store request header names lower-cased, but resolveOne looked a
@header/@headers key up exactly as the decorator wrote it. Any name
with a capital letter, such as @header('Content-Type'), therefore
reached the handler as undefined.

resolveOne now lower-cases the key for the headers source before the
lookup. A picked bag (@headers([...])) keeps the names as written, so a
handler reads back the key it asked for; @headers() with no argument
still returns the whole lower-cased bag.

test/params.test.ts covers the single and picked forms on resolveArgs;
test/header-case.test.ts sends a request over app.fetch and the Node
server. All three fail without the fix.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-24 22:36:18 -05:00
chrnx cf5df70c62 Merge pull request 'fix(multipart): accept exactly maxParts parts (#118)' (#170) from fix/multipart-max-parts-boundary into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 20s
CI / build (push) Successful in 30s
CI / runtimes (edge) (push) Successful in 20s
CI / runtimes (deno) (push) Successful in 33s
Promote → GitHub / push-github (push) Successful in 6s
2026-10-25 03:36:02 +00:00
chrnx 5536093894 fix(multipart): accept exactly maxParts parts (#118)
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 30s
CI / runtimes (edge) (pull_request) Successful in 19s
CI / runtimes (deno) (pull_request) Successful in 34s
busboy emits `partsLimit` once its part count reaches `limits.parts`,
not when it passes it, and parseMultipart treats that event as a
malformed body. With `maxParts: N` a body of exactly N parts was
therefore rejected with 400 and only N-1 were accepted.

parseMultipart now passes `maxParts + 1` to busboy, the same one-unit
headroom it already gives `fieldSize`. N parts are accepted, N+1 are
rejected. Route-level and server-level maxParts share this path, as do
the Node server and app.fetch.

test/multipart.test.ts adds the exact-N case on parseMultipart;
test/multipart-http.test.ts sends exactly N parts at route and server
level. All three new assertions fail without the fix.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-24 22:21:10 -05:00
14 changed files with 214 additions and 11 deletions

No files matched your search

+1
View File
@@ -23,6 +23,7 @@ coverage/
test/edge/_worker.mjs test/edge/_worker.mjs
test/edge/_parity-worker.mjs test/edge/_parity-worker.mjs
test/edge/_compression-worker.mjs test/edge/_compression-worker.mjs
test/edge/_dist-worker.mjs
# Bun writes this on `bun install`, and nothing here consumes it: `npm run test:bun` runs # Bun writes this on `bun install`, and nothing here consumes it: `npm run test:bun` runs
# `bun test` against the node_modules npm installed, which package-lock.json already pins. # `bun test` against the node_modules npm installed, which package-lock.json already pins.
+28
View File
@@ -126,6 +126,15 @@ npm treats versions as semver and semver forbids leading zeros.
migrate, remove the token from the node's `needs`, or move the work that produces it into a migrate, remove the token from the node's `needs`, or move the work that produces it into a
separate provider or step the node needs. separate provider or step the node needs.
- **A handler that returns `undefined` answers `204 No Content`** (GitHub #38). The default JSON
transformer passed the value to `JSON.stringify`, which returns `undefined` rather than a string:
the Node server sent an empty `200` with `content-type: application/json`, and the fetch adapter
threw a `TypeError`, so Deno, Bun and the edge answered `500` for a handler that did nothing
wrong. Every runtime now sends `204` with no body and no `content-type`. A handler that returns
`null` still gets `200` with `null`. A client that checked for `200` after a handler with no
`return` sees `204` instead; return a value to keep a `200`. A route with its own `@Transformer`
is not affected.
### Added ### Added
- **Health probes: `createApp({ health: true })`** (#115). Off by default. `GET`/`HEAD /__live__` - **Health probes: `createApp({ health: true })`** (#115). Off by default. `GET`/`HEAD /__live__`
@@ -327,6 +336,25 @@ npm treats versions as semver and semver forbids leading zeros.
handing the handler partial data. The Node server and `app.fetch` parse multipart through the handing the handler partial data. The Node server and `app.fetch` parse multipart through the
same path, so the fix applies to both. same path, so the fix applies to both.
- **`maxParts: N` accepts exactly N parts** (#118). busboy signals its parts limit once the count
reaches it, so a body of exactly `maxParts` parts was rejected with `400 Invalid multipart body`
and only N−1 got through. busboy now gets one part of headroom, the same way `fieldSize` does:
N parts are accepted and N+1 are rejected, as the option's name says. Both the route-level and
the server-level `maxParts` were affected, on the Node server and `app.fetch` alike.
- **`@header('Content-Type')` finds the header** (GitHub #37). Every adapter stores request
header names lower-cased, and `@header`/`@headers` looked the name up as written, so any name
with a capital letter reached the handler as `undefined`. The name is now matched without case.
`@headers(['X-Trace'])` keeps the names as written in the bag it hands over, so the handler reads
`X-Trace` back; `@headers()` with no argument still returns the lower-cased bag. Node, Deno, Bun
and the edge share this path.
- **The npm ESM build loads on Cloudflare Workers** (#93). tsup gives every ESM file a
`createRequire(import.meta.url)` banner so the lazy `require('ws')`/`require('busboy')` work, and
it ran at module scope. On workerd `import.meta.url` is not a file URL, so `createRequire` threw
and the whole worker failed to load: `@green-tea/core/edge` from npm could not be used at all.
The edge suite never noticed because it bundles `src/`. The call is now guarded; where it fails,
`require` is left undefined and the existing fallback takes over. `npm run test:edge` now also
builds and boots the published `dist/` on workerd. Node, Deno, Bun and JSR are unchanged.
- **`listen()` rejects when the port is taken** (#138). A bind failure such as `EADDRINUSE` or - **`listen()` rejects when the port is taken** (#138). A bind failure such as `EADDRINUSE` or
`EACCES` arrives as the server's `error` event, which `listen()` did not handle: the promise `EACCES` arrives as the server's `error` event, which `listen()` did not handle: the promise
never settled, and the error surfaced as an unhandled one. It now rejects with that error. The never settled, and the error surfaced as an unhandled one. It now rejects with that error. The
+1 -1
View File
@@ -90,7 +90,7 @@
"test:dev": "vitest", "test:dev": "vitest",
"test:deno": "deno test --allow-net --allow-read --allow-run --allow-env --no-check test/deno/", "test:deno": "deno test --allow-net --allow-read --allow-run --allow-env --no-check test/deno/",
"test:bun": "bun test test/bun/", "test:bun": "bun test test/bun/",
"test:edge": "tsx test/edge/run.ts && tsx test/edge/compression.ts", "test:edge": "tsx test/edge/run.ts && tsx test/edge/compression.ts && npm run build && tsx test/edge/dist.ts",
"test:all": "npm test && npm run test:deno && npm run test:bun && npm run test:edge && deno publish --dry-run --allow-dirty", "test:all": "npm test && npm run test:deno && npm run test:bun && npm run test:edge && deno publish --dry-run --allow-dirty",
"typecheck": "tsc --noEmit -p tsconfig.json", "typecheck": "tsc --noEmit -p tsconfig.json",
"typecheck:bench": "tsc --noEmit -p bench/tsconfig.json", "typecheck:bench": "tsc --noEmit -p bench/tsconfig.json",
+4 -1
View File
@@ -99,11 +99,14 @@ export function parseMultipart(raw: Buffer, boundary: string, opts: MultipartOpt
// busboy flags a field as truncated once it *reaches* `fieldSize`, so a field of exactly // busboy flags a field as truncated once it *reaches* `fieldSize`, so a field of exactly
// `maxFieldBytes` needs one byte of headroom to count as whole. // `maxFieldBytes` needs one byte of headroom to count as whole.
const fieldSize = opts.maxFieldBytes === undefined ? undefined : opts.maxFieldBytes + 1; const fieldSize = opts.maxFieldBytes === undefined ? undefined : opts.maxFieldBytes + 1;
// Same for parts: busboy emits `partsLimit` once the count *reaches* `parts`, so a body of
// exactly `maxParts` parts needs one of headroom to be accepted (Gitea #118).
const parts = opts.maxParts + 1;
try { try {
bb = busboy({ bb = busboy({
headers: { 'content-type': `multipart/form-data; boundary=${boundary}` }, headers: { 'content-type': `multipart/form-data; boundary=${boundary}` },
limits: { parts: opts.maxParts, fieldSize }, limits: { parts, fieldSize },
}); });
} catch { } catch {
return fail(); return fail();
+5 -2
View File
@@ -147,14 +147,17 @@ function resolveOne(spec: ArgSpec, context: Context): unknown {
const bag = spec.source === 'cookies' ? cookiesOf(context) : context[spec.source]; const bag = spec.source === 'cookies' ? cookiesOf(context) : context[spec.source];
if (typeof bag !== 'object' || bag === null) return bag; // can't pick from a non-object; return as-is if (typeof bag !== 'object' || bag === null) return bag; // can't pick from a non-object; return as-is
const values = bag as Record<string, unknown>; const values = bag as Record<string, unknown>;
// Every adapter stores header names lower-cased, so `@header('Content-Type')` looks up
// `content-type` (GitHub #37). A picked bag keeps the names as the handler wrote them.
const at = spec.source === 'headers' ? (key: string) => values[key.toLowerCase()] : (key: string) => values[key];
if (spec.keys) { if (spec.keys) {
const picked: Record<string, unknown> = {}; const picked: Record<string, unknown> = {};
for (const key of spec.keys) picked[key] = values[key]; for (const key of spec.keys) picked[key] = at(key);
return picked; return picked;
} }
if (spec.key !== undefined) return values[spec.key]; if (spec.key !== undefined) return at(spec.key);
return values; return values;
} }
+8 -6
View File
@@ -24,12 +24,14 @@ export interface ErrorRequest {
*/ */
export type ErrorRenderer = (error: unknown, req: ErrorRequest) => ErrorResponse | undefined | void; export type ErrorRenderer = (error: unknown, req: ErrorRequest) => ErrorResponse | undefined | void;
/** Default transformer: serialize a handler's return value as a JSON `200` response. */ /**
export const JsonTransformer: TransformerFn = (value) => ({ * Default transformer: serialize a handler's return value as a JSON `200` response. A handler that
status: 200, * returns `undefined` (no `return`) answers `204 No Content` with no body, on every runtime (GitHub #38).
headers: { 'content-type': 'application/json' }, */
body: JSON.stringify(value), export const JsonTransformer: TransformerFn = (value) => {
}); if (value === undefined) return { status: 204, body: '' };
return { status: 200, headers: { 'content-type': 'application/json' }, body: JSON.stringify(value) };
};
/** /**
* Map a thrown value to a JSON error response (422 for validation, `HttpError` status, else 500). * Map a thrown value to a JSON error response (422 for validation, `HttpError` status, else 500).
+16
View File
@@ -0,0 +1,16 @@
// Worker entry for test/edge/dist.ts: the npm ESM build as an app installs it, not `src/`.
import { createApp, Route, Get, Module } from '../../dist/index.mjs';
import { edgeHandler } from '../../dist/edge.mjs';
@Route('/rt')
class Rt {
@Get('/hello')
hello() {
return { ok: true };
}
}
@Module({ mountpoint: '/', controllers: [Rt] })
class AppModule {}
export default { fetch: edgeHandler(createApp({ modules: [AppModule] })) };
+46
View File
@@ -0,0 +1,46 @@
// #93: the published `dist/` ESM build must load on workerd. test/edge/run.ts bundles `src/`, so it
// never saw tsup's `createRequire` banner, which ran at module scope and threw there because
// `import.meta.url` is not a file URL. `npm run test:edge` builds first.
//
// Run with: npm run test:edge
import { strict as assert } from 'node:assert';
import { existsSync } from 'node:fs';
import { build } from 'esbuild';
import { Miniflare } from 'miniflare';
const BUNDLE = 'test/edge/_dist-worker.mjs';
async function main() {
if (!existsSync('dist/edge.mjs')) throw new Error('dist/edge.mjs is missing: run `npm run build` first');
// Same bundling as run.ts, which is what wrangler does with an installed package.
await build({
entryPoints: ['test/edge/dist-worker.ts'],
bundle: true,
format: 'esm',
outfile: BUNDLE,
platform: 'browser',
target: 'esnext',
external: ['node:*', 'http', 'https'],
alias: { stream: 'node:stream', events: 'node:events', zlib: 'node:zlib', crypto: 'node:crypto' },
});
const mf = new Miniflare({
modules: true,
scriptPath: BUNDLE,
compatibilityDate: '2024-11-01',
compatibilityFlags: ['nodejs_compat'],
});
try {
const res = await mf.dispatchFetch('http://localhost/rt/hello');
assert.equal(res.status, 200);
assert.deepEqual(await res.json(), { ok: true });
console.log('edge dist: OK (the npm ESM build loads and serves on workerd)');
} finally {
await mf.dispose();
}
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
+36
View File
@@ -0,0 +1,36 @@
// GitHub #37: `@header('Content-Type')` reached the handler as undefined, because every adapter
// stores header names lower-cased and the lookup used the name as written.
import 'reflect-metadata';
import { afterEach, describe, expect, it } from 'vitest';
import type { AddressInfo } from 'node:net';
import type { Server } from 'node:http';
import { createApp, Get, Module, Route, header } from '../src/index';
@Route('/')
class Ctl {
@Get('/h') h(@header('Content-Type') ct: unknown, @header('X-Trace') trace: unknown) {
return { ct: ct ?? null, trace: trace ?? null };
}
}
@Module({ mountpoint: '/', controllers: [Ctl] })
class M {}
const sent = { 'content-type': 'text/plain', 'x-trace': 'abc' };
const expected = { ct: 'text/plain', trace: 'abc' };
describe('@header matches the name without case (GitHub #37)', () => {
let server: Server | undefined;
afterEach(() => new Promise<void>((resolve) => (server ? server.close(() => resolve()) : resolve())));
it('on app.fetch', async () => {
const app = createApp({ modules: [M] });
expect(await (await app.fetch(new Request('http://x/h', { headers: sent }))).json()).toEqual(expected);
});
it('on the Node server', async () => {
server = await createApp({ modules: [M] }).listen(0);
const r = await fetch(`http://127.0.0.1:${(server.address() as AddressInfo).port}/h`, { headers: sent });
expect(await r.json()).toEqual(expected);
});
});
+2
View File
@@ -147,6 +147,7 @@ describe('multipart limits on app.fetch (#105)', () => {
@Module({ mountpoint: '/', controllers: [C] }) class CMod {} @Module({ mountpoint: '/', controllers: [C] }) class CMod {}
app = createApp({ modules: [CMod] }); app = createApp({ modules: [CMod] });
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(2) }))).status).toBe(200); // #118
const r = await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) })); const r = await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) }));
expect(r.status).toBe(400); expect(r.status).toBe(400);
@@ -175,6 +176,7 @@ describe('multipart limits on app.fetch (#105)', () => {
app = createApp({ modules: [CMod], limits: { maxParts: 2 } }); app = createApp({ modules: [CMod], limits: { maxParts: 2 } });
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(1) }))).status).toBe(200); expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(1) }))).status).toBe(200);
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(2) }))).status).toBe(200);
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) }))).status).toBe(400); expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) }))).status).toBe(400);
}); });
}); });
+6
View File
@@ -79,6 +79,12 @@ describe('parseMultipart', () => {
await expect(parseMultipart(b, B, { maxParts: 2, duplicates: 'last' })).rejects.toThrow(); await expect(parseMultipart(b, B, { maxParts: 2, duplicates: 'last' })).rejects.toThrow();
}); });
// Gitea #118: busboy signals the limit when the count reaches it, which used to reject exactly N.
it('exactly maxParts parts → accepted', async () => {
const b = body([field('a', '1'), field('b', '2')]);
expect((await parseMultipart(b, B, { maxParts: 2, duplicates: 'last' })).fields).toEqual({ a: '1', b: '2' });
});
// GitHub #39: busboy cuts a field at its size limit and only flags it, so the parser has to refuse // GitHub #39: busboy cuts a field at its size limit and only flags it, so the parser has to refuse
// the body rather than hand the handler partial data. // the body rather than hand the handler partial data.
it('a field over maxFieldBytes → rejects with 413 instead of truncating', async () => { it('a field over maxFieldBytes → rejects with 413 instead of truncating', async () => {
+10
View File
@@ -110,6 +110,16 @@ describe('@headers / @header', () => {
expect(args[1]).toEqual({ authorization: 'Bearer t0ken', 'x-trace': 'abc' }); expect(args[1]).toEqual({ authorization: 'Bearer t0ken', 'x-trace': 'abc' });
}); });
// GitHub #37: adapters store header names lower-cased; the decorator name is matched without case.
it('@header and @headers([...]) match the name without case, keeping the written names', async () => {
class Ctl {
handle(@header('Authorization') _auth: string, @headers(['X-Trace', 'x-count']) _some: unknown) {}
}
const args = await resolveArgs(getArgs(Ctl, 'handle'), { headers: reqHeaders });
expect(args[0]).toBe('Bearer t0ken');
expect(args[1]).toEqual({ 'X-Trace': 'abc', 'x-count': '5' });
});
it('@header(name, schema) validates the picked header', async () => { it('@header(name, schema) validates the picked header', async () => {
class Ctl { class Ctl {
handle(@header('x-count', numFromStr) _count: number) {} handle(@header('x-count', numFromStr) _count: number) {}
+45
View File
@@ -0,0 +1,45 @@
// GitHub #38: `JSON.stringify(undefined)` is `undefined`, so a handler with no `return` gave an
// empty 200 on Node and a 500 (a TypeError in the fetch adapter) on Deno, Bun and the edge. It now
// answers 204 with no body everywhere.
import 'reflect-metadata';
import { afterEach, describe, expect, it } from 'vitest';
import type { AddressInfo } from 'node:net';
import type { Server } from 'node:http';
import { createApp, Get, Module, Route } from '../src/index';
@Route('/')
class Ctl {
@Get('/none') none() {}
@Get('/null') nul() {
return null;
}
}
@Module({ mountpoint: '/', controllers: [Ctl] })
class M {}
describe('a handler that returns undefined answers 204 (GitHub #38)', () => {
let server: Server | undefined;
afterEach(() => new Promise<void>((resolve) => (server ? server.close(() => resolve()) : resolve())));
it('on app.fetch', async () => {
const r = await createApp({ modules: [M] }).fetch(new Request('http://x/none'));
expect(r.status).toBe(204);
expect(r.headers.get('content-type')).toBeNull();
expect(await r.text()).toBe('');
});
it('on the Node server', async () => {
server = await createApp({ modules: [M] }).listen(0);
const r = await fetch(`http://127.0.0.1:${(server.address() as AddressInfo).port}/none`);
expect(r.status).toBe(204);
expect(r.headers.get('content-type')).toBeNull();
expect(await r.text()).toBe('');
});
it('null is still a JSON value: 200 with `null`', async () => {
const r = await createApp({ modules: [M] }).fetch(new Request('http://x/null'));
expect(r.status).toBe(200);
expect(await r.text()).toBe('null');
});
});
+6 -1
View File
@@ -12,10 +12,15 @@ export default defineConfig({
target: 'node22', target: 'node22',
// Give the ESM output a real `require` (via createRequire) so the lazy require('ws') / require('busboy') // 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. // (optional peer deps) resolve instead of hitting esbuild's "Dynamic require not supported" stub.
// The call is guarded because it runs at module scope: on workerd `import.meta.url` is not a file
// URL and `createRequire` throws, which failed the whole worker at load (#93). `require` is then
// undefined, and src/node-require.ts falls back to `process.getBuiltinModule` or reports the miss
// in its callers' own terms. The static `node:module` import stays: edge already needs
// `nodejs_compat`, which provides it, and Node 22.0-22.2 have no `getBuiltinModule` to replace it.
esbuildOptions(options, context) { esbuildOptions(options, context) {
if (context.format === 'esm') { if (context.format === 'esm') {
options.banner = { options.banner = {
js: "import { createRequire as _createRequire } from 'node:module'; const require = _createRequire(import.meta.url);", js: "import { createRequire as _createRequire } from 'node:module'; const require = (() => { try { return _createRequire(import.meta.url); } catch { return undefined; } })();",
}; };
} }
}, },