Skip to content

Commit 68bebc0

Browse files
author
Max Black
committed
fix: check proxy env vars case-insensitively to match agent behavior
The agent library (via proxy.js) checks proxy environment variables case-insensitively by converting all env var names to lowercase before checking. This updates npm config list to do the same, ensuring that variables like Http_Proxy, HTTP_PROXY, and http_proxy are all detected. - Updated proxyEnv list to use lowercase keys matching agent library - Modified config list to check environment variables case-insensitively - Now finds any casing of http_proxy, https_proxy, proxy, and no_proxy
1 parent 9c29072 commit 68bebc0

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/commands/config.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,14 @@ ${defData}
353353
const envVars = []
354354

355355
// Show proxy-related environment variables if they're set
356-
for (const envVar of proxyEnv) {
357-
if (process.env[envVar]) {
358-
envVars.push(`; ${envVar} = ${JSON.stringify(process.env[envVar])}`)
356+
// Check case-insensitively since environment variables can be set in any casing
357+
// and the agent library (via proxy.js) checks them case-insensitively
358+
const foundEnvVars = new Set()
359+
for (const key of Object.keys(process.env)) {
360+
const lowerKey = key.toLowerCase()
361+
if (proxyEnv.includes(lowerKey) && !foundEnvVars.has(lowerKey)) {
362+
foundEnvVars.add(lowerKey)
363+
envVars.push(`; ${key} = ${JSON.stringify(process.env[key])}`)
359364
}
360365
}
361366

workspaces/config/lib/definitions/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,11 @@ const nerfDarts = [
7373

7474
// Environment variables that can affect npm's behavior but are not npm configs
7575
// These are shown in `npm config list` to help users understand their environment
76+
// This list matches the keys checked in @npmcli/agent's proxy detection
7677
const proxyEnv = [
77-
'HTTP_PROXY',
78-
'HTTPS_PROXY',
79-
'NO_PROXY',
8078
'http_proxy',
8179
'https_proxy',
80+
'proxy',
8281
'no_proxy',
8382
]
8483

0 commit comments

Comments
 (0)