Просмотр исходного кода

Use correct detection method for Node standalone

Mohammed Nafees 4 лет назад
Родитель
Сommit
c60d0f4940
3 измененных файлов с 31 добавлено и 27 удалено
  1. 28 24
      cmd/test-runtime/runtimes/nodejs.go
  2. 1 1
      go.mod
  3. 2 2
      go.sum

+ 28 - 24
cmd/test-runtime/runtimes/nodejs.go

@@ -6,8 +6,8 @@ import (
 	"path/filepath"
 	"path/filepath"
 	"sync"
 	"sync"
 
 
-	nodemodulebom "github.com/paketo-buildpacks/node-module-bom"
 	noderunscript "github.com/paketo-buildpacks/node-run-script"
 	noderunscript "github.com/paketo-buildpacks/node-run-script"
+	nodestart "github.com/paketo-buildpacks/node-start"
 	npminstall "github.com/paketo-buildpacks/npm-install"
 	npminstall "github.com/paketo-buildpacks/npm-install"
 	"github.com/paketo-buildpacks/packit"
 	"github.com/paketo-buildpacks/packit"
 	yarninstall "github.com/paketo-buildpacks/yarn-install"
 	yarninstall "github.com/paketo-buildpacks/yarn-install"
@@ -151,8 +151,8 @@ func (runtime *nodeRuntime) detectStandalone(results chan struct {
 	string
 	string
 	bool
 	bool
 }, workingDir string) {
 }, workingDir string) {
-	// FIXME: the detect function seems to be working for non-node projects as well?
-	detect := nodemodulebom.Detect()
+	appFinder := nodestart.NewNodeApplicationFinder()
+	detect := nodestart.Detect(appFinder)
 	_, err := detect(packit.DetectContext{
 	_, err := detect(packit.DetectContext{
 		WorkingDir: workingDir,
 		WorkingDir: workingDir,
 	})
 	})
@@ -193,29 +193,33 @@ func (runtime *nodeRuntime) Detect(workingDir string) (BuildpackInfo, map[string
 	}
 	}
 
 
 	if atLeastOne {
 	if atLeastOne {
-		// it is safe to assume that the project contains a package.json
-		packageJSONPath := filepath.Join(workingDir, "package.json")
-
-		scriptManager := noderunscript.NewScriptManager()
-		scripts, err := scriptManager.GetPackageScripts(workingDir)
-		if err != nil {
-			fmt.Printf("Error reading %s: %v\n", packageJSONPath, err)
-			os.Exit(1)
+		if detected[yarn] || detected[npm] {
+			// it is safe to assume that the project contains a package.json
+			packageJSONPath := filepath.Join(workingDir, "package.json")
+
+			scriptManager := noderunscript.NewScriptManager()
+			scripts, err := scriptManager.GetPackageScripts(workingDir)
+			if err != nil {
+				fmt.Printf("Error reading %s: %v\n", packageJSONPath, err)
+				os.Exit(1)
+			}
+
+			packageJSONParser := npminstall.NewPackageJSONParser()
+			engineVersion, err := packageJSONParser.ParseVersion(packageJSONPath)
+			if err != nil {
+				fmt.Printf("Error reading %s: %v\n", packageJSONPath, err)
+				os.Exit(1)
+			}
+
+			if detected[yarn] {
+				return *runtime.packs[yarn], map[string]interface{}{"scripts": scripts, "engine_version": engineVersion}
+			} else {
+				return *runtime.packs[npm], map[string]interface{}{"scripts": scripts, "engine_version": engineVersion}
+			}
 		}
 		}
 
 
-		packageJSONParser := npminstall.NewPackageJSONParser()
-		engineVersion, err := packageJSONParser.ParseVersion(packageJSONPath)
-		if err != nil {
-			fmt.Printf("Error reading %s: %v\n", packageJSONPath, err)
-			os.Exit(1)
-		}
-
-		if detected[yarn] {
-			return *runtime.packs[yarn], map[string]interface{}{"scripts": scripts, "engine_version": engineVersion}
-		} else if detected[npm] {
-			return *runtime.packs[npm], map[string]interface{}{"scripts": scripts, "engine_version": engineVersion}
-		} else if detected[standalone] {
-			return *runtime.packs[standalone], map[string]interface{}{"scripts": scripts, "engine_version": engineVersion}
+		if detected[standalone] {
+			return *runtime.packs[standalone], map[string]interface{}{}
 		}
 		}
 	}
 	}
 
 

+ 1 - 1
go.mod

@@ -41,8 +41,8 @@ require (
 	github.com/opencontainers/image-spec v1.0.1
 	github.com/opencontainers/image-spec v1.0.1
 	github.com/paketo-buildpacks/conda-env-update v0.2.2
 	github.com/paketo-buildpacks/conda-env-update v0.2.2
 	github.com/paketo-buildpacks/go-mod-vendor v0.3.1
 	github.com/paketo-buildpacks/go-mod-vendor v0.3.1
-	github.com/paketo-buildpacks/node-module-bom v0.1.2
 	github.com/paketo-buildpacks/node-run-script v0.2.0
 	github.com/paketo-buildpacks/node-run-script v0.2.0
+	github.com/paketo-buildpacks/node-start v0.5.0
 	github.com/paketo-buildpacks/npm-install v0.5.0
 	github.com/paketo-buildpacks/npm-install v0.5.0
 	github.com/paketo-buildpacks/packit v1.3.0
 	github.com/paketo-buildpacks/packit v1.3.0
 	github.com/paketo-buildpacks/pipenv-install v0.2.3
 	github.com/paketo-buildpacks/pipenv-install v0.2.3

+ 2 - 2
go.sum

@@ -1056,10 +1056,10 @@ github.com/paketo-buildpacks/conda-env-update v0.2.2 h1:0bT6Se/r/06Gc3sBeg+OJ/9B
 github.com/paketo-buildpacks/conda-env-update v0.2.2/go.mod h1:OKSG9rf9ClDLcoHA3JJgbRECShCpNJKrmkYgIiYAu9k=
 github.com/paketo-buildpacks/conda-env-update v0.2.2/go.mod h1:OKSG9rf9ClDLcoHA3JJgbRECShCpNJKrmkYgIiYAu9k=
 github.com/paketo-buildpacks/go-mod-vendor v0.3.1 h1:4ltB7mmMg2dGRNDLxwPMLoY98rePUhny/6L0QUn8aYU=
 github.com/paketo-buildpacks/go-mod-vendor v0.3.1 h1:4ltB7mmMg2dGRNDLxwPMLoY98rePUhny/6L0QUn8aYU=
 github.com/paketo-buildpacks/go-mod-vendor v0.3.1/go.mod h1:ycd4yAggQShyoQg+bXZyaxazx/Nms98f1SH9NkG/I3k=
 github.com/paketo-buildpacks/go-mod-vendor v0.3.1/go.mod h1:ycd4yAggQShyoQg+bXZyaxazx/Nms98f1SH9NkG/I3k=
-github.com/paketo-buildpacks/node-module-bom v0.1.2 h1:mJSBiuMzOlqlZ22nJR8Akxorv0PECM60k6hWz+RMxIE=
-github.com/paketo-buildpacks/node-module-bom v0.1.2/go.mod h1:gLG2ixUiwOanH2iy/wEdipfhEUXIoEHzgtK1eYYzGl4=
 github.com/paketo-buildpacks/node-run-script v0.2.0 h1:IAmnpavIuBM49RaKDIK/OdRbo12TfdUCzJ88CvYe4Kk=
 github.com/paketo-buildpacks/node-run-script v0.2.0 h1:IAmnpavIuBM49RaKDIK/OdRbo12TfdUCzJ88CvYe4Kk=
 github.com/paketo-buildpacks/node-run-script v0.2.0/go.mod h1:5SexxOVrn+IfafiZthaFNUo/DM0ugOA83kWAffkPbVE=
 github.com/paketo-buildpacks/node-run-script v0.2.0/go.mod h1:5SexxOVrn+IfafiZthaFNUo/DM0ugOA83kWAffkPbVE=
+github.com/paketo-buildpacks/node-start v0.5.0 h1:R9FXIiXYaTig6PlG335GDoCR2v9z9M6d3eLdiI/T5LU=
+github.com/paketo-buildpacks/node-start v0.5.0/go.mod h1:5aYa3S+AWUHDSGJQD6oa8xUfIXN0o7AmWzKMealO5zw=
 github.com/paketo-buildpacks/npm-install v0.5.0 h1:PWIdaa14IcLllbv1LyZa5mVh5r6DbpdB3bDSxz5+r94=
 github.com/paketo-buildpacks/npm-install v0.5.0 h1:PWIdaa14IcLllbv1LyZa5mVh5r6DbpdB3bDSxz5+r94=
 github.com/paketo-buildpacks/npm-install v0.5.0/go.mod h1:lJ+qayMglLeNbeDxnppIMTKKKNDO+sejM5qiPCBMwzw=
 github.com/paketo-buildpacks/npm-install v0.5.0/go.mod h1:lJ+qayMglLeNbeDxnppIMTKKKNDO+sejM5qiPCBMwzw=
 github.com/paketo-buildpacks/occam v0.0.22/go.mod h1:aPNRyPEgYp4a01O4UKAuFWYnRmY4ujeuV3x6yAa1hxs=
 github.com/paketo-buildpacks/occam v0.0.22/go.mod h1:aPNRyPEgYp4a01O4UKAuFWYnRmY4ujeuV3x6yAa1hxs=