File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 11import { Worker } from "node:worker_threads" ;
2- import { join } from "node:path" ;
2+ import { join , dirname , sep } from "node:path" ;
33
44interface 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" ) ;
3448const worker = new Worker ( workerPath ) ;
3549
3650// Handle messages from worker
You can’t perform that action at this time.
0 commit comments