rushstack
rushstack copied to clipboard
[rush] rush alert should honor `-q` and `--json` and similar
Summary
When rush alerts is used, utilities that rely on output could fail if the alert is triggered. shouldRestrictConsoleOutput should probably be honored on rush alerts.
Repro steps
run any command that relies on output, like rush list --json | jq
Expected result: Only JSON should be written to STDOUT
Actual result: Rush alerts are written to stdout, resulting in an error
jq: parse error: Invalid numeric literal at line 4015, column 0
Details
Standard questions
Please answer these questions to help us investigate your issue more quickly:
| Question | Answer |
|---|---|
@microsoft/rush globally installed version? |
5.153.1 |
rushVersion from rush.json? |
5.153.1 |
useWorkspaces from rush.json? |
undefined |
| Operating system? | Mac / Linux |
| Would you consider contributing a PR? | No |
Node.js version (node -v)? |
22.14.0 |
Looks like this was an oversight when that feature was implemented. Should be a fairly easy fix.
Hi! @iclanton I’d like to take this issue, could you please assign it to me?
Proposed approach:
- Honor
shouldRestrictConsoleOutput()for Rush alerts so-q/--quietand--jsonsuppress the alert banner. - Change site: libraries/rush-lib/src/cli/RushCommandLineParser.ts
- Console restriction logic: https://github.com/microsoft/rushstack/blob/main/libraries/rush-lib/src/cli/RushCommandLineParser.ts#L205-L221
- Alert invocation in onExecuteAsync(): https://github.com/microsoft/rushstack/blob/main/libraries/rush-lib/src/cli/RushCommandLineParser.ts#L255-L275
- Minimal change (parser-level guard): if (!RushCommandLineParser.shouldRestrictConsoleOutput()) { await rushAlerts.printAlertsAsync(); }
Rationale:
- Prevents alert output on stdout so commands like
rush list --json | jqemit only JSON. - Keeps explicit
rush alertbehavior unchanged.
Tests:
- Add/extend a test to assert no alert output when
--jsonor-qis present, and JSON remains valid.
If this direction looks good, I’ll proceed from branch fix/5228-alert-honor-quiet-json. Thanks!