fix(osv_check): honor npx --package/-p install target when parsing package arg (#40567)

Salvaged from #40461; cleaned up, re-verified against main, tests added.

Co-authored-by: HeLLGURD <HeLLGURD@users.noreply.github.com>
This commit is contained in:
Teknium
2026-06-06 18:30:39 -07:00
committed by GitHub
co-authored by HeLLGURD
parent 56f833efa4
commit c0424b06af
2 changed files with 46 additions and 1 deletions
+15 -1
View File
@@ -82,11 +82,25 @@ def _parse_package_from_args(
if not args:
return None, None
# Skip flags to find the package token
# Skip flags to find the package token.
# Honor npx's explicit install target: --package=NAME / --package NAME and
# the -p NAME short form, which name a package distinct from the executed
# binary. Without this the first bare positional (often the command name)
# is mistaken for the package.
package_token = None
take_next = False
for arg in args:
if not isinstance(arg, str):
continue
if take_next:
package_token = arg
break
if arg in ("--package", "-p"):
take_next = True
continue
if arg.startswith("--package="):
package_token = arg[len("--package="):]
break
if arg.startswith("-"):
continue
package_token = arg