fix: only strip own package manager name in ParseCommand args (#208)

* fix: only strip own package manager name in ParseCommand args

ParseCommand was stripping the first arg if it matched any package
manager name (npm, pnpm, bun, yarn). This caused yarn's parser to
incorrectly strip "npm" from "yarn npm login", since "npm" is a
valid yarn subcommand, not a package manager prefix.

Fixes #204

* use require in test
This commit is contained in:
Sahil Bansal
2026-04-08 22:27:45 +05:30
committed by GitHub
parent 987bda5d6a
commit dbe968dec6
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ func (npm *npmPackageManager) Ecosystem() packagev1.Ecosystem {
}
func (npm *npmPackageManager) ParseCommand(args []string) (*ParsedCommand, error) {
if len(args) > 0 && (args[0] == "npm" || args[0] == "pnpm" || args[0] == "bun" || args[0] == "yarn") {
if len(args) > 0 && args[0] == npm.Config.CommandName {
args = args[1:]
}
+10
View File
@@ -5,6 +5,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNpmParseCommand(t *testing.T) {
@@ -249,6 +250,15 @@ func TestYarnParseCommand(t *testing.T) {
assert.Equal(t, "@types/node", parsedCommand.InstallTargets[0].PackageVersion.Package.Name)
},
},
{
name: "yarn npm subcommand is not stripped",
command: "npm login",
assert: func(t *testing.T, parsedCommand *ParsedCommand, err error) {
require.NoError(t, err)
assert.Equal(t, "yarn", parsedCommand.Command.Exe)
assert.Equal(t, []string{"npm", "login"}, parsedCommand.Command.Args)
},
},
}
for _, tc := range cases {