Skip to content

Commit 6d96c05

Browse files
authored
[nodejs planner] InputFiles should take paths relative to devbox.json, and not combined with srcDir (#212)
## Summary ~This should fix a consequence of a change introduced in #200 to make the devbox.srcDir be an absolute path. In the BuildPlanners, we need the paths to be relative so they are inside the "docker context" and can be used in Dockerfiles.~ New Fix: I think the problem is actually scoped to just the NodeJSPlanner. Within NodeJSPlanner, the inputFiles were being set using `filepath.Join(srcDir, <filename>)` when instead it should be just `<filename>`, or more pedantically `path/of/filename/from/devbox-json`. This is because the docker-context is the directory-of-devbox-json, and any files `COPY --link`'d should be specified with paths relative to this docker-context. I inspected `git grep InputFiles` and it seems NodeJSPlanner is the only one with this issue. I also went back in history to a commit from Monday, built the binary and found that the following would fail due to this reason: ``` > cd testdata/nodejs > devbox build nodejs-18 ``` It works now with this fix. ## How was it tested? in www.jetpack.io repo, 1. did `devbox build` and `docker run -p 3000:3000 --expose 3000 -ti devbox` and could open the website in localhost:3000 2. did `cd root-of-www.jetpack.io` and did `devbox build www && docker run -p 3000:3000 --expose 3000 -ti devbox`. Works! 3. did `mkdir -p root-of-www.jetpack.io/www/fake-dir && cd root-of-www.jetpack.io/www/fake-dir` and then: `devbox build ../ && docker run -p 3000:3000 --expose 3000 -ti devbox`. Works! Also, works with just `devbox build` i.e. omitting `../` argument (due to #200) For NodeJS testdata in `testdata/nodejs`: 1. `cd testdata/nodejs` and `devbox build nodejs-18 && docker run devbox`. Works! 2. `cd testdata/nodejs/nodejs-18` and `devbox build && docker run devbox`. Works! 3. `cd testdata/nodejs/nodejs-18/fake-dir` and `devbox build && docker run devbox`. Works! in devbox repo, did `devbox build` and `docker run devbox` with: - `testdata/rust/rust-stable` - `testdata/python/pip-example`
1 parent 0bead52 commit 6d96c05

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

planner/languages/javascript/nodejs_planner.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ func (p *Planner) packages(pkgManager string, project *nodeProject) []string {
115115

116116
func (p *Planner) inputFiles(srcDir string) []string {
117117
inputFiles := []string{
118-
filepath.Join(srcDir, "package.json"),
118+
"package.json",
119119
}
120120

121-
npmPkgLockPath := filepath.Join(srcDir, "package-lock.json")
122-
if plansdk.FileExists(npmPkgLockPath) {
123-
inputFiles = append(inputFiles, npmPkgLockPath)
121+
npmPkgLockFile := "package-lock.json"
122+
if plansdk.FileExists(filepath.Join(srcDir, npmPkgLockFile)) {
123+
inputFiles = append(inputFiles, npmPkgLockFile)
124124
}
125125

126-
yarnPkgLockPath := filepath.Join(srcDir, "yarn.lock")
127-
if plansdk.FileExists(yarnPkgLockPath) {
128-
inputFiles = append(inputFiles, yarnPkgLockPath)
126+
yarnPkgLockFile := "yarn.lock"
127+
if plansdk.FileExists(filepath.Join(srcDir, yarnPkgLockFile)) {
128+
inputFiles = append(inputFiles, yarnPkgLockFile)
129129
}
130130

131131
return inputFiles

testdata/nodejs/nodejs-18/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ const NODE_MAJOR_VERSION = process.versions.node.split('.')[0];
22
if (NODE_MAJOR_VERSION !== "18") {
33
throw new Error('Node version is not 18');
44
}
5+
console.log("the NODE_MAJOR_VERSION is", NODE_MAJOR_VERSION)

0 commit comments

Comments
 (0)