From 34409bea7e51d1748a4be9ade59129446e6fea83 Mon Sep 17 00:00:00 2001
From: Karl Horky <karl.horky@gmail.com>
Date: Fri, 19 Apr 2024 05:32:04 +0200
Subject: [PATCH] Fix npm 10 compatibility for real (#744)

---
 source/npm/util.js | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/source/npm/util.js b/source/npm/util.js
index 724271d6..02736fcb 100644
--- a/source/npm/util.js
+++ b/source/npm/util.js
@@ -138,12 +138,17 @@ export const checkIgnoreStrategy = async ({files}, rootDirectory) => {
 };
 
 export const getFilesToBePacked = async rootDirectory => {
-	const {stdout} = await execa('npm', ['pack', '--dry-run', '--json', '--silent'], {cwd: rootDirectory});
+	const {stdout} = await execa('npm', [
+		'pack',
+		'--dry-run',
+		'--json',
+		'--silent',
+		// TODO: Remove this once [npm/cli#7354](https://github.com/npm/cli/issues/7354) is resolved.
+		'--foreground-scripts=false',
+	], {cwd: rootDirectory});
 
 	try {
-		// TODO: Remove this once [npm/cli#7354](https://github.com/npm/cli/issues/7354) is resolved.
-		const cleanStdout = stdout.replace(/^[^[]*\[/, '[').trim();
-		const {files} = JSON.parse(cleanStdout).at(0);
+		const {files} = JSON.parse(stdout).at(0);
 		return files.map(file => file.path);
 	} catch (error) {
 		throw new Error('Failed to parse output of npm pack', {cause: error});