fix: mark npx binary as optional to suppress false unlisted-binary reports#1805
Open
axelray-dev wants to merge 1 commit into
Open
fix: mark npx binary as optional to suppress false unlisted-binary reports#1805axelray-dev wants to merge 1 commit into
axelray-dev wants to merge 1 commit into
Conversation
…ports
When a script uses `npx some-tool`, knip previously reported `some-tool` as
an unlisted binary. The bunx resolver already marks binaries as optional, but
the npx resolver did not.
Add `{ optional: true }` to the `toBinary` call in the npx resolver when
the specifier is the npx target (no `--package` flag). When `--package`
is used, the positional arg is a command binary and remains non-optional.
Fixes webpro-nl#1803
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.
Summary
When a script uses
npx some-tool, knip reportssome-toolas "Unlisted binary" even though it's being run on-demand via npx and shouldn't be expected inpackage.json.The
bunxresolver already marks binaries as optional (toBinary(specifier, { optional: true })), but thenpxresolver did not.Fix
Add
{ optional: true }to thetoBinarycall in the npx resolver when the specifier is the npx target (no--packageflag). When--packageis used, the positional arg is a command binary and remains non-optional.This matches the existing
bunxresolver behavior.Test plan
test/util/get-inputs-from-scripts.test.tsto reflect that npx-resolved binaries are now optionalget-inputs-from-scripts.test.tspass--packageflag correctly leave the command binary non-optional