Skip to content

Commit 5ec66b7

Browse files
committed
test: keep loopback registry traffic off HTTP proxies
In a proxied environment (HTTP_PROXY/HTTPS_PROXY without a loopback no-proxy entry) package managers would send the 127.0.0.1 registry requests through the proxy and never reach the local server. Extend the no-proxy list (NO_PROXY/no_proxy and npm's noproxy spellings, merged with any existing value) in the registry env so loopback traffic always goes direct.
1 parent 554df03 commit 5ec66b7

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

packages/tools/src/local-npm-registry.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,23 @@ const server = createServer(async (req, res) => {
493493
// refetching, so a later run would reuse dead URLs or stale local package
494494
// bytes. Give each run throwaway caches instead.
495495
function buildRegistryEnv(registry: string): Record<string, string> {
496+
// In a proxied environment (HTTP_PROXY/HTTPS_PROXY without a loopback
497+
// no-proxy entry), package managers would send the 127.0.0.1 registry
498+
// requests through the proxy and never reach this server; extend the
499+
// no-proxy list so loopback traffic always goes direct.
500+
const noProxy = [process.env.NO_PROXY ?? process.env.no_proxy, '127.0.0.1']
501+
.filter(Boolean)
502+
.join(',');
496503
return {
497504
NPM_CONFIG_REGISTRY: registry,
498505
npm_config_registry: registry,
499506
PNPM_CONFIG_REGISTRY: registry,
500507
YARN_NPM_REGISTRY_SERVER: registry,
501508
YARN_UNSAFE_HTTP_WHITELIST: '127.0.0.1',
509+
NO_PROXY: noProxy,
510+
no_proxy: noProxy,
511+
NPM_CONFIG_NOPROXY: noProxy,
512+
npm_config_noproxy: noProxy,
502513
YARN_GLOBAL_FOLDER: mkdtempSync(path.join(tmpdir(), 'vp-local-registry-yarn-')),
503514
BUN_INSTALL_CACHE_DIR: mkdtempSync(path.join(tmpdir(), 'vp-local-registry-bun-')),
504515
};

0 commit comments

Comments
 (0)