tailwindcss 0.0.0-oxide-insiders.a7fe2fe → 0.0.0-oxide-insiders.759a8c2

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.
Files changed (108) hide show
  1. package/lib/cli/build/deps.js +34 -18
  2. package/lib/cli/build/index.js +45 -12
  3. package/lib/cli/build/plugin.js +273 -90
  4. package/lib/cli/build/utils.js +56 -24
  5. package/lib/cli/build/watching.js +156 -38
  6. package/lib/cli/help/index.js +61 -16
  7. package/lib/cli/index.js +121 -62
  8. package/lib/cli/init/index.js +47 -23
  9. package/lib/cli-peer-dependencies.js +23 -13
  10. package/lib/cli.js +5 -1
  11. package/lib/corePluginList.js +7 -4
  12. package/lib/corePlugins.js +855 -386
  13. package/lib/featureFlags.js +43 -18
  14. package/lib/lib/cacheInvalidation.js +78 -30
  15. package/lib/lib/collapseAdjacentRules.js +46 -23
  16. package/lib/lib/collapseDuplicateDeclarations.js +70 -27
  17. package/lib/lib/content.js +134 -41
  18. package/lib/lib/defaultExtractor.js +201 -96
  19. package/lib/lib/detectNesting.js +38 -12
  20. package/lib/lib/evaluateTailwindFunctions.js +192 -103
  21. package/lib/lib/expandApplyAtRules.js +488 -181
  22. package/lib/lib/expandTailwindAtRules.js +240 -70
  23. package/lib/lib/findAtConfigPath.js +34 -15
  24. package/lib/lib/generateRules.js +775 -353
  25. package/lib/lib/getModuleDependencies.js +67 -29
  26. package/lib/lib/load-config.js +27 -17
  27. package/lib/lib/normalizeTailwindDirectives.js +73 -27
  28. package/lib/lib/offsets.js +227 -62
  29. package/lib/lib/partitionApplyAtRules.js +53 -29
  30. package/lib/lib/regex.js +50 -28
  31. package/lib/lib/remap-bitfield.js +86 -9
  32. package/lib/lib/resolveDefaultsAtRules.js +123 -53
  33. package/lib/lib/setupContextUtils.js +1117 -584
  34. package/lib/lib/setupTrackingContext.js +149 -58
  35. package/lib/lib/sharedState.js +71 -23
  36. package/lib/lib/substituteScreenAtRules.js +19 -9
  37. package/lib/oxide/cli/build/deps.js +46 -23
  38. package/lib/oxide/cli/build/index.js +44 -12
  39. package/lib/oxide/cli/build/plugin.js +271 -89
  40. package/lib/oxide/cli/build/utils.js +55 -24
  41. package/lib/oxide/cli/build/watching.js +153 -36
  42. package/lib/oxide/cli/help/index.js +60 -16
  43. package/lib/oxide/cli/index.js +128 -67
  44. package/lib/oxide/cli/init/index.js +40 -19
  45. package/lib/oxide/cli.js +3 -2
  46. package/lib/plugin.js +58 -31
  47. package/lib/postcss-plugins/nesting/index.js +13 -7
  48. package/lib/postcss-plugins/nesting/plugin.js +65 -20
  49. package/lib/processTailwindFeatures.js +41 -10
  50. package/lib/public/colors.js +25 -16
  51. package/lib/public/create-plugin.js +11 -6
  52. package/lib/public/default-config.js +12 -6
  53. package/lib/public/default-theme.js +12 -6
  54. package/lib/public/load-config.js +9 -5
  55. package/lib/public/resolve-config.js +10 -6
  56. package/lib/util/applyImportantSelector.js +28 -17
  57. package/lib/util/bigSign.js +9 -6
  58. package/lib/util/buildMediaQuery.js +19 -10
  59. package/lib/util/cloneDeep.js +19 -9
  60. package/lib/util/cloneNodes.js +29 -14
  61. package/lib/util/color.js +87 -47
  62. package/lib/util/colorNames.js +752 -0
  63. package/lib/util/configurePlugins.js +18 -9
  64. package/lib/util/createPlugin.js +17 -8
  65. package/lib/util/createUtilityPlugin.js +30 -16
  66. package/lib/util/dataTypes.js +189 -38
  67. package/lib/util/defaults.js +21 -9
  68. package/lib/util/escapeClassName.js +15 -9
  69. package/lib/util/escapeCommas.js +9 -6
  70. package/lib/util/flattenColorPalette.js +11 -7
  71. package/lib/util/formatVariantSelector.js +209 -60
  72. package/lib/util/getAllConfigs.js +44 -35
  73. package/lib/util/hashConfig.js +12 -8
  74. package/lib/util/isKeyframeRule.js +10 -7
  75. package/lib/util/isPlainObject.js +14 -9
  76. package/lib/util/isSyntacticallyValidPropertyValue.js +45 -14
  77. package/lib/util/log.js +20 -9
  78. package/lib/util/nameClass.js +31 -10
  79. package/lib/util/negateValue.js +28 -10
  80. package/lib/util/normalizeConfig.js +242 -63
  81. package/lib/util/normalizeScreens.js +145 -70
  82. package/lib/util/parseAnimationValue.js +64 -14
  83. package/lib/util/parseBoxShadowValue.js +63 -14
  84. package/lib/util/parseDependency.js +39 -13
  85. package/lib/util/parseGlob.js +25 -8
  86. package/lib/util/parseObjectStyles.js +29 -18
  87. package/lib/util/pluginUtils.js +196 -77
  88. package/lib/util/prefixSelector.js +31 -12
  89. package/lib/util/pseudoElements.js +116 -34
  90. package/lib/util/removeAlphaVariables.js +23 -8
  91. package/lib/util/resolveConfig.js +224 -105
  92. package/lib/util/resolveConfigPath.js +45 -15
  93. package/lib/util/responsive.js +10 -6
  94. package/lib/util/splitAtTopLevelOnly.js +46 -10
  95. package/lib/util/tap.js +11 -7
  96. package/lib/util/toColorValue.js +10 -7
  97. package/lib/util/toPath.js +28 -8
  98. package/lib/util/transformThemeValue.js +49 -14
  99. package/lib/util/validateConfig.js +25 -15
  100. package/lib/util/validateFormalSyntax.js +14 -6
  101. package/lib/util/withAlphaVariable.js +54 -30
  102. package/package.json +18 -22
  103. package/peers/index.js +57849 -43101
  104. package/src/lib/expandTailwindAtRules.js +1 -1
  105. package/src/lib/setupTrackingContext.js +1 -1
  106. package/src/util/color.js +1 -1
  107. package/src/util/colorNames.js +150 -0
  108. package/src/util/pseudoElements.js +4 -4
@@ -1,46 +1,62 @@
1
+ // @ts-check
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", {
3
- value: !0
4
- }), function(target, all) {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
5
7
  for(var name in all)Object.defineProperty(target, name, {
6
- enumerable: !0,
8
+ enumerable: true,
7
9
  get: all[name]
8
10
  });
9
- }(exports, {
10
- loadPostcss: ()=>loadPostcss,
11
- loadPostcssImport: ()=>loadPostcssImport,
12
- loadCssNano: ()=>loadCssNano,
13
- loadAutoprefixer: ()=>loadAutoprefixer
11
+ }
12
+ _export(exports, {
13
+ loadPostcss: function() {
14
+ return loadPostcss;
15
+ },
16
+ loadPostcssImport: function() {
17
+ return loadPostcssImport;
18
+ },
19
+ loadCssNano: function() {
20
+ return loadCssNano;
21
+ },
22
+ loadAutoprefixer: function() {
23
+ return loadAutoprefixer;
24
+ }
14
25
  });
15
- const _indexJs = require("../../../peers/index.js");
26
+ const _index = require("../../../peers/index.js");
16
27
  function loadPostcss() {
28
+ // Try to load a local `postcss` version first
17
29
  try {
18
30
  return require("postcss");
19
31
  } catch {}
20
- return (0, _indexJs.lazyPostcss)();
32
+ return (0, _index.lazyPostcss)();
21
33
  }
22
34
  function loadPostcssImport() {
35
+ // Try to load a local `postcss-import` version first
23
36
  try {
24
37
  return require("postcss-import");
25
38
  } catch {}
26
- return (0, _indexJs.lazyPostcssImport)();
39
+ return (0, _index.lazyPostcssImport)();
27
40
  }
28
41
  function loadCssNano() {
29
- try {
30
- return require("cssnano");
31
- } catch {}
32
- return (0, _indexJs.lazyCssnano)()({
42
+ let options = {
33
43
  preset: [
34
44
  "default",
35
45
  {
36
- cssDeclarationSorter: !1
46
+ cssDeclarationSorter: false
37
47
  }
38
48
  ]
39
- });
49
+ };
50
+ // Try to load a local `cssnano` version first
51
+ try {
52
+ return require("cssnano");
53
+ } catch {}
54
+ return (0, _index.lazyCssnano)()(options);
40
55
  }
41
56
  function loadAutoprefixer() {
57
+ // Try to load a local `autoprefixer` version first
42
58
  try {
43
59
  return require("autoprefixer");
44
60
  } catch {}
45
- return (0, _indexJs.lazyAutoprefixer)();
61
+ return (0, _index.lazyAutoprefixer)();
46
62
  }
@@ -1,21 +1,54 @@
1
+ // @ts-check
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", {
3
- value: !0
4
- }), Object.defineProperty(exports, "build", {
5
- enumerable: !0,
6
- get: ()=>build
4
+ value: true
7
5
  });
8
- const _fs = _interopRequireDefault(require("fs")), _path = _interopRequireDefault(require("path")), _resolveConfigPathJs = require("../../util/resolveConfigPath.js"), _pluginJs = require("./plugin.js");
9
- function _interopRequireDefault(obj) {
6
+ Object.defineProperty(exports, "build", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return build;
10
+ }
11
+ });
12
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
13
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
14
+ const _resolveConfigPath = require("../../util/resolveConfigPath.js");
15
+ const _plugin = require("./plugin.js");
16
+ function _interop_require_default(obj) {
10
17
  return obj && obj.__esModule ? obj : {
11
18
  default: obj
12
19
  };
13
20
  }
14
21
  async function build(args) {
15
- let input = args["--input"], shouldWatch = args["--watch"];
16
- !input && args._[1] && (console.error("[deprecation] Running tailwindcss without -i, please provide an input file."), input = args["--input"] = args._[1]), input && "-" !== input && !_fs.default.existsSync(input = _path.default.resolve(input)) && (console.error(`Specified input file ${args["--input"]} does not exist.`), process.exit(9)), args["--config"] && !_fs.default.existsSync(args["--config"] = _path.default.resolve(args["--config"])) && (console.error(`Specified config file ${args["--config"]} does not exist.`), process.exit(9));
17
- let configPath = args["--config"] ? args["--config"] : (0, _resolveConfigPathJs.resolveDefaultConfigPath)(), processor = await (0, _pluginJs.createProcessor)(args, configPath);
18
- shouldWatch ? ("always" !== args["--watch"] && process.stdin.on("end", ()=>process.exit(0)), process.stdin.resume(), await processor.watch()) : await processor.build().catch((e)=>{
19
- console.error(e), process.exit(1);
20
- });
22
+ let input = args["--input"];
23
+ let shouldWatch = args["--watch"];
24
+ // TODO: Deprecate this in future versions
25
+ if (!input && args["_"][1]) {
26
+ console.error("[deprecation] Running tailwindcss without -i, please provide an input file.");
27
+ input = args["--input"] = args["_"][1];
28
+ }
29
+ if (input && input !== "-" && !_fs.default.existsSync(input = _path.default.resolve(input))) {
30
+ console.error(`Specified input file ${args["--input"]} does not exist.`);
31
+ process.exit(9);
32
+ }
33
+ if (args["--config"] && !_fs.default.existsSync(args["--config"] = _path.default.resolve(args["--config"]))) {
34
+ console.error(`Specified config file ${args["--config"]} does not exist.`);
35
+ process.exit(9);
36
+ }
37
+ // TODO: Reference the @config path here if exists
38
+ let configPath = args["--config"] ? args["--config"] : (0, _resolveConfigPath.resolveDefaultConfigPath)();
39
+ let processor = await (0, _plugin.createProcessor)(args, configPath);
40
+ if (shouldWatch) {
41
+ // Abort the watcher if stdin is closed to avoid zombie processes
42
+ // You can disable this behavior with --watch=always
43
+ if (args["--watch"] !== "always") {
44
+ process.stdin.on("end", ()=>process.exit(0));
45
+ }
46
+ process.stdin.resume();
47
+ await processor.watch();
48
+ } else {
49
+ await processor.build().catch((e)=>{
50
+ console.error(e);
51
+ process.exit(1);
52
+ });
53
+ }
21
54
  }
@@ -1,41 +1,123 @@
1
+ // @ts-check
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", {
3
- value: !0
4
- }), Object.defineProperty(exports, "createProcessor", {
5
- enumerable: !0,
6
- get: ()=>createProcessor
4
+ value: true
7
5
  });
8
- const _path = _interopRequireDefault(require("path")), _fs = _interopRequireDefault(require("fs")), _postcssLoadConfig = _interopRequireDefault(require("postcss-load-config")), _lilconfig = require("lilconfig"), _plugins = _interopRequireDefault(require("postcss-load-config/src/plugins")), _options = _interopRequireDefault(require("postcss-load-config/src/options")), _processTailwindFeatures = _interopRequireDefault(require("../../processTailwindFeatures")), _deps = require("./deps"), _utils = require("./utils"), _sharedState = require("../../lib/sharedState"), _resolveConfigJs = _interopRequireDefault(require("../../../resolveConfig.js")), _contentJs = require("../../lib/content.js"), _watchingJs = require("./watching.js"), _fastGlob = _interopRequireDefault(require("fast-glob")), _findAtConfigPathJs = require("../../lib/findAtConfigPath.js"), _log = _interopRequireDefault(require("../../util/log")), _loadConfig = require("../../lib/load-config"), _getModuleDependencies = _interopRequireDefault(require("../../lib/getModuleDependencies"));
9
- function _interopRequireDefault(obj) {
6
+ Object.defineProperty(exports, "createProcessor", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return createProcessor;
10
+ }
11
+ });
12
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
14
+ const _postcssloadconfig = /*#__PURE__*/ _interop_require_default(require("postcss-load-config"));
15
+ const _lilconfig = require("lilconfig");
16
+ const _plugins = /*#__PURE__*/ _interop_require_default(require("postcss-load-config/src/plugins" // Little bit scary, looking at private/internal API
17
+ ));
18
+ const _options = /*#__PURE__*/ _interop_require_default(require("postcss-load-config/src/options" // Little bit scary, looking at private/internal API
19
+ ));
20
+ const _processTailwindFeatures = /*#__PURE__*/ _interop_require_default(require("../../processTailwindFeatures"));
21
+ const _deps = require("./deps");
22
+ const _utils = require("./utils");
23
+ const _sharedState = require("../../lib/sharedState");
24
+ const _resolveConfig = /*#__PURE__*/ _interop_require_default(require("../../../resolveConfig.js"));
25
+ const _content = require("../../lib/content.js");
26
+ const _watching = require("./watching.js");
27
+ const _fastglob = /*#__PURE__*/ _interop_require_default(require("fast-glob"));
28
+ const _findAtConfigPath = require("../../lib/findAtConfigPath.js");
29
+ const _log = /*#__PURE__*/ _interop_require_default(require("../../util/log"));
30
+ const _loadconfig = require("../../lib/load-config");
31
+ const _getModuleDependencies = /*#__PURE__*/ _interop_require_default(require("../../lib/getModuleDependencies"));
32
+ function _interop_require_default(obj) {
10
33
  return obj && obj.__esModule ? obj : {
11
34
  default: obj
12
35
  };
13
36
  }
14
- async function loadPostCssPlugins(customPostCssPath) {
37
+ /**
38
+ *
39
+ * @param {string} [customPostCssPath ]
40
+ * @returns
41
+ */ async function loadPostCssPlugins(customPostCssPath) {
15
42
  let config = customPostCssPath ? await (async ()=>{
16
- let file = _path.default.resolve(customPostCssPath), { config ={} } = await (0, _lilconfig.lilconfig)("postcss").load(file);
17
- return (config = "function" == typeof config ? config() : Object.assign({}, config)).plugins || (config.plugins = []), {
43
+ let file = _path.default.resolve(customPostCssPath);
44
+ // Implementation, see: https://unpkg.com/browse/postcss-load-config@3.1.0/src/index.js
45
+ // @ts-ignore
46
+ let { config ={} } = await (0, _lilconfig.lilconfig)("postcss").load(file);
47
+ if (typeof config === "function") {
48
+ config = config();
49
+ } else {
50
+ config = Object.assign({}, config);
51
+ }
52
+ if (!config.plugins) {
53
+ config.plugins = [];
54
+ }
55
+ return {
18
56
  file,
19
57
  plugins: (0, _plugins.default)(config, file),
20
58
  options: (0, _options.default)(config, file)
21
59
  };
22
- })() : await (0, _postcssLoadConfig.default)(), configPlugins = config.plugins, configPluginTailwindIdx = configPlugins.findIndex((plugin)=>"function" == typeof plugin && "tailwindcss" === plugin.name || "object" == typeof plugin && null !== plugin && "tailwindcss" === plugin.postcssPlugin);
60
+ })() : await (0, _postcssloadconfig.default)();
61
+ let configPlugins = config.plugins;
62
+ let configPluginTailwindIdx = configPlugins.findIndex((plugin)=>{
63
+ if (typeof plugin === "function" && plugin.name === "tailwindcss") {
64
+ return true;
65
+ }
66
+ if (typeof plugin === "object" && plugin !== null && plugin.postcssPlugin === "tailwindcss") {
67
+ return true;
68
+ }
69
+ return false;
70
+ });
71
+ let beforePlugins = configPluginTailwindIdx === -1 ? [] : configPlugins.slice(0, configPluginTailwindIdx);
72
+ let afterPlugins = configPluginTailwindIdx === -1 ? configPlugins : configPlugins.slice(configPluginTailwindIdx + 1);
23
73
  return [
24
- -1 === configPluginTailwindIdx ? [] : configPlugins.slice(0, configPluginTailwindIdx),
25
- -1 === configPluginTailwindIdx ? configPlugins : configPlugins.slice(configPluginTailwindIdx + 1),
74
+ beforePlugins,
75
+ afterPlugins,
26
76
  config.options
27
77
  ];
28
78
  }
79
+ function loadBuiltinPostcssPlugins() {
80
+ let postcss = (0, _deps.loadPostcss)();
81
+ let IMPORT_COMMENT = "__TAILWIND_RESTORE_IMPORT__: ";
82
+ return [
83
+ [
84
+ (root)=>{
85
+ root.walkAtRules("import", (rule)=>{
86
+ if (rule.params.slice(1).startsWith("tailwindcss/")) {
87
+ rule.after(postcss.comment({
88
+ text: IMPORT_COMMENT + rule.params
89
+ }));
90
+ rule.remove();
91
+ }
92
+ });
93
+ },
94
+ (0, _deps.loadPostcssImport)(),
95
+ (root)=>{
96
+ root.walkComments((rule)=>{
97
+ if (rule.text.startsWith(IMPORT_COMMENT)) {
98
+ rule.after(postcss.atRule({
99
+ name: "import",
100
+ params: rule.text.replace(IMPORT_COMMENT, "")
101
+ }));
102
+ rule.remove();
103
+ }
104
+ });
105
+ }
106
+ ],
107
+ [],
108
+ {}
109
+ ];
110
+ }
29
111
  let state = {
30
- context: null,
31
- watcher: null,
32
- changedContent: [],
33
- configBag: null,
112
+ /** @type {any} */ context: null,
113
+ /** @type {ReturnType<typeof createWatcher> | null} */ watcher: null,
114
+ /** @type {{content: string, extension: string}[]} */ changedContent: [],
115
+ /** @type {ReturnType<typeof load> | null} */ configBag: null,
34
116
  contextDependencies: new Set(),
35
- contentPaths: [],
117
+ /** @type {import('../../lib/content.js').ContentPath[]} */ contentPaths: [],
36
118
  refreshContentPaths () {
37
119
  var _this_context;
38
- this.contentPaths = (0, _contentJs.parseCandidateFiles)(this.context, null === (_this_context = this.context) || void 0 === _this_context ? void 0 : _this_context.tailwindConfig);
120
+ this.contentPaths = (0, _content.parseCandidateFiles)(this.context, (_this_context = this.context) === null || _this_context === void 0 ? void 0 : _this_context.tailwindConfig);
39
121
  },
40
122
  get config () {
41
123
  return this.context.tailwindConfig;
@@ -43,105 +125,167 @@ let state = {
43
125
  get contentPatterns () {
44
126
  return {
45
127
  all: this.contentPaths.map((contentPath)=>contentPath.pattern),
46
- dynamic: this.contentPaths.filter((contentPath)=>void 0 !== contentPath.glob).map((contentPath)=>contentPath.pattern)
128
+ dynamic: this.contentPaths.filter((contentPath)=>contentPath.glob !== undefined).map((contentPath)=>contentPath.pattern)
47
129
  };
48
130
  },
49
131
  loadConfig (configPath, content) {
50
- this.watcher && configPath && this.refreshConfigDependencies();
51
- let config = (0, _loadConfig.loadConfig)(configPath), dependencies = (0, _getModuleDependencies.default)(configPath);
52
- return this.configBag = {
132
+ if (this.watcher && configPath) {
133
+ this.refreshConfigDependencies();
134
+ }
135
+ let config = (0, _loadconfig.loadConfig)(configPath);
136
+ let dependencies = (0, _getModuleDependencies.default)(configPath);
137
+ this.configBag = {
53
138
  config,
54
139
  dependencies,
55
140
  dispose () {
56
- for (let file of dependencies)delete require.cache[require.resolve(file)];
141
+ for (let file of dependencies){
142
+ delete require.cache[require.resolve(file)];
143
+ }
57
144
  }
58
- }, this.configBag.config = (0, _resolveConfigJs.default)(this.configBag.config, {
145
+ };
146
+ // @ts-ignore
147
+ this.configBag.config = (0, _resolveConfig.default)(this.configBag.config, {
59
148
  content: {
60
149
  files: []
61
150
  }
62
- }), (null == content ? void 0 : content.length) > 0 && (this.configBag.config.content.files = content), this.configBag.config;
151
+ });
152
+ // Override content files if `--content` has been passed explicitly
153
+ if ((content === null || content === void 0 ? void 0 : content.length) > 0) {
154
+ this.configBag.config.content.files = content;
155
+ }
156
+ return this.configBag.config;
63
157
  },
64
158
  refreshConfigDependencies () {
65
159
  var _this_configBag;
66
- _sharedState.env.DEBUG && console.time("Module dependencies"), null === (_this_configBag = this.configBag) || void 0 === _this_configBag || _this_configBag.dispose(), _sharedState.env.DEBUG && console.timeEnd("Module dependencies");
160
+ _sharedState.env.DEBUG && console.time("Module dependencies");
161
+ (_this_configBag = this.configBag) === null || _this_configBag === void 0 ? void 0 : _this_configBag.dispose();
162
+ _sharedState.env.DEBUG && console.timeEnd("Module dependencies");
67
163
  },
68
164
  readContentPaths () {
69
165
  let content = [];
70
- for (let file of _fastGlob.default.sync(this.contentPatterns.all))content.push({
71
- file,
72
- extension: _path.default.extname(file).slice(1)
73
- });
74
- for (let { raw: htmlContent , extension ="html" } of this.config.content.files.filter((file)=>null !== file && "object" == typeof file))content.push({
75
- content: htmlContent,
76
- extension
166
+ // Resolve globs from the content config
167
+ // TODO: When we make the postcss plugin async-capable this can become async
168
+ let files = _fastglob.default.sync(this.contentPatterns.all);
169
+ for (let file of files){
170
+ if (true) {
171
+ content.push({
172
+ file,
173
+ extension: _path.default.extname(file).slice(1)
174
+ });
175
+ } else {
176
+ content.push({
177
+ content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
178
+ extension: _path.default.extname(file).slice(1)
179
+ });
180
+ }
181
+ }
182
+ // Resolve raw content in the tailwind config
183
+ let rawContent = this.config.content.files.filter((file)=>{
184
+ return file !== null && typeof file === "object";
77
185
  });
186
+ for (let { raw: htmlContent , extension ="html" } of rawContent){
187
+ content.push({
188
+ content: htmlContent,
189
+ extension
190
+ });
191
+ }
78
192
  return content;
79
193
  },
80
194
  getContext ({ createContext , cliConfigPath , root , result , content }) {
81
- var _findAtConfigPath;
82
- if (this.context) return this.context.changedContent = this.changedContent.splice(0), this.context;
195
+ if (this.context) {
196
+ this.context.changedContent = this.changedContent.splice(0);
197
+ return this.context;
198
+ }
83
199
  _sharedState.env.DEBUG && console.time("Searching for config");
84
- let configPath = null !== (_findAtConfigPath = (0, _findAtConfigPathJs.findAtConfigPath)(root, result)) && void 0 !== _findAtConfigPath ? _findAtConfigPath : cliConfigPath;
85
- _sharedState.env.DEBUG && console.timeEnd("Searching for config"), _sharedState.env.DEBUG && console.time("Loading config");
200
+ var _findAtConfigPath1;
201
+ let configPath = (_findAtConfigPath1 = (0, _findAtConfigPath.findAtConfigPath)(root, result)) !== null && _findAtConfigPath1 !== void 0 ? _findAtConfigPath1 : cliConfigPath;
202
+ _sharedState.env.DEBUG && console.timeEnd("Searching for config");
203
+ _sharedState.env.DEBUG && console.time("Loading config");
86
204
  let config = this.loadConfig(configPath, content);
87
- for (let file of (_sharedState.env.DEBUG && console.timeEnd("Loading config"), _sharedState.env.DEBUG && console.time("Creating context"), this.context = createContext(config, []), Object.assign(this.context, {
205
+ _sharedState.env.DEBUG && console.timeEnd("Loading config");
206
+ _sharedState.env.DEBUG && console.time("Creating context");
207
+ this.context = createContext(config, []);
208
+ Object.assign(this.context, {
88
209
  userConfigPath: configPath
89
- }), _sharedState.env.DEBUG && console.timeEnd("Creating context"), _sharedState.env.DEBUG && console.time("Resolving content paths"), this.refreshContentPaths(), _sharedState.env.DEBUG && console.timeEnd("Resolving content paths"), this.watcher && (_sharedState.env.DEBUG && console.time("Watch new files"), this.watcher.refreshWatchedFiles(), _sharedState.env.DEBUG && console.timeEnd("Watch new files")), this.readContentPaths()))this.context.changedContent.push(file);
210
+ });
211
+ _sharedState.env.DEBUG && console.timeEnd("Creating context");
212
+ _sharedState.env.DEBUG && console.time("Resolving content paths");
213
+ this.refreshContentPaths();
214
+ _sharedState.env.DEBUG && console.timeEnd("Resolving content paths");
215
+ if (this.watcher) {
216
+ _sharedState.env.DEBUG && console.time("Watch new files");
217
+ this.watcher.refreshWatchedFiles();
218
+ _sharedState.env.DEBUG && console.timeEnd("Watch new files");
219
+ }
220
+ for (let file of this.readContentPaths()){
221
+ this.context.changedContent.push(file);
222
+ }
90
223
  return this.context;
91
224
  }
92
225
  };
93
226
  async function createProcessor(args, cliConfigPath) {
94
- var _args_content, _args_content_split;
95
- let postcss, IMPORT_COMMENT;
96
- let postcss1 = (0, _deps.loadPostcss)(), input = args["--input"], output = args["--output"], includePostCss = args["--postcss"], customPostCssPath = "string" == typeof args["--postcss"] ? args["--postcss"] : void 0, [beforePlugins, afterPlugins, postcssOptions] = includePostCss ? await loadPostCssPlugins(customPostCssPath) : (postcss = (0, _deps.loadPostcss)(), IMPORT_COMMENT = "__TAILWIND_RESTORE_IMPORT__: ", [
97
- [
98
- (root)=>{
99
- root.walkAtRules("import", (rule)=>{
100
- rule.params.slice(1).startsWith("tailwindcss/") && (rule.after(postcss.comment({
101
- text: IMPORT_COMMENT + rule.params
102
- })), rule.remove());
103
- });
104
- },
105
- (0, _deps.loadPostcssImport)(),
106
- (root)=>{
107
- root.walkComments((rule)=>{
108
- rule.text.startsWith(IMPORT_COMMENT) && (rule.after(postcss.atRule({
109
- name: "import",
110
- params: rule.text.replace(IMPORT_COMMENT, "")
111
- })), rule.remove());
112
- });
113
- }
114
- ],
115
- [],
116
- {}
117
- ]);
118
- args["--purge"] && (_log.default.warn("purge-flag-deprecated", [
119
- "The `--purge` flag has been deprecated.",
120
- "Please use `--content` instead."
121
- ]), args["--content"] || (args["--content"] = args["--purge"]));
122
- let content = null !== (_args_content_split = null === (_args_content = args["--content"]) || void 0 === _args_content ? void 0 : _args_content.split(/(?<!{[^}]+),/)) && void 0 !== _args_content_split ? _args_content_split : [], tailwindPlugin = ()=>({
227
+ var _args_content;
228
+ let postcss = (0, _deps.loadPostcss)();
229
+ let input = args["--input"];
230
+ let output = args["--output"];
231
+ let includePostCss = args["--postcss"];
232
+ let customPostCssPath = typeof args["--postcss"] === "string" ? args["--postcss"] : undefined;
233
+ let [beforePlugins, afterPlugins, postcssOptions] = includePostCss ? await loadPostCssPlugins(customPostCssPath) : loadBuiltinPostcssPlugins();
234
+ if (args["--purge"]) {
235
+ _log.default.warn("purge-flag-deprecated", [
236
+ "The `--purge` flag has been deprecated.",
237
+ "Please use `--content` instead."
238
+ ]);
239
+ if (!args["--content"]) {
240
+ args["--content"] = args["--purge"];
241
+ }
242
+ }
243
+ var _args_content_split;
244
+ let content = (_args_content_split = (_args_content = args["--content"]) === null || _args_content === void 0 ? void 0 : _args_content.split(/(?<!{[^}]+),/)) !== null && _args_content_split !== void 0 ? _args_content_split : [];
245
+ let tailwindPlugin = ()=>{
246
+ return {
123
247
  postcssPlugin: "tailwindcss",
124
248
  Once (root, { result }) {
125
- _sharedState.env.DEBUG && console.time("Compiling CSS"), (0, _processTailwindFeatures.default)(({ createContext })=>(console.error(), console.error("Rebuilding..."), ()=>state.getContext({
249
+ _sharedState.env.DEBUG && console.time("Compiling CSS");
250
+ (0, _processTailwindFeatures.default)(({ createContext })=>{
251
+ console.error();
252
+ console.error("Rebuilding...");
253
+ return ()=>{
254
+ return state.getContext({
126
255
  createContext,
127
256
  cliConfigPath,
128
257
  root,
129
258
  result,
130
259
  content
131
- })))(root, result), _sharedState.env.DEBUG && console.timeEnd("Compiling CSS");
260
+ });
261
+ };
262
+ })(root, result);
263
+ _sharedState.env.DEBUG && console.timeEnd("Compiling CSS");
132
264
  }
133
- });
134
- tailwindPlugin.postcss = !0;
135
- let processor = postcss1([
265
+ };
266
+ };
267
+ tailwindPlugin.postcss = true;
268
+ let plugins = [
136
269
  ...beforePlugins,
137
270
  tailwindPlugin,
138
271
  !args["--minify"] && _utils.formatNodes,
139
272
  ...afterPlugins,
140
273
  !args["--no-autoprefixer"] && (0, _deps.loadAutoprefixer)(),
141
274
  args["--minify"] && (0, _deps.loadCssNano)()
142
- ].filter(Boolean));
275
+ ].filter(Boolean);
276
+ /** @type {import('postcss').Processor} */ // @ts-ignore
277
+ let processor = postcss(plugins);
143
278
  async function readInput() {
144
- return "-" === input ? (0, _utils.drainStdin)() : input ? _fs.default.promises.readFile(_path.default.resolve(input), "utf8") : "@tailwind base; @tailwind components; @tailwind utilities";
279
+ // Piping in data, let's drain the stdin
280
+ if (input === "-") {
281
+ return (0, _utils.drainStdin)();
282
+ }
283
+ // Input file has been provided
284
+ if (input) {
285
+ return _fs.default.promises.readFile(_path.default.resolve(input), "utf8");
286
+ }
287
+ // No input file provided, fallback to default atrules
288
+ return "@tailwind base; @tailwind components; @tailwind utilities";
145
289
  }
146
290
  async function build() {
147
291
  let start = process.hrtime.bigint();
@@ -150,9 +294,21 @@ async function createProcessor(args, cliConfigPath) {
150
294
  from: input,
151
295
  to: output
152
296
  })).then((result)=>{
153
- if (!state.watcher) return result;
154
- for (let message of (_sharedState.env.DEBUG && console.time("Recording PostCSS dependencies"), result.messages))"dependency" === message.type && state.contextDependencies.add(message.file);
155
- return _sharedState.env.DEBUG && console.timeEnd("Recording PostCSS dependencies"), _sharedState.env.DEBUG && console.time("Watch new files"), state.watcher.refreshWatchedFiles(), _sharedState.env.DEBUG && console.timeEnd("Watch new files"), result;
297
+ if (!state.watcher) {
298
+ return result;
299
+ }
300
+ _sharedState.env.DEBUG && console.time("Recording PostCSS dependencies");
301
+ for (let message of result.messages){
302
+ if (message.type === "dependency") {
303
+ state.contextDependencies.add(message.file);
304
+ }
305
+ }
306
+ _sharedState.env.DEBUG && console.timeEnd("Recording PostCSS dependencies");
307
+ // TODO: This needs to be in a different spot
308
+ _sharedState.env.DEBUG && console.time("Watch new files");
309
+ state.watcher.refreshWatchedFiles();
310
+ _sharedState.env.DEBUG && console.timeEnd("Watch new files");
311
+ return result;
156
312
  }).then((result)=>{
157
313
  if (!output) {
158
314
  process.stdout.write(result.css);
@@ -164,32 +320,59 @@ async function createProcessor(args, cliConfigPath) {
164
320
  ]);
165
321
  }).then(()=>{
166
322
  let end = process.hrtime.bigint();
167
- console.error(), console.error("Done in", (end - start) / BigInt(1e6) + "ms.");
323
+ console.error();
324
+ console.error("Done in", (end - start) / BigInt(1e6) + "ms.");
168
325
  }).then(()=>{}, (err)=>{
169
- if (!state.watcher) return Promise.reject(err);
170
- console.error(err);
326
+ // TODO: If an initial build fails we can't easily pick up any PostCSS dependencies
327
+ // that were collected before the error occurred
328
+ // The result is not stored on the error so we have to store it externally
329
+ // and pull the messages off of it here somehow
330
+ // This results in a less than ideal DX because the watcher will not pick up
331
+ // changes to imported CSS if one of them caused an error during the initial build
332
+ // If you fix it and then save the main CSS file so there's no error
333
+ // The watcher will start watching the imported CSS files and will be
334
+ // resilient to future errors.
335
+ if (state.watcher) {
336
+ console.error(err);
337
+ } else {
338
+ return Promise.reject(err);
339
+ }
171
340
  });
172
341
  }
173
- async function parseChanges(changes) {
342
+ /**
343
+ * @param {{file: string, content(): Promise<string>, extension: string}[]} changes
344
+ */ async function parseChanges(changes) {
174
345
  return Promise.all(changes.map(async (change)=>({
175
346
  content: await change.content(),
176
347
  extension: change.extension
177
348
  })));
178
349
  }
179
- return void 0 !== input && "-" !== input && state.contextDependencies.add(_path.default.resolve(input)), {
350
+ if (input !== undefined && input !== "-") {
351
+ state.contextDependencies.add(_path.default.resolve(input));
352
+ }
353
+ return {
180
354
  build,
181
355
  watch: async ()=>{
182
- state.watcher = (0, _watchingJs.createWatcher)(args, {
356
+ state.watcher = (0, _watching.createWatcher)(args, {
183
357
  state,
184
- async rebuild (changes) {
185
- if (changes.some((change)=>{
358
+ /**
359
+ * @param {{file: string, content(): Promise<string>, extension: string}[]} changes
360
+ */ async rebuild (changes) {
361
+ let needsNewContext = changes.some((change)=>{
186
362
  var _state_configBag;
187
- return (null === (_state_configBag = state.configBag) || void 0 === _state_configBag ? void 0 : _state_configBag.dependencies.has(change.file)) || state.contextDependencies.has(change.file);
188
- })) state.context = null;
189
- else for (let change of (await parseChanges(changes)))state.changedContent.push(change);
363
+ return ((_state_configBag = state.configBag) === null || _state_configBag === void 0 ? void 0 : _state_configBag.dependencies.has(change.file)) || state.contextDependencies.has(change.file);
364
+ });
365
+ if (needsNewContext) {
366
+ state.context = null;
367
+ } else {
368
+ for (let change of (await parseChanges(changes))){
369
+ state.changedContent.push(change);
370
+ }
371
+ }
190
372
  return build();
191
373
  }
192
- }), await build();
374
+ });
375
+ await build();
193
376
  }
194
377
  };
195
378
  }