From 22fc782653b65b5d4b623716526a83c0b925f938 Mon Sep 17 00:00:00 2001 From: kapilvus Date: Wed, 17 Jun 2026 23:04:06 +0530 Subject: [PATCH] fix(run-multiple): avoid temp.mjs filename collision across forked processes When run-multiple forks N concurrent processes, each process transpiles the same .ts files (config, helpers, includes) to identically named *.temp.mjs files. A process that finishes first deletes its temp file, causing other processes that haven't imported it yet to fail with "Cannot find module *.temp.mjs". Fix: embed process.pid in the temp filename so every worker writes its own isolated copy. Cleanup still works because allTempFiles is built from transpiledFiles.values(), which already contains the pid-suffixed paths. The .includes('.temp.mjs') substring check in step/base.js continues to match the new *.{pid}.temp.mjs filenames. Fixes #5642 --- lib/utils/typescript.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/utils/typescript.js b/lib/utils/typescript.js index 5f9d0d417..3f75c07f9 100644 --- a/lib/utils/typescript.js +++ b/lib/utils/typescript.js @@ -385,7 +385,9 @@ const __dirname = __dirname_fn(__filename); ) // Write the transpiled file with updated imports - const tempFile = filePath.replace(/\.ts$/, '.temp.mjs') + // Use process.pid in the filename to avoid collisions when run-multiple forks + // several processes that all transpile the same .ts files concurrently. + const tempFile = filePath.replace(/\.ts$/, `.${process.pid}.temp.mjs`) fs.writeFileSync(tempFile, jsContent) transpiledFiles.set(filePath, tempFile) }