firebase-tools
Version:
Command-Line Interface for Firebase
146 lines (145 loc) • 6.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.displayWarningsForDeploy = displayWarningsForDeploy;
exports.outOfBandChangesWarning = outOfBandChangesWarning;
exports.isSilenced = isSilenced;
exports.showDeprecationWarningBefore = showDeprecationWarningBefore;
exports.showDeprecationWarningAfter = showDeprecationWarningAfter;
const clc = require("colorette");
const extensionsHelper_1 = require("./extensionsHelper");
const deploymentSummary_1 = require("../deploy/extensions/deploymentSummary");
const planner_1 = require("../deploy/extensions/planner");
const error_1 = require("../error");
const logger_1 = require("../logger");
const utils = require("../utils");
const replacementRegistry_1 = require("./replacementRegistry");
const manifest = require("./manifest");
const refs = require("./refs");
const toListEntry = (i) => {
const idAndRef = (0, deploymentSummary_1.humanReadable)(i);
const sourceCodeLink = `\n\t[Source Code](${i.extensionVersion?.buildSourceUri ?? i.extensionVersion?.sourceDownloadUri})`;
const githubLink = i.extensionVersion?.spec?.sourceUrl
? `\n\t[Publisher Contact](${i.extensionVersion?.spec.sourceUrl})`
: "";
return `${idAndRef}${sourceCodeLink}${githubLink}`;
};
async function displayWarningsForDeploy(instancesToCreate) {
const uploadedExtensionInstances = instancesToCreate.filter((i) => i.ref);
for (const i of uploadedExtensionInstances) {
await (0, planner_1.getExtensionVersion)(i);
}
const unpublishedExtensions = uploadedExtensionInstances.filter((i) => i.extensionVersion?.listing?.state !== "APPROVED");
if (unpublishedExtensions.length) {
const humanReadableList = unpublishedExtensions.map(toListEntry).join("\n");
utils.logLabeledBullet(extensionsHelper_1.logPrefix, `The following extension versions have not been published to the Firebase Extensions Hub:\n${humanReadableList}\n.` +
"Unpublished extensions have not been reviewed by " +
"Firebase. Please make sure you trust the extension publisher before installing this extension.");
}
return unpublishedExtensions.length > 0;
}
function outOfBandChangesWarning(instanceIds, isDynamic) {
const extra = isDynamic
? ""
: " To avoid this, run `firebase ext:export` to sync these changes to your local extensions manifest.";
logger_1.logger.warn("The following instances may have been changed in the Firebase console or by another machine since the last deploy from this machine.\n\t" +
clc.bold(instanceIds.join("\n\t")) +
`\nIf you proceed with this deployment, those changes will be overwritten.${extra}`);
}
const FAQ_URL = "https://firebase.google.com/docs/extensions/faq-and-troubleshooting";
const BANNER_BORDER = "=".repeat(80);
const WARN_BEFORE_COMMANDS = new Set([
"ext:install",
"ext:configure",
"ext:update",
"ext:sdk:install",
]);
const WARN_STRONGLY_BEFORE_COMMANDS = new Set([
"ext:dev:init",
"ext:dev:upload",
"ext:dev:list",
"ext:dev:usage",
"ext:dev:undeprecate",
]);
const WARN_AFTER_COMMANDS = new Set(["ext:list", "ext:info", "ext:export"]);
function isSilenced(options) {
const opts = options;
if (opts?.json ||
utils.getInheritedOption(options, "json") ||
opts?.nonInteractive ||
utils.getInheritedOption(options, "nonInteractive") ||
!process.stdout?.isTTY ||
opts?.quiet ||
utils.getInheritedOption(options, "quiet")) {
return true;
}
if (utils.isRunningInGithubAction() ||
(!!process.env.CI && process.env.CI !== "false") ||
!!process.env.BUILD_ID ||
!!process.env.TF_BUILD ||
!!process.env.GITHUB_ACTIONS) {
return true;
}
return false;
}
function resolveExtensionRef(commandName, options, args = []) {
const firstArg = typeof args[0] === "string" ? args[0] : undefined;
if (!firstArg || (0, extensionsHelper_1.isLocalPath)(firstArg)) {
return undefined;
}
try {
const ref = commandName === "ext:configure" || commandName === "ext:update"
? manifest.getInstanceRef(firstArg, manifest.loadConfig(options))
: refs.parse(firstArg);
return refs.toExtensionRef(ref);
}
catch (err) {
logger_1.logger.debug(`Could not resolve extension ref for deprecation warning: ${String(err)}`);
return undefined;
}
}
async function showDeprecationWarningBefore(commandName, options, args = []) {
if (commandName === "ext:dev:register") {
throw new error_1.FirebaseError(`ext:dev:register is disabled. Registering new publisher profile IDs is no longer supported.\n` +
`The Firebase Extensions service will shut down on March 31, 2027.\n` +
`Learn more: ${FAQ_URL}`, { exit: 1 });
}
if (isSilenced(options)) {
return;
}
if (WARN_BEFORE_COMMANDS.has(commandName)) {
let actionLine = "We recommend migrating active instances to function kits.";
const ref = resolveExtensionRef(commandName, options, args);
if (ref) {
try {
const registry = await (0, replacementRegistry_1.getReplacementsRegistry)();
const npmPackage = (0, replacementRegistry_1.getReplacementPackageName)(ref, registry);
if (npmPackage) {
actionLine = `Recommended replacement: ${npmPackage}`;
}
}
catch (err) {
logger_1.logger.debug(`Failed to resolve replacement info for warning: ${String(err)}`);
}
}
logger_1.logger.warn(clc.yellow(`${BANNER_BORDER}\n` +
`⚠ Firebase Extensions will shut down on March 31, 2027.\n` +
`${actionLine}\n` +
`Learn more & view migration steps: ${FAQ_URL}\n` +
`${BANNER_BORDER}`));
}
else if (WARN_STRONGLY_BEFORE_COMMANDS.has(commandName)) {
logger_1.logger.warn(clc.yellow(`${BANNER_BORDER}\n` +
`⚠ Notice for Publishers: Firebase Extensions will shut down on March 31, 2027.\n` +
`Learn more & view migration steps: ${FAQ_URL}\n` +
`${BANNER_BORDER}`));
}
}
function showDeprecationWarningAfter(commandName, options) {
if (isSilenced(options) || !WARN_AFTER_COMMANDS.has(commandName)) {
return;
}
if (commandName === "ext:export" && options.mode === "functions") {
return;
}
logger_1.logger.warn(clc.yellow(`⚠ Notice: Firebase Extensions will shut down on March 31, 2027. Learn more & view migration steps: ${FAQ_URL}`));
}