firebase-tools 15.30.2 → 15.30.3-main.1

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.
@@ -94,7 +94,7 @@ exports.command = new command_1.Command("ext:migrate")
94
94
  throw new error_1.FirebaseError(`Failed to deploy. Please fix and retry with firebase deploy --only functions:${kitInstanceId}. After success you may remove the old extension with firebase ext:uninstall ${plan.instanceId} --project ${projectId} --immediate`, { original: err instanceof Error ? err : undefined, exit: 1 });
95
95
  }
96
96
  const shouldUninstall = await (0, prompt_1.confirm)({
97
- message: `Functions kit ${kitInstanceId} successfully deployed. After checking function logs to verify that your backend is performing correctly, you should uninstall extension instance ${plan.instanceId}. Uninstall it now?`,
97
+ message: `Functions kit ${kitInstanceId} successfully deployed. After checking function logs to verify that your backend is performing correctly, you should uninstall extension instance ${plan.instanceId}. It can take a few minutes for Eventarc to fully provision and new kits to react to events. Uninstall it now?`,
98
98
  default: false,
99
99
  nonInteractive: options.nonInteractive,
100
100
  force: options.force,
@@ -92,7 +92,6 @@ async function resolveBackend(opts) {
92
92
  userEnvs: envWithTypes(opts.build.params, opts.userEnvs),
93
93
  codebase: opts.codebase,
94
94
  nonInteractive: opts.nonInteractive,
95
- force: opts.force,
96
95
  isEmulator: opts.isEmulator,
97
96
  });
98
97
  return { backend: toBackend(opts.build, paramValues), envs: paramValues, secretRefs: secretRefs };
@@ -16,7 +16,6 @@ const logger_1 = require("../../logger");
16
16
  const error_1 = require("../../error");
17
17
  const prompt_1 = require("../../prompt");
18
18
  const secrets_1 = require("../../functions/secrets");
19
- const build = require("./build");
20
19
  const functional_1 = require("../../functional");
21
20
  const secretManager = require("../../gcp/secretManager");
22
21
  const storage_1 = require("../../gcp/storage");
@@ -169,7 +168,7 @@ function canSatisfyParam(param, value) {
169
168
  (0, functional_1.assertExhaustive)(param);
170
169
  }
171
170
  async function resolveParams(opts) {
172
- const { params, firebaseConfig, userEnvs, codebase, nonInteractive = false, force = false, isEmulator = false, } = opts;
171
+ const { params, firebaseConfig, userEnvs, codebase, nonInteractive = false, isEmulator = false, } = opts;
173
172
  const paramValues = populateDefaultParams(firebaseConfig);
174
173
  const secretRefs = {};
175
174
  const [resolved, outstanding] = (0, functional_1.partition)(params, (param) => {
@@ -181,7 +180,7 @@ async function resolveParams(opts) {
181
180
  const [needSecret, needPrompt] = (0, functional_1.partition)(outstanding, (param) => param.type === "secret");
182
181
  if (!isEmulator) {
183
182
  for (const param of needSecret) {
184
- secretRefs[param.name] = await ensureSecret(param, firebaseConfig.projectId, nonInteractive, force);
183
+ secretRefs[param.name] = await ensureSecret(param, firebaseConfig.projectId, nonInteractive);
185
184
  }
186
185
  }
187
186
  if (nonInteractive && needPrompt.length > 0) {
@@ -234,7 +233,7 @@ function populateDefaultParams(config) {
234
233
  }
235
234
  return defaultParams;
236
235
  }
237
- async function ensureSecret(secretParam, projectId, nonInteractive, force) {
236
+ async function ensureSecret(secretParam, projectId, nonInteractive) {
238
237
  const resourceId = secretParam.resourceId || secretParam.name;
239
238
  const version = secretParam.version || "latest";
240
239
  let secretAlreadyExisted = false;
@@ -245,25 +244,6 @@ async function ensureSecret(secretParam, projectId, nonInteractive, force) {
245
244
  "Set this secret before deploying:\n" +
246
245
  `\tfirebase functions:secrets:set ${resourceId}${secretParam.format === "json" ? " --format=json --data-file <file.json>" : ""}`);
247
246
  }
248
- if (experiments.isEnabled("secretEnvParams") && typeof secretParam.resourceId === "undefined") {
249
- if (force) {
250
- logger_1.logger.info(`--force: Using default resource ID for secret ${secretParam.name}`);
251
- secretParam.resourceId = secretParam.name;
252
- }
253
- else {
254
- secretParam.resourceId = await (0, prompt_1.input)({
255
- default: secretParam.name,
256
- message: `What resource ID do you want to use for the backing Secret resource for secret param ${secretParam.name}?`,
257
- validate: (id) => {
258
- if (new RegExp(`^${build.GCP_SECRET_ID_PATTERN}$`).test(id)) {
259
- return true;
260
- }
261
- return "GCP Secret identifiers must contain only letters, numbers, underscores, and hyphens.";
262
- },
263
- });
264
- }
265
- return ensureSecret(secretParam, projectId, nonInteractive, force);
266
- }
267
247
  const label = secretParam.label || secretParam.name;
268
248
  const notice = `The value for this secret will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${resourceId}.`;
269
249
  const desc = secretParam.description ? `${secretParam.description} ${notice}` : notice;
@@ -289,7 +269,8 @@ async function ensureSecret(secretParam, projectId, nonInteractive, force) {
289
269
  secretAlreadyExisted = true;
290
270
  }
291
271
  const secretRefString = typeof version === "undefined" ? resourceId : `${resourceId}:${version}`;
292
- if (experiments.isEnabled("secretEnvParams")) {
272
+ if (experiments.isEnabled("secretEnvParams") &&
273
+ experiments.isEnabled("writeDefaultSecretBindings")) {
293
274
  if (!secretParam.inLocalEnvironment && secretAlreadyExisted) {
294
275
  logger_1.logger.info(`Onetime (firebase-tools x.y.z+): storing a reference to existing secret ${secretParam.name}=${secretRefString} in .env files.`);
295
276
  }
@@ -218,11 +218,11 @@ async function prepare(context, options, payload) {
218
218
  userEnvs,
219
219
  codebase,
220
220
  nonInteractive: options.nonInteractive,
221
- force: options.force,
222
221
  isEmulator: false,
223
222
  });
224
223
  functionsEnv.writeResolvedParams(resolvedEnvs, userEnvs, userEnvOpt);
225
- if (experiments.isEnabled("secretEnvParams")) {
224
+ if (experiments.isEnabled("secretEnvParams") &&
225
+ experiments.isEnabled("writeDefaultSecretBindings")) {
226
226
  functionsEnv.writeResolvedSecretRefs(resolvedSecretRefs, secretRefs, userEnvOpt);
227
227
  }
228
228
  let hasEnvsFromParams = false;
@@ -13,6 +13,10 @@ const logger_1 = require("../../../../logger");
13
13
  const python_1 = require("../../../../functions/python");
14
14
  const error_1 = require("../../../../error");
15
15
  const functional_1 = require("../../../../functional");
16
+ const utils_1 = require("../../../../utils");
17
+ const FORCE_KILL_DELAY_MS = 10000;
18
+ const SHUTDOWN_TIMEOUT_MS = 15000;
19
+ const QUITQUITQUIT_TIMEOUT_MS = 5000;
16
20
  async function tryCreateDelegate(context) {
17
21
  const requirementsTextPath = path.join(context.sourceDir, "requirements.txt");
18
22
  if (!(await (0, util_1.promisify)(fs.exists)(requirementsTextPath))) {
@@ -120,31 +124,58 @@ class Delegate {
120
124
  };
121
125
  const args = [this.bin, `"${path.join(modulesDir, "private", "serving.py")}"`];
122
126
  logger_1.logger.debug(`Running admin server with args: ${JSON.stringify(args)} and env: ${JSON.stringify(envWithAdminPort)} in ${this.sourceDir}`);
123
- const childProcess = (0, python_1.runWithVirtualEnv)(args, this.sourceDir, envWithAdminPort);
127
+ const childProcess = (0, python_1.runWithVirtualEnv)(args, this.sourceDir, envWithAdminPort, {
128
+ detached: !utils_1.IS_WINDOWS,
129
+ });
124
130
  childProcess.stdout?.on("data", (chunk) => {
125
131
  logger_1.logger.info(chunk.toString("utf8"));
126
132
  });
127
133
  childProcess.stderr?.on("data", (chunk) => {
128
134
  logger_1.logger.error(chunk.toString("utf8"));
129
135
  });
130
- return Promise.resolve(async () => {
131
- try {
132
- await fetch(`http://127.0.0.1:${port}/__/quitquitquit`);
133
- }
134
- catch (e) {
135
- logger_1.logger.debug("Failed to call quitquitquit. This often means the server failed to start", e);
136
- }
137
- const quitTimeout = setTimeout(() => {
138
- if (!childProcess.killed) {
139
- childProcess.kill("SIGKILL");
140
- }
141
- }, 10000);
142
- clearTimeout(quitTimeout);
143
- return new Promise((resolve, reject) => {
144
- childProcess.once("exit", resolve);
145
- childProcess.once("error", reject);
136
+ const exited = new Promise((resolve) => {
137
+ childProcess.once("exit", () => resolve());
138
+ childProcess.once("error", () => resolve());
139
+ });
140
+ (0, python_1.trackVirtualEnvChild)(childProcess);
141
+ return Promise.resolve(() => this.shutdownAdmin(childProcess, port, exited));
142
+ }
143
+ async shutdownAdmin(childProcess, port, exited) {
144
+ try {
145
+ await fetch(`http://127.0.0.1:${port}/__/quitquitquit`, {
146
+ signal: AbortSignal.timeout(QUITQUITQUIT_TIMEOUT_MS),
146
147
  });
148
+ }
149
+ catch (e) {
150
+ logger_1.logger.debug("Failed to call quitquitquit. This often means the server failed to start", e);
151
+ }
152
+ const forceKill = setTimeout(() => {
153
+ if (childProcess.pid) {
154
+ logger_1.logger.debug(`Discovery admin server on port ${port} did not shut down when asked. Force-killing it.`);
155
+ (0, python_1.killProcessTree)(childProcess.pid);
156
+ }
157
+ }, FORCE_KILL_DELAY_MS);
158
+ let giveUp;
159
+ const timedOut = new Promise((resolve) => {
160
+ giveUp = setTimeout(() => resolve(false), SHUTDOWN_TIMEOUT_MS);
147
161
  });
162
+ try {
163
+ const exitedCleanly = await Promise.race([exited.then(() => true), timedOut]);
164
+ if (exitedCleanly) {
165
+ (0, python_1.untrackVirtualEnvChild)(childProcess);
166
+ }
167
+ else {
168
+ logger_1.logger.debug(`Discovery admin server on port ${port} survived being force-killed. ` +
169
+ `Continuing without it; it may need to be cleaned up manually.`);
170
+ }
171
+ }
172
+ finally {
173
+ clearTimeout(forceKill);
174
+ clearTimeout(giveUp);
175
+ childProcess.stdout?.destroy();
176
+ childProcess.stderr?.destroy();
177
+ childProcess.unref();
178
+ }
148
179
  }
149
180
  async discoverBuild(_configValues, envs) {
150
181
  let discovered = await discovery.detectFromYaml(this.sourceDir, this.projectId, this.runtime);
@@ -227,6 +227,11 @@ exports.ALL_EXPERIMENTS = experiments({
227
227
  default: false,
228
228
  public: false,
229
229
  },
230
+ writeDefaultSecretBindings: {
231
+ shortDescription: "Write Cloud Secret Manager bindings to the default resource ID to .env.",
232
+ default: false,
233
+ public: false,
234
+ },
230
235
  });
231
236
  function isValidExperiment(name) {
232
237
  return Object.keys(exports.ALL_EXPERIMENTS).includes(name);
@@ -121,16 +121,30 @@ function resolveMigratedMemory(liveSystemParams = {}, specSystemParams = []) {
121
121
  }
122
122
  return v2 ?? v1;
123
123
  }
124
+ function resolveLiveSecret(specParam, liveParams) {
125
+ const val = liveParams[specParam.param];
126
+ if (!val && !specParam.required) {
127
+ return undefined;
128
+ }
129
+ if (!val) {
130
+ throw new error_1.FirebaseError(`Secret ${specParam.param} was defined in the extension spec, but is missing in live deployed secrets.`, { exit: 1 });
131
+ }
132
+ return val;
133
+ }
124
134
  function functionsEnvFromInstance(instance) {
125
135
  const liveParams = instance.config?.params || {};
126
136
  const liveSystemParams = instance.config?.systemParams || {};
127
137
  const specParams = instance.config?.source?.spec?.params || [];
128
138
  const specSystemParams = instance.config?.source?.spec?.systemParams || [];
129
139
  const envs = {};
130
- specParams.forEach((specParam) => {
140
+ for (const specParam of specParams) {
131
141
  if (specParam.type === "SECRET") {
142
+ const val = resolveLiveSecret(specParam, liveParams);
143
+ if (!val) {
144
+ continue;
145
+ }
132
146
  const renamed = "FIREBASE_SECRET_REF_" + specParam.param;
133
- envs[renamed] = liveParams[specParam.param];
147
+ envs[renamed] = val;
134
148
  }
135
149
  else if (specParam.param in liveParams) {
136
150
  envs[specParam.param] = liveParams[specParam.param];
@@ -138,7 +152,7 @@ function functionsEnvFromInstance(instance) {
138
152
  else {
139
153
  envs[specParam.param] = specParam.default ?? "";
140
154
  }
141
- });
155
+ }
142
156
  for (const [sysParamName, sysParamValue] of Object.entries(liveSystemParams)) {
143
157
  if (MEMORY_PARAMS.has(sysParamName)) {
144
158
  continue;
@@ -181,12 +195,9 @@ async function secretsNeedingEjection(instance) {
181
195
  const liveParams = instance.config?.params || {};
182
196
  const secretParams = (instance.config?.source?.spec?.params ?? []).filter((p) => p.type === "SECRET");
183
197
  const checks = secretParams.map(async (specParam) => {
184
- const secretName = specParam.param;
185
- const resourceName = liveParams[secretName];
198
+ const resourceName = resolveLiveSecret(specParam, liveParams);
186
199
  if (!resourceName) {
187
- throw new error_1.FirebaseError("Secret " +
188
- secretName +
189
- " was defined in the extension spec, but is missing in live deployed secrets.", { exit: 1 });
200
+ return undefined;
190
201
  }
191
202
  const match = resourceName.match(secretManager_1.SECRET_VERSION_NAME_REGEX);
192
203
  if (!match?.groups) {
@@ -208,10 +219,9 @@ async function ejectSecretsFromInstance(instance) {
208
219
  if (specParam.type !== "SECRET") {
209
220
  continue;
210
221
  }
211
- const secretName = specParam.param;
212
- const resourceName = liveParams[secretName];
222
+ const resourceName = resolveLiveSecret(specParam, liveParams);
213
223
  if (!resourceName) {
214
- throw new error_1.FirebaseError(`Secret ${secretName} was defined in the extension spec, but is missing in live deployed secrets.`, { exit: 1 });
224
+ continue;
215
225
  }
216
226
  const match = resourceName.match(secretManager_1.SECRET_VERSION_NAME_REGEX);
217
227
  if (!match?.groups) {
@@ -1,48 +1,41 @@
1
1
  {
2
2
  "replacements": {
3
3
  "firebase/delete-user-data": {
4
- "status": "REPLACEMENT_AVAILABLE",
5
- "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/delete-user-data/README.md",
6
- "npmPackage": "@firebase-function-kits/delete-user-data"
4
+ "status": "PENDING_PUBLISHER",
5
+ "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/delete-user-data/README.md"
7
6
  },
8
7
  "firebase/firestore-bigquery-export": {
9
8
  "status": "REPLACEMENT_AVAILABLE",
10
- "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/firestore-bigquery-export/README.md",
11
- "npmPackage": "@firebase-function-kits/firestore-bigquery-export"
9
+ "npmPackage": "@firebase-function-kits/firestore-bigquery-export",
10
+ "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/firestore-bigquery-export/README.md"
12
11
  },
13
12
  "firebase/firestore-bundle-builder": {
14
13
  "status": "PENDING_PUBLISHER",
15
14
  "extensionRepositoryUrl": "https://github.com/firebase/firestore-bundle-builder/blob/master/README.md"
16
15
  },
17
16
  "firebase/firestore-counter": {
18
- "status": "REPLACEMENT_AVAILABLE",
19
- "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/firestore-counter/README.md",
20
- "npmPackage": "@firebase-function-kits/firestore-counter"
17
+ "status": "PENDING_PUBLISHER",
18
+ "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/firestore-counter/README.md"
21
19
  },
22
20
  "firebase/firestore-send-email": {
23
- "status": "REPLACEMENT_AVAILABLE",
24
- "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/firestore-send-email/README.md",
25
- "npmPackage": "@firebase-function-kits/firestore-send-email"
21
+ "status": "PENDING_PUBLISHER",
22
+ "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/firestore-send-email/README.md"
26
23
  },
27
24
  "firebase/firestore-shorten-urls-bitly": {
28
25
  "status": "PENDING_PUBLISHER",
29
- "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/main/firestore-shorten-urls-bitly/README.md",
30
- "npmPackage": "@firebase/firestore-shorten-urls-bitly"
26
+ "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/main/firestore-shorten-urls-bitly/README.md"
31
27
  },
32
28
  "firebase/firestore-translate-text": {
33
- "status": "REPLACEMENT_AVAILABLE",
34
- "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/firestore-translate-text/README.md",
35
- "npmPackage": "@firebase-function-kits/firestore-translate-text"
29
+ "status": "PENDING_PUBLISHER",
30
+ "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/firestore-translate-text/README.md"
36
31
  },
37
32
  "firebase/rtdb-limit-child-nodes": {
38
- "status": "REPLACEMENT_AVAILABLE",
39
- "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/rtdb-limit-child-nodes/README.md",
40
- "npmPackage": "@firebase-function-kits/rtdb-limit-child-nodes"
33
+ "status": "PENDING_PUBLISHER",
34
+ "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/rtdb-limit-child-nodes/README.md"
41
35
  },
42
36
  "firebase/storage-resize-images": {
43
- "status": "REPLACEMENT_AVAILABLE",
44
- "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/storage-resize-images/README.md",
45
- "npmPackage": "@firebase-function-kits/storage-resize-images"
37
+ "status": "PENDING_PUBLISHER",
38
+ "extensionRepositoryUrl": "https://github.com/firebase/extensions/tree/kits/storage-resize-images/README.md"
46
39
  },
47
40
  "googlecloud/bigquery-firestore-export": {
48
41
  "status": "PENDING_PUBLISHER",
@@ -649,10 +649,10 @@ async function promptAndWriteKitParams(options) {
649
649
  userEnvs: typedUserEnvs,
650
650
  codebase: options.instanceId,
651
651
  nonInteractive: options.nonInteractive,
652
- force: options.force,
653
652
  });
654
653
  functionsEnv.writeResolvedParams(resolvedEnvs, userEnvs, userEnvOpt);
655
- if (experiments.isEnabled("secretEnvParams")) {
654
+ if (experiments.isEnabled("secretEnvParams") &&
655
+ experiments.isEnabled("writeDefaultSecretBindings")) {
656
656
  functionsEnv.writeResolvedSecretRefs(resolvedSecretRefs, secretRefs, userEnvOpt);
657
657
  }
658
658
  }
@@ -827,7 +827,6 @@ async function addKitInstanceOrConfigureProject(options) {
827
827
  absSourcePath,
828
828
  instanceId,
829
829
  nonInteractive: options.nonInteractive,
830
- force: options.force,
831
830
  params: discoveredBuild.params,
832
831
  });
833
832
  }
@@ -999,7 +998,6 @@ async function installKitOrInstance(options) {
999
998
  absSourcePath,
1000
999
  instanceId,
1001
1000
  nonInteractive: options.nonInteractive,
1002
- force: options.force,
1003
1001
  params: discoveredBuild.params,
1004
1002
  });
1005
1003
  }
@@ -3,10 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_VENV_DIR = void 0;
4
4
  exports.virtualEnvCmd = virtualEnvCmd;
5
5
  exports.runWithVirtualEnv = runWithVirtualEnv;
6
+ exports.killProcessTree = killProcessTree;
7
+ exports.trackVirtualEnvChild = trackVirtualEnvChild;
8
+ exports.untrackVirtualEnvChild = untrackVirtualEnvChild;
9
+ const os = require("os");
6
10
  const path = require("path");
7
11
  const cross_spawn_1 = require("cross-spawn");
12
+ const cp = require("child_process");
8
13
  const logger_1 = require("../logger");
9
14
  const utils_1 = require("../utils");
15
+ const error_1 = require("../error");
10
16
  exports.DEFAULT_VENV_DIR = "venv";
11
17
  function virtualEnvCmd(cwd, venvDir) {
12
18
  const activateScriptPath = utils_1.IS_WINDOWS ? ["Scripts", "activate.bat"] : ["bin", "activate"];
@@ -28,3 +34,79 @@ function runWithVirtualEnv(commandAndArgs, cwd, envs, spawnOpts = {}, venvDir =
28
34
  env: { ...process.env, ...envs },
29
35
  });
30
36
  }
37
+ function killProcessTree(pid) {
38
+ if (!pid || pid <= 0) {
39
+ return;
40
+ }
41
+ if (utils_1.IS_WINDOWS) {
42
+ const result = cp.spawnSync("taskkill", ["/pid", pid.toString(), "/T", "/F"]);
43
+ if (result.error || result.status !== 0) {
44
+ logger_1.logger.debug(`taskkill on pid ${pid} exited with ${String(result.status)}: ` +
45
+ `${result.error?.message ?? result.stderr?.toString().trim() ?? ""}`);
46
+ }
47
+ return;
48
+ }
49
+ try {
50
+ process.kill(-pid, "SIGKILL");
51
+ }
52
+ catch (e) {
53
+ logger_1.logger.debug(`Failed to kill process group ${pid}: ${(0, error_1.getErrMsg)(e)}`);
54
+ }
55
+ }
56
+ const CLEANUP_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"];
57
+ const trackedChildren = new Set();
58
+ const signalHandlers = new Map();
59
+ function reRaise(signal) {
60
+ try {
61
+ process.kill(process.pid, signal);
62
+ }
63
+ catch (e) {
64
+ logger_1.logger.debug(`Could not re-raise ${signal}, exiting instead: ${(0, error_1.getErrMsg)(e)}`);
65
+ process.exit(128 + (os.constants.signals[signal] ?? 0));
66
+ }
67
+ }
68
+ function killAllTrackedChildren() {
69
+ for (const child of trackedChildren) {
70
+ if (child.pid && child.exitCode === null && child.signalCode === null) {
71
+ killProcessTree(child.pid);
72
+ }
73
+ }
74
+ trackedChildren.clear();
75
+ }
76
+ function removeCleanupHandlers() {
77
+ if (!signalHandlers.size) {
78
+ return;
79
+ }
80
+ process.removeListener("exit", killAllTrackedChildren);
81
+ for (const [signal, handler] of signalHandlers) {
82
+ process.removeListener(signal, handler);
83
+ }
84
+ signalHandlers.clear();
85
+ }
86
+ function addCleanupHandlers() {
87
+ if (signalHandlers.size) {
88
+ return;
89
+ }
90
+ process.on("exit", killAllTrackedChildren);
91
+ for (const signal of CLEANUP_SIGNALS) {
92
+ const handler = () => {
93
+ killAllTrackedChildren();
94
+ removeCleanupHandlers();
95
+ if (process.listenerCount(signal) === 0) {
96
+ reRaise(signal);
97
+ }
98
+ };
99
+ signalHandlers.set(signal, handler);
100
+ process.on(signal, handler);
101
+ }
102
+ }
103
+ function trackVirtualEnvChild(child) {
104
+ trackedChildren.add(child);
105
+ addCleanupHandlers();
106
+ }
107
+ function untrackVirtualEnvChild(child) {
108
+ trackedChildren.delete(child);
109
+ if (!trackedChildren.size) {
110
+ removeCleanupHandlers();
111
+ }
112
+ }
@@ -257,6 +257,17 @@ async function createCloudProject(projectId, options) {
257
257
  }
258
258
  }
259
259
  }
260
+ function isTosNotAcceptedError(err) {
261
+ if (!(err instanceof error_1.FirebaseError) || !err.context) {
262
+ return false;
263
+ }
264
+ const context = err.context;
265
+ const details = context.body?.error?.details;
266
+ if (!Array.isArray(details)) {
267
+ return false;
268
+ }
269
+ return details.some((d) => typeof d?.detail === "string" && d.detail.includes("Firebase Tos Not Accepted"));
270
+ }
260
271
  async function addFirebaseToCloudProject(projectId) {
261
272
  try {
262
273
  const response = await firebaseAPIClient.request({
@@ -274,6 +285,9 @@ async function addFirebaseToCloudProject(projectId) {
274
285
  }
275
286
  catch (err) {
276
287
  logger_1.logger.debug(err.message);
288
+ if (isTosNotAcceptedError(err)) {
289
+ throw new error_1.FirebaseError(`Failed to add Firebase to Google Cloud Platform project ${clc.bold(projectId)} because your account has not accepted the Firebase Terms of Service. Please accept the Terms of Service in the Firebase console at ${api.consoleOrigin()} and try again.`, { exit: 2, original: err });
290
+ }
277
291
  throw new error_1.FirebaseError("Failed to add Firebase to Google Cloud Platform project. See firebase-debug.log for more info.", { exit: 2, original: err });
278
292
  }
279
293
  }