From 9fcf6536068c0accc3f1304b3346645f4edc5b48 Mon Sep 17 00:00:00 2001 From: mkorwel Date: Fri, 26 Sep 2025 08:44:55 -0700 Subject: [PATCH] be smarter about ls issues. --- scripts/version.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/scripts/version.js b/scripts/version.js index 3d3a5e29c9..144d4a8212 100644 --- a/scripts/version.js +++ b/scripts/version.js @@ -36,9 +36,35 @@ run(`npm version ${versionType} --no-git-tag-version --allow-same-version`); // 3. Get all workspaces and filter out the one we don't want to version. const workspacesToExclude = []; -const lsOutput = JSON.parse( - execSync('npm ls --workspaces --json --depth=0').toString(), -); +let lsOutput; +try { + lsOutput = JSON.parse( + execSync('npm ls --workspaces --json --depth=0').toString(), + ); +} catch (e) { + // `npm ls` can exit with a non-zero status code if there are issues + // with dependencies, but it will still produce the JSON output we need. + // We'll try to parse the stdout from the error object. + if (e.stdout) { + console.warn( + 'Warning: `npm ls` exited with a non-zero status code. Attempting to proceed with the output.', + ); + try { + lsOutput = JSON.parse(e.stdout.toString()); + } catch (parseError) { + console.error( + 'Error: Failed to parse JSON from `npm ls` output even after `npm ls` failed.', + ); + console.error('npm ls stderr:', e.stderr.toString()); + console.error('Parse error:', parseError); + process.exit(1); + } + } else { + console.error('Error: `npm ls` failed with no output.'); + console.error(e.stderr?.toString() || e); + process.exit(1); + } +} const allWorkspaces = Object.keys(lsOutput.dependencies || {}); const workspacesToVersion = allWorkspaces.filter( (wsName) => !workspacesToExclude.includes(wsName),