Skip to content

[rush] Route lockfile-changed warning to stderr (fixes #5406)#5804

Open
LeSingh1 wants to merge 1 commit into
microsoft:mainfrom
LeSingh1:fix/rush-list-json-stderr
Open

[rush] Route lockfile-changed warning to stderr (fixes #5406)#5804
LeSingh1 wants to merge 1 commit into
microsoft:mainfrom
LeSingh1:fix/rush-list-json-stderr

Conversation

@LeSingh1
Copy link
Copy Markdown

Summary

rush list --json corrupts its own JSON output when the lockfile was added or removed in the diff range:

$ rush list --json --impacted-by git:<sha_with_no_lockfile>
Lockfile was created or deleted. Assuming all projects are affected.
{
  "projects": [
     ...
  ]
}

The first line is written to stdout, so the output is no longer parseable by jq or any other tool consuming the JSON.

Fix

Route both branches of the lockfile-status warning in ProjectChangeAnalyzer.ts through terminal.writeWarningLine (which writes to stderr) rather than terminal.writeLine. This is the standard CLI convention for warnings that should not pollute machine-readable stdout, and it matches how the rest of this file already emits non-fatal diagnostics (see existing writeWarningLine calls at lines 418, 446, 458 on main).

iclanton green-lit a PR in the issue thread ("Probably pretty simple to fix. Are you interested in putting together a PR?").

Changeset

Added a patch changeset for @microsoft/rush under common/changes/.

Verification

I do not have a Rush-managed monorepo set up locally to demonstrate the before/after pipe, but the diff is a one-method swap (writeLinewriteWarningLine) and the receiving terminal type already exposes the warning method (used elsewhere in the same file).

Issue

Fixes #5406

`rush list --json` writes `Lockfile was created or deleted. Assuming
all projects are affected.` to stdout when the lockfile was added or
removed in the diff range, which corrupts the JSON output and breaks
pipes such as `rush list --json --impacted-by git:<sha> | jq .`.

The information is useful diagnostic context, so rather than suppress
it, route it through `terminal.writeWarningLine` (which writes to
stderr) -- the standard CLI convention for warnings that should not
pollute machine-readable stdout. Matches how the rest of this file
already emits non-fatal diagnostics (see lines 418, 446, 458).

Fixes microsoft#5406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

[rush] rush list --json outputs non-JSON output when a lockfile is created or deleted

1 participant