Skip to content

fix: mark npx binary as optional to suppress false unlisted-binary reports#1805

Open
axelray-dev wants to merge 1 commit into
webpro-nl:mainfrom
axelray-dev:fix/npx-unlisted-binary
Open

fix: mark npx binary as optional to suppress false unlisted-binary reports#1805
axelray-dev wants to merge 1 commit into
webpro-nl:mainfrom
axelray-dev:fix/npx-unlisted-binary

Conversation

@axelray-dev

Copy link
Copy Markdown

Summary

When a script uses npx some-tool, knip reports some-tool as "Unlisted binary" even though it's being run on-demand via npx and shouldn't be expected in package.json.

The bunx resolver already marks binaries as optional (toBinary(specifier, { optional: true })), but the npx resolver did not.

Fix

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.

This matches the existing bunx resolver behavior.

Test plan

  • Updated test expectations in test/util/get-inputs-from-scripts.test.ts to reflect that npx-resolved binaries are now optional
  • All 30 tests in get-inputs-from-scripts.test.ts pass
  • Cases with --package flag correctly leave the command binary non-optional

…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
@axelray-dev axelray-dev marked this pull request as ready for review June 19, 2026 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant