fix(npm): handle multiple packages and flag parsing correctly (#17)

* fix(npm): handle multiple packages and flag parsing correctly

- Fixes issue where only the first package was scanned; now all packages in install command are parsed and processed.
- Correctly separates flags (e.g., --save-dev) from package names to avoid treating them as packages.
- Applies same fixes to both npm and pnpm flows.
- Updated wrapper to scan all packages before installing, maintaining original CLI behavior.

* refactor: fixed the registry type

* feat: continue installing other packages if one is denied

* Update pkg/wrapper/npm_base.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com>

* fix(wrapper): exit gracefully for user-rejected packages

* fix: remove env validation

---------

Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Sahil Bansal
2025-05-12 09:23:08 +05:30
committed by GitHub
co-authored by Copilot
parent f7855e99a2
commit 8b46964c7a
6 changed files with 146 additions and 73 deletions
+12 -5
View File
@@ -24,13 +24,20 @@ func NewNpmCommand() *cobra.Command {
}
if len(args) >= 2 && utils.IsInstallCommand(string(registry.RegistryNPM), args[0]) {
pmw := wrapper.NewPackageManagerWrapper(registry.RegistryNPM)
pmw.Action = args[0]
pmw.PackageName = args[1]
// Parse arguments to separate flags and packages
flags, packages := utils.ParseNpmInstallArgs(args[1:])
if err := pmw.Wrap(); err != nil {
os.Exit(1)
// If no packages specified, just pass through to npm
if len(packages) == 0 {
return utils.ExecCmd(execPath, args, []string{})
}
// Create single wrapper instance for all packages
pmw := wrapper.NewPackageManagerWrapper(registry.RegistryNPM, flags, packages, args[0])
if err := pmw.Wrap(); err != nil {
return err
}
return nil
}
+12 -5
View File
@@ -24,13 +24,20 @@ func NewPnpmCommand() *cobra.Command {
}
if len(args) >= 2 && utils.IsInstallCommand(string(registry.RegistryPNPM), args[0]) {
pmw := wrapper.NewPackageManagerWrapper(registry.RegistryPNPM)
pmw.Action = args[0]
pmw.PackageName = args[1]
// Parse arguments to separate flags and packages
flags, packages := utils.ParseNpmInstallArgs(args[1:])
if err := pmw.Wrap(); err != nil {
os.Exit(1)
// If no packages specified, just pass through to npm
if len(packages) == 0 {
return utils.ExecCmd(execPath, args, []string{})
}
// Create single wrapper instance for all packages
pmw := wrapper.NewPackageManagerWrapper(registry.RegistryPNPM, flags, packages, args[0])
if err := pmw.Wrap(); err != nil {
return err
}
return nil
}