fix(compression): use pathToFileURL for workerUrl to prevent bundler resolution failure (#11364)

Merged via consolidated batch validation. Fixes Webpack/Turbopack production build failure (Module not found: compressionWorker.js) by using pathToFileURL(join(...)) instead of new URL(..., import.meta.url), which static bundler scanning misidentifies as an asset import.
This commit is contained in:
Nguyễn Viết Tuấn
2026-08-24 22:12:43 +07:00
committed by GitHub
parent 378eff0f75
commit 077bc1a8a2
2 changed files with 5 additions and 3 deletions

View File

@@ -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

View File

@@ -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<string, unknown>): CompressionResult {
return { body, compressed: false, stats: null };