Skip to content

Commit ed71acb

Browse files
JeepsboucherJean-Philippe Boucher
andauthored
fix(arborist): #8472 Keeps the registry protocol when modifying resolve URL (#8473)
Fix an issue where the configured registry protocol does not follow when resolving a package resolved url. ## References Fixes #8472 Co-authored-by: Jean-Philippe Boucher <[email protected]>
1 parent 5d82d0b commit ed71acb

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

workspaces/arborist/lib/arborist/reify.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ module.exports = cls => class Reifier extends cls {
885885
// Replace the host with the registry host while keeping the path intact
886886
resolvedURL.hostname = registryURL.hostname
887887
resolvedURL.port = registryURL.port
888+
resolvedURL.protocol = registryURL.protocol
888889

889890
// Make sure we don't double-include the path if it's already there
890891
const registryPath = registryURL.pathname.replace(/\/$/, '')

workspaces/arborist/test/arborist/reify.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3627,6 +3627,59 @@ t.test('should preserve exact ranges, missing actual tree', async (t) => {
36273627

36283628
await t.resolves(arb.reify(), 'reify should complete successfully')
36293629
})
3630+
3631+
t.test('registry with different protocol should swap protocol', async (t) => {
3632+
const abbrevPackument4 = JSON.stringify({
3633+
_id: 'abbrev',
3634+
_rev: 'lkjadflkjasdf',
3635+
name: 'abbrev',
3636+
'dist-tags': { latest: '1.1.1' },
3637+
versions: {
3638+
'1.1.1': {
3639+
name: 'abbrev',
3640+
version: '1.1.1',
3641+
dist: {
3642+
// Note: This URL has no path component that matches our registry path
3643+
tarball: 'https://external-registry.example.com/abbrev-1.1.1.tgz',
3644+
},
3645+
},
3646+
},
3647+
})
3648+
3649+
const testdir = t.testdir({
3650+
project: {
3651+
'package.json': JSON.stringify({
3652+
name: 'myproject',
3653+
version: '1.0.0',
3654+
dependencies: {
3655+
abbrev: '1.1.1',
3656+
},
3657+
}),
3658+
},
3659+
})
3660+
3661+
// Set up the registrywith an http protocol
3662+
const registryHost = 'http://registry.example.com'
3663+
const registryPath = '/custom/deep/path/registry'
3664+
const registry = `${registryHost}${registryPath}`
3665+
3666+
tnock(t, registryHost)
3667+
.get(`${registryPath}/abbrev`)
3668+
.reply(200, abbrevPackument4)
3669+
3670+
tnock(t, registryHost)
3671+
.get(`${registryPath}/abbrev-1.1.1.tgz`)
3672+
.reply(200, abbrevTGZ)
3673+
3674+
const arb = new Arborist({
3675+
path: resolve(testdir, 'project'),
3676+
registry,
3677+
cache: resolve(testdir, 'cache'),
3678+
replaceRegistryHost: 'always',
3679+
})
3680+
3681+
await t.resolves(arb.reify(), 'reify should complete successfully when protocol changes from https to http')
3682+
})
36303683
})
36313684

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

0 commit comments

Comments
 (0)