Skip to content

Commit b6d8024

Browse files
Sophie Wigmorearjun024thitch97
authored
Update buildpack and fixtures to work with Node 16 (#290)
* Move re-configure vendored and preinstall app modules Signed-off-by: Arjun Sreedharan <[email protected]> * move all apps/tests to Node 16 Signed-off-by: Sophie Wigmore <[email protected]> * modify install process to deal with NPM 7 symlinking Signed-off-by: Sophie Wigmore <[email protected]> * add modules that require native module compilation to vendored apps Co-authored-by: Arjun Sreedharan <[email protected]> Co-authored-by: Tim Hitchener <[email protected]> Co-authored-by: Arjun Sreedharan <[email protected]>
1 parent 8630801 commit b6d8024

File tree

3,872 files changed

+349394
-261233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,872 files changed

+349394
-261233
lines changed

install_build_process.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package npminstall
22

33
import (
44
"bytes"
5+
"errors"
56
"fmt"
67
"os"
78
"path/filepath"
89
"strings"
910

11+
"github.com/paketo-buildpacks/packit/fs"
1012
"github.com/paketo-buildpacks/packit/pexec"
1113
"github.com/paketo-buildpacks/packit/scribe"
1214
)
@@ -35,11 +37,6 @@ func (r InstallBuildProcess) Run(modulesDir, cacheDir, workingDir string) error
3537
return err
3638
}
3739

38-
err = os.Symlink(filepath.Join(modulesDir, "node_modules"), filepath.Join(workingDir, "node_modules"))
39-
if err != nil {
40-
return err
41-
}
42-
4340
buffer := bytes.NewBuffer(nil)
4441
args := []string{"install", "--unsafe-perm", "--cache", cacheDir}
4542

@@ -59,5 +56,24 @@ func (r InstallBuildProcess) Run(modulesDir, cacheDir, workingDir string) error
5956
return fmt.Errorf("npm install failed: %w", err)
6057
}
6158

59+
_, err = os.Stat(filepath.Join(workingDir, "node_modules"))
60+
if err != nil {
61+
if errors.Is(err, os.ErrNotExist) {
62+
return nil
63+
} else {
64+
return fmt.Errorf("unable to stat node_modules in working directory: %w", err)
65+
}
66+
}
67+
68+
err = fs.Move(filepath.Join(workingDir, "node_modules"), filepath.Join(modulesDir, "node_modules"))
69+
if err != nil {
70+
return err
71+
}
72+
73+
err = os.Symlink(filepath.Join(modulesDir, "node_modules"), filepath.Join(workingDir, "node_modules"))
74+
if err != nil {
75+
return err
76+
}
77+
6278
return nil
6379
}

install_build_process_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func testInstallBuildProcess(t *testing.T, context spec.G, it spec.S) {
7171
})
7272

7373
context("Run", func() {
74+
it.Before(func() {
75+
Expect(os.MkdirAll(filepath.Join(workingDir, "node_modules"), os.ModePerm)).To(Succeed())
76+
})
77+
7478
it("succeeds", func() {
7579
Expect(process.Run(modulesDir, cacheDir, workingDir)).To(Succeed())
7680
Expect(executable.ExecuteCall.Receives.Execution).To(Equal(pexec.Execution{
@@ -100,7 +104,12 @@ func testInstallBuildProcess(t *testing.T, context spec.G, it spec.S) {
100104

101105
context("when the node_modules directory cannot be symlinked into the working directory", func() {
102106
it.Before(func() {
103-
Expect(os.Chmod(workingDir, 0000)).To(Succeed())
107+
Expect(os.MkdirAll(filepath.Join(workingDir, "node_modules"), os.ModePerm)).To(Succeed())
108+
Expect(os.Chmod(filepath.Join(workingDir, "node_modules"), 0000)).To(Succeed())
109+
})
110+
111+
it.After(func() {
112+
Expect(os.Chmod(filepath.Join(workingDir, "node_modules"), os.ModePerm)).To(Succeed())
104113
})
105114

106115
it("returns an error", func() {

integration/testdata/empty_node_modules/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/testdata/locked_app/package-lock.json

Lines changed: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/testdata/no_vendored_dependencies/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"express": "~4.0.0",
1313
"chalk-cli": "~3.0.0"
1414
},
15-
"engines" : { "node" : "~>14" }
15+
"engines" : { "node" : "~>16" }
1616
}

integration/testdata/npmrc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"url": ""
1616
},
1717
"engines": {
18-
"node": "~14"
18+
"node": "~16"
1919
}
2020
}

integration/testdata/pre_post_scripts_vendored/node_modules/.bin/install-from-cache

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/testdata/pre_post_scripts_vendored/node_modules/.bin/loose-envify

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/testdata/pre_post_scripts_vendored/node_modules/.bin/node-gyp

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/testdata/pre_post_scripts_vendored/node_modules/.bin/node-which

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)