firebase-tools 15.35.0 → 15.36.1-main.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/accountExporter.js +1 -1
- package/lib/accountImporter.js +7 -6
- package/lib/apiv2.js +0 -1
- package/lib/appcheck/debugTokens.js +293 -0
- package/lib/appcheck/localConfig.js +191 -0
- package/lib/appdistribution/options-parser-util.js +1 -1
- package/lib/apphosting/githubConnections.js +1 -1
- package/lib/apptesting/parseTestFiles.js +1 -1
- package/lib/auth.js +9 -3
- package/lib/bin/progressiveHelp.js +1 -1
- package/lib/command.js +1 -2
- package/lib/commands/appcheck-debugtokens-create.js +60 -35
- package/lib/commands/appcheck-debugtokens-delete.js +21 -7
- package/lib/commands/appcheck-debugtokens-list.js +37 -8
- package/lib/commands/appcheck-debugtokens-prune.js +59 -0
- package/lib/commands/crashlytics-events-get.js +48 -0
- package/lib/commands/crashlytics-events-list.js +70 -0
- package/lib/commands/crashlytics-heapdumps-enable.js +3 -4
- package/lib/commands/crashlytics-heapdumps-status.js +5 -3
- package/lib/commands/crashlytics-issues-get.js +61 -0
- package/lib/commands/crashlytics-reports-get.js +179 -0
- package/lib/commands/crashlytics-reports-list.js +42 -0
- package/lib/commands/deploy.js +1 -3
- package/lib/commands/ext-dev-init.js +1 -1
- package/lib/commands/hosting-channel-create.js +1 -3
- package/lib/commands/hosting-channel-delete.js +1 -3
- package/lib/commands/hosting-channel-deploy.js +1 -3
- package/lib/commands/hosting-channel-list.js +1 -3
- package/lib/commands/hosting-channel-open.js +5 -4
- package/lib/commands/hosting-clone.js +3 -5
- package/lib/commands/hosting-disable.js +2 -2
- package/lib/commands/hosting-sites-create.js +1 -3
- package/lib/commands/hosting-sites-delete.js +1 -3
- package/lib/commands/hosting-sites-get.js +1 -3
- package/lib/commands/hosting-sites-list.js +1 -3
- package/lib/commands/index.js +11 -0
- package/lib/commands/open.js +3 -1
- package/lib/commands/serve.js +1 -1
- package/lib/commands/use.js +1 -1
- package/lib/config.js +1 -1
- package/lib/crashlytics/commandUtils.js +194 -0
- package/lib/crashlytics/events.js +122 -1
- package/lib/crashlytics/filters.js +12 -6
- package/lib/crashlytics/profilingManager.js +77 -50
- package/lib/crashlytics/reports.js +5 -1
- package/lib/crashlytics/utils.js +14 -0
- package/lib/database/import.js +5 -4
- package/lib/dataconnect/names.js +3 -3
- package/lib/dataconnect/schemaMigration.js +1 -1
- package/lib/deploy/firestore/prepare.js +21 -3
- package/lib/deploy/functions/backend.js +0 -10
- package/lib/deploy/functions/cel.js +2 -2
- package/lib/deploy/functions/deploy.js +2 -1
- package/lib/deploy/functions/release/fabricator.js +9 -2
- package/lib/deploy/functions/release/planner.js +3 -0
- package/lib/deploy/functions/release/reporter.js +0 -26
- package/lib/deploy/functions/runtimes/discovery/index.js +4 -1
- package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +1 -1
- package/lib/deploy/functions/services/index.js +13 -11
- package/lib/deploy/hosting/prepare.js +1 -3
- package/lib/deploy/lifecycleHooks.js +1 -1
- package/lib/emulator/auth/operations.js +2 -2
- package/lib/emulator/auth/server.js +4 -2
- package/lib/emulator/auth/widget_ui.js +1 -1
- package/lib/emulator/commandUtils.js +4 -1
- package/lib/emulator/databaseEmulator.js +16 -11
- package/lib/emulator/dataconnect/pgliteServer.js +30 -24
- package/lib/emulator/downloadableEmulatorInfo.json +31 -31
- package/lib/emulator/downloadableEmulators.js +2 -2
- package/lib/emulator/extensions/postinstall.js +6 -6
- package/lib/emulator/firestoreEmulator.js +21 -15
- package/lib/emulator/functionsEmulator.js +11 -7
- package/lib/emulator/functionsEmulatorRuntime.js +9 -4
- package/lib/emulator/hub.js +12 -8
- package/lib/emulator/shared/express.js +30 -0
- package/lib/emulator/storage/apis/firebase.js +11 -10
- package/lib/emulator/storage/apis/gcloud.js +21 -20
- package/lib/emulator/storage/files.js +1 -1
- package/lib/emulator/storage/rules/manager.js +15 -12
- package/lib/emulator/storage/server.js +10 -5
- package/lib/experiments.js +5 -0
- package/lib/extensions/extensionsHelper.js +2 -2
- package/lib/extensions/listExtensions.js +1 -1
- package/lib/extensions/paramHelper.js +1 -1
- package/lib/extensions/provisioningHelper.js +1 -6
- package/lib/firestore/delete.js +2 -3
- package/lib/firestore/util.js +3 -3
- package/lib/frameworks/angular/utils.js +1 -1
- package/lib/frameworks/next/constants.js +17 -14
- package/lib/frameworks/next/index.js +25 -3
- package/lib/frameworks/next/utils.js +7 -9
- package/lib/functions/kits/install.js +221 -316
- package/lib/functions/kits/sources/directory.js +32 -0
- package/lib/functions/kits/sources/npm.js +55 -5
- package/lib/functionsConfig.js +0 -4
- package/lib/functionsShellCommandAction.js +1 -1
- package/lib/gcp/cloudbilling.js +2 -2
- package/lib/gcp/cloudbuild.js +0 -77
- package/lib/gcp/cloudfunctionsv2.js +0 -6
- package/lib/gcp/cloudtasks.js +0 -4
- package/lib/gcp/devConnect.js +2 -8
- package/lib/gcp/iam.js +15 -1
- package/lib/gcp/resourceManager.js +1 -14
- package/lib/gcp/storage.js +87 -4
- package/lib/hosting/api.js +79 -7
- package/lib/hosting/implicitInit.js +1 -1
- package/lib/hosting/proxy.js +5 -2
- package/lib/init/features/firestore/rules.js +1 -1
- package/lib/init/features/functions/index.js +2 -2
- package/lib/init/features/functions/npm-dependencies.js +1 -1
- package/lib/init/features/hosting/github.js +6 -4
- package/lib/init/features/hosting/index.js +4 -0
- package/lib/init/features/storage/rules.js +1 -1
- package/lib/localFunction.js +3 -3
- package/lib/management/database.js +1 -1
- package/lib/mcp/apps/init/mcp-app.js +5 -2
- package/lib/mcp/apps/update_environment/mcp-app.js +1 -1
- package/lib/mcp/index.js +14 -4
- package/lib/mcp/prompts/apptesting/run_test.js +3 -3
- package/lib/mcp/prompts/core/deploy.js +3 -3
- package/lib/mcp/resources/guides/init_ai.js +10 -10
- package/lib/mcp/tools/crashlytics/events.js +18 -93
- package/lib/mcp/tools/crashlytics/index.js +2 -0
- package/lib/mcp/tools/crashlytics/reports.js +3 -3
- package/lib/mcp/tools/crashlytics/setup.js +392 -0
- package/lib/mcp/util/dataconnect/converter.js +1 -1
- package/lib/profileReport.js +1 -1
- package/lib/profiler.js +1 -1
- package/lib/rulesDeploy.js +0 -1
- package/lib/throttler/throttler.js +1 -1
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +5 -11
- package/package.json +4 -4
- package/lib/functions/kits/sources/index.js +0 -19
|
@@ -24,15 +24,13 @@ exports.addKitToConfig = addKitToConfig;
|
|
|
24
24
|
exports.findKitConfig = findKitConfig;
|
|
25
25
|
exports.addInstanceToKitConfig = addInstanceToKitConfig;
|
|
26
26
|
exports.revertFunctionsConfig = revertFunctionsConfig;
|
|
27
|
-
exports.scaffoldKit = scaffoldKit;
|
|
28
27
|
exports.addInstanceToKit = addInstanceToKit;
|
|
29
28
|
exports.discoverKitBuild = discoverKitBuild;
|
|
30
29
|
exports.promptAndWriteKitParams = promptAndWriteKitParams;
|
|
31
30
|
exports.printKitFirstDeployReport = printKitFirstDeployReport;
|
|
32
|
-
exports.
|
|
33
|
-
exports.
|
|
34
|
-
exports.
|
|
35
|
-
exports.resolveDirectorySource = resolveDirectorySource;
|
|
31
|
+
exports.ensureKit = ensureKit;
|
|
32
|
+
exports.resolveOrCreateInstance = resolveOrCreateInstance;
|
|
33
|
+
exports.configureInstanceForProject = configureInstanceForProject;
|
|
36
34
|
exports.installKitOrInstance = installKitOrInstance;
|
|
37
35
|
const crypto = require("crypto");
|
|
38
36
|
const path = require("path");
|
|
@@ -44,7 +42,6 @@ const utils_1 = require("../../utils");
|
|
|
44
42
|
const projectConfig_1 = require("../projectConfig");
|
|
45
43
|
const logger_1 = require("../../logger");
|
|
46
44
|
const prompt_1 = require("../../prompt");
|
|
47
|
-
const supported = require("../../deploy/functions/runtimes/supported");
|
|
48
45
|
const runtimes = require("../../deploy/functions/runtimes");
|
|
49
46
|
const build = require("../../deploy/functions/build");
|
|
50
47
|
const params = require("../../deploy/functions/params");
|
|
@@ -54,11 +51,14 @@ const functionsEnv = require("../env");
|
|
|
54
51
|
const functionsConfig = require("../../functionsConfig");
|
|
55
52
|
const prepare_1 = require("../../deploy/functions/prepare");
|
|
56
53
|
const functional_1 = require("../../functional");
|
|
57
|
-
const env_1 = require("
|
|
58
|
-
const env_2 = require("./env");
|
|
54
|
+
const env_1 = require("./env");
|
|
59
55
|
const fsutils_1 = require("../../fsutils");
|
|
60
|
-
const
|
|
61
|
-
|
|
56
|
+
const types_1 = require("./sources/types");
|
|
57
|
+
const directory_1 = require("./sources/directory");
|
|
58
|
+
const npm_1 = require("./sources/npm");
|
|
59
|
+
__exportStar(require("./sources/types"), exports);
|
|
60
|
+
__exportStar(require("./sources/npm"), exports);
|
|
61
|
+
__exportStar(require("./sources/directory"), exports);
|
|
62
62
|
function generateUniqueId(baseId, existingIds) {
|
|
63
63
|
if (!existingIds.includes(baseId)) {
|
|
64
64
|
return baseId;
|
|
@@ -71,9 +71,10 @@ function generateUniqueId(baseId, existingIds) {
|
|
|
71
71
|
} while (existingIds.includes(candidate));
|
|
72
72
|
return candidate;
|
|
73
73
|
}
|
|
74
|
-
function getUnconfiguredInstancesForProject(
|
|
74
|
+
function getUnconfiguredInstancesForProject(options) {
|
|
75
|
+
const { config, kit, projectId, projectAlias } = options;
|
|
75
76
|
return Object.entries(kit.instances || {})
|
|
76
|
-
.filter(([, configDir]) => !
|
|
77
|
+
.filter(([, configDir]) => !functionsEnv.hasProjectEnv(config.path(configDir), projectId, projectAlias))
|
|
77
78
|
.map(([instanceId]) => instanceId);
|
|
78
79
|
}
|
|
79
80
|
function extractExistingFunctionsInfo(configFunctions) {
|
|
@@ -103,7 +104,8 @@ function extractExistingFunctionsInfo(configFunctions) {
|
|
|
103
104
|
existingInstanceIds,
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
|
-
async function promptKitInstanceId(
|
|
107
|
+
async function promptKitInstanceId(options) {
|
|
108
|
+
const { baseKitId, existingInstanceIds, existingCodebases, nonInteractive, customInstanceId } = options;
|
|
107
109
|
const instanceCollisions = [...existingInstanceIds, ...existingCodebases];
|
|
108
110
|
const defaultInstanceId = generateUniqueId(baseKitId, instanceCollisions);
|
|
109
111
|
if (customInstanceId) {
|
|
@@ -145,9 +147,9 @@ async function promptKitInstanceId(baseKitId, existingInstanceIds, existingCodeb
|
|
|
145
147
|
}
|
|
146
148
|
return instanceId;
|
|
147
149
|
}
|
|
148
|
-
async function promptKitId(
|
|
149
|
-
const baseKitId
|
|
150
|
-
const defaultKitId = generateUniqueId(baseKitId, existingKitIds);
|
|
150
|
+
async function promptKitId(options) {
|
|
151
|
+
const { baseKitId, existingKitIds, nonInteractive, customKitId } = options;
|
|
152
|
+
const defaultKitId = generateUniqueId(baseKitId || "kit", existingKitIds);
|
|
151
153
|
if (customKitId) {
|
|
152
154
|
(0, projectConfig_1.validateKit)(customKitId);
|
|
153
155
|
if (existingKitIds.includes(customKitId)) {
|
|
@@ -206,18 +208,15 @@ async function promptExistingInstanceForProject(options) {
|
|
|
206
208
|
nonInteractive: options.nonInteractive,
|
|
207
209
|
});
|
|
208
210
|
}
|
|
209
|
-
function addKitToConfig(
|
|
210
|
-
const configSrc = config.src;
|
|
211
|
+
function addKitToConfig(options) {
|
|
212
|
+
const configSrc = options.config.src;
|
|
211
213
|
const newKitConfig = {
|
|
212
214
|
kit: options.kitId,
|
|
213
|
-
...(options.
|
|
215
|
+
...(options.sourcePackage ? { sourcePackage: options.sourcePackage } : {}),
|
|
214
216
|
source: options.sourcePath,
|
|
215
|
-
instances: {
|
|
216
|
-
|
|
217
|
-
},
|
|
218
|
-
...(options.hasBuildScript ?? true
|
|
219
|
-
? { predeploy: ['npm --prefix "$RESOURCE_DIR" run build'] }
|
|
220
|
-
: {}),
|
|
217
|
+
instances: {},
|
|
218
|
+
...(options.runtime ? { runtime: options.runtime } : {}),
|
|
219
|
+
...(options.predeploy ? { predeploy: options.predeploy } : {}),
|
|
221
220
|
};
|
|
222
221
|
const functionsRaw = configSrc.functions;
|
|
223
222
|
if (!functionsRaw) {
|
|
@@ -229,7 +228,10 @@ function addKitToConfig(config, options) {
|
|
|
229
228
|
else {
|
|
230
229
|
configSrc.functions = [functionsRaw, newKitConfig];
|
|
231
230
|
}
|
|
232
|
-
|
|
231
|
+
if (options.write) {
|
|
232
|
+
options.config.writeProjectFile("firebase.json", configSrc);
|
|
233
|
+
}
|
|
234
|
+
return newKitConfig;
|
|
233
235
|
}
|
|
234
236
|
function findKitConfig(config, kitId) {
|
|
235
237
|
const functions = config.src.functions;
|
|
@@ -246,7 +248,8 @@ function findKitConfig(config, kitId) {
|
|
|
246
248
|
}
|
|
247
249
|
return undefined;
|
|
248
250
|
}
|
|
249
|
-
function addInstanceToKitConfig(
|
|
251
|
+
function addInstanceToKitConfig(options) {
|
|
252
|
+
const { config, kitId, instanceId, configDirPath } = options;
|
|
250
253
|
const target = findKitConfig(config, kitId);
|
|
251
254
|
if (!target) {
|
|
252
255
|
throw new error_1.FirebaseError(`Kit '${kitId}' not found in firebase.json.`);
|
|
@@ -271,55 +274,29 @@ function revertFunctionsConfig(options) {
|
|
|
271
274
|
logger_1.logger.debug(`Failed to revert firebase.json: ${(0, error_1.getErrMsg)(err)}`);
|
|
272
275
|
}
|
|
273
276
|
}
|
|
274
|
-
async function scaffoldKit(options) {
|
|
275
|
-
const paths = await (0, sources_1.scaffoldKitFiles)(options.config, options.kitId, options.instanceId, options.packageName, options.templateType);
|
|
276
|
-
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
277
|
-
(0, env_2.seedKitInstanceEnv)({
|
|
278
|
-
configDir: paths.absConfigDirPath,
|
|
279
|
-
functionsSource: paths.absSourcePath,
|
|
280
|
-
projectDir: options.config.projectDir,
|
|
281
|
-
projectId: options.seedEnv.projectId,
|
|
282
|
-
projectAlias: options.seedEnv.projectAlias,
|
|
283
|
-
envs: options.seedEnv.envs,
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
addKitToConfig(options.config, {
|
|
287
|
-
kitId: options.kitId,
|
|
288
|
-
instanceId: options.instanceId,
|
|
289
|
-
packageName: options.packageName,
|
|
290
|
-
sourcePath: paths.sourcePath,
|
|
291
|
-
configDirPath: paths.configDirPath,
|
|
292
|
-
});
|
|
293
|
-
return paths;
|
|
294
|
-
}
|
|
295
277
|
async function addInstanceToKit(options) {
|
|
296
278
|
const target = findKitConfig(options.config, options.kitId);
|
|
297
279
|
if (!target) {
|
|
298
280
|
throw new error_1.FirebaseError(`Kit '${options.kitId}' not found in firebase.json.`);
|
|
299
281
|
}
|
|
300
|
-
const configDirPath = path.join(
|
|
282
|
+
const configDirPath = path.join(types_1.FUNCTION_KITS_DIR, options.kitId, `config-${options.instanceId}`);
|
|
301
283
|
const absConfigDirPath = options.config.path(configDirPath);
|
|
302
284
|
await fs.ensureDir(absConfigDirPath);
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
projectAlias: options.seedEnv.projectAlias,
|
|
310
|
-
envs: options.seedEnv.envs,
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
addInstanceToKitConfig(options.config, options.kitId, options.instanceId, configDirPath);
|
|
285
|
+
addInstanceToKitConfig({
|
|
286
|
+
config: options.config,
|
|
287
|
+
kitId: options.kitId,
|
|
288
|
+
instanceId: options.instanceId,
|
|
289
|
+
configDirPath,
|
|
290
|
+
});
|
|
314
291
|
return { configDirPath, absConfigDirPath };
|
|
315
292
|
}
|
|
316
|
-
async function discoverKitBuild(options
|
|
293
|
+
async function discoverKitBuild(options) {
|
|
317
294
|
const projectId = (0, projectUtils_1.getProjectId)(options) || "";
|
|
318
295
|
const delegateContext = {
|
|
319
296
|
projectId,
|
|
320
|
-
sourceDir: absSourcePath,
|
|
297
|
+
sourceDir: options.absSourcePath,
|
|
321
298
|
projectDir: options.config?.projectDir || "",
|
|
322
|
-
runtime:
|
|
299
|
+
...(options.runtime ? { runtime: options.runtime } : {}),
|
|
323
300
|
};
|
|
324
301
|
const runtimeDelegate = await runtimes.getRuntimeDelegate(delegateContext);
|
|
325
302
|
const firebaseEnvs = functionsEnv.loadFirebaseEnvs({ projectId }, projectId, options.instanceId);
|
|
@@ -375,7 +352,7 @@ async function printKitFirstDeployReport(options) {
|
|
|
375
352
|
try {
|
|
376
353
|
discoveredBuild = options.preDiscoveredBuild
|
|
377
354
|
? (0, utils_1.cloneDeep)(options.preDiscoveredBuild)
|
|
378
|
-
: await discoverKitBuild(options
|
|
355
|
+
: await discoverKitBuild(options);
|
|
379
356
|
build.applyEndpointPrefix(discoveredBuild, prefix);
|
|
380
357
|
}
|
|
381
358
|
catch (err) {
|
|
@@ -424,109 +401,162 @@ async function printKitFirstDeployReport(options) {
|
|
|
424
401
|
(0, utils_1.logLabeledWarning)("functions", `${clc.bold("Please review the changes above. If you do not want them applied to your project, uninstall this kit before running firebase deploy.")}`);
|
|
425
402
|
}
|
|
426
403
|
}
|
|
427
|
-
async function
|
|
428
|
-
const {
|
|
404
|
+
async function ensureKit(options) {
|
|
405
|
+
const { config, adapter, existingFunctionsInfo, createdPaths = [] } = options;
|
|
406
|
+
const existingKit = adapter.findExistingKit(existingFunctionsInfo.existingFunctions);
|
|
407
|
+
if (existingKit) {
|
|
408
|
+
return { kit: existingKit, isNewKit: false };
|
|
409
|
+
}
|
|
410
|
+
await adapter.validateAndConfirm();
|
|
411
|
+
const kitId = await promptKitId({
|
|
412
|
+
baseKitId: adapter.defaultKitId,
|
|
413
|
+
existingKitIds: existingFunctionsInfo.existingKitIds,
|
|
414
|
+
nonInteractive: options.nonInteractive,
|
|
415
|
+
customKitId: options.kitId,
|
|
416
|
+
});
|
|
417
|
+
const prepared = await adapter.prepareSource(kitId);
|
|
418
|
+
if (prepared.createdPaths) {
|
|
419
|
+
createdPaths.push(...prepared.createdPaths);
|
|
420
|
+
}
|
|
421
|
+
const kit = addKitToConfig({
|
|
422
|
+
config,
|
|
423
|
+
kitId,
|
|
424
|
+
sourcePath: prepared.sourcePath,
|
|
425
|
+
sourcePackage: prepared.sourcePackage,
|
|
426
|
+
predeploy: prepared.predeploy,
|
|
427
|
+
});
|
|
428
|
+
return { kit, isNewKit: true };
|
|
429
|
+
}
|
|
430
|
+
async function resolveOrCreateInstance(options) {
|
|
431
|
+
const { kit, existingFunctionsInfo, createdPaths = [] } = options;
|
|
429
432
|
const projectId = (0, projectUtils_1.getProjectId)(options) || options.projectId;
|
|
430
433
|
const projectAlias = options.rc?.hasProjects && options.project && options.rc.hasProjectAlias(options.project)
|
|
431
434
|
? options.project
|
|
432
435
|
: undefined;
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (
|
|
437
|
-
|
|
438
|
-
Object.prototype.hasOwnProperty.call(existingKit.instances, options.instanceId)) {
|
|
439
|
-
if (!unconfiguredInstances.includes(options.instanceId)) {
|
|
440
|
-
throw new error_1.FirebaseError(`Instance '${options.instanceId}' is already configured for this project.`);
|
|
441
|
-
}
|
|
442
|
-
action = "addEnv";
|
|
443
|
-
}
|
|
444
|
-
else if (options.instanceId) {
|
|
445
|
-
action = "addInstance";
|
|
446
|
-
}
|
|
447
|
-
else if (unconfiguredInstances.length > 0 && !options.nonInteractive) {
|
|
448
|
-
const unconfiguredInstancesList = unconfiguredInstances.join(", ");
|
|
449
|
-
action = await (0, prompt_1.select)({
|
|
450
|
-
message: `The following instances already exist, but are not configured for this project: ${unconfiguredInstancesList}. What would you like to do?`,
|
|
451
|
-
choices: [
|
|
452
|
-
{
|
|
453
|
-
name: "Add an instance to the existing kit",
|
|
454
|
-
value: "addInstance",
|
|
455
|
-
},
|
|
456
|
-
{
|
|
457
|
-
name: "Configure an existing instance for this project",
|
|
458
|
-
value: "addEnv",
|
|
459
|
-
},
|
|
460
|
-
],
|
|
461
|
-
});
|
|
436
|
+
let mode;
|
|
437
|
+
let unconfiguredInstances = [];
|
|
438
|
+
const existingInstancesCount = Object.keys(kit.instances || {}).length;
|
|
439
|
+
if (existingInstancesCount === 0) {
|
|
440
|
+
mode = "addInstance";
|
|
462
441
|
}
|
|
463
442
|
else {
|
|
464
|
-
|
|
465
|
-
|
|
443
|
+
unconfiguredInstances = getUnconfiguredInstancesForProject({
|
|
444
|
+
config: options.config,
|
|
445
|
+
kit,
|
|
446
|
+
projectId,
|
|
447
|
+
projectAlias,
|
|
448
|
+
});
|
|
449
|
+
const isConfiguredForProject = existingInstancesCount > 0 && unconfiguredInstances.length === 0;
|
|
450
|
+
if (options.instanceId &&
|
|
451
|
+
kit.instances &&
|
|
452
|
+
Object.prototype.hasOwnProperty.call(kit.instances, options.instanceId)) {
|
|
453
|
+
if (!unconfiguredInstances.includes(options.instanceId)) {
|
|
454
|
+
throw new error_1.FirebaseError(`Instance '${options.instanceId}' is already configured for this project.`);
|
|
455
|
+
}
|
|
456
|
+
mode = "addEnv";
|
|
457
|
+
}
|
|
458
|
+
else if (options.instanceId) {
|
|
459
|
+
mode = "addInstance";
|
|
460
|
+
}
|
|
461
|
+
else if (unconfiguredInstances.length > 0 && !options.nonInteractive) {
|
|
462
|
+
const unconfiguredInstancesList = unconfiguredInstances.join(", ");
|
|
463
|
+
mode = await (0, prompt_1.select)({
|
|
464
|
+
message: `The following instances already exist, but are not configured for this project: ${unconfiguredInstancesList}. What would you like to do?`,
|
|
465
|
+
choices: [
|
|
466
|
+
{
|
|
467
|
+
name: "Add an instance to the existing kit",
|
|
468
|
+
value: "addInstance",
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
name: "Configure an existing instance for this project",
|
|
472
|
+
value: "addEnv",
|
|
473
|
+
},
|
|
474
|
+
],
|
|
475
|
+
});
|
|
466
476
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
477
|
+
else {
|
|
478
|
+
if (isConfiguredForProject) {
|
|
479
|
+
const sourceLabel = kit.sourcePackage ? "package" : "directory";
|
|
480
|
+
(0, utils_1.logLabeledBullet)("functions", `This ${sourceLabel} is already installed as kit ${kit.kit}, creating a new instance.`);
|
|
481
|
+
}
|
|
482
|
+
mode = "addInstance";
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (mode === "addInstance") {
|
|
486
|
+
const instanceId = await promptKitInstanceId({
|
|
487
|
+
baseKitId: options.defaultInstanceId ?? kit.kit,
|
|
488
|
+
existingInstanceIds: existingFunctionsInfo.existingInstanceIds,
|
|
489
|
+
existingCodebases: existingFunctionsInfo.existingCodebases,
|
|
490
|
+
nonInteractive: options.nonInteractive,
|
|
491
|
+
customInstanceId: options.instanceId,
|
|
492
|
+
});
|
|
479
493
|
const result = await addInstanceToKit({
|
|
480
494
|
config: options.config,
|
|
481
|
-
kitId:
|
|
495
|
+
kitId: kit.kit,
|
|
482
496
|
instanceId,
|
|
483
|
-
seedEnv: options.seedEnv,
|
|
484
497
|
});
|
|
485
|
-
|
|
486
|
-
|
|
498
|
+
createdPaths.push(result.absConfigDirPath);
|
|
499
|
+
return {
|
|
500
|
+
instanceId,
|
|
501
|
+
configDirPath: result.configDirPath,
|
|
502
|
+
absConfigDirPath: result.absConfigDirPath,
|
|
503
|
+
isNewInstance: true,
|
|
504
|
+
};
|
|
487
505
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
506
|
+
const instanceId = await promptExistingInstanceForProject({
|
|
507
|
+
...options,
|
|
508
|
+
existingKit: kit,
|
|
509
|
+
unconfiguredInstanceIds: unconfiguredInstances,
|
|
510
|
+
});
|
|
511
|
+
const configDirPath = kit.instances?.[instanceId];
|
|
512
|
+
if (!configDirPath) {
|
|
513
|
+
throw new error_1.FirebaseError(`Configuration directory for instance '${instanceId}' not found in kit '${kit.kit}'.`);
|
|
514
|
+
}
|
|
515
|
+
const absConfigDirPath = options.config.path(configDirPath);
|
|
516
|
+
return {
|
|
517
|
+
instanceId,
|
|
518
|
+
configDirPath,
|
|
519
|
+
absConfigDirPath,
|
|
520
|
+
isNewInstance: false,
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
async function configureInstanceForProject(options) {
|
|
524
|
+
const { kit, instanceId, absConfigDirPath, createdPaths = [] } = options;
|
|
525
|
+
const projectId = (0, projectUtils_1.getProjectId)(options) || options.projectId;
|
|
526
|
+
const projectAlias = options.rc?.hasProjects && options.project && options.rc.hasProjectAlias(options.project)
|
|
527
|
+
? options.project
|
|
528
|
+
: undefined;
|
|
529
|
+
const absSourcePath = options.config.path(kit.source);
|
|
530
|
+
if (projectId) {
|
|
531
|
+
const envPath = path.join(absConfigDirPath, `.env.${projectId}`);
|
|
532
|
+
if (!(await fs.pathExists(envPath))) {
|
|
533
|
+
createdPaths.push(envPath);
|
|
516
534
|
}
|
|
517
535
|
}
|
|
518
|
-
|
|
519
|
-
|
|
536
|
+
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
537
|
+
await fs.ensureDir(absConfigDirPath);
|
|
538
|
+
(0, env_1.seedKitInstanceEnv)({
|
|
539
|
+
configDir: absConfigDirPath,
|
|
540
|
+
functionsSource: absSourcePath,
|
|
541
|
+
projectDir: options.config.projectDir,
|
|
542
|
+
projectId: options.seedEnv.projectId,
|
|
543
|
+
projectAlias: options.seedEnv.projectAlias,
|
|
544
|
+
envs: options.seedEnv.envs,
|
|
545
|
+
});
|
|
520
546
|
}
|
|
521
547
|
if (projectId) {
|
|
522
548
|
fs.ensureFileSync(path.join(absConfigDirPath, `.env.${projectId}`));
|
|
523
549
|
}
|
|
524
|
-
const absSourcePath = options.config.path(existingKit.source);
|
|
525
550
|
let discoveredBuild;
|
|
526
551
|
const shouldConfigure = options.configure !== false;
|
|
527
552
|
if (shouldConfigure) {
|
|
528
553
|
try {
|
|
529
|
-
discoveredBuild = await discoverKitBuild({
|
|
554
|
+
discoveredBuild = await discoverKitBuild({
|
|
555
|
+
...options,
|
|
556
|
+
absSourcePath,
|
|
557
|
+
instanceId,
|
|
558
|
+
runtime: kit.runtime,
|
|
559
|
+
});
|
|
530
560
|
}
|
|
531
561
|
catch (err) {
|
|
532
562
|
logger_1.logger.debug(`Could not discover kit build for params prompting: ${(0, error_1.getErrMsg)(err)}`);
|
|
@@ -544,202 +574,77 @@ async function addKitInstanceOrConfigureProject(options) {
|
|
|
544
574
|
});
|
|
545
575
|
}
|
|
546
576
|
}
|
|
547
|
-
|
|
548
|
-
(0, utils_1.logLabeledSuccess)("functions", `Function kit instance ${clc.bold(instanceId)} successfully added to kit ${clc.bold(existingKit.kit)}.`);
|
|
549
|
-
}
|
|
550
|
-
else if (action === "addEnv") {
|
|
551
|
-
const projectDisplay = projectId || options.project || "project";
|
|
552
|
-
(0, utils_1.logLabeledSuccess)("functions", `Function kit instance ${clc.bold(instanceId)} successfully configured for ${clc.bold(projectDisplay)}.`);
|
|
553
|
-
}
|
|
554
|
-
await printKitFirstDeployReport({
|
|
555
|
-
config: options.config,
|
|
556
|
-
project: options.project,
|
|
557
|
-
projectId: options.projectId,
|
|
558
|
-
instanceId,
|
|
559
|
-
absSourcePath,
|
|
560
|
-
preDiscoveredBuild: discoveredBuild,
|
|
561
|
-
});
|
|
562
|
-
return {
|
|
563
|
-
action: resultAction,
|
|
564
|
-
kitId: existingKit.kit,
|
|
565
|
-
instanceId,
|
|
566
|
-
sourcePath: existingKit.source,
|
|
567
|
-
configDirPath,
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
function findExistingKit(existingFunctions, options) {
|
|
571
|
-
if (options.package) {
|
|
572
|
-
const { packageName } = (0, sources_1.parseNpmPackageSpecifier)(options.package);
|
|
573
|
-
return existingFunctions.find((c) => (0, projectConfig_1.isKitConfig)(c) && c.sourcePackage?.name === packageName);
|
|
574
|
-
}
|
|
575
|
-
if (options.directory) {
|
|
576
|
-
const absDir = path.isAbsolute(options.directory)
|
|
577
|
-
? options.directory
|
|
578
|
-
: path.resolve(options.config.projectDir, options.directory);
|
|
579
|
-
return existingFunctions.find((c) => (0, projectConfig_1.isKitConfig)(c) &&
|
|
580
|
-
!c.sourcePackage &&
|
|
581
|
-
path.resolve(options.config.projectDir, c.source) === absDir);
|
|
582
|
-
}
|
|
583
|
-
return undefined;
|
|
584
|
-
}
|
|
585
|
-
async function resolvePackageSource(options) {
|
|
586
|
-
const templateType = options.template || sources_1.DEFAULT_TEMPLATE;
|
|
587
|
-
if (!(templateType in sources_1.TEMPLATES)) {
|
|
588
|
-
const validTemplates = Object.keys(sources_1.TEMPLATES)
|
|
589
|
-
.map((t) => `'${t}'`)
|
|
590
|
-
.join(" or ");
|
|
591
|
-
throw new error_1.FirebaseError(`Invalid template '${templateType}'. Template must be ${validTemplates}.`);
|
|
592
|
-
}
|
|
593
|
-
const rawPkgName = options.package;
|
|
594
|
-
if (!rawPkgName) {
|
|
595
|
-
throw new error_1.FirebaseError("Set the --package option to a valid NPM package and try again.");
|
|
596
|
-
}
|
|
597
|
-
await (0, sources_1.validateNpmPackageExists)(rawPkgName);
|
|
598
|
-
const { packageName } = (0, sources_1.parseNpmPackageSpecifier)(rawPkgName);
|
|
599
|
-
const isThirdParty = await (0, sources_1.promptSecurityConfirmation)({
|
|
600
|
-
rawPkgName,
|
|
601
|
-
packageName,
|
|
602
|
-
nonInteractive: options.nonInteractive,
|
|
603
|
-
force: options.force,
|
|
604
|
-
});
|
|
605
|
-
return {
|
|
606
|
-
defaultKitName: packageName,
|
|
607
|
-
sourcePackageName: packageName,
|
|
608
|
-
hasBuildScript: true,
|
|
609
|
-
setup: (kitId, instanceId) => (0, sources_1.scaffoldKitFiles)(options.config, kitId, instanceId, packageName, templateType),
|
|
610
|
-
buildAndInstall: (absSourcePath) => (0, sources_1.buildAndInstallKit)(absSourcePath, rawPkgName, isThirdParty),
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
async function resolveDirectorySource(options) {
|
|
614
|
-
if (!options.directory) {
|
|
615
|
-
throw new error_1.FirebaseError("Must specify --directory.");
|
|
616
|
-
}
|
|
617
|
-
const { absDirectoryPath, relSourcePath, hasBuildScript } = await (0, sources_1.validateAndResolveDirectoryKit)(options.config.projectDir, options.directory);
|
|
618
|
-
return {
|
|
619
|
-
defaultKitName: path.basename(absDirectoryPath),
|
|
620
|
-
sourcePackageName: undefined,
|
|
621
|
-
hasBuildScript,
|
|
622
|
-
setup: async (kitId, instanceId) => {
|
|
623
|
-
const configDirPath = path.join(sources_1.FUNCTION_KITS_DIR, kitId, `config-${instanceId}`);
|
|
624
|
-
const absConfigDirPath = options.config.path(configDirPath);
|
|
625
|
-
await fs.ensureDir(absConfigDirPath);
|
|
626
|
-
return {
|
|
627
|
-
sourcePath: relSourcePath,
|
|
628
|
-
configDirPath,
|
|
629
|
-
absSourcePath: absDirectoryPath,
|
|
630
|
-
absConfigDirPath,
|
|
631
|
-
};
|
|
632
|
-
},
|
|
633
|
-
buildAndInstall: (absSourcePath) => (0, sources_1.buildAndInstallDirectoryKit)(absSourcePath, hasBuildScript),
|
|
634
|
-
};
|
|
577
|
+
return discoveredBuild;
|
|
635
578
|
}
|
|
636
579
|
async function installKitOrInstance(options) {
|
|
637
580
|
if (options.package && options.directory) {
|
|
638
581
|
throw new error_1.FirebaseError("Cannot specify both --package and --directory. Please choose one.");
|
|
639
582
|
}
|
|
640
|
-
if (!options.package && !options.directory) {
|
|
641
|
-
throw new error_1.FirebaseError("Must specify either --package or --directory.");
|
|
642
|
-
}
|
|
643
583
|
if (options.directory && options.template) {
|
|
644
584
|
throw new error_1.FirebaseError("Cannot specify --template with --directory.");
|
|
645
585
|
}
|
|
646
|
-
if (options.package) {
|
|
647
|
-
|
|
586
|
+
if (!options.package && !options.directory) {
|
|
587
|
+
throw new error_1.FirebaseError("Must specify either --package or --directory.");
|
|
648
588
|
}
|
|
589
|
+
const adapter = options.directory
|
|
590
|
+
? (0, directory_1.createDirectoryAdapter)(options.config, options.directory)
|
|
591
|
+
: (0, npm_1.createNpmPackageAdapter)({
|
|
592
|
+
config: options.config,
|
|
593
|
+
package: options.package || "",
|
|
594
|
+
template: options.template,
|
|
595
|
+
nonInteractive: options.nonInteractive,
|
|
596
|
+
force: options.force,
|
|
597
|
+
});
|
|
649
598
|
const originalFunctions = (0, utils_1.cloneDeep)(options.config.src.functions);
|
|
650
599
|
const createdPaths = [];
|
|
651
600
|
let kitId;
|
|
652
601
|
try {
|
|
653
602
|
const existingFunctionsInfo = extractExistingFunctionsInfo(options.config.src.functions);
|
|
654
|
-
const existingKit = findExistingKit(existingFunctionsInfo.existingFunctions, options);
|
|
655
|
-
if (existingKit) {
|
|
656
|
-
kitId = existingKit.kit;
|
|
657
|
-
return await addKitInstanceOrConfigureProject({
|
|
658
|
-
...options,
|
|
659
|
-
existingKit,
|
|
660
|
-
existingFunctionsInfo,
|
|
661
|
-
createdPaths,
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
const source = options.directory
|
|
665
|
-
? await resolveDirectorySource(options)
|
|
666
|
-
: await resolvePackageSource(options);
|
|
667
|
-
kitId = await promptKitId(source.defaultKitName, existingFunctionsInfo.existingKitIds, options.nonInteractive, options.kitId);
|
|
668
|
-
const instanceId = await promptKitInstanceId(options.defaultInstanceId ?? kitId, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
669
|
-
const isPackageKit = !options.directory;
|
|
670
|
-
const absKitDir = options.config.path(path.join(sources_1.FUNCTION_KITS_DIR, kitId));
|
|
671
|
-
const expectedConfigDirPath = path.join(sources_1.FUNCTION_KITS_DIR, kitId, `config-${instanceId}`);
|
|
672
|
-
const absConfigDirPath = options.config.path(expectedConfigDirPath);
|
|
673
|
-
if (isPackageKit) {
|
|
674
|
-
createdPaths.push(absKitDir);
|
|
675
|
-
}
|
|
676
|
-
else {
|
|
677
|
-
createdPaths.push(absConfigDirPath);
|
|
678
|
-
}
|
|
679
|
-
const setupResult = await source.setup(kitId, instanceId);
|
|
680
|
-
const { sourcePath, configDirPath, absSourcePath } = setupResult;
|
|
681
|
-
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
682
|
-
(0, env_2.seedKitInstanceEnv)({
|
|
683
|
-
configDir: setupResult.absConfigDirPath,
|
|
684
|
-
functionsSource: absSourcePath,
|
|
685
|
-
projectDir: options.config.projectDir,
|
|
686
|
-
projectId: options.seedEnv.projectId,
|
|
687
|
-
projectAlias: options.seedEnv.projectAlias,
|
|
688
|
-
envs: options.seedEnv.envs,
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
await source.buildAndInstall(absSourcePath);
|
|
692
603
|
const projectId = (0, projectUtils_1.getProjectId)(options) || options.projectId;
|
|
693
|
-
const
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
await promptAndWriteKitParams({
|
|
710
|
-
config: options.config,
|
|
711
|
-
projectId,
|
|
712
|
-
projectAlias,
|
|
713
|
-
absConfigDirPath: setupResult.absConfigDirPath,
|
|
714
|
-
absSourcePath,
|
|
715
|
-
instanceId,
|
|
716
|
-
nonInteractive: options.nonInteractive,
|
|
717
|
-
params: discoveredBuild.params,
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
addKitToConfig(options.config, {
|
|
722
|
-
kitId,
|
|
604
|
+
const { kit, isNewKit } = await ensureKit({
|
|
605
|
+
...options,
|
|
606
|
+
adapter,
|
|
607
|
+
existingFunctionsInfo,
|
|
608
|
+
createdPaths,
|
|
609
|
+
});
|
|
610
|
+
kitId = kit.kit;
|
|
611
|
+
const { instanceId, configDirPath, absConfigDirPath, isNewInstance } = await resolveOrCreateInstance({
|
|
612
|
+
...options,
|
|
613
|
+
kit,
|
|
614
|
+
existingFunctionsInfo,
|
|
615
|
+
createdPaths,
|
|
616
|
+
});
|
|
617
|
+
const discoveredBuild = await configureInstanceForProject({
|
|
618
|
+
...options,
|
|
619
|
+
kit,
|
|
723
620
|
instanceId,
|
|
724
|
-
packageName: source.sourcePackageName,
|
|
725
|
-
sourcePath,
|
|
726
621
|
configDirPath,
|
|
727
|
-
|
|
622
|
+
absConfigDirPath,
|
|
623
|
+
createdPaths,
|
|
728
624
|
});
|
|
729
|
-
(
|
|
625
|
+
if (isNewKit) {
|
|
626
|
+
(0, utils_1.logLabeledSuccess)("functions", `Function kit ${clc.bold(kit.kit)} successfully installed.`);
|
|
627
|
+
}
|
|
628
|
+
else if (isNewInstance) {
|
|
629
|
+
(0, utils_1.logLabeledSuccess)("functions", `Function kit instance ${clc.bold(instanceId)} successfully added to kit ${clc.bold(kit.kit)}.`);
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
const projectDisplay = projectId || options.project || "project";
|
|
633
|
+
(0, utils_1.logLabeledSuccess)("functions", `Function kit instance ${clc.bold(instanceId)} successfully configured for ${clc.bold(projectDisplay)}.`);
|
|
634
|
+
}
|
|
730
635
|
await printKitFirstDeployReport({
|
|
731
636
|
config: options.config,
|
|
732
637
|
project: options.project,
|
|
733
638
|
projectId: options.projectId,
|
|
734
639
|
instanceId,
|
|
735
|
-
absSourcePath,
|
|
640
|
+
absSourcePath: options.config.path(kit.source),
|
|
641
|
+
runtime: kit.runtime,
|
|
736
642
|
preDiscoveredBuild: discoveredBuild,
|
|
737
643
|
});
|
|
738
644
|
return {
|
|
739
|
-
|
|
740
|
-
kitId,
|
|
645
|
+
kitId: kit.kit,
|
|
741
646
|
instanceId,
|
|
742
|
-
sourcePath,
|
|
647
|
+
sourcePath: kit.source,
|
|
743
648
|
configDirPath,
|
|
744
649
|
};
|
|
745
650
|
}
|
|
@@ -748,9 +653,9 @@ async function installKitOrInstance(options) {
|
|
|
748
653
|
logger_1.logger.debug(`Failed to clean up path '${targetPath}': ${(0, error_1.getErrMsg)(cleanupErr)}`);
|
|
749
654
|
})));
|
|
750
655
|
if (kitId) {
|
|
751
|
-
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(path.join(
|
|
656
|
+
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(path.join(types_1.FUNCTION_KITS_DIR, kitId)));
|
|
752
657
|
}
|
|
753
|
-
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(
|
|
658
|
+
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(types_1.FUNCTION_KITS_DIR));
|
|
754
659
|
revertFunctionsConfig({ config: options.config, originalFunctions });
|
|
755
660
|
throw err;
|
|
756
661
|
}
|