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
@@ -485,13 +485,21 @@ function createAuthUri(state, reqBody) {
485
485
  }
486
486
  }
487
487
  }
488
- return {
489
- kind: "identitytoolkit#CreateAuthUriResponse",
490
- registered,
491
- allProviders,
492
- sessionId,
493
- signinMethods,
494
- };
488
+ if (state.enableImprovedEmailPrivacy) {
489
+ return {
490
+ kind: "identitytoolkit#CreateAuthUriResponse",
491
+ sessionId,
492
+ };
493
+ }
494
+ else {
495
+ return {
496
+ kind: "identitytoolkit#CreateAuthUriResponse",
497
+ registered,
498
+ allProviders,
499
+ sessionId,
500
+ signinMethods,
501
+ };
502
+ }
495
503
  }
496
504
  const SESSION_COOKIE_MIN_VALID_DURATION = 5 * 60;
497
505
  exports.SESSION_COOKIE_MAX_VALID_DURATION = 14 * 24 * 60 * 60;
@@ -636,7 +644,14 @@ function sendOobCode(state, reqBody, ctx) {
636
644
  mode = "resetPassword";
637
645
  (0, errors_1.assert)(reqBody.email, "MISSING_EMAIL");
638
646
  email = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
639
- (0, errors_1.assert)(state.getUserByEmail(email), "EMAIL_NOT_FOUND");
647
+ const maybeUser = state.getUserByEmail(email);
648
+ if (state.enableImprovedEmailPrivacy && !maybeUser) {
649
+ return {
650
+ kind: "identitytoolkit#GetOobConfirmationCodeResponse",
651
+ email,
652
+ };
653
+ }
654
+ (0, errors_1.assert)(maybeUser, "EMAIL_NOT_FOUND");
640
655
  break;
641
656
  case "VERIFY_EMAIL":
642
657
  mode = "verifyEmail";
@@ -1168,7 +1183,7 @@ async function signInWithIdp(state, reqBody) {
1168
1183
  }
1169
1184
  else {
1170
1185
  if (!response.localId) {
1171
- throw new Error("Internal assertion error: localId not set for exising user.");
1186
+ throw new Error("Internal assertion error: localId not set for existing user.");
1172
1187
  }
1173
1188
  const maybeUser = state.getUserByLocalId(response.localId);
1174
1189
  (0, errors_1.assert)(maybeUser, "USER_NOT_FOUND");
@@ -1219,10 +1234,18 @@ async function signInWithPassword(state, reqBody) {
1219
1234
  }
1220
1235
  const email = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
1221
1236
  let user = state.getUserByEmail(email);
1222
- (0, errors_1.assert)(user, "EMAIL_NOT_FOUND");
1223
- (0, errors_1.assert)(!user.disabled, "USER_DISABLED");
1224
- (0, errors_1.assert)(user.passwordHash && user.salt, "INVALID_PASSWORD");
1225
- (0, errors_1.assert)(user.passwordHash === hashPassword(reqBody.password, user.salt), "INVALID_PASSWORD");
1237
+ if (state.enableImprovedEmailPrivacy) {
1238
+ (0, errors_1.assert)(user, "INVALID_LOGIN_CREDENTIALS");
1239
+ (0, errors_1.assert)(!user.disabled, "USER_DISABLED");
1240
+ (0, errors_1.assert)(user.passwordHash && user.salt, "INVALID_LOGIN_CREDENTIALS");
1241
+ (0, errors_1.assert)(user.passwordHash === hashPassword(reqBody.password, user.salt), "INVALID_LOGIN_CREDENTIALS");
1242
+ }
1243
+ else {
1244
+ (0, errors_1.assert)(user, "EMAIL_NOT_FOUND");
1245
+ (0, errors_1.assert)(!user.disabled, "USER_DISABLED");
1246
+ (0, errors_1.assert)(user.passwordHash && user.salt, "INVALID_PASSWORD");
1247
+ (0, errors_1.assert)(user.passwordHash === hashPassword(reqBody.password, user.salt), "INVALID_PASSWORD");
1248
+ }
1226
1249
  const response = {
1227
1250
  kind: "identitytoolkit#VerifyPasswordResponse",
1228
1251
  registered: true,
@@ -1339,6 +1362,9 @@ function getEmulatorProjectConfig(state) {
1339
1362
  signIn: {
1340
1363
  allowDuplicateEmails: !state.oneAccountPerEmail,
1341
1364
  },
1365
+ emailPrivacyConfig: {
1366
+ enableImprovedEmailPrivacy: state.enableImprovedEmailPrivacy,
1367
+ },
1342
1368
  };
1343
1369
  }
1344
1370
  function updateEmulatorProjectConfig(state, reqBody, ctx) {
@@ -1346,6 +1372,9 @@ function updateEmulatorProjectConfig(state, reqBody, ctx) {
1346
1372
  if (reqBody.signIn?.allowDuplicateEmails != null) {
1347
1373
  updateMask.push("signIn.allowDuplicateEmails");
1348
1374
  }
1375
+ if (reqBody.emailPrivacyConfig?.enableImprovedEmailPrivacy != null) {
1376
+ updateMask.push("emailPrivacyConfig.enableImprovedEmailPrivacy");
1377
+ }
1349
1378
  ctx.params.query.updateMask = updateMask.join();
1350
1379
  updateConfig(state, reqBody, ctx);
1351
1380
  return getEmulatorProjectConfig(state);
@@ -408,6 +408,9 @@ class AgentProjectState extends ProjectState {
408
408
  this._config = {
409
409
  signIn: { allowDuplicateEmails: false },
410
410
  blockingFunctions: {},
411
+ emailPrivacyConfig: {
412
+ enableImprovedEmailPrivacy: false,
413
+ },
411
414
  };
412
415
  }
413
416
  get authCloudFunction() {
@@ -419,6 +422,12 @@ class AgentProjectState extends ProjectState {
419
422
  set oneAccountPerEmail(oneAccountPerEmail) {
420
423
  this._config.signIn.allowDuplicateEmails = !oneAccountPerEmail;
421
424
  }
425
+ get enableImprovedEmailPrivacy() {
426
+ return !!this._config.emailPrivacyConfig.enableImprovedEmailPrivacy;
427
+ }
428
+ set enableImprovedEmailPrivacy(improveEmailPrivacy) {
429
+ this._config.emailPrivacyConfig.enableImprovedEmailPrivacy = improveEmailPrivacy;
430
+ }
422
431
  get allowPasswordSignup() {
423
432
  return true;
424
433
  }
@@ -466,6 +475,8 @@ class AgentProjectState extends ProjectState {
466
475
  if (!updateMask) {
467
476
  this.oneAccountPerEmail = !update.signIn?.allowDuplicateEmails ?? true;
468
477
  this.blockingFunctionsConfig = update.blockingFunctions ?? {};
478
+ this.enableImprovedEmailPrivacy =
479
+ update.emailPrivacyConfig?.enableImprovedEmailPrivacy ?? false;
469
480
  return this.config;
470
481
  }
471
482
  return applyMask(updateMask, this.config, update);
@@ -538,6 +549,9 @@ class TenantProjectState extends ProjectState {
538
549
  get oneAccountPerEmail() {
539
550
  return this.parentProject.oneAccountPerEmail;
540
551
  }
552
+ get enableImprovedEmailPrivacy() {
553
+ return this.parentProject.enableImprovedEmailPrivacy;
554
+ }
541
555
  get authCloudFunction() {
542
556
  return this.parentProject.authCloudFunction;
543
557
  }
@@ -250,7 +250,7 @@ class CloudStorageBucketMetadata {
250
250
  this.location = "US";
251
251
  this.storageClass = "STANDARD";
252
252
  this.etag = "====";
253
- this.locationType = "mutli-region";
253
+ this.locationType = "multi-region";
254
254
  }
255
255
  }
256
256
  exports.CloudStorageBucketMetadata = CloudStorageBucketMetadata;
@@ -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
87
  async function createRollout(projectId, location, backendId, rolloutId, rollout) {
51
- const res = await client.post(`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`, rollout, { queryParams: { rolloutId } });
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 } });
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;
@@ -95,7 +95,7 @@ async function createFunction(cloudFunction) {
95
95
  };
96
96
  cloudFunction.serviceConfig.environmentVariables = {
97
97
  ...cloudFunction.serviceConfig.environmentVariables,
98
- FUNCTION_TARGET: functionId.replaceAll("-", "."),
98
+ FUNCTION_TARGET: cloudFunction.buildConfig.entryPoint.replaceAll("-", "."),
99
99
  };
100
100
  try {
101
101
  const res = await client.post(components.join("/"), cloudFunction, { queryParams: { functionId } });
@@ -149,8 +149,6 @@ async function listFunctionsInternal(projectId, region) {
149
149
  }
150
150
  }
151
151
  async function updateFunction(cloudFunction) {
152
- const components = cloudFunction.name.split("/");
153
- const functionId = components.splice(-1, 1)[0];
154
152
  const fieldMasks = proto.fieldMasks(cloudFunction, "labels", "serviceConfig.environmentVariables", "serviceConfig.secretEnvironmentVariables");
155
153
  cloudFunction.buildConfig.environmentVariables = {
156
154
  ...cloudFunction.buildConfig.environmentVariables,
@@ -159,7 +157,7 @@ async function updateFunction(cloudFunction) {
159
157
  fieldMasks.push("buildConfig.buildEnvironmentVariables");
160
158
  cloudFunction.serviceConfig.environmentVariables = {
161
159
  ...cloudFunction.serviceConfig.environmentVariables,
162
- FUNCTION_TARGET: functionId.replaceAll("-", "."),
160
+ FUNCTION_TARGET: cloudFunction.buildConfig.entryPoint.replaceAll("-", "."),
163
161
  };
164
162
  try {
165
163
  const queryParams = {
@@ -51,10 +51,7 @@ async function listChannels(project = "-", site) {
51
51
  for (;;) {
52
52
  try {
53
53
  const res = await apiClient.get(`/projects/${project}/sites/${site}/channels`, { queryParams: { pageToken: nextPageToken, pageSize: 10 } });
54
- const c = res.body.channels;
55
- if (c) {
56
- channels.push(...c);
57
- }
54
+ channels.push(...(res.body.channels ?? []));
58
55
  nextPageToken = res.body.nextPageToken || "";
59
56
  if (!nextPageToken) {
60
57
  return channels;
@@ -110,7 +107,7 @@ async function listVersions(site) {
110
107
  const res = await apiClient.get(`projects/-/sites/${site}/versions`, {
111
108
  queryParams,
112
109
  });
113
- versions.push(...res.body.versions);
110
+ versions.push(...(res.body.versions ?? []));
114
111
  pageToken = res.body.nextPageToken;
115
112
  } while (pageToken);
116
113
  return versions;
@@ -142,10 +139,7 @@ async function listSites(project) {
142
139
  for (;;) {
143
140
  try {
144
141
  const res = await apiClient.get(`/projects/${project}/sites`, { queryParams: { pageToken: nextPageToken, pageSize: 10 } });
145
- const c = res.body.sites;
146
- if (c) {
147
- sites.push(...c);
148
- }
142
+ sites.push(...(res.body.sites ?? []));
149
143
  nextPageToken = res.body.nextPageToken || "";
150
144
  if (!nextPageToken) {
151
145
  return sites;