Skip to content

Commit 0f07b2f

Browse files
committed
fix: detect Bun vs Node for worker loading
The previous fix used extname(__filename) === '.ts' to detect source execution, but ts-jest also sets __filename to .ts while running under Node. Node cannot load .ts workers directly (only Bun can), so we now check process.isBun to distinguish between: - Bun running .ts source -> use tokenizer.worker.ts - Node/ts-jest running .ts source -> use tokenizer.worker.js from dist/
1 parent 27f634f commit 0f07b2f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/node/utils/main/workerPool.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ const srcIndex = pathParts.lastIndexOf("src");
3939
let workerDir: string;
4040
let workerFile = "tokenizer.worker.js";
4141

42-
if (extname(__filename) === ".ts") {
43-
// Running from source (e.g. via Bun)
42+
// Check if we're running under Bun (not Node with ts-jest)
43+
// ts-jest transpiles .ts files but runs them via Node, which can't load .ts workers
44+
const isBun = !!(process as unknown as { isBun?: boolean }).isBun;
45+
46+
if (isBun && extname(__filename) === ".ts") {
47+
// Running from source via Bun - use .ts worker directly
4448
workerDir = currentDir;
4549
workerFile = "tokenizer.worker.ts";
4650
} else if (srcIndex !== -1 && !hasDist) {

0 commit comments

Comments
 (0)