Sin descripción
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

experiments.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.flushToDisk = exports.assertEnabled = exports.enableExperimentsFromCliEnvVariable = exports.setEnabled = exports.isEnabled = exports.experimentNameAutocorrect = exports.isValidExperiment = exports.ALL_EXPERIMENTS = void 0;
  4. const colorette_1 = require("colorette");
  5. const leven = require("leven");
  6. const configstore_1 = require("./configstore");
  7. const error_1 = require("./error");
  8. function experiments(exp) {
  9. return Object.freeze(exp);
  10. }
  11. exports.ALL_EXPERIMENTS = experiments({
  12. experiments: {
  13. shortDescription: "enables the experiments family of commands",
  14. },
  15. rtdbrules: {
  16. shortDescription: "Advanced security rules management",
  17. },
  18. rtdbmanagement: {
  19. shortDescription: "Use new endpoint to administer realtime database instances",
  20. },
  21. ext: {
  22. shortDescription: `Enables the ${(0, colorette_1.bold)("ext:sources:create")} command`,
  23. },
  24. extdev: {
  25. shortDescription: `Enables the ${(0, colorette_1.bold)("ext:dev")} family of commands`,
  26. docsUri: "https://firebase.google.com/docs/extensions/alpha/overview-build-extensions",
  27. },
  28. pythonfunctions: {
  29. shortDescription: "Python support for Cloud Functions for Firebase",
  30. fullDescription: "Adds the ability to initializea and deploy Cloud " +
  31. "Functions for Firebase in Python. While this feature is experimental " +
  32. "breaking API changes are allowed in MINOR API revisions",
  33. },
  34. deletegcfartifacts: {
  35. shortDescription: `Add the ${(0, colorette_1.bold)("functions:deletegcfartifacts")} command to purge docker build images`,
  36. fullDescription: `Add the ${(0, colorette_1.bold)("functions:deletegcfartifacts")}` +
  37. "command. Google Cloud Functions creates Docker images when building your " +
  38. "functions. Cloud Functions for Firebase automatically cleans up these " +
  39. "images for you on deploy. Customers who predated this cleanup, or customers " +
  40. "who also deploy Google Cloud Functions with non-Firebase tooling may have " +
  41. "old Docker images stored in either Google Container Repository or Artifact " +
  42. `Registry. The ${(0, colorette_1.bold)("functions:deletegcfartifacts")} command ` +
  43. "will delete all Docker images created by Google Cloud Functions irrespective " +
  44. "of how that image was created.",
  45. public: true,
  46. },
  47. functionsparams: {
  48. shortDescription: "Adds support for paramaterizing functions deployments",
  49. default: true,
  50. },
  51. emulatoruisnapshot: {
  52. shortDescription: "Load pre-release versions of the emulator UI",
  53. },
  54. webframeworks: {
  55. shortDescription: "Native support for popular web frameworks",
  56. fullDescription: "Adds support for popular web frameworks such as Next.js " +
  57. "Angular, React, Svelte, and Vite-compatible frameworks. Firebase is " +
  58. "committed to support these platforms long-term, but a manual migration " +
  59. "may be required when the non-experimental support for these frameworks " +
  60. "is released",
  61. docsUri: "https://firebase.google.com/docs/hosting/frameworks-overview",
  62. public: true,
  63. },
  64. pintags: {
  65. shortDescription: "Adds the pinTag option to Run and Functions rewrites",
  66. fullDescription: "Adds support for the 'pinTag' boolean on Runction and Run rewrites for " +
  67. "Firebase Hosting. With this option, newly released hosting sites will be " +
  68. "bound to the current latest version of their referenced functions or services. " +
  69. "This option depends on Run pinned traffic targets, of which only 2000 can " +
  70. "exist per region. firebase-tools aggressively garbage collects tags it creates " +
  71. "if any service exceeds 500 tags, but it is theoretically possible that a project " +
  72. "exceeds the region-wide limit of tags and an old site version fails",
  73. },
  74. crossservicerules: {
  75. shortDescription: "Allow Firebase Rules to reference resources in other services",
  76. },
  77. internaltesting: {
  78. shortDescription: "Exposes Firebase CLI commands intended for internal testing purposes.",
  79. fullDescription: "Exposes Firebase CLI commands intended for internal testing purposes. " +
  80. "These commands are not meant for public consumption and may break or disappear " +
  81. "without a notice.",
  82. },
  83. });
  84. function isValidExperiment(name) {
  85. return Object.keys(exports.ALL_EXPERIMENTS).includes(name);
  86. }
  87. exports.isValidExperiment = isValidExperiment;
  88. function experimentNameAutocorrect(malformed) {
  89. if (isValidExperiment(malformed)) {
  90. throw new error_1.FirebaseError("Assertion failed: experimentNameAutocorrect given actual experiment name", { exit: 2 });
  91. }
  92. return Object.keys(exports.ALL_EXPERIMENTS).filter((name) => leven(name, malformed) < malformed.length * 0.4);
  93. }
  94. exports.experimentNameAutocorrect = experimentNameAutocorrect;
  95. let localPreferencesCache = undefined;
  96. function localPreferences() {
  97. if (!localPreferencesCache) {
  98. localPreferencesCache = (configstore_1.configstore.get("previews") || {});
  99. for (const key of Object.keys(localPreferencesCache)) {
  100. if (!isValidExperiment(key)) {
  101. delete localPreferencesCache[key];
  102. }
  103. }
  104. }
  105. return localPreferencesCache;
  106. }
  107. function isEnabled(name) {
  108. var _a, _b, _c;
  109. return (_c = (_a = localPreferences()[name]) !== null && _a !== void 0 ? _a : (_b = exports.ALL_EXPERIMENTS[name]) === null || _b === void 0 ? void 0 : _b.default) !== null && _c !== void 0 ? _c : false;
  110. }
  111. exports.isEnabled = isEnabled;
  112. function setEnabled(name, to) {
  113. if (to === null) {
  114. delete localPreferences()[name];
  115. }
  116. else {
  117. localPreferences()[name] = to;
  118. }
  119. }
  120. exports.setEnabled = setEnabled;
  121. function enableExperimentsFromCliEnvVariable() {
  122. const experiments = process.env.FIREBASE_CLI_EXPERIMENTS || "";
  123. for (const experiment of experiments.split(",")) {
  124. if (isValidExperiment(experiment)) {
  125. setEnabled(experiment, true);
  126. }
  127. }
  128. }
  129. exports.enableExperimentsFromCliEnvVariable = enableExperimentsFromCliEnvVariable;
  130. function assertEnabled(name, task) {
  131. if (!isEnabled(name)) {
  132. throw new error_1.FirebaseError(`Cannot ${task} because the experiment ${(0, colorette_1.bold)(name)} is not enabled. To enable ${(0, colorette_1.bold)(name)} run ${(0, colorette_1.bold)(`firebase experiments:enable ${name}`)}`);
  133. }
  134. }
  135. exports.assertEnabled = assertEnabled;
  136. function flushToDisk() {
  137. configstore_1.configstore.set("previews", localPreferences());
  138. }
  139. exports.flushToDisk = flushToDisk;