Introduce --fail-fast flag for npm run in workspaces #8323
+72
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now, when using
npm run --workspaces {cmd}
ornpm 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: npm/rfcs#575