From fab356d9c44075e465a10828f38b4c2c4b044794 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 2 Oct 2024 20:13:39 -1000 Subject: [PATCH] fix(plugin-workspace-tools): report errors for all non-zero exit codes --- .yarn/versions/30ae755e.yml | 32 +++++++++++++++++++ .../sources/commands/foreach.ts | 16 ++++++---- 2 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 .yarn/versions/30ae755e.yml diff --git a/.yarn/versions/30ae755e.yml b/.yarn/versions/30ae755e.yml new file mode 100644 index 000000000000..11300a475dea --- /dev/null +++ b/.yarn/versions/30ae755e.yml @@ -0,0 +1,32 @@ +releases: + "@yarnpkg/builder": patch + "@yarnpkg/cli": patch + "@yarnpkg/core": patch + "@yarnpkg/doctor": patch + "@yarnpkg/extensions": patch + "@yarnpkg/nm": patch + "@yarnpkg/plugin-compat": patch + "@yarnpkg/plugin-constraints": patch + "@yarnpkg/plugin-dlx": patch + "@yarnpkg/plugin-essentials": patch + "@yarnpkg/plugin-exec": patch + "@yarnpkg/plugin-file": patch + "@yarnpkg/plugin-git": patch + "@yarnpkg/plugin-github": patch + "@yarnpkg/plugin-http": patch + "@yarnpkg/plugin-init": patch + "@yarnpkg/plugin-interactive-tools": patch + "@yarnpkg/plugin-link": patch + "@yarnpkg/plugin-nm": patch + "@yarnpkg/plugin-npm": patch + "@yarnpkg/plugin-npm-cli": patch + "@yarnpkg/plugin-pack": patch + "@yarnpkg/plugin-patch": patch + "@yarnpkg/plugin-pnp": patch + "@yarnpkg/plugin-pnpm": patch + "@yarnpkg/plugin-stage": patch + "@yarnpkg/plugin-typescript": patch + "@yarnpkg/plugin-version": patch + "@yarnpkg/plugin-workspace-tools": patch + "@yarnpkg/pnpify": patch + "@yarnpkg/sdks": patch diff --git a/packages/plugin-workspace-tools/sources/commands/foreach.ts b/packages/plugin-workspace-tools/sources/commands/foreach.ts index 47668fc447c8..b63e9e54c518 100644 --- a/packages/plugin-workspace-tools/sources/commands/foreach.ts +++ b/packages/plugin-workspace-tools/sources/commands/foreach.ts @@ -405,7 +405,7 @@ export default class WorkspacesForeachCommand extends BaseCommand { needsProcessing.delete(identHash); processing.delete(workspace.anchoredDescriptor.descriptorHash); - return exitCode; + return {workspace, exitCode}; })); // If we're not executing processes in parallel we can just wait for it @@ -424,13 +424,15 @@ export default class WorkspacesForeachCommand extends BaseCommand { return; } - const exitCodes: Array = await Promise.all(commandPromises); - const errorCode = exitCodes.find(code => code !== 0); + const results: Array<{ workspace: Workspace, exitCode: number }> = await Promise.all(commandPromises); + results.forEach(({workspace, exitCode}) => { + if (exitCode !== 0) { + report.reportError(MessageName.UNNAMED, `The command failed in workspace ${structUtils.prettyLocator(configuration, workspace.anchoredLocator)} with exit code ${exitCode}`); + } + }); - // The order in which the exit codes will be processed is fairly - // opaque, so better just return a generic "1" for determinism. - if (finalExitCode === null) - finalExitCode = typeof errorCode !== `undefined` ? 1 : finalExitCode; + const exitCodes = results.map(result => result.exitCode); + const errorCode = exitCodes.find(code => code !== 0); if ((this.topological || this.topologicalDev) && typeof errorCode !== `undefined`) { report.reportError(MessageName.UNNAMED, `The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph`);