diff --git a/docs/deploy/getting-started.md b/docs/deploy/getting-started.md index 5e3cf180d..1c701adc0 100644 --- a/docs/deploy/getting-started.md +++ b/docs/deploy/getting-started.md @@ -97,7 +97,7 @@ Setting `functionsNodeVersion` and `functionsRuntimeOptions` in your `angular.js "deploy": { "builder": "@angular/fire:deploy", "options": { - "functionsNodeVersion": 12, + "functionsNodeVersion": 22, "functionsRuntimeOptions": { "memory": "2GB", "timeoutSeconds": 10, diff --git a/site/src/get-started/deploying.md b/site/src/get-started/deploying.md index b0e9011b4..f5c4886a7 100644 --- a/site/src/get-started/deploying.md +++ b/site/src/get-started/deploying.md @@ -98,13 +98,13 @@ To customize the deployment flow, you can use the configuration files you're alr ### Configuring Cloud Functions -Setting `functionsNodeVersion` and `functionsRuntimeOptions` in your `angular.json` allow you to custimze the version of Node.js Cloud Functions is running and run-time settings like timeout, VPC connectors, and memory. +Setting `functionsNodeVersion` and `functionsRuntimeOptions` in your `angular.json` allow you to customize the version of Node.js Cloud Functions is running and run-time settings like timeout, VPC connectors, and memory. ```json "deploy": { "builder": "@angular/fire:deploy", "options": { - "functionsNodeVersion": 12, + "functionsNodeVersion": 22, "functionsRuntimeOptions": { "memory": "2GB", "timeoutSeconds": 10, diff --git a/src/schematics/deploy/functions-templates.jasmine.ts b/src/schematics/deploy/functions-templates.jasmine.ts new file mode 100644 index 000000000..b6bf4c148 --- /dev/null +++ b/src/schematics/deploy/functions-templates.jasmine.ts @@ -0,0 +1,20 @@ +import { DEFAULT_NODE_VERSION, defaultFunction, defaultPackage } from './functions-templates.js'; +import 'jasmine'; + +describe('functions templates', () => { + describe('defaultFunction', () => { + it('requires the firebase-functions/v1 subpath, where the v1 API lives on firebase-functions 6', () => { + const generated = defaultFunction('dist/app', {}, undefined); + expect(generated).toContain(`require('firebase-functions/v1')`); + expect(generated).not.toContain(`require('firebase-functions')`); + }); + }); + + describe('defaultPackage', () => { + it('defaults engines.node to a runtime Cloud Functions still accepts', () => { + const generated = defaultPackage({}, {}, {}); + expect(generated.engines.node).toBe(DEFAULT_NODE_VERSION.toString()); + expect(DEFAULT_NODE_VERSION).toBe(22); + }); + }); +}); diff --git a/src/schematics/deploy/functions-templates.ts b/src/schematics/deploy/functions-templates.ts index 13cd9ab14..b7af2a3b1 100644 --- a/src/schematics/deploy/functions-templates.ts +++ b/src/schematics/deploy/functions-templates.ts @@ -1,6 +1,9 @@ import { DeployBuilderOptions } from './actions'; -export const DEFAULT_NODE_VERSION = 14; +// Must be a runtime Cloud Functions still accepts, and must satisfy the engines of @angular/core +// (the function runs the Angular server) and of firebase-admin. The `dockerfile` template below +// also drops it into `FROM node:-slim`, so it picks the base image on the Cloud Run path. +export const DEFAULT_NODE_VERSION = 22; export const DEFAULT_FUNCTION_NAME = 'ssr'; const DEFAULT_FUNCTION_REGION = 'us-central1'; @@ -30,11 +33,13 @@ export const defaultPackage = ( private: true }); +// `.region()` lives on the /v1 subpath since firebase-functions 6. Requiring the package root +// instead still resolves, and fails only when the deployed function serves its first request. export const defaultFunction = ( path: string, options: DeployBuilderOptions, functionName: string|undefined, -) => `const functions = require('firebase-functions'); +) => `const functions = require('firebase-functions/v1'); // Increase readability in Cloud Logging require("firebase-functions/logger/compat");