fix: silence package manager warnings that break outdated --json - #176
Merged
Merged
Conversation
- pnpm writes warnings to stdout even under --json, which puts them ahead of the payload and makes vim.json.decode fail, taking down the whole virtual text feature with "Error running pnpm outdated --json" - pass --loglevel=error so warnings are muted while the json payload and genuine errors still come through - extract the command into show.__get_outdated_command, matching the builder convention in change-version.lua, and cover both branches
Owner
|
Thanks <3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When you open a
package.jsonin a pnpm workspace, the plugin can fail with thismessage:
The virtual text is never shown. If you run
pnpm outdated --jsonyourself in the samedirectory, it works. This makes the error confusing.
Root cause
pnpm writes warnings to stdout, not to stderr, even when you use
--json:utils/job.luapasses all of stdout tovim.json.decode. The library behind it needsthe whole string to be one JSON document. Spaces before the JSON are fine, but any other
text is not. The payload here is valid JSON, but it does not start at the beginning of
the string. So the decode fails and the feature stops working.
The exit code is not the problem.
ignore_error = truealready handles the exit code 1that
outdatedreturns.You do not need any special configuration for this to happen.
pnpm config get minimumReleaseAgereturnsundefined, but pnpm still runs the check. So it also affectsusers who have configured nothing. What you do need is a dependency from a registry that
has no
timefield in its package metadata. Self-hosted registries such as GitLab,Verdaccio and Artifactory do this.
Fix
Add
--loglevel=errorto the outdated command. This hides the warnings, but the JSONpayload and real errors still come through.
The command now lives in
show.__get_outdated_command. This follows the same pattern aschange-version.__get_version_list_command.Verification
I reproduced the problem with a local registry that serves package metadata without a
timefield, using pnpm 11.3.0 and Neovim 0.12.4. This produces the exact warning shownabove. These are the results for each flag:
pnpm outdated --jsonpnpm --loglevel=error outdated --jsonpnpm --reporter=silent outdated --jsonpnpm --silent outdated --jsonpnpm --reporter=ndjson outdated --jsonThe payload is exactly the same with and without the flag. So the flag hides the warning
but keeps the result. npm accepts the same flag, and its output does not change.
I also ran the real
utils/job.luacode with the new command against that registry. Itnow decodes correctly, where before it failed.
make testpasses completely, and stylua 0.17.0 reports no problems.Alternatives considered
Another option is to make the decode in
job.luamore tolerant: skip the extra text andfind the first position where the JSON decodes. This would work for every package
manager at once, including the
yqjob and any manager added later.I chose the flag instead, for two reasons. First, it solves the cause instead of
accepting the broken output. Second, the search becomes very slow when the output never
decodes, because it tries again from every
{in the string, including the thousands ofthem inside the payload. I measured 31 ms for 92 KB, but 6.1 s for 945 KB. This runs in
the
on_exitcallback, so a cut-off response would freeze the editor before it shows theerror anyway.
Setting
loglevel=errorin.npmrcalso works. But it hides pnpm warnings in the wholerepository for everyone, while the flag only affects this one command.