@@ -3905,6 +3905,154 @@ t.test('should preserve exact ranges, missing actual tree', async (t) => {
39053905 await t . resolves ( arb . reify ( ) , 'reify should complete successfully' )
39063906 } )
39073907
3908+ // Validates both URL-prefix matching modes for replace-registry-host:
3909+ // A) full URL with path → entire prefix (host + old path) is replaced with registry URL
3910+ // B) host-only URL → only the host is swapped, resolved path is left unchanged
3911+ t . test ( 'replace-registry-host as full URL with path replaces entire prefix' , async t => {
3912+ const packument = JSON . stringify ( {
3913+ _id : 'abbrev' ,
3914+ _rev : 'lkjadflkjasdf' ,
3915+ name : 'abbrev' ,
3916+ 'dist-tags' : { latest : '1.1.1' } ,
3917+ versions : {
3918+ '1.1.1' : {
3919+ name : 'abbrev' ,
3920+ version : '1.1.1' ,
3921+ dist : {
3922+ // tarball lives under /npm/b on the old host
3923+ tarball : 'https://old.example.com/npm/b/abbrev/-/abbrev-1.1.1.tgz' ,
3924+ } ,
3925+ } ,
3926+ } ,
3927+ } )
3928+
3929+ const testdir = t . testdir ( {
3930+ project : {
3931+ 'package.json' : JSON . stringify ( {
3932+ name : 'myproject' ,
3933+ version : '1.0.0' ,
3934+ dependencies : { abbrev : '1.1.1' } ,
3935+ } ) ,
3936+ } ,
3937+ } )
3938+
3939+ // packument lookup goes through new host + new path prefix
3940+ tnock ( t , 'https://new.example.com' )
3941+ . get ( '/npm/a/abbrev' )
3942+ . reply ( 200 , packument )
3943+
3944+ // tarball: /npm/b prefix replaced with /npm/a — NOT /npm/a/npm/b/…
3945+ tnock ( t , 'https://new.example.com' )
3946+ . get ( '/npm/a/abbrev/-/abbrev-1.1.1.tgz' )
3947+ . reply ( 200 , abbrevTGZ )
3948+
3949+ const arb = new Arborist ( {
3950+ path : resolve ( testdir , 'project' ) ,
3951+ registry : 'https://new.example.com/npm/a' ,
3952+ cache : resolve ( testdir , 'cache' ) ,
3953+ replaceRegistryHost : 'https://old.example.com/npm/b' ,
3954+ } )
3955+
3956+ await t . resolves ( arb . reify ( ) , 'prefix is replaced without duplication' )
3957+ } )
3958+
3959+ t . test ( 'replace-registry-host as host-only URL leaves resolved path unchanged' , async t => {
3960+ const packument = JSON . stringify ( {
3961+ _id : 'abbrev' ,
3962+ _rev : 'lkjadflkjasdf' ,
3963+ name : 'abbrev' ,
3964+ 'dist-tags' : { latest : '1.1.1' } ,
3965+ versions : {
3966+ '1.1.1' : {
3967+ name : 'abbrev' ,
3968+ version : '1.1.1' ,
3969+ dist : {
3970+ // tarball has its own path on the old host
3971+ tarball : 'https://old.example.com/abbrev/-/abbrev-1.1.1.tgz' ,
3972+ } ,
3973+ } ,
3974+ } ,
3975+ } )
3976+
3977+ const testdir = t . testdir ( {
3978+ project : {
3979+ 'package.json' : JSON . stringify ( {
3980+ name : 'myproject' ,
3981+ version : '1.0.0' ,
3982+ dependencies : { abbrev : '1.1.1' } ,
3983+ } ) ,
3984+ } ,
3985+ } )
3986+
3987+ // packument lookup: host swapped, path unchanged
3988+ tnock ( t , 'https://new.example.com' )
3989+ . get ( '/abbrev' )
3990+ . reply ( 200 , packument )
3991+
3992+ // tarball: host swapped only — /abbrev/-/… path is preserved as-is
3993+ tnock ( t , 'https://new.example.com' )
3994+ . get ( '/abbrev/-/abbrev-1.1.1.tgz' )
3995+ . reply ( 200 , abbrevTGZ )
3996+
3997+ const arb = new Arborist ( {
3998+ path : resolve ( testdir , 'project' ) ,
3999+ registry : 'https://new.example.com/' ,
4000+ cache : resolve ( testdir , 'cache' ) ,
4001+ // trailing slash only → host-only replacement, path left unchanged
4002+ replaceRegistryHost : 'https://old.example.com/' ,
4003+ } )
4004+
4005+ await t . resolves ( arb . reify ( ) , 'only host is replaced; resolved path is unchanged' )
4006+ } )
4007+
4008+ t . test ( 'replace-registry-host as full URL with path does not replace non-matching path' , async t => {
4009+ const packument = JSON . stringify ( {
4010+ _id : 'abbrev' ,
4011+ _rev : 'lkjadflkjasdf' ,
4012+ name : 'abbrev' ,
4013+ 'dist-tags' : { latest : '1.1.1' } ,
4014+ versions : {
4015+ '1.1.1' : {
4016+ name : 'abbrev' ,
4017+ version : '1.1.1' ,
4018+ dist : {
4019+ // tarball is under /npm/b, but replaceRegistryHost specifies /npm/c
4020+ tarball : 'https://old.example.com/npm/b/abbrev/-/abbrev-1.1.1.tgz' ,
4021+ } ,
4022+ } ,
4023+ } ,
4024+ } )
4025+
4026+ const testdir = t . testdir ( {
4027+ project : {
4028+ 'package.json' : JSON . stringify ( {
4029+ name : 'myproject' ,
4030+ version : '1.0.0' ,
4031+ dependencies : { abbrev : '1.1.1' } ,
4032+ } ) ,
4033+ } ,
4034+ } )
4035+
4036+ // packument comes from configured registry
4037+ tnock ( t , 'https://new.example.com' )
4038+ . get ( '/npm/a/abbrev' )
4039+ . reply ( 200 , packument )
4040+
4041+ // tarball is NOT replaced because /npm/b does not start with /npm/c
4042+ tnock ( t , 'https://old.example.com' )
4043+ . get ( '/npm/b/abbrev/-/abbrev-1.1.1.tgz' )
4044+ . reply ( 200 , abbrevTGZ )
4045+
4046+ const arb = new Arborist ( {
4047+ path : resolve ( testdir , 'project' ) ,
4048+ registry : 'https://new.example.com/npm/a' ,
4049+ cache : resolve ( testdir , 'cache' ) ,
4050+ replaceRegistryHost : 'https://old.example.com/npm/c' ,
4051+ } )
4052+
4053+ await t . resolves ( arb . reify ( ) , 'non-matching path prefix leaves resolved URL unchanged' )
4054+ } )
4055+
39084056 t . test ( 'allowRemote=none allows registry tarball under registry path without trailing slash' , async t => {
39094057 const abbrevPackument5 = JSON . stringify ( {
39104058 _id : 'abbrev' ,
0 commit comments