Skip to content

Commit f327fcd

Browse files
arjun024ryanmoran
authored andcommitted
Symlink after running npm ci/rebuild not before
With node 16 and the npm7 that comes with it, it was noticed that it refuses to follow a node_modules symlink if it was created prior to the run of npm commands. So we should run the commands first, then relocate the modules dir to the layer and then point the symlink there from the working directory of the app. In #290, this was dealt with for the "npm install" command. This commit applies the same logic to rebuild and ci commands. See matrix here for how the buildpack chooses commands. https://paketo.io/docs/reference/nodejs-reference The only important changes are in ci_build_process.go and rebuild_build_process.go. Others are testdata changes. Fixes: paketo-buildpacks/nodejs#492
1 parent 8a23d2a commit f327fcd

File tree

1,883 files changed

+128377
-177138
lines changed

Some content is hidden

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

1,883 files changed

+128377
-177138
lines changed

ci_build_process.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package npminstall
22

33
import (
44
"bytes"
5+
"errors"
56
"fmt"
67
"os"
78
"path/filepath"
@@ -61,16 +62,6 @@ func (r CIBuildProcess) Run(modulesDir, cacheDir, workingDir string) error {
6162
return err
6263
}
6364

64-
err = fs.Move(filepath.Join(workingDir, "node_modules"), filepath.Join(modulesDir, "node_modules"))
65-
if err != nil {
66-
return err
67-
}
68-
69-
err = os.Symlink(filepath.Join(modulesDir, "node_modules"), filepath.Join(workingDir, "node_modules"))
70-
if err != nil {
71-
return err
72-
}
73-
7465
buffer := bytes.NewBuffer(nil)
7566
args := []string{"ci", "--unsafe-perm", "--cache", cacheDir}
7667

@@ -90,5 +81,24 @@ func (r CIBuildProcess) Run(modulesDir, cacheDir, workingDir string) error {
9081
return fmt.Errorf("npm ci failed: %w", err)
9182
}
9283

84+
_, err = os.Stat(filepath.Join(workingDir, "node_modules"))
85+
if err != nil {
86+
if errors.Is(err, os.ErrNotExist) {
87+
return nil
88+
} else {
89+
return fmt.Errorf("unable to stat node_modules in working directory: %w", err)
90+
}
91+
}
92+
93+
err = fs.Move(filepath.Join(workingDir, "node_modules"), filepath.Join(modulesDir, "node_modules"))
94+
if err != nil {
95+
return err
96+
}
97+
98+
err = os.Symlink(filepath.Join(modulesDir, "node_modules"), filepath.Join(workingDir, "node_modules"))
99+
if err != nil {
100+
return err
101+
}
102+
93103
return nil
94104
}

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

integration/testdata/pre_post_scripts_vendored/node_modules/.bin/save-to-github-cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

integration/testdata/pre_post_scripts_vendored/node_modules/.bin/sshpk-conv

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/sshpk-sign

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/sshpk-verify

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/uuid

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)