firebase-tools 12.4.8 → 12.5.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.
- package/lib/bin/firebase.js +0 -0
- package/lib/deploy/functions/release/fabricator.js +8 -6
- package/lib/deploy/functions/release/sourceTokenScraper.js +9 -2
- package/lib/emulator/extensionsEmulator.js +1 -5
- package/lib/extensions/emulator/optionsHelper.js +4 -130
- package/lib/extensions/emulator/specHelper.js +12 -1
- package/lib/frameworks/next/constants.js +2 -1
- package/lib/frameworks/next/index.js +1 -1
- package/package.json +1 -1
package/lib/bin/firebase.js
CHANGED
|
File without changes
|
|
@@ -132,7 +132,7 @@ class Fabricator {
|
|
|
132
132
|
await this.createV1Function(endpoint, scraper);
|
|
133
133
|
}
|
|
134
134
|
else if (endpoint.platform === "gcfv2") {
|
|
135
|
-
await this.createV2Function(endpoint);
|
|
135
|
+
await this.createV2Function(endpoint, scraper);
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
138
|
(0, functional_1.assertExhaustive)(endpoint.platform);
|
|
@@ -150,7 +150,7 @@ class Fabricator {
|
|
|
150
150
|
await this.updateV1Function(update.endpoint, scraper);
|
|
151
151
|
}
|
|
152
152
|
else if (update.endpoint.platform === "gcfv2") {
|
|
153
|
-
await this.updateV2Function(update.endpoint);
|
|
153
|
+
await this.updateV2Function(update.endpoint, scraper);
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
156
156
|
(0, functional_1.assertExhaustive)(update.endpoint.platform);
|
|
@@ -221,7 +221,7 @@ class Fabricator {
|
|
|
221
221
|
.catch(rethrowAs(endpoint, "set invoker"));
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
async createV2Function(endpoint) {
|
|
224
|
+
async createV2Function(endpoint, scraper) {
|
|
225
225
|
var _a, _b, _c, _d, _e;
|
|
226
226
|
const storageSource = (_a = this.sources[endpoint.codebase]) === null || _a === void 0 ? void 0 : _a.storage;
|
|
227
227
|
if (!storageSource) {
|
|
@@ -275,8 +275,9 @@ class Fabricator {
|
|
|
275
275
|
while (!resultFunction) {
|
|
276
276
|
resultFunction = await this.functionExecutor
|
|
277
277
|
.run(async () => {
|
|
278
|
+
apiFunction.buildConfig.sourceToken = await scraper.getToken();
|
|
278
279
|
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 }));
|
|
280
|
+
return await poller.pollOperation(Object.assign(Object.assign({}, gcfV2PollerOptions), { pollerName: `create-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`, operationResourceName: op.name, onPoll: scraper.poller }));
|
|
280
281
|
})
|
|
281
282
|
.catch(async (err) => {
|
|
282
283
|
if (err.code === CLOUD_RUN_RESOURCE_EXHAUSTED_CODE) {
|
|
@@ -366,7 +367,7 @@ class Fabricator {
|
|
|
366
367
|
.catch(rethrowAs(endpoint, "set invoker"));
|
|
367
368
|
}
|
|
368
369
|
}
|
|
369
|
-
async updateV2Function(endpoint) {
|
|
370
|
+
async updateV2Function(endpoint, scraper) {
|
|
370
371
|
var _a, _b, _c, _d;
|
|
371
372
|
const storageSource = (_a = this.sources[endpoint.codebase]) === null || _a === void 0 ? void 0 : _a.storage;
|
|
372
373
|
if (!storageSource) {
|
|
@@ -379,8 +380,9 @@ class Fabricator {
|
|
|
379
380
|
}
|
|
380
381
|
const resultFunction = await this.functionExecutor
|
|
381
382
|
.run(async () => {
|
|
383
|
+
apiFunction.buildConfig.sourceToken = await scraper.getToken();
|
|
382
384
|
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 }));
|
|
385
|
+
return await poller.pollOperation(Object.assign(Object.assign({}, gcfV2PollerOptions), { pollerName: `update-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`, operationResourceName: op.name, onPoll: scraper.poller }));
|
|
384
386
|
}, { retryCodes: [...executor_1.DEFAULT_RETRY_CODES, CLOUD_RUN_RESOURCE_EXHAUSTED_CODE] })
|
|
385
387
|
.catch(rethrowAs(endpoint, "update"));
|
|
386
388
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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",
|
|
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
|
});
|