Skip to content

Commit 4543cfc

Browse files
authored
[Bug] Fix nodejs npm build step (#112)
## Summary Quick fix nodejs npm build step, as the command is different between npm and yarn. This needs to go in before the next release. ## How was it tested? go test ./...
1 parent 5f04732 commit 4543cfc

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

planner/languages/javascript/nodejs_planner.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,18 @@ func (p *Planner) inputFiles(srcDir string) []string {
131131

132132
func (p *Planner) buildCommand(pkgManager string, project *nodeProject) string {
133133
buildScript := project.Scripts.Build
134+
defaultBuildCmd := "npm run build"
134135
postBuildCmdHook := "npm prune --production"
135136

136137
if pkgManager == "yarn" {
138+
defaultBuildCmd = "yarn build"
137139
postBuildCmdHook = "yarn install --production --ignore-scripts --prefer-offline"
138140
}
139141
if buildScript == "" {
140142
return postBuildCmdHook
141143
}
142144

143-
return fmt.Sprintf("%s build && %s", pkgManager, postBuildCmdHook)
145+
return fmt.Sprintf("%s && %s", defaultBuildCmd, postBuildCmdHook)
144146
}
145147

146148
func (p *Planner) startCommand(pkgManager string, project *nodeProject) string {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"name": "nodejs-npm",
33
"main": "index.js",
4+
"scripts": {
5+
"build": "echo building...",
6+
"start": "node index.js"
7+
},
48
"dependencies": {}
59
}

testdata/nodejs/nodejs-npm/plan.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
]
88
},
99
"build_stage": {
10-
"command": "npm prune --production",
10+
"command": "npm run build && npm prune --production",
1111
"input_files": [
1212
"."
1313
]
1414
},
1515
"start_stage": {
16-
"command": "node index.js",
16+
"command": "npm start",
1717
"input_files": [
1818
"."
1919
]

0 commit comments

Comments
 (0)