Skip to content

Commit

Permalink
use the LTS node when unspecified
Browse files Browse the repository at this point in the history
This commit updates the nodejs.runtime buildpack to use 20.x.x as the default version specifier if the project does not include one. This pins Node.js to the LTS track by default instead of using the latest available version.

Fixes #416

PiperOrigin-RevId: 636948468
Change-Id: I31c9d7dda344ae899e5af4c79b860ca03296630a
  • Loading branch information
matthewrobertson authored and copybara-github committed May 24, 2024
1 parent c988649 commit aad45a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions pkg/nodejs/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const (

nodeVersionKey = "node_version"
dependencyHashKey = "dependency_hash"
// defaultVersionConstraint is used if the project does not provide a Node.js version specifier in
// their package.json or via an env var. This pins them to the active LTS version, instead of the
// the latest available version.
defaultVersionConstraint = "20.*.*"
)

// semVer11 is the smallest possible semantic version with major version 11.
Expand Down Expand Up @@ -233,8 +237,8 @@ func RequestedNodejsVersion(ctx *gcp.Context, pjs *PackageJSON) (string, error)
ctx.Logf("Using runtime version from %s: %s", env.RuntimeVersion, version)
return version, nil
}
if pjs == nil {
return "", nil
if pjs == nil || pjs.Engines.Node == "" {
return defaultVersionConstraint, nil
}
return pjs.Engines.Node, nil
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/nodejs/nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ func TestRequestedNodejsVersion(t *testing.T) {
}{
{
name: "default is empty",
want: "",
want: defaultVersionConstraint,
},
{
name: "package.json without engines",
packageJSON: `{}`,
want: defaultVersionConstraint,
},
{
name: "GOOGLE_NODEJS_VERSION is set",
Expand Down

0 comments on commit aad45a6

Please sign in to comment.