Skip to content

Commit 0a949db

Browse files
committed
Pin runtimes on init for functions.
1 parent a0b7ea5 commit 0a949db

File tree

9 files changed

+31
-11
lines changed

9 files changed

+31
-11
lines changed

src/deploy/functions/runtimes/supported/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,5 @@ export type DecommissionedRuntime = {
116116
? R
117117
: never;
118118
}[keyof typeof RUNTIMES];
119+
120+
export type ActiveRuntime = Exclude<Runtime, DecommissionedRuntime>;

src/firebaseConfig.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import type { HttpsOptions } from "firebase-functions/v2/https";
99
import { IngressSetting, MemoryOption, VpcEgressSetting } from "firebase-functions/v2/options";
10-
import { Runtime, DecommissionedRuntime } from "./deploy/functions/runtimes/supported/types";
10+
import { ActiveRuntime } from "./deploy/functions/runtimes/supported/types";
1111

1212
/**
1313
* Creates a type that requires at least one key to be present in an interface
@@ -167,7 +167,7 @@ export type FirestoreConfig = FirestoreSingle | FirestoreMultiple;
167167
export type FunctionConfig = {
168168
source?: string;
169169
ignore?: string[];
170-
runtime?: Exclude<Runtime, DecommissionedRuntime>;
170+
runtime?: ActiveRuntime;
171171
codebase?: string;
172172
} & Deployable;
173173

src/init/features/functions/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "../../../functions/projectConfig";
1515
import { FirebaseError } from "../../../error";
1616
import { functionsOrigin, runtimeconfigOrigin } from "../../../api";
17+
import * as supported from "../../../deploy/functions/runtimes/supported";
1718

1819
const MAX_ATTEMPTS = 5;
1920

@@ -198,6 +199,9 @@ async function languageSetup(setup: any, config: Config): Promise<any> {
198199
break;
199200
case "python":
200201
cbconfig.ignore = ["venv", ".git", "firebase-debug.log", "firebase-debug.*.log", "*.local"];
202+
// In practical sense, latest supported runtime will not be a decomissioned runtime,
203+
// but in theory this doesn't have to be the case.
204+
cbconfig.runtime = supported.latest("python") as supported.ActiveRuntime;
201205
break;
202206
}
203207
setup.functions.languageChoice = language;

src/init/features/functions/javascript.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { askInstallDependencies } from "./npm-dependencies";
22
import { confirm } from "../../../prompt";
33
import { configForCodebase } from "../../../functions/projectConfig";
44
import { readTemplateSync } from "../../../templates";
5+
import * as supported from "../../../deploy/functions/runtimes/supported";
56

67
const INDEX_TEMPLATE = readTemplateSync("init/functions/javascript/index.js");
78
const PACKAGE_LINTING_TEMPLATE = readTemplateSync("init/functions/javascript/package.lint.json");
@@ -20,13 +21,19 @@ export async function setup(setup: any, config: any): Promise<any> {
2021
cbconfig.predeploy = ['npm --prefix "$RESOURCE_DIR" run lint'];
2122
await config.askWriteProjectFile(
2223
`${setup.functions.source}/package.json`,
23-
PACKAGE_LINTING_TEMPLATE,
24+
PACKAGE_LINTING_TEMPLATE.replace(
25+
"{{RUNTIME}}",
26+
supported.latest("nodejs").replace("nodejs", ""),
27+
),
2428
);
2529
await config.askWriteProjectFile(`${setup.functions.source}/.eslintrc.js`, ESLINT_TEMPLATE);
2630
} else {
2731
await config.askWriteProjectFile(
2832
`${setup.functions.source}/package.json`,
29-
PACKAGE_NO_LINTING_TEMPLATE,
33+
PACKAGE_NO_LINTING_TEMPLATE.replace(
34+
"{{RUNTIME}}",
35+
supported.latest("nodejs").replace("nodejs", ""),
36+
),
3037
);
3138
}
3239

src/init/features/functions/typescript.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { askInstallDependencies } from "./npm-dependencies";
22
import { confirm } from "../../../prompt";
33
import { configForCodebase } from "../../../functions/projectConfig";
44
import { readTemplateSync } from "../../../templates";
5+
import * as supported from "../../../deploy/functions/runtimes/supported";
56

67
const PACKAGE_LINTING_TEMPLATE = readTemplateSync("init/functions/typescript/package.lint.json");
78
const PACKAGE_NO_LINTING_TEMPLATE = readTemplateSync(
@@ -28,7 +29,10 @@ export async function setup(setup: any, config: any): Promise<any> {
2829
cbconfig.predeploy.push('npm --prefix "$RESOURCE_DIR" run build');
2930
await config.askWriteProjectFile(
3031
`${setup.functions.source}/package.json`,
31-
PACKAGE_LINTING_TEMPLATE,
32+
PACKAGE_LINTING_TEMPLATE.replace(
33+
"{{RUNTIME}}",
34+
supported.latest("nodejs").replace("nodejs", ""),
35+
),
3236
);
3337
await config.askWriteProjectFile(`${setup.functions.source}/.eslintrc.js`, ESLINT_TEMPLATE);
3438
// TODO: isn't this file out of date now?
@@ -40,7 +44,10 @@ export async function setup(setup: any, config: any): Promise<any> {
4044
cbconfig.predeploy.push('npm --prefix "$RESOURCE_DIR" run build');
4145
await config.askWriteProjectFile(
4246
`${setup.functions.source}/package.json`,
43-
PACKAGE_NO_LINTING_TEMPLATE,
47+
PACKAGE_NO_LINTING_TEMPLATE.replace(
48+
"{{RUNTIME}}",
49+
supported.latest("nodejs").replace("nodejs", ""),
50+
),
4451
);
4552
}
4653

templates/init/functions/javascript/package.lint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"logs": "firebase functions:log"
1111
},
1212
"engines": {
13-
"node": "22"
13+
"node": "{{RUNTIME}}"
1414
},
1515
"main": "index.js",
1616
"dependencies": {

templates/init/functions/javascript/package.nolint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"logs": "firebase functions:log"
1010
},
1111
"engines": {
12-
"node": "22"
12+
"node": "{{RUNTIME}}"
1313
},
1414
"main": "index.js",
1515
"dependencies": {

templates/init/functions/typescript/package.lint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"logs": "firebase functions:log"
1212
},
1313
"engines": {
14-
"node": "22"
14+
"node": "{{RUNTIME}}"
1515
},
1616
"main": "lib/index.js",
1717
"dependencies": {

templates/init/functions/typescript/package.nolint.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"logs": "firebase functions:log"
1111
},
1212
"engines": {
13-
"node": "22"
13+
"node": "{{RUNTIME}}"
1414
},
1515
"main": "lib/index.js",
1616
"dependencies": {
@@ -22,4 +22,4 @@
2222
"firebase-functions-test": "^3.1.0"
2323
},
2424
"private": true
25-
}
25+
}

0 commit comments

Comments
 (0)