firebase-tools 15.28.1 → 15.28.2
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/apphosting/backend.js +44 -10
- package/lib/apphosting/githubConnections.js +1 -1
- package/lib/apphosting/repo.js +1 -1
- package/lib/apphosting/rollout.js +1 -1
- package/lib/commands/ext-export.js +25 -29
- package/lib/commands/ext-migrate.js +36 -0
- package/lib/commands/functions-kits-install.js +21 -401
- package/lib/commands/functions-kits-uninstall.js +266 -0
- package/lib/commands/index.js +4 -0
- package/lib/config.js +34 -0
- package/lib/dataconnect/client.js +2 -2
- package/lib/deploy/functions/ensure.js +29 -19
- package/lib/deploy/functions/prepare.js +8 -1
- package/lib/deploy/functions/release/fabricator.js +19 -3
- package/lib/deploy/functions/release/planner.js +8 -0
- package/lib/extensions/listExtensions.js +27 -3
- package/lib/extensions/migrate.js +171 -0
- package/lib/extensions/replacementRegistry.js +39 -4
- package/lib/extensions/replacements.json +7 -7
- package/lib/functions/kits/env.js +38 -0
- package/lib/functions/kits/index.js +19 -0
- package/lib/functions/kits/install.js +709 -0
- package/lib/requireTosAcceptance.js +2 -1
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/schema/firebase-config.json +1 -1
|
@@ -1,417 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.command =
|
|
4
|
-
exports.generateUniqueId = generateUniqueId;
|
|
5
|
-
exports.parseNpmPackageSpecifier = parseNpmPackageSpecifier;
|
|
6
|
-
exports.validateNpmPackageName = validateNpmPackageName;
|
|
7
|
-
exports.sanitizePackageNameToKitName = sanitizePackageNameToKitName;
|
|
8
|
-
exports.isThirdPartyPackage = isThirdPartyPackage;
|
|
9
|
-
exports.checkPackageHasShrinkwrap = checkPackageHasShrinkwrap;
|
|
10
|
-
exports.isKitConfiguredForProject = isKitConfiguredForProject;
|
|
11
|
-
exports.extractExistingFunctionsInfo = extractExistingFunctionsInfo;
|
|
12
|
-
exports.promptKitInstanceId = promptKitInstanceId;
|
|
13
|
-
exports.promptKitId = promptKitId;
|
|
14
|
-
exports.promptSecurityConfirmation = promptSecurityConfirmation;
|
|
15
|
-
exports.promptExistingInstanceForProject = promptExistingInstanceForProject;
|
|
16
|
-
exports.addKitInstanceOrConfigureProject = addKitInstanceOrConfigureProject;
|
|
17
|
-
exports.scaffoldKitFiles = scaffoldKitFiles;
|
|
18
|
-
exports.buildAndInstallKit = buildAndInstallKit;
|
|
19
|
-
exports.addKitToConfig = addKitToConfig;
|
|
20
|
-
const clc = require("colorette");
|
|
21
|
-
const crypto = require("crypto");
|
|
22
|
-
const path = require("path");
|
|
23
|
-
const fs = require("fs-extra");
|
|
3
|
+
exports.command = void 0;
|
|
24
4
|
const command_1 = require("../command");
|
|
25
5
|
const error_1 = require("../error");
|
|
26
|
-
const projectUtils_1 = require("../projectUtils");
|
|
27
|
-
const utils_1 = require("../utils");
|
|
28
|
-
const projectConfig_1 = require("../functions/projectConfig");
|
|
29
6
|
const experiments = require("../experiments");
|
|
30
|
-
const
|
|
31
|
-
const prompt_1 = require("../prompt");
|
|
32
|
-
const spawn_1 = require("../init/spawn");
|
|
33
|
-
const templates_1 = require("../templates");
|
|
34
|
-
const supported = require("../deploy/functions/runtimes/supported");
|
|
35
|
-
const env_1 = require("../functions/env");
|
|
36
|
-
const self = require("./functions-kits-install");
|
|
37
|
-
const PACKAGE_NO_LINTING_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/package.nolint.json");
|
|
38
|
-
const TSCONFIG_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/tsconfig.json");
|
|
39
|
-
const GITIGNORE_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/_gitignore");
|
|
40
|
-
const INDEX_KIT_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/index-kit.ts");
|
|
41
|
-
const INDEX_KIT_MIGRATION_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/index-kit-migration.ts");
|
|
42
|
-
exports.TEMPLATES = {
|
|
43
|
-
installation: INDEX_KIT_TEMPLATE,
|
|
44
|
-
migration: INDEX_KIT_MIGRATION_TEMPLATE,
|
|
45
|
-
};
|
|
46
|
-
exports.DEFAULT_TEMPLATE = "installation";
|
|
47
|
-
exports.FUNCTION_KITS_DIR = "function-kits";
|
|
48
|
-
function generateUniqueId(baseId, existingIds) {
|
|
49
|
-
if (!existingIds.has(baseId)) {
|
|
50
|
-
return baseId;
|
|
51
|
-
}
|
|
52
|
-
const prefix = baseId.slice(0, 35);
|
|
53
|
-
let candidate = "";
|
|
54
|
-
do {
|
|
55
|
-
const randomSuffix = crypto.randomBytes(2).toString("hex");
|
|
56
|
-
candidate = `${prefix}-${randomSuffix}`;
|
|
57
|
-
} while (existingIds.has(candidate));
|
|
58
|
-
return candidate;
|
|
59
|
-
}
|
|
60
|
-
function parseNpmPackageSpecifier(rawPkg) {
|
|
61
|
-
const lastAt = rawPkg.lastIndexOf("@");
|
|
62
|
-
if (lastAt > 0) {
|
|
63
|
-
return {
|
|
64
|
-
packageName: rawPkg.substring(0, lastAt),
|
|
65
|
-
version: rawPkg.substring(lastAt + 1),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return { packageName: rawPkg };
|
|
69
|
-
}
|
|
70
|
-
function validateNpmPackageName(packageName) {
|
|
71
|
-
const npmPackageRegex = /^(?:@[a-z0-9_.-]+\/[a-z0-9_.-]+|[a-z0-9_.-]+)$/i;
|
|
72
|
-
if (!packageName || packageName.length > 214 || !npmPackageRegex.test(packageName)) {
|
|
73
|
-
throw new error_1.FirebaseError(`Invalid NPM package name '${packageName}'. Package names must be valid npm package specifiers (e.g. 'my-kit' or '@scope/my-kit').`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function sanitizePackageNameToKitName(packageName) {
|
|
77
|
-
const parts = packageName.split("/");
|
|
78
|
-
const nameWithoutScope = parts[parts.length - 1] || packageName;
|
|
79
|
-
const sanitized = nameWithoutScope.toLowerCase().replace(/[^a-z0-9_-]/g, "");
|
|
80
|
-
return sanitized.slice(0, 40);
|
|
81
|
-
}
|
|
82
|
-
function isThirdPartyPackage(packageName) {
|
|
83
|
-
return !packageName.startsWith("@firebase-functions-kits/");
|
|
84
|
-
}
|
|
85
|
-
async function checkPackageHasShrinkwrap(rawPkgName) {
|
|
86
|
-
try {
|
|
87
|
-
const output = await (0, spawn_1.spawnWithOutput)("npm", ["pack", rawPkgName, "--dry-run", "--json"]);
|
|
88
|
-
const parsed = JSON.parse(output);
|
|
89
|
-
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
90
|
-
const pkgInfo = parsed[0];
|
|
91
|
-
if (pkgInfo.hasShrinkwrap) {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
if (Array.isArray(pkgInfo.files)) {
|
|
95
|
-
return pkgInfo.files.some((f) => f.path === "npm-shrinkwrap.json" || f.path === "npm-shrinkwrap.js");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
logger_1.logger.debug(`Failed to inspect package shrinkwrap for ${rawPkgName}: ${(0, error_1.getErrMsg)(err)}`);
|
|
101
|
-
}
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
function isKitConfiguredForProject(config, kit, projectId, projectAlias) {
|
|
105
|
-
return Object.values(kit.instances || {}).some((configDir) => (0, env_1.hasProjectEnv)(config.path(configDir), projectId, projectAlias));
|
|
106
|
-
}
|
|
107
|
-
function extractExistingFunctionsInfo(configFunctions) {
|
|
108
|
-
const existingFunctions = configFunctions && (!Array.isArray(configFunctions) || configFunctions.length > 0)
|
|
109
|
-
? (0, projectConfig_1.normalizeAndValidate)(configFunctions)
|
|
110
|
-
: [];
|
|
111
|
-
const existingKitIds = new Set();
|
|
112
|
-
const existingCodebases = new Set();
|
|
113
|
-
const existingInstanceIds = new Set();
|
|
114
|
-
for (const c of existingFunctions) {
|
|
115
|
-
if ((0, projectConfig_1.isKitConfig)(c)) {
|
|
116
|
-
if (c.kit) {
|
|
117
|
-
existingKitIds.add(c.kit);
|
|
118
|
-
}
|
|
119
|
-
if (c.instances) {
|
|
120
|
-
for (const instId of Object.keys(c.instances)) {
|
|
121
|
-
existingInstanceIds.add(instId);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else if (c.codebase) {
|
|
126
|
-
existingCodebases.add(c.codebase);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
existingFunctions,
|
|
131
|
-
existingKitIds,
|
|
132
|
-
existingCodebases,
|
|
133
|
-
existingInstanceIds,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
async function promptKitInstanceId(baseKitId, existingInstanceIds, existingCodebases, nonInteractive) {
|
|
137
|
-
const instanceCollisions = new Set([...existingInstanceIds, ...existingCodebases]);
|
|
138
|
-
const defaultInstanceId = generateUniqueId(baseKitId, instanceCollisions);
|
|
139
|
-
const instanceId = await (0, prompt_1.input)({
|
|
140
|
-
message: "What would you like to name this instance?",
|
|
141
|
-
default: defaultInstanceId,
|
|
142
|
-
nonInteractive,
|
|
143
|
-
validate: (val) => {
|
|
144
|
-
try {
|
|
145
|
-
(0, projectConfig_1.validateKitInstanceId)(val);
|
|
146
|
-
}
|
|
147
|
-
catch (err) {
|
|
148
|
-
return (0, error_1.getErrMsg)(err);
|
|
149
|
-
}
|
|
150
|
-
if (existingInstanceIds.has(val)) {
|
|
151
|
-
return `functions kit instance ID must be unique across all kits, but '${val}' was used more than once.`;
|
|
152
|
-
}
|
|
153
|
-
if (existingCodebases.has(val)) {
|
|
154
|
-
return `functions codebase name and kit instance ID must be mutually exclusive, but '${val}' was used as both a codebase name and a kit instance ID.`;
|
|
155
|
-
}
|
|
156
|
-
return true;
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
(0, projectConfig_1.validateKitInstanceId)(instanceId);
|
|
160
|
-
if (existingInstanceIds.has(instanceId)) {
|
|
161
|
-
throw new error_1.FirebaseError(`functions kit instance ID must be unique across all kits, but '${instanceId}' was used more than once.`);
|
|
162
|
-
}
|
|
163
|
-
if (existingCodebases.has(instanceId)) {
|
|
164
|
-
throw new error_1.FirebaseError(`functions codebase name and kit instance ID must be mutually exclusive, but '${instanceId}' was used as both a codebase name and a kit instance ID.`);
|
|
165
|
-
}
|
|
166
|
-
return instanceId;
|
|
167
|
-
}
|
|
168
|
-
async function promptKitId(packageName, existingKitIds, nonInteractive) {
|
|
169
|
-
const baseKitId = sanitizePackageNameToKitName(packageName);
|
|
170
|
-
const defaultKitId = generateUniqueId(baseKitId, existingKitIds);
|
|
171
|
-
const kitId = await (0, prompt_1.input)({
|
|
172
|
-
message: "What would you like to name this kit?",
|
|
173
|
-
default: defaultKitId,
|
|
174
|
-
nonInteractive,
|
|
175
|
-
validate: (val) => {
|
|
176
|
-
try {
|
|
177
|
-
(0, projectConfig_1.validateKit)(val);
|
|
178
|
-
}
|
|
179
|
-
catch (err) {
|
|
180
|
-
return (0, error_1.getErrMsg)(err);
|
|
181
|
-
}
|
|
182
|
-
if (existingKitIds.has(val)) {
|
|
183
|
-
return `functions.kit must be unique but '${val}' was used more than once.`;
|
|
184
|
-
}
|
|
185
|
-
return true;
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
(0, projectConfig_1.validateKit)(kitId);
|
|
189
|
-
if (existingKitIds.has(kitId)) {
|
|
190
|
-
throw new error_1.FirebaseError(`functions.kit must be unique but '${kitId}' was used more than once.`);
|
|
191
|
-
}
|
|
192
|
-
return kitId;
|
|
193
|
-
}
|
|
194
|
-
async function promptSecurityConfirmation(rawPkgName, packageName, nonInteractive) {
|
|
195
|
-
const isThirdParty = isThirdPartyPackage(packageName);
|
|
196
|
-
if (isThirdParty) {
|
|
197
|
-
(0, utils_1.logLabeledWarning)("functions", `Package ${clc.bold(packageName)} is a third-party kit (outside the @firebase-functions-kits scope).`);
|
|
198
|
-
}
|
|
199
|
-
const hasShrinkwrap = await self.checkPackageHasShrinkwrap(rawPkgName);
|
|
200
|
-
if (!hasShrinkwrap) {
|
|
201
|
-
(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.`);
|
|
202
|
-
}
|
|
203
|
-
if (isThirdParty || !hasShrinkwrap) {
|
|
204
|
-
let confirmMessage;
|
|
205
|
-
if (isThirdParty && !hasShrinkwrap) {
|
|
206
|
-
confirmMessage = `Are you sure you want to install the third-party kit ${packageName} without locked dependencies?`;
|
|
207
|
-
}
|
|
208
|
-
else if (isThirdParty) {
|
|
209
|
-
confirmMessage = `Are you sure you want to install the third-party kit ${packageName}?`;
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
confirmMessage = `Are you sure you want to install ${packageName} without locked dependencies?`;
|
|
213
|
-
}
|
|
214
|
-
const confirmInstallation = await (0, prompt_1.confirm)({
|
|
215
|
-
message: confirmMessage,
|
|
216
|
-
default: false,
|
|
217
|
-
nonInteractive,
|
|
218
|
-
});
|
|
219
|
-
if (!confirmInstallation) {
|
|
220
|
-
throw new error_1.FirebaseError("Installation cancelled.");
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return isThirdParty;
|
|
224
|
-
}
|
|
225
|
-
async function addInstanceToExistingKit(options, existingKit, existingFunctionsInfo) {
|
|
226
|
-
const instanceId = await promptKitInstanceId(existingKit.kit, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive);
|
|
227
|
-
const configDirPath = path.join(exports.FUNCTION_KITS_DIR, existingKit.kit, `config-${instanceId}`);
|
|
228
|
-
const absConfigDirPath = options.config.path(configDirPath);
|
|
229
|
-
await fs.ensureDir(absConfigDirPath);
|
|
230
|
-
existingKit.instances[instanceId] = configDirPath;
|
|
231
|
-
options.config.writeProjectFile("firebase.json", options.config.src);
|
|
232
|
-
(0, utils_1.logLabeledSuccess)("functions", `Function kit instance ${clc.bold(instanceId)} successfully added to kit ${clc.bold(existingKit.kit)}.`);
|
|
233
|
-
}
|
|
234
|
-
async function promptExistingInstanceForProject(options, existingKit) {
|
|
235
|
-
const instanceIds = Object.keys(existingKit.instances);
|
|
236
|
-
if (instanceIds.length === 0) {
|
|
237
|
-
throw new error_1.FirebaseError(`Kit '${existingKit.kit}' has no instances configured.`);
|
|
238
|
-
}
|
|
239
|
-
let selectedInstanceId = "<instance-name>";
|
|
240
|
-
if (instanceIds.length === 1) {
|
|
241
|
-
selectedInstanceId = instanceIds[0];
|
|
242
|
-
}
|
|
243
|
-
else if (!options.nonInteractive) {
|
|
244
|
-
selectedInstanceId = await (0, prompt_1.select)({
|
|
245
|
-
message: "Which instance would you like to configure for this project?",
|
|
246
|
-
choices: instanceIds.map((id) => ({ name: id, value: id })),
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
const targetProject = (0, projectUtils_1.getProjectId)(options) || options.project || "<project-name>";
|
|
250
|
-
(0, utils_1.logLabeledBullet)("functions", `To create a new instance in this project, deploy the instance dedicated to this project using\n` +
|
|
251
|
-
clc.bold(`firebase deploy --only functions:${selectedInstanceId} --project ${targetProject}`));
|
|
252
|
-
}
|
|
253
|
-
async function addKitInstanceOrConfigureProject(options, existingKit, existingFunctionsInfo) {
|
|
254
|
-
const projectId = (0, projectUtils_1.getProjectId)(options);
|
|
255
|
-
const projectAlias = options.rc?.hasProjects && options.project && options.rc.hasProjectAlias(options.project)
|
|
256
|
-
? options.project
|
|
257
|
-
: undefined;
|
|
258
|
-
const isConfiguredForProject = isKitConfiguredForProject(options.config, existingKit, projectId, projectAlias);
|
|
259
|
-
let action;
|
|
260
|
-
if (!isConfiguredForProject && !options.nonInteractive) {
|
|
261
|
-
const existingInstances = Object.keys(existingKit.instances || {}).join(", ");
|
|
262
|
-
action = await (0, prompt_1.select)({
|
|
263
|
-
message: `The following instances already exist, but are not configured for this project: ${existingInstances}. What would you like to do?`,
|
|
264
|
-
choices: [
|
|
265
|
-
{
|
|
266
|
-
name: "Add an instance to the existing kit",
|
|
267
|
-
value: "addInstance",
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
name: "Configure an existing instance for this project",
|
|
271
|
-
value: "addEnv",
|
|
272
|
-
},
|
|
273
|
-
],
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
if (isConfiguredForProject) {
|
|
278
|
-
(0, utils_1.logLabeledBullet)("functions", `This package is already installed as kit ${existingKit.kit}, creating a new instance.`);
|
|
279
|
-
}
|
|
280
|
-
action = "addInstance";
|
|
281
|
-
}
|
|
282
|
-
if (action === "addInstance") {
|
|
283
|
-
await addInstanceToExistingKit(options, existingKit, existingFunctionsInfo);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
if (action === "addEnv") {
|
|
287
|
-
await promptExistingInstanceForProject(options, existingKit);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async function writeKitPackageJson(config, sourcePath, kitId, packageName, version) {
|
|
292
|
-
const relPackageJsonPath = path.join(sourcePath, "package.json");
|
|
293
|
-
const absPackageJsonPath = config.path(relPackageJsonPath);
|
|
294
|
-
let pkgJson = {};
|
|
295
|
-
if (await fs.pathExists(absPackageJsonPath)) {
|
|
296
|
-
try {
|
|
297
|
-
pkgJson = (await fs.readJson(absPackageJsonPath));
|
|
298
|
-
}
|
|
299
|
-
catch (err) {
|
|
300
|
-
logger_1.logger.debug(`Failed to read existing package.json: ${(0, error_1.getErrMsg)(err)}`);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
const latestNodeVersion = supported.latest("nodejs").replace("nodejs", "");
|
|
305
|
-
const subbedTemplate = PACKAGE_NO_LINTING_TEMPLATE.replace("{{RUNTIME}}", latestNodeVersion);
|
|
306
|
-
try {
|
|
307
|
-
pkgJson = JSON.parse(subbedTemplate);
|
|
308
|
-
}
|
|
309
|
-
catch (err) {
|
|
310
|
-
throw new error_1.FirebaseError("Failed to parse package.nolint.json template: " + (0, error_1.getErrMsg)(err));
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
pkgJson.name = `${kitId}-wrapper`;
|
|
314
|
-
pkgJson.dependencies = pkgJson.dependencies || {};
|
|
315
|
-
pkgJson.dependencies[packageName] = version || "latest";
|
|
316
|
-
await config.askWriteProjectFile(relPackageJsonPath, pkgJson);
|
|
317
|
-
}
|
|
318
|
-
async function writeKitIndexTs(config, sourcePath, packageName, templateType) {
|
|
319
|
-
const relIndexTsPath = path.join(sourcePath, "src", "index.ts");
|
|
320
|
-
const absIndexTsPath = config.path(relIndexTsPath);
|
|
321
|
-
if (!(await fs.pathExists(absIndexTsPath))) {
|
|
322
|
-
const template = exports.TEMPLATES[templateType];
|
|
323
|
-
const indexContent = template.replace("{{PACKAGE_NAME}}", packageName);
|
|
324
|
-
await config.askWriteProjectFile(relIndexTsPath, indexContent);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
async function scaffoldKitFiles(config, kitId, instanceId, packageName, version, templateType = exports.DEFAULT_TEMPLATE) {
|
|
328
|
-
const sourcePath = path.join(exports.FUNCTION_KITS_DIR, kitId, "source");
|
|
329
|
-
const configDirPath = path.join(exports.FUNCTION_KITS_DIR, kitId, `config-${instanceId}`);
|
|
330
|
-
const absSourcePath = config.path(sourcePath);
|
|
331
|
-
const absConfigDirPath = config.path(configDirPath);
|
|
332
|
-
await fs.ensureDir(absSourcePath);
|
|
333
|
-
await fs.ensureDir(absConfigDirPath);
|
|
334
|
-
await writeKitPackageJson(config, sourcePath, kitId, packageName, version);
|
|
335
|
-
await config.askWriteProjectFile(path.join(sourcePath, "tsconfig.json"), TSCONFIG_TEMPLATE);
|
|
336
|
-
await config.askWriteProjectFile(path.join(sourcePath, ".gitignore"), GITIGNORE_TEMPLATE);
|
|
337
|
-
await writeKitIndexTs(config, sourcePath, packageName, templateType);
|
|
338
|
-
return { sourcePath, configDirPath, absSourcePath };
|
|
339
|
-
}
|
|
340
|
-
async function buildAndInstallKit(absSourcePath, isThirdParty) {
|
|
341
|
-
const installArgs = isThirdParty ? ["install", "--ignore-scripts"] : ["install"];
|
|
342
|
-
(0, utils_1.logLabeledBullet)("functions", `Running npm ${installArgs.join(" ")}...`);
|
|
343
|
-
try {
|
|
344
|
-
await (0, spawn_1.wrapSpawn)("npm", installArgs, absSourcePath);
|
|
345
|
-
}
|
|
346
|
-
catch (err) {
|
|
347
|
-
throw new error_1.FirebaseError(`NPM install failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
348
|
-
}
|
|
349
|
-
(0, utils_1.logLabeledBullet)("functions", "Building TypeScript source...");
|
|
350
|
-
try {
|
|
351
|
-
await (0, spawn_1.wrapSpawn)("npm", ["run", "build"], absSourcePath);
|
|
352
|
-
}
|
|
353
|
-
catch (err) {
|
|
354
|
-
throw new error_1.FirebaseError(`TypeScript build failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
function addKitToConfig(config, kitId, instanceId, packageName, sourcePath, configDirPath) {
|
|
358
|
-
const configSrc = config.src;
|
|
359
|
-
const newKitConfig = {
|
|
360
|
-
kit: kitId,
|
|
361
|
-
sourcePackage: {
|
|
362
|
-
name: packageName,
|
|
363
|
-
},
|
|
364
|
-
source: sourcePath,
|
|
365
|
-
instances: {
|
|
366
|
-
[instanceId]: configDirPath,
|
|
367
|
-
},
|
|
368
|
-
predeploy: ['npm --prefix "$RESOURCE_DIR" run build'],
|
|
369
|
-
};
|
|
370
|
-
const functionsRaw = configSrc.functions;
|
|
371
|
-
if (!functionsRaw) {
|
|
372
|
-
configSrc.functions = [newKitConfig];
|
|
373
|
-
}
|
|
374
|
-
else if (Array.isArray(functionsRaw)) {
|
|
375
|
-
functionsRaw.push(newKitConfig);
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
configSrc.functions = [functionsRaw, newKitConfig];
|
|
379
|
-
}
|
|
380
|
-
config.writeProjectFile("firebase.json", configSrc);
|
|
381
|
-
}
|
|
7
|
+
const install_1 = require("../functions/kits/install");
|
|
382
8
|
exports.command = new command_1.Command("functions:kits:install")
|
|
383
9
|
.description("install a function kit into your project")
|
|
384
|
-
.option("--
|
|
385
|
-
.option(
|
|
10
|
+
.option("--package <package>", "NPM package name or specifier to install as a function kit")
|
|
11
|
+
.option("--directory <directory>", "path to a local functions codebase directory to install as a function kit")
|
|
12
|
+
.option(`--template <template>`, `template to use for the kit index file (${Object.keys(install_1.TEMPLATES).join("|")})`)
|
|
386
13
|
.action(async (options) => {
|
|
387
14
|
experiments.assertEnabled("kits", "install a function kit");
|
|
388
15
|
if (!options.config) {
|
|
389
16
|
throw new error_1.FirebaseError("Not in a Firebase project directory (firebase.json not found).");
|
|
390
17
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
const validTemplates = Object.keys(exports.TEMPLATES)
|
|
394
|
-
.map((t) => `'${t}'`)
|
|
395
|
-
.join(" or ");
|
|
396
|
-
throw new error_1.FirebaseError(`Invalid template '${templateType}'. Template must be ${validTemplates}.`);
|
|
18
|
+
if (options.package && options.directory) {
|
|
19
|
+
throw new error_1.FirebaseError("Cannot specify both --package and --directory. Please choose one.");
|
|
397
20
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
throw new error_1.FirebaseError("set the --npm_package option to a valid NPM package and try again.");
|
|
21
|
+
if (!options.package && !options.directory) {
|
|
22
|
+
throw new error_1.FirebaseError("Must specify either --package or --directory.");
|
|
401
23
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const existingFunctionsInfo = extractExistingFunctionsInfo(options.config.src.functions);
|
|
405
|
-
const existingKit = existingFunctionsInfo.existingFunctions.find((c) => (0, projectConfig_1.isKitConfig)(c) && c.sourcePackage?.name === packageName);
|
|
406
|
-
if (existingKit) {
|
|
407
|
-
await addKitInstanceOrConfigureProject(options, existingKit, existingFunctionsInfo);
|
|
408
|
-
return;
|
|
24
|
+
if (options.directory && options.template) {
|
|
25
|
+
throw new error_1.FirebaseError("Cannot specify --template with --directory.");
|
|
409
26
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
27
|
+
await (0, install_1.installKitOrInstance)({
|
|
28
|
+
config: options.config,
|
|
29
|
+
package: options.package,
|
|
30
|
+
directory: options.directory,
|
|
31
|
+
template: options.template,
|
|
32
|
+
nonInteractive: options.nonInteractive,
|
|
33
|
+
project: options.project,
|
|
34
|
+
projectId: options.projectId,
|
|
35
|
+
rc: options.rc,
|
|
36
|
+
});
|
|
417
37
|
});
|