From 1bcc5e3b03e613310c6ab336675c23e4e1aff827 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Wed, 4 Jun 2025 17:22:15 +0700 Subject: [PATCH] fix: register ts-node in test environments if consumer project passes a .ts source file --- src/helpers/worker-thread-manager.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/helpers/worker-thread-manager.ts b/src/helpers/worker-thread-manager.ts index 2087dbe..09eec6c 100644 --- a/src/helpers/worker-thread-manager.ts +++ b/src/helpers/worker-thread-manager.ts @@ -1,6 +1,5 @@ import * as WorkerThreads from 'node:worker_threads'; import * as os from 'node:os'; -import * as path from 'node:path'; import { EventEmitter, addAbortListener } from 'node:events'; import { waiter, Waiter } from './time'; import { deserializeError, isErrorLike } from './serialize-error'; @@ -124,7 +123,9 @@ export class WorkerThreadManager { const workerOpt: WorkerThreads.WorkerOptions = { workerData, }; - if (path.extname(workerThreadInitFilename) === '.ts') { + const hasTsSource = + workerThreadInitFilename.endsWith('.ts') || this.workerFile.endsWith('.ts'); + if (hasTsSource) { if (process.env.NODE_ENV !== 'test') { throw new Error( 'Worker threads are being created with ts-node outside of a test environment'