@@ -736,3 +736,112 @@ test("install --initMirror should add init mirror deps from package.json", async
736
736
} ) ;
737
737
} ) ;
738
738
739
+ test ( "install --save with new dependency should be deterministic" , async ( ) => {
740
+ // mime-types@2.0.0->mime-db@1.0.3 is saved in local mirror and is deduped
741
+ // install mime-db@1.23.0 should move mime-db@1.0.3 deep into mime-types
742
+
743
+ let mirrorPath = "mirror-for-offline" ;
744
+ let fixture = "install-deterministic" ;
745
+ let cwd = path . join ( fixturesLoc , fixture ) ;
746
+ await fs . copy ( path . join ( cwd , "fbkpm.lock.before" ) , path . join ( cwd , "fbkpm.lock" ) ) ;
747
+ await fs . copy ( path . join ( cwd , "package.json.before" ) , path . join ( cwd , "package.json" ) ) ;
748
+
749
+ return run ( { } , [ ] , fixture , async ( config ) => {
750
+ assert ( semver . satisfies (
751
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-db/package.json" ) ) ) . version ,
752
+ "~1.0.1" )
753
+ ) ;
754
+ assert . equal (
755
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-types/package.json" ) ) ) . version ,
756
+ "2.0.0"
757
+ ) ;
758
+
759
+ return run ( { save : true } , [ "mime-db@1.23.0" ] , fixture , async ( config ) => {
760
+ assert ( semver . satisfies (
761
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-db/package.json" ) ) ) . version ,
762
+ "~1.23.0"
763
+ ) ) ;
764
+ assert . equal (
765
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-types/package.json" ) ) ) . version ,
766
+ "2.0.0"
767
+ ) ;
768
+ assert . equal (
769
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
770
+ "node_modules/mime-types/node_modules/mime-db/package.json" ) ) ) . version ,
771
+ "1.0.3"
772
+ ) ;
773
+ assert . deepEqual (
774
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "package.json" ) ) ) . dependencies , {
775
+ "mime-types" : "2.0.0" ,
776
+ "mime-db" : "1.23.0"
777
+ }
778
+ ) ;
779
+
780
+ let lockFileWritten = await fs . readFile ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
781
+ let lockFileLines = lockFileWritten . split ( "\n" ) . filter ( ( line ) => ! ! line ) ;
782
+ assert . equal ( lockFileLines . length , 14 ) ;
783
+
784
+
785
+ let mirror = await fs . walk ( path . join ( config . cwd , mirrorPath ) ) ;
786
+ assert . equal ( mirror . length , 3 ) ;
787
+ assert . equal ( mirror [ 1 ] . relative , "mime-db-1.23.0.tgz" ) ;
788
+
789
+ await fs . unlink ( mirror [ 1 ] . absolute ) ;
790
+ await fs . unlink ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
791
+ await fs . unlink ( path . join ( config . cwd , "package.json" ) ) ;
792
+ } ) ;
793
+ } ) ;
794
+ } ) ;
795
+
796
+ test . only ( "install --save with new dependency should be deterministic 2" , async ( ) => {
797
+ // mime-types@2.0.0->mime-db@1.0.1 is saved in local mirror and is deduped
798
+ // install mime-db@1.0.3 should replace mime-db@1.0.1 in root
799
+
800
+ let mirrorPath = "mirror-for-offline" ;
801
+ let fixture = "install-deterministic-2" ;
802
+ let cwd = path . join ( fixturesLoc , fixture ) ;
803
+ await fs . copy ( path . join ( cwd , "fbkpm.lock.before" ) , path . join ( cwd , "fbkpm.lock" ) ) ;
804
+ await fs . copy ( path . join ( cwd , "package.json.before" ) , path . join ( cwd , "package.json" ) ) ;
805
+
806
+ return run ( { } , [ ] , fixture , async ( config ) => {
807
+ assert . equal (
808
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-db/package.json" ) ) ) . version ,
809
+ "1.0.1"
810
+ ) ;
811
+ assert . equal (
812
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-types/package.json" ) ) ) . version ,
813
+ "2.0.0"
814
+ ) ;
815
+
816
+ return run ( { save : true } , [ "mime-db@1.0.3" ] , fixture , async ( config ) => {
817
+ assert . equal (
818
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-db/package.json" ) ) ) . version ,
819
+ "1.0.3"
820
+ ) ;
821
+ assert . equal (
822
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-types/package.json" ) ) ) . version ,
823
+ "2.0.0"
824
+ ) ;
825
+ assert ( ! await fs . exists ( path . join ( config . cwd , "node_modules/mime-types/node-modules/mime-db" ) ) ) ;
826
+ assert . deepEqual (
827
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "package.json" ) ) ) . dependencies , {
828
+ "mime-types" : "2.0.0" ,
829
+ "mime-db" : "1.0.3"
830
+ }
831
+ ) ;
832
+
833
+ let lockFileWritten = await fs . readFile ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
834
+ let lockFileLines = lockFileWritten . split ( "\n" ) . filter ( ( line ) => ! ! line ) ;
835
+ assert . equal ( lockFileLines . length , 10 ) ;
836
+
837
+
838
+ let mirror = await fs . walk ( path . join ( config . cwd , mirrorPath ) ) ;
839
+ assert . equal ( mirror . length , 3 ) ;
840
+ assert . equal ( mirror [ 1 ] . relative , "mime-db-1.0.3.tgz" ) ;
841
+
842
+ await fs . unlink ( mirror [ 1 ] . absolute ) ;
843
+ await fs . unlink ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
844
+ await fs . unlink ( path . join ( config . cwd , "package.json" ) ) ;
845
+ } ) ;
846
+ } ) ;
847
+ } ) ;
0 commit comments