firebase-tools-with-isolate 13.0.2 → 13.2.1-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 (38) hide show
  1. package/README.md +6 -2
  2. package/lib/appdistribution/client.js +36 -28
  3. package/lib/appdistribution/options-parser-util.js +80 -1
  4. package/lib/appdistribution/types.js +31 -0
  5. package/lib/commands/appdistribution-distribute.js +70 -10
  6. package/lib/commands/apphosting-backends-list.js +19 -35
  7. package/lib/commands/apphosting-builds-create.js +4 -4
  8. package/lib/commands/apphosting-rollouts-create.js +2 -2
  9. package/lib/commands/apphosting-rollouts-list.js +4 -1
  10. package/lib/commands/functions-config-export.js +4 -2
  11. package/lib/commands/use.js +4 -1
  12. package/lib/deploy/hosting/convertConfig.js +5 -0
  13. package/lib/deploy/hosting/prepare.js +2 -1
  14. package/lib/emulator/auth/handlers.js +1 -1
  15. package/lib/emulator/auth/operations.js +42 -13
  16. package/lib/emulator/auth/state.js +14 -0
  17. package/lib/emulator/storage/metadata.js +1 -1
  18. package/lib/frameworks/angular/index.js +2 -2
  19. package/lib/frameworks/angular/utils.js +14 -10
  20. package/lib/frameworks/astro/index.js +1 -2
  21. package/lib/frameworks/flutter/index.js +1 -1
  22. package/lib/frameworks/index.js +2 -3
  23. package/lib/frameworks/next/index.js +5 -3
  24. package/lib/frameworks/nuxt/index.js +2 -2
  25. package/lib/frameworks/nuxt2/index.js +1 -2
  26. package/lib/frameworks/sveltekit/index.js +2 -2
  27. package/lib/frameworks/utils.js +11 -2
  28. package/lib/frameworks/vite/index.js +8 -4
  29. package/lib/functions/env.js +2 -0
  30. package/lib/gcp/apphosting.js +102 -16
  31. package/lib/gcp/cloudfunctionsv2.js +2 -4
  32. package/lib/hosting/api.js +3 -9
  33. package/lib/hosting/options.js +2 -1
  34. package/lib/init/features/apphosting/index.js +32 -11
  35. package/lib/init/features/hosting/github.js +1 -1
  36. package/lib/metaprogramming.js +3 -0
  37. package/lib/utils.js +1 -12
  38. package/package.json +7 -7
package/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # Firebase CLI with monorepo support
2
2
 
3
- This is an experimental fork of the [firebase-tools](https://github.com/firebase/firebase-tools) which integrates [isolate-package](https://github.com/0x80/isolate-package/) as part of the functions `deploy` command in order to [support monorepo setups](https://thijs-koerselman.medium.com/deploy-to-firebase-without-the-hacks-e685de39025e).
3
+ This is a fork of the [firebase-tools](https://github.com/firebase/firebase-tools) which integrates [isolate-package](https://github.com/0x80/isolate-package/) as part of the functions `deploy` command in order to [support monorepo setups](https://thijs-koerselman.medium.com/deploy-to-firebase-without-the-hacks-e685de39025e).
4
4
 
5
5
  Alternatively, you can manually configure `isolate` as part of the `predeploy` step of your configuration, but having the process integrated and only running as part of the deploy command is essential if you want to have live code updates when running the Firebase emulators locally during development with a watch task.
6
6
 
7
7
  I suspect it will take some time before the Firebase team would agree to make isolate an integral part of the toolchain and that is why I have published this fork to be available on NPM.
8
8
 
9
- In the meantime I will try to keep this fairly in-sync with updates to the original firebase-tools repository. The published versions of the fork will be kept the same as the original `firebase-tools` package, so you can easily see how up-to-date it is.
9
+ The fork is pretty much identical, and the integration with isolate-package does
10
+ not affect any existing functionality, so I do not think there is a reason to worry
11
+ about things breaking. I will sync the fork with the upstream firebase-tools on
12
+ a regular basis. The fork versions will match the firebase-tools versions for
13
+ clarity.
10
14
 
11
15
  ## Installation
12
16
 
@@ -1,37 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppDistributionClient = exports.UploadReleaseResult = exports.IntegrationState = void 0;
3
+ exports.AppDistributionClient = void 0;
4
4
  const utils = require("../utils");
5
5
  const operationPoller = require("../operation-poller");
6
6
  const error_1 = require("../error");
7
7
  const apiv2_1 = require("../apiv2");
8
8
  const api_1 = require("../api");
9
- var IntegrationState;
10
- (function (IntegrationState) {
11
- IntegrationState["AAB_INTEGRATION_STATE_UNSPECIFIED"] = "AAB_INTEGRATION_STATE_UNSPECIFIED";
12
- IntegrationState["INTEGRATED"] = "INTEGRATED";
13
- IntegrationState["PLAY_ACCOUNT_NOT_LINKED"] = "PLAY_ACCOUNT_NOT_LINKED";
14
- IntegrationState["NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT"] = "NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT";
15
- IntegrationState["APP_NOT_PUBLISHED"] = "APP_NOT_PUBLISHED";
16
- IntegrationState["AAB_STATE_UNAVAILABLE"] = "AAB_STATE_UNAVAILABLE";
17
- IntegrationState["PLAY_IAS_TERMS_NOT_ACCEPTED"] = "PLAY_IAS_TERMS_NOT_ACCEPTED";
18
- })(IntegrationState = exports.IntegrationState || (exports.IntegrationState = {}));
19
- var UploadReleaseResult;
20
- (function (UploadReleaseResult) {
21
- UploadReleaseResult["UPLOAD_RELEASE_RESULT_UNSPECIFIED"] = "UPLOAD_RELEASE_RESULT_UNSPECIFIED";
22
- UploadReleaseResult["RELEASE_CREATED"] = "RELEASE_CREATED";
23
- UploadReleaseResult["RELEASE_UPDATED"] = "RELEASE_UPDATED";
24
- UploadReleaseResult["RELEASE_UNMODIFIED"] = "RELEASE_UNMODIFIED";
25
- })(UploadReleaseResult = exports.UploadReleaseResult || (exports.UploadReleaseResult = {}));
9
+ const types_1 = require("./types");
26
10
  class AppDistributionClient {
27
11
  constructor() {
28
- this.appDistroV2Client = new apiv2_1.Client({
12
+ this.appDistroV1Client = new apiv2_1.Client({
29
13
  urlPrefix: api_1.appDistributionOrigin,
30
14
  apiVersion: "v1",
31
15
  });
16
+ this.appDistroV1AlphaClient = new apiv2_1.Client({
17
+ urlPrefix: api_1.appDistributionOrigin,
18
+ apiVersion: "v1alpha",
19
+ });
32
20
  }
33
21
  async getAabInfo(appName) {
34
- const apiResponse = await this.appDistroV2Client.get(`/${appName}/aabInfo`);
22
+ const apiResponse = await this.appDistroV1Client.get(`/${appName}/aabInfo`);
35
23
  return apiResponse.body;
36
24
  }
37
25
  async uploadRelease(appName, distribution) {
@@ -74,7 +62,7 @@ class AppDistributionClient {
74
62
  };
75
63
  const queryParams = { updateMask: "release_notes.text" };
76
64
  try {
77
- await this.appDistroV2Client.patch(`/${releaseName}`, data, { queryParams });
65
+ await this.appDistroV1Client.patch(`/${releaseName}`, data, { queryParams });
78
66
  }
79
67
  catch (err) {
80
68
  throw new error_1.FirebaseError(`failed to update release notes with ${err?.message}`);
@@ -92,7 +80,7 @@ class AppDistributionClient {
92
80
  groupAliases,
93
81
  };
94
82
  try {
95
- await this.appDistroV2Client.post(`/${releaseName}:distribute`, data);
83
+ await this.appDistroV1Client.post(`/${releaseName}:distribute`, data);
96
84
  }
97
85
  catch (err) {
98
86
  let errorMessage = err.message;
@@ -111,7 +99,7 @@ class AppDistributionClient {
111
99
  }
112
100
  async addTesters(projectName, emails) {
113
101
  try {
114
- await this.appDistroV2Client.request({
102
+ await this.appDistroV1Client.request({
115
103
  method: "POST",
116
104
  path: `${projectName}/testers:batchAdd`,
117
105
  body: { emails: emails },
@@ -125,7 +113,7 @@ class AppDistributionClient {
125
113
  async removeTesters(projectName, emails) {
126
114
  let apiResponse;
127
115
  try {
128
- apiResponse = await this.appDistroV2Client.request({
116
+ apiResponse = await this.appDistroV1Client.request({
129
117
  method: "POST",
130
118
  path: `${projectName}/testers:batchRemove`,
131
119
  body: { emails: emails },
@@ -139,7 +127,7 @@ class AppDistributionClient {
139
127
  async createGroup(projectName, displayName, alias) {
140
128
  let apiResponse;
141
129
  try {
142
- apiResponse = await this.appDistroV2Client.request({
130
+ apiResponse = await this.appDistroV1Client.request({
143
131
  method: "POST",
144
132
  path: alias === undefined ? `${projectName}/groups` : `${projectName}/groups?groupId=${alias}`,
145
133
  body: { displayName: displayName },
@@ -152,7 +140,7 @@ class AppDistributionClient {
152
140
  }
153
141
  async deleteGroup(groupName) {
154
142
  try {
155
- await this.appDistroV2Client.request({
143
+ await this.appDistroV1Client.request({
156
144
  method: "DELETE",
157
145
  path: groupName,
158
146
  });
@@ -164,7 +152,7 @@ class AppDistributionClient {
164
152
  }
165
153
  async addTestersToGroup(groupName, emails) {
166
154
  try {
167
- await this.appDistroV2Client.request({
155
+ await this.appDistroV1Client.request({
168
156
  method: "POST",
169
157
  path: `${groupName}:batchJoin`,
170
158
  body: { emails: emails },
@@ -177,7 +165,7 @@ class AppDistributionClient {
177
165
  }
178
166
  async removeTestersFromGroup(groupName, emails) {
179
167
  try {
180
- await this.appDistroV2Client.request({
168
+ await this.appDistroV1Client.request({
181
169
  method: "POST",
182
170
  path: `${groupName}:batchLeave`,
183
171
  body: { emails: emails },
@@ -188,5 +176,25 @@ class AppDistributionClient {
188
176
  }
189
177
  utils.logSuccess(`Testers removed from group successfully`);
190
178
  }
179
+ async createReleaseTest(releaseName, devices, loginCredential) {
180
+ try {
181
+ const response = await this.appDistroV1AlphaClient.request({
182
+ method: "POST",
183
+ path: `${releaseName}/tests`,
184
+ body: {
185
+ deviceExecutions: devices.map(types_1.mapDeviceToExecution),
186
+ loginCredential,
187
+ },
188
+ });
189
+ return response.body;
190
+ }
191
+ catch (err) {
192
+ throw new error_1.FirebaseError(`Failed to create release test ${err}`);
193
+ }
194
+ }
195
+ async getReleaseTest(releaseTestName) {
196
+ const response = await this.appDistroV1AlphaClient.get(releaseTestName);
197
+ return response.body;
198
+ }
191
199
  }
192
200
  exports.AppDistributionClient = AppDistributionClient;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAppName = exports.getProjectName = exports.ensureFileExists = exports.getEmails = exports.getTestersOrGroups = void 0;
3
+ exports.getLoginCredential = exports.getTestDevices = exports.getAppName = exports.getProjectName = exports.ensureFileExists = exports.getEmails = exports.getTestersOrGroups = void 0;
4
4
  const fs = require("fs-extra");
5
5
  const error_1 = require("../error");
6
6
  const projectUtils_1 = require("../projectUtils");
@@ -49,3 +49,82 @@ function getAppName(options) {
49
49
  return `projects/${appId.split(":")[1]}/apps/${appId}`;
50
50
  }
51
51
  exports.getAppName = getAppName;
52
+ function getTestDevices(value, file) {
53
+ if (!value && file) {
54
+ ensureFileExists(file);
55
+ value = fs.readFileSync(file, "utf8");
56
+ }
57
+ if (!value) {
58
+ return [];
59
+ }
60
+ return value
61
+ .split(/[;\n]/)
62
+ .map((entry) => entry.trim())
63
+ .filter((entry) => !!entry)
64
+ .map((str) => parseTestDevice(str));
65
+ }
66
+ exports.getTestDevices = getTestDevices;
67
+ function parseTestDevice(testDeviceString) {
68
+ const entries = testDeviceString.split(",");
69
+ const allowedKeys = new Set(["model", "version", "orientation", "locale"]);
70
+ let model;
71
+ let version;
72
+ let orientation;
73
+ let locale;
74
+ for (const entry of entries) {
75
+ const keyAndValue = entry.split("=");
76
+ switch (keyAndValue[0]) {
77
+ case "model":
78
+ model = keyAndValue[1];
79
+ break;
80
+ case "version":
81
+ version = keyAndValue[1];
82
+ break;
83
+ case "orientation":
84
+ orientation = keyAndValue[1];
85
+ break;
86
+ case "locale":
87
+ locale = keyAndValue[1];
88
+ break;
89
+ default:
90
+ throw new error_1.FirebaseError(`Unrecognized key in test devices. Can only contain ${Array.from(allowedKeys).join(", ")}`);
91
+ }
92
+ }
93
+ if (!model || !version || !orientation || !locale) {
94
+ throw new error_1.FirebaseError("Test devices must be in the format 'model=<model-id>,version=<os-version-id>,locale=<locale>,orientation=<orientation>'");
95
+ }
96
+ return { model, version, locale, orientation };
97
+ }
98
+ function getLoginCredential(args) {
99
+ const { username, passwordFile, usernameResourceName, passwordResourceName } = args;
100
+ let password = args.password;
101
+ if (!password && passwordFile) {
102
+ ensureFileExists(passwordFile);
103
+ password = fs.readFileSync(passwordFile, "utf8").trim();
104
+ }
105
+ if (isPresenceMismatched(usernameResourceName, passwordResourceName)) {
106
+ throw new error_1.FirebaseError("Username and password resource names for automated tests need to be specified together.");
107
+ }
108
+ let fieldHints;
109
+ if (usernameResourceName && passwordResourceName) {
110
+ fieldHints = {
111
+ usernameResourceName: usernameResourceName,
112
+ passwordResourceName: passwordResourceName,
113
+ };
114
+ }
115
+ if (isPresenceMismatched(username, password)) {
116
+ throw new error_1.FirebaseError("Username and password for automated tests need to be specified together.");
117
+ }
118
+ let loginCredential;
119
+ if (username && password) {
120
+ loginCredential = { username, password, fieldHints };
121
+ }
122
+ else if (fieldHints) {
123
+ throw new error_1.FirebaseError("Must specify username and password for automated tests if resource names are set");
124
+ }
125
+ return loginCredential;
126
+ }
127
+ exports.getLoginCredential = getLoginCredential;
128
+ function isPresenceMismatched(value1, value2) {
129
+ return (value1 && !value2) || (!value1 && value2);
130
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapDeviceToExecution = exports.UploadReleaseResult = exports.IntegrationState = void 0;
4
+ var IntegrationState;
5
+ (function (IntegrationState) {
6
+ IntegrationState["AAB_INTEGRATION_STATE_UNSPECIFIED"] = "AAB_INTEGRATION_STATE_UNSPECIFIED";
7
+ IntegrationState["INTEGRATED"] = "INTEGRATED";
8
+ IntegrationState["PLAY_ACCOUNT_NOT_LINKED"] = "PLAY_ACCOUNT_NOT_LINKED";
9
+ IntegrationState["NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT"] = "NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT";
10
+ IntegrationState["APP_NOT_PUBLISHED"] = "APP_NOT_PUBLISHED";
11
+ IntegrationState["AAB_STATE_UNAVAILABLE"] = "AAB_STATE_UNAVAILABLE";
12
+ IntegrationState["PLAY_IAS_TERMS_NOT_ACCEPTED"] = "PLAY_IAS_TERMS_NOT_ACCEPTED";
13
+ })(IntegrationState = exports.IntegrationState || (exports.IntegrationState = {}));
14
+ var UploadReleaseResult;
15
+ (function (UploadReleaseResult) {
16
+ UploadReleaseResult["UPLOAD_RELEASE_RESULT_UNSPECIFIED"] = "UPLOAD_RELEASE_RESULT_UNSPECIFIED";
17
+ UploadReleaseResult["RELEASE_CREATED"] = "RELEASE_CREATED";
18
+ UploadReleaseResult["RELEASE_UPDATED"] = "RELEASE_UPDATED";
19
+ UploadReleaseResult["RELEASE_UNMODIFIED"] = "RELEASE_UNMODIFIED";
20
+ })(UploadReleaseResult = exports.UploadReleaseResult || (exports.UploadReleaseResult = {}));
21
+ function mapDeviceToExecution(device) {
22
+ return {
23
+ device: {
24
+ model: device.model,
25
+ version: device.version,
26
+ orientation: device.orientation,
27
+ locale: device.locale,
28
+ },
29
+ };
30
+ }
31
+ exports.mapDeviceToExecution = mapDeviceToExecution;
@@ -6,9 +6,12 @@ const command_1 = require("../command");
6
6
  const utils = require("../utils");
7
7
  const requireAuth_1 = require("../requireAuth");
8
8
  const client_1 = require("../appdistribution/client");
9
+ const types_1 = require("../appdistribution/types");
9
10
  const error_1 = require("../error");
10
11
  const distribution_1 = require("../appdistribution/distribution");
11
12
  const options_parser_util_1 = require("../appdistribution/options-parser-util");
13
+ const TEST_MAX_POLLING_RETRIES = 40;
14
+ const TEST_POLLING_INTERVAL_MILLIS = 30000;
12
15
  function getReleaseNotes(releaseNotes, releaseNotesFile) {
13
16
  if (releaseNotes) {
14
17
  return releaseNotes.replace(/\\n/g, "\n");
@@ -28,6 +31,14 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
28
31
  .option("--testers-file <file>", "path to file with a comma separated list of tester emails to distribute to")
29
32
  .option("--groups <string>", "a comma separated list of group aliases to distribute to")
30
33
  .option("--groups-file <file>", "path to file with a comma separated list of group aliases to distribute to")
34
+ .option("--test-devices <string>", "semicolon-separated list of devices to run automated tests on, in the format 'model=<model-id>,version=<os-version-id>,locale=<locale>,orientation=<orientation>'. Run 'gcloud firebase test android|ios models list' to see available devices. Note: This feature is in beta.")
35
+ .option("--test-devices-file <string>", "path to file containing a list of semicolon- or newline-separated devices to run automated tests on, in the format 'model=<model-id>,version=<os-version-id>,locale=<locale>,orientation=<orientation>'. Run 'gcloud firebase test android|ios models list' to see available devices. Note: This feature is in beta.")
36
+ .option("--test-username <string>", "username for automatic login")
37
+ .option("--test-password <string>", "password for automatic login. If using a real password, use --test-password-file instead to avoid putting sensitive info in history and logs.")
38
+ .option("--test-password-file <string>", "path to file containing password for automatic login")
39
+ .option("--test-username-resource <string>", "resource name for the username field for automatic login")
40
+ .option("--test-password-resource <string>", "resource name for the password field for automatic login")
41
+ .option("--test-non-blocking", "run automated tests without waiting for them to complete. Visit the Firebase console for the test results.")
31
42
  .before(requireAuth_1.requireAuth)
32
43
  .action(async (file, options) => {
33
44
  const appName = (0, options_parser_util_1.getAppName)(options);
@@ -35,6 +46,14 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
35
46
  const releaseNotes = getReleaseNotes(options.releaseNotes, options.releaseNotesFile);
36
47
  const testers = (0, options_parser_util_1.getTestersOrGroups)(options.testers, options.testersFile);
37
48
  const groups = (0, options_parser_util_1.getTestersOrGroups)(options.groups, options.groupsFile);
49
+ const testDevices = (0, options_parser_util_1.getTestDevices)(options.testDevices, options.testDevicesFile);
50
+ const loginCredential = (0, options_parser_util_1.getLoginCredential)({
51
+ username: options.testUsername,
52
+ password: options.testPassword,
53
+ passwordFile: options.testPasswordFile,
54
+ usernameResourceName: options.testUsernameResource,
55
+ passwordResourceName: options.testPasswordResource,
56
+ });
38
57
  const requests = new client_1.AppDistributionClient();
39
58
  let aabInfo;
40
59
  if (distribution.distributionFileType() === distribution_1.DistributionFileType.AAB) {
@@ -50,19 +69,19 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
50
69
  }
51
70
  throw new error_1.FirebaseError(`failed to determine AAB info. ${err.message}`, { exit: 1 });
52
71
  }
53
- if (aabInfo.integrationState !== client_1.IntegrationState.INTEGRATED &&
54
- aabInfo.integrationState !== client_1.IntegrationState.AAB_STATE_UNAVAILABLE) {
72
+ if (aabInfo.integrationState !== types_1.IntegrationState.INTEGRATED &&
73
+ aabInfo.integrationState !== types_1.IntegrationState.AAB_STATE_UNAVAILABLE) {
55
74
  switch (aabInfo.integrationState) {
56
- case client_1.IntegrationState.PLAY_ACCOUNT_NOT_LINKED: {
75
+ case types_1.IntegrationState.PLAY_ACCOUNT_NOT_LINKED: {
57
76
  throw new error_1.FirebaseError("This project is not linked to a Google Play account.");
58
77
  }
59
- case client_1.IntegrationState.APP_NOT_PUBLISHED: {
78
+ case types_1.IntegrationState.APP_NOT_PUBLISHED: {
60
79
  throw new error_1.FirebaseError('"This app is not published in the Google Play console.');
61
80
  }
62
- case client_1.IntegrationState.NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT: {
81
+ case types_1.IntegrationState.NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT: {
63
82
  throw new error_1.FirebaseError("App with matching package name does not exist in Google Play.");
64
83
  }
65
- case client_1.IntegrationState.PLAY_IAS_TERMS_NOT_ACCEPTED: {
84
+ case types_1.IntegrationState.PLAY_IAS_TERMS_NOT_ACCEPTED: {
66
85
  throw new error_1.FirebaseError("You must accept the Play Internal App Sharing (IAS) terms to upload AABs.");
67
86
  }
68
87
  default: {
@@ -78,13 +97,13 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
78
97
  const uploadResponse = await requests.pollUploadStatus(operationName);
79
98
  const release = uploadResponse.release;
80
99
  switch (uploadResponse.result) {
81
- case client_1.UploadReleaseResult.RELEASE_CREATED:
100
+ case types_1.UploadReleaseResult.RELEASE_CREATED:
82
101
  utils.logSuccess(`uploaded new release ${release.displayVersion} (${release.buildVersion}) successfully!`);
83
102
  break;
84
- case client_1.UploadReleaseResult.RELEASE_UPDATED:
103
+ case types_1.UploadReleaseResult.RELEASE_UPDATED:
85
104
  utils.logSuccess(`uploaded update to existing release ${release.displayVersion} (${release.buildVersion}) successfully!`);
86
105
  break;
87
- case client_1.UploadReleaseResult.RELEASE_UNMODIFIED:
106
+ case types_1.UploadReleaseResult.RELEASE_UNMODIFIED:
88
107
  utils.logSuccess(`re-uploaded already existing release ${release.displayVersion} (${release.buildVersion}) successfully!`);
89
108
  break;
90
109
  default:
@@ -102,7 +121,7 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
102
121
  "button on the App Distribution page in the Firebase console: " +
103
122
  "https://console.firebase.google.com/project/_/appdistribution", { exit: 1 });
104
123
  }
105
- throw new error_1.FirebaseError(`failed to upload release. ${err.message}`, { exit: 1 });
124
+ throw new error_1.FirebaseError(`Failed to upload release. ${err.message}`, { exit: 1 });
106
125
  }
107
126
  if (aabInfo && !aabInfo.testCertificate) {
108
127
  aabInfo = await requests.getAabInfo(appName);
@@ -118,4 +137,45 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
118
137
  }
119
138
  await requests.updateReleaseNotes(releaseName, releaseNotes);
120
139
  await requests.distribute(releaseName, testers, groups);
140
+ if (testDevices?.length) {
141
+ utils.logBullet("starting automated tests (note: this feature is in beta)");
142
+ const releaseTest = await requests.createReleaseTest(releaseName, testDevices, loginCredential);
143
+ utils.logSuccess(`Release test created successfully`);
144
+ if (!options.testNonBlocking) {
145
+ await awaitTestResults(releaseTest.name, requests);
146
+ }
147
+ }
121
148
  });
149
+ async function awaitTestResults(releaseTestName, requests) {
150
+ for (let i = 0; i < TEST_MAX_POLLING_RETRIES; i++) {
151
+ utils.logBullet("the automated tests results are pending");
152
+ await delay(TEST_POLLING_INTERVAL_MILLIS);
153
+ const releaseTest = await requests.getReleaseTest(releaseTestName);
154
+ if (releaseTest.deviceExecutions.every((e) => e.state === "PASSED")) {
155
+ utils.logSuccess("automated test(s) passed!");
156
+ return;
157
+ }
158
+ for (const execution of releaseTest.deviceExecutions) {
159
+ switch (execution.state) {
160
+ case "PASSED":
161
+ case "IN_PROGRESS":
162
+ continue;
163
+ case "FAILED":
164
+ throw new error_1.FirebaseError(`Automated test failed for ${deviceToString(execution.device)}: ${execution.failedReason}`, { exit: 1 });
165
+ case "INCONCLUSIVE":
166
+ throw new error_1.FirebaseError(`Automated test inconclusive for ${deviceToString(execution.device)}: ${execution.inconclusiveReason}`, { exit: 1 });
167
+ default:
168
+ throw new error_1.FirebaseError(`Unsupported automated test state for ${deviceToString(execution.device)}: ${execution.state}`, { exit: 1 });
169
+ }
170
+ }
171
+ }
172
+ throw new error_1.FirebaseError("It took longer than expected to process your test, please try again.", {
173
+ exit: 1,
174
+ });
175
+ }
176
+ function delay(ms) {
177
+ return new Promise((resolve) => setTimeout(resolve, ms));
178
+ }
179
+ function deviceToString(device) {
180
+ return `${device.model} (${device.version}/${device.orientation}/${device.locale})`;
181
+ }
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.command = void 0;
4
+ const Table = require("cli-table");
4
5
  const command_1 = require("../command");
5
- const projectUtils_1 = require("../projectUtils");
6
+ const utils_1 = require("../utils");
6
7
  const error_1 = require("../error");
7
8
  const logger_1 = require("../logger");
9
+ const projectUtils_1 = require("../projectUtils");
8
10
  const apphosting = require("../gcp/apphosting");
9
- const Table = require("cli-table");
10
- const COLUMN_LENGTH = 20;
11
- const TABLE_HEAD = ["Backend Id", "Repository", "Location", "URL", "Created Date", "Updated Date"];
11
+ const TABLE_HEAD = ["Backend ID", "Repository", "Location", "URL", "Created Date", "Updated Date"];
12
12
  exports.command = new command_1.Command("apphosting:backends:list")
13
13
  .description("List backends of a Firebase project.")
14
14
  .option("-l, --location <location>", "App Backend location", "-")
@@ -16,42 +16,26 @@ exports.command = new command_1.Command("apphosting:backends:list")
16
16
  .action(async (options) => {
17
17
  const projectId = (0, projectUtils_1.needProjectId)(options);
18
18
  const location = options.location;
19
- const table = new Table({
20
- head: TABLE_HEAD,
21
- style: { head: ["green"] },
22
- });
23
- table.colWidths = COLUMN_LENGTH;
24
- const backendsList = [];
19
+ const table = new Table({ head: TABLE_HEAD, style: { head: ["green"] } });
20
+ let backendRes;
25
21
  try {
26
- const backendsPerRegion = await apphosting.listBackends(projectId, location);
27
- backendsList.push(...(backendsPerRegion.backends || []));
28
- populateTable(backendsList, table);
29
- logger_1.logger.info(table.toString());
22
+ backendRes = await apphosting.listBackends(projectId, location);
30
23
  }
31
24
  catch (err) {
32
25
  throw new error_1.FirebaseError(`Unable to list backends present for project: ${projectId}. Please check the parameters you have provided.`, { original: err });
33
26
  }
34
- return backendsList;
35
- });
36
- function populateTable(backends, table) {
27
+ const backends = backendRes?.backends;
37
28
  for (const backend of backends) {
38
- const [location, , backendId] = backend.name.split("/").slice(3, 6);
39
- const entry = [
29
+ const [backendLocation, , backendId] = backend.name.split("/").slice(3, 6);
30
+ table.push([
40
31
  backendId,
41
- backend.codebase.repository?.split("/").pop(),
42
- location,
43
- backend.uri,
44
- backend.createTime,
45
- backend.updateTime,
46
- ];
47
- const newRow = entry.map((name) => {
48
- const maxCellWidth = COLUMN_LENGTH - 2;
49
- const chunks = [];
50
- for (let i = 0; name && i < name.length; i += maxCellWidth) {
51
- chunks.push(name.substring(i, i + maxCellWidth));
52
- }
53
- return chunks.join("\n");
54
- });
55
- table.push(newRow);
32
+ backend.codebase?.repository?.split("/").pop() ?? "",
33
+ backendLocation,
34
+ backend.uri.startsWith("https:") ? backend.uri : "https://" + backend.uri,
35
+ (0, utils_1.datetimeString)(new Date(backend.createTime)),
36
+ (0, utils_1.datetimeString)(new Date(backend.updateTime)),
37
+ ]);
56
38
  }
57
- }
39
+ logger_1.logger.info(table.toString());
40
+ return backends;
41
+ });
@@ -4,7 +4,6 @@ exports.command = void 0;
4
4
  const apphosting = require("../gcp/apphosting");
5
5
  const logger_1 = require("../logger");
6
6
  const command_1 = require("../command");
7
- const utils_1 = require("../utils");
8
7
  const projectUtils_1 = require("../projectUtils");
9
8
  exports.command = new command_1.Command("apphosting:builds:create <backendId>")
10
9
  .description("Create a build for an App Hosting backend")
@@ -15,12 +14,13 @@ exports.command = new command_1.Command("apphosting:builds:create <backendId>")
15
14
  .action(async (backendId, options) => {
16
15
  const projectId = (0, projectUtils_1.needProjectId)(options);
17
16
  const location = options.location;
18
- const buildId = options.buildId || (0, utils_1.generateId)();
19
- const branch = options.branch;
17
+ const buildId = options.buildId ||
18
+ (await apphosting.getNextRolloutId(projectId, location, backendId));
19
+ const branch = options.branch ?? "main";
20
20
  const op = await apphosting.createBuild(projectId, location, backendId, buildId, {
21
21
  source: {
22
22
  codebase: {
23
- branch: "main",
23
+ branch,
24
24
  },
25
25
  },
26
26
  });
@@ -5,7 +5,6 @@ const apphosting = require("../gcp/apphosting");
5
5
  const logger_1 = require("../logger");
6
6
  const command_1 = require("../command");
7
7
  const projectUtils_1 = require("../projectUtils");
8
- const utils_1 = require("../utils");
9
8
  exports.command = new command_1.Command("apphosting:rollouts:create <backendId> <buildId>")
10
9
  .description("Create a build for an App Hosting backend")
11
10
  .option("-l, --location <location>", "Specify the region of the backend", "us-central1")
@@ -14,7 +13,8 @@ exports.command = new command_1.Command("apphosting:rollouts:create <backendId>
14
13
  .action(async (backendId, buildId, options) => {
15
14
  const projectId = (0, projectUtils_1.needProjectId)(options);
16
15
  const location = options.location;
17
- const rolloutId = options.buildId || (0, utils_1.generateId)();
16
+ const rolloutId = options.buildId ||
17
+ (await apphosting.getNextRolloutId(projectId, location, backendId));
18
18
  const build = `projects/${projectId}/backends/${backendId}/builds/${buildId}`;
19
19
  const op = await apphosting.createRollout(projectId, location, backendId, rolloutId, {
20
20
  build,
@@ -13,6 +13,9 @@ exports.command = new command_1.Command("apphosting:rollouts:list <backendId>")
13
13
  const projectId = (0, projectUtils_1.needProjectId)(options);
14
14
  const location = options.location;
15
15
  const rollouts = await apphosting.listRollouts(projectId, location, backendId);
16
- logger_1.logger.info(JSON.stringify(rollouts, null, 2));
16
+ if (rollouts.unreachable) {
17
+ logger_1.logger.error(`WARNING: the following locations were unreachable: ${rollouts.unreachable.join(", ")}`);
18
+ }
19
+ logger_1.logger.info(JSON.stringify(rollouts.rollouts, null, 2));
17
20
  return rollouts;
18
21
  });
@@ -110,8 +110,10 @@ exports.command = new command_1.Command("functions:config:export")
110
110
  const dotEnvs = pInfos.map((pInfo) => configExport.toDotenvFormat(pInfo.envs, header));
111
111
  const filenames = pInfos.map(configExport.generateDotenvFilename);
112
112
  const filesToWrite = fromEntries((0, functional_1.zip)(filenames, dotEnvs));
113
- filesToWrite[".env.local"] = `${header}\n# .env.local file contains environment variables for the Functions Emulator.\n`;
114
- filesToWrite[".env"] = `${header}# .env file contains environment variables that applies to all projects.\n`;
113
+ filesToWrite[".env.local"] =
114
+ `${header}\n# .env.local file contains environment variables for the Functions Emulator.\n`;
115
+ filesToWrite[".env"] =
116
+ `${header}# .env file contains environment variables that applies to all projects.\n`;
115
117
  for (const [filename, content] of Object.entries(filesToWrite)) {
116
118
  await options.config.askWriteProjectFile(path.join(functionsDir, filename), content);
117
119
  }
@@ -70,7 +70,10 @@ exports.command = new command_1.Command("use [alias_or_project_id]")
70
70
  }
71
71
  if (hasAlias) {
72
72
  if (!project) {
73
- return utils.reject("Unable to use alias " + clc.bold(newActive) + ", " + verifyMessage(resolvedProject));
73
+ return utils.reject("Unable to use alias " +
74
+ clc.bold(newActive) +
75
+ ", " +
76
+ verifyMessage(resolvedProject));
74
77
  }
75
78
  utils.makeActiveProject(options.projectRoot, newActive);
76
79
  logger_1.logger.info("Now using alias", clc.bold(newActive), "(" + resolvedProject + ")");
@@ -133,6 +133,11 @@ async function convertConfig(context, functionsPayload, deploy) {
133
133
  },
134
134
  };
135
135
  if (rewrite.function.pinTag) {
136
+ if (endpoint.minInstances) {
137
+ throw new error_1.FirebaseError(`Function ${endpoint.id} has minInstances set and is in a rewrite ` +
138
+ "pinTags=true. These features are not currently compatible with each " +
139
+ "other.");
140
+ }
136
141
  experiments.assertEnabled("pintags", "pin a function version");
137
142
  apiRewrite.run.tag = runTags.TODO_TAG_NAME;
138
143
  }
@@ -155,7 +155,8 @@ async function unsafePins(context, config) {
155
155
  const existingUntaggedRewrites = {};
156
156
  for (const rewrite of channelConfig?.release?.version?.config?.rewrites || []) {
157
157
  if ("run" in rewrite && !rewrite.run.tag) {
158
- existingUntaggedRewrites[rewriteTarget(rewrite)] = `${rewrite.run.region}/${rewrite.run.serviceId}`;
158
+ existingUntaggedRewrites[rewriteTarget(rewrite)] =
159
+ `${rewrite.run.region}/${rewrite.run.serviceId}`;
159
160
  }
160
161
  }
161
162
  return Object.keys(targetTaggedRewrites).filter((target) => targetTaggedRewrites[target] === existingUntaggedRewrites[target]);
@@ -159,7 +159,7 @@ function registerHandlers(app, getProjectStateByApiKey) {
159
159
  res.set("Content-Type", "text/html; charset=utf-8");
160
160
  const apiKey = req.query.apiKey;
161
161
  const providerId = req.query.providerId;
162
- const tenantId = req.query.tenantId;
162
+ const tenantId = (req.query.tenantId || req.query.tid);
163
163
  if (!apiKey || !providerId) {
164
164
  return res.status(400).json({
165
165
  authEmulator: {