MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/buildpacks / RequestedNodejsVersion

Function RequestedNodejsVersion

pkg/nodejs/nodejs.go:311–330  ·  view source on GitHub ↗

RequestedNodejsVersion returns any customer provided Node.js version constraint by inspecting the environment and the package.json.

(ctx *gcp.Context, pjs *PackageJSON)

Source from the content-addressed store, hash-verified

309}
310
311// RequestedNodejsVersion returns any customer provided Node.js version constraint by inspecting the
312// environment and the package.json.
313func RequestedNodejsVersion(ctx *gcp.Context, pjs *PackageJSON) (string, error) {
314 if version := os.Getenv(EnvNodeVersion); version != "" {
315 ctx.Logf("Using runtime version from %s: %s", EnvNodeVersion, version)
316 return version, nil
317 }
318 if version := os.Getenv(env.RuntimeVersion); version != "" {
319 ctx.Logf("Using runtime version from %s: %s", env.RuntimeVersion, version)
320 return version, nil
321 }
322 if pjs == nil || pjs.Engines.Node == "" {
323 os := runtime.OSForStack(ctx)
324 latestNodejsVersionForStack, ok := latestNodejsVersionPerStack[os]
325 if !ok {
326 return "", gcp.UserErrorf("invalid stack for Nodejs runtime: %q", os)
327 }
328 ctx.Logf("Nodejs version not specified, using the latest available Nodejs runtime for the stack %q", os)
329 return latestNodejsVersionForStack, nil
330 }
331 return pjs.Engines.Node, nil
332}
333

Callers 3

DetectFnFunction · 0.92
BuildFnFunction · 0.92

Calls 2

OSForStackFunction · 0.92
LogfMethod · 0.80

Tested by 1