Skip to content

Commit 8370680

Browse files
authored
Prevent GCF from automatically running the build script. (#5687)
GCF will now run `npm run build` script as part of function deploys: https://cloud.google.com/functions/docs/release-notes#April_11_2023 This is a breaking change. We want to shield Cloud Functions for Firebase user from the breaking change and manually disable the behavior in CF3 deploys. We will enable the GCF feature in the next major CLI release.
1 parent 8207170 commit 8370680

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Default emulators:start to use fast dev-mode for Nuxt3 applications (#5551)
2+
- Disable GCF breaking change to automatically run npm build scripts as part of function deploy (#5687)

src/gcp/cloudfunctions.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ export async function createFunction(
205205
// the API is a POST to the collection that owns the function name.
206206
const apiPath = cloudFunction.name.substring(0, cloudFunction.name.lastIndexOf("/"));
207207
const endpoint = `/${apiPath}`;
208+
cloudFunction.buildEnvironmentVariables = {
209+
...cloudFunction.buildEnvironmentVariables,
210+
// Disable GCF from automatically running npm run build script
211+
// https://cloud.google.com/functions/docs/release-notes
212+
GOOGLE_NODE_RUN_SCRIPTS: "",
213+
};
208214

209215
try {
210216
const res = await client.post<Omit<CloudFunction, OutputOnlyFields>, CloudFunction>(
@@ -352,15 +358,23 @@ export async function updateFunction(
352358
cloudFunction: Omit<CloudFunction, OutputOnlyFields>
353359
): Promise<Operation> {
354360
const endpoint = `/${cloudFunction.name}`;
355-
// Keys in labels and environmentVariables and secretEnvironmentVariables are user defined, so we don't recurse
356-
// for field masks.
361+
// Keys in labels and environmentVariables and secretEnvironmentVariables are user defined,
362+
// so we don't recurse for field masks.
357363
const fieldMasks = proto.fieldMasks(
358364
cloudFunction,
359365
/* doNotRecurseIn...=*/ "labels",
360366
"environmentVariables",
361367
"secretEnvironmentVariables"
362368
);
363369

370+
cloudFunction.buildEnvironmentVariables = {
371+
...cloudFunction.buildEnvironmentVariables,
372+
// Disable GCF from automatically running npm run build script
373+
// https://cloud.google.com/functions/docs/release-notes
374+
GOOGLE_NODE_RUN_SCRIPTS: "",
375+
};
376+
fieldMasks.push("buildEnvironmentVariables");
377+
364378
// Failure policy is always an explicit policy and is only signified by the presence or absence of
365379
// a protobuf.Empty value, so we have to manually add it in the missing case.
366380
try {

src/gcp/cloudfunctionsv2.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ export async function createFunction(
299299
const components = cloudFunction.name.split("/");
300300
const functionId = components.splice(-1, 1)[0];
301301

302+
cloudFunction.buildConfig.environmentVariables = {
303+
...cloudFunction.buildConfig.environmentVariables,
304+
// Disable GCF from automatically running npm run build script
305+
// https://cloud.google.com/functions/docs/release-notes
306+
GOOGLE_NODE_RUN_SCRIPTS: "",
307+
};
308+
302309
try {
303310
const res = await client.post<typeof cloudFunction, Operation>(
304311
components.join("/"),
@@ -390,6 +397,14 @@ export async function updateFunction(
390397
"serviceConfig.environmentVariables",
391398
"serviceConfig.secretEnvironmentVariables"
392399
);
400+
401+
cloudFunction.buildConfig.environmentVariables = {
402+
...cloudFunction.buildConfig.environmentVariables,
403+
// Disable GCF from automatically running npm run build script
404+
// https://cloud.google.com/functions/docs/release-notes
405+
GOOGLE_NODE_RUN_SCRIPTS: "",
406+
};
407+
fieldMasks.push("buildConfig.buildEnvironmentVariables");
393408
try {
394409
const queryParams = {
395410
updateMask: fieldMasks.join(","),

0 commit comments

Comments
 (0)