firebase-tools 15.34.0 → 15.34.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/auth.js +10 -5
- package/lib/commands/apps-android-sha-create.js +1 -1
- package/lib/commands/apps-android-sha-delete.js +1 -1
- package/lib/commands/apps-android-sha-list.js +1 -1
- package/lib/commands/deploy.js +4 -0
- package/lib/commands/hosting-channel-create.js +3 -0
- package/lib/commands/hosting-channel-delete.js +3 -0
- package/lib/commands/hosting-channel-deploy.js +3 -0
- package/lib/commands/hosting-channel-list.js +3 -0
- package/lib/commands/hosting-channel-open.js +3 -0
- package/lib/commands/hosting-clone.js +14 -0
- package/lib/commands/hosting-disable.js +2 -0
- package/lib/commands/hosting-sites-create.js +3 -0
- package/lib/commands/hosting-sites-delete.js +3 -0
- package/lib/commands/hosting-sites-get.js +3 -0
- package/lib/commands/hosting-sites-list.js +3 -0
- package/lib/commands/index.js +2 -4
- package/lib/commands/run-services-update.js +2 -0
- package/lib/crashlytics/alerts.js +1 -11
- package/lib/crashlytics/onboarding.js +15 -19
- package/lib/deploy/functions/params.js +1 -0
- package/lib/deploy/functions/release/fabricator.js +6 -3
- package/lib/deploy/hosting/prepare.js +3 -0
- package/lib/deploy/run/deploy.js +36 -8
- package/lib/deploy/run/prepare.js +54 -2
- package/lib/deploy/run/update.js +2 -1
- package/lib/deploy/run/util.js +2 -0
- package/lib/emulator/auth/cloudFunctions.js +47 -18
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/firestoreEmulator.js +5 -0
- package/lib/emulator/functionsEmulator.js +22 -7
- package/lib/emulator/pubsubEmulator.js +64 -11
- package/lib/emulator/storage/rules/manager.js +31 -15
- package/lib/emulator/taskQueue.js +5 -4
- package/lib/experiments.js +0 -10
- package/lib/extensions/emulator/specHelper.js +0 -4
- package/lib/extensions/extensionsHelper.js +0 -49
- package/lib/extensions/runtimes/common.js +0 -12
- package/lib/extensions/updateHelper.js +2 -88
- package/lib/frameworks/angular/utils.js +3 -2
- package/lib/gcp/cloudlogging.js +0 -54
- package/lib/init/features/aitools/promptUpdater.js +3 -2
- package/lib/init/features/run.js +40 -1
- package/lib/mcp/errors.js +1 -1
- package/lib/mcp/index.js +19 -3
- package/lib/mcp/util/dataconnect/converter.js +0 -29
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +15 -5
- package/lib/apphosting/repo.js +0 -243
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.prepare = prepare;
|
|
4
|
+
const app_1 = require("../../apphosting/app");
|
|
5
|
+
const utils_1 = require("../../apphosting/utils");
|
|
4
6
|
const error_1 = require("../../error");
|
|
5
|
-
const
|
|
7
|
+
const computeEngine_1 = require("../../gcp/computeEngine");
|
|
8
|
+
const resourceManager = require("../../gcp/resourceManager");
|
|
9
|
+
const getProjectNumber_1 = require("../../getProjectNumber");
|
|
10
|
+
const managementApps = require("../../management/apps");
|
|
11
|
+
const utils_2 = require("../../utils");
|
|
6
12
|
const buildEnv_1 = require("./buildEnv");
|
|
7
13
|
const prereqs_1 = require("./prereqs");
|
|
8
14
|
const util_1 = require("./util");
|
|
15
|
+
const ADMIN_SDK_ROLE = "roles/firebase.sdkAdminServiceAgent";
|
|
9
16
|
async function prepare(context, options, payload) {
|
|
10
17
|
const configs = (0, util_1.getServiceConfigs)(options);
|
|
11
18
|
if (!configs.length) {
|
|
@@ -24,6 +31,10 @@ async function prepareService(context, config) {
|
|
|
24
31
|
if (context.baseImage !== undefined) {
|
|
25
32
|
baseImage = context.baseImage ?? undefined;
|
|
26
33
|
}
|
|
34
|
+
let appId = existing?.annotations?.[util_1.FIREBASE_APP_ANNOTATION];
|
|
35
|
+
if (context.appId !== undefined) {
|
|
36
|
+
appId = context.appId ?? undefined;
|
|
37
|
+
}
|
|
27
38
|
if (config.localBuild && !baseImage) {
|
|
28
39
|
const fix = existing
|
|
29
40
|
? `firebase run:services:update ${serviceId} --region ${region} --base-image <baseImage>`
|
|
@@ -39,9 +50,50 @@ async function prepareService(context, config) {
|
|
|
39
50
|
}
|
|
40
51
|
const svc = { config, existing, baseImage };
|
|
41
52
|
if (Object.keys(buildEnv).length) {
|
|
42
|
-
(0,
|
|
53
|
+
(0, utils_2.logLabeledBullet)("run", `Using build environment variables for service ${serviceId} in ${region} from ` +
|
|
43
54
|
`${buildEnv_1.BUILD_ENV_ANNOTATION}: ${Object.keys(buildEnv).join(", ")}`);
|
|
44
55
|
svc.buildEnv = buildEnv;
|
|
45
56
|
}
|
|
57
|
+
if (appId) {
|
|
58
|
+
const autoInitEnv = (0, utils_1.getAutoinitEnvVars)(await getWebAppConfig(context, config, appId));
|
|
59
|
+
if (appId !== existing?.annotations?.[util_1.FIREBASE_APP_ANNOTATION]) {
|
|
60
|
+
await checkAdminSdkRole(context, config, existing);
|
|
61
|
+
}
|
|
62
|
+
svc.autoInit = { appId, firebaseConfig: autoInitEnv.FIREBASE_CONFIG };
|
|
63
|
+
svc.buildEnv = { ...buildEnv, ...autoInitEnv };
|
|
64
|
+
}
|
|
46
65
|
return svc;
|
|
47
66
|
}
|
|
67
|
+
async function getWebAppConfig(context, config, appId) {
|
|
68
|
+
try {
|
|
69
|
+
await app_1.webApps.getOrCreateWebApp(context.projectId, appId, config.serviceId);
|
|
70
|
+
return (await managementApps.getAppConfig(appId, managementApps.AppPlatform.WEB));
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
const update = `firebase run:services:update ${config.serviceId} --region ${config.region}`;
|
|
74
|
+
throw new error_1.FirebaseError(`Unable to look up Firebase Web App ${appId} for service ${config.serviceId} in ` +
|
|
75
|
+
`${config.region}: ${(0, error_1.getErrMsg)(err)}\n` +
|
|
76
|
+
`To use a different app, run "${update} --app <appId>". ` +
|
|
77
|
+
`To deploy without Firebase SDK auto-initialization, run "${update} --clear-app".`, { original: (0, error_1.getError)(err) });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function checkAdminSdkRole(context, config, existing) {
|
|
81
|
+
const serviceAccount = existing?.template?.serviceAccount ||
|
|
82
|
+
(await (0, computeEngine_1.getDefaultServiceAccount)(await (0, getProjectNumber_1.getProjectNumber)(context)));
|
|
83
|
+
let problem = "";
|
|
84
|
+
try {
|
|
85
|
+
const hasRole = await resourceManager.serviceAccountHasRoles(context.projectId, serviceAccount, [ADMIN_SDK_ROLE], true);
|
|
86
|
+
if (!hasRole) {
|
|
87
|
+
problem = `${serviceAccount} doesn't have ${ADMIN_SDK_ROLE}`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
problem = `Couldn't check whether ${serviceAccount} has ${ADMIN_SDK_ROLE} (${(0, error_1.getErrMsg)(err)})`;
|
|
92
|
+
}
|
|
93
|
+
if (problem) {
|
|
94
|
+
(0, utils_2.logLabeledWarning)("run", `${problem}. Service ${config.serviceId} runs as this account, so if its Firebase Admin SDK ` +
|
|
95
|
+
`calls fail with permission errors, grant the role with:\n` +
|
|
96
|
+
` gcloud projects add-iam-policy-binding ${context.projectId} ` +
|
|
97
|
+
`--member=serviceAccount:${serviceAccount} --role=${ADMIN_SDK_ROLE} --condition=None`);
|
|
98
|
+
}
|
|
99
|
+
}
|
package/lib/deploy/run/update.js
CHANGED
|
@@ -9,9 +9,10 @@ const util_1 = require("./util");
|
|
|
9
9
|
async function updateService(serviceId, region, options) {
|
|
10
10
|
const settings = {
|
|
11
11
|
baseImage: readFlagPair(options.baseImage, options.clearBaseImage, "base-image"),
|
|
12
|
+
appId: readFlagPair(options.app, options.clearApp, "app"),
|
|
12
13
|
};
|
|
13
14
|
if (Object.values(settings).every((value) => value === undefined)) {
|
|
14
|
-
throw new error_1.FirebaseError("Specify a setting to update: --base-image <baseImage
|
|
15
|
+
throw new error_1.FirebaseError("Specify a setting to update: --base-image <baseImage>, --clear-base-image, --app <appId>, or --clear-app.");
|
|
15
16
|
}
|
|
16
17
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
17
18
|
const config = findServiceToUpdate(serviceId, region, options);
|
package/lib/deploy/run/util.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FIREBASE_APP_ANNOTATION = void 0;
|
|
3
4
|
exports.getAllServiceConfigs = getAllServiceConfigs;
|
|
4
5
|
exports.getServiceConfigs = getServiceConfigs;
|
|
5
6
|
exports.findServices = findServices;
|
|
@@ -9,6 +10,7 @@ exports.mainContainer = mainContainer;
|
|
|
9
10
|
const error_1 = require("../../error");
|
|
10
11
|
const runv2 = require("../../gcp/runv2");
|
|
11
12
|
const utils_1 = require("../../utils");
|
|
13
|
+
exports.FIREBASE_APP_ANNOTATION = "firebase.google.com/app-id";
|
|
12
14
|
function getAllServiceConfigs(options) {
|
|
13
15
|
const configs = [options.config?.src?.run ?? []].flat();
|
|
14
16
|
const names = new Set();
|
|
@@ -19,9 +19,8 @@ class AuthCloudFunction {
|
|
|
19
19
|
async dispatch(action, user) {
|
|
20
20
|
if (!this.enabled)
|
|
21
21
|
return;
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const v2CloudEventBody = this.createCloudEventRequestBody(action, userInfoPayload);
|
|
22
|
+
const legacyEventBody = this.createEventRequestBody(action, user);
|
|
23
|
+
const v2CloudEventBody = this.createCloudEventRequestBody(action, user);
|
|
25
24
|
const c = registry_1.EmulatorRegistry.client(types_1.Emulators.FUNCTIONS);
|
|
26
25
|
const errStatus = [];
|
|
27
26
|
let err;
|
|
@@ -49,7 +48,7 @@ class AuthCloudFunction {
|
|
|
49
48
|
this.logger.logLabeled("WARN", "functions", `Firebase Authentication function was not triggered due to emulation error. Please file a bug.`);
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
|
-
createEventRequestBody(action,
|
|
51
|
+
createEventRequestBody(action, user) {
|
|
53
52
|
return {
|
|
54
53
|
eventId: (0, crypto_1.randomUUID)(),
|
|
55
54
|
eventType: `providers/firebase.auth/eventTypes/user.${action}`,
|
|
@@ -59,26 +58,36 @@ class AuthCloudFunction {
|
|
|
59
58
|
},
|
|
60
59
|
params: {},
|
|
61
60
|
timestamp: new Date().toISOString(),
|
|
62
|
-
data:
|
|
61
|
+
data: this.createUserInfoPayload(user),
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
|
-
createCloudEventRequestBody(action,
|
|
64
|
+
createCloudEventRequestBody(action, user) {
|
|
66
65
|
const ceAction = AUTH_V2_ACTION_MAP[action];
|
|
66
|
+
const v2UserPayload = this.createV2UserInfoPayload(user);
|
|
67
67
|
const cloudEvent = {
|
|
68
68
|
specversion: "1.0",
|
|
69
69
|
id: (0, crypto_1.randomUUID)(),
|
|
70
70
|
time: new Date().toISOString(),
|
|
71
71
|
type: `google.firebase.auth.user.v2.${ceAction}`,
|
|
72
72
|
source: `//identitytoolkit.googleapis.com/projects/${this.projectId}`,
|
|
73
|
-
subject: `users/${
|
|
74
|
-
data: action === "create" ? { value:
|
|
73
|
+
subject: `users/${v2UserPayload.uid}`,
|
|
74
|
+
data: action === "create" ? { value: v2UserPayload } : { oldValue: v2UserPayload },
|
|
75
75
|
};
|
|
76
|
-
if (
|
|
77
|
-
cloudEvent.tenantid =
|
|
76
|
+
if (user.tenantId) {
|
|
77
|
+
cloudEvent.tenantid = user.tenantId;
|
|
78
78
|
}
|
|
79
79
|
return cloudEvent;
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
toIsoTimestamp(epochMs) {
|
|
82
|
+
if (!epochMs)
|
|
83
|
+
return undefined;
|
|
84
|
+
const ms = parseInt(epochMs, 10);
|
|
85
|
+
if (isNaN(ms))
|
|
86
|
+
return undefined;
|
|
87
|
+
const date = new Date(ms);
|
|
88
|
+
return isNaN(date.getTime()) ? undefined : date.toISOString();
|
|
89
|
+
}
|
|
90
|
+
createBaseUserInfoPayload(user) {
|
|
82
91
|
return {
|
|
83
92
|
uid: user.localId,
|
|
84
93
|
email: user.email,
|
|
@@ -87,15 +96,35 @@ class AuthCloudFunction {
|
|
|
87
96
|
photoURL: user.photoUrl,
|
|
88
97
|
phoneNumber: user.phoneNumber,
|
|
89
98
|
disabled: user.disabled,
|
|
99
|
+
customClaims: JSON.parse(user.customAttributes || "{}"),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
createV2UserInfoPayload(user) {
|
|
103
|
+
return {
|
|
104
|
+
...this.createBaseUserInfoPayload(user),
|
|
90
105
|
metadata: {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
createTime: this.toIsoTimestamp(user.createdAt),
|
|
107
|
+
lastSignInTime: this.toIsoTimestamp(user.lastLoginAt),
|
|
108
|
+
},
|
|
109
|
+
providerData: user.providerUserInfo?.map((info) => this.createV2ProviderUserInfoPayload(info)),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
createV2ProviderUserInfoPayload(info) {
|
|
113
|
+
return {
|
|
114
|
+
uid: info.rawId,
|
|
115
|
+
providerId: info.providerId,
|
|
116
|
+
displayName: info.displayName,
|
|
117
|
+
email: info.email,
|
|
118
|
+
photoURL: info.photoUrl,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
createUserInfoPayload(user) {
|
|
122
|
+
return {
|
|
123
|
+
...this.createBaseUserInfoPayload(user),
|
|
124
|
+
metadata: {
|
|
125
|
+
creationTime: this.toIsoTimestamp(user.createdAt),
|
|
126
|
+
lastSignInTime: this.toIsoTimestamp(user.lastLoginAt),
|
|
97
127
|
},
|
|
98
|
-
customClaims: JSON.parse(user.customAttributes || "{}"),
|
|
99
128
|
providerData: user.providerUserInfo?.map((info) => this.createProviderUserInfoPayload(info)),
|
|
100
129
|
tenantId: user.tenantId,
|
|
101
130
|
mfaInfo: user.mfaInfo,
|
|
@@ -54,36 +54,36 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dataconnect": {
|
|
56
56
|
"darwin": {
|
|
57
|
-
"version": "3.4.
|
|
58
|
-
"expectedSize":
|
|
59
|
-
"expectedChecksum": "
|
|
60
|
-
"expectedChecksumSHA256": "
|
|
61
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.
|
|
62
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
57
|
+
"version": "3.4.25",
|
|
58
|
+
"expectedSize": 35760048,
|
|
59
|
+
"expectedChecksum": "357570277013f47df1908542d8de4adf",
|
|
60
|
+
"expectedChecksumSHA256": "28520242e277523b66da7ccc9e255e265547471896ee842d820c32ae4d861aa9",
|
|
61
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.25",
|
|
62
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.25"
|
|
63
63
|
},
|
|
64
64
|
"darwin_arm64": {
|
|
65
|
-
"version": "3.4.
|
|
66
|
-
"expectedSize":
|
|
67
|
-
"expectedChecksum": "
|
|
68
|
-
"expectedChecksumSHA256": "
|
|
69
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.
|
|
70
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
65
|
+
"version": "3.4.25",
|
|
66
|
+
"expectedSize": 33727618,
|
|
67
|
+
"expectedChecksum": "f5326947b1de0dfb3d817292188be7ab",
|
|
68
|
+
"expectedChecksumSHA256": "11bf1a66434e32e63e39c2c0e758fc5aa1fcc8bf844062404f73a06e8509c9a9",
|
|
69
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.25",
|
|
70
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.25"
|
|
71
71
|
},
|
|
72
72
|
"win32": {
|
|
73
|
-
"version": "3.4.
|
|
74
|
-
"expectedSize":
|
|
75
|
-
"expectedChecksum": "
|
|
76
|
-
"expectedChecksumSHA256": "
|
|
77
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.
|
|
78
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
73
|
+
"version": "3.4.25",
|
|
74
|
+
"expectedSize": 35740672,
|
|
75
|
+
"expectedChecksum": "da426d34d42478414d11dfa338c5574a",
|
|
76
|
+
"expectedChecksumSHA256": "ac73a8a4f6051382287bb91e5bdab25d500600c17be215ee6372f77586e7f8d6",
|
|
77
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.25",
|
|
78
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.25.exe"
|
|
79
79
|
},
|
|
80
80
|
"linux": {
|
|
81
|
-
"version": "3.4.
|
|
82
|
-
"expectedSize":
|
|
83
|
-
"expectedChecksum": "
|
|
84
|
-
"expectedChecksumSHA256": "
|
|
85
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.
|
|
86
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
81
|
+
"version": "3.4.25",
|
|
82
|
+
"expectedSize": 34762914,
|
|
83
|
+
"expectedChecksum": "1db9678c3c0f1461a9d6a4b0139da409",
|
|
84
|
+
"expectedChecksumSHA256": "6925e7484fc7357f99169411e72dfee490c8ec63de5a49c05fc8c53ad756d9e9",
|
|
85
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.25",
|
|
86
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.25"
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -21,6 +21,11 @@ class FirestoreEmulator {
|
|
|
21
21
|
if (this.args.rules && this.args.project_id) {
|
|
22
22
|
const rulesPath = this.args.rules;
|
|
23
23
|
this.rulesWatcher = chokidar.watch(rulesPath, { persistent: true, ignoreInitial: true });
|
|
24
|
+
this.rulesWatcher.on("error", (err) => {
|
|
25
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
26
|
+
utils.logLabeledWarning("firestore", `Could not watch ${rulesPath} for changes, so rules hot reloading is disabled: ${message}. ` +
|
|
27
|
+
"If your environment does not support file watching, set CHOKIDAR_USEPOLLING=1 to fall back to polling.");
|
|
28
|
+
});
|
|
24
29
|
this.rulesWatcher.on("change", async () => {
|
|
25
30
|
await new Promise((res) => setTimeout(res, 5));
|
|
26
31
|
utils.logLabeledBullet("firestore", "Change detected, updating rules...");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FunctionsEmulator = exports.TCPConn = exports.IPCConn = void 0;
|
|
4
|
+
exports.createIgnoredFilter = createIgnoredFilter;
|
|
4
5
|
const fs = require("fs");
|
|
5
6
|
const path = require("path");
|
|
6
7
|
const express = require("express");
|
|
@@ -15,6 +16,7 @@ const track_1 = require("../track");
|
|
|
15
16
|
const constants_1 = require("./constants");
|
|
16
17
|
const types_1 = require("./types");
|
|
17
18
|
const chokidar = require("chokidar");
|
|
19
|
+
const minimatch = require("minimatch");
|
|
18
20
|
const portfinder = require("portfinder");
|
|
19
21
|
const spawn = require("cross-spawn");
|
|
20
22
|
const functionsEmulatorShared_1 = require("./functionsEmulatorShared");
|
|
@@ -64,6 +66,25 @@ class TCPConn {
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
exports.TCPConn = TCPConn;
|
|
69
|
+
function createIgnoredFilter(ignore) {
|
|
70
|
+
const ignored = [
|
|
71
|
+
/(^|[\/\\])\../,
|
|
72
|
+
/.+\.log/,
|
|
73
|
+
/.+?[\\\/]node_modules[\\\/].+?/,
|
|
74
|
+
/.+?[\\\/]venv[\\\/].+?/,
|
|
75
|
+
];
|
|
76
|
+
if (ignore) {
|
|
77
|
+
const minimatchInstances = ignore.map((pattern) => {
|
|
78
|
+
const p = pattern.startsWith("**/") ? pattern : `**/${pattern}`;
|
|
79
|
+
return new minimatch.Minimatch(p, { dot: true });
|
|
80
|
+
});
|
|
81
|
+
ignored.push((filePath) => {
|
|
82
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
83
|
+
return minimatchInstances.some((m) => m.match(normalized));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return ignored;
|
|
87
|
+
}
|
|
67
88
|
class FunctionsEmulator {
|
|
68
89
|
static getHttpFunctionUrl(projectId, name, region, info) {
|
|
69
90
|
let url;
|
|
@@ -298,13 +319,7 @@ class FunctionsEmulator {
|
|
|
298
319
|
}
|
|
299
320
|
else {
|
|
300
321
|
const watcher = chokidar.watch(backend.functionsDir, {
|
|
301
|
-
ignored:
|
|
302
|
-
/(^|[\/\\])\../,
|
|
303
|
-
/.+\.log/,
|
|
304
|
-
/.+?[\\\/]node_modules[\\\/].+?/,
|
|
305
|
-
/.+?[\\\/]venv[\\\/].+?/,
|
|
306
|
-
...(backend.ignore?.map((i) => `**/${i}`) ?? []),
|
|
307
|
-
],
|
|
322
|
+
ignored: createIgnoredFilter(backend.ignore),
|
|
308
323
|
persistent: true,
|
|
309
324
|
});
|
|
310
325
|
this.watchers.push(watcher);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PubsubEmulator = void 0;
|
|
3
|
+
exports.PubsubEmulator = exports.SUBSCRIPTION_CLOSE_TIMEOUT_MS = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const pubsub_1 = require("@google-cloud/pubsub");
|
|
6
6
|
const downloadableEmulators = require("./downloadableEmulators");
|
|
@@ -12,6 +12,24 @@ const registry_1 = require("./registry");
|
|
|
12
12
|
const child_process_1 = require("child_process");
|
|
13
13
|
const PUBSUB_KILL_COMMAND = "pubsub_pids=$(ps aux | grep '[p]ubsub-emulator' | awk '{print $2}');" +
|
|
14
14
|
" if [ ! -z '$pubsub_pids' ]; then kill -9 $pubsub_pids; fi;";
|
|
15
|
+
exports.SUBSCRIPTION_CLOSE_TIMEOUT_MS = 2000;
|
|
16
|
+
async function withTimeout(promise, timeoutMs, timeoutMessage) {
|
|
17
|
+
let timer;
|
|
18
|
+
try {
|
|
19
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
20
|
+
timer = setTimeout(() => {
|
|
21
|
+
reject(new Error(timeoutMessage));
|
|
22
|
+
}, timeoutMs);
|
|
23
|
+
timer.unref?.();
|
|
24
|
+
});
|
|
25
|
+
return await Promise.race([promise, timeoutPromise]);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
if (timer !== undefined) {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
15
33
|
class PubsubEmulator {
|
|
16
34
|
get pubsub() {
|
|
17
35
|
if (!this._pubsub) {
|
|
@@ -36,13 +54,47 @@ class PubsubEmulator {
|
|
|
36
54
|
}
|
|
37
55
|
async stop() {
|
|
38
56
|
try {
|
|
39
|
-
|
|
57
|
+
const closePromises = Array.from(this.subscriptionForTopic.values()).map(async (sub) => {
|
|
58
|
+
try {
|
|
59
|
+
await withTimeout(sub.close(), exports.SUBSCRIPTION_CLOSE_TIMEOUT_MS, "Timed out waiting " +
|
|
60
|
+
exports.SUBSCRIPTION_CLOSE_TIMEOUT_MS +
|
|
61
|
+
"ms for subscription " +
|
|
62
|
+
sub.name +
|
|
63
|
+
" to close");
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
this.logger.logLabeled("DEBUG", "pubsub", "Failed to close subscription " +
|
|
67
|
+
sub.name +
|
|
68
|
+
": " +
|
|
69
|
+
(err instanceof Error ? err.message : String(err)));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
await Promise.all(closePromises);
|
|
73
|
+
this.subscriptionForTopic.clear();
|
|
74
|
+
this.triggersForTopic.clear();
|
|
75
|
+
if (this._pubsub) {
|
|
76
|
+
try {
|
|
77
|
+
await withTimeout(this._pubsub.close(), exports.SUBSCRIPTION_CLOSE_TIMEOUT_MS, "Timed out waiting " + exports.SUBSCRIPTION_CLOSE_TIMEOUT_MS + "ms for pubsub client to close");
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
this.logger.logLabeled("DEBUG", "pubsub", "Failed to close pubsub client: " + (err instanceof Error ? err.message : String(err)));
|
|
81
|
+
}
|
|
82
|
+
this._pubsub = undefined;
|
|
83
|
+
}
|
|
40
84
|
}
|
|
41
|
-
catch (
|
|
42
|
-
this.logger.logLabeled("DEBUG", "pubsub",
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
85
|
+
catch (err) {
|
|
86
|
+
this.logger.logLabeled("DEBUG", "pubsub", "Error during pubsub client cleanup: " + (err instanceof Error ? err.message : String(err)));
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
try {
|
|
90
|
+
await downloadableEmulators.stop(types_1.Emulators.PUBSUB);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
this.logger.logLabeled("DEBUG", "pubsub", e instanceof Error ? e.message : String(e));
|
|
94
|
+
if (process.platform !== "win32") {
|
|
95
|
+
const buffer = (0, child_process_1.execSync)(PUBSUB_KILL_COMMAND);
|
|
96
|
+
this.logger.logLabeled("DEBUG", "pubsub", "Pubsub kill output: " + JSON.stringify(buffer));
|
|
97
|
+
}
|
|
46
98
|
}
|
|
47
99
|
}
|
|
48
100
|
}
|
|
@@ -95,16 +147,17 @@ class PubsubEmulator {
|
|
|
95
147
|
}
|
|
96
148
|
async addTrigger(topicName, triggerKey, signatureType) {
|
|
97
149
|
this.logger.logLabeled("DEBUG", "pubsub", `addTrigger(${topicName}, ${triggerKey}, ${signatureType})`);
|
|
98
|
-
const sub = await this.maybeCreateTopicAndSub(topicName);
|
|
99
150
|
const triggers = this.triggersForTopic.get(topicName) || [];
|
|
100
|
-
if (triggers.some((t) => t.triggerKey === triggerKey)
|
|
101
|
-
this.subscriptionForTopic.has(topicName)) {
|
|
151
|
+
if (triggers.some((t) => t.triggerKey === triggerKey)) {
|
|
102
152
|
this.logger.logLabeled("DEBUG", "pubsub", "Trigger already exists");
|
|
103
153
|
return;
|
|
104
154
|
}
|
|
155
|
+
if (!this.subscriptionForTopic.has(topicName)) {
|
|
156
|
+
const sub = await this.maybeCreateTopicAndSub(topicName);
|
|
157
|
+
this.subscriptionForTopic.set(topicName, sub);
|
|
158
|
+
}
|
|
105
159
|
triggers.push({ triggerKey, signatureType });
|
|
106
160
|
this.triggersForTopic.set(topicName, triggers);
|
|
107
|
-
this.subscriptionForTopic.set(topicName, sub);
|
|
108
161
|
}
|
|
109
162
|
ensureFunctionsClient() {
|
|
110
163
|
if (this.client !== undefined)
|
|
@@ -6,6 +6,8 @@ const emulatorLogger_1 = require("../../emulatorLogger");
|
|
|
6
6
|
const types_1 = require("../../types");
|
|
7
7
|
const runtime_1 = require("./runtime");
|
|
8
8
|
const fsutils_1 = require("../../../fsutils");
|
|
9
|
+
const WATCHER_READY_TIMEOUT_MS = 1000;
|
|
10
|
+
const WATCHER_CHANGE_DELAY_MS = 5;
|
|
9
11
|
function createStorageRulesManager(rules, runtime) {
|
|
10
12
|
return Array.isArray(rules)
|
|
11
13
|
? new ResourceBasedStorageRulesManager(rules, runtime)
|
|
@@ -20,7 +22,7 @@ class DefaultStorageRulesManager {
|
|
|
20
22
|
}
|
|
21
23
|
async start() {
|
|
22
24
|
const issues = await this.loadRuleset();
|
|
23
|
-
this.updateWatcher(this._rules.name);
|
|
25
|
+
await this.updateWatcher(this._rules.name);
|
|
24
26
|
return issues;
|
|
25
27
|
}
|
|
26
28
|
getRuleset() {
|
|
@@ -30,20 +32,34 @@ class DefaultStorageRulesManager {
|
|
|
30
32
|
await this._watcher.close();
|
|
31
33
|
}
|
|
32
34
|
updateWatcher(rulesFile) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const message =
|
|
45
|
-
this._logger.logLabeled("DEBUG", "storage", `A
|
|
46
|
-
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
const timer = setTimeout(resolve, WATCHER_READY_TIMEOUT_MS);
|
|
37
|
+
timer.unref?.();
|
|
38
|
+
this._watcher = chokidar
|
|
39
|
+
.watch(rulesFile, { persistent: true, ignoreInitial: true })
|
|
40
|
+
.once("ready", () => {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
resolve();
|
|
43
|
+
})
|
|
44
|
+
.on("error", (err) => {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
47
|
+
this._logger.logLabeled("DEBUG", "storage", `A storage rules file watcher error occurred: ${message}`);
|
|
48
|
+
resolve();
|
|
49
|
+
})
|
|
50
|
+
.on("change", async () => {
|
|
51
|
+
await new Promise((res) => setTimeout(res, WATCHER_CHANGE_DELAY_MS));
|
|
52
|
+
try {
|
|
53
|
+
const content = (0, fsutils_1.readFile)(rulesFile);
|
|
54
|
+
this._rules.content = content;
|
|
55
|
+
this._logger.logLabeled("BULLET", "storage", "Change detected, updating rules for Cloud Storage...");
|
|
56
|
+
await this.loadRuleset();
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
60
|
+
this._logger.logLabeled("DEBUG", "storage", `A rule file change was detected, but there was an error reading it: ${message}`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
47
63
|
});
|
|
48
64
|
}
|
|
49
65
|
async loadRuleset() {
|
|
@@ -179,10 +179,10 @@ class TaskQueue {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
async runTask(dispatchIndex) {
|
|
182
|
-
|
|
182
|
+
const emulatedTask = this.dispatches[dispatchIndex];
|
|
183
|
+
if (emulatedTask === null) {
|
|
183
184
|
throw new Error("Trying to dispatch a nonexistent task");
|
|
184
185
|
}
|
|
185
|
-
const emulatedTask = this.dispatches[dispatchIndex];
|
|
186
186
|
if (emulatedTask.metadata.lastRunTime !== null &&
|
|
187
187
|
Date.now() - emulatedTask.metadata.lastRunTime < emulatedTask.metadata.currentBackoff * 1000) {
|
|
188
188
|
return;
|
|
@@ -237,10 +237,11 @@ class TaskQueue {
|
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
handleRetry(dispatchIndex) {
|
|
240
|
-
|
|
240
|
+
const task = this.dispatches[dispatchIndex];
|
|
241
|
+
if (task === null) {
|
|
241
242
|
throw new Error("Trying to retry a nonexistent task");
|
|
242
243
|
}
|
|
243
|
-
const { metadata } =
|
|
244
|
+
const { metadata } = task;
|
|
244
245
|
const { retryConfig } = this.config;
|
|
245
246
|
if (this.shouldStopRetrying(metadata, retryConfig)) {
|
|
246
247
|
metadata.status = TaskStatus.FAILED;
|
package/lib/experiments.js
CHANGED
|
@@ -197,16 +197,6 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
197
197
|
default: true,
|
|
198
198
|
public: false,
|
|
199
199
|
},
|
|
200
|
-
crashlyticsWeb: {
|
|
201
|
-
shortDescription: "Enable the ability to upload source maps for web apps to Crashlytics.",
|
|
202
|
-
default: false,
|
|
203
|
-
public: true,
|
|
204
|
-
},
|
|
205
|
-
crashlyticsWebAlerts: {
|
|
206
|
-
shortDescription: "Enable configuring Crashlytics email alerts during web app onboarding.",
|
|
207
|
-
default: false,
|
|
208
|
-
public: false,
|
|
209
|
-
},
|
|
210
200
|
crashlyticsWebBreadcrumbs: {
|
|
211
201
|
shortDescription: "Enable provisioning Cloud Trace storage during web app onboarding.",
|
|
212
202
|
default: false,
|
|
@@ -4,7 +4,6 @@ exports.DEFAULT_RUNTIME = void 0;
|
|
|
4
4
|
exports.readExtensionYaml = readExtensionYaml;
|
|
5
5
|
exports.readPostinstall = readPostinstall;
|
|
6
6
|
exports.getFunctionResourcesWithParamSubstitution = getFunctionResourcesWithParamSubstitution;
|
|
7
|
-
exports.getFunctionProperties = getFunctionProperties;
|
|
8
7
|
exports.getRuntime = getRuntime;
|
|
9
8
|
const supported = require("../../deploy/functions/runtimes/supported");
|
|
10
9
|
const error_1 = require("../../error");
|
|
@@ -41,9 +40,6 @@ function getFunctionResourcesWithParamSubstitution(extensionSpec, params) {
|
|
|
41
40
|
const rawResources = extensionSpec.resources.filter((resource) => validFunctionTypes.includes(resource.type));
|
|
42
41
|
return (0, extensionsHelper_1.substituteParams)(rawResources, params);
|
|
43
42
|
}
|
|
44
|
-
function getFunctionProperties(resources) {
|
|
45
|
-
return resources.map((r) => r.properties);
|
|
46
|
-
}
|
|
47
43
|
exports.DEFAULT_RUNTIME = supported.latest("nodejs");
|
|
48
44
|
function getRuntime(resources) {
|
|
49
45
|
if (resources.length === 0) {
|