@@ -2,6 +2,7 @@ const { 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' )
@@ -2865,3 +2866,132 @@ t.test('installLinks', (t) => {
2865
2866
2866
2867
t . end ( )
2867
2868
} )
2869
+
2870
+ t . only ( 'should preserve exact ranges, missing actual tree' , async ( t ) => {
2871
+ const Arborist = require ( '../../lib/index.js' )
2872
+ const abbrev = resolve ( __dirname ,
2873
+ '../fixtures/registry-mocks/content/abbrev/-/abbrev-1.1.1.tgz' )
2874
+ const abbrevTGZ = fs . readFileSync ( abbrev )
2875
+
2876
+ const abbrevPackument = JSON . stringify ( {
2877
+ _id : 'abbrev' ,
2878
+ _rev : 'lkjadflkjasdf' ,
2879
+ name : 'abbrev' ,
2880
+ 'dist-tags' : { latest : '1.1.1' } ,
2881
+ versions : {
2882
+ '1.1.1' : {
2883
+ name : 'abbrev' ,
2884
+ version : '1.1.1' ,
2885
+ dist : {
2886
+ tarball : 'https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz' ,
2887
+ } ,
2888
+ } ,
2889
+ } ,
2890
+ } )
2891
+
2892
+ const abbrevPackument2 = JSON . stringify ( {
2893
+ _id : 'abbrev' ,
2894
+ _rev : 'lkjadflkjasdf' ,
2895
+ name : 'abbrev' ,
2896
+ 'dist-tags' : { latest : '1.1.1' } ,
2897
+ versions : {
2898
+ '1.1.1' : {
2899
+ name : 'abbrev' ,
2900
+ version : '1.1.1' ,
2901
+ dist : {
2902
+ tarball : 'https://registry.garbage.org/abbrev/-/abbrev-1.1.1.tgz' ,
2903
+ } ,
2904
+ } ,
2905
+ } ,
2906
+ } )
2907
+
2908
+ t . only ( 'host should not be replaced replaceRegistryHost=never' , async ( t ) => {
2909
+ const testdir = t . testdir ( {
2910
+ project : {
2911
+ 'package.json' : JSON . stringify ( {
2912
+ name : 'myproject' ,
2913
+ version : '1.0.0' ,
2914
+ dependencies : {
2915
+ abbrev : '1.1.1' ,
2916
+ } ,
2917
+ } ) ,
2918
+ } ,
2919
+ } )
2920
+
2921
+ tnock ( t , 'https://registry.github.com' )
2922
+ . get ( '/abbrev' )
2923
+ . reply ( 200 , abbrevPackument )
2924
+
2925
+ tnock ( t , 'https://registry.npmjs.org' )
2926
+ . get ( '/abbrev/-/abbrev-1.1.1.tgz' )
2927
+ . reply ( 200 , abbrevTGZ )
2928
+
2929
+ const arb = new Arborist ( {
2930
+ path : resolve ( testdir , 'project' ) ,
2931
+ registry : 'https://registry.github.com' ,
2932
+ cache : resolve ( testdir , 'cache' ) ,
2933
+ replaceRegistryHost : 'never' ,
2934
+ } )
2935
+ await arb . reify ( )
2936
+ } )
2937
+
2938
+ t . only ( 'host should be replaced replaceRegistryHost=npmjs' , async ( t ) => {
2939
+ const testdir = t . testdir ( {
2940
+ project : {
2941
+ 'package.json' : JSON . stringify ( {
2942
+ name : 'myproject' ,
2943
+ version : '1.0.0' ,
2944
+ dependencies : {
2945
+ abbrev : '1.1.1' ,
2946
+ } ,
2947
+ } ) ,
2948
+ } ,
2949
+ } )
2950
+
2951
+ tnock ( t , 'https://registry.github.com' )
2952
+ . get ( '/abbrev' )
2953
+ . reply ( 200 , abbrevPackument )
2954
+
2955
+ tnock ( t , 'https://registry.github.com' )
2956
+ . get ( '/abbrev/-/abbrev-1.1.1.tgz' )
2957
+ . reply ( 200 , abbrevTGZ )
2958
+
2959
+ const arb = new Arborist ( {
2960
+ path : resolve ( testdir , 'project' ) ,
2961
+ registry : 'https://registry.github.com' ,
2962
+ cache : resolve ( testdir , 'cache' ) ,
2963
+ replaceRegistryHost : 'npmjs' ,
2964
+ } )
2965
+ await arb . reify ( )
2966
+ } )
2967
+
2968
+ t . only ( 'host should be always replaceRegistryHost=always' , async ( t ) => {
2969
+ const testdir = t . testdir ( {
2970
+ project : {
2971
+ 'package.json' : JSON . stringify ( {
2972
+ name : 'myproject' ,
2973
+ version : '1.0.0' ,
2974
+ dependencies : {
2975
+ abbrev : '1.1.1' ,
2976
+ } ,
2977
+ } ) ,
2978
+ } ,
2979
+ } )
2980
+
2981
+ tnock ( t , 'https://registry.github.com' )
2982
+ . get ( '/abbrev' )
2983
+ . reply ( 200 , abbrevPackument2 )
2984
+
2985
+ tnock ( t , 'https://registry.github.com' )
2986
+ . get ( '/abbrev/-/abbrev-1.1.1.tgz' )
2987
+ . reply ( 200 , abbrevTGZ )
2988
+
2989
+ const arb = new Arborist ( {
2990
+ path : resolve ( testdir , 'project' ) ,
2991
+ registry : 'https://registry.github.com' ,
2992
+ cache : resolve ( testdir , 'cache' ) ,
2993
+ replaceRegistryHost : 'always' ,
2994
+ } )
2995
+ await arb . reify ( )
2996
+ } )
2997
+ } )
0 commit comments