From ab1ade8c2987b6ce555bf01740903cc7f2181a90 Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Sun, 18 Oct 2026 21:50:15 +0200 Subject: [PATCH] Keep the user's package.json when loading a script To load a .js script as CommonJS, Browsertime wrote an empty package.json next to the script and then deleted it. If the folder already had a package.json, it was overwritten and then deleted, so the user lost their file. Now the temporary file is only created when no package.json exists, and only that temporary file is removed. Assisted-by: Claude Opus 5.5 noreply@anthropic.com --- lib/support/engineUtils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/support/engineUtils.js b/lib/support/engineUtils.js index 7809e71e4..289baf492 100644 --- a/lib/support/engineUtils.js +++ b/lib/support/engineUtils.js @@ -58,7 +58,8 @@ async function loadFile(script, options, throwError) { 'package.json' ); try { - await writeFile(packageJson, '{}'); + // Do not overwrite a package.json that the user owns + await writeFile(packageJson, '{}', { flag: 'wx' }); createdPackageJson = true; } catch { log.error(