Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { spawn } = require('node:child_process')
const { EOL } = require('node:os')
const localeCompare = require('@isaacs/string-locale-compare')('en')
const pkgJson = require('@npmcli/package-json')
const { defaults, definitions, nerfDarts } = require('@npmcli/config/lib/definitions')
const { defaults, definitions, nerfDarts, proxyEnv } = require('@npmcli/config/lib/definitions')
const { log, output } = require('proc-log')
const BaseCommand = require('../base-cmd.js')
const { redact } = require('@npmcli/redact')
Expand Down Expand Up @@ -350,6 +350,23 @@ ${defData}
}

if (!long) {
const envVars = []

const foundEnvVars = new Set()
for (const key of Object.keys(process.env)) {
const lowerKey = key.toLowerCase()
if (proxyEnv.includes(lowerKey) && !foundEnvVars.has(lowerKey)) {
foundEnvVars.add(lowerKey)
envVars.push(`; ${key} = ${JSON.stringify(process.env[key])}`)
}
}

if (envVars.length > 0) {
msg.push('; environment-related config', '')
msg.push(...envVars)
msg.push('')
}

msg.push(
`; node bin location = ${process.execPath}`,
`; node version = ${process.version}`,
Expand Down
21 changes: 21 additions & 0 deletions tap-snapshots/test/lib/commands/config.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
"before": null,
"bin-links": true,
"browser": null,
"bypass-2fa": false,
"ca": null,
"cache-max": null,
"cache-min": 0,
Expand All @@ -48,6 +49,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
"engine-strict": false,
"expect-result-count": null,
"expect-results": null,
"expires": null,
"fetch-retries": 2,
"fetch-retry-factor": 10,
"fetch-retry-maxtimeout": 60000,
Expand Down Expand Up @@ -97,6 +99,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
"logs-dir": null,
"logs-max": 10,
"long": false,
"name": null,
"maxsockets": 15,
"message": "%s",
"node-gyp": "{CWD}/node_modules/node-gyp/bin/node-gyp.js",
Expand All @@ -108,13 +111,15 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
"omit": [],
"omit-lockfile-registry-resolved": false,
"only": null,
"orgs": null,
"optional": null,
"os": null,
"otp": null,
"package": [],
"package-lock": true,
"package-lock-only": false,
"pack-destination": ".",
"packages": [],
"parseable": false,
"prefer-dedupe": false,
"prefer-offline": false,
Expand All @@ -141,6 +146,11 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
"sbom-format": null,
"sbom-type": "library",
"scope": "",
"scopes": null,
"packages-all": false,
"packages-and-scopes-permission": null,
"orgs-permission": null,
"token-description": null,
"script-shell": null,
"searchexclude": "",
"searchlimit": 20,
Expand Down Expand Up @@ -187,6 +197,7 @@ auth-type = "web"
before = null
bin-links = true
browser = null
bypass-2fa = false
ca = null
; cache = "{CACHE}" ; overridden by cli
cache-max = null
Expand Down Expand Up @@ -214,6 +225,7 @@ editor = "{EDITOR}"
engine-strict = false
expect-result-count = null
expect-results = null
expires = null
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
Expand Down Expand Up @@ -266,6 +278,7 @@ logs-max = 10
; long = false ; overridden by cli
maxsockets = 15
message = "%s"
name = null
node-gyp = "{CWD}/node_modules/node-gyp/bin/node-gyp.js"
node-options = null
noproxy = [""]
Expand All @@ -275,13 +288,19 @@ omit = []
omit-lockfile-registry-resolved = false
only = null
optional = null
orgs = null
orgs-permission = null
os = null
otp = null
pack-destination = "."
package = []
package-lock = true
package-lock-only = false
packages = []
packages-all = false
packages-and-scopes-permission = null
parseable = false
password = (protected)
prefer-dedupe = false
prefer-offline = false
prefer-online = false
Expand All @@ -307,6 +326,7 @@ save-prod = false
sbom-format = null
sbom-type = "library"
scope = ""
scopes = null
script-shell = null
searchexclude = ""
searchlimit = 20
Expand All @@ -321,6 +341,7 @@ strict-ssl = true
tag = "latest"
tag-version-prefix = "v"
timing = false
token-description = null
umask = 0
unicode = false
update-notifier = true
Expand Down
43 changes: 43 additions & 0 deletions test/lib/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,49 @@ t.test('config list', async t => {
t.matchSnapshot(output, 'output matches snapshot')
})

t.test('config list with proxy environment variables', async t => {
const originalHTTP = process.env.HTTP_PROXY
const originalHTTPS = process.env.HTTPS_PROXY
const originalNO = process.env.NO_PROXY

t.teardown(() => {
if (originalHTTP !== undefined) {
process.env.HTTP_PROXY = originalHTTP
} else {
delete process.env.HTTP_PROXY
}
if (originalHTTPS !== undefined) {
process.env.HTTPS_PROXY = originalHTTPS
} else {
delete process.env.HTTPS_PROXY
}
if (originalNO !== undefined) {
process.env.NO_PROXY = originalNO
} else {
delete process.env.NO_PROXY
}
})

process.env.HTTP_PROXY = 'http://proxy.example.com:8080'
process.env.HTTPS_PROXY = 'https://secure-proxy.example.com:8443'
process.env.NO_PROXY = 'localhost,127.0.0.1'

const { npm, joinedOutput } = await loadMockNpm(t, {
prefixDir: {
'.npmrc': 'test=value',
},
})

await npm.exec('config', ['list'])

const output = joinedOutput()

t.match(output, 'HTTP_PROXY = "http://proxy.example.com:8080"')
t.match(output, 'HTTPS_PROXY = "https://secure-proxy.example.com:8443"')
t.match(output, 'NO_PROXY = "localhost,127.0.0.1"')
t.match(output, 'environment-related config')
})

t.test('config list --long', async t => {
const { npm, joinedOutput } = await loadMockNpm(t, {
prefixDir: {
Expand Down
8 changes: 8 additions & 0 deletions workspaces/config/lib/definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,18 @@ const nerfDarts = [
'username', // Does not have a config
]

const proxyEnv = [
'http_proxy',
'https_proxy',
'proxy',
'no_proxy',
]

module.exports = {
defaults: definitionProps.defaults,
definitions,
flatten,
nerfDarts,
proxyEnv,
shorthands,
}
Loading