Skip to content

Commit a824bac

Browse files
dfreilichndon55555
andcommitted
Define consts for various Node sources
Co-authored-by: Don Nguyen <dnguyen@pivotal.io>
1 parent fe9cffe commit a824bac

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

cmd/detect/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/cloudfoundry/libcfbuildpack/buildpackplan"
9+
810
"github.com/cloudfoundry/libcfbuildpack/helper"
911
"github.com/cloudfoundry/node-engine-cnb/node"
1012
"github.com/cloudfoundry/node-engine-cnb/nvmrc"
@@ -37,7 +39,7 @@ func runDetect(context detect.Detect) (int, error) {
3739
}
3840

3941
if nvmrcExists {
40-
versionSource = ".nvmrc"
42+
versionSource = node.NvmrcSource
4143
version, err = nvmrc.GetVersion(nvmrcPath, context.Logger)
4244
if err != nil {
4345
return context.Fail(), err
@@ -52,7 +54,7 @@ func runDetect(context detect.Detect) (int, error) {
5254
}
5355

5456
if buildpackYamlExists {
55-
versionSource = "buildpack.yml"
57+
versionSource = node.BuildpackYAMLSource
5658
bpYml := &node.BuildpackYAML{}
5759
err := helper.ReadBuildpackYaml(buildpackYamlPath, bpYml)
5860
if err != nil {
@@ -70,7 +72,7 @@ func runDetect(context detect.Detect) (int, error) {
7072
Requires: []buildplan.Required{{
7173
Name: node.Dependency,
7274
Version: version,
73-
Metadata: buildplan.Metadata{"launch": true, node.VersionSource: versionSource},
75+
Metadata: buildplan.Metadata{"launch": true, buildpackplan.VersionSource: versionSource},
7476
}},
7577
})
7678
}

cmd/detect/main_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"path/filepath"
66
"testing"
77

8+
"github.com/cloudfoundry/libcfbuildpack/buildpackplan"
9+
810
"github.com/cloudfoundry/node-engine-cnb/node"
911

1012
"github.com/buildpack/libbuildpack/buildplan"
@@ -43,7 +45,7 @@ func testDetect(t *testing.T, when spec.G, it spec.S) {
4345
})
4446

4547
it("should request the node version in the buildpack.yml", func() {
46-
buildPlan = getStandardBuildplanWithNodeVersion(buildpackYamlVersion, "buildpack.yml")
48+
buildPlan = getStandardBuildplanWithNodeVersion(buildpackYamlVersion, node.BuildpackYAMLSource)
4749
runDetectAndExpectBuildplan(factory, buildPlan, t)
4850
})
4951
})
@@ -54,7 +56,7 @@ func testDetect(t *testing.T, when spec.G, it spec.S) {
5456
})
5557

5658
it("should request the node version in the .nvmrc file", func() {
57-
buildPlan = getStandardBuildplanWithNodeVersion(nvmrcVersion, ".nvmrc")
59+
buildPlan = getStandardBuildplanWithNodeVersion(nvmrcVersion, node.NvmrcSource)
5860
runDetectAndExpectBuildplan(factory, buildPlan, t)
5961
})
6062
})
@@ -66,7 +68,7 @@ func testDetect(t *testing.T, when spec.G, it spec.S) {
6668
})
6769

6870
it("should request the node version in the buildpack.yml", func() {
69-
buildPlan = getStandardBuildplanWithNodeVersion(buildpackYamlVersion, "buildpack.yml")
71+
buildPlan = getStandardBuildplanWithNodeVersion(buildpackYamlVersion, node.BuildpackYAMLSource)
7072
runDetectAndExpectBuildplan(factory, buildPlan, t)
7173
})
7274
})
@@ -78,7 +80,7 @@ func testDetect(t *testing.T, when spec.G, it spec.S) {
7880
})
7981

8082
it("should request the node version in the .nvmrc", func() {
81-
buildPlan = getStandardBuildplanWithNodeVersion(nvmrcVersion, "buildpack.yml")
83+
buildPlan = getStandardBuildplanWithNodeVersion(nvmrcVersion, node.BuildpackYAMLSource)
8284
runDetectAndExpectBuildplan(factory, buildPlan, t)
8385
})
8486
})
@@ -102,8 +104,8 @@ func getStandardBuildplanWithNodeVersion(version, versionSource string) buildpla
102104
Name: node.Dependency,
103105
Version: version,
104106
Metadata: buildplan.Metadata{
105-
"launch": true,
106-
node.VersionSource: versionSource,
107+
"launch": true,
108+
buildpackplan.VersionSource: versionSource,
107109
}}},
108110
}
109111
}

node/node.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
)
1111

1212
const Dependency = "node"
13-
const VersionSource = "version-source"
13+
const BuildpackYAMLSource = "buildpack.yml"
14+
const PackageJsonSource = "package.json"
15+
const NvmrcSource = ".nvmrc"
1416

1517
type Config struct {
1618
OptimizeMemory bool `yaml:"optimize-memory"`
@@ -29,10 +31,10 @@ type Contributor struct {
2931
}
3032

3133
var priorities = map[interface{}]int{
32-
"buildpack.yml": 3,
33-
"package.json": 2,
34-
".nvmrc": 1,
35-
"": -1,
34+
BuildpackYAMLSource: 3,
35+
PackageJsonSource: 2,
36+
NvmrcSource: 1,
37+
"": -1,
3638
}
3739

3840
func NewContributor(context build.Build) (Contributor, bool, error) {

0 commit comments

Comments
 (0)