yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Support for `yarn workspaces run` that continues on non-zero exit codes

Open samuela opened this issue 5 years ago • 3 comments

Do you want to request a feature or report a bug? feature request

What is the current behavior? yarn workspaces run lint aborts as soon as the lint command in any workspace produces a non-zero exit code.

If the current behavior is a bug, please provide the steps to reproduce. n/a

What is the expected behavior? It would be nice to add a flag (eg --continue) that forces yarn workspaces run ... to continue irrespective of the result of each workspace run. That way things like linting or compiling can be run across the whole project without worrying that each project lints perfectly.

The final exit code should still reflect whether or not any of the subcommands failed.

Please mention your node.js, yarn and operating system version. macOS 10.14.2, yarn 1.13.0, node v11.8.0

samuela avatar Feb 03 '19 21:02 samuela

Workarounds: Create a script to do it for you,

#!/usr/bin/env node

const shell = require("shelljs");

const packages = JSON.parse(
  JSON.parse(shell.exec("yarn workspaces info --json", { silent: true }).stdout)
    .data,
);

const args = process.argv.slice(2);
var exitCode = 0;

for (let [packageName, { location }] of Object.entries(packages)) {
  console.log(`=== Running in ${packageName}`);
  const { code } = shell.exec(
    `yarn --cwd ${location} --color=always run ${args.join(" ")}`,
  );
  if (code > 0) exitCode = 1;
}

shell.exit(exitCode);

or if you're using tslint: yarn workspaces run lint --force

samuela avatar Feb 03 '19 22:02 samuela

Hi!

I just encountered the same issue. Although the workaround is welcome, it would be great if this was working out of the box.

I haven't started checking the code but I was wondering though, what's exiting the process? Is it yarn workspaces run or the linter/tester (e.g. eslint in my case) that kills everything once it finished and found errors?

Depending on what's the answer, the issue may not lie with yarn.

In an automated setting (like a CI/CD process) it's not very handy to have the linter stop on the first workspace it found errors in.

truumahn avatar Dec 02 '20 16:12 truumahn

Not having the option to ignore the non-zero exit code is a problem when working with eslint and multiple workspaces.

I want the linter to run on all workspaces, no matter what was the exit code.

Having this option in yarn workspaces run makes more sense than having it in eslint.

KurzedMetal avatar May 12 '22 22:05 KurzedMetal