@@ -28,6 +28,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
28
28
layersDir string
29
29
workingDir string
30
30
cnbDir string
31
+ tempDir string
31
32
32
33
processLayerDir string
33
34
processWorkingDir string
@@ -60,6 +61,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
60
61
cnbDir , err = os .MkdirTemp ("" , "cnb" )
61
62
Expect (err ).NotTo (HaveOccurred ())
62
63
64
+ tempDir = t .TempDir ()
65
+ t .Setenv ("TMPDIR" , tempDir )
66
+
63
67
t .Setenv ("BP_NODE_PROJECT_PATH" , "" )
64
68
65
69
buildProcess = & fakes.BuildProcess {}
@@ -423,6 +427,38 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
423
427
Expect (symlinkResolver .ResolveCall .Receives .LockfilePath ).To (Equal (filepath .Join (workingDir , "package-lock.json" )))
424
428
Expect (symlinkResolver .ResolveCall .Receives .LayerPath ).To (Equal (filepath .Join (layersDir , "launch-modules" )))
425
429
})
430
+
431
+ it ("symlinks node_modules/.cache to tmp/node_modules_cache in order to work for the run user" , func () {
432
+ err := os .MkdirAll (filepath .Join (tempDir , "node_modules_cache" , "temp-content" ), os .ModePerm )
433
+ Expect (err ).NotTo (HaveOccurred ())
434
+ result , err := build (packit.BuildContext {
435
+ BuildpackInfo : packit.BuildpackInfo {
436
+ SBOMFormats : []string {"application/vnd.cyclonedx+json" , "application/spdx+json" , "application/vnd.syft+json" },
437
+ },
438
+ Platform : packit.Platform {
439
+ Path : "some-platform-path" ,
440
+ },
441
+ WorkingDir : workingDir ,
442
+ Layers : packit.Layers {Path : layersDir },
443
+ CNBPath : cnbDir ,
444
+ Plan : packit.BuildpackPlan {
445
+ Entries : []packit.BuildpackPlanEntry {
446
+ {Name : "node_modules" },
447
+ },
448
+ },
449
+ })
450
+ Expect (err ).NotTo (HaveOccurred ())
451
+
452
+ Expect (len (result .Layers )).To (Equal (2 ))
453
+
454
+ launchLayer := result .Layers [0 ]
455
+ Expect (launchLayer .Name ).To (Equal ("launch-modules" ))
456
+ Expect (launchLayer .Path ).To (Equal (filepath .Join (layersDir , "launch-modules" )))
457
+
458
+ linkedTmpContent := filepath .Join (launchLayer .Path , "node_modules" , ".cache" , "temp-content" )
459
+ _ , err = os .Stat (linkedTmpContent )
460
+ Expect (err ).NotTo (HaveOccurred ())
461
+ })
426
462
})
427
463
428
464
context ("when node_modules is required at build and launch" , func () {
@@ -674,6 +710,39 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
674
710
Expect (symlinkResolver .CopyCall .Receives .SourceLayerPath ).To (Equal (filepath .Join (buildLayer .Path )))
675
711
Expect (symlinkResolver .CopyCall .Receives .TargetLayerPath ).To (Equal (filepath .Join (launchLayer .Path )))
676
712
})
713
+
714
+ it ("symlinks node_modules/.cache to tmp/node_modules_cache in order to work for the run user" , func () {
715
+ err := os .MkdirAll (filepath .Join (tempDir , "node_modules_cache" , "temp-content" ), os .ModePerm )
716
+ Expect (err ).NotTo (HaveOccurred ())
717
+ result , err := build (packit.BuildContext {
718
+ BuildpackInfo : packit.BuildpackInfo {
719
+ SBOMFormats : []string {"application/vnd.cyclonedx+json" , "application/spdx+json" , "application/vnd.syft+json" },
720
+ },
721
+ Platform : packit.Platform {
722
+ Path : "some-platform-path" ,
723
+ },
724
+ WorkingDir : workingDir ,
725
+ Layers : packit.Layers {Path : layersDir },
726
+ CNBPath : cnbDir ,
727
+ Plan : packit.BuildpackPlan {
728
+ Entries : []packit.BuildpackPlanEntry {
729
+ {Name : "node_modules" },
730
+ },
731
+ },
732
+ })
733
+ Expect (err ).NotTo (HaveOccurred ())
734
+
735
+ Expect (len (result .Layers )).To (Equal (3 ))
736
+
737
+ launchLayer := result .Layers [1 ]
738
+ Expect (launchLayer .Name ).To (Equal ("launch-modules" ))
739
+ Expect (launchLayer .Path ).To (Equal (filepath .Join (layersDir , "launch-modules" )))
740
+
741
+ linkedTmpContent := filepath .Join (launchLayer .Path , "node_modules" , ".cache" , "temp-content" )
742
+ _ , err = os .Stat (linkedTmpContent )
743
+ Expect (err ).NotTo (HaveOccurred ())
744
+ })
745
+
677
746
})
678
747
679
748
context ("when one npmrc binding is detected" , func () {
@@ -768,6 +837,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
768
837
if err != nil {
769
838
return err
770
839
}
840
+ err = os .MkdirAll (filepath .Join (ld , "node_modules" ), os .ModePerm )
841
+ if err != nil {
842
+ return err
843
+ }
771
844
772
845
return nil
773
846
}
0 commit comments