Skip to content

Commit

Permalink
Update buildpack and fixtures to work with Node 16 (#290)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Nov 17, 2021
1 parent 8630801 commit b6d8024
Show file tree
Hide file tree
Showing 3,872 changed files with 349,394 additions and 261,233 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
26 changes: 21 additions & 5 deletions install_build_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package npminstall

import (
"bytes"
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/paketo-buildpacks/packit/fs"
"github.com/paketo-buildpacks/packit/pexec"
"github.com/paketo-buildpacks/packit/scribe"
)
Expand Down Expand Up @@ -35,11 +37,6 @@ func (r InstallBuildProcess) Run(modulesDir, cacheDir, workingDir string) error
return err
}

err = os.Symlink(filepath.Join(modulesDir, "node_modules"), filepath.Join(workingDir, "node_modules"))
if err != nil {
return err
}

buffer := bytes.NewBuffer(nil)
args := []string{"install", "--unsafe-perm", "--cache", cacheDir}

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

_, err = os.Stat(filepath.Join(workingDir, "node_modules"))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil
} else {
return fmt.Errorf("unable to stat node_modules in working directory: %w", err)
}
}

err = fs.Move(filepath.Join(workingDir, "node_modules"), filepath.Join(modulesDir, "node_modules"))
if err != nil {
return err
}

err = os.Symlink(filepath.Join(modulesDir, "node_modules"), filepath.Join(workingDir, "node_modules"))
if err != nil {
return err
}

return nil
}
11 changes: 10 additions & 1 deletion install_build_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func testInstallBuildProcess(t *testing.T, context spec.G, it spec.S) {
})

context("Run", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(workingDir, "node_modules"), os.ModePerm)).To(Succeed())
})

it("succeeds", func() {
Expect(process.Run(modulesDir, cacheDir, workingDir)).To(Succeed())
Expect(executable.ExecuteCall.Receives.Execution).To(Equal(pexec.Execution{
Expand Down Expand Up @@ -100,7 +104,12 @@ func testInstallBuildProcess(t *testing.T, context spec.G, it spec.S) {

context("when the node_modules directory cannot be symlinked into the working directory", func() {
it.Before(func() {
Expect(os.Chmod(workingDir, 0000)).To(Succeed())
Expect(os.MkdirAll(filepath.Join(workingDir, "node_modules"), os.ModePerm)).To(Succeed())
Expect(os.Chmod(filepath.Join(workingDir, "node_modules"), 0000)).To(Succeed())
})

it.After(func() {
Expect(os.Chmod(filepath.Join(workingDir, "node_modules"), os.ModePerm)).To(Succeed())
})

it("returns an error", func() {
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/empty_node_modules/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions integration/testdata/locked_app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration/testdata/no_vendored_dependencies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"express": "~4.0.0",
"chalk-cli": "~3.0.0"
},
"engines" : { "node" : "~>14" }
"engines" : { "node" : "~>16" }
}
2 changes: 1 addition & 1 deletion integration/testdata/npmrc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"url": ""
},
"engines": {
"node": "~14"
"node": "~16"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b6d8024

Please sign in to comment.