firebase-tools-with-isolate 13.0.2 → 13.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) 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/auth.js +11 -2
  6. package/lib/commands/appdistribution-distribute.js +70 -10
  7. package/lib/commands/apphosting-backends-create.js +6 -3
  8. package/lib/commands/apphosting-backends-delete.js +3 -5
  9. package/lib/commands/apphosting-backends-get.js +2 -2
  10. package/lib/commands/apphosting-backends-list.js +21 -37
  11. package/lib/commands/apphosting-builds-create.js +8 -8
  12. package/lib/commands/apphosting-builds-get.js +2 -2
  13. package/lib/commands/apphosting-rollouts-create.js +5 -5
  14. package/lib/commands/apphosting-rollouts-list.js +6 -3
  15. package/lib/commands/firestore-backups-delete.js +44 -0
  16. package/lib/commands/firestore-backups-get.js +25 -0
  17. package/lib/commands/firestore-backups-list.js +33 -0
  18. package/lib/commands/firestore-backups-schedules-create.js +67 -0
  19. package/lib/commands/firestore-backups-schedules-delete.js +46 -0
  20. package/lib/commands/firestore-backups-schedules-list.js +27 -0
  21. package/lib/commands/firestore-backups-schedules-update.js +33 -0
  22. package/lib/commands/firestore-databases-create.js +4 -2
  23. package/lib/commands/firestore-databases-delete.js +4 -2
  24. package/lib/commands/firestore-databases-get.js +3 -1
  25. package/lib/commands/firestore-databases-list.js +3 -1
  26. package/lib/commands/firestore-databases-restore.js +42 -0
  27. package/lib/commands/firestore-databases-update.js +4 -2
  28. package/lib/commands/firestore-indexes-list.js +5 -3
  29. package/lib/commands/firestore-locations.js +3 -1
  30. package/lib/commands/functions-config-export.js +4 -2
  31. package/lib/commands/index.js +11 -1
  32. package/lib/commands/init.js +3 -3
  33. package/lib/commands/use.js +4 -1
  34. package/lib/deploy/functions/runtimes/index.js +2 -0
  35. package/lib/deploy/functions/runtimes/python/index.js +4 -1
  36. package/lib/deploy/functions/services/firestore.js +1 -1
  37. package/lib/deploy/hosting/convertConfig.js +5 -0
  38. package/lib/deploy/hosting/prepare.js +2 -1
  39. package/lib/emulator/auth/handlers.js +1 -1
  40. package/lib/emulator/auth/operations.js +42 -13
  41. package/lib/emulator/auth/state.js +14 -0
  42. package/lib/emulator/downloadableEmulators.js +3 -3
  43. package/lib/emulator/storage/metadata.js +1 -1
  44. package/lib/emulator/storage/rules/runtime.js +1 -1
  45. package/lib/experiments.js +2 -2
  46. package/lib/firestore/api-sort.js +23 -1
  47. package/lib/firestore/api-types.js +6 -1
  48. package/lib/firestore/api.js +18 -115
  49. package/lib/firestore/backupUtils.js +30 -0
  50. package/lib/firestore/delete.js +3 -3
  51. package/lib/firestore/pretty-print.js +184 -0
  52. package/lib/frameworks/angular/index.js +2 -2
  53. package/lib/frameworks/angular/utils.js +14 -10
  54. package/lib/frameworks/astro/index.js +1 -2
  55. package/lib/frameworks/flutter/index.js +1 -1
  56. package/lib/frameworks/index.js +2 -3
  57. package/lib/frameworks/next/index.js +5 -3
  58. package/lib/frameworks/nuxt/index.js +2 -2
  59. package/lib/frameworks/nuxt2/index.js +1 -2
  60. package/lib/frameworks/sveltekit/index.js +2 -2
  61. package/lib/frameworks/utils.js +11 -2
  62. package/lib/frameworks/vite/index.js +8 -4
  63. package/lib/functions/env.js +2 -0
  64. package/lib/gcp/apphosting.js +103 -17
  65. package/lib/gcp/cloudbuild.js +7 -2
  66. package/lib/gcp/cloudfunctionsv2.js +2 -4
  67. package/lib/gcp/firestore.js +89 -6
  68. package/lib/hosting/api.js +3 -9
  69. package/lib/hosting/options.js +2 -1
  70. package/lib/init/features/apphosting/index.js +150 -68
  71. package/lib/init/features/apphosting/repo.js +80 -32
  72. package/lib/init/features/hosting/github.js +6 -1
  73. package/lib/metaprogramming.js +3 -0
  74. package/lib/prompt.js +1 -0
  75. package/lib/utils.js +1 -12
  76. package/package.json +15 -10
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrettyPrint = void 0;
4
+ const clc = require("colorette");
5
+ const Table = require("cli-table");
6
+ const sort = require("./api-sort");
7
+ const types = require("./api-types");
8
+ const logger_1 = require("../logger");
9
+ const util = require("./util");
10
+ class PrettyPrint {
11
+ prettyPrintIndexes(indexes) {
12
+ if (indexes.length === 0) {
13
+ logger_1.logger.info("None");
14
+ return;
15
+ }
16
+ const sortedIndexes = indexes.sort(sort.compareApiIndex);
17
+ sortedIndexes.forEach((index) => {
18
+ logger_1.logger.info(this.prettyIndexString(index));
19
+ });
20
+ }
21
+ prettyPrintDatabases(databases) {
22
+ if (databases.length === 0) {
23
+ logger_1.logger.info("No databases found.");
24
+ return;
25
+ }
26
+ const sortedDatabases = databases.sort(sort.compareApiDatabase);
27
+ const table = new Table({
28
+ head: ["Database Name"],
29
+ colWidths: [Math.max(...sortedDatabases.map((database) => database.name.length + 5), 20)],
30
+ });
31
+ table.push(...sortedDatabases.map((database) => [this.prettyDatabaseString(database)]));
32
+ logger_1.logger.info(table.toString());
33
+ }
34
+ prettyPrintDatabase(database) {
35
+ const table = new Table({
36
+ head: ["Field", "Value"],
37
+ colWidths: [25, Math.max(50, 5 + database.name.length)],
38
+ });
39
+ table.push(["Name", clc.yellow(database.name)], ["Create Time", clc.yellow(database.createTime)], ["Last Update Time", clc.yellow(database.updateTime)], ["Type", clc.yellow(database.type)], ["Location", clc.yellow(database.locationId)], ["Delete Protection State", clc.yellow(database.deleteProtectionState)], ["Point In Time Recovery", clc.yellow(database.pointInTimeRecoveryEnablement)], ["Earliest Version Time", clc.yellow(database.earliestVersionTime)], ["Version Retention Period", clc.yellow(database.versionRetentionPeriod)]);
40
+ logger_1.logger.info(table.toString());
41
+ }
42
+ prettyPrintBackups(backups) {
43
+ if (backups.length === 0) {
44
+ logger_1.logger.info("No backups found.");
45
+ return;
46
+ }
47
+ const sortedBackups = backups.sort(sort.compareApiBackup);
48
+ const table = new Table({
49
+ head: ["Backup Name", "Database Name", "Snapshot Time", "State"],
50
+ colWidths: [
51
+ Math.max(...sortedBackups.map((backup) => backup.name.length + 5), 20),
52
+ Math.max(...sortedBackups.map((backup) => backup.database.length + 5), 20),
53
+ 30,
54
+ 10,
55
+ ],
56
+ });
57
+ table.push(...sortedBackups.map((backup) => [
58
+ this.prettyBackupString(backup),
59
+ this.prettyDatabaseString(backup.database || ""),
60
+ backup.snapshotTime,
61
+ backup.state,
62
+ ]));
63
+ logger_1.logger.info(table.toString());
64
+ }
65
+ prettyPrintBackupSchedules(backupSchedules, databaseId) {
66
+ if (backupSchedules.length === 0) {
67
+ logger_1.logger.info(`No backup schedules for database ${databaseId} found.`);
68
+ return;
69
+ }
70
+ const sortedBackupSchedules = backupSchedules.sort(sort.compareApiBackupSchedule);
71
+ sortedBackupSchedules.forEach((schedule) => this.prettyPrintBackupSchedule(schedule));
72
+ }
73
+ prettyPrintBackupSchedule(backupSchedule) {
74
+ const table = new Table({
75
+ head: ["Field", "Value"],
76
+ colWidths: [25, Math.max(50, 5 + backupSchedule.name.length)],
77
+ });
78
+ table.push(["Name", clc.yellow(backupSchedule.name)], ["Create Time", clc.yellow(backupSchedule.createTime)], ["Last Update Time", clc.yellow(backupSchedule.updateTime)], ["Retention", clc.yellow(backupSchedule.retention)], ["Recurrence", this.prettyRecurrenceString(backupSchedule)]);
79
+ logger_1.logger.info(table.toString());
80
+ }
81
+ prettyRecurrenceString(backupSchedule) {
82
+ if (backupSchedule.dailyRecurrence) {
83
+ return clc.yellow("DAILY");
84
+ }
85
+ else if (backupSchedule.weeklyRecurrence) {
86
+ return clc.yellow(`WEEKLY (${backupSchedule.weeklyRecurrence.day})`);
87
+ }
88
+ return "";
89
+ }
90
+ prettyPrintBackup(backup) {
91
+ const table = new Table({
92
+ head: ["Field", "Value"],
93
+ colWidths: [25, Math.max(50, 5 + backup.name.length, 5 + backup.database.length)],
94
+ });
95
+ table.push(["Name", clc.yellow(backup.name)], ["Database", clc.yellow(backup.database)], ["Database UID", clc.yellow(backup.databaseUid)], ["State", clc.yellow(backup.state)], ["Snapshot Time", clc.yellow(backup.snapshotTime)], ["Expire Time", clc.yellow(backup.expireTime)], ["Stats", clc.yellow(backup.stats)]);
96
+ logger_1.logger.info(table.toString());
97
+ }
98
+ prettyPrintLocations(locations) {
99
+ if (locations.length === 0) {
100
+ logger_1.logger.info("No Locations Available");
101
+ return;
102
+ }
103
+ const table = new Table({
104
+ head: ["Display Name", "LocationId"],
105
+ colWidths: [20, 30],
106
+ });
107
+ table.push(...locations
108
+ .sort(sort.compareLocation)
109
+ .map((location) => [location.displayName, location.locationId]));
110
+ logger_1.logger.info(table.toString());
111
+ }
112
+ printFieldOverrides(fields) {
113
+ if (fields.length === 0) {
114
+ logger_1.logger.info("None");
115
+ return;
116
+ }
117
+ const sortedFields = fields.sort(sort.compareApiField);
118
+ sortedFields.forEach((field) => {
119
+ logger_1.logger.info(this.prettyFieldString(field));
120
+ });
121
+ }
122
+ prettyIndexString(index, includeState = true) {
123
+ let result = "";
124
+ if (index.state && includeState) {
125
+ const stateMsg = `[${index.state}] `;
126
+ if (index.state === types.State.READY) {
127
+ result += clc.green(stateMsg);
128
+ }
129
+ else if (index.state === types.State.CREATING) {
130
+ result += clc.yellow(stateMsg);
131
+ }
132
+ else {
133
+ result += clc.red(stateMsg);
134
+ }
135
+ }
136
+ const nameInfo = util.parseIndexName(index.name);
137
+ result += clc.cyan(`(${nameInfo.collectionGroupId})`);
138
+ result += " -- ";
139
+ index.fields.forEach((field) => {
140
+ if (field.fieldPath === "__name__") {
141
+ return;
142
+ }
143
+ const orderOrArrayConfig = field.order ? field.order : field.arrayConfig;
144
+ result += `(${field.fieldPath},${orderOrArrayConfig}) `;
145
+ });
146
+ return result;
147
+ }
148
+ prettyBackupString(backup) {
149
+ return clc.yellow(backup.name || "");
150
+ }
151
+ prettyBackupScheduleString(backupSchedule) {
152
+ return clc.yellow(backupSchedule.name || "");
153
+ }
154
+ prettyDatabaseString(database) {
155
+ return clc.yellow(typeof database === "string" ? database : database.name);
156
+ }
157
+ prettyFieldString(field) {
158
+ let result = "";
159
+ const parsedName = util.parseFieldName(field.name);
160
+ result +=
161
+ "[" +
162
+ clc.cyan(parsedName.collectionGroupId) +
163
+ "." +
164
+ clc.yellow(parsedName.fieldPath) +
165
+ "] --";
166
+ const fieldIndexes = field.indexConfig.indexes || [];
167
+ if (fieldIndexes.length > 0) {
168
+ fieldIndexes.forEach((index) => {
169
+ const firstField = index.fields[0];
170
+ const mode = firstField.order || firstField.arrayConfig;
171
+ result += ` (${mode})`;
172
+ });
173
+ }
174
+ else {
175
+ result += " (no indexes)";
176
+ }
177
+ const fieldTtl = field.ttlConfig;
178
+ if (fieldTtl) {
179
+ result += ` TTL(${fieldTtl.state})`;
180
+ }
181
+ return result;
182
+ }
183
+ }
184
+ exports.PrettyPrint = PrettyPrint;
@@ -22,7 +22,7 @@ async function discover(dir) {
22
22
  if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "angular.json"))))
23
23
  return;
24
24
  const version = (0, utils_2.getAngularVersion)(dir);
25
- return { mayWantBackend: true, publicDirectory: (0, path_1.join)(dir, "src", "assets"), version };
25
+ return { mayWantBackend: true, version };
26
26
  }
27
27
  exports.discover = discover;
28
28
  function init(setup, config) {
@@ -59,7 +59,7 @@ async function build(dir, configuration) {
59
59
  }
60
60
  exports.build = build;
61
61
  async function getDevModeHandle(dir, configuration) {
62
- const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
62
+ const { targetStringFromTarget } = await (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
63
63
  const { serveTarget } = await (0, utils_2.getContext)(dir, configuration);
64
64
  if (!serveTarget)
65
65
  throw new Error("Could not find the serveTarget");
@@ -8,7 +8,7 @@ const assert_1 = require("assert");
8
8
  const utils_2 = require("../../utils");
9
9
  const semver_1 = require("semver");
10
10
  async function localesForTarget(dir, architectHost, target, workspaceProject) {
11
- const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
11
+ const { targetStringFromTarget } = await (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
12
12
  const targetOptions = await architectHost.getOptionsForTarget(target);
13
13
  if (!targetOptions) {
14
14
  const targetString = targetStringFromTarget(target);
@@ -71,9 +71,11 @@ function getValidBuilders(purpose) {
71
71
  }
72
72
  async function getAllTargets(purpose, dir) {
73
73
  const validBuilders = getValidBuilders(purpose);
74
- const { NodeJsAsyncHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node");
75
- const { workspaces } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core");
76
- const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
74
+ const [{ NodeJsAsyncHost }, { workspaces }, { targetStringFromTarget }] = await Promise.all([
75
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node"),
76
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/core"),
77
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect"),
78
+ ]);
77
79
  const host = workspaces.createWorkspaceHost(new NodeJsAsyncHost());
78
80
  const { workspace } = await workspaces.readWorkspace(dir, host);
79
81
  const targets = [];
@@ -97,11 +99,13 @@ async function getAllTargets(purpose, dir) {
97
99
  }
98
100
  exports.getAllTargets = getAllTargets;
99
101
  async function getContext(dir, targetOrConfiguration) {
100
- const { NodeJsAsyncHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node");
101
- const { workspaces } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core");
102
- const { WorkspaceNodeModulesArchitectHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect/node");
103
- const { Architect, targetFromTargetString, targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
104
- const { parse } = (0, utils_1.relativeRequire)(dir, "jsonc-parser");
102
+ const [{ NodeJsAsyncHost }, { workspaces }, { WorkspaceNodeModulesArchitectHost }, { Architect, targetFromTargetString, targetStringFromTarget }, { parse },] = await Promise.all([
103
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node"),
104
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/core"),
105
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect/node"),
106
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect"),
107
+ (0, utils_1.relativeRequire)(dir, "jsonc-parser"),
108
+ ]);
105
109
  const host = workspaces.createWorkspaceHost(new NodeJsAsyncHost());
106
110
  const { workspace } = await workspaces.readWorkspace(dir, host);
107
111
  const architectHost = new WorkspaceNodeModulesArchitectHost(workspace, dir);
@@ -425,7 +429,7 @@ async function getServerConfig(sourceDir, configuration) {
425
429
  }
426
430
  exports.getServerConfig = getServerConfig;
427
431
  async function getBuildConfig(sourceDir, configuration) {
428
- const { targetStringFromTarget } = (0, utils_1.relativeRequire)(sourceDir, "@angular-devkit/architect");
432
+ const { targetStringFromTarget } = await (0, utils_1.relativeRequire)(sourceDir, "@angular-devkit/architect");
429
433
  const { buildTarget, browserTarget, baseHref, prerenderTarget, serverTarget, architectHost, workspaceProject, serveOptimizedImages, ssr, } = await getContext(sourceDir, configuration);
430
434
  const targets = (buildTarget
431
435
  ? [buildTarget]
@@ -17,10 +17,9 @@ async function discover(dir) {
17
17
  const version = (0, utils_2.getAstroVersion)(dir);
18
18
  if (!version)
19
19
  return;
20
- const { output, publicDir: publicDirectory } = await (0, utils_2.getConfig)(dir);
20
+ const { output } = await (0, utils_2.getConfig)(dir);
21
21
  return {
22
22
  mayWantBackend: output !== "static",
23
- publicDirectory,
24
23
  version,
25
24
  };
26
25
  }
@@ -22,7 +22,7 @@ async function discover(dir) {
22
22
  const usingFlutter = pubSpec.dependencies?.flutter;
23
23
  if (!usingFlutter)
24
24
  return;
25
- return { mayWantBackend: false, publicDirectory: (0, path_1.join)(dir, "web") };
25
+ return { mayWantBackend: false };
26
26
  }
27
27
  exports.discover = discover;
28
28
  function init(setup, config) {
@@ -188,7 +188,7 @@ async function prepareFrameworks(purpose, targetNames, context, options, emulato
188
188
  if (!results) {
189
189
  throw new error_1.FirebaseError((0, utils_1.frameworksCallToAction)("Unable to detect the web framework in use, check firebase-debug.log for more info."));
190
190
  }
191
- const { framework, mayWantBackend, publicDirectory } = results;
191
+ const { framework, mayWantBackend } = results;
192
192
  const { build, ɵcodegenPublicDirectory, ɵcodegenFunctionsDirectory: codegenProdModeFunctionsDirectory, getDevModeHandle, name, support, docsUrl, supportedRange, getValidBuildTargets = constants_2.GET_DEFAULT_BUILD_TARGETS, shouldUseDevModeHandle = constants_2.DEFAULT_SHOULD_USE_DEV_MODE_HANDLE, } = frameworks_1.WebFrameworks[framework];
193
193
  logger_1.logger.info(`\n${(0, utils_1.frameworksCallToAction)(constants_2.SupportLevelWarnings[support](name), docsUrl, " ", name, results.version, supportedRange, results.vite)}\n`);
194
194
  const hostingEmulatorInfo = emulators.find((e) => e.name === types_1.Emulators.HOSTING);
@@ -210,7 +210,6 @@ async function prepareFrameworks(purpose, targetNames, context, options, emulato
210
210
  getDevModeHandle &&
211
211
  (await getDevModeHandle(getProjectPath(), frameworksBuildTarget, hostingEmulatorInfo));
212
212
  if (devModeHandle) {
213
- config.public = (0, path_1.relative)(projectRoot, publicDirectory);
214
213
  options.frameworksDevModeHandle = devModeHandle;
215
214
  if (mayWantBackend && firebaseDefaults) {
216
215
  codegenFunctionsDirectory = codegenDevModeFunctionsDirectory;
@@ -238,10 +237,10 @@ async function prepareFrameworks(purpose, targetNames, context, options, emulato
238
237
  project,
239
238
  site,
240
239
  });
241
- config.public = (0, path_1.relative)(projectRoot, hostingDist);
242
240
  if (wantsBackend && !omitCloudFunction)
243
241
  codegenFunctionsDirectory = codegenProdModeFunctionsDirectory;
244
242
  }
243
+ config.public = (0, path_1.relative)(projectRoot, hostingDist);
245
244
  config.webFramework = `${framework}${codegenFunctionsDirectory ? "_ssr" : ""}`;
246
245
  if (codegenFunctionsDirectory) {
247
246
  if (firebaseDefaults) {
@@ -378,7 +378,7 @@ async function getDevModeHandle(dir, _, hostingEmulatorInfo) {
378
378
  throw new error_1.FirebaseError(`${clc.bold("firebase serve")} does not support Next.js Middleware. Please use ${clc.bold("firebase emulators:start")} instead.`);
379
379
  }
380
380
  }
381
- let next = (0, utils_1.relativeRequire)(dir, "next");
381
+ let next = await (0, utils_1.relativeRequire)(dir, "next");
382
382
  if ("default" in next)
383
383
  next = next.default;
384
384
  const nextApp = next({
@@ -403,8 +403,10 @@ async function getConfig(dir) {
403
403
  if (!version)
404
404
  throw new Error("Unable to find the next dep, try NPM installing?");
405
405
  if ((0, semver_1.gte)(version, "12.0.0")) {
406
- const { default: loadConfig } = (0, utils_1.relativeRequire)(dir, "next/dist/server/config");
407
- const { PHASE_PRODUCTION_BUILD } = (0, utils_1.relativeRequire)(dir, "next/constants");
406
+ const [{ default: loadConfig }, { PHASE_PRODUCTION_BUILD }] = await Promise.all([
407
+ (0, utils_1.relativeRequire)(dir, "next/dist/server/config"),
408
+ (0, utils_1.relativeRequire)(dir, "next/constants"),
409
+ ]);
408
410
  config = await loadConfig(PHASE_PRODUCTION_BUILD, dir);
409
411
  }
410
412
  else {
@@ -25,8 +25,8 @@ async function discover(dir) {
25
25
  return;
26
26
  if (version && (0, semver_1.lt)(version, "3.0.0-0"))
27
27
  return;
28
- const { dir: { public: publicDirectory }, ssr: mayWantBackend, } = await getConfig(dir);
29
- return { publicDirectory, mayWantBackend, version };
28
+ const { ssr: mayWantBackend } = await getConfig(dir);
29
+ return { mayWantBackend, version };
30
30
  }
31
31
  exports.discover = discover;
32
32
  async function build(cwd) {
@@ -25,8 +25,7 @@ async function discover(rootDir) {
25
25
  const version = (0, utils_2.getNuxtVersion)(rootDir);
26
26
  if (!version || (version && (0, semver_1.gte)(version, "3.0.0-0")))
27
27
  return;
28
- const { app } = await getAndLoadNuxt({ rootDir, for: "build" });
29
- return { mayWantBackend: true, publicDirectory: app.options.dir.static, version };
28
+ return { mayWantBackend: true, version };
30
29
  }
31
30
  exports.discover = discover;
32
31
  async function build(rootDir) {
@@ -13,10 +13,10 @@ exports.discover = (0, vite_1.viteDiscoverWithNpmDependency)("@sveltejs/kit");
13
13
  var vite_2 = require("../vite");
14
14
  Object.defineProperty(exports, "getDevModeHandle", { enumerable: true, get: function () { return vite_2.getDevModeHandle; } });
15
15
  Object.defineProperty(exports, "supportedRange", { enumerable: true, get: function () { return vite_2.supportedRange; } });
16
- async function build(root) {
16
+ async function build(root, target) {
17
17
  const config = await getConfig(root);
18
18
  const wantsBackend = config.kit.adapter?.name !== "@sveltejs/adapter-static";
19
- await (0, vite_1.build)(root);
19
+ await (0, vite_1.build)(root, target);
20
20
  return { wantsBackend };
21
21
  }
22
22
  exports.build = build;
@@ -192,11 +192,20 @@ function findDependency(name, options = {}) {
192
192
  return scanDependencyTree(name, json.dependencies);
193
193
  }
194
194
  exports.findDependency = findDependency;
195
- function relativeRequire(dir, mod) {
195
+ async function relativeRequire(dir, mod) {
196
196
  try {
197
197
  const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
198
198
  const path = requireFunc.resolve(mod, { paths: [dir] });
199
- if ((0, path_1.extname)(path) === ".mjs") {
199
+ let packageJson;
200
+ let isEsm = (0, path_1.extname)(path) === ".mjs";
201
+ if (!isEsm) {
202
+ packageJson = await readJSON((0, path_1.join)((0, path_1.dirname)(path), "package.json")).catch(() => undefined);
203
+ isEsm = packageJson?.type === "module";
204
+ }
205
+ if (isEsm) {
206
+ if ((0, path_1.extname)(path) === ".cjs" && packageJson?.main) {
207
+ return dynamicImport((0, path_1.join)((0, path_1.dirname)(path), packageJson.main));
208
+ }
200
209
  return dynamicImport((0, url_1.pathToFileURL)(path).toString());
201
210
  }
202
211
  else {
@@ -67,13 +67,17 @@ async function discover(dir, plugin, npmDependency) {
67
67
  };
68
68
  }
69
69
  exports.discover = discover;
70
- async function build(root) {
71
- const { build } = (0, utils_1.relativeRequire)(root, "vite");
70
+ async function build(root, target) {
71
+ const { build } = await (0, utils_1.relativeRequire)(root, "vite");
72
72
  await (0, utils_1.warnIfCustomBuildScript)(root, exports.name, exports.DEFAULT_BUILD_SCRIPT);
73
73
  const cwd = process.cwd();
74
74
  process.chdir(root);
75
- await build({ root, mode: "production" });
75
+ const originalNodeEnv = process.env.NODE_ENV;
76
+ const envKey = "NODE_ENV";
77
+ process.env[envKey] = target;
78
+ await build({ root, mode: target });
76
79
  process.chdir(cwd);
80
+ process.env[envKey] = originalNodeEnv;
77
81
  return { rewrites: [{ source: "**", destination: "/index.html" }] };
78
82
  }
79
83
  exports.build = build;
@@ -103,7 +107,7 @@ async function getDevModeHandle(dir) {
103
107
  }
104
108
  exports.getDevModeHandle = getDevModeHandle;
105
109
  async function getConfig(root) {
106
- const { resolveConfig } = (0, utils_1.relativeRequire)(root, "vite");
110
+ const { resolveConfig } = await (0, utils_1.relativeRequire)(root, "vite");
107
111
  const cwd = process.cwd();
108
112
  process.chdir(root);
109
113
  const config = await resolveConfig({ root }, "build", "production");
@@ -31,6 +31,8 @@ const RESERVED_KEYS = [
31
31
  "K_CONFIGURATION",
32
32
  ];
33
33
  const LINE_RE = new RegExp("^" +
34
+ "\\s*" +
35
+ "(?:export)?" +
34
36
  "\\s*" +
35
37
  "([\\w./]+)" +
36
38
  "\\s*=[\\f\\t\\v]*" +
@@ -1,79 +1,138 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureApiEnabled = exports.listLocations = exports.updateTraffic = exports.listRollouts = exports.createRollout = exports.createBuild = exports.getBuild = exports.deleteBackend = exports.listBackends = exports.getBackend = exports.createBackend = exports.API_VERSION = exports.API_HOST = void 0;
3
+ exports.getNextRolloutId = exports.ensureApiEnabled = exports.listLocations = exports.updateTraffic = exports.listRollouts = exports.createRollout = exports.createBuild = exports.listBuilds = exports.getBuild = exports.deleteBackend = exports.listBackends = exports.getBackend = exports.createBackend = exports.client = exports.API_VERSION = exports.API_HOST = void 0;
4
4
  const proto = require("../gcp/proto");
5
5
  const apiv2_1 = require("../apiv2");
6
6
  const projectUtils_1 = require("../projectUtils");
7
7
  const api_1 = require("../api");
8
8
  const ensureApiEnabled_1 = require("../ensureApiEnabled");
9
+ const deploymentTool = require("../deploymentTool");
10
+ const error_1 = require("../error");
11
+ const metaprogramming_1 = require("../metaprogramming");
9
12
  exports.API_HOST = new URL(api_1.apphostingOrigin).host;
10
13
  exports.API_VERSION = "v1alpha";
11
- const client = new apiv2_1.Client({
14
+ exports.client = new apiv2_1.Client({
12
15
  urlPrefix: api_1.apphostingOrigin,
13
16
  auth: true,
14
17
  apiVersion: exports.API_VERSION,
15
18
  });
19
+ (0, metaprogramming_1.assertImplements)();
20
+ (0, metaprogramming_1.assertImplements)();
21
+ (0, metaprogramming_1.assertImplements)();
22
+ (0, metaprogramming_1.assertImplements)();
16
23
  async function createBackend(projectId, location, backendReqBoby, backendId) {
17
- const res = await client.post(`projects/${projectId}/locations/${location}/backends`, backendReqBoby, { queryParams: { backendId } });
24
+ const res = await exports.client.post(`projects/${projectId}/locations/${location}/backends`, {
25
+ ...backendReqBoby,
26
+ labels: {
27
+ ...backendReqBoby.labels,
28
+ ...deploymentTool.labels(),
29
+ },
30
+ }, { queryParams: { backendId } });
18
31
  return res.body;
19
32
  }
20
33
  exports.createBackend = createBackend;
21
34
  async function getBackend(projectId, location, backendId) {
22
35
  const name = `projects/${projectId}/locations/${location}/backends/${backendId}`;
23
- const res = await client.get(name);
36
+ const res = await exports.client.get(name);
24
37
  return res.body;
25
38
  }
26
39
  exports.getBackend = getBackend;
27
40
  async function listBackends(projectId, location) {
28
41
  const name = `projects/${projectId}/locations/${location}/backends`;
29
- const res = await client.get(name);
42
+ const res = await exports.client.get(name);
30
43
  return res.body;
31
44
  }
32
45
  exports.listBackends = listBackends;
33
46
  async function deleteBackend(projectId, location, backendId) {
34
47
  const name = `projects/${projectId}/locations/${location}/backends/${backendId}`;
35
- const res = await client.delete(name);
48
+ const res = await exports.client.delete(name, { queryParams: { force: "true" } });
36
49
  return res.body;
37
50
  }
38
51
  exports.deleteBackend = deleteBackend;
39
52
  async function getBuild(projectId, location, backendId, buildId) {
40
53
  const name = `projects/${projectId}/locations/${location}/backends/${backendId}/builds/${buildId}`;
41
- const res = await client.get(name);
54
+ const res = await exports.client.get(name);
42
55
  return res.body;
43
56
  }
44
57
  exports.getBuild = getBuild;
58
+ async function listBuilds(projectId, location, backendId) {
59
+ const name = `projects/${projectId}/locations/${location}/backends/${backendId}/builds`;
60
+ let pageToken;
61
+ const res = {
62
+ builds: [],
63
+ unreachable: [],
64
+ };
65
+ do {
66
+ const queryParams = pageToken ? { pageToken } : {};
67
+ const int = await exports.client.get(name, { queryParams });
68
+ res.builds.push(...(int.body.builds || []));
69
+ res.unreachable?.push(...(int.body.unreachable || []));
70
+ pageToken = int.body.nextPageToken;
71
+ } while (pageToken);
72
+ res.unreachable = [...new Set(res.unreachable)];
73
+ return res;
74
+ }
75
+ exports.listBuilds = listBuilds;
45
76
  async function createBuild(projectId, location, backendId, buildId, buildInput) {
46
- const res = await client.post(`projects/${projectId}/locations/${location}/backends/${backendId}/builds`, buildInput, { queryParams: { buildId } });
77
+ const res = await exports.client.post(`projects/${projectId}/locations/${location}/backends/${backendId}/builds`, {
78
+ ...buildInput,
79
+ labels: {
80
+ ...buildInput.labels,
81
+ ...deploymentTool.labels(),
82
+ },
83
+ }, { queryParams: { buildId } });
47
84
  return res.body;
48
85
  }
49
86
  exports.createBuild = createBuild;
50
- async function createRollout(projectId, location, backendId, rolloutId, rollout) {
51
- const res = await client.post(`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`, rollout, { queryParams: { rolloutId } });
87
+ async function createRollout(projectId, location, backendId, rolloutId, rollout, validateOnly = false) {
88
+ const res = await exports.client.post(`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`, {
89
+ ...rollout,
90
+ labels: {
91
+ ...rollout.labels,
92
+ ...deploymentTool.labels(),
93
+ },
94
+ }, { queryParams: { rolloutId, validateOnly: validateOnly ? "true" : "false" } });
52
95
  return res.body;
53
96
  }
54
97
  exports.createRollout = createRollout;
55
98
  async function listRollouts(projectId, location, backendId) {
56
- const res = await client.get(`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`);
57
- return res.body.rollouts;
99
+ const name = `projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`;
100
+ let pageToken = undefined;
101
+ const res = {
102
+ rollouts: [],
103
+ unreachable: [],
104
+ };
105
+ do {
106
+ const queryParams = pageToken ? { pageToken } : {};
107
+ const int = await exports.client.get(name, { queryParams });
108
+ res.rollouts.splice(res.rollouts.length, 0, ...(int.body.rollouts || []));
109
+ res.unreachable.splice(res.unreachable.length, 0, ...(int.body.unreachable || []));
110
+ pageToken = int.body.nextPageToken;
111
+ } while (pageToken);
112
+ res.unreachable = [...new Set(res.unreachable)];
113
+ return res;
58
114
  }
59
115
  exports.listRollouts = listRollouts;
60
116
  async function updateTraffic(projectId, location, backendId, traffic) {
61
- const fieldMasks = proto.fieldMasks(traffic);
117
+ const fieldMasks = proto.fieldMasks(traffic, "rolloutPolicy");
62
118
  const queryParams = {
63
119
  updateMask: fieldMasks.join(","),
64
120
  };
65
121
  const name = `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`;
66
- const res = await client.patch(name, { ...traffic, name }, {
122
+ const res = await exports.client.patch(name, { ...traffic, name }, {
67
123
  queryParams,
68
124
  });
69
125
  return res.body;
70
126
  }
71
127
  exports.updateTraffic = updateTraffic;
72
128
  async function listLocations(projectId) {
73
- let pageToken;
129
+ let pageToken = undefined;
74
130
  let locations = [];
75
131
  do {
76
- const response = await client.get(`projects/${projectId}/locations`);
132
+ const queryParams = pageToken ? { pageToken } : {};
133
+ const response = await exports.client.get(`projects/${projectId}/locations`, {
134
+ queryParams,
135
+ });
77
136
  if (response.body.locations && response.body.locations.length > 0) {
78
137
  locations = locations.concat(response.body.locations);
79
138
  }
@@ -84,6 +143,33 @@ async function listLocations(projectId) {
84
143
  exports.listLocations = listLocations;
85
144
  async function ensureApiEnabled(options) {
86
145
  const projectId = (0, projectUtils_1.needProjectId)(options);
87
- return await (0, ensureApiEnabled_1.ensure)(projectId, exports.API_HOST, "frameworks", true);
146
+ return await (0, ensureApiEnabled_1.ensure)(projectId, exports.API_HOST, "app hosting", true);
88
147
  }
89
148
  exports.ensureApiEnabled = ensureApiEnabled;
149
+ async function getNextRolloutId(projectId, location, backendId, counter) {
150
+ const date = new Date();
151
+ const year = date.getUTCFullYear();
152
+ const month = String(date.getUTCMonth() + 1).padStart(2, "0");
153
+ const day = String(date.getUTCDate()).padStart(2, "0");
154
+ if (counter) {
155
+ return `build-${year}-${month}-${day}-${String(counter).padStart(3, "0")}`;
156
+ }
157
+ const builds = await exports.listRollouts(projectId, location, backendId);
158
+ if (builds.unreachable?.includes(location)) {
159
+ throw new error_1.FirebaseError(`Firebase App Hosting is currently unreachable in location ${location}`);
160
+ }
161
+ let highest = 0;
162
+ const test = new RegExp(`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts/build-${year}-${month}-${day}-(\\d+)`);
163
+ for (const rollout of builds.rollouts) {
164
+ const match = rollout.name.match(test);
165
+ if (!match) {
166
+ continue;
167
+ }
168
+ const n = Number(match[1]);
169
+ if (n > highest) {
170
+ highest = n;
171
+ }
172
+ }
173
+ return `build-${year}-${month}-${day}-${String(highest + 1).padStart(3, "0")}`;
174
+ }
175
+ exports.getNextRolloutId = getNextRolloutId;
@@ -46,9 +46,14 @@ async function deleteConnection(projectId, location, connectionId) {
46
46
  return res.body;
47
47
  }
48
48
  exports.deleteConnection = deleteConnection;
49
- async function fetchLinkableRepositories(projectId, location, connectionId) {
49
+ async function fetchLinkableRepositories(projectId, location, connectionId, pageToken = "", pageSize = 1000) {
50
50
  const name = `projects/${projectId}/locations/${location}/connections/${connectionId}:fetchLinkableRepositories`;
51
- const res = await client.get(name);
51
+ const res = await client.get(name, {
52
+ queryParams: {
53
+ pageSize,
54
+ pageToken,
55
+ },
56
+ });
52
57
  return res.body;
53
58
  }
54
59
  exports.fetchLinkableRepositories = fetchLinkableRepositories;