diff --git a/changelog.d/fixes/compression-worker-bundler-resolve.md b/changelog.d/fixes/compression-worker-bundler-resolve.md new file mode 100644 index 0000000000..3a867303d6 --- /dev/null +++ b/changelog.d/fixes/compression-worker-bundler-resolve.md @@ -0,0 +1 @@ +- **fix(compression):** use `pathToFileURL` in `compressionWorkerPool` so bundlers (Webpack / Turbopack) do not attempt static asset resolution of missing `compressionWorker.js` during build diff --git a/open-sse/services/compression/compressionWorkerPool.ts b/open-sse/services/compression/compressionWorkerPool.ts index c3f0f839c1..109940a14d 100644 --- a/open-sse/services/compression/compressionWorkerPool.ts +++ b/open-sse/services/compression/compressionWorkerPool.ts @@ -1,6 +1,6 @@ import { existsSync } from "node:fs"; import { dirname, join } from "node:path"; -import { fileURLToPath } from "node:url"; +import { fileURLToPath, pathToFileURL } from "node:url"; import { Worker } from "node:worker_threads"; import type { CompressionResult } from "./types.ts"; import type { StackedCompressionStep } from "./strategySelector.ts"; @@ -17,9 +17,10 @@ function positiveInteger(value: string | undefined, fallback: number): number { function workerUrl(): URL { const dir = dirname(fileURLToPath(import.meta.url)); for (const name of ["compressionWorker.js", "compressionWorker.ts"]) { - if (existsSync(join(dir, name))) return new URL(name, import.meta.url); + const candidate = join(dir, name); + if (existsSync(candidate)) return pathToFileURL(candidate); } - return new URL("compressionWorker.js", import.meta.url); + return pathToFileURL(join(dir, "compressionWorker.js")); } function unchanged(body: Record): CompressionResult { return { body, compressed: false, stats: null };