@@ -2,6 +2,7 @@ const { join, resolve, basename } = require('path')
2
2
const t = require ( 'tap' )
3
3
const runScript = require ( '@npmcli/run-script' )
4
4
const localeCompare = require ( '@isaacs/string-locale-compare' ) ( 'en' )
5
+ const tnock = require ( '../fixtures/tnock' )
5
6
6
7
// mock rimraf so we can make it fail in rollback tests
7
8
const realRimraf = require ( 'rimraf' )
@@ -2923,3 +2924,132 @@ t.test('installLinks', (t) => {
2923
2924
2924
2925
t . end ( )
2925
2926
} )
2927
+
2928
+ t . only ( 'should preserve exact ranges, missing actual tree' , async ( t ) => {
2929
+ const Arborist = require ( '../../lib/index.js' )
2930
+ const abbrev = resolve ( __dirname ,
2931
+ '../fixtures/registry-mocks/content/abbrev/-/abbrev-1.1.1.tgz' )
2932
+ const abbrevTGZ = fs . readFileSync ( abbrev )
2933
+
2934
+ const abbrevPackument = JSON . stringify ( {
2935
+ _id : 'abbrev' ,
2936
+ _rev : 'lkjadflkjasdf' ,
2937
+ name : 'abbrev' ,
2938
+ 'dist-tags' : { latest : '1.1.1' } ,
2939
+ versions : {
2940
+ '1.1.1' : {
2941
+ name : 'abbrev' ,
2942
+ version : '1.1.1' ,
2943
+ dist : {
2944
+ tarball : 'https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz' ,
2945
+ } ,
2946
+ } ,
2947
+ } ,
2948
+ } )
2949
+
2950
+ const abbrevPackument2 = JSON . stringify ( {
2951
+ _id : 'abbrev' ,
2952
+ _rev : 'lkjadflkjasdf' ,
2953
+ name : 'abbrev' ,
2954
+ 'dist-tags' : { latest : '1.1.1' } ,
2955
+ versions : {
2956
+ '1.1.1' : {
2957
+ name : 'abbrev' ,
2958
+ version : '1.1.1' ,
2959
+ dist : {
2960
+ tarball : 'https://registry.garbage.org/abbrev/-/abbrev-1.1.1.tgz' ,
2961
+ } ,
2962
+ } ,
2963
+ } ,
2964
+ } )
2965
+
2966
+ t . only ( 'host should not be replaced replaceRegistryHost=never' , async ( t ) => {
2967
+ const testdir = t . testdir ( {
2968
+ project : {
2969
+ 'package.json' : JSON . stringify ( {
2970
+ name : 'myproject' ,
2971
+ version : '1.0.0' ,
2972
+ dependencies : {
2973
+ abbrev : '1.1.1' ,
2974
+ } ,
2975
+ } ) ,
2976
+ } ,
2977
+ } )
2978
+
2979
+ tnock ( t , 'https://registry.github.com' )
2980
+ . get ( '/abbrev' )
2981
+ . reply ( 200 , abbrevPackument )
2982
+
2983
+ tnock ( t , 'https://registry.npmjs.org' )
2984
+ . get ( '/abbrev/-/abbrev-1.1.1.tgz' )
2985
+ . reply ( 200 , abbrevTGZ )
2986
+
2987
+ const arb = new Arborist ( {
2988
+ path : resolve ( testdir , 'project' ) ,
2989
+ registry : 'https://registry.github.com' ,
2990
+ cache : resolve ( testdir , 'cache' ) ,
2991
+ replaceRegistryHost : 'never' ,
2992
+ } )
2993
+ await arb . reify ( )
2994
+ } )
2995
+
2996
+ t . only ( 'host should be replaced replaceRegistryHost=npmjs' , async ( t ) => {
2997
+ const testdir = t . testdir ( {
2998
+ project : {
2999
+ 'package.json' : JSON . stringify ( {
3000
+ name : 'myproject' ,
3001
+ version : '1.0.0' ,
3002
+ dependencies : {
3003
+ abbrev : '1.1.1' ,
3004
+ } ,
3005
+ } ) ,
3006
+ } ,
3007
+ } )
3008
+
3009
+ tnock ( t , 'https://registry.github.com' )
3010
+ . get ( '/abbrev' )
3011
+ . reply ( 200 , abbrevPackument )
3012
+
3013
+ tnock ( t , 'https://registry.github.com' )
3014
+ . get ( '/abbrev/-/abbrev-1.1.1.tgz' )
3015
+ . reply ( 200 , abbrevTGZ )
3016
+
3017
+ const arb = new Arborist ( {
3018
+ path : resolve ( testdir , 'project' ) ,
3019
+ registry : 'https://registry.github.com' ,
3020
+ cache : resolve ( testdir , 'cache' ) ,
3021
+ replaceRegistryHost : 'npmjs' ,
3022
+ } )
3023
+ await arb . reify ( )
3024
+ } )
3025
+
3026
+ t . only ( 'host should be always replaceRegistryHost=always' , async ( t ) => {
3027
+ const testdir = t . testdir ( {
3028
+ project : {
3029
+ 'package.json' : JSON . stringify ( {
3030
+ name : 'myproject' ,
3031
+ version : '1.0.0' ,
3032
+ dependencies : {
3033
+ abbrev : '1.1.1' ,
3034
+ } ,
3035
+ } ) ,
3036
+ } ,
3037
+ } )
3038
+
3039
+ tnock ( t , 'https://registry.github.com' )
3040
+ . get ( '/abbrev' )
3041
+ . reply ( 200 , abbrevPackument2 )
3042
+
3043
+ tnock ( t , 'https://registry.github.com' )
3044
+ . get ( '/abbrev/-/abbrev-1.1.1.tgz' )
3045
+ . reply ( 200 , abbrevTGZ )
3046
+
3047
+ const arb = new Arborist ( {
3048
+ path : resolve ( testdir , 'project' ) ,
3049
+ registry : 'https://registry.github.com' ,
3050
+ cache : resolve ( testdir , 'cache' ) ,
3051
+ replaceRegistryHost : 'always' ,
3052
+ } )
3053
+ await arb . reify ( )
3054
+ } )
3055
+ } )
0 commit comments