Skip to content

Commit db71290

Browse files
author
Test
committed
🤖 fix: use lastIndexOf to find correct src directory
Change-Id: I8dd32f69c1ef9d48a0110e7103b3964c0191bfaf Signed-off-by: Test <test@example.com>
1 parent d8ee815 commit db71290

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/utils/main/workerPool.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Worker } from "node:worker_threads";
2-
import { join } from "node:path";
2+
import { join, dirname, sep } from "node:path";
33

44
interface WorkerRequest {
55
messageId: number;
@@ -28,9 +28,23 @@ const pendingPromises = new Map<
2828
{ resolve: (value: unknown) => void; reject: (error: Error) => void }
2929
>();
3030

31-
// Resolve worker path - both workerPool.js and tokenizer.worker.js compile to dist/utils/main/
32-
// Using __dirname ensures we always get the correct compiled location
33-
const workerPath = join(__dirname, "tokenizer.worker.js");
31+
// Resolve worker path
32+
// In production: both workerPool.js and tokenizer.worker.js are in dist/utils/main/
33+
// During tests: workerPool.ts is in src/utils/main/ but worker is in dist/utils/main/
34+
const currentDir = dirname(__filename);
35+
const pathParts = currentDir.split(sep);
36+
const srcIndex = pathParts.lastIndexOf("src");
37+
38+
let workerDir: string;
39+
if (srcIndex !== -1) {
40+
// Replace 'src' with 'dist' in the path
41+
pathParts[srcIndex] = "dist";
42+
workerDir = pathParts.join(sep);
43+
} else {
44+
workerDir = currentDir;
45+
}
46+
47+
const workerPath = join(workerDir, "tokenizer.worker.js");
3448
const worker = new Worker(workerPath);
3549

3650
// Handle messages from worker

0 commit comments

Comments
 (0)