firebase-tools 15.32.1 → 15.33.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 +4 -2
- package/lib/commands/apps-create.js +34 -3
- package/lib/commands/functions-kits-uninstall.js +43 -21
- package/lib/commands/functions-lifecycle-list.js +5 -6
- package/lib/commands/hosting-channel-deploy.js +3 -3
- package/lib/commands/hosting-clone.js +60 -29
- package/lib/commands/hosting-disable.js +5 -1
- package/lib/crashlytics/onboarding.js +17 -2
- package/lib/deploy/functions/build.js +3 -0
- package/lib/deploy/functions/cel.js +89 -58
- package/lib/deploy/functions/functionsDeployHelper.js +10 -0
- package/lib/deploy/functions/prepare.js +25 -8
- package/lib/deploy/functions/release/fabricator.js +1 -5
- package/lib/deploy/functions/release/planner.js +3 -2
- package/lib/deploy/functions/validate.js +16 -0
- package/lib/deploy/hosting/prepare.js +1 -1
- package/lib/deploy/hosting/release.js +2 -2
- package/lib/experiments.js +12 -0
- package/lib/frameworks/next/constants.js +20 -12
- package/lib/frameworks/next/index.js +3 -0
- package/lib/functions/env.js +4 -2
- package/lib/gcp/artifactregistry.js +20 -0
- package/lib/gcp/cloudtasks.js +14 -0
- package/lib/gcp/cloudtrace.js +38 -0
- package/lib/gcp/run.js +5 -0
- package/lib/gcp/runv2.js +32 -11
- package/lib/hosting/api.js +15 -15
- package/lib/hosting/runTags.js +1 -1
- package/lib/init/features/auth.js +46 -8
- package/lib/mcp/tools/firestore/converter.js +2 -2
- package/lib/mcp/util.js +11 -10
- package/lib/profileReport.js +4 -4
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
package/lib/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.developerKnowledgeOrigin = exports.cloudTestingOrigin = exports.appTestingOrigin = exports.aiLogicProxyOrigin = exports.vertexAIOrigin = exports.cloudSQLAdminOrigin = exports.dataConnectLocalConnString = exports.dataconnectP4SADomain = exports.dataconnectOrigin = exports.githubClientSecret = exports.githubClientId = exports.computeOrigin = exports.secretManagerOrigin = exports.githubApiOrigin = exports.githubOrigin = exports.studioApiOrigin = exports.serviceUsageOrigin = exports.cloudRunApiOrigin = exports.hostingApiOrigin = exports.firebaseStorageOrigin = exports.storageOrigin = void 0;
|
|
3
|
+
exports.rulesOrigin = exports.resourceManagerOrigin = exports.firebaseTelemetryAdminOrigin = exports.crashlyticsApiOrigin = exports.messagingApiOrigin = exports.remoteConfigApiOrigin = exports.rtdbMetadataOrigin = exports.rtdbManagementOrigin = exports.realtimeOrigin = exports.extensionsTOSOrigin = exports.extensionsPublisherOrigin = exports.extensionsOrigin = exports.iamOrigin = exports.identityOrigin = exports.hostingOrigin = exports.googleOrigin = exports.pubsubOrigin = exports.cloudTasksOrigin = exports.cloudschedulerOrigin = exports.cloudbuildOrigin = exports.functionsDefaultRegion = exports.runOrigin = exports.functionsV2Origin = exports.functionsOrigin = exports.firestoreOrigin = exports.firestoreOriginOrEmulator = exports.firedataOrigin = exports.firebaseExtensionsRegistryOrigin = exports.firebaseApiOrigin = exports.eventarcOrigin = exports.consoleOrigin = exports.authManagementOrigin = exports.authOrigin = exports.apphostingGitHubAppInstallationURL = exports.apphostingP4SADomain = exports.apphostingOrigin = exports.appDistributionOrigin = exports.appCheckOrigin = exports.apiKeysOrigin = exports.artifactRegistryDomain = exports.developerConnectP4SADomain = exports.developerConnectOrigin = exports.containerRegistryDomain = exports.cloudTraceOrigin = exports.cloudMonitoringOrigin = exports.cloudloggingOrigin = exports.cloudbillingOrigin = exports.clientSecret = exports.clientId = exports.authProxyOrigin = void 0;
|
|
4
|
+
exports.developerKnowledgeOrigin = exports.cloudTestingOrigin = exports.appTestingOrigin = exports.aiLogicProxyOrigin = exports.vertexAIOrigin = exports.cloudSQLAdminOrigin = exports.dataConnectLocalConnString = exports.dataconnectP4SADomain = exports.dataconnectOrigin = exports.githubClientSecret = exports.githubClientId = exports.computeOrigin = exports.secretManagerOrigin = exports.githubApiOrigin = exports.githubOrigin = exports.studioApiOrigin = exports.serviceUsageOrigin = exports.cloudRunApiOrigin = exports.hostingApiOrigin = exports.firebaseStorageOrigin = exports.storageOrigin = exports.runtimeconfigOrigin = void 0;
|
|
5
5
|
exports.getScopes = getScopes;
|
|
6
6
|
exports.setScopes = setScopes;
|
|
7
7
|
const constants_1 = require("./emulator/constants");
|
|
@@ -21,6 +21,8 @@ const cloudloggingOrigin = () => utils.envOverride("FIREBASE_CLOUDLOGGING_URL",
|
|
|
21
21
|
exports.cloudloggingOrigin = cloudloggingOrigin;
|
|
22
22
|
const cloudMonitoringOrigin = () => utils.envOverride("CLOUD_MONITORING_URL", "https://monitoring.googleapis.com");
|
|
23
23
|
exports.cloudMonitoringOrigin = cloudMonitoringOrigin;
|
|
24
|
+
const cloudTraceOrigin = () => utils.envOverride("CLOUD_TRACE_URL", "https://cloudtrace.googleapis.com");
|
|
25
|
+
exports.cloudTraceOrigin = cloudTraceOrigin;
|
|
24
26
|
const containerRegistryDomain = () => utils.envOverride("CONTAINER_REGISTRY_DOMAIN", "gcr.io");
|
|
25
27
|
exports.containerRegistryDomain = containerRegistryDomain;
|
|
26
28
|
const developerConnectOrigin = () => utils.envOverride("DEVELOPERCONNECT_URL", "https://developerconnect.googleapis.com");
|
|
@@ -9,6 +9,10 @@ const apps_1 = require("../management/apps");
|
|
|
9
9
|
const requireAuth_1 = require("../requireAuth");
|
|
10
10
|
const logger_1 = require("../logger");
|
|
11
11
|
const prompt_1 = require("../prompt");
|
|
12
|
+
const getDefaultHostingSite_1 = require("../getDefaultHostingSite");
|
|
13
|
+
const interactive_1 = require("../hosting/interactive");
|
|
14
|
+
const api_1 = require("../hosting/api");
|
|
15
|
+
const utils_1 = require("../utils");
|
|
12
16
|
function logPostAppCreationInformation(appMetadata, appPlatform) {
|
|
13
17
|
logger_1.logger.info("");
|
|
14
18
|
logger_1.logger.info(`🎉🎉🎉 Your Firebase ${appPlatform} App is ready! 🎉🎉🎉`);
|
|
@@ -40,8 +44,9 @@ exports.command = new command_1.Command("apps:create [platform] [displayName]")
|
|
|
40
44
|
.before(requireAuth_1.requireAuth)
|
|
41
45
|
.action(async (platform = "", displayName, options) => {
|
|
42
46
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
let chosenPlatform = typeof platform === "string" ? platform : "";
|
|
48
|
+
if (!options.nonInteractive && !chosenPlatform) {
|
|
49
|
+
chosenPlatform = await (0, prompt_1.select)({
|
|
45
50
|
message: "Please choose the platform of the app:",
|
|
46
51
|
choices: [
|
|
47
52
|
{ name: "iOS", value: apps_1.AppPlatform.IOS },
|
|
@@ -50,13 +55,39 @@ exports.command = new command_1.Command("apps:create [platform] [displayName]")
|
|
|
50
55
|
],
|
|
51
56
|
});
|
|
52
57
|
}
|
|
53
|
-
const appPlatform = (0, apps_1.getAppPlatform)(
|
|
58
|
+
const appPlatform = (0, apps_1.getAppPlatform)(chosenPlatform);
|
|
54
59
|
if (appPlatform === apps_1.AppPlatform.ANY) {
|
|
55
60
|
throw new error_1.FirebaseError("App platform must be provided");
|
|
56
61
|
}
|
|
57
62
|
logger_1.logger.info(`Create your ${appPlatform} app in project ${clc.bold(projectId)}:`);
|
|
63
|
+
let newSiteId;
|
|
64
|
+
if (appPlatform === apps_1.AppPlatform.WEB) {
|
|
65
|
+
const existingSite = await (0, getDefaultHostingSite_1.getDefaultHostingSite)({ projectId }).catch((err) => {
|
|
66
|
+
if (err !== getDefaultHostingSite_1.errNoDefaultSite) {
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (existingSite) {
|
|
71
|
+
logger_1.logger.info(`Firebase Hosting site is present: ${clc.bold(existingSite)}.`);
|
|
72
|
+
}
|
|
73
|
+
else if (await (0, prompt_1.confirm)({
|
|
74
|
+
message: "A Firebase Hosting site is recommended for Web apps. Would you like to create a default site now?",
|
|
75
|
+
default: true,
|
|
76
|
+
nonInteractive: options.nonInteractive,
|
|
77
|
+
})) {
|
|
78
|
+
newSiteId = await (0, interactive_1.pickHostingSiteName)("", {
|
|
79
|
+
projectId,
|
|
80
|
+
nonInteractive: options.nonInteractive,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
58
84
|
options.displayName = displayName;
|
|
59
85
|
const appData = await (0, apps_1.sdkInit)(appPlatform, options);
|
|
86
|
+
if (newSiteId) {
|
|
87
|
+
await (0, api_1.createSite)(projectId, newSiteId, appData.appId);
|
|
88
|
+
logger_1.logger.info("");
|
|
89
|
+
(0, utils_1.logSuccess)(`Firebase Hosting site ${newSiteId} created!`);
|
|
90
|
+
}
|
|
60
91
|
logPostAppCreationInformation(appData, appPlatform);
|
|
61
92
|
return appData;
|
|
62
93
|
});
|
|
@@ -13,6 +13,7 @@ const projectUtils_1 = require("../projectUtils");
|
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
14
|
const logger_1 = require("../logger");
|
|
15
15
|
const delete_1 = require("../deploy/functions/delete");
|
|
16
|
+
const ENV_FILE_PREFIX = ".env.";
|
|
16
17
|
exports.command = new command_1.Command("functions:kits:uninstall")
|
|
17
18
|
.description("uninstall a function kit or kit instance from your project. Deletes all running resources and the associated managed service account.")
|
|
18
19
|
.before(requireConfig_1.requireConfig)
|
|
@@ -73,10 +74,7 @@ async function handleInstance(options, config) {
|
|
|
73
74
|
const instanceConfigDirPath = kitForInstance.instances[instanceId];
|
|
74
75
|
const conservativeDeletion = nonstandardKitLayout(kitForInstance);
|
|
75
76
|
logger_1.logger.debug(`Kit ${kitForInstance.kit} uninstall mode: conservativeDeletion=${conservativeDeletion}`);
|
|
76
|
-
const
|
|
77
|
-
const envFileNames = configDirContents
|
|
78
|
-
.filter((f) => f.isFile() && f.name.startsWith(".env."))
|
|
79
|
-
.map((f) => f.name.slice(".env.".length));
|
|
77
|
+
const envFileNames = getInstanceEnvNames(config, instanceConfigDirPath);
|
|
80
78
|
const projectNamesInEnvs = envFileNames.map((envName) => options.rc ? options.rc.resolveAlias(envName) : envName);
|
|
81
79
|
if (projectNamesInEnvs.length > 0 && !projectNamesInEnvs.includes(projectId)) {
|
|
82
80
|
throw new error_1.FirebaseError(`Instance at ${instanceConfigDirPath} contains no .env file for current project`);
|
|
@@ -101,7 +99,7 @@ async function handleInstance(options, config) {
|
|
|
101
99
|
let filesystemNameForProject = projectId;
|
|
102
100
|
const envFilesWhichAliasToProject = envFileNames.filter((name) => (options.rc?.resolveAlias(name) || name) === projectId);
|
|
103
101
|
if (envFilesWhichAliasToProject.length > 1) {
|
|
104
|
-
throw new error_1.FirebaseError(`Instance ${instanceId} contains multiple .env files which ambiguously resolve to the current project ${envFilesWhichAliasToProject.map((s) =>
|
|
102
|
+
throw new error_1.FirebaseError(`Instance ${instanceId} contains multiple .env files which ambiguously resolve to the current project ${envFilesWhichAliasToProject.map((s) => ENV_FILE_PREFIX + s).join(", ")}`);
|
|
105
103
|
}
|
|
106
104
|
if (envFilesWhichAliasToProject.length === 1) {
|
|
107
105
|
filesystemNameForProject = envFilesWhichAliasToProject[0];
|
|
@@ -109,18 +107,8 @@ async function handleInstance(options, config) {
|
|
|
109
107
|
await uninstallProjectInstance(options, config, filesystemNameForProject, instanceId, instanceConfigDirPath);
|
|
110
108
|
}
|
|
111
109
|
async function uninstallInstance(options, config, instanceId, instanceConfigDirPath, onlyDeleteEmpty) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
for (const fileName of fileNames) {
|
|
115
|
-
if (!fileName.startsWith(".env.")) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const projectIdOrAlias = fileName.slice(".env.".length);
|
|
119
|
-
await uninstallProjectInstance(options, config, projectIdOrAlias, instanceId, instanceConfigDirPath);
|
|
120
|
-
}
|
|
121
|
-
if (!onlyDeleteEmpty || configDirEmpty(config, instanceConfigDirPath)) {
|
|
122
|
-
config.deleteProjectDir(instanceConfigDirPath);
|
|
123
|
-
}
|
|
110
|
+
await deleteInstancesFunctions(options, config, { [instanceId]: instanceConfigDirPath });
|
|
111
|
+
deleteInstanceConfigFiles(config, instanceConfigDirPath, onlyDeleteEmpty);
|
|
124
112
|
let functionsConfig = config.src.functions ?? [];
|
|
125
113
|
if (!Array.isArray(functionsConfig)) {
|
|
126
114
|
functionsConfig = [functionsConfig];
|
|
@@ -141,7 +129,7 @@ async function uninstallInstance(options, config, instanceId, instanceConfigDirP
|
|
|
141
129
|
}
|
|
142
130
|
async function uninstallProjectInstance(options, config, envName, instanceId, kitInstancePath) {
|
|
143
131
|
const projectId = options.rc?.resolveAlias(envName) || envName;
|
|
144
|
-
const envFilePath = (0, path_1.join)(kitInstancePath,
|
|
132
|
+
const envFilePath = (0, path_1.join)(kitInstancePath, `${ENV_FILE_PREFIX}${envName}`);
|
|
145
133
|
if (!config.projectFileExists(envFilePath)) {
|
|
146
134
|
throw new error_1.FirebaseError(`Expected to clean up project kit instance .env file at ${envFilePath}, but it doesn't exist.`);
|
|
147
135
|
}
|
|
@@ -155,10 +143,11 @@ async function uninstallProjectInstance(options, config, envName, instanceId, ki
|
|
|
155
143
|
}
|
|
156
144
|
async function uninstallKit(options, config, kit) {
|
|
157
145
|
const conservativeDeletion = nonstandardKitLayout(kit);
|
|
158
|
-
|
|
159
|
-
await uninstallInstance(options, config, instanceId, instanceConfigDir, conservativeDeletion);
|
|
160
|
-
}
|
|
146
|
+
await deleteInstancesFunctions(options, config, kit.instances);
|
|
161
147
|
if (conservativeDeletion) {
|
|
148
|
+
for (const instanceConfigDir of Object.values(kit.instances)) {
|
|
149
|
+
deleteInstanceConfigFiles(config, instanceConfigDir);
|
|
150
|
+
}
|
|
162
151
|
const instanceConfigDirParents = Object.values(kit.instances).map((p) => (0, posix_1.dirname)(p));
|
|
163
152
|
if (instanceConfigDirParents.length > 0 &&
|
|
164
153
|
instanceConfigDirParents.every((p) => p === instanceConfigDirParents[0]) &&
|
|
@@ -184,6 +173,33 @@ async function uninstallKit(options, config, kit) {
|
|
|
184
173
|
config.set("functions", functionsConfig);
|
|
185
174
|
config.writeProjectFile("firebase.json", config.src);
|
|
186
175
|
}
|
|
176
|
+
async function deleteInstancesFunctions(options, config, instances) {
|
|
177
|
+
const instancesByProject = new Map();
|
|
178
|
+
for (const [instanceId, instanceConfigDir] of Object.entries(instances)) {
|
|
179
|
+
for (const projectIdOrAlias of getInstanceEnvNames(config, instanceConfigDir)) {
|
|
180
|
+
const projectId = options.rc ? options.rc.resolveAlias(projectIdOrAlias) : projectIdOrAlias;
|
|
181
|
+
const list = instancesByProject.get(projectId) ?? [];
|
|
182
|
+
list.push(instanceId);
|
|
183
|
+
instancesByProject.set(projectId, list);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const [projectId, instanceIds] of instancesByProject.entries()) {
|
|
187
|
+
const epFilters = instanceIds.map((id) => ({ codebase: id }));
|
|
188
|
+
const deployContext = { projectId, filters: epFilters };
|
|
189
|
+
const deletionCount = await (0, delete_1.deleteFunctionsByEndpointFilters)(deployContext, options);
|
|
190
|
+
if (deletionCount === 0) {
|
|
191
|
+
logger_1.logger.info(`No deployed functions found for instances: ${instanceIds.join(", ")}. This is normal if firebase deploy was never run.`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function deleteInstanceConfigFiles(config, instanceConfigDirPath, onlyDeleteEmpty = true) {
|
|
196
|
+
for (const projectIdOrAlias of getInstanceEnvNames(config, instanceConfigDirPath)) {
|
|
197
|
+
config.deleteProjectFile((0, path_1.join)(instanceConfigDirPath, `${ENV_FILE_PREFIX}${projectIdOrAlias}`));
|
|
198
|
+
}
|
|
199
|
+
if (!onlyDeleteEmpty || configDirEmpty(config, instanceConfigDirPath)) {
|
|
200
|
+
config.deleteProjectDir(instanceConfigDirPath);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
187
203
|
function nonstandardKitLayout(kitConfig) {
|
|
188
204
|
if (kitConfig.sourcePackage) {
|
|
189
205
|
if (kitConfig.source !== `function-kits/${kitConfig.kit}/source`) {
|
|
@@ -209,3 +225,9 @@ function configDirEmpty(config, projectRelativePath) {
|
|
|
209
225
|
}
|
|
210
226
|
return true;
|
|
211
227
|
}
|
|
228
|
+
function getInstanceEnvNames(config, instanceConfigDirPath) {
|
|
229
|
+
return config
|
|
230
|
+
.lsProjectDir(instanceConfigDirPath)
|
|
231
|
+
.filter((f) => f.isFile() && f.name.startsWith(ENV_FILE_PREFIX))
|
|
232
|
+
.map((f) => f.name.slice(ENV_FILE_PREFIX.length));
|
|
233
|
+
}
|
|
@@ -19,16 +19,13 @@ async function loadCodebaseBuild(codebase, options) {
|
|
|
19
19
|
throw new error_1.FirebaseError("Not in a Firebase project directory (firebase.json not found).");
|
|
20
20
|
}
|
|
21
21
|
const fnConfig = (0, projectConfig_1.normalizeAndValidate)(options.config.src.functions);
|
|
22
|
-
const
|
|
23
|
-
if (!hasCodebase) {
|
|
24
|
-
throw new error_1.FirebaseError(`Codebase "${codebase}" is not defined in firebase.json.`);
|
|
25
|
-
}
|
|
22
|
+
const codebaseConfig = (0, projectConfig_1.configForCodebase)(fnConfig, codebase);
|
|
26
23
|
const firebaseConfig = await (0, adminSdkConfig_1.getProjectAdminSdkConfigOrCached)(projectId);
|
|
27
24
|
if (!firebaseConfig) {
|
|
28
25
|
throw new error_1.FirebaseError("Admin SDK config unexpectedly undefined - have you run firebase init?");
|
|
29
26
|
}
|
|
30
27
|
let runtimeConfig = { firebase: firebaseConfig };
|
|
31
|
-
if (
|
|
28
|
+
if ((0, projectConfig_1.shouldUseRuntimeConfig)(codebaseConfig)) {
|
|
32
29
|
try {
|
|
33
30
|
const runtimeConfigApiEnabled = await ensureApiEnabled.check(projectId, (0, api_1.runtimeconfigOrigin)(), "runtimeconfig", true);
|
|
34
31
|
if (runtimeConfigApiEnabled) {
|
|
@@ -39,7 +36,9 @@ async function loadCodebaseBuild(codebase, options) {
|
|
|
39
36
|
logger_1.logger.debug("Could not check Runtime Config API status, assuming disabled:", err);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
|
-
const wantBuilds = await (0, prepare_1.loadCodebases)(fnConfig, options, firebaseConfig, runtimeConfig,
|
|
39
|
+
const wantBuilds = await (0, prepare_1.loadCodebases)(fnConfig, options, firebaseConfig, runtimeConfig, [
|
|
40
|
+
{ codebase },
|
|
41
|
+
]);
|
|
43
42
|
const codebaseBuild = wantBuilds[codebase];
|
|
44
43
|
if (!codebaseBuild) {
|
|
45
44
|
throw new error_1.FirebaseError(`Failed to load build for codebase "${codebase}".`);
|
|
@@ -112,13 +112,13 @@ async function hostingChannelDeployAction(channelId, options) {
|
|
|
112
112
|
if (d.expireTime) {
|
|
113
113
|
expires = `[expires ${(0, colorette_1.bold)((0, utils_1.datetimeString)(new Date(d.expireTime)))}]`;
|
|
114
114
|
}
|
|
115
|
-
const versionPrefix = `sites/${d.site}/versions/`;
|
|
115
|
+
const versionPrefix = `projects/${projectId}/sites/${d.site}/versions/`;
|
|
116
116
|
const versionName = versionNames.find((v) => {
|
|
117
|
-
return v.startsWith(versionPrefix);
|
|
117
|
+
return v.startsWith(versionPrefix) || v.startsWith(`sites/${d.site}/versions/`);
|
|
118
118
|
});
|
|
119
119
|
let version = "";
|
|
120
120
|
if (versionName) {
|
|
121
|
-
d.version = versionName.
|
|
121
|
+
d.version = (0, utils_1.last)(versionName.split("/")) || "";
|
|
122
122
|
version = ` [version ${(0, colorette_1.bold)(d.version)}]`;
|
|
123
123
|
}
|
|
124
124
|
(0, utils_1.logLabeledSuccess)(LOG_TAG, `Channel URL (${(0, colorette_1.bold)(d.site || d.target || "")}): ${d.url} ${expires}${version}`);
|
|
@@ -9,6 +9,7 @@ const api_1 = require("../hosting/api");
|
|
|
9
9
|
const utils = require("../utils");
|
|
10
10
|
const requireAuth_1 = require("../requireAuth");
|
|
11
11
|
const logger_1 = require("../logger");
|
|
12
|
+
const projectUtils_1 = require("../projectUtils");
|
|
12
13
|
exports.command = new command_1.Command("hosting:clone <source> <targetChannel>")
|
|
13
14
|
.description("clone a version from one site to another")
|
|
14
15
|
.help(`<source> and <targetChannel> accept the following format: <siteId>:<channelId>
|
|
@@ -17,32 +18,64 @@ For example, to copy the content for a site \`my-site\` from a preview channel \
|
|
|
17
18
|
|
|
18
19
|
firebase hosting:clone my-site:foo my-site:live`)
|
|
19
20
|
.before(requireAuth_1.requireAuth)
|
|
20
|
-
.action(async (source = "", targetChannel = "") => {
|
|
21
|
-
let
|
|
21
|
+
.action(async (source = "", targetChannel = "", options) => {
|
|
22
|
+
let sourceProjectId;
|
|
23
|
+
let sourceSiteId;
|
|
24
|
+
let sourceChannelId;
|
|
22
25
|
let sourceVersion;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (source.includes("@")) {
|
|
27
|
+
const [sitePart, version] = source.split("@");
|
|
28
|
+
sourceVersion = version;
|
|
29
|
+
if (sitePart.includes(":")) {
|
|
30
|
+
[sourceProjectId, sourceSiteId] = sitePart.split(":");
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
sourceSiteId = sitePart;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const parts = source.split(":");
|
|
38
|
+
if (parts.length === 3) {
|
|
39
|
+
[sourceProjectId, sourceSiteId, sourceChannelId] = parts;
|
|
29
40
|
}
|
|
30
|
-
|
|
41
|
+
else if (parts.length === 2) {
|
|
42
|
+
[sourceSiteId, sourceChannelId] = parts;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
let targetProjectId;
|
|
46
|
+
let targetSiteId;
|
|
47
|
+
let targetChannelId;
|
|
48
|
+
const targetParts = targetChannel.split(":");
|
|
49
|
+
if (targetParts.length === 3) {
|
|
50
|
+
[targetProjectId, targetSiteId, targetChannelId] = targetParts;
|
|
51
|
+
}
|
|
52
|
+
else if (targetParts.length === 2) {
|
|
53
|
+
[targetSiteId, targetChannelId] = targetParts;
|
|
54
|
+
}
|
|
55
|
+
if (!sourceSiteId || (!sourceChannelId && !sourceVersion)) {
|
|
56
|
+
throw new error_1.FirebaseError(`"${source}" is not a valid source. Must be in the form "<site>:<channel>" or "<site>@<version>"`);
|
|
31
57
|
}
|
|
32
58
|
if (!targetSiteId || !targetChannelId) {
|
|
33
59
|
throw new error_1.FirebaseError(`"${targetChannel}" is not a valid target channel. Must be in the form "<site>:<channel>" (to clone to the active website, use "live" as the channel).`);
|
|
34
60
|
}
|
|
61
|
+
sourceProjectId = sourceProjectId || (0, projectUtils_1.needProjectId)(options);
|
|
62
|
+
targetProjectId = targetProjectId || (0, projectUtils_1.needProjectId)(options);
|
|
35
63
|
targetChannelId = (0, api_1.normalizeName)(targetChannelId);
|
|
36
64
|
if (sourceChannelId) {
|
|
37
65
|
sourceChannelId = (0, api_1.normalizeName)(sourceChannelId);
|
|
38
66
|
}
|
|
67
|
+
const equalProjectIds = sourceProjectId === targetProjectId;
|
|
39
68
|
const equalSiteIds = sourceSiteId === targetSiteId;
|
|
40
69
|
const equalChannelIds = sourceChannelId === targetChannelId;
|
|
41
|
-
if (equalSiteIds && equalChannelIds) {
|
|
42
|
-
throw new error_1.FirebaseError(`Source and destination cannot be equal. Please pick a different source or
|
|
70
|
+
if (equalProjectIds && equalSiteIds && equalChannelIds) {
|
|
71
|
+
throw new error_1.FirebaseError(`Source and destination cannot be equal. Please pick a different source or destination.`);
|
|
43
72
|
}
|
|
44
|
-
|
|
45
|
-
|
|
73
|
+
let sourceVersionName;
|
|
74
|
+
if (sourceVersion) {
|
|
75
|
+
sourceVersionName = `projects/${sourceProjectId}/sites/${sourceSiteId}/versions/${sourceVersion}`;
|
|
76
|
+
}
|
|
77
|
+
else if (sourceChannelId) {
|
|
78
|
+
const sChannel = await (0, api_1.getChannel)(sourceProjectId, sourceSiteId, sourceChannelId);
|
|
46
79
|
if (!sChannel) {
|
|
47
80
|
throw new error_1.FirebaseError(`Could not find the channel ${(0, colorette_1.bold)(sourceChannelId)} for site ${(0, colorette_1.bold)(sourceSiteId)}.`);
|
|
48
81
|
}
|
|
@@ -51,51 +84,49 @@ For example, to copy the content for a site \`my-site\` from a preview channel \
|
|
|
51
84
|
throw new error_1.FirebaseError(`Could not find a version on the channel ${(0, colorette_1.bold)(sourceChannelId)} for site ${(0, colorette_1.bold)(sourceSiteId)}.`);
|
|
52
85
|
}
|
|
53
86
|
}
|
|
54
|
-
|
|
87
|
+
if (!sourceVersionName) {
|
|
88
|
+
throw new error_1.FirebaseError(`Could not find a version to clone for site ${(0, colorette_1.bold)(sourceSiteId)}.`);
|
|
89
|
+
}
|
|
90
|
+
let tChannel = await (0, api_1.getChannel)(targetProjectId, targetSiteId, targetChannelId);
|
|
55
91
|
if (!tChannel) {
|
|
56
92
|
utils.logBullet(`could not find channel ${(0, colorette_1.bold)(targetChannelId)} in site ${(0, colorette_1.bold)(targetSiteId)}, creating it...`);
|
|
57
93
|
try {
|
|
58
|
-
tChannel = await (0, api_1.createChannel)(
|
|
94
|
+
tChannel = await (0, api_1.createChannel)(targetProjectId, targetSiteId, targetChannelId);
|
|
59
95
|
}
|
|
60
96
|
catch (e) {
|
|
61
97
|
throw new error_1.FirebaseError(`Could not create the channel ${(0, colorette_1.bold)(targetChannelId)} for site ${(0, colorette_1.bold)(targetSiteId)}.`, { original: e });
|
|
62
98
|
}
|
|
63
99
|
utils.logSuccess(`Created new channel ${targetChannelId}`);
|
|
64
100
|
try {
|
|
65
|
-
|
|
66
|
-
await (0, api_1.addAuthDomains)(tProjectId, [tChannel.url]);
|
|
101
|
+
await (0, api_1.addAuthDomains)(targetProjectId, [tChannel.url]);
|
|
67
102
|
}
|
|
68
103
|
catch (e) {
|
|
69
|
-
utils.logLabeledWarning("hosting:clone", `Unable to add channel domain to Firebase Auth. Visit the Firebase Console at ${utils.consoleUrl(
|
|
104
|
+
utils.logLabeledWarning("hosting:clone", `Unable to add channel domain to Firebase Auth. Visit the Firebase Console at ${utils.consoleUrl(targetProjectId, "/authentication/providers")}`);
|
|
70
105
|
logger_1.logger.debug("[hosting] unable to add auth domain", e);
|
|
71
106
|
}
|
|
72
107
|
}
|
|
73
108
|
const currentTargetVersionName = tChannel.release?.version?.name;
|
|
74
|
-
if (equalSiteIds && sourceVersionName === currentTargetVersionName) {
|
|
75
|
-
utils.logSuccess(`Channels ${(0, colorette_1.bold)(sourceChannelId)} and ${(0, colorette_1.bold)(targetChannel)} are serving identical versions. No need to clone.`);
|
|
109
|
+
if (equalProjectIds && equalSiteIds && sourceVersionName === currentTargetVersionName) {
|
|
110
|
+
utils.logSuccess(`Channels ${(0, colorette_1.bold)(sourceChannelId || sourceVersion || "")} and ${(0, colorette_1.bold)(targetChannel)} are serving identical versions. No need to clone.`);
|
|
76
111
|
return;
|
|
77
112
|
}
|
|
78
113
|
let targetVersionName = sourceVersionName;
|
|
79
114
|
const spinner = ora("Cloning site content...").start();
|
|
80
115
|
try {
|
|
81
|
-
if (!equalSiteIds) {
|
|
82
|
-
const targetVersion = await (0, api_1.cloneVersion)(targetSiteId, sourceVersionName, true);
|
|
116
|
+
if (!equalSiteIds || !equalProjectIds) {
|
|
117
|
+
const targetVersion = await (0, api_1.cloneVersion)(targetProjectId, targetSiteId, sourceVersionName, true);
|
|
83
118
|
if (!targetVersion) {
|
|
84
|
-
throw new error_1.FirebaseError(`Could not clone the version ${(0, colorette_1.bold)(sourceVersion)} for site ${(0, colorette_1.bold)(targetSiteId)}.`);
|
|
119
|
+
throw new error_1.FirebaseError(`Could not clone the version ${(0, colorette_1.bold)(sourceVersion || sourceVersionName)} for site ${(0, colorette_1.bold)(targetSiteId)}.`);
|
|
85
120
|
}
|
|
86
121
|
targetVersionName = targetVersion.name;
|
|
87
122
|
}
|
|
88
|
-
await (0, api_1.createRelease)(targetSiteId, targetChannelId, targetVersionName);
|
|
123
|
+
await (0, api_1.createRelease)(targetProjectId, targetSiteId, targetChannelId, targetVersionName);
|
|
89
124
|
}
|
|
90
125
|
catch (err) {
|
|
91
126
|
spinner.fail();
|
|
92
127
|
throw err;
|
|
93
128
|
}
|
|
94
129
|
spinner.succeed();
|
|
95
|
-
utils.logSuccess(`Site ${(0, colorette_1.bold)(sourceSiteId)} ${sourceChannelId ? "channel" : "version"} ${(0, colorette_1.bold)(sourceChannelId || sourceVersion)} has been cloned to site ${(0, colorette_1.bold)(targetSiteId)} channel ${(0, colorette_1.bold)(targetChannelId)}.`);
|
|
130
|
+
utils.logSuccess(`Site ${(0, colorette_1.bold)(sourceSiteId)} ${sourceChannelId ? "channel" : "version"} ${(0, colorette_1.bold)(sourceChannelId || sourceVersion || sourceVersionName)} has been cloned to site ${(0, colorette_1.bold)(targetSiteId)} channel ${(0, colorette_1.bold)(targetChannelId)}.`);
|
|
96
131
|
utils.logSuccess(`Channel URL (${targetChannelId}): ${tChannel.url}`);
|
|
97
132
|
});
|
|
98
|
-
function parseProjectId(name) {
|
|
99
|
-
const matches = name.match(`^projects/([^/]+)`);
|
|
100
|
-
return matches ? matches[1] || "" : "";
|
|
101
|
-
}
|
|
@@ -8,6 +8,7 @@ const api_1 = require("../api");
|
|
|
8
8
|
const prompt_1 = require("../prompt");
|
|
9
9
|
const requireHostingSite_1 = require("../requireHostingSite");
|
|
10
10
|
const requirePermissions_1 = require("../requirePermissions");
|
|
11
|
+
const projectUtils_1 = require("../projectUtils");
|
|
11
12
|
const utils = require("../utils");
|
|
12
13
|
exports.command = new command_1.Command("hosting:disable")
|
|
13
14
|
.description("stop serving web traffic to your Firebase Hosting site")
|
|
@@ -16,6 +17,7 @@ exports.command = new command_1.Command("hosting:disable")
|
|
|
16
17
|
.before(requirePermissions_1.requirePermissions, ["firebasehosting.sites.update"])
|
|
17
18
|
.before(requireHostingSite_1.requireHostingSite)
|
|
18
19
|
.action(async (options) => {
|
|
20
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
19
21
|
const siteToDisable = options.site;
|
|
20
22
|
const confirmed = await (0, prompt_1.confirm)({
|
|
21
23
|
message: `Are you sure you want to disable Firebase Hosting for the site ${clc.underline(siteToDisable)}\n${clc.underline("This will immediately make your site inaccessible!")}`,
|
|
@@ -26,6 +28,8 @@ exports.command = new command_1.Command("hosting:disable")
|
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
28
30
|
const c = new apiv2_1.Client({ urlPrefix: (0, api_1.hostingApiOrigin)(), apiVersion: "v1beta1", auth: true });
|
|
29
|
-
await c.post(`/sites/${siteToDisable}/releases`, {
|
|
31
|
+
await c.post(`/projects/${projectId}/sites/${siteToDisable}/releases`, {
|
|
32
|
+
type: "SITE_DISABLE",
|
|
33
|
+
});
|
|
30
34
|
utils.logSuccess(`Hosting has been disabled for ${clc.bold(siteToDisable)}. Deploy a new version to re-enable.`);
|
|
31
35
|
});
|
|
@@ -12,6 +12,7 @@ const firebasetelemetry_1 = require("./firebasetelemetry");
|
|
|
12
12
|
const types_1 = require("./types");
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
14
|
const apikeys_1 = require("../gcp/apikeys");
|
|
15
|
+
const cloudtrace_1 = require("../gcp/cloudtrace");
|
|
15
16
|
const apps_1 = require("../management/apps");
|
|
16
17
|
const logger_1 = require("../logger");
|
|
17
18
|
const prompt_1 = require("../prompt");
|
|
@@ -42,10 +43,14 @@ async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
|
|
|
42
43
|
await (0, cloudbilling_1.enableBilling)(projectId, "Crashlytics");
|
|
43
44
|
}
|
|
44
45
|
(0, utils_1.logLabeledBullet)("crashlytics", "Enabling required telemetry APIs...");
|
|
45
|
-
|
|
46
|
+
const requiredApis = [
|
|
46
47
|
(0, ensureApiEnabled_1.ensure)(projectId, exports.CRASHLYTICS_TELEMETRY_SERVICE, "crashlytics", false),
|
|
47
48
|
(0, ensureApiEnabled_1.ensure)(projectId, "firebasetelemetryadmin.googleapis.com", "crashlytics", false),
|
|
48
|
-
]
|
|
49
|
+
];
|
|
50
|
+
if (experiments.isEnabled("crashlyticsWebTrace")) {
|
|
51
|
+
requiredApis.push((0, ensureApiEnabled_1.ensure)(projectId, "cloudtrace.googleapis.com", "crashlytics", false));
|
|
52
|
+
}
|
|
53
|
+
await Promise.all(requiredApis);
|
|
49
54
|
(0, utils_1.logLabeledSuccess)("crashlytics", "Telemetry APIs enabled.");
|
|
50
55
|
const appConfig = await (0, apps_1.getAppConfig)(appId, apps_1.AppPlatform.WEB);
|
|
51
56
|
if ("apiKey" in appConfig && appConfig.apiKey) {
|
|
@@ -73,6 +78,16 @@ async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
|
|
|
73
78
|
(0, utils_1.logLabeledBullet)("crashlytics", `Setting up Cloud Logging routing sink '${exports.CRASHLYTICS_TELEMETRY_SINK_ID}'...`);
|
|
74
79
|
const sink = await (0, cloudlogging_1.createOrUpdateLogSink)(projectId, exports.CRASHLYTICS_TELEMETRY_SINK_ID, destination, filter);
|
|
75
80
|
(0, utils_1.logLabeledSuccess)("crashlytics", "Cloud Logging routing sink configured.");
|
|
81
|
+
if (experiments.isEnabled("crashlyticsWebTrace")) {
|
|
82
|
+
(0, utils_1.logLabeledBullet)("crashlytics", "Provisioning Cloud Trace storage...");
|
|
83
|
+
try {
|
|
84
|
+
await (0, cloudtrace_1.provisionTraceStorage)(projectId);
|
|
85
|
+
(0, utils_1.logLabeledSuccess)("crashlytics", "Cloud Trace storage provisioned.");
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
(0, utils_1.logLabeledWarning)("crashlytics", (0, error_1.getErrMsg)(err));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
76
91
|
(0, utils_1.logLabeledBullet)("crashlytics", "Configuring Crashlytics telemetry for web app...");
|
|
77
92
|
const config = await (0, firebasetelemetry_1.createOrUpdateTelemetryConfig)(projectId, appId, `projects/${projectId}/locations/global/buckets/${exports.CRASHLYTICS_TELEMETRY_BUCKET_ID}`, 1);
|
|
78
93
|
(0, utils_1.logLabeledSuccess)("crashlytics", "Crashlytics telemetry configured successfully.");
|
|
@@ -94,6 +94,9 @@ async function resolveBackend(opts) {
|
|
|
94
94
|
nonInteractive: opts.nonInteractive,
|
|
95
95
|
isEmulator: opts.isEmulator,
|
|
96
96
|
});
|
|
97
|
+
if (opts.resolveRegions) {
|
|
98
|
+
await opts.resolveRegions(opts.build, paramValues);
|
|
99
|
+
}
|
|
97
100
|
return { backend: toBackend(opts.build, paramValues), envs: paramValues, secretRefs: secretRefs };
|
|
98
101
|
}
|
|
99
102
|
function envWithTypes(definedParams, rawEnvs) {
|