Skip to content

Commit 4a5ff11

Browse files
authored
fix: prevent double dist substitution in worker path resolution (#508)
When workerPool.ts runs from dist/, the existing logic would incorrectly try to replace 'src' with 'dist' again, leading to malformed paths like dist/utils/main/dist/utils/main/worker.js. Now checks if 'dist' already exists in the path before performing the src->dist replacement, ensuring correct worker resolution in both development (src/) and production (dist/) contexts.
1 parent 4e04915 commit 4a5ff11

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/utils/main/workerPool.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ const pendingPromises = new Map<
3333
// During tests: workerPool.ts is in src/utils/main/ but worker is in dist/utils/main/
3434
const currentDir = dirname(__filename);
3535
const pathParts = currentDir.split(sep);
36+
const hasDist = pathParts.includes("dist");
3637
const srcIndex = pathParts.lastIndexOf("src");
3738

3839
let workerDir: string;
39-
if (srcIndex !== -1) {
40-
// Replace 'src' with 'dist' in the path
40+
if (srcIndex !== -1 && !hasDist) {
41+
// Replace 'src' with 'dist' in the path (only if not already in dist)
4142
pathParts[srcIndex] = "dist";
4243
workerDir = pathParts.join(sep);
4344
} else {

0 commit comments

Comments
 (0)