firebase-tools 15.34.2 → 15.36.0

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.
Files changed (126) hide show
  1. package/lib/api.js +2 -4
  2. package/lib/appcheck/debugTokens.js +293 -0
  3. package/lib/appcheck/localConfig.js +191 -0
  4. package/lib/appdistribution/options-parser-util.js +1 -1
  5. package/lib/apphosting/constants.js +1 -4
  6. package/lib/apphosting/githubConnections.js +1 -1
  7. package/lib/apphosting/utils.js +0 -26
  8. package/lib/auth.js +8 -2
  9. package/lib/commands/appcheck-debugtokens-create.js +60 -35
  10. package/lib/commands/appcheck-debugtokens-delete.js +21 -7
  11. package/lib/commands/appcheck-debugtokens-list.js +37 -8
  12. package/lib/commands/appcheck-debugtokens-prune.js +59 -0
  13. package/lib/commands/crashlytics-heapdumps-status.js +1 -1
  14. package/lib/commands/{crashlytics-onboard-web.js → crashlytics-setup.js} +5 -5
  15. package/lib/commands/crashlytics-sourcemap-upload.js +4 -0
  16. package/lib/commands/deploy.js +1 -3
  17. package/lib/commands/emulators-start.js +2 -2
  18. package/lib/commands/hosting-channel-create.js +1 -3
  19. package/lib/commands/hosting-channel-delete.js +1 -3
  20. package/lib/commands/hosting-channel-deploy.js +1 -3
  21. package/lib/commands/hosting-channel-list.js +1 -3
  22. package/lib/commands/hosting-channel-open.js +1 -3
  23. package/lib/commands/hosting-clone.js +3 -5
  24. package/lib/commands/hosting-disable.js +2 -2
  25. package/lib/commands/hosting-sites-create.js +1 -3
  26. package/lib/commands/hosting-sites-delete.js +1 -3
  27. package/lib/commands/hosting-sites-get.js +1 -3
  28. package/lib/commands/hosting-sites-list.js +1 -3
  29. package/lib/commands/index.js +4 -2
  30. package/lib/commands/run-services-get.js +19 -0
  31. package/lib/commands/run-services-list.js +11 -0
  32. package/lib/crashlytics/alerts.js +1 -0
  33. package/lib/crashlytics/events.js +122 -1
  34. package/lib/crashlytics/filters.js +12 -6
  35. package/lib/crashlytics/firebasetelemetry.js +5 -3
  36. package/lib/crashlytics/onboarding.js +8 -7
  37. package/lib/crashlytics/profilingManager.js +14 -34
  38. package/lib/crashlytics/reports.js +46 -17
  39. package/lib/crashlytics/sourcemap.js +19 -5
  40. package/lib/crashlytics/utils.js +14 -0
  41. package/lib/database/import.js +5 -4
  42. package/lib/dataconnect/dataplaneClient.js +0 -10
  43. package/lib/dataconnect/names.js +3 -3
  44. package/lib/dataconnect/schemaMigration.js +1 -1
  45. package/lib/deploy/apphosting/deploy.js +20 -41
  46. package/lib/deploy/apphosting/localBuild.js +49 -0
  47. package/lib/deploy/apphosting/prepare.js +12 -25
  48. package/lib/deploy/apphosting/release.js +1 -1
  49. package/lib/deploy/apphosting/util.js +27 -4
  50. package/lib/deploy/functions/backend.js +0 -10
  51. package/lib/deploy/functions/cel.js +1 -1
  52. package/lib/deploy/functions/containerCleaner.js +1 -142
  53. package/lib/deploy/functions/functionsDeployHelper.js +0 -4
  54. package/lib/deploy/functions/release/reporter.js +0 -26
  55. package/lib/deploy/functions/runtimes/discovery/index.js +4 -1
  56. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +1 -1
  57. package/lib/deploy/functions/services/index.js +13 -11
  58. package/lib/deploy/functions/validate.js +1 -1
  59. package/lib/deploy/hosting/prepare.js +1 -3
  60. package/lib/deploy/lifecycleHooks.js +1 -1
  61. package/lib/deploy/run/deploy.js +26 -43
  62. package/lib/deploy/run/get.js +30 -0
  63. package/lib/deploy/run/list.js +38 -0
  64. package/lib/deploy/run/prereqs.js +0 -3
  65. package/lib/deploy/run/util.js +9 -0
  66. package/lib/emulator/auth/operations.js +2 -2
  67. package/lib/emulator/auth/server.js +4 -2
  68. package/lib/emulator/auth/widget_ui.js +1 -1
  69. package/lib/emulator/commandUtils.js +109 -24
  70. package/lib/emulator/databaseEmulator.js +16 -11
  71. package/lib/emulator/dataconnect/pgliteServer.js +31 -24
  72. package/lib/emulator/downloadableEmulatorInfo.json +24 -24
  73. package/lib/emulator/downloadableEmulators.js +45 -7
  74. package/lib/emulator/extensions/postinstall.js +6 -6
  75. package/lib/emulator/firestoreEmulator.js +21 -15
  76. package/lib/emulator/functionsEmulator.js +11 -7
  77. package/lib/emulator/functionsEmulatorRuntime.js +7 -2
  78. package/lib/emulator/hub.js +12 -8
  79. package/lib/emulator/shared/express.js +30 -0
  80. package/lib/emulator/storage/apis/firebase.js +11 -10
  81. package/lib/emulator/storage/apis/gcloud.js +21 -20
  82. package/lib/emulator/storage/files.js +1 -1
  83. package/lib/emulator/storage/rules/manager.js +15 -12
  84. package/lib/emulator/storage/rules/runtime.js +1 -0
  85. package/lib/emulator/storage/server.js +10 -5
  86. package/lib/extensions/extensionsApi.js +0 -8
  87. package/lib/extensions/extensionsHelper.js +3 -24
  88. package/lib/extensions/paramHelper.js +1 -1
  89. package/lib/extensions/provisioningHelper.js +1 -6
  90. package/lib/extensions/secretsUtils.js +0 -24
  91. package/lib/firestore/util.js +3 -3
  92. package/lib/frameworks/angular/utils.js +1 -1
  93. package/lib/frameworks/next/utils.js +1 -12
  94. package/lib/fsAsync.js +34 -20
  95. package/lib/functions/kits/install.js +233 -628
  96. package/lib/functions/kits/sources/directory.js +91 -0
  97. package/lib/functions/kits/sources/npm.js +324 -0
  98. package/lib/functions/kits/sources/types.js +12 -0
  99. package/lib/functionsConfig.js +0 -4
  100. package/lib/functionsShellCommandAction.js +1 -1
  101. package/lib/gcp/artifactregistry.js +0 -5
  102. package/lib/gcp/cloudfunctionsv2.js +0 -6
  103. package/lib/gcp/devConnect.js +2 -2
  104. package/lib/gcp/iam.js +0 -4
  105. package/lib/gcp/pubsub.js +0 -14
  106. package/lib/gcp/storage.js +2 -1
  107. package/lib/hosting/api.js +79 -0
  108. package/lib/hosting/proxy.js +4 -1
  109. package/lib/init/features/hosting/github.js +6 -4
  110. package/lib/init/features/hosting/index.js +4 -0
  111. package/lib/init/features/run.js +3 -7
  112. package/lib/mcp/apps/init/mcp-app.js +4 -1
  113. package/lib/mcp/index.js +8 -2
  114. package/lib/mcp/prompts/apptesting/run_test.js +3 -3
  115. package/lib/mcp/prompts/core/deploy.js +3 -3
  116. package/lib/mcp/resources/guides/crashlytics_reports.js +33 -71
  117. package/lib/mcp/resources/guides/init_ai.js +10 -10
  118. package/lib/mcp/tools/crashlytics/events.js +18 -93
  119. package/lib/mcp/tools/crashlytics/index.js +2 -0
  120. package/lib/mcp/tools/crashlytics/reports.js +26 -31
  121. package/lib/mcp/tools/crashlytics/setup.js +392 -0
  122. package/lib/tsconfig.compile.tsbuildinfo +1 -1
  123. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  124. package/lib/utils.js +4 -10
  125. package/package.json +1 -2
  126. package/lib/deploy/hosting/args.js +0 -2
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PLATFORM_PATH = exports.CRASHLYTICS_API_CLIENT = exports.TIMEOUT = void 0;
4
4
  exports.parseProjectNumber = parseProjectNumber;
5
+ exports.parseAppPlatform = parseAppPlatform;
5
6
  exports.parsePlatform = parsePlatform;
6
7
  const error_1 = require("../error");
7
8
  const apiv2_1 = require("../apiv2");
8
9
  const api_1 = require("../api");
10
+ const apps_1 = require("../management/apps");
9
11
  exports.TIMEOUT = 10000;
10
12
  exports.CRASHLYTICS_API_CLIENT = new apiv2_1.Client({
11
13
  urlPrefix: (0, api_1.crashlyticsApiOrigin)(),
@@ -23,6 +25,18 @@ function parseProjectNumber(appId) {
23
25
  }
24
26
  throw new error_1.FirebaseError("Unable to get the projectId from the AppId.");
25
27
  }
28
+ function parseAppPlatform(appId) {
29
+ const platformSegment = appId?.split(":")[2];
30
+ if (!platformSegment) {
31
+ return undefined;
32
+ }
33
+ try {
34
+ return (0, apps_1.getAppPlatform)(platformSegment);
35
+ }
36
+ catch {
37
+ return undefined;
38
+ }
39
+ }
26
40
  function parsePlatform(appId) {
27
41
  const appIdParts = appId.split(":");
28
42
  if (appIdParts.length < 3) {
@@ -124,10 +124,11 @@ class DatabaseImporter {
124
124
  done();
125
125
  };
126
126
  const writeBatch = new stream.Transform({ objectMode: true });
127
- writeBatch._transform = async function (batch, _, done) {
128
- const res = await doWriteBatch(batch);
129
- this.push(res);
130
- done();
127
+ writeBatch._transform = function (batch, _, done) {
128
+ void doWriteBatch(batch).then((res) => {
129
+ this.push(res);
130
+ done();
131
+ }, (err) => done(err));
131
132
  };
132
133
  return new Promise((resolve, reject) => {
133
134
  const responses = [];
@@ -4,8 +4,6 @@ exports.DATACONNECT_API_VERSION = exports.dataconnectOrigin = void 0;
4
4
  exports.dataconnectDataplaneClient = dataconnectDataplaneClient;
5
5
  exports.executeGraphQL = executeGraphQL;
6
6
  exports.executeGraphQLRead = executeGraphQLRead;
7
- exports.executeGraphQLQuery = executeGraphQLQuery;
8
- exports.executeGraphQLMutation = executeGraphQLMutation;
9
7
  const api_1 = require("../api");
10
8
  var api_2 = require("../api");
11
9
  Object.defineProperty(exports, "dataconnectOrigin", { enumerable: true, get: function () { return api_2.dataconnectOrigin; } });
@@ -26,11 +24,3 @@ async function executeGraphQLRead(client, servicePath, body) {
26
24
  const res = await client.post(`${servicePath}:executeGraphqlRead`, body, { resolveOnHTTPError: true });
27
25
  return res;
28
26
  }
29
- async function executeGraphQLQuery(client, connectorPath, body) {
30
- const res = await client.post(`${connectorPath}:executeQuery`, body, { resolveOnHTTPError: true });
31
- return res;
32
- }
33
- async function executeGraphQLMutation(client, connectorPath, body) {
34
- const res = await client.post(`${connectorPath}:executeMutation`, body, { resolveOnHTTPError: true });
35
- return res;
36
- }
@@ -5,7 +5,7 @@ exports.parseConnectorName = parseConnectorName;
5
5
  exports.parseCloudSQLInstanceName = parseCloudSQLInstanceName;
6
6
  exports.isGraphqlName = isGraphqlName;
7
7
  const error_1 = require("../error");
8
- const serviceNameRegex = /projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/services\/(?<serviceId>[^\/]+)/;
8
+ const serviceNameRegex = /projects\/(?<projectId>[^/]+)\/locations\/(?<location>[^/]+)\/services\/(?<serviceId>[^/]+)/;
9
9
  function parseServiceName(serviceName) {
10
10
  const res = serviceNameRegex.exec(serviceName);
11
11
  const projectId = res?.groups?.projectId;
@@ -24,7 +24,7 @@ function parseServiceName(serviceName) {
24
24
  toString,
25
25
  };
26
26
  }
27
- const connectorNameRegex = /projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/services\/(?<serviceId>[^\/]+)\/connectors\/(?<connectorId>[^\/]+)/;
27
+ const connectorNameRegex = /projects\/(?<projectId>[^/]+)\/locations\/(?<location>[^/]+)\/services\/(?<serviceId>[^/]+)\/connectors\/(?<connectorId>[^/]+)/;
28
28
  function parseConnectorName(connectorName) {
29
29
  const res = connectorNameRegex.exec(connectorName);
30
30
  const projectId = res?.groups?.projectId;
@@ -45,7 +45,7 @@ function parseConnectorName(connectorName) {
45
45
  toString,
46
46
  };
47
47
  }
48
- const cloudSQLInstanceNameRegex = /projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/instances\/(?<instanceId>[^\/]+)/;
48
+ const cloudSQLInstanceNameRegex = /projects\/(?<projectId>[^/]+)\/locations\/(?<location>[^/]+)\/instances\/(?<instanceId>[^/]+)/;
49
49
  function parseCloudSQLInstanceName(cloudSQLInstanceName) {
50
50
  const res = cloudSQLInstanceNameRegex.exec(cloudSQLInstanceName);
51
51
  const projectId = res?.groups?.projectId;
@@ -576,5 +576,5 @@ function diffsToString(diffs) {
576
576
  return diffs.map(diffToString).join("\n\n");
577
577
  }
578
578
  function diffToString(diff) {
579
- return `\/** ${diff.destructive ? clc.red("Destructive: ") : ""}${diff.description}*\/\n${(0, sql_formatter_1.format)(diff.sql, { language: "postgresql" })}`;
579
+ return `/** ${diff.destructive ? clc.red("Destructive: ") : ""}${diff.description}*/\n${(0, sql_formatter_1.format)(diff.sql, { language: "postgresql" })}`;
580
580
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = default_1;
4
- const fs = require("fs");
5
4
  const path = require("path");
6
5
  const error_1 = require("../../error");
7
6
  const gcs = require("../../gcp/storage");
@@ -10,8 +9,6 @@ const projectUtils_1 = require("../../projectUtils");
10
9
  const utils_1 = require("../../utils");
11
10
  const util = require("./util");
12
11
  const experiments = require("../../experiments");
13
- const logger_1 = require("../../logger");
14
- const constants_1 = require("../../apphosting/constants");
15
12
  async function default_1(context, options) {
16
13
  if (Object.entries(context.backendConfigs).length === 0) {
17
14
  return;
@@ -54,46 +51,28 @@ async function default_1(context, options) {
54
51
  }));
55
52
  await Promise.all(Object.values(context.backendConfigs).map(async (cfg) => {
56
53
  const rootDir = options.projectRoot ?? process.cwd();
57
- let localBuildScratchDir;
58
- try {
59
- const isLocalBuild = cfg.localBuild;
60
- let outputFiles;
61
- if (isLocalBuild) {
62
- experiments.assertEnabled("apphostinglocalbuilds", "App Hosting local builds");
63
- const localBuild = context.backendLocalBuilds[cfg.backendId];
64
- outputFiles = localBuild?.outputFiles;
65
- localBuildScratchDir = localBuild?.localBuildScratchDir;
66
- if (!outputFiles || !localBuildScratchDir) {
67
- throw new error_1.FirebaseError(`No local build output files found for ${cfg.backendId}`);
68
- }
54
+ const isLocalBuild = cfg.localBuild;
55
+ let archive;
56
+ if (isLocalBuild) {
57
+ experiments.assertEnabled("apphostinglocalbuilds", "App Hosting local builds");
58
+ archive = context.backendLocalBuilds[cfg.backendId]?.archive;
59
+ if (!archive) {
60
+ throw new error_1.FirebaseError(`No local build output files found for ${cfg.backendId}`);
69
61
  }
70
- const zippedSourcePath = isLocalBuild
71
- ? await util.createLocalBuildTarArchive(cfg, localBuildScratchDir, outputFiles ?? [])
72
- : await util.createSourceDeployArchive(cfg, rootDir);
73
- (0, utils_1.logLabeledBullet)("apphosting", `Zipped ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}`);
74
- const backendLocation = context.backendLocations[cfg.backendId];
75
- if (!backendLocation) {
76
- throw new error_1.FirebaseError(`Failed to find location for backend ${cfg.backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`);
77
- }
78
- (0, utils_1.logLabeledBullet)("apphosting", `Uploading ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}...`);
79
- const bucketName = bucketsPerLocation[backendLocation];
80
- const { bucket, object } = await gcs.uploadObject({
81
- file: zippedSourcePath,
82
- stream: fs.createReadStream(zippedSourcePath),
83
- }, bucketName, isLocalBuild ? gcs.ContentType.TAR : gcs.ContentType.ZIP, isLocalBuild ? constants_1.CLOUD_RUN_SIZE_LIMIT_BYTES : undefined);
84
- (0, utils_1.logLabeledBullet)("apphosting", `Uploaded at gs://${bucket}/${object}`);
85
- context.backendStorageUris[cfg.backendId] =
86
- `gs://${bucketName}/${path.basename(zippedSourcePath)}`;
87
62
  }
88
- finally {
89
- if (localBuildScratchDir && fs.existsSync(localBuildScratchDir)) {
90
- try {
91
- fs.rmSync(localBuildScratchDir, { recursive: true, force: true });
92
- }
93
- catch (err) {
94
- logger_1.logger.debug(`Failed to clean up local build directory ${localBuildScratchDir}: ${err}`);
95
- }
96
- }
63
+ const zippedSourcePath = archive ?? (await util.createSourceDeployArchive(cfg, rootDir));
64
+ if (!archive) {
65
+ (0, utils_1.logLabeledBullet)("apphosting", `Zipped source for backend ${cfg.backendId}`);
66
+ }
67
+ const backendLocation = context.backendLocations[cfg.backendId];
68
+ if (!backendLocation) {
69
+ throw new error_1.FirebaseError(`Failed to find location for backend ${cfg.backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`);
97
70
  }
71
+ (0, utils_1.logLabeledBullet)("apphosting", `Uploading ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}...`);
72
+ const bucketName = bucketsPerLocation[backendLocation];
73
+ const { bucket, object } = await util.uploadArchive(zippedSourcePath, bucketName, !!isLocalBuild);
74
+ (0, utils_1.logLabeledBullet)("apphosting", `Uploaded at gs://${bucket}/${object}`);
75
+ context.backendStorageUris[cfg.backendId] =
76
+ `gs://${bucketName}/${path.basename(zippedSourcePath)}`;
98
77
  }));
99
78
  }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildLocally = buildLocally;
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const localbuilds_1 = require("../../apphosting/localbuilds");
7
+ const error_1 = require("../../error");
8
+ const fsAsync = require("../../fsAsync");
9
+ const logger_1 = require("../../logger");
10
+ const util_1 = require("./util");
11
+ async function buildLocally(options) {
12
+ const { projectId, projectDir, config, env, scratchDir } = options;
13
+ const { buildFolder, appFolder } = (0, util_1.buildDirectory)(projectDir, config.rootDir);
14
+ const scratchBuildFolder = path.join(scratchDir, path.relative(projectDir, buildFolder));
15
+ try {
16
+ await prepareLocalBuildScratchDirectory(projectDir, scratchDir, config);
17
+ const { outputFiles, buildConfig } = await (0, localbuilds_1.localBuild)(projectId, scratchBuildFolder, env, {
18
+ nonInteractive: options.nonInteractive,
19
+ allowLocalBuildSecrets: options.allowLocalBuildSecrets,
20
+ rootDir: appFolder,
21
+ });
22
+ const archive = await (0, util_1.createLocalBuildTarArchive)(config, scratchBuildFolder, outputFiles);
23
+ return { archive, rootDirectory: appFolder, buildConfig };
24
+ }
25
+ finally {
26
+ try {
27
+ fs.rmSync(scratchDir, { recursive: true, force: true });
28
+ }
29
+ catch (err) {
30
+ logger_1.logger.debug(`Failed to clean up local build directory ${scratchDir}: ${(0, error_1.getErrMsg)(err)}`);
31
+ }
32
+ }
33
+ }
34
+ async function prepareLocalBuildScratchDirectory(rootDir, localBuildScratchDir, cfg) {
35
+ const ignore = (0, util_1.resolveIgnorePatterns)(cfg);
36
+ fs.rmSync(localBuildScratchDir, { recursive: true, force: true });
37
+ fs.mkdirSync(localBuildScratchDir, { recursive: true });
38
+ const filesToCopy = await fsAsync.readdirRecursive({
39
+ path: rootDir,
40
+ ignoreStrings: ignore,
41
+ supportGitIgnore: true,
42
+ });
43
+ for (const file of filesToCopy) {
44
+ const relativePath = path.relative(rootDir, file.name);
45
+ const destPath = path.join(localBuildScratchDir, relativePath);
46
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
47
+ fs.copyFileSync(file.name, destPath);
48
+ }
49
+ }
@@ -4,14 +4,12 @@ exports.default = default_1;
4
4
  exports.injectEnvVarsFromApphostingConfig = injectEnvVarsFromApphostingConfig;
5
5
  exports.injectAutoInitEnvVars = injectAutoInitEnvVars;
6
6
  exports.getBackendConfigs = getBackendConfigs;
7
- exports.prepareLocalBuildScratchDirectory = prepareLocalBuildScratchDirectory;
8
7
  exports.injectAngularEnvVars = injectAngularEnvVars;
9
8
  const crypto = require("crypto");
10
9
  const fs = require("fs");
11
10
  const os = require("os");
12
11
  const path = require("path");
13
- const fsAsync = require("../../fsAsync");
14
- const util_1 = require("./util");
12
+ const localBuild_1 = require("./localBuild");
15
13
  const backend_1 = require("../../apphosting/backend");
16
14
  const apphosting_1 = require("../../gcp/apphosting");
17
15
  const yaml_1 = require("../../apphosting/yaml");
@@ -163,15 +161,18 @@ async function default_1(context, options) {
163
161
  const pathHash = crypto.createHash("md5").update(rootDir).digest("hex").substring(0, 8);
164
162
  const localBuildScratchDir = path.join(os.tmpdir(), `apphosting-local-build-${cfg.backendId}-${pathHash}`);
165
163
  try {
166
- await prepareLocalBuildScratchDirectory(rootDir, localBuildScratchDir, cfg);
167
- const { outputFiles, buildConfig } = await (0, localbuilds_1.localBuild)(projectId, localBuildScratchDir, buildEnv[cfg.backendId] || {}, {
164
+ const { archive, rootDirectory, buildConfig } = await (0, localBuild_1.buildLocally)({
165
+ projectId,
166
+ projectDir: rootDir,
167
+ config: cfg,
168
+ env: buildEnv[cfg.backendId] || {},
169
+ scratchDir: localBuildScratchDir,
168
170
  nonInteractive: options.nonInteractive,
169
171
  allowLocalBuildSecrets: !!options.allowLocalBuildSecrets,
170
- rootDir: cfg.rootDir,
171
172
  });
172
173
  context.backendLocalBuilds[cfg.backendId] = {
173
- outputFiles,
174
- localBuildScratchDir,
174
+ archive,
175
+ rootDirectory,
175
176
  buildConfig: {
176
177
  ...buildConfig,
177
178
  env: mergeEnvVars(buildConfig.env || [], runtimeEnv[cfg.backendId] || {}),
@@ -216,7 +217,9 @@ async function injectAutoInitEnvVars(cfg, backends, buildEnv, runtimeEnv) {
216
217
  const autoinitVars = (0, utils_2.getAutoinitEnvVars)(webappConfig);
217
218
  for (const [envVarName, envVarValue] of Object.entries(autoinitVars)) {
218
219
  (_a = buildEnv[cfg.backendId])[envVarName] ?? (_a[envVarName] = { value: envVarValue });
219
- (_b = runtimeEnv[cfg.backendId])[envVarName] ?? (_b[envVarName] = { value: envVarValue });
220
+ if (envVarName === "FIREBASE_CONFIG") {
221
+ (_b = runtimeEnv[cfg.backendId])[envVarName] ?? (_b[envVarName] = { value: envVarValue });
222
+ }
220
223
  }
221
224
  }
222
225
  catch (e) {
@@ -280,22 +283,6 @@ async function ensureAppHostingServiceAgentRoles(projectId, projectNumber) {
280
283
  (0, utils_1.logLabeledWarning)("apphosting", `Unable to verify App Hosting service agent permissions for ${p4saEmail}. If you encounter a PERMISSION_DENIED error during rollout, please ensure the service agent has the "Storage Object Viewer" role.`);
281
284
  }
282
285
  }
283
- async function prepareLocalBuildScratchDirectory(rootDir, localBuildScratchDir, cfg) {
284
- const ignore = (0, util_1.resolveIgnorePatterns)(cfg);
285
- fs.rmSync(localBuildScratchDir, { recursive: true, force: true });
286
- fs.mkdirSync(localBuildScratchDir, { recursive: true });
287
- const filesToCopy = await fsAsync.readdirRecursive({
288
- path: rootDir,
289
- ignoreStrings: ignore,
290
- supportGitIgnore: true,
291
- });
292
- for (const file of filesToCopy) {
293
- const relativePath = path.relative(rootDir, file.name);
294
- const destPath = path.join(localBuildScratchDir, relativePath);
295
- fs.mkdirSync(path.dirname(destPath), { recursive: true });
296
- fs.copyFileSync(file.name, destPath);
297
- }
298
- }
299
286
  function isAngularApplication(appDir) {
300
287
  const packageJsonPath = path.join(appDir, "package.json");
301
288
  if (fs.existsSync(packageJsonPath)) {
@@ -27,7 +27,7 @@ async function default_1(context, options) {
27
27
  ? {
28
28
  locallyBuilt: {
29
29
  userStorageUri,
30
- rootDirectory,
30
+ rootDirectory: localBuild.rootDirectory,
31
31
  runCommand: localBuild.buildConfig?.runCommand,
32
32
  env: localBuild.buildConfig?.env,
33
33
  ...(localBuild.buildConfig?.runConfig
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLocalBuildTarArchive = createLocalBuildTarArchive;
4
4
  exports.createSourceDeployArchive = createSourceDeployArchive;
5
+ exports.uploadArchive = uploadArchive;
5
6
  exports.resolveIgnorePatterns = resolveIgnorePatterns;
7
+ exports.buildDirectory = buildDirectory;
6
8
  const archiver = require("archiver");
7
9
  const fs = require("fs");
8
10
  const path = require("path");
@@ -11,6 +13,7 @@ const tmp = require("tmp");
11
13
  const error_1 = require("../../error");
12
14
  const logger_1 = require("../../logger");
13
15
  const fsAsync = require("../../fsAsync");
16
+ const gcs = require("../../gcp/storage");
14
17
  const utils_1 = require("../../utils");
15
18
  const constants_1 = require("../../apphosting/constants");
16
19
  async function createLocalBuildTarArchive(config, rootDir, outputFiles, sizeLimitBytes = constants_1.CLOUD_RUN_SIZE_LIMIT_BYTES) {
@@ -64,23 +67,23 @@ async function createLocalBuildTarArchive(config, rootDir, outputFiles, sizeLimi
64
67
  }
65
68
  return tmpFile;
66
69
  }
67
- async function createSourceDeployArchive(config, rootDir, targetSubDir) {
70
+ async function createSourceDeployArchive(config, folderToZip, projectFolder = folderToZip) {
68
71
  const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".zip" }).name;
69
72
  const fileStream = fs.createWriteStream(tmpFile, {
70
73
  flags: "w",
71
74
  encoding: "binary",
72
75
  });
73
76
  const archive = archiver("zip");
74
- const targetDir = targetSubDir ? path.join(rootDir, targetSubDir) : rootDir;
75
77
  const ignore = resolveIgnorePatterns(config);
76
78
  try {
77
79
  const files = await fsAsync.readdirRecursive({
78
- path: targetDir,
80
+ path: folderToZip,
79
81
  ignoreStrings: ignore,
80
82
  supportGitIgnore: true,
83
+ gitIgnoreRoot: projectFolder,
81
84
  });
82
85
  for (const file of files) {
83
- const name = path.relative(rootDir, file.name);
86
+ const name = path.relative(folderToZip, file.name);
84
87
  archive.file(file.name, {
85
88
  name,
86
89
  mode: file.mode,
@@ -93,6 +96,10 @@ async function createSourceDeployArchive(config, rootDir, targetSubDir) {
93
96
  }
94
97
  return tmpFile;
95
98
  }
99
+ async function uploadArchive(archive, bucketName, localBuild) {
100
+ const { bucket, object } = await gcs.uploadObject({ file: archive, stream: fs.createReadStream(archive) }, bucketName, localBuild ? gcs.ContentType.TAR : gcs.ContentType.ZIP, localBuild ? constants_1.CLOUD_RUN_SIZE_LIMIT_BYTES : undefined);
101
+ return { bucket, object };
102
+ }
96
103
  function resolveIgnorePatterns(config, skipDefaultNodeModules = false) {
97
104
  const ignore = config.ignore
98
105
  ? [...config.ignore]
@@ -103,6 +110,22 @@ function resolveIgnorePatterns(config, skipDefaultNodeModules = false) {
103
110
  ignore.push(".local_build_*");
104
111
  return ignore;
105
112
  }
113
+ const MONOREPO_CONFIG_FILES = ["nx.json", "turbo.json"];
114
+ function buildDirectory(projectDir, rootDir = "") {
115
+ const appFolderPath = path.join(projectDir, rootDir);
116
+ const appFolderInProject = path.relative(projectDir, appFolderPath);
117
+ if (appFolderInProject.startsWith("..")) {
118
+ throw new error_1.FirebaseError(`rootDir "${rootDir}" must be inside the project directory.`);
119
+ }
120
+ const segments = appFolderInProject ? appFolderInProject.split(path.sep) : [];
121
+ for (let depth = segments.length; depth >= 0; depth--) {
122
+ const folder = path.join(projectDir, ...segments.slice(0, depth));
123
+ if (MONOREPO_CONFIG_FILES.some((file) => fs.existsSync(path.join(folder, file)))) {
124
+ return { buildFolder: folder, appFolder: segments.slice(depth).join("/") };
125
+ }
126
+ }
127
+ return { buildFolder: appFolderPath, appFolder: "" };
128
+ }
106
129
  async function pipeAsync(from, to) {
107
130
  from.pipe(to);
108
131
  await from.finalize();
@@ -18,7 +18,6 @@ exports.isBlockingTriggered = isBlockingTriggered;
18
18
  exports.empty = empty;
19
19
  exports.of = of;
20
20
  exports.merge = merge;
21
- exports.isEmptyBackend = isEmptyBackend;
22
21
  exports.functionName = functionName;
23
22
  exports.scheduleIdForFunction = scheduleIdForFunction;
24
23
  exports.existingBackend = existingBackend;
@@ -27,7 +26,6 @@ exports.allEndpoints = allEndpoints;
27
26
  exports.someEndpoint = someEndpoint;
28
27
  exports.findEndpoint = findEndpoint;
29
28
  exports.matchingBackend = matchingBackend;
30
- exports.regionalEndpoints = regionalEndpoints;
31
29
  exports.compareFunctions = compareFunctions;
32
30
  exports.maybeDeterministicCloudRunUri = maybeDeterministicCloudRunUri;
33
31
  const gcf = require("../../gcp/cloudfunctions");
@@ -192,11 +190,6 @@ function merge(...backends) {
192
190
  }
193
191
  return merged;
194
192
  }
195
- function isEmptyBackend(backend) {
196
- return (Object.keys(backend.requiredAPIs).length === 0 &&
197
- Object.keys(backend.endpoints).length === 0 &&
198
- Object.keys(backend.lifecycleHooks || {}).length === 0);
199
- }
200
193
  function functionName(cloudFunction) {
201
194
  return `projects/${cloudFunction.project}/locations/${cloudFunction.region}/functions/${cloudFunction.id}`;
202
195
  }
@@ -345,9 +338,6 @@ function matchingBackend(backend, predicate) {
345
338
  }
346
339
  return filtered;
347
340
  }
348
- function regionalEndpoints(backend, region) {
349
- return backend.endpoints[region] ? Object.values(backend.endpoints[region]) : [];
350
- }
351
341
  const hasEndpoint = (backend) => (endpoint) => {
352
342
  return (!!backend.endpoints[endpoint.region] && !!backend.endpoints[endpoint.region][endpoint.id]);
353
343
  };
@@ -105,7 +105,7 @@ function resolveExpression(wantType, expr, params) {
105
105
  }
106
106
  function preprocessLists(wantType, expr, params) {
107
107
  let rv = expr;
108
- const listMatcher = /\[[^\[\]]*\]/g;
108
+ const listMatcher = /\[[^[\]]*\]/g;
109
109
  let match;
110
110
  while ((match = listMatcher.exec(expr)) != null) {
111
111
  const list = match[0];
@@ -1,18 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DockerHelper = exports.ContainerRegistryCleaner = exports.ArtifactRegistryCleaner = void 0;
4
- exports.cleanupBuildImages = cleanupBuildImages;
3
+ exports.DockerHelper = void 0;
5
4
  exports.listGcfPaths = listGcfPaths;
6
5
  exports.deleteGcfArtifacts = deleteGcfArtifacts;
7
- const clc = require("colorette");
8
6
  const error_1 = require("../../error");
9
7
  const api_1 = require("../../api");
10
8
  const logger_1 = require("../../logger");
11
- const artifactregistry = require("../../gcp/artifactregistry");
12
- const backend = require("./backend");
13
9
  const docker = require("../../gcp/docker");
14
- const utils = require("../../utils");
15
- const poller = require("../../operation-poller");
16
10
  async function retry(func) {
17
11
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
18
12
  const MAX_RETRIES = 3;
@@ -36,141 +30,6 @@ async function retry(func) {
36
30
  }
37
31
  }
38
32
  }
39
- async function cleanupBuildImages(haveFunctions, deletedFunctions, cleaners = {}) {
40
- utils.logBullet(clc.bold(clc.cyan("functions: ")) + "cleaning up build files...");
41
- const failedDomains = new Set();
42
- const cleanup = [];
43
- const arCleaner = cleaners.ar || new ArtifactRegistryCleaner();
44
- cleanup.push(...haveFunctions.map(async (func) => {
45
- try {
46
- await arCleaner.cleanupFunction(func);
47
- }
48
- catch (err) {
49
- const path = `${func.project}/${func.region}/gcf-artifacts`;
50
- failedDomains.add(`https://console.cloud.google.com/artifacts/docker/${path}`);
51
- }
52
- }));
53
- cleanup.push(...deletedFunctions.map(async (func) => {
54
- try {
55
- await arCleaner.cleanupFunction(func);
56
- }
57
- catch (err) {
58
- const path = `${func.project}/${func.region}/gcf-artifacts`;
59
- failedDomains.add(`https://console.cloud.google.com/artifacts/docker/${path}`);
60
- }
61
- }));
62
- const gcrCleaner = cleaners.gcr || new ContainerRegistryCleaner();
63
- cleanup.push(...[...haveFunctions, ...deletedFunctions].map(async (func) => {
64
- try {
65
- await gcrCleaner.cleanupFunction(func);
66
- }
67
- catch (err) {
68
- const path = `${func.project}/${docker.GCR_SUBDOMAIN_MAPPING[func.region]}/gcf`;
69
- failedDomains.add(`https://console.cloud.google.com/gcr/images/${path}`);
70
- }
71
- }));
72
- await Promise.all(cleanup);
73
- if (failedDomains.size) {
74
- let message = "Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. ";
75
- message +=
76
- "You can attempt to delete these images by redeploying or you can delete them manually at";
77
- if (failedDomains.size === 1) {
78
- message += " " + failedDomains.values().next().value;
79
- }
80
- else {
81
- message += [...failedDomains].map((domain) => "\n\t" + domain).join("");
82
- }
83
- utils.logLabeledWarning("functions", message);
84
- }
85
- }
86
- class ArtifactRegistryCleaner {
87
- static packagePath(func) {
88
- const encodedId = func.platform === "gcfv2"
89
- ? ArtifactRegistryCleaner.encodePackageNameV2(func)
90
- : ArtifactRegistryCleaner.encodePackageNameV1(func);
91
- return `projects/${func.project}/locations/${func.region}/repositories/gcf-artifacts/packages/${encodedId}`;
92
- }
93
- static encodePart(part) {
94
- return part
95
- .replace(/_/g, "__")
96
- .replace(/-/g, "--")
97
- .replace(/^[A-Z]/, (first) => `${first.toLowerCase()}-${first.toLowerCase()}`)
98
- .replace(/[A-Z]/g, (upper) => `_${upper.toLowerCase()}`);
99
- }
100
- static encodePackageNameV1(func) {
101
- return ArtifactRegistryCleaner.encodePart(func.id);
102
- }
103
- static encodePackageNameV2(func) {
104
- return [
105
- ArtifactRegistryCleaner.encodePart(func.project),
106
- ArtifactRegistryCleaner.encodePart(func.region),
107
- ArtifactRegistryCleaner.encodePart(func.id),
108
- ].join("__");
109
- }
110
- async cleanupFunction(func) {
111
- let op;
112
- try {
113
- op = await artifactregistry.deletePackage(ArtifactRegistryCleaner.packagePath(func));
114
- }
115
- catch (err) {
116
- if (err.status === 404) {
117
- return;
118
- }
119
- throw err;
120
- }
121
- if (op.done) {
122
- return;
123
- }
124
- await poller.pollOperation({
125
- ...ArtifactRegistryCleaner.POLLER_OPTIONS,
126
- pollerName: `cleanup-${func.region}-${func.id}`,
127
- operationResourceName: op.name,
128
- });
129
- }
130
- }
131
- exports.ArtifactRegistryCleaner = ArtifactRegistryCleaner;
132
- ArtifactRegistryCleaner.POLLER_OPTIONS = {
133
- apiOrigin: (0, api_1.artifactRegistryDomain)(),
134
- apiVersion: artifactregistry.API_VERSION,
135
- masterTimeout: 5 * 60 * 1000,
136
- };
137
- class ContainerRegistryCleaner {
138
- constructor() {
139
- this.helpers = {};
140
- }
141
- helper(location) {
142
- const subdomain = docker.GCR_SUBDOMAIN_MAPPING[location] || "us";
143
- if (!this.helpers[subdomain]) {
144
- const origin = `https://${subdomain}.${(0, api_1.containerRegistryDomain)()}`;
145
- this.helpers[subdomain] = new DockerHelper(origin);
146
- }
147
- return this.helpers[subdomain];
148
- }
149
- async cleanupFunction(func) {
150
- const helper = this.helper(func.region);
151
- const uuids = (await helper.ls(`${func.project}/gcf/${func.region}`)).children;
152
- const uuidTags = {};
153
- const loadUuidTags = [];
154
- for (const uuid of uuids) {
155
- loadUuidTags.push((async () => {
156
- const path = `${func.project}/gcf/${func.region}/${uuid}`;
157
- const tags = (await helper.ls(path)).tags;
158
- uuidTags[path] = tags;
159
- })());
160
- }
161
- await Promise.all(loadUuidTags);
162
- const extractFunction = /^(.*)_version-\d+$/;
163
- const entry = Object.entries(uuidTags).find(([, tags]) => {
164
- return tags.find((tag) => extractFunction.exec(tag)?.[1] === func.id);
165
- });
166
- if (!entry) {
167
- logger_1.logger.debug("Could not find image for function", backend.functionName(func));
168
- return;
169
- }
170
- await helper.rm(entry[0]);
171
- }
172
- }
173
- exports.ContainerRegistryCleaner = ContainerRegistryCleaner;
174
33
  function getHelper(cache, subdomain) {
175
34
  if (!cache[subdomain]) {
176
35
  cache[subdomain] = new DockerHelper(`https://${subdomain}.${(0, api_1.containerRegistryDomain)()}`);
@@ -11,7 +11,6 @@ exports.generationDowngradeMessage = generationDowngradeMessage;
11
11
  exports.targetCodebases = targetCodebases;
12
12
  exports.groupEndpointsByCodebase = groupEndpointsByCodebase;
13
13
  exports.isCodebaseFiltered = isCodebaseFiltered;
14
- exports.isEndpointFiltered = isEndpointFiltered;
15
14
  exports.isCodebasePartiallyFiltered = isCodebasePartiallyFiltered;
16
15
  exports.parseDeleteFilters = parseDeleteFilters;
17
16
  exports.detectCodebaseAndIdCollisions = detectCodebaseAndIdCollisions;
@@ -148,9 +147,6 @@ function isCodebaseFiltered(codebase, filters) {
148
147
  return noIdChunks && filter.codebase === codebase;
149
148
  });
150
149
  }
151
- function isEndpointFiltered(endpoint, filters) {
152
- return filters.some((filter) => endpointMatchesFilter(endpoint, filter));
153
- }
154
150
  function isCodebasePartiallyFiltered(codebase, filters) {
155
151
  if (!filters) {
156
152
  return false;