Content-Length: 413754 | pFad | http://github.com/npm/cli/commit/0886e7abced0d8bdfd564a3b254817ecbdc14857

55 fix: preserve registry path when replacing a host · npm/cli@0886e7a · GitHub
Skip to content

Commit 0886e7a

Browse files
committed
fix: preserve registry path when replacing a host
1 parent 7eca19c commit 0886e7a

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

workspaces/arborist/lib/arborist/reify.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,19 @@ module.exports = cls => class Reifier extends cls {
895895
if ((this.options.replaceRegistryHost === resolvedURL.hostname) ||
896896
this.options.replaceRegistryHost === 'always') {
897897
const registryURL = new URL(this.registry)
898+
898899
// Replace the host with the registry host while keeping the path intact
899900
resolvedURL.hostname = registryURL.hostname
900901
resolvedURL.port = registryURL.port
902+
903+
// Make sure we don't double-include the path if it's already there
904+
const registryPath = registryURL.pathname.replace(/\/$/, '')
905+
906+
if (registryPath && registryPath !== '/' && !resolvedURL.pathname.startsWith(registryPath)) {
907+
// Since hostname is changed, we need to ensure the registry path is included
908+
resolvedURL.pathname = registryPath + resolvedURL.pathname
909+
}
910+
901911
return resolvedURL.toString()
902912
}
903913
return resolved

workspaces/arborist/test/arborist/reify.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,6 +3506,61 @@ t.test('should preserve exact ranges, missing actual tree', async (t) => {
35063506
})
35073507
await arb.reify()
35083508
})
3509+
3510+
t.test('registry path prepending', async t => {
3511+
// A registry path is prepended to resolved URLs that don't already have it
3512+
const abbrevPackument4 = JSON.stringify({
3513+
_id: 'abbrev',
3514+
_rev: 'lkjadflkjasdf',
3515+
name: 'abbrev',
3516+
'dist-tags': { latest: '1.1.1' },
3517+
versions: {
3518+
'1.1.1': {
3519+
name: 'abbrev',
3520+
version: '1.1.1',
3521+
dist: {
3522+
// Note: This URL has no path component that matches our registry path
3523+
tarball: 'https://external-registry.example.com/abbrev-1.1.1.tgz',
3524+
},
3525+
},
3526+
},
3527+
})
3528+
3529+
const testdir = t.testdir({
3530+
project: {
3531+
'package.json': JSON.stringify({
3532+
name: 'myproject',
3533+
version: '1.0.0',
3534+
dependencies: {
3535+
abbrev: '1.1.1',
3536+
},
3537+
}),
3538+
},
3539+
})
3540+
3541+
// Set up the registry with a deep path
3542+
const registryHost = 'https://registry.example.com'
3543+
const registryPath = '/custom/deep/path/registry'
3544+
const registry = `${registryHost}${registryPath}`
3545+
3546+
tnock(t, registryHost)
3547+
.get(`${registryPath}/abbrev`)
3548+
.reply(200, abbrevPackument4)
3549+
3550+
// This is the critical test - the tarball URL in the packument doesn't have our registry path, but when replaceRegistryHost is 'always', we should get a request to this URL which includes the registry path
3551+
tnock(t, registryHost)
3552+
.get(`${registryPath}/abbrev-1.1.1.tgz`)
3553+
.reply(200, abbrevTGZ)
3554+
3555+
const arb = new Arborist({
3556+
path: resolve(testdir, 'project'),
3557+
registry,
3558+
cache: resolve(testdir, 'cache'),
3559+
replaceRegistryHost: 'always',
3560+
})
3561+
3562+
await t.resolves(arb.reify(), 'reify should complete successfully')
3563+
})
35093564
})
35103565

35113566
t.test('install stategy linked', async (t) => {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/npm/cli/commit/0886e7abced0d8bdfd564a3b254817ecbdc14857

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy