/** * Worker entrypoint. Stubs the `server-only` import guard before loading any * src/lib code, then hands off to the real worker registry. * * Why: src/lib/** modules begin with `import 'server-only'` to keep RSC-only * code out of client bundles. That package throws when required outside Next's * React Server bundler. Workers are server code but run under plain Node/tsx, * so we resolve `server-only` to a no-op here — and ONLY here, so the app's * build-time guard is untouched. Mirrors the vitest alias in vitest.config.ts. */ import Module, { createRequire } from 'module'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const here = dirname(fileURLToPath(import.meta.url)); const NOOP = join(here, 'server-only.noop.cjs'); type ResolveFn = (request: string, ...rest: unknown[]) => string; const moduleInternals = Module as unknown as { _resolveFilename: ResolveFn }; const originalResolve = moduleInternals._resolveFilename; moduleInternals._resolveFilename = function (request, ...rest) { if (request === 'server-only') return NOOP; return originalResolve.call(this, request, ...rest); }; // Load the worker graph *after* the stub is installed (require keeps it // synchronous — tsx compiles this file to CJS, where top-level await is unavailable). const require = createRequire(import.meta.url); require('./index');