From abf62601fb7423b3349d8039c10a9526be1d34b5 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 16 May 2023 16:42:52 -0400 Subject: [PATCH] avoid using isMainThread, since it interacts poorly with vitest --- packages/kit/src/utils/fork.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/kit/src/utils/fork.js b/packages/kit/src/utils/fork.js index bfdc0f281051..cbf24ac1ba6e 100644 --- a/packages/kit/src/utils/fork.js +++ b/packages/kit/src/utils/fork.js @@ -1,5 +1,5 @@ import { fileURLToPath } from 'node:url'; -import { Worker, isMainThread, parentPort } from 'node:worker_threads'; +import { Worker, parentPort } from 'node:worker_threads'; /** * Runs a task in a subprocess so any dangling stuff gets killed upon completion. @@ -11,7 +11,7 @@ import { Worker, isMainThread, parentPort } from 'node:worker_threads'; * @returns {(opts: T) => Promise} A function that when called starts the subprocess */ export function forked(module, callback) { - if (!isMainThread && parentPort) { + if (process.env.SVELTEKIT_FORK && parentPort) { parentPort.on( 'message', /** @param {any} data */ async (data) => { @@ -36,7 +36,8 @@ export function forked(module, callback) { return new Promise((fulfil, reject) => { const worker = new Worker(fileURLToPath(module), { env: { - ...process.env + ...process.env, + SVELTEKIT_FORK: 'true' } });