firebase-tools 15.34.1 → 15.35.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/api.js +2 -4
- package/lib/apphosting/constants.js +1 -4
- package/lib/apphosting/utils.js +0 -26
- package/lib/commands/apps-android-sha-create.js +1 -1
- package/lib/commands/apps-android-sha-delete.js +1 -1
- package/lib/commands/apps-android-sha-list.js +1 -1
- package/lib/commands/{crashlytics-onboard-web.js → crashlytics-setup.js} +5 -5
- package/lib/commands/crashlytics-sourcemap-upload.js +4 -0
- package/lib/commands/emulators-start.js +2 -2
- package/lib/commands/index.js +5 -6
- package/lib/commands/run-services-get.js +19 -0
- package/lib/commands/run-services-list.js +11 -0
- package/lib/crashlytics/alerts.js +1 -0
- package/lib/crashlytics/firebasetelemetry.js +5 -3
- package/lib/crashlytics/onboarding.js +15 -23
- package/lib/crashlytics/reports.js +46 -17
- package/lib/crashlytics/sourcemap.js +19 -5
- package/lib/dataconnect/dataplaneClient.js +0 -10
- package/lib/deploy/apphosting/deploy.js +20 -41
- package/lib/deploy/apphosting/localBuild.js +49 -0
- package/lib/deploy/apphosting/prepare.js +12 -25
- package/lib/deploy/apphosting/release.js +1 -1
- package/lib/deploy/apphosting/util.js +27 -4
- package/lib/deploy/functions/containerCleaner.js +1 -142
- package/lib/deploy/functions/functionsDeployHelper.js +0 -4
- package/lib/deploy/functions/release/fabricator.js +6 -3
- package/lib/deploy/functions/validate.js +1 -1
- package/lib/deploy/run/deploy.js +26 -43
- package/lib/deploy/run/get.js +30 -0
- package/lib/deploy/run/list.js +38 -0
- package/lib/deploy/run/prereqs.js +0 -3
- package/lib/deploy/run/util.js +9 -0
- package/lib/emulator/commandUtils.js +105 -23
- package/lib/emulator/dataconnect/pgliteServer.js +1 -0
- package/lib/emulator/downloadableEmulatorInfo.json +22 -22
- package/lib/emulator/downloadableEmulators.js +43 -5
- package/lib/emulator/firestoreEmulator.js +5 -0
- package/lib/emulator/functionsEmulator.js +22 -7
- package/lib/emulator/pubsubEmulator.js +64 -11
- package/lib/emulator/storage/rules/manager.js +31 -15
- package/lib/emulator/storage/rules/runtime.js +1 -0
- package/lib/emulator/taskQueue.js +5 -4
- package/lib/experiments.js +0 -5
- package/lib/extensions/emulator/specHelper.js +0 -4
- package/lib/extensions/extensionsApi.js +0 -8
- package/lib/extensions/extensionsHelper.js +1 -71
- package/lib/extensions/runtimes/common.js +0 -12
- package/lib/extensions/secretsUtils.js +0 -24
- package/lib/extensions/updateHelper.js +2 -88
- package/lib/frameworks/angular/utils.js +3 -2
- package/lib/frameworks/next/utils.js +0 -11
- package/lib/fsAsync.js +34 -20
- package/lib/functions/kits/install.js +37 -337
- package/lib/functions/kits/sources/directory.js +59 -0
- package/lib/functions/kits/sources/index.js +19 -0
- package/lib/functions/kits/sources/npm.js +274 -0
- package/lib/functions/kits/sources/types.js +12 -0
- package/lib/gcp/artifactregistry.js +0 -5
- package/lib/gcp/cloudlogging.js +0 -54
- package/lib/gcp/iam.js +0 -4
- package/lib/gcp/pubsub.js +0 -14
- package/lib/gcp/storage.js +2 -1
- package/lib/init/features/aitools/promptUpdater.js +3 -2
- package/lib/init/features/run.js +3 -7
- package/lib/mcp/errors.js +1 -1
- package/lib/mcp/resources/guides/crashlytics_reports.js +33 -71
- package/lib/mcp/tools/crashlytics/reports.js +25 -30
- package/lib/mcp/util/dataconnect/converter.js +0 -29
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +9 -6
- package/lib/apphosting/repo.js +0 -243
- package/lib/deploy/hosting/args.js +0 -2
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FUNCTION_KITS_DIR = exports.DEFAULT_TEMPLATE = exports.TEMPLATES = void 0;
|
|
4
17
|
exports.generateUniqueId = generateUniqueId;
|
|
5
|
-
exports.parseNpmPackageSpecifier = parseNpmPackageSpecifier;
|
|
6
|
-
exports.validateNpmPackageName = validateNpmPackageName;
|
|
7
|
-
exports.validateNpmPackageExists = validateNpmPackageExists;
|
|
8
|
-
exports.sanitizePackageNameToKitName = sanitizePackageNameToKitName;
|
|
9
|
-
exports.isThirdPartyPackage = isThirdPartyPackage;
|
|
10
|
-
exports.checkPackageHasShrinkwrap = checkPackageHasShrinkwrap;
|
|
11
18
|
exports.getUnconfiguredInstancesForProject = getUnconfiguredInstancesForProject;
|
|
12
19
|
exports.extractExistingFunctionsInfo = extractExistingFunctionsInfo;
|
|
13
20
|
exports.promptKitInstanceId = promptKitInstanceId;
|
|
14
21
|
exports.promptKitId = promptKitId;
|
|
15
|
-
exports.promptSecurityConfirmation = promptSecurityConfirmation;
|
|
16
22
|
exports.promptExistingInstanceForProject = promptExistingInstanceForProject;
|
|
17
|
-
exports.writeKitPackageJson = writeKitPackageJson;
|
|
18
|
-
exports.writeKitIndexTs = writeKitIndexTs;
|
|
19
|
-
exports.scaffoldKitFiles = scaffoldKitFiles;
|
|
20
|
-
exports.resolveSdkSpecifierToSave = resolveSdkSpecifierToSave;
|
|
21
|
-
exports.getKitPackagesToSave = getKitPackagesToSave;
|
|
22
|
-
exports.buildAndInstallKit = buildAndInstallKit;
|
|
23
23
|
exports.addKitToConfig = addKitToConfig;
|
|
24
|
-
exports.validateAndResolveDirectoryKit = validateAndResolveDirectoryKit;
|
|
25
|
-
exports.buildAndInstallDirectoryKit = buildAndInstallDirectoryKit;
|
|
26
24
|
exports.findKitConfig = findKitConfig;
|
|
27
25
|
exports.addInstanceToKitConfig = addInstanceToKitConfig;
|
|
28
26
|
exports.revertFunctionsConfig = revertFunctionsConfig;
|
|
@@ -40,15 +38,12 @@ const crypto = require("crypto");
|
|
|
40
38
|
const path = require("path");
|
|
41
39
|
const clc = require("colorette");
|
|
42
40
|
const fs = require("fs-extra");
|
|
43
|
-
const semver = require("semver");
|
|
44
41
|
const error_1 = require("../../error");
|
|
45
42
|
const projectUtils_1 = require("../../projectUtils");
|
|
46
43
|
const utils_1 = require("../../utils");
|
|
47
44
|
const projectConfig_1 = require("../projectConfig");
|
|
48
45
|
const logger_1 = require("../../logger");
|
|
49
46
|
const prompt_1 = require("../../prompt");
|
|
50
|
-
const spawn_1 = require("../../init/spawn");
|
|
51
|
-
const templates_1 = require("../../templates");
|
|
52
47
|
const supported = require("../../deploy/functions/runtimes/supported");
|
|
53
48
|
const runtimes = require("../../deploy/functions/runtimes");
|
|
54
49
|
const build = require("../../deploy/functions/build");
|
|
@@ -62,12 +57,8 @@ const functional_1 = require("../../functional");
|
|
|
62
57
|
const env_1 = require("../env");
|
|
63
58
|
const env_2 = require("./env");
|
|
64
59
|
const fsutils_1 = require("../../fsutils");
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
migration: "init/functions/typescript/index-kit-migration.ts",
|
|
68
|
-
};
|
|
69
|
-
exports.DEFAULT_TEMPLATE = "installation";
|
|
70
|
-
exports.FUNCTION_KITS_DIR = "function-kits";
|
|
60
|
+
const sources_1 = require("./sources");
|
|
61
|
+
__exportStar(require("./sources"), exports);
|
|
71
62
|
function generateUniqueId(baseId, existingIds) {
|
|
72
63
|
if (!existingIds.includes(baseId)) {
|
|
73
64
|
return baseId;
|
|
@@ -80,69 +71,6 @@ function generateUniqueId(baseId, existingIds) {
|
|
|
80
71
|
} while (existingIds.includes(candidate));
|
|
81
72
|
return candidate;
|
|
82
73
|
}
|
|
83
|
-
function parseNpmPackageSpecifier(rawPkg) {
|
|
84
|
-
const lastAt = rawPkg.lastIndexOf("@");
|
|
85
|
-
if (lastAt > 0) {
|
|
86
|
-
const version = rawPkg.substring(lastAt + 1);
|
|
87
|
-
return {
|
|
88
|
-
packageName: rawPkg.substring(0, lastAt),
|
|
89
|
-
...(version ? { version } : {}),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
return { packageName: rawPkg };
|
|
93
|
-
}
|
|
94
|
-
function validateNpmPackageName(packageNameOrSpecifier) {
|
|
95
|
-
const { packageName, version } = parseNpmPackageSpecifier(packageNameOrSpecifier);
|
|
96
|
-
const npmPackageRegex = /^(?:@[a-z0-9_.-]+\/[a-z0-9_.-]+|[a-z0-9_.-]+)$/i;
|
|
97
|
-
if (!packageName ||
|
|
98
|
-
packageName.length > 214 ||
|
|
99
|
-
!npmPackageRegex.test(packageName) ||
|
|
100
|
-
(packageNameOrSpecifier.lastIndexOf("@") > 0 && !version)) {
|
|
101
|
-
throw new error_1.FirebaseError(`Invalid NPM package name '${packageNameOrSpecifier}'. Package names must be valid npm package specifiers (e.g. 'my-kit' or '@scope/my-kit').`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async function validateNpmPackageExists(rawPkgName) {
|
|
105
|
-
validateNpmPackageName(rawPkgName);
|
|
106
|
-
try {
|
|
107
|
-
const output = await (0, spawn_1.spawnWithOutput)("npm", ["view", rawPkgName, "version"]);
|
|
108
|
-
if (!output.trim()) {
|
|
109
|
-
throw new Error(`No version found for '${rawPkgName}'`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (err) {
|
|
113
|
-
throw new error_1.FirebaseError(`NPM package '${rawPkgName}' could not be found in the npm registry. Please verify the package name and version.`, { original: err instanceof Error ? err : undefined });
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function sanitizePackageNameToKitName(packageNameOrSpecifier) {
|
|
117
|
-
const { packageName } = parseNpmPackageSpecifier(packageNameOrSpecifier);
|
|
118
|
-
const parts = packageName.split("/");
|
|
119
|
-
const nameWithoutScope = parts[parts.length - 1] || packageName;
|
|
120
|
-
const sanitized = nameWithoutScope.toLowerCase().replace(/[^a-z0-9_-]/g, "");
|
|
121
|
-
return sanitized.slice(0, 40);
|
|
122
|
-
}
|
|
123
|
-
function isThirdPartyPackage(packageNameOrSpecifier) {
|
|
124
|
-
const { packageName } = parseNpmPackageSpecifier(packageNameOrSpecifier);
|
|
125
|
-
return !packageName.startsWith("@firebase-function-kits/");
|
|
126
|
-
}
|
|
127
|
-
async function checkPackageHasShrinkwrap(rawPkgName) {
|
|
128
|
-
try {
|
|
129
|
-
const output = await (0, spawn_1.spawnWithOutput)("npm", ["pack", rawPkgName, "--dry-run", "--json"]);
|
|
130
|
-
const parsed = JSON.parse(output);
|
|
131
|
-
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
132
|
-
const pkgInfo = parsed[0];
|
|
133
|
-
if (pkgInfo.hasShrinkwrap) {
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
if (Array.isArray(pkgInfo.files)) {
|
|
137
|
-
return pkgInfo.files.some((f) => f.path === "npm-shrinkwrap.json" || f.path === "npm-shrinkwrap.js");
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
catch (err) {
|
|
142
|
-
logger_1.logger.debug(`Failed to inspect package shrinkwrap for ${rawPkgName}: ${(0, error_1.getErrMsg)(err)}`);
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
74
|
function getUnconfiguredInstancesForProject(config, kit, projectId, projectAlias) {
|
|
147
75
|
return Object.entries(kit.instances || {})
|
|
148
76
|
.filter(([, configDir]) => !(0, env_1.hasProjectEnv)(config.path(configDir), projectId, projectAlias))
|
|
@@ -218,7 +146,7 @@ async function promptKitInstanceId(baseKitId, existingInstanceIds, existingCodeb
|
|
|
218
146
|
return instanceId;
|
|
219
147
|
}
|
|
220
148
|
async function promptKitId(packageName, existingKitIds, nonInteractive, customKitId) {
|
|
221
|
-
const baseKitId = sanitizePackageNameToKitName(packageName) || "kit";
|
|
149
|
+
const baseKitId = (0, sources_1.sanitizePackageNameToKitName)(packageName) || "kit";
|
|
222
150
|
const defaultKitId = generateUniqueId(baseKitId, existingKitIds);
|
|
223
151
|
if (customKitId) {
|
|
224
152
|
(0, projectConfig_1.validateKit)(customKitId);
|
|
@@ -250,39 +178,6 @@ async function promptKitId(packageName, existingKitIds, nonInteractive, customKi
|
|
|
250
178
|
}
|
|
251
179
|
return kitId;
|
|
252
180
|
}
|
|
253
|
-
async function promptSecurityConfirmation(options) {
|
|
254
|
-
const { rawPkgName, packageName, nonInteractive, force } = options;
|
|
255
|
-
const isThirdParty = isThirdPartyPackage(packageName);
|
|
256
|
-
if (isThirdParty) {
|
|
257
|
-
(0, utils_1.logLabeledWarning)("functions", `Package ${clc.bold(packageName)} is a third-party kit (outside the @firebase-function-kits scope).`);
|
|
258
|
-
}
|
|
259
|
-
const hasShrinkwrap = await checkPackageHasShrinkwrap(rawPkgName);
|
|
260
|
-
if (!hasShrinkwrap) {
|
|
261
|
-
(0, utils_1.logLabeledWarning)("functions", `Package ${clc.bold(packageName)} does not have an npm-shrinkwrap.json file. npm-shrinkwrap guarantees that you deploy the same version of dependencies that the publisher tested against. Since this kit does not have an npm-shrinkwrap, it is possible that deploys or updates may introduce bugs or vulnerabilities in newer dependency versions that the publisher did not test against.`);
|
|
262
|
-
}
|
|
263
|
-
if (isThirdParty || !hasShrinkwrap) {
|
|
264
|
-
let confirmMessage;
|
|
265
|
-
if (isThirdParty && !hasShrinkwrap) {
|
|
266
|
-
confirmMessage = `Are you sure you want to install the third-party kit ${packageName} without locked dependencies?`;
|
|
267
|
-
}
|
|
268
|
-
else if (isThirdParty) {
|
|
269
|
-
confirmMessage = `Are you sure you want to install the third-party kit ${packageName}?`;
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
confirmMessage = `Are you sure you want to install ${packageName} without locked dependencies?`;
|
|
273
|
-
}
|
|
274
|
-
const confirmInstallation = await (0, prompt_1.confirm)({
|
|
275
|
-
message: confirmMessage,
|
|
276
|
-
default: false,
|
|
277
|
-
nonInteractive,
|
|
278
|
-
force,
|
|
279
|
-
});
|
|
280
|
-
if (!confirmInstallation) {
|
|
281
|
-
throw new error_1.FirebaseError("Installation cancelled.");
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return isThirdParty;
|
|
285
|
-
}
|
|
286
181
|
async function promptExistingInstanceForProject(options) {
|
|
287
182
|
const allInstanceIds = Object.keys(options.existingKit.instances || {});
|
|
288
183
|
if (allInstanceIds.length === 0) {
|
|
@@ -311,151 +206,6 @@ async function promptExistingInstanceForProject(options) {
|
|
|
311
206
|
nonInteractive: options.nonInteractive,
|
|
312
207
|
});
|
|
313
208
|
}
|
|
314
|
-
async function writeKitPackageJson(config, sourcePath, kitId) {
|
|
315
|
-
const relPackageJsonPath = path.join(sourcePath, "package.json");
|
|
316
|
-
const absPackageJsonPath = config.path(relPackageJsonPath);
|
|
317
|
-
let pkgJson = {};
|
|
318
|
-
if (await fs.pathExists(absPackageJsonPath)) {
|
|
319
|
-
try {
|
|
320
|
-
pkgJson = (await fs.readJson(absPackageJsonPath));
|
|
321
|
-
}
|
|
322
|
-
catch (err) {
|
|
323
|
-
logger_1.logger.debug(`Failed to read existing package.json: ${(0, error_1.getErrMsg)(err)}`);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
const latestNodeVersion = supported.latest("nodejs").replace("nodejs", "");
|
|
328
|
-
const packageKitTemplate = (0, templates_1.readTemplateSync)("init/functions/typescript/package-kit.json");
|
|
329
|
-
const subbedTemplate = packageKitTemplate.replace(/{{RUNTIME}}/g, latestNodeVersion);
|
|
330
|
-
try {
|
|
331
|
-
pkgJson = JSON.parse(subbedTemplate);
|
|
332
|
-
}
|
|
333
|
-
catch (err) {
|
|
334
|
-
throw new error_1.FirebaseError("Failed to parse package-kit.json template: " + (0, error_1.getErrMsg)(err), {
|
|
335
|
-
original: err instanceof Error ? err : undefined,
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
pkgJson.name = `${kitId}-wrapper`;
|
|
340
|
-
await config.askWriteProjectFile(relPackageJsonPath, pkgJson);
|
|
341
|
-
}
|
|
342
|
-
async function writeKitIndexTs(config, sourcePath, packageName, templateType) {
|
|
343
|
-
const relIndexTsPath = path.join(sourcePath, "src", "index.ts");
|
|
344
|
-
const absIndexTsPath = config.path(relIndexTsPath);
|
|
345
|
-
if (!(await fs.pathExists(absIndexTsPath))) {
|
|
346
|
-
const template = (0, templates_1.readTemplateSync)(exports.TEMPLATES[templateType]);
|
|
347
|
-
const indexContent = template.replace(/{{PACKAGE_NAME}}/g, packageName);
|
|
348
|
-
await config.askWriteProjectFile(relIndexTsPath, indexContent);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
async function scaffoldKitFiles(config, kitId, instanceId, packageName, templateType = exports.DEFAULT_TEMPLATE) {
|
|
352
|
-
const sourcePath = path.join(exports.FUNCTION_KITS_DIR, kitId, "source");
|
|
353
|
-
const configDirPath = path.join(exports.FUNCTION_KITS_DIR, kitId, `config-${instanceId}`);
|
|
354
|
-
const absSourcePath = config.path(sourcePath);
|
|
355
|
-
const absConfigDirPath = config.path(configDirPath);
|
|
356
|
-
await fs.ensureDir(absSourcePath);
|
|
357
|
-
await fs.ensureDir(absConfigDirPath);
|
|
358
|
-
await writeKitPackageJson(config, sourcePath, kitId);
|
|
359
|
-
await config.askWriteProjectFile(path.join(sourcePath, "tsconfig.json"), (0, templates_1.readTemplateSync)("init/functions/typescript/tsconfig.json"));
|
|
360
|
-
await config.askWriteProjectFile(path.join(sourcePath, ".gitignore"), (0, templates_1.readTemplateSync)("init/functions/typescript/_gitignore"));
|
|
361
|
-
await writeKitIndexTs(config, sourcePath, packageName, templateType);
|
|
362
|
-
return { sourcePath, configDirPath, absSourcePath, absConfigDirPath };
|
|
363
|
-
}
|
|
364
|
-
function resolveSdkSpecifierToSave(packageName, declaredVer, installedVer) {
|
|
365
|
-
const cleanVer = semver.clean(declaredVer);
|
|
366
|
-
if (cleanVer) {
|
|
367
|
-
return `${packageName}@=${installedVer || cleanVer}`;
|
|
368
|
-
}
|
|
369
|
-
if (declaredVer.trim().startsWith("~")) {
|
|
370
|
-
return installedVer ? `${packageName}@~${installedVer}` : `${packageName}@${declaredVer}`;
|
|
371
|
-
}
|
|
372
|
-
if (installedVer) {
|
|
373
|
-
return `${packageName}@^${installedVer}`;
|
|
374
|
-
}
|
|
375
|
-
return `${packageName}@${declaredVer}`;
|
|
376
|
-
}
|
|
377
|
-
async function getKitPackagesToSave(absSourcePath, packageName) {
|
|
378
|
-
const lockfilePath = path.join(absSourcePath, "package-lock.json");
|
|
379
|
-
let peerDeps = {};
|
|
380
|
-
let directDeps = {};
|
|
381
|
-
let installedFunctionsVer;
|
|
382
|
-
let installedAdminVer;
|
|
383
|
-
if (await fs.pathExists(lockfilePath)) {
|
|
384
|
-
try {
|
|
385
|
-
const lockfile = (await fs.readJson(lockfilePath));
|
|
386
|
-
const packages = lockfile.packages || {};
|
|
387
|
-
const kitEntry = packages[`node_modules/${packageName}`] || {};
|
|
388
|
-
peerDeps = kitEntry.peerDependencies || {};
|
|
389
|
-
directDeps = kitEntry.dependencies || {};
|
|
390
|
-
installedFunctionsVer = packages["node_modules/firebase-functions"]?.version;
|
|
391
|
-
installedAdminVer = packages["node_modules/firebase-admin"]?.version;
|
|
392
|
-
}
|
|
393
|
-
catch (err) {
|
|
394
|
-
logger_1.logger.debug(`Failed to read package-lock.json: ${(0, error_1.getErrMsg)(err)}`);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
if (Object.keys(peerDeps).length === 0 && Object.keys(directDeps).length === 0) {
|
|
398
|
-
const kitPkgJsonPath = path.join(absSourcePath, "node_modules", packageName, "package.json");
|
|
399
|
-
if (await fs.pathExists(kitPkgJsonPath)) {
|
|
400
|
-
try {
|
|
401
|
-
const kitPkgJson = (await fs.readJson(kitPkgJsonPath));
|
|
402
|
-
peerDeps = kitPkgJson.peerDependencies || {};
|
|
403
|
-
directDeps = kitPkgJson.dependencies || {};
|
|
404
|
-
}
|
|
405
|
-
catch (err) {
|
|
406
|
-
logger_1.logger.debug(`Failed to read kit package.json: ${(0, error_1.getErrMsg)(err)}`);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
const declaredFunctionsVer = peerDeps["firebase-functions"] || directDeps["firebase-functions"];
|
|
411
|
-
if (!declaredFunctionsVer) {
|
|
412
|
-
throw new error_1.FirebaseError(`Package '${packageName}' is not a valid Function Kit: it must declare 'firebase-functions' as a dependency or peer dependency.`);
|
|
413
|
-
}
|
|
414
|
-
const packagesToSave = [
|
|
415
|
-
resolveSdkSpecifierToSave("firebase-functions", declaredFunctionsVer, installedFunctionsVer),
|
|
416
|
-
];
|
|
417
|
-
const declaredAdminVer = peerDeps["firebase-admin"] || directDeps["firebase-admin"];
|
|
418
|
-
if (declaredAdminVer) {
|
|
419
|
-
packagesToSave.push(resolveSdkSpecifierToSave("firebase-admin", declaredAdminVer, installedAdminVer));
|
|
420
|
-
}
|
|
421
|
-
return packagesToSave;
|
|
422
|
-
}
|
|
423
|
-
async function buildAndInstallKit(absSourcePath, rawPkgName, isThirdParty) {
|
|
424
|
-
const { packageName } = parseNpmPackageSpecifier(rawPkgName);
|
|
425
|
-
const installArgs = ["install", rawPkgName, "--save-prefix=^"];
|
|
426
|
-
if (isThirdParty) {
|
|
427
|
-
installArgs.push("--ignore-scripts");
|
|
428
|
-
}
|
|
429
|
-
(0, utils_1.logLabeledBullet)("functions", `Running npm ${installArgs.join(" ")}...`);
|
|
430
|
-
try {
|
|
431
|
-
await (0, spawn_1.wrapSpawn)("npm", installArgs, absSourcePath);
|
|
432
|
-
}
|
|
433
|
-
catch (err) {
|
|
434
|
-
throw new error_1.FirebaseError(`NPM install failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
435
|
-
}
|
|
436
|
-
const packagesToSave = await getKitPackagesToSave(absSourcePath, packageName);
|
|
437
|
-
if (packagesToSave.length > 0) {
|
|
438
|
-
(0, utils_1.logLabeledBullet)("functions", `Saving resolved SDK dependencies: ${clc.bold(packagesToSave.join(", "))}...`);
|
|
439
|
-
const saveArgs = ["install", ...packagesToSave, "--save-prefix=^"];
|
|
440
|
-
if (isThirdParty) {
|
|
441
|
-
saveArgs.push("--ignore-scripts");
|
|
442
|
-
}
|
|
443
|
-
try {
|
|
444
|
-
await (0, spawn_1.wrapSpawn)("npm", saveArgs, absSourcePath);
|
|
445
|
-
}
|
|
446
|
-
catch (err) {
|
|
447
|
-
throw new error_1.FirebaseError(`Failed to install required SDK dependencies (${packagesToSave.join(", ")}): ${(0, error_1.getErrMsg)(err)}. ` +
|
|
448
|
-
"Verify that the kit's dependencies are compatible with the resolved Firebase SDK versions.", { original: err instanceof Error ? err : undefined });
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
(0, utils_1.logLabeledBullet)("functions", "Building TypeScript source...");
|
|
452
|
-
try {
|
|
453
|
-
await (0, spawn_1.wrapSpawn)("npm", ["run", "build"], absSourcePath);
|
|
454
|
-
}
|
|
455
|
-
catch (err) {
|
|
456
|
-
throw new error_1.FirebaseError(`TypeScript build failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
209
|
function addKitToConfig(config, options) {
|
|
460
210
|
const configSrc = config.src;
|
|
461
211
|
const newKitConfig = {
|
|
@@ -481,56 +231,6 @@ function addKitToConfig(config, options) {
|
|
|
481
231
|
}
|
|
482
232
|
config.writeProjectFile("firebase.json", configSrc);
|
|
483
233
|
}
|
|
484
|
-
async function validateAndResolveDirectoryKit(projectDir, rawDir) {
|
|
485
|
-
const absDirectoryPath = (0, utils_1.resolveWithin)(projectDir, rawDir, `Directory '${rawDir}' is outside of project directory. Function kit directory must be inside the project directory.`);
|
|
486
|
-
if (!(await fs.pathExists(absDirectoryPath))) {
|
|
487
|
-
throw new error_1.FirebaseError(`Directory '${rawDir}' does not exist.`);
|
|
488
|
-
}
|
|
489
|
-
const stat = await fs.stat(absDirectoryPath);
|
|
490
|
-
if (!stat.isDirectory()) {
|
|
491
|
-
throw new error_1.FirebaseError(`Directory '${rawDir}' is not a directory.`);
|
|
492
|
-
}
|
|
493
|
-
const packageJsonPath = path.join(absDirectoryPath, "package.json");
|
|
494
|
-
if (!(await fs.pathExists(packageJsonPath))) {
|
|
495
|
-
throw new error_1.FirebaseError(`Directory '${rawDir}' must contain a package.json file to be installed as a function kit.`);
|
|
496
|
-
}
|
|
497
|
-
let packageJson = {};
|
|
498
|
-
try {
|
|
499
|
-
packageJson = (await fs.readJson(packageJsonPath));
|
|
500
|
-
}
|
|
501
|
-
catch (err) {
|
|
502
|
-
throw new error_1.FirebaseError(`Failed to parse package.json in '${rawDir}': ${(0, error_1.getErrMsg)(err)}`);
|
|
503
|
-
}
|
|
504
|
-
const hasBuildScript = Boolean(packageJson.scripts && packageJson.scripts.build);
|
|
505
|
-
let relSourcePath = path.relative(projectDir, absDirectoryPath);
|
|
506
|
-
if (!relSourcePath) {
|
|
507
|
-
relSourcePath = ".";
|
|
508
|
-
}
|
|
509
|
-
relSourcePath = relSourcePath.split(path.sep).join("/");
|
|
510
|
-
return {
|
|
511
|
-
absDirectoryPath,
|
|
512
|
-
relSourcePath,
|
|
513
|
-
hasBuildScript,
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
async function buildAndInstallDirectoryKit(absSourcePath, hasBuildScript) {
|
|
517
|
-
(0, utils_1.logLabeledBullet)("functions", "Running npm install...");
|
|
518
|
-
try {
|
|
519
|
-
await (0, spawn_1.wrapSpawn)("npm", ["install"], absSourcePath);
|
|
520
|
-
}
|
|
521
|
-
catch (err) {
|
|
522
|
-
throw new error_1.FirebaseError(`NPM install failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
523
|
-
}
|
|
524
|
-
if (hasBuildScript) {
|
|
525
|
-
(0, utils_1.logLabeledBullet)("functions", "Building TypeScript source...");
|
|
526
|
-
try {
|
|
527
|
-
await (0, spawn_1.wrapSpawn)("npm", ["run", "build"], absSourcePath);
|
|
528
|
-
}
|
|
529
|
-
catch (err) {
|
|
530
|
-
throw new error_1.FirebaseError(`TypeScript build failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
234
|
function findKitConfig(config, kitId) {
|
|
535
235
|
const functions = config.src.functions;
|
|
536
236
|
if (!functions) {
|
|
@@ -572,7 +272,7 @@ function revertFunctionsConfig(options) {
|
|
|
572
272
|
}
|
|
573
273
|
}
|
|
574
274
|
async function scaffoldKit(options) {
|
|
575
|
-
const paths = await scaffoldKitFiles(options.config, options.kitId, options.instanceId, options.packageName, options.templateType);
|
|
275
|
+
const paths = await (0, sources_1.scaffoldKitFiles)(options.config, options.kitId, options.instanceId, options.packageName, options.templateType);
|
|
576
276
|
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
577
277
|
(0, env_2.seedKitInstanceEnv)({
|
|
578
278
|
configDir: paths.absConfigDirPath,
|
|
@@ -597,7 +297,7 @@ async function addInstanceToKit(options) {
|
|
|
597
297
|
if (!target) {
|
|
598
298
|
throw new error_1.FirebaseError(`Kit '${options.kitId}' not found in firebase.json.`);
|
|
599
299
|
}
|
|
600
|
-
const configDirPath = path.join(
|
|
300
|
+
const configDirPath = path.join(sources_1.FUNCTION_KITS_DIR, options.kitId, `config-${options.instanceId}`);
|
|
601
301
|
const absConfigDirPath = options.config.path(configDirPath);
|
|
602
302
|
await fs.ensureDir(absConfigDirPath);
|
|
603
303
|
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
@@ -773,7 +473,7 @@ async function addKitInstanceOrConfigureProject(options) {
|
|
|
773
473
|
if (action === "addInstance") {
|
|
774
474
|
resultAction = "addedInstance";
|
|
775
475
|
instanceId = await promptKitInstanceId(options.defaultInstanceId ?? existingKit.kit, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
776
|
-
const expectedConfigDirPath = path.join(
|
|
476
|
+
const expectedConfigDirPath = path.join(sources_1.FUNCTION_KITS_DIR, existingKit.kit, `config-${instanceId}`);
|
|
777
477
|
absConfigDirPath = options.config.path(expectedConfigDirPath);
|
|
778
478
|
createdPaths.push(absConfigDirPath);
|
|
779
479
|
const result = await addInstanceToKit({
|
|
@@ -869,7 +569,7 @@ async function addKitInstanceOrConfigureProject(options) {
|
|
|
869
569
|
}
|
|
870
570
|
function findExistingKit(existingFunctions, options) {
|
|
871
571
|
if (options.package) {
|
|
872
|
-
const { packageName } = parseNpmPackageSpecifier(options.package);
|
|
572
|
+
const { packageName } = (0, sources_1.parseNpmPackageSpecifier)(options.package);
|
|
873
573
|
return existingFunctions.find((c) => (0, projectConfig_1.isKitConfig)(c) && c.sourcePackage?.name === packageName);
|
|
874
574
|
}
|
|
875
575
|
if (options.directory) {
|
|
@@ -883,9 +583,9 @@ function findExistingKit(existingFunctions, options) {
|
|
|
883
583
|
return undefined;
|
|
884
584
|
}
|
|
885
585
|
async function resolvePackageSource(options) {
|
|
886
|
-
const templateType = options.template ||
|
|
887
|
-
if (!(templateType in
|
|
888
|
-
const validTemplates = Object.keys(
|
|
586
|
+
const templateType = options.template || sources_1.DEFAULT_TEMPLATE;
|
|
587
|
+
if (!(templateType in sources_1.TEMPLATES)) {
|
|
588
|
+
const validTemplates = Object.keys(sources_1.TEMPLATES)
|
|
889
589
|
.map((t) => `'${t}'`)
|
|
890
590
|
.join(" or ");
|
|
891
591
|
throw new error_1.FirebaseError(`Invalid template '${templateType}'. Template must be ${validTemplates}.`);
|
|
@@ -894,9 +594,9 @@ async function resolvePackageSource(options) {
|
|
|
894
594
|
if (!rawPkgName) {
|
|
895
595
|
throw new error_1.FirebaseError("Set the --package option to a valid NPM package and try again.");
|
|
896
596
|
}
|
|
897
|
-
await validateNpmPackageExists(rawPkgName);
|
|
898
|
-
const { packageName } = parseNpmPackageSpecifier(rawPkgName);
|
|
899
|
-
const isThirdParty = await promptSecurityConfirmation({
|
|
597
|
+
await (0, sources_1.validateNpmPackageExists)(rawPkgName);
|
|
598
|
+
const { packageName } = (0, sources_1.parseNpmPackageSpecifier)(rawPkgName);
|
|
599
|
+
const isThirdParty = await (0, sources_1.promptSecurityConfirmation)({
|
|
900
600
|
rawPkgName,
|
|
901
601
|
packageName,
|
|
902
602
|
nonInteractive: options.nonInteractive,
|
|
@@ -906,21 +606,21 @@ async function resolvePackageSource(options) {
|
|
|
906
606
|
defaultKitName: packageName,
|
|
907
607
|
sourcePackageName: packageName,
|
|
908
608
|
hasBuildScript: true,
|
|
909
|
-
setup: (kitId, instanceId) => scaffoldKitFiles(options.config, kitId, instanceId, packageName, templateType),
|
|
910
|
-
buildAndInstall: (absSourcePath) => buildAndInstallKit(absSourcePath, rawPkgName, isThirdParty),
|
|
609
|
+
setup: (kitId, instanceId) => (0, sources_1.scaffoldKitFiles)(options.config, kitId, instanceId, packageName, templateType),
|
|
610
|
+
buildAndInstall: (absSourcePath) => (0, sources_1.buildAndInstallKit)(absSourcePath, rawPkgName, isThirdParty),
|
|
911
611
|
};
|
|
912
612
|
}
|
|
913
613
|
async function resolveDirectorySource(options) {
|
|
914
614
|
if (!options.directory) {
|
|
915
615
|
throw new error_1.FirebaseError("Must specify --directory.");
|
|
916
616
|
}
|
|
917
|
-
const { absDirectoryPath, relSourcePath, hasBuildScript } = await validateAndResolveDirectoryKit(options.config.projectDir, options.directory);
|
|
617
|
+
const { absDirectoryPath, relSourcePath, hasBuildScript } = await (0, sources_1.validateAndResolveDirectoryKit)(options.config.projectDir, options.directory);
|
|
918
618
|
return {
|
|
919
619
|
defaultKitName: path.basename(absDirectoryPath),
|
|
920
620
|
sourcePackageName: undefined,
|
|
921
621
|
hasBuildScript,
|
|
922
622
|
setup: async (kitId, instanceId) => {
|
|
923
|
-
const configDirPath = path.join(
|
|
623
|
+
const configDirPath = path.join(sources_1.FUNCTION_KITS_DIR, kitId, `config-${instanceId}`);
|
|
924
624
|
const absConfigDirPath = options.config.path(configDirPath);
|
|
925
625
|
await fs.ensureDir(absConfigDirPath);
|
|
926
626
|
return {
|
|
@@ -930,7 +630,7 @@ async function resolveDirectorySource(options) {
|
|
|
930
630
|
absConfigDirPath,
|
|
931
631
|
};
|
|
932
632
|
},
|
|
933
|
-
buildAndInstall: (absSourcePath) => buildAndInstallDirectoryKit(absSourcePath, hasBuildScript),
|
|
633
|
+
buildAndInstall: (absSourcePath) => (0, sources_1.buildAndInstallDirectoryKit)(absSourcePath, hasBuildScript),
|
|
934
634
|
};
|
|
935
635
|
}
|
|
936
636
|
async function installKitOrInstance(options) {
|
|
@@ -944,7 +644,7 @@ async function installKitOrInstance(options) {
|
|
|
944
644
|
throw new error_1.FirebaseError("Cannot specify --template with --directory.");
|
|
945
645
|
}
|
|
946
646
|
if (options.package) {
|
|
947
|
-
validateNpmPackageName(options.package);
|
|
647
|
+
(0, sources_1.validateNpmPackageName)(options.package);
|
|
948
648
|
}
|
|
949
649
|
const originalFunctions = (0, utils_1.cloneDeep)(options.config.src.functions);
|
|
950
650
|
const createdPaths = [];
|
|
@@ -967,8 +667,8 @@ async function installKitOrInstance(options) {
|
|
|
967
667
|
kitId = await promptKitId(source.defaultKitName, existingFunctionsInfo.existingKitIds, options.nonInteractive, options.kitId);
|
|
968
668
|
const instanceId = await promptKitInstanceId(options.defaultInstanceId ?? kitId, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
969
669
|
const isPackageKit = !options.directory;
|
|
970
|
-
const absKitDir = options.config.path(path.join(
|
|
971
|
-
const expectedConfigDirPath = path.join(
|
|
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}`);
|
|
972
672
|
const absConfigDirPath = options.config.path(expectedConfigDirPath);
|
|
973
673
|
if (isPackageKit) {
|
|
974
674
|
createdPaths.push(absKitDir);
|
|
@@ -1048,9 +748,9 @@ async function installKitOrInstance(options) {
|
|
|
1048
748
|
logger_1.logger.debug(`Failed to clean up path '${targetPath}': ${(0, error_1.getErrMsg)(cleanupErr)}`);
|
|
1049
749
|
})));
|
|
1050
750
|
if (kitId) {
|
|
1051
|
-
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(path.join(
|
|
751
|
+
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(path.join(sources_1.FUNCTION_KITS_DIR, kitId)));
|
|
1052
752
|
}
|
|
1053
|
-
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(
|
|
753
|
+
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(sources_1.FUNCTION_KITS_DIR));
|
|
1054
754
|
revertFunctionsConfig({ config: options.config, originalFunctions });
|
|
1055
755
|
throw err;
|
|
1056
756
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAndResolveDirectoryKit = validateAndResolveDirectoryKit;
|
|
4
|
+
exports.buildAndInstallDirectoryKit = buildAndInstallDirectoryKit;
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const fs = require("fs-extra");
|
|
7
|
+
const error_1 = require("../../../error");
|
|
8
|
+
const spawn_1 = require("../../../init/spawn");
|
|
9
|
+
const utils_1 = require("../../../utils");
|
|
10
|
+
async function validateAndResolveDirectoryKit(projectDir, rawDir) {
|
|
11
|
+
const absDirectoryPath = (0, utils_1.resolveWithin)(projectDir, rawDir, `Directory '${rawDir}' is outside of project directory. Function kit directory must be inside the project directory.`);
|
|
12
|
+
if (!(await fs.pathExists(absDirectoryPath))) {
|
|
13
|
+
throw new error_1.FirebaseError(`Directory '${rawDir}' does not exist.`);
|
|
14
|
+
}
|
|
15
|
+
const stat = await fs.stat(absDirectoryPath);
|
|
16
|
+
if (!stat.isDirectory()) {
|
|
17
|
+
throw new error_1.FirebaseError(`Directory '${rawDir}' is not a directory.`);
|
|
18
|
+
}
|
|
19
|
+
const packageJsonPath = path.join(absDirectoryPath, "package.json");
|
|
20
|
+
if (!(await fs.pathExists(packageJsonPath))) {
|
|
21
|
+
throw new error_1.FirebaseError(`Directory '${rawDir}' must contain a package.json file to be installed as a function kit.`);
|
|
22
|
+
}
|
|
23
|
+
let packageJson = {};
|
|
24
|
+
try {
|
|
25
|
+
packageJson = (await fs.readJson(packageJsonPath)) || {};
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
throw new error_1.FirebaseError(`Failed to parse package.json in '${rawDir}': ${(0, error_1.getErrMsg)(err)}`);
|
|
29
|
+
}
|
|
30
|
+
const hasBuildScript = Boolean(packageJson?.scripts?.build);
|
|
31
|
+
let relSourcePath = path.relative(projectDir, absDirectoryPath);
|
|
32
|
+
if (!relSourcePath) {
|
|
33
|
+
relSourcePath = ".";
|
|
34
|
+
}
|
|
35
|
+
relSourcePath = relSourcePath.split(path.sep).join("/");
|
|
36
|
+
return {
|
|
37
|
+
absDirectoryPath,
|
|
38
|
+
relSourcePath,
|
|
39
|
+
hasBuildScript,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function buildAndInstallDirectoryKit(absSourcePath, hasBuildScript) {
|
|
43
|
+
(0, utils_1.logLabeledBullet)("functions", "Running npm install...");
|
|
44
|
+
try {
|
|
45
|
+
await (0, spawn_1.wrapSpawn)("npm", ["install"], absSourcePath);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
throw new error_1.FirebaseError(`NPM install failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
49
|
+
}
|
|
50
|
+
if (hasBuildScript) {
|
|
51
|
+
(0, utils_1.logLabeledBullet)("functions", "Building TypeScript source...");
|
|
52
|
+
try {
|
|
53
|
+
await (0, spawn_1.wrapSpawn)("npm", ["run", "build"], absSourcePath);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
throw new error_1.FirebaseError(`TypeScript build failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./npm"), exports);
|
|
19
|
+
__exportStar(require("./directory"), exports);
|