Introduce --fail-fast flag for npm run in workspaces
Right now, when using npm run --workspaces {cmd} or npm run -w {package1} -w {package2} {cmd}, npm will always run the command in every single package even if some packages fail.
This means that if packages depend on each other and the first package fails, the second package will still try to be built and also crash. This both wastes resources as we are running commands that we know will fail and also has the potential to corrupt or generate corrupt output as the conditions to execute the command are not met.
To handle this, this pull request introduces a new command line flag for use with npm run when working with workspaces named --fail-fast that when provided, rather than running the specified command in every package no matter success, once the first package fails, the command will stop running.
This flag was originally proposed in this RFC. The conversation in the RFC got blocked due to discussion about how this would benefit from also implementing topological sort for workspace packages which requires a lot more thought and careful handling. This flag is useful even without topological sort and can be implemented in a backwards compatible way with immediate impact to users so I decided to submit it as a community contribution.
References
Related to: https://github.com/npm/rfcs/issues/575