firebase-tools 15.34.1 → 15.35.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 (73) hide show
  1. package/lib/api.js +2 -4
  2. package/lib/apphosting/constants.js +1 -4
  3. package/lib/apphosting/utils.js +0 -26
  4. package/lib/commands/apps-android-sha-create.js +1 -1
  5. package/lib/commands/apps-android-sha-delete.js +1 -1
  6. package/lib/commands/apps-android-sha-list.js +1 -1
  7. package/lib/commands/{crashlytics-onboard-web.js → crashlytics-setup.js} +5 -5
  8. package/lib/commands/crashlytics-sourcemap-upload.js +4 -0
  9. package/lib/commands/emulators-start.js +2 -2
  10. package/lib/commands/index.js +5 -6
  11. package/lib/commands/run-services-get.js +19 -0
  12. package/lib/commands/run-services-list.js +11 -0
  13. package/lib/crashlytics/alerts.js +1 -0
  14. package/lib/crashlytics/firebasetelemetry.js +5 -3
  15. package/lib/crashlytics/onboarding.js +15 -23
  16. package/lib/crashlytics/reports.js +46 -17
  17. package/lib/crashlytics/sourcemap.js +19 -5
  18. package/lib/dataconnect/dataplaneClient.js +0 -10
  19. package/lib/deploy/apphosting/deploy.js +20 -41
  20. package/lib/deploy/apphosting/localBuild.js +49 -0
  21. package/lib/deploy/apphosting/prepare.js +12 -25
  22. package/lib/deploy/apphosting/release.js +1 -1
  23. package/lib/deploy/apphosting/util.js +27 -4
  24. package/lib/deploy/functions/containerCleaner.js +1 -142
  25. package/lib/deploy/functions/functionsDeployHelper.js +0 -4
  26. package/lib/deploy/functions/release/fabricator.js +6 -3
  27. package/lib/deploy/functions/validate.js +1 -1
  28. package/lib/deploy/run/deploy.js +26 -43
  29. package/lib/deploy/run/get.js +30 -0
  30. package/lib/deploy/run/list.js +38 -0
  31. package/lib/deploy/run/prereqs.js +0 -3
  32. package/lib/deploy/run/util.js +9 -0
  33. package/lib/emulator/commandUtils.js +105 -23
  34. package/lib/emulator/dataconnect/pgliteServer.js +1 -0
  35. package/lib/emulator/downloadableEmulatorInfo.json +22 -22
  36. package/lib/emulator/downloadableEmulators.js +43 -5
  37. package/lib/emulator/firestoreEmulator.js +5 -0
  38. package/lib/emulator/functionsEmulator.js +22 -7
  39. package/lib/emulator/pubsubEmulator.js +64 -11
  40. package/lib/emulator/storage/rules/manager.js +31 -15
  41. package/lib/emulator/storage/rules/runtime.js +1 -0
  42. package/lib/emulator/taskQueue.js +5 -4
  43. package/lib/experiments.js +0 -5
  44. package/lib/extensions/emulator/specHelper.js +0 -4
  45. package/lib/extensions/extensionsApi.js +0 -8
  46. package/lib/extensions/extensionsHelper.js +1 -71
  47. package/lib/extensions/runtimes/common.js +0 -12
  48. package/lib/extensions/secretsUtils.js +0 -24
  49. package/lib/extensions/updateHelper.js +2 -88
  50. package/lib/frameworks/angular/utils.js +3 -2
  51. package/lib/frameworks/next/utils.js +0 -11
  52. package/lib/fsAsync.js +34 -20
  53. package/lib/functions/kits/install.js +37 -337
  54. package/lib/functions/kits/sources/directory.js +59 -0
  55. package/lib/functions/kits/sources/index.js +19 -0
  56. package/lib/functions/kits/sources/npm.js +274 -0
  57. package/lib/functions/kits/sources/types.js +12 -0
  58. package/lib/gcp/artifactregistry.js +0 -5
  59. package/lib/gcp/cloudlogging.js +0 -54
  60. package/lib/gcp/iam.js +0 -4
  61. package/lib/gcp/pubsub.js +0 -14
  62. package/lib/gcp/storage.js +2 -1
  63. package/lib/init/features/aitools/promptUpdater.js +3 -2
  64. package/lib/init/features/run.js +3 -7
  65. package/lib/mcp/errors.js +1 -1
  66. package/lib/mcp/resources/guides/crashlytics_reports.js +33 -71
  67. package/lib/mcp/tools/crashlytics/reports.js +25 -30
  68. package/lib/mcp/util/dataconnect/converter.js +0 -29
  69. package/lib/tsconfig.compile.tsbuildinfo +1 -1
  70. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  71. package/package.json +9 -6
  72. package/lib/apphosting/repo.js +0 -243
  73. package/lib/deploy/hosting/args.js +0 -2
@@ -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
- this._watcher = chokidar
34
- .watch(rulesFile, { persistent: true, ignoreInitial: true })
35
- .on("change", async () => {
36
- await new Promise((res) => setTimeout(res, 5));
37
- try {
38
- const content = (0, fsutils_1.readFile)(rulesFile);
39
- this._rules.content = content;
40
- this._logger.logLabeled("BULLET", "storage", "Change detected, updating rules for Cloud Storage...");
41
- await this.loadRuleset();
42
- }
43
- catch (e) {
44
- const message = e instanceof Error ? e.message : String(e);
45
- this._logger.logLabeled("DEBUG", "storage", `A rule file change was detected, but there was an error reading it: ${message}`);
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() {
@@ -93,6 +93,7 @@ class StorageRulesRuntime {
93
93
  const command = (0, downloadableEmulators_1._getCommand)(types_2.Emulators.STORAGE, {});
94
94
  this._childprocess = (0, cross_spawn_1.spawn)(command.binary, command.args, {
95
95
  stdio: ["pipe", "pipe", "pipe"],
96
+ windowsHide: true,
96
97
  });
97
98
  this._childprocess.on("exit", () => {
98
99
  this._alive = false;
@@ -179,10 +179,10 @@ class TaskQueue {
179
179
  }
180
180
  }
181
181
  async runTask(dispatchIndex) {
182
- if (this.dispatches[dispatchIndex] === null) {
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
- if (this.dispatches[dispatchIndex] === null) {
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 } = this.dispatches[dispatchIndex];
244
+ const { metadata } = task;
244
245
  const { retryConfig } = this.config;
245
246
  if (this.shouldStopRetrying(metadata, retryConfig)) {
246
247
  metadata.status = TaskStatus.FAILED;
@@ -197,11 +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
200
  crashlyticsWebBreadcrumbs: {
206
201
  shortDescription: "Enable provisioning Cloud Trace storage during web app onboarding.",
207
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) {
@@ -9,7 +9,6 @@ exports.updateInstance = updateInstance;
9
9
  exports.updateInstanceFromRegistry = updateInstanceFromRegistry;
10
10
  exports.populateSpec = populateSpec;
11
11
  exports.createSource = createSource;
12
- exports.getSource = getSource;
13
12
  exports.getExtensionVersion = getExtensionVersion;
14
13
  exports.listExtensions = listExtensions;
15
14
  exports.listExtensionVersions = listExtensionVersions;
@@ -263,13 +262,6 @@ async function createSource(projectId, packageUri, extensionRoot) {
263
262
  }
264
263
  return pollRes;
265
264
  }
266
- async function getSource(sourceName) {
267
- const res = await extensionsApiClient.get(`/${sourceName}`);
268
- if (res.body.spec) {
269
- populateSpec(res.body.spec);
270
- }
271
- return res.body;
272
- }
273
265
  async function getExtensionVersion(extensionVersionRef) {
274
266
  const ref = refs.parse(extensionVersionRef);
275
267
  if (!ref.version) {
@@ -1,17 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resourceTypeToNiceName = exports.AUTOPOPULATED_PARAM_PLACEHOLDERS = exports.EXTENSIONS_BUCKET_NAME = exports.URL_REGEX = exports.logPrefix = exports.SourceOrigin = exports.SpecParamType = void 0;
3
+ exports.resourceTypeToNiceName = exports.AUTOPOPULATED_PARAM_PLACEHOLDERS = exports.EXTENSIONS_BUCKET_NAME = exports.logPrefix = exports.SourceOrigin = exports.SpecParamType = void 0;
4
4
  exports.getDBInstanceFromURL = getDBInstanceFromURL;
5
5
  exports.getFirebaseProjectParams = getFirebaseProjectParams;
6
6
  exports.substituteParams = substituteParams;
7
7
  exports.substituteSecretParams = substituteSecretParams;
8
8
  exports.populateDefaultParams = populateDefaultParams;
9
- exports.validateCommandLineParams = validateCommandLineParams;
10
9
  exports.validateSpec = validateSpec;
11
10
  exports.promptForValidInstanceId = promptForValidInstanceId;
12
11
  exports.promptForValidRepoURI = promptForValidRepoURI;
13
12
  exports.promptForExtensionRoot = promptForExtensionRoot;
14
- exports.checkExtensionsApiEnabled = checkExtensionsApiEnabled;
15
13
  exports.ensureExtensionsApiEnabled = ensureExtensionsApiEnabled;
16
14
  exports.ensureExtensionsPublisherApiEnabled = ensureExtensionsPublisherApiEnabled;
17
15
  exports.getNextVersionByStage = getNextVersionByStage;
@@ -22,8 +20,6 @@ exports.getMissingPublisherError = getMissingPublisherError;
22
20
  exports.createSourceFromLocation = createSourceFromLocation;
23
21
  exports.getPublisherProjectFromName = getPublisherProjectFromName;
24
22
  exports.displayReleaseNotes = displayReleaseNotes;
25
- exports.promptForRepeatInstance = promptForRepeatInstance;
26
- exports.instanceIdExists = instanceIdExists;
27
23
  exports.isUrlPath = isUrlPath;
28
24
  exports.isLocalPath = isLocalPath;
29
25
  exports.isLocalOrURLPath = isLocalOrURLPath;
@@ -47,7 +43,6 @@ const functionsConfig_1 = require("../functionsConfig");
47
43
  const adminSdkConfig_1 = require("../emulator/adminSdkConfig");
48
44
  const error_1 = require("../error");
49
45
  const diagnose_1 = require("./diagnose");
50
- const askUserForParam_1 = require("./askUserForParam");
51
46
  const ensureApiEnabled_1 = require("../ensureApiEnabled");
52
47
  const storage_1 = require("../gcp/storage");
53
48
  const projectUtils_1 = require("../projectUtils");
@@ -80,15 +75,7 @@ var SourceOrigin;
80
75
  })(SourceOrigin || (exports.SourceOrigin = SourceOrigin = {}));
81
76
  exports.logPrefix = "extensions";
82
77
  const VALID_LICENSES = ["apache-2.0"];
83
- exports.URL_REGEX = /^https:/;
84
78
  exports.EXTENSIONS_BUCKET_NAME = (0, utils_1.envOverride)("FIREBASE_EXTENSIONS_UPLOAD_BUCKET", "firebase-ext-eap-uploads");
85
- const AUTOPOPULATED_PARAM_NAMES = [
86
- "PROJECT_ID",
87
- "STORAGE_BUCKET",
88
- "EXT_INSTANCE_ID",
89
- "DATABASE_INSTANCE",
90
- "DATABASE_URL",
91
- ];
92
79
  exports.AUTOPOPULATED_PARAM_PLACEHOLDERS = {
93
80
  PROJECT_ID: "project-id",
94
81
  STORAGE_BUCKET: "project-id.appspot.com",
@@ -185,25 +172,6 @@ function populateDefaultParams(paramVars, paramSpecs) {
185
172
  }
186
173
  return newParams;
187
174
  }
188
- function validateCommandLineParams(envVars, paramSpec) {
189
- const paramNames = paramSpec.map((p) => p.param);
190
- const misnamedParams = Object.keys(envVars).filter((key) => {
191
- return !paramNames.includes(key) && !AUTOPOPULATED_PARAM_NAMES.includes(key);
192
- });
193
- if (misnamedParams.length) {
194
- logger_1.logger.warn("Warning: The following params were specified in your env file but do not exist in the extension spec: " +
195
- `${misnamedParams.join(", ")}.`);
196
- }
197
- let allParamsValid = true;
198
- for (const param of paramSpec) {
199
- if (!(0, askUserForParam_1.checkResponse)(envVars[param.param], param)) {
200
- allParamsValid = false;
201
- }
202
- }
203
- if (!allParamsValid) {
204
- throw new error_1.FirebaseError(`Some param values are not valid. Please check your params file.`);
205
- }
206
- }
207
175
  function validateSpec(spec) {
208
176
  const errors = [];
209
177
  if (!spec.name) {
@@ -377,13 +345,6 @@ async function promptForReleaseStage(args) {
377
345
  }
378
346
  return stage;
379
347
  }
380
- async function checkExtensionsApiEnabled(options) {
381
- const projectId = (0, projectUtils_1.getProjectId)(options);
382
- if (!projectId) {
383
- return false;
384
- }
385
- return await (0, ensureApiEnabled_1.check)(projectId, (0, api_1.extensionsOrigin)(), "extensions", options.markdown);
386
- }
387
348
  async function ensureExtensionsApiEnabled(options) {
388
349
  const projectId = (0, projectUtils_1.getProjectId)(options);
389
350
  if (!projectId) {
@@ -788,37 +749,6 @@ function displayReleaseNotes(args) {
788
749
  `Once an extension version is uploaded, it becomes installable by other users and cannot be changed. If you wish to make changes after uploading, you will need to upload a new version.\n`;
789
750
  logger_1.logger.info(message);
790
751
  }
791
- async function promptForRepeatInstance(projectName, extensionName) {
792
- const message = `An extension with the ID '${clc.bold(extensionName)}' already exists in the project '${clc.bold(projectName)}'. What would you like to do?`;
793
- return await (0, prompt_1.select)({
794
- message,
795
- choices: [
796
- { name: "Update or reconfigure the existing instance", value: "updateExisting" },
797
- { name: "Install a new instance with a different ID", value: "installNew" },
798
- { name: "Cancel extension installation", value: "cancel" },
799
- ],
800
- });
801
- }
802
- async function instanceIdExists(projectId, instanceId) {
803
- try {
804
- await (0, extensionsApi_1.getInstance)(projectId, instanceId);
805
- }
806
- catch (err) {
807
- if (err instanceof error_1.FirebaseError) {
808
- if (err.status === 404) {
809
- return false;
810
- }
811
- const msg = `Unexpected error when checking if instance ID exists: ${err.message}`;
812
- throw new error_1.FirebaseError(msg, {
813
- original: err,
814
- });
815
- }
816
- else {
817
- throw err;
818
- }
819
- }
820
- return true;
821
- }
822
752
  function isUrlPath(extInstallPath) {
823
753
  return extInstallPath.startsWith("https:");
824
754
  }
@@ -11,9 +11,7 @@ exports.writeSDK = writeSDK;
11
11
  exports.getCodebaseDir = getCodebaseDir;
12
12
  exports.getInstallPathPrefix = getInstallPathPrefix;
13
13
  exports.toTitleCase = toTitleCase;
14
- exports.capitalizeFirstLetter = capitalizeFirstLetter;
15
14
  exports.lowercaseFirstLetter = lowercaseFirstLetter;
16
- exports.snakeToCamelCase = snakeToCamelCase;
17
15
  exports.longestCommonPrefix = longestCommonPrefix;
18
16
  const fs = require("fs");
19
17
  const path = require("path");
@@ -186,19 +184,9 @@ function getInstallPathPrefix(options) {
186
184
  function toTitleCase(txt) {
187
185
  return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
188
186
  }
189
- function capitalizeFirstLetter(txt) {
190
- return txt.charAt(0).toUpperCase() + txt.substring(1);
191
- }
192
187
  function lowercaseFirstLetter(txt) {
193
188
  return txt.charAt(0).toLowerCase() + txt.substring(1);
194
189
  }
195
- function snakeToCamelCase(txt) {
196
- let ret = txt.toLowerCase();
197
- ret = ret.replace(/_/g, " ");
198
- ret = ret.replace(/\w\S*/g, toTitleCase);
199
- ret = ret.charAt(0).toLowerCase() + ret.substring(1);
200
- return ret;
201
- }
202
190
  function longestCommonPrefix(arr) {
203
191
  if (arr.length === 0) {
204
192
  return "";
@@ -4,17 +4,14 @@ exports.SECRET_ROLE = exports.SECRET_LABEL = void 0;
4
4
  exports.ensureSecretManagerApiEnabled = ensureSecretManagerApiEnabled;
5
5
  exports.usesSecrets = usesSecrets;
6
6
  exports.grantFirexServiceAgentSecretAdminRole = grantFirexServiceAgentSecretAdminRole;
7
- exports.getManagedSecrets = getManagedSecrets;
8
7
  exports.getActiveSecrets = getActiveSecrets;
9
8
  exports.getSecretLabels = getSecretLabels;
10
- exports.prettySecretName = prettySecretName;
11
9
  const getProjectNumber_1 = require("../getProjectNumber");
12
10
  const utils = require("../utils");
13
11
  const ensureApiEnabled_1 = require("../ensureApiEnabled");
14
12
  const projectUtils_1 = require("../projectUtils");
15
13
  const types_1 = require("./types");
16
14
  const secretManagerApi = require("../gcp/secretManager");
17
- const logger_1 = require("../logger");
18
15
  const api_1 = require("../api");
19
16
  exports.SECRET_LABEL = "firebase-extensions-managed";
20
17
  exports.SECRET_ROLE = "secretmanager.secretAccessor";
@@ -31,19 +28,6 @@ async function grantFirexServiceAgentSecretAdminRole(secret) {
31
28
  const saEmail = `service-${projectNumber}@${firexSaProjectId}.iam.gserviceaccount.com`;
32
29
  return secretManagerApi.ensureServiceAgentRole(secret, [saEmail], "roles/secretmanager.admin");
33
30
  }
34
- async function getManagedSecrets(instance) {
35
- if (!instance.config?.source?.spec) {
36
- return [];
37
- }
38
- return (await Promise.all(getActiveSecrets(instance.config.source.spec, instance.config.params).map(async (secretResourceName) => {
39
- const secret = secretManagerApi.parseSecretResourceName(secretResourceName);
40
- const labels = (await secretManagerApi.getSecret(secret.projectId, secret.name)).labels;
41
- if (labels && labels[exports.SECRET_LABEL]) {
42
- return secretResourceName;
43
- }
44
- return Promise.resolve("");
45
- }))).filter((secretId) => !!secretId);
46
- }
47
31
  function getActiveSecrets(spec, params) {
48
32
  return spec.params
49
33
  .map((p) => (p.type === types_1.ParamType.SECRET ? params[p.param] : ""))
@@ -54,11 +38,3 @@ function getSecretLabels(instanceId) {
54
38
  labels[exports.SECRET_LABEL] = instanceId;
55
39
  return labels;
56
40
  }
57
- function prettySecretName(secretResourceName) {
58
- const nameTokens = secretResourceName.split("/");
59
- if (nameTokens.length !== 4 && nameTokens.length !== 6) {
60
- logger_1.logger.debug(`unable to parse secret secretResourceName: ${secretResourceName}`);
61
- return secretResourceName;
62
- }
63
- return nameTokens.slice(0, 4).join("/");
64
- }
@@ -1,59 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExistingSourceOrigin = getExistingSourceOrigin;
4
- exports.warningUpdateToOtherSource = warningUpdateToOtherSource;
5
3
  exports.update = update;
6
- exports.updateFromLocalSource = updateFromLocalSource;
7
- exports.updateFromUrlSource = updateFromUrlSource;
8
4
  exports.inferUpdateSource = inferUpdateSource;
9
- const clc = require("colorette");
10
5
  const semver = require("semver");
11
6
  const error_1 = require("../error");
12
- const logger_1 = require("../logger");
13
7
  const extensionsApi = require("./extensionsApi");
14
8
  const extensionsHelper_1 = require("./extensionsHelper");
15
- const utils = require("../utils");
16
- const displayExtensionInfo_1 = require("./displayExtensionInfo");
17
- function invalidSourceErrMsgTemplate(instanceId, source) {
18
- return `Unable to update from the source \`${clc.bold(source)}\`. To update this instance, you can either:\n
19
- - Run \`${clc.bold("firebase ext:update " + instanceId)}\` to update from the published source.\n
20
- - Check your directory path or URL, then run \`${clc.bold("firebase ext:update " + instanceId + " <otherSource>")}\` to update from a local directory or URL source.`;
21
- }
22
- async function getExistingSourceOrigin(projectId, instanceId) {
23
- const instance = await extensionsApi.getInstance(projectId, instanceId);
24
- return instance && instance.config.extensionRef
25
- ? extensionsHelper_1.SourceOrigin.PUBLISHED_EXTENSION
26
- : extensionsHelper_1.SourceOrigin.LOCAL;
27
- }
28
- function showUpdateVersionInfo(instanceId, from, to, source) {
29
- if (source) {
30
- source = clc.bold(source);
31
- }
32
- else {
33
- source = "version";
34
- }
35
- utils.logLabeledBullet(extensionsHelper_1.logPrefix, `Updating ${clc.bold(instanceId)} from version ${clc.bold(from)} to ${source} (${clc.bold(to)})`);
36
- if (semver.lt(to, from)) {
37
- utils.logLabeledWarning(extensionsHelper_1.logPrefix, "The version you are updating to is less than the current version for this extension. This extension may not be backwards compatible.");
38
- }
39
- return;
40
- }
41
- function warningUpdateToOtherSource(sourceOrigin) {
42
- let targetText;
43
- if ([extensionsHelper_1.SourceOrigin.PUBLISHED_EXTENSION, extensionsHelper_1.SourceOrigin.PUBLISHED_EXTENSION_VERSION].includes(sourceOrigin)) {
44
- targetText = "published extension";
45
- }
46
- else if (sourceOrigin === extensionsHelper_1.SourceOrigin.LOCAL) {
47
- targetText = "local directory";
48
- }
49
- else if (sourceOrigin === extensionsHelper_1.SourceOrigin.URL) {
50
- targetText = "URL";
51
- }
52
- const warning = `All the instance's resources and logic will be overwritten to use the source code and files from the ${targetText}.\n`;
53
- logger_1.logger.info(warning);
54
- }
55
9
  async function update(updateOptions) {
56
- const { projectId, instanceId, source, extRef, params, systemParams, canEmitEvents, allowedEventTypes, eventarcChannel, } = updateOptions;
10
+ const { projectId, instanceId, extRef, params, systemParams, canEmitEvents, allowedEventTypes, eventarcChannel, } = updateOptions;
57
11
  if (extRef) {
58
12
  return await extensionsApi.updateInstanceFromRegistry({
59
13
  projectId,
@@ -66,47 +20,7 @@ async function update(updateOptions) {
66
20
  eventarcChannel,
67
21
  });
68
22
  }
69
- else if (source) {
70
- return await extensionsApi.updateInstance({
71
- projectId,
72
- instanceId,
73
- extensionSource: source,
74
- params,
75
- systemParams,
76
- canEmitEvents,
77
- allowedEventTypes,
78
- eventarcChannel,
79
- });
80
- }
81
- throw new error_1.FirebaseError(`Neither a source nor a version of the extension was supplied for ${instanceId}. Please make sure this is a valid extension and try again.`);
82
- }
83
- async function updateFromLocalSource(projectId, instanceId, localSource, existingSpec) {
84
- await (0, displayExtensionInfo_1.displayExtensionVersionInfo)({ spec: existingSpec });
85
- let source;
86
- try {
87
- source = await (0, extensionsHelper_1.createSourceFromLocation)(projectId, localSource);
88
- }
89
- catch (err) {
90
- throw new error_1.FirebaseError(invalidSourceErrMsgTemplate(instanceId, localSource));
91
- }
92
- utils.logLabeledBullet(extensionsHelper_1.logPrefix, `${clc.bold("You are updating this extension instance to a local source.")}`);
93
- showUpdateVersionInfo(instanceId, existingSpec.version, source.spec.version, localSource);
94
- warningUpdateToOtherSource(extensionsHelper_1.SourceOrigin.LOCAL);
95
- return source.name;
96
- }
97
- async function updateFromUrlSource(projectId, instanceId, urlSource, existingSpec) {
98
- await (0, displayExtensionInfo_1.displayExtensionVersionInfo)({ spec: existingSpec });
99
- let source;
100
- try {
101
- source = await (0, extensionsHelper_1.createSourceFromLocation)(projectId, urlSource);
102
- }
103
- catch (err) {
104
- throw new error_1.FirebaseError(invalidSourceErrMsgTemplate(instanceId, urlSource));
105
- }
106
- utils.logLabeledBullet(extensionsHelper_1.logPrefix, `${clc.bold("You are updating this extension instance to a URL source.")}`);
107
- showUpdateVersionInfo(instanceId, existingSpec.version, source.spec.version, urlSource);
108
- warningUpdateToOtherSource(extensionsHelper_1.SourceOrigin.URL);
109
- return source.name;
23
+ throw new error_1.FirebaseError(`A version of the extension was not supplied for ${instanceId}. Please make sure this is a valid extension and try again.`);
110
24
  }
111
25
  function inferUpdateSource(updateSource, existingRef) {
112
26
  if (!updateSource) {
@@ -207,9 +207,10 @@ async function getContext(dir, targetOrConfiguration) {
207
207
  }
208
208
  }
209
209
  if (deployTarget) {
210
+ const target = deployTarget;
210
211
  const options = await architectHost
211
- .getOptionsForTarget(deployTarget)
212
- .catch(() => workspaceProject.targets.get(deployTarget.target)?.options);
212
+ .getOptionsForTarget(target)
213
+ .catch(() => workspaceProject.targets.get(target.target)?.options);
213
214
  if (!options)
214
215
  throw new error_1.FirebaseError("Unable to get options for ng-deploy.");
215
216
  if (options.buildTarget) {
@@ -8,9 +8,7 @@ exports.isRewriteSupportedByHosting = isRewriteSupportedByHosting;
8
8
  exports.isRedirectSupportedByHosting = isRedirectSupportedByHosting;
9
9
  exports.isHeaderSupportedByHosting = isHeaderSupportedByHosting;
10
10
  exports.getNextjsRewritesToUse = getNextjsRewritesToUse;
11
- exports.usesAppDirRouter = usesAppDirRouter;
12
11
  exports.usesNextImage = usesNextImage;
13
- exports.hasUnoptimizedImage = hasUnoptimizedImage;
14
12
  exports.isUsingMiddleware = isUsingMiddleware;
15
13
  exports.isUsingImageOptimization = isUsingImageOptimization;
16
14
  exports.isUsingNextImageInAppDirectory = isUsingNextImageInAppDirectory;
@@ -34,7 +32,6 @@ exports.findEsbuildPath = findEsbuildPath;
34
32
  exports.getGlobalEsbuildVersion = getGlobalEsbuildVersion;
35
33
  exports.installEsbuild = installEsbuild;
36
34
  exports.isNextJsVersionVulnerable = isNextJsVersionVulnerable;
37
- const fs_1 = require("fs");
38
35
  const fs_extra_1 = require("fs-extra");
39
36
  const path_1 = require("path");
40
37
  const promises_1 = require("fs/promises");
@@ -92,18 +89,10 @@ function getNextjsRewritesToUse(nextJsRewrites) {
92
89
  }
93
90
  return [];
94
91
  }
95
- function usesAppDirRouter(sourceDir) {
96
- const appPathRoutesManifestPath = (0, path_1.join)(sourceDir, constants_1.APP_PATH_ROUTES_MANIFEST);
97
- return (0, fs_1.existsSync)(appPathRoutesManifestPath);
98
- }
99
92
  async function usesNextImage(sourceDir, distDir) {
100
93
  const exportMarker = await (0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, constants_1.EXPORT_MARKER));
101
94
  return exportMarker.isNextImageImported;
102
95
  }
103
- async function hasUnoptimizedImage(sourceDir, distDir) {
104
- const imagesManifest = await (0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, constants_1.IMAGES_MANIFEST));
105
- return imagesManifest.images.unoptimized;
106
- }
107
96
  async function isUsingMiddleware(dir, isDevMode) {
108
97
  if (isDevMode) {
109
98
  const middlewareFiles = await Promise.all([
package/lib/fsAsync.js CHANGED
@@ -6,31 +6,42 @@ const ignore_1 = require("ignore");
6
6
  const _ = require("lodash");
7
7
  const minimatch = require("minimatch");
8
8
  const path_1 = require("path");
9
- const logger_1 = require("./logger");
9
+ const error_1 = require("./error");
10
+ function readGitIgnore(dirPath) {
11
+ const gitIgnorePath = (0, path_1.join)(dirPath, ".gitignore");
12
+ try {
13
+ const lines = (0, fs_extra_1.readFileSync)(gitIgnorePath)
14
+ .toString()
15
+ .split("\n")
16
+ .map((line) => line.trim())
17
+ .filter((line) => !line.startsWith("#") && line !== "");
18
+ return { dirPath, ignore: (0, ignore_1.default)().add(lines) };
19
+ }
20
+ catch (err) {
21
+ throw new error_1.FirebaseError(`Could not read ${gitIgnorePath}: ${(0, error_1.getErrMsg)(err)}`, {
22
+ original: (0, error_1.getError)(err),
23
+ });
24
+ }
25
+ }
26
+ function parentGitIgnores(root, dir) {
27
+ const folders = (0, path_1.relative)(root, dir).split(path_1.sep).filter(Boolean);
28
+ const states = [];
29
+ for (let depth = 0; depth < folders.length; depth++) {
30
+ const ancestor = (0, path_1.join)(root, ...folders.slice(0, depth));
31
+ const gitIgnorePath = (0, path_1.join)(ancestor, ".gitignore");
32
+ if (!(0, fs_extra_1.existsSync)(gitIgnorePath) || !(0, fs_extra_1.statSync)(gitIgnorePath).isFile()) {
33
+ continue;
34
+ }
35
+ states.push(readGitIgnore(ancestor));
36
+ }
37
+ return states;
38
+ }
10
39
  async function readdirRecursiveHelper(options) {
11
40
  const dirContents = (0, fs_extra_1.readdirSync)(options.path, { withFileTypes: true });
12
41
  let currentGitIgnoreStack = options.gitIgnoreStack || [];
13
42
  if (options.supportGitIgnore) {
14
43
  if (dirContents.find((n) => n.name === ".gitignore")?.isFile()) {
15
- const localGitIgnore = (0, path_1.join)(options.path, ".gitignore");
16
- try {
17
- const lines = (0, fs_extra_1.readFileSync)(localGitIgnore)
18
- .toString()
19
- .split("\n")
20
- .map((line) => line.trim())
21
- .filter((line) => !line.startsWith("#") && line !== "");
22
- const subIgnore = (0, ignore_1.default)().add(lines);
23
- currentGitIgnoreStack = [
24
- ...currentGitIgnoreStack,
25
- {
26
- dirPath: options.path,
27
- ignore: subIgnore,
28
- },
29
- ];
30
- }
31
- catch (e) {
32
- logger_1.logger.debug(`Error reading .gitignore file at ${localGitIgnore}:`, e);
33
- }
44
+ currentGitIgnoreStack = [...currentGitIgnoreStack, readGitIgnore(options.path)];
34
45
  }
35
46
  }
36
47
  const fullPaths = dirContents
@@ -91,6 +102,9 @@ async function readdirRecursive(options) {
91
102
  dirPath: options.path,
92
103
  ignore: (0, ignore_1.default)().add(options.ignoreStrings || []),
93
104
  });
105
+ if (options.gitIgnoreRoot) {
106
+ initialGitIgnoreStack.push(...parentGitIgnores(options.gitIgnoreRoot, options.path));
107
+ }
94
108
  }
95
109
  const maxDepth = options.maxDepth && options.maxDepth > 0 ? options.maxDepth : Infinity;
96
110
  return await readdirRecursiveHelper({