RequestedNodejsVersion returns any customer provided Node.js version constraint by inspecting the environment and the package.json.
(ctx *gcp.Context, pjs *PackageJSON)
| 309 | } |
| 310 | |
| 311 | // RequestedNodejsVersion returns any customer provided Node.js version constraint by inspecting the |
| 312 | // environment and the package.json. |
| 313 | func 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 |