summaryrefslogtreecommitdiff
path: root/config/node.go
diff options
context:
space:
mode:
Diffstat (limited to 'config/node.go')
-rw-r--r--config/node.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/config/node.go b/config/node.go
index bd5d4db..5834443 100644
--- a/config/node.go
+++ b/config/node.go
@@ -9,15 +9,17 @@ import (
// whether/how to install NPM packages.
//
type NodeConfig struct {
- Dependencies Flag `yaml:"dependencies"` // install dependencies declared in package.json
- Env string `yaml:"env" validate:"omitempty,nodeenv"` // environment name ("production" install)
+ Requirements []string `yaml:"requirements"` // install requirements from given files
+ Env string `yaml:"env" validate:"omitempty,nodeenv"` // environment name ("production" install)
}
// Merge takes another NodeConfig and merges its fields into this one's,
-// overwriting both the environment and dependencies flag.
+// overwriting both the environment and requirements files.
//
func (nc *NodeConfig) Merge(nc2 NodeConfig) {
- nc.Dependencies.Merge(nc2.Dependencies)
+ if nc2.Requirements != nil {
+ nc.Requirements = nc2.Requirements
+ }
if nc2.Env != "" {
nc.Env = nc2.Env
@@ -30,13 +32,13 @@ func (nc *NodeConfig) Merge(nc2 NodeConfig) {
//
// PhasePreInstall
//
-// Installs Node package dependencies declared in package.json into the shared
-// library directory (/opt/lib). Only production related packages are install
-// if NodeConfig.Env is set to "production" in which case `npm dedupe` is also
-// run. Installing dependencies during the build.PhasePreInstall phase allows
-// a compiler implementation (e.g. Docker) to produce cache-efficient output
-// so only changes to package.json will invalidate these steps of the image
-// build.
+// Installs Node package dependencies declared in requirements files into the
+// shared library directory (/opt/lib). Only production related packages are
+// install if NodeConfig.Env is set to "production" in which case `npm dedupe`
+// is also run. Installing dependencies during the build.PhasePreInstall phase
+// allows a compiler implementation (e.g. Docker) to produce cache-efficient
+// output so only changes to package.json will invalidate these steps of the
+// image build.
//
// PhasePostInstall
//
@@ -48,7 +50,7 @@ func (nc *NodeConfig) Merge(nc2 NodeConfig) {
func (nc NodeConfig) InstructionsForPhase(phase build.Phase) []build.Instruction {
switch phase {
case build.PhasePreInstall:
- if nc.Dependencies.True {
+ if len(nc.Requirements) > 0 {
npmInstall := build.RunAll{[]build.Run{
{"cd", []string{LocalLibPrefix}},
{"npm install", []string{}},
@@ -62,12 +64,12 @@ func (nc NodeConfig) InstructionsForPhase(phase build.Phase) []build.Instruction
}
return []build.Instruction{
- build.Copy{[]string{"package.json"}, LocalLibPrefix},
+ build.Copy{nc.Requirements, LocalLibPrefix},
npmInstall,
}
}
case build.PhasePostInstall:
- if nc.Env != "" || nc.Dependencies.True {
+ if nc.Env != "" || len(nc.Requirements) > 0 {
return []build.Instruction{build.Env{map[string]string{
"NODE_ENV": nc.Env,
"NODE_PATH": path.Join(LocalLibPrefix, "node_modules"),