From 4f1aa37893f1f5b89e16b4f599a55b5a4e1bf7bb Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Mon, 15 Apr 2024 20:17:41 -0500 Subject: [PATCH 1/2] fix: npm 10 bug with npm pack; issue 740 --- source/npm/util.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/npm/util.js b/source/npm/util.js index 5677847b..741cfb12 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -141,7 +141,8 @@ export const getFilesToBePacked = async rootDirectory => { const {stdout} = await execa('npm', ['pack', '--dry-run', '--json', '--silent'], {cwd: rootDirectory}); try { - const {files} = JSON.parse(stdout).at(0); + const cleanStdout = stdout.replace(/^[^[]*\[/, '[').trim(); + const {files} = JSON.parse(cleanStdout).at(0); return files.map(file => file.path); } catch (error) { throw new Error('Failed to parse output of npm pack', {cause: error}); From a262e80f90738fe4e1ac33457e5bab2b46a496c0 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Tue, 16 Apr 2024 13:52:39 -0500 Subject: [PATCH 2/2] chore: add code comment to npm/cli#7354 discussing 'npm pack' json issue --- source/npm/util.js | 1 + 1 file changed, 1 insertion(+) diff --git a/source/npm/util.js b/source/npm/util.js index 741cfb12..724271d6 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -141,6 +141,7 @@ export const getFilesToBePacked = async rootDirectory => { const {stdout} = await execa('npm', ['pack', '--dry-run', '--json', '--silent'], {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); return files.map(file => file.path);