mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
fix: remove script runners from NonDownloadCommands lists (#242)
Script runners (run, start, stop, restart, test, etc.) are not package management commands — remove them so they go through the proxy instead of being skipped.
This commit is contained in:
@@ -21,16 +21,7 @@ func DefaultNpmPackageManagerConfig() NpmPackageManagerConfig {
|
|||||||
InstallCommands: []string{"install", "i", "add"},
|
InstallCommands: []string{"install", "i", "add"},
|
||||||
// Commands that are known to never download packages from a registry.
|
// Commands that are known to never download packages from a registry.
|
||||||
// Anything not in this list (including unknown future commands) runs with the proxy.
|
// Anything not in this list (including unknown future commands) runs with the proxy.
|
||||||
//
|
|
||||||
// Script runners: "run", "start", "stop", "restart", "test"/"t" are all shorthand for
|
|
||||||
// "npm run <script>". They spin up local processes (dev servers, test runners) that make
|
|
||||||
// their own HTTP calls — setting proxy env vars breaks them without providing any security
|
|
||||||
// benefit since they don't contact the package registry themselves.
|
|
||||||
//
|
|
||||||
// "exec" is intentionally excluded — it downloads and runs a package (npx equivalent).
|
|
||||||
NonDownloadCommands: []string{
|
NonDownloadCommands: []string{
|
||||||
// Script runners — may start servers or long-running processes
|
|
||||||
"run", "start", "stop", "restart", "test", "t",
|
|
||||||
// Removal — uninstalls local packages, no registry download
|
// Removal — uninstalls local packages, no registry download
|
||||||
"uninstall", "remove", "rm", "r", "un", "unlink",
|
"uninstall", "remove", "rm", "r", "un", "unlink",
|
||||||
// Local operations — no registry contact
|
// Local operations — no registry contact
|
||||||
@@ -47,7 +38,6 @@ func DefaultPnpmPackageManagerConfig() NpmPackageManagerConfig {
|
|||||||
return NpmPackageManagerConfig{
|
return NpmPackageManagerConfig{
|
||||||
InstallCommands: []string{"install", "i", "add"},
|
InstallCommands: []string{"install", "i", "add"},
|
||||||
NonDownloadCommands: []string{
|
NonDownloadCommands: []string{
|
||||||
"run", "start", "stop", "restart", "test",
|
|
||||||
"remove", "rm", "uninstall", "un",
|
"remove", "rm", "uninstall", "un",
|
||||||
"prune", "link", "unlink",
|
"prune", "link", "unlink",
|
||||||
"ls", "list", "outdated", "info", "view", "config", "why",
|
"ls", "list", "outdated", "info", "view", "config", "why",
|
||||||
@@ -60,8 +50,6 @@ func DefaultBunPackageManagerConfig() NpmPackageManagerConfig {
|
|||||||
return NpmPackageManagerConfig{
|
return NpmPackageManagerConfig{
|
||||||
InstallCommands: []string{"install", "i", "add"},
|
InstallCommands: []string{"install", "i", "add"},
|
||||||
NonDownloadCommands: []string{
|
NonDownloadCommands: []string{
|
||||||
// Script runners and local operations
|
|
||||||
"run", "test", "build",
|
|
||||||
// Removal
|
// Removal
|
||||||
"remove", "rm",
|
"remove", "rm",
|
||||||
},
|
},
|
||||||
@@ -73,7 +61,6 @@ func DefaultYarnPackageManagerConfig() NpmPackageManagerConfig {
|
|||||||
return NpmPackageManagerConfig{
|
return NpmPackageManagerConfig{
|
||||||
InstallCommands: []string{"install", "add", ""},
|
InstallCommands: []string{"install", "add", ""},
|
||||||
NonDownloadCommands: []string{
|
NonDownloadCommands: []string{
|
||||||
"run", "start", "stop", "restart", "test",
|
|
||||||
"remove", "unlink",
|
"remove", "unlink",
|
||||||
"ls", "list", "outdated", "info", "config", "why",
|
"ls", "list", "outdated", "info", "config", "why",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -539,26 +539,26 @@ func TestNpmProxyBehavior(t *testing.T) {
|
|||||||
isKnownNonDownloadCmd: true,
|
isKnownNonDownloadCmd: true,
|
||||||
isInstallationCommand: false,
|
isInstallationCommand: false,
|
||||||
},
|
},
|
||||||
// Script execution via run
|
// Script runners are not in NonDownloadCommands — proxy runs for them
|
||||||
{
|
{
|
||||||
name: "npm run dev — proxy skipped (executes local script, no registry contact)",
|
name: "npm run dev — proxy runs (script runner)",
|
||||||
pm: func() (*npmPackageManager, error) { return NewNpmPackageManager(DefaultNpmPackageManagerConfig()) },
|
pm: func() (*npmPackageManager, error) { return NewNpmPackageManager(DefaultNpmPackageManagerConfig()) },
|
||||||
command: "npm run dev",
|
command: "npm run dev",
|
||||||
isKnownNonDownloadCmd: true,
|
isKnownNonDownloadCmd: false,
|
||||||
isInstallationCommand: false,
|
isInstallationCommand: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "yarn run build — proxy skipped (executes local script)",
|
name: "yarn run build — proxy runs (script runner)",
|
||||||
pm: func() (*npmPackageManager, error) { return NewNpmPackageManager(DefaultYarnPackageManagerConfig()) },
|
pm: func() (*npmPackageManager, error) { return NewNpmPackageManager(DefaultYarnPackageManagerConfig()) },
|
||||||
command: "yarn run build",
|
command: "yarn run build",
|
||||||
isKnownNonDownloadCmd: true,
|
isKnownNonDownloadCmd: false,
|
||||||
isInstallationCommand: false,
|
isInstallationCommand: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bun run test — proxy skipped (executes local script)",
|
name: "bun run test — proxy runs (script runner)",
|
||||||
pm: func() (*npmPackageManager, error) { return NewNpmPackageManager(DefaultBunPackageManagerConfig()) },
|
pm: func() (*npmPackageManager, error) { return NewNpmPackageManager(DefaultBunPackageManagerConfig()) },
|
||||||
command: "bun run test",
|
command: "bun run test",
|
||||||
isKnownNonDownloadCmd: true,
|
isKnownNonDownloadCmd: false,
|
||||||
isInstallationCommand: false,
|
isInstallationCommand: false,
|
||||||
},
|
},
|
||||||
// False positive regression: package/script names matching NonDownloadCommands words
|
// False positive regression: package/script names matching NonDownloadCommands words
|
||||||
|
|||||||
@@ -62,10 +62,6 @@ func DefaultPoetryPackageManagerConfig() PypiPackageManagerConfig {
|
|||||||
return PypiPackageManagerConfig{
|
return PypiPackageManagerConfig{
|
||||||
InstallCommands: []string{"add"},
|
InstallCommands: []string{"add"},
|
||||||
NonDownloadCommands: []string{
|
NonDownloadCommands: []string{
|
||||||
// Script runners — "run" executes a command in the venv (e.g., `poetry run uvicorn app:app`).
|
|
||||||
// "shell" activates the venv shell. Both may start long-running processes and must not
|
|
||||||
// have proxy env vars set against them.
|
|
||||||
"run", "shell",
|
|
||||||
// Removal
|
// Removal
|
||||||
"remove",
|
"remove",
|
||||||
// Inspection / read-only
|
// Inspection / read-only
|
||||||
|
|||||||
Reference in New Issue
Block a user