mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
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:
@@ -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:]
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user