Skip to content

[rush] Write the npm/Yarn "Lockfile has changed" warning to stderr - #6197

Open
PranavThukral wants to merge 1 commit into
microsoft:mainfrom
PranavThukral:fix-npm-yarn-lockfile-warning-stderr
Open

PranavThukral wants to merge 1 commit into
microsoft:mainfrom
PranavThukral:fix-npm-yarn-lockfile-warning-stderr

Conversation

@PranavThukral

Copy link
Copy Markdown

Summary

In npm and Yarn repos, rush list --json --impacted-by git:<ref> prints this line to stdout before the JSON whenever the committed lockfile was modified in the diff range:

Lockfile has changed and lockfile content comparison is only supported for pnpm. Assuming all projects are affected.

Because it lands on stdout, piping the output into jq or a CI script fails to parse. This PR writes that message to stderr instead, so stdout stays valid JSON.

Details

PR #5804 fixed the same issue for the similar "Lockfile was created or deleted" message in ProjectChangeAnalyzer.getChangedProjectsAsync, but the npm/Yarn else branch a few lines below still uses terminal.writeLine, even though that branch is generally the more common one as lockfiles are modified on almost every dependency update.

This change switches both forms of that message (subspace & non-subspace) from writeLine to writeWarningLine, matching #5804. As subspaces only work with pnpm, the copy never prints in practice. But, I changed for consistency.

Nothing else was changed, only the output stream was affected. No other compatibility or performance impact beyond the message going to stderr.

How it was tested

  • Added a test covering a modified (M) and a created (A) npm-shrinkwrap.json, the latter checking [rush] Route lockfile-changed warning to stderr (fixes #5406) #5804. Each case shows that the message goes to warning output, not normal output.
  • heft test --test-path-pattern ProjectChangeAnalyzer: 48 passed, no lint warnings.
  • With the source change reverted, the modified case fails, so the test catches the bug.

When a non-pnpm lockfile is modified in the diff range, ProjectChangeAnalyzer
printed "Lockfile has changed and lockfile content comparison is only
supported for pnpm" with writeLine, which goes to stdout. That breaks
`rush list --json --impacted-by git:<ref> | jq`.

microsoft#5804 already moved the "created or deleted" message to stderr; this does
the same for the modified case and adds tests for both.
@PranavThukral

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
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.

1 participant