UNPKG

firebase-tools

Version:
72 lines (71 loc) • 4.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.command = void 0; const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion"); const command_1 = require("../command"); const extensionsHelper_1 = require("../extensions/extensionsHelper"); const requirePermissions_1 = require("../requirePermissions"); const utils_1 = require("../utils"); const manifest = require("../extensions/manifest"); const projectUtils_1 = require("../projectUtils"); const migrate_1 = require("../extensions/migrate"); const extensionsApi_1 = require("../extensions/extensionsApi"); const export_1 = require("../extensions/export"); const error_1 = require("../error"); const prompt_1 = require("../prompt"); exports.command = new command_1.Command("ext:uninstall <extensionInstanceId>") .description("uninstall an extension that is installed in your Firebase project by instance ID") .option("--local", "deprecated") .option("--immediate", "immediately destroy GCP resources instead of waiting on next deploy. Can be run outside a firebase project directory if --project is specified.") .withForce() .before(requirePermissions_1.requirePermissions, ["firebaseextensions.instances.delete"]) .before(extensionsHelper_1.ensureExtensionsApiEnabled) .before(checkMinRequiredVersion_1.checkMinRequiredVersion, "extMinVersion") .before(extensionsHelper_1.diagnoseAndFixProject) .action(async (instanceId, options) => { if (options.local) { (0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, "As of firebase-tools@11.0.0, the `--local` flag is no longer required, as it is the default behavior."); } if (options.immediate) { const projectId = (0, projectUtils_1.needProjectId)(options); let instance; try { instance = await (0, extensionsApi_1.getInstance)(projectId, instanceId); } catch (err) { if (err instanceof error_1.FirebaseError && err.status === 404) { (0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, "ext:uninstall called with --immediate, but no deployed GCP resources found for the extension."); const config = manifest.loadConfig(options); manifest.removeFromManifest(instanceId, config); return; } throw new error_1.FirebaseError(`Failed to retrieve extension instance ${instanceId}: ${err instanceof Error ? err.message : String(err)}`, { original: err instanceof Error ? err : undefined, exit: 1, }); } if (!instance) { throw new error_1.FirebaseError(`Failed to retrieve extension instance ${instanceId}`); } instance = await (0, extensionsHelper_1.ensureInstanceSpec)(instance); const outstandingSecrets = await (0, export_1.secretsNeedingEjection)(instance); if (outstandingSecrets.length > 0) { const shouldContinue = await (0, prompt_1.confirm)({ message: `Extension instance ${instanceId} has secrets with the "firebase-extensions-managed" label:\n${outstandingSecrets.join(", ")}\nContinuing with extension uninstall will permanently destroy these secrets.\nYou can keep these secrets by running ext:export, or by manually removing the label in the Cloud Console.\nContinue?`, default: false, nonInteractive: options.nonInteractive, force: options.force, }); if (!shouldContinue) { if (options.nonInteractive && !options.force) { throw new error_1.FirebaseError(`Extension instance ${instanceId} has managed secrets that would be permanently destroyed. Re-run with --force in non-interactive mode to confirm deletion.`); } return; } } await (0, migrate_1.uninstallExtension)(projectId, instanceId, options, false); return; } const config = manifest.loadConfig(options); manifest.removeFromManifest(instanceId, config); });