firebase-tools 12.4.8 → 12.5.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.
File without changes
@@ -95,17 +95,18 @@ class Fabricator {
95
95
  deployResults.push(result);
96
96
  };
97
97
  const upserts = [];
98
- const scraper = new sourceTokenScraper_1.SourceTokenScraper();
98
+ const scraperV1 = new sourceTokenScraper_1.SourceTokenScraper();
99
+ const scraperV2 = new sourceTokenScraper_1.SourceTokenScraper();
99
100
  for (const endpoint of changes.endpointsToCreate) {
100
101
  this.logOpStart("creating", endpoint);
101
- upserts.push(handle("create", endpoint, () => this.createEndpoint(endpoint, scraper)));
102
+ upserts.push(handle("create", endpoint, () => this.createEndpoint(endpoint, scraperV1, scraperV2)));
102
103
  }
103
104
  for (const endpoint of changes.endpointsToSkip) {
104
105
  utils.logSuccess(this.getLogSuccessMessage("skip", endpoint));
105
106
  }
106
107
  for (const update of changes.endpointsToUpdate) {
107
108
  this.logOpStart("updating", update.endpoint);
108
- upserts.push(handle("update", update.endpoint, () => this.updateEndpoint(update, scraper)));
109
+ upserts.push(handle("update", update.endpoint, () => this.updateEndpoint(update, scraperV1, scraperV2)));
109
110
  }
110
111
  await utils.allSettled(upserts);
111
112
  if (deployResults.find((r) => r.error)) {
@@ -126,31 +127,31 @@ class Fabricator {
126
127
  await utils.allSettled(deletes);
127
128
  return deployResults;
128
129
  }
129
- async createEndpoint(endpoint, scraper) {
130
+ async createEndpoint(endpoint, scraperV1, scraperV2) {
130
131
  endpoint.labels = Object.assign(Object.assign({}, endpoint.labels), deploymentTool.labels());
131
132
  if (endpoint.platform === "gcfv1") {
132
- await this.createV1Function(endpoint, scraper);
133
+ await this.createV1Function(endpoint, scraperV1);
133
134
  }
134
135
  else if (endpoint.platform === "gcfv2") {
135
- await this.createV2Function(endpoint);
136
+ await this.createV2Function(endpoint, scraperV2);
136
137
  }
137
138
  else {
138
139
  (0, functional_1.assertExhaustive)(endpoint.platform);
139
140
  }
140
141
  await this.setTrigger(endpoint);
141
142
  }
142
- async updateEndpoint(update, scraper) {
143
+ async updateEndpoint(update, scraperV1, scraperV2) {
143
144
  update.endpoint.labels = Object.assign(Object.assign({}, update.endpoint.labels), deploymentTool.labels());
144
145
  if (update.deleteAndRecreate) {
145
146
  await this.deleteEndpoint(update.deleteAndRecreate);
146
- await this.createEndpoint(update.endpoint, scraper);
147
+ await this.createEndpoint(update.endpoint, scraperV1, scraperV2);
147
148
  return;
148
149
  }
149
150
  if (update.endpoint.platform === "gcfv1") {
150
- await this.updateV1Function(update.endpoint, scraper);
151
+ await this.updateV1Function(update.endpoint, scraperV1);
151
152
  }
152
153
  else if (update.endpoint.platform === "gcfv2") {
153
- await this.updateV2Function(update.endpoint);
154
+ await this.updateV2Function(update.endpoint, scraperV2);
154
155
  }
155
156
  else {
156
157
  (0, functional_1.assertExhaustive)(update.endpoint.platform);
@@ -221,7 +222,7 @@ class Fabricator {
221
222
  .catch(rethrowAs(endpoint, "set invoker"));
222
223
  }
223
224
  }
224
- async createV2Function(endpoint) {
225
+ async createV2Function(endpoint, scraper) {
225
226
  var _a, _b, _c, _d, _e;
226
227
  const storageSource = (_a = this.sources[endpoint.codebase]) === null || _a === void 0 ? void 0 : _a.storage;
227
228
  if (!storageSource) {
@@ -275,8 +276,9 @@ class Fabricator {
275
276
  while (!resultFunction) {
276
277
  resultFunction = await this.functionExecutor
277
278
  .run(async () => {
279
+ apiFunction.buildConfig.sourceToken = await scraper.getToken();
278
280
  const op = await gcfV2.createFunction(apiFunction);
279
- return await poller.pollOperation(Object.assign(Object.assign({}, gcfV2PollerOptions), { pollerName: `create-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`, operationResourceName: op.name }));
281
+ return await poller.pollOperation(Object.assign(Object.assign({}, gcfV2PollerOptions), { pollerName: `create-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`, operationResourceName: op.name, onPoll: scraper.poller }));
280
282
  })
281
283
  .catch(async (err) => {
282
284
  if (err.code === CLOUD_RUN_RESOURCE_EXHAUSTED_CODE) {
@@ -366,7 +368,7 @@ class Fabricator {
366
368
  .catch(rethrowAs(endpoint, "set invoker"));
367
369
  }
368
370
  }
369
- async updateV2Function(endpoint) {
371
+ async updateV2Function(endpoint, scraper) {
370
372
  var _a, _b, _c, _d;
371
373
  const storageSource = (_a = this.sources[endpoint.codebase]) === null || _a === void 0 ? void 0 : _a.storage;
372
374
  if (!storageSource) {
@@ -379,8 +381,9 @@ class Fabricator {
379
381
  }
380
382
  const resultFunction = await this.functionExecutor
381
383
  .run(async () => {
384
+ apiFunction.buildConfig.sourceToken = await scraper.getToken();
382
385
  const op = await gcfV2.updateFunction(apiFunction);
383
- return await poller.pollOperation(Object.assign(Object.assign({}, gcfV2PollerOptions), { pollerName: `update-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`, operationResourceName: op.name }));
386
+ return await poller.pollOperation(Object.assign(Object.assign({}, gcfV2PollerOptions), { pollerName: `update-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`, operationResourceName: op.name, onPoll: scraper.poller }));
384
387
  }, { retryCodes: [...executor_1.DEFAULT_RETRY_CODES, CLOUD_RUN_RESOURCE_EXHAUSTED_CODE] })
385
388
  .catch(rethrowAs(endpoint, "update"));
386
389
  endpoint.uri = (_c = resultFunction.serviceConfig) === null || _c === void 0 ? void 0 : _c.uri;
@@ -5,8 +5,9 @@ const error_1 = require("../../../error");
5
5
  const functional_1 = require("../../../functional");
6
6
  const logger_1 = require("../../../logger");
7
7
  class SourceTokenScraper {
8
- constructor(validDurationMs = 1500000) {
8
+ constructor(validDurationMs = 1500000, fetchTimeoutMs = 180000) {
9
9
  this.tokenValidDurationMs = validDurationMs;
10
+ this.fetchTimeoutMs = fetchTimeoutMs;
10
11
  this.promise = new Promise((resolve) => (this.resolve = resolve));
11
12
  this.fetchState = "NONE";
12
13
  }
@@ -16,7 +17,13 @@ class SourceTokenScraper {
16
17
  return undefined;
17
18
  }
18
19
  else if (this.fetchState === "FETCHING") {
19
- return this.promise;
20
+ const timeout = new Promise((resolve) => {
21
+ setTimeout(() => {
22
+ this.fetchState = "NONE";
23
+ resolve(undefined);
24
+ }, this.fetchTimeoutMs);
25
+ });
26
+ return Promise.race([this.promise, timeout]);
20
27
  }
21
28
  else if (this.fetchState === "VALID") {
22
29
  if (this.isTokenExpired()) {
@@ -92,11 +92,7 @@ class ExtensionsEmulator {
92
92
  this.installAndBuildSourceCode(sourceCodePath);
93
93
  }
94
94
  hasValidSource(args) {
95
- const requiredFiles = [
96
- "./extension.yaml",
97
- "./functions/package.json",
98
- "./functions/node_modules",
99
- ];
95
+ const requiredFiles = ["./extension.yaml", "./functions/package.json"];
100
96
  if (!fs.existsSync(args.path)) {
101
97
  return false;
102
98
  }
@@ -1,42 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getParams = exports.getSecretEnvVars = exports.getNonSecretEnv = exports.getExtensionFunctionInfo = exports.buildOptions = void 0;
4
- const fs = require("fs-extra");
5
- const path = require("path");
3
+ exports.getParams = exports.getSecretEnvVars = exports.getNonSecretEnv = exports.getExtensionFunctionInfo = void 0;
6
4
  const paramHelper = require("../paramHelper");
7
5
  const specHelper = require("./specHelper");
8
- const localHelper = require("../localHelper");
9
6
  const triggerHelper = require("./triggerHelper");
10
7
  const types_1 = require("../types");
11
8
  const extensionsHelper = require("../extensionsHelper");
12
9
  const planner = require("../../deploy/extensions/planner");
13
- const config_1 = require("../../config");
14
- const error_1 = require("../../error");
15
- const emulatorLogger_1 = require("../../emulator/emulatorLogger");
16
10
  const projectUtils_1 = require("../../projectUtils");
17
- const types_2 = require("../../emulator/types");
18
- async function buildOptions(options) {
19
- const extDevDir = localHelper.findExtensionYaml(process.cwd());
20
- options.extDevDir = extDevDir;
21
- const spec = await specHelper.readExtensionYaml(extDevDir);
22
- extensionsHelper.validateSpec(spec);
23
- const params = getParams(options, spec);
24
- extensionsHelper.validateCommandLineParams(params, spec.params);
25
- const functionResources = specHelper.getFunctionResourcesWithParamSubstitution(spec, params);
26
- let testConfig;
27
- if (options.testConfig) {
28
- testConfig = readTestConfigFile(options.testConfig);
29
- checkTestConfig(testConfig, functionResources);
30
- }
31
- options.config = buildConfig(functionResources, testConfig);
32
- options.extDevEnv = params;
33
- const functionEmuTriggerDefs = functionResources.map((r) => triggerHelper.functionResourceToEmulatedTriggerDefintion(r));
34
- options.extDevTriggers = functionEmuTriggerDefs;
35
- options.extDevRuntime = specHelper.getRuntime(functionResources);
36
- return options;
37
- }
38
- exports.buildOptions = buildOptions;
39
11
  async function getExtensionFunctionInfo(instance, paramValues) {
12
+ var _a, _b;
40
13
  const spec = await planner.getExtensionSpec(instance);
41
14
  const functionResources = specHelper.getFunctionResourcesWithParamSubstitution(spec, paramValues);
42
15
  const extensionTriggers = functionResources
@@ -46,8 +19,8 @@ async function getExtensionFunctionInfo(instance, paramValues) {
46
19
  return trigger;
47
20
  });
48
21
  const runtime = specHelper.getRuntime(functionResources);
49
- const nonSecretEnv = getNonSecretEnv(spec.params, paramValues);
50
- const secretEnvVariables = getSecretEnvVars(spec.params, paramValues);
22
+ const nonSecretEnv = getNonSecretEnv((_a = spec.params) !== null && _a !== void 0 ? _a : [], paramValues);
23
+ const secretEnvVariables = getSecretEnvVars((_b = spec.params) !== null && _b !== void 0 ? _b : [], paramValues);
51
24
  return {
52
25
  extensionTriggers,
53
26
  runtime,
@@ -98,102 +71,3 @@ function getParams(options, extensionSpec) {
98
71
  return extensionsHelper.substituteParams(unsubbedParams, unsubbedParams);
99
72
  }
100
73
  exports.getParams = getParams;
101
- function checkTestConfig(testConfig, functionResources) {
102
- const logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_2.Emulators.FUNCTIONS);
103
- if (!testConfig.functions && functionResources.length) {
104
- logger.log("WARN", "This extension uses functions," +
105
- "but 'firebase.json' provided by --test-config is missing a top-level 'functions' object." +
106
- "Functions will not be emulated.");
107
- }
108
- if (!testConfig.firestore && shouldEmulateFirestore(functionResources)) {
109
- logger.log("WARN", "This extension interacts with Cloud Firestore," +
110
- "but 'firebase.json' provided by --test-config is missing a top-level 'firestore' object." +
111
- "Cloud Firestore will not be emulated.");
112
- }
113
- if (!testConfig.database && shouldEmulateDatabase(functionResources)) {
114
- logger.log("WARN", "This extension interacts with Realtime Database," +
115
- "but 'firebase.json' provided by --test-config is missing a top-level 'database' object." +
116
- "Realtime Database will not be emulated.");
117
- }
118
- if (!testConfig.storage && shouldEmulateStorage(functionResources)) {
119
- logger.log("WARN", "This extension interacts with Cloud Storage," +
120
- "but 'firebase.json' provided by --test-config is missing a top-level 'storage' object." +
121
- "Cloud Storage will not be emulated.");
122
- }
123
- }
124
- function readTestConfigFile(testConfigPath) {
125
- try {
126
- const buf = fs.readFileSync(path.resolve(testConfigPath));
127
- return JSON.parse(buf.toString());
128
- }
129
- catch (err) {
130
- throw new error_1.FirebaseError(`Error reading --test-config file: ${err.message}\n`, {
131
- original: err,
132
- });
133
- }
134
- }
135
- function buildConfig(functionResources, testConfig) {
136
- const config = new config_1.Config(testConfig || {}, { projectDir: process.cwd(), cwd: process.cwd() });
137
- const emulateFunctions = shouldEmulateFunctions(functionResources);
138
- if (!testConfig) {
139
- if (emulateFunctions) {
140
- config.set("functions", {});
141
- }
142
- if (shouldEmulateFirestore(functionResources)) {
143
- config.set("firestore", {});
144
- }
145
- if (shouldEmulateDatabase(functionResources)) {
146
- config.set("database", {});
147
- }
148
- if (shouldEmulatePubsub(functionResources)) {
149
- config.set("pubsub", {});
150
- }
151
- if (shouldEmulateStorage(functionResources)) {
152
- config.set("storage", {});
153
- }
154
- }
155
- if (config.src.functions) {
156
- const sourceDirectory = getFunctionSourceDirectory(functionResources);
157
- config.set("functions.source", sourceDirectory);
158
- }
159
- return config;
160
- }
161
- function getFunctionSourceDirectory(functionResources) {
162
- var _a;
163
- let sourceDirectory;
164
- for (const r of functionResources) {
165
- const dir = ((_a = r.properties) === null || _a === void 0 ? void 0 : _a.sourceDirectory) || "functions";
166
- if (!sourceDirectory) {
167
- sourceDirectory = dir;
168
- }
169
- else if (sourceDirectory !== dir) {
170
- throw new error_1.FirebaseError(`Found function resources with different sourceDirectories: '${sourceDirectory}' and '${dir}'. The extensions emulator only supports a single sourceDirectory.`);
171
- }
172
- }
173
- return sourceDirectory || "functions";
174
- }
175
- function shouldEmulateFunctions(resources) {
176
- return resources.length > 0;
177
- }
178
- function shouldEmulate(emulatorName, resources) {
179
- var _a, _b;
180
- for (const r of resources) {
181
- const eventType = ((_b = (_a = r.properties) === null || _a === void 0 ? void 0 : _a.eventTrigger) === null || _b === void 0 ? void 0 : _b.eventType) || "";
182
- if (eventType.includes(emulatorName)) {
183
- return true;
184
- }
185
- }
186
- return false;
187
- }
188
- function shouldEmulateFirestore(resources) {
189
- return shouldEmulate("cloud.firestore", resources);
190
- }
191
- function shouldEmulateDatabase(resources) {
192
- return shouldEmulate("google.firebase.database", resources);
193
- }
194
- function shouldEmulatePubsub(resources) {
195
- return shouldEmulate("google.pubsub", resources);
196
- }
197
- function shouldEmulateStorage(resources) {
198
- return shouldEmulate("google.storage", resources);
199
- }
@@ -26,9 +26,20 @@ function wrappedSafeLoad(source) {
26
26
  }
27
27
  }
28
28
  async function readExtensionYaml(directory) {
29
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
29
30
  const extensionYaml = await readFileFromDirectory(directory, SPEC_FILE);
30
31
  const source = extensionYaml.source;
31
- return wrappedSafeLoad(source);
32
+ const spec = wrappedSafeLoad(source);
33
+ spec.params = (_a = spec.params) !== null && _a !== void 0 ? _a : [];
34
+ spec.systemParams = (_b = spec.systemParams) !== null && _b !== void 0 ? _b : [];
35
+ spec.resources = (_c = spec.resources) !== null && _c !== void 0 ? _c : [];
36
+ spec.apis = (_d = spec.apis) !== null && _d !== void 0 ? _d : [];
37
+ spec.roles = (_e = spec.roles) !== null && _e !== void 0 ? _e : [];
38
+ spec.externalServices = (_f = spec.externalServices) !== null && _f !== void 0 ? _f : [];
39
+ spec.events = (_g = spec.events) !== null && _g !== void 0 ? _g : [];
40
+ spec.lifecycleEvents = (_h = spec.lifecycleEvents) !== null && _h !== void 0 ? _h : [];
41
+ spec.contributors = (_j = spec.contributors) !== null && _j !== void 0 ? _j : [];
42
+ return spec;
32
43
  }
33
44
  exports.readExtensionYaml = readExtensionYaml;
34
45
  async function readPostinstall(directory) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.APP_PATHS_MANIFEST = exports.ROUTES_MANIFEST = exports.PRERENDER_MANIFEST = exports.PAGES_MANIFEST = exports.MIDDLEWARE_MANIFEST = exports.IMAGES_MANIFEST = exports.EXPORT_MARKER = exports.APP_PATH_ROUTES_MANIFEST = void 0;
3
+ exports.ESBUILD_VERSION = exports.APP_PATHS_MANIFEST = exports.ROUTES_MANIFEST = exports.PRERENDER_MANIFEST = exports.PAGES_MANIFEST = exports.MIDDLEWARE_MANIFEST = exports.IMAGES_MANIFEST = exports.EXPORT_MARKER = exports.APP_PATH_ROUTES_MANIFEST = void 0;
4
4
  exports.APP_PATH_ROUTES_MANIFEST = "app-path-routes-manifest.json";
5
5
  exports.EXPORT_MARKER = "export-marker.json";
6
6
  exports.IMAGES_MANIFEST = "images-manifest.json";
@@ -9,3 +9,4 @@ exports.PAGES_MANIFEST = "pages-manifest.json";
9
9
  exports.PRERENDER_MANIFEST = "prerender-manifest.json";
10
10
  exports.ROUTES_MANIFEST = "routes-manifest.json";
11
11
  exports.APP_PATHS_MANIFEST = "app-paths-manifest.json";
12
+ exports.ESBUILD_VERSION = "0.19.2";
@@ -327,7 +327,7 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
327
327
  const esbuildArgs = productionDeps
328
328
  .map((it) => `--external:${it}`)
329
329
  .concat("--bundle", "--platform=node", `--target=node${constants_1.NODE_VERSION}`, `--outdir=${destDir}`, "--log-level=error");
330
- const bundle = (0, cross_spawn_1.sync)("npx", ["--yes", "esbuild", "next.config.js", ...esbuildArgs], {
330
+ const bundle = (0, cross_spawn_1.sync)("npx", ["--yes", `esbuild@${constants_2.ESBUILD_VERSION}`, "next.config.js", ...esbuildArgs], {
331
331
  cwd: sourceDir,
332
332
  timeout: BUNDLE_NEXT_CONFIG_TIMEOUT,
333
333
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "12.4.8",
3
+ "version": "12.5.1",
4
4
  "description": "Command-Line Interface for Firebase",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {