featureFlags.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. function _export(target, all) {
  6. for(var name in all)Object.defineProperty(target, name, {
  7. enumerable: true,
  8. get: all[name]
  9. });
  10. }
  11. _export(exports, {
  12. flagEnabled: function() {
  13. return flagEnabled;
  14. },
  15. issueFlagNotices: function() {
  16. return issueFlagNotices;
  17. },
  18. default: function() {
  19. return _default;
  20. }
  21. });
  22. const _picocolors = /*#__PURE__*/ _interop_require_default(require("picocolors"));
  23. const _log = /*#__PURE__*/ _interop_require_default(require("./util/log"));
  24. function _interop_require_default(obj) {
  25. return obj && obj.__esModule ? obj : {
  26. default: obj
  27. };
  28. }
  29. let defaults = {
  30. optimizeUniversalDefaults: false,
  31. generalizedModifiers: true,
  32. disableColorOpacityUtilitiesByDefault: false,
  33. relativeContentPathsByDefault: false
  34. };
  35. let featureFlags = {
  36. future: [
  37. "hoverOnlyWhenSupported",
  38. "respectDefaultRingColorOpacity",
  39. "disableColorOpacityUtilitiesByDefault",
  40. "relativeContentPathsByDefault"
  41. ],
  42. experimental: [
  43. "optimizeUniversalDefaults",
  44. "generalizedModifiers"
  45. ]
  46. };
  47. function flagEnabled(config, flag) {
  48. if (featureFlags.future.includes(flag)) {
  49. var _config_future;
  50. var _config_future_flag, _ref;
  51. return config.future === "all" || ((_ref = (_config_future_flag = config === null || config === void 0 ? void 0 : (_config_future = config.future) === null || _config_future === void 0 ? void 0 : _config_future[flag]) !== null && _config_future_flag !== void 0 ? _config_future_flag : defaults[flag]) !== null && _ref !== void 0 ? _ref : false);
  52. }
  53. if (featureFlags.experimental.includes(flag)) {
  54. var _config_experimental;
  55. var _config_experimental_flag, _ref1;
  56. return config.experimental === "all" || ((_ref1 = (_config_experimental_flag = config === null || config === void 0 ? void 0 : (_config_experimental = config.experimental) === null || _config_experimental === void 0 ? void 0 : _config_experimental[flag]) !== null && _config_experimental_flag !== void 0 ? _config_experimental_flag : defaults[flag]) !== null && _ref1 !== void 0 ? _ref1 : false);
  57. }
  58. return false;
  59. }
  60. function experimentalFlagsEnabled(config) {
  61. if (config.experimental === "all") {
  62. return featureFlags.experimental;
  63. }
  64. var _config_experimental;
  65. return Object.keys((_config_experimental = config === null || config === void 0 ? void 0 : config.experimental) !== null && _config_experimental !== void 0 ? _config_experimental : {}).filter((flag)=>featureFlags.experimental.includes(flag) && config.experimental[flag]);
  66. }
  67. function issueFlagNotices(config) {
  68. if (process.env.JEST_WORKER_ID !== undefined) {
  69. return;
  70. }
  71. if (experimentalFlagsEnabled(config).length > 0) {
  72. let changes = experimentalFlagsEnabled(config).map((s)=>_picocolors.default.yellow(s)).join(", ");
  73. _log.default.warn("experimental-flags-enabled", [
  74. `You have enabled experimental features: ${changes}`,
  75. "Experimental features in Tailwind CSS are not covered by semver, may introduce breaking changes, and can change at any time."
  76. ]);
  77. }
  78. }
  79. const _default = featureFlags;