tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7d8eb21

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 (161) hide show
  1. package/CHANGELOG.md +246 -6
  2. package/README.md +13 -9
  3. package/defaultTheme.d.ts +2 -1
  4. package/lib/cli/build/deps.js +54 -0
  5. package/lib/cli/build/index.js +48 -0
  6. package/lib/cli/build/plugin.js +362 -0
  7. package/lib/cli/build/utils.js +78 -0
  8. package/lib/cli/build/watching.js +178 -0
  9. package/lib/cli/help/index.js +71 -0
  10. package/lib/cli/index.js +18 -0
  11. package/lib/cli/init/index.js +46 -0
  12. package/lib/cli/shared.js +12 -0
  13. package/lib/cli-peer-dependencies.js +18 -5
  14. package/lib/cli.js +62 -592
  15. package/lib/constants.js +19 -12
  16. package/lib/corePluginList.js +5 -3
  17. package/lib/corePlugins.js +619 -347
  18. package/lib/css/preflight.css +7 -0
  19. package/lib/featureFlags.js +34 -22
  20. package/lib/index.js +16 -9
  21. package/lib/lib/cacheInvalidation.js +42 -21
  22. package/lib/lib/collapseAdjacentRules.js +16 -14
  23. package/lib/lib/collapseDuplicateDeclarations.js +13 -10
  24. package/lib/lib/content.js +177 -0
  25. package/lib/lib/defaultExtractor.js +230 -33
  26. package/lib/lib/detectNesting.js +13 -4
  27. package/lib/lib/evaluateTailwindFunctions.js +105 -42
  28. package/lib/lib/expandApplyAtRules.js +151 -92
  29. package/lib/lib/expandTailwindAtRules.js +134 -149
  30. package/lib/lib/findAtConfigPath.js +44 -0
  31. package/lib/lib/generateRules.js +404 -185
  32. package/lib/lib/getModuleDependencies.js +21 -18
  33. package/lib/lib/normalizeTailwindDirectives.js +11 -8
  34. package/lib/lib/offsets.js +285 -0
  35. package/lib/lib/partitionApplyAtRules.js +14 -11
  36. package/lib/lib/regex.js +60 -0
  37. package/lib/lib/remap-bitfield.js +87 -0
  38. package/lib/lib/resolveDefaultsAtRules.js +97 -79
  39. package/lib/lib/setupContextUtils.js +567 -242
  40. package/lib/lib/setupTrackingContext.js +77 -106
  41. package/lib/lib/sharedState.js +18 -10
  42. package/lib/lib/substituteScreenAtRules.js +9 -7
  43. package/lib/postcss-plugins/nesting/index.js +7 -5
  44. package/lib/postcss-plugins/nesting/plugin.js +10 -8
  45. package/lib/processTailwindFeatures.js +34 -31
  46. package/lib/public/colors.js +7 -5
  47. package/lib/public/create-plugin.js +6 -4
  48. package/lib/public/default-config.js +7 -5
  49. package/lib/public/default-theme.js +7 -5
  50. package/lib/public/resolve-config.js +13 -10
  51. package/lib/util/bigSign.js +4 -1
  52. package/lib/util/buildMediaQuery.js +10 -5
  53. package/lib/util/cloneDeep.js +6 -5
  54. package/lib/util/cloneNodes.js +9 -2
  55. package/lib/util/color.js +20 -17
  56. package/lib/util/configurePlugins.js +5 -2
  57. package/lib/util/createPlugin.js +6 -5
  58. package/lib/util/createUtilityPlugin.js +15 -13
  59. package/lib/util/dataTypes.js +75 -51
  60. package/lib/util/defaults.js +8 -5
  61. package/lib/util/escapeClassName.js +13 -10
  62. package/lib/util/escapeCommas.js +4 -1
  63. package/lib/util/flattenColorPalette.js +7 -8
  64. package/lib/util/formatVariantSelector.js +270 -103
  65. package/lib/util/getAllConfigs.js +34 -15
  66. package/lib/util/hashConfig.js +10 -7
  67. package/lib/util/isKeyframeRule.js +4 -1
  68. package/lib/util/isPlainObject.js +4 -1
  69. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +34 -26
  70. package/lib/util/log.js +14 -8
  71. package/lib/util/nameClass.js +19 -8
  72. package/lib/util/negateValue.js +20 -5
  73. package/lib/util/normalizeConfig.js +94 -53
  74. package/lib/util/normalizeScreens.js +115 -4
  75. package/lib/util/parseAnimationValue.js +43 -41
  76. package/lib/util/parseBoxShadowValue.js +12 -45
  77. package/lib/util/parseDependency.js +37 -55
  78. package/lib/util/parseGlob.js +34 -0
  79. package/lib/util/parseObjectStyles.js +15 -12
  80. package/lib/util/pluginUtils.js +146 -42
  81. package/lib/util/prefixSelector.js +26 -9
  82. package/lib/util/removeAlphaVariables.js +29 -0
  83. package/lib/util/resolveConfig.js +104 -105
  84. package/lib/util/resolveConfigPath.js +20 -17
  85. package/lib/util/responsive.js +12 -9
  86. package/lib/util/splitAtTopLevelOnly.js +43 -0
  87. package/lib/util/tap.js +4 -1
  88. package/lib/util/toColorValue.js +4 -1
  89. package/lib/util/toPath.js +18 -2
  90. package/lib/util/transformThemeValue.js +23 -11
  91. package/lib/util/validateConfig.js +24 -0
  92. package/lib/util/validateFormalSyntax.js +24 -0
  93. package/lib/util/withAlphaVariable.js +32 -24
  94. package/package.json +32 -29
  95. package/peers/index.js +6693 -3036
  96. package/plugin.d.ts +10 -5
  97. package/resolveConfig.d.ts +12 -0
  98. package/scripts/generate-types.js +53 -0
  99. package/scripts/release-channel.js +18 -0
  100. package/scripts/release-notes.js +21 -0
  101. package/scripts/type-utils.js +27 -0
  102. package/src/cli/build/deps.js +56 -0
  103. package/src/cli/build/index.js +49 -0
  104. package/src/cli/build/plugin.js +434 -0
  105. package/src/cli/build/utils.js +76 -0
  106. package/src/cli/build/watching.js +227 -0
  107. package/src/cli/help/index.js +70 -0
  108. package/src/cli/index.js +3 -0
  109. package/src/cli/init/index.js +50 -0
  110. package/src/cli/shared.js +5 -0
  111. package/src/cli-peer-dependencies.js +7 -1
  112. package/src/cli.js +46 -659
  113. package/src/corePlugins.js +346 -79
  114. package/src/css/preflight.css +7 -0
  115. package/src/featureFlags.js +12 -2
  116. package/src/index.js +5 -0
  117. package/src/lib/content.js +213 -0
  118. package/src/lib/defaultExtractor.js +202 -35
  119. package/src/lib/detectNesting.js +9 -1
  120. package/src/lib/evaluateTailwindFunctions.js +78 -7
  121. package/src/lib/expandApplyAtRules.js +129 -34
  122. package/src/lib/expandTailwindAtRules.js +12 -50
  123. package/src/lib/findAtConfigPath.js +48 -0
  124. package/src/lib/generateRules.js +379 -126
  125. package/src/lib/offsets.js +351 -0
  126. package/src/lib/regex.js +74 -0
  127. package/src/lib/remap-bitfield.js +82 -0
  128. package/src/lib/resolveDefaultsAtRules.js +53 -36
  129. package/src/lib/setupContextUtils.js +510 -120
  130. package/src/lib/setupTrackingContext.js +8 -45
  131. package/src/lib/sharedState.js +2 -0
  132. package/src/util/buildMediaQuery.js +5 -3
  133. package/src/util/cloneNodes.js +5 -1
  134. package/src/util/dataTypes.js +51 -26
  135. package/src/util/formatVariantSelector.js +317 -101
  136. package/src/util/getAllConfigs.js +19 -0
  137. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  138. package/src/util/log.js +1 -1
  139. package/src/util/nameClass.js +4 -0
  140. package/src/util/negateValue.js +10 -2
  141. package/src/util/normalizeConfig.js +40 -10
  142. package/src/util/normalizeScreens.js +99 -4
  143. package/src/util/parseBoxShadowValue.js +3 -50
  144. package/src/util/parseDependency.js +37 -42
  145. package/src/util/parseGlob.js +24 -0
  146. package/src/util/pluginUtils.js +132 -10
  147. package/src/util/prefixSelector.js +28 -10
  148. package/src/util/removeAlphaVariables.js +24 -0
  149. package/src/util/resolveConfig.js +70 -62
  150. package/src/util/splitAtTopLevelOnly.js +45 -0
  151. package/src/util/toPath.js +1 -1
  152. package/src/util/transformThemeValue.js +13 -3
  153. package/src/util/validateConfig.js +13 -0
  154. package/src/util/validateFormalSyntax.js +34 -0
  155. package/src/util/withAlphaVariable.js +1 -1
  156. package/stubs/defaultConfig.stub.js +165 -164
  157. package/stubs/simpleConfig.stub.js +1 -0
  158. package/types/config.d.ts +77 -37
  159. package/types/generated/default-theme.d.ts +342 -0
  160. package/types/index.d.ts +7 -1
  161. package/types.d.ts +0 -1
package/lib/cli.js CHANGED
@@ -1,122 +1,36 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var _indexJs = require("../peers/index.js");
4
- var _chokidar = _interopRequireDefault(require("chokidar"));
5
- var _path = _interopRequireDefault(require("path"));
6
- var _arg = _interopRequireDefault(require("arg"));
7
- var _fs = _interopRequireDefault(require("fs"));
8
- var _postcssLoadConfig = _interopRequireDefault(require("postcss-load-config"));
9
- var _lilconfig = require("lilconfig");
10
- var _plugins // Little bit scary, looking at private/internal API
11
- = _interopRequireDefault(require("postcss-load-config/src/plugins"));
12
- var _options // Little bit scary, looking at private/internal API
13
- = _interopRequireDefault(require("postcss-load-config/src/options"));
14
- var _processTailwindFeatures = _interopRequireDefault(require("./processTailwindFeatures"));
15
- var _resolveConfig = _interopRequireDefault(require("../resolveConfig"));
16
- var _fastGlob = _interopRequireDefault(require("fast-glob"));
17
- var _getModuleDependencies = _interopRequireDefault(require("./lib/getModuleDependencies"));
18
- var _log = _interopRequireDefault(require("./util/log"));
19
- var _packageJson = _interopRequireDefault(require("../package.json"));
20
- var _normalizePath = _interopRequireDefault(require("normalize-path"));
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
7
+ const _arg = /*#__PURE__*/ _interopRequireDefault(require("arg"));
8
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
9
+ const _build = require("./cli/build");
10
+ const _help = require("./cli/help");
11
+ const _init = require("./cli/init");
21
12
  function _interopRequireDefault(obj) {
22
13
  return obj && obj.__esModule ? obj : {
23
14
  default: obj
24
15
  };
25
16
  }
26
- let env = {
27
- DEBUG: process.env.DEBUG !== undefined && process.env.DEBUG !== "0"
28
- };
29
- // ---
30
- function indentRecursive(node, indent = 0) {
31
- node.each && node.each((child, i)=>{
32
- if (!child.raws.before || !child.raws.before.trim() || child.raws.before.includes("\n")) {
33
- child.raws.before = `\n${node.type !== "rule" && i > 0 ? "\n" : ""}${" ".repeat(indent)}`;
34
- }
35
- child.raws.after = `\n${" ".repeat(indent)}`;
36
- indentRecursive(child, indent + 1);
37
- });
38
- }
39
- function formatNodes(root) {
40
- indentRecursive(root);
41
- if (root.first) {
42
- root.first.raws.before = "";
43
- }
44
- }
45
- async function outputFile(file, contents) {
46
- if (_fs.default.existsSync(file) && await _fs.default.promises.readFile(file, "utf8") === contents) {
47
- return; // Skip writing the file
48
- }
49
- // Write the file
50
- await _fs.default.promises.writeFile(file, contents, "utf8");
51
- }
52
- function drainStdin() {
53
- return new Promise((resolve, reject)=>{
54
- let result = "";
55
- process.stdin.on("data", (chunk)=>{
56
- result += chunk;
57
- });
58
- process.stdin.on("end", ()=>resolve(result)
59
- );
60
- process.stdin.on("error", (err)=>reject(err)
61
- );
62
- });
63
- }
64
- function help({ message , usage , commands: commands1 , options }) {
65
- let indent = 2;
66
- // Render header
67
- console.log();
68
- console.log(`${_packageJson.default.name} v${_packageJson.default.version}`);
69
- // Render message
70
- if (message) {
71
- console.log();
72
- for (let msg of message.split("\n")){
73
- console.log(msg);
74
- }
75
- }
76
- // Render usage
77
- if (usage && usage.length > 0) {
78
- console.log();
79
- console.log("Usage:");
80
- for (let example of usage){
81
- console.log(" ".repeat(indent), example);
82
- }
83
- }
84
- // Render commands
85
- if (commands1 && commands1.length > 0) {
86
- console.log();
87
- console.log("Commands:");
88
- for (let command1 of commands1){
89
- console.log(" ".repeat(indent), command1);
90
- }
91
- }
92
- // Render options
93
- if (options) {
94
- let groupedOptions = {};
95
- for (let [key, value] of Object.entries(options)){
96
- if (typeof value === "object") {
97
- groupedOptions[key] = {
98
- ...value,
99
- flags: [
100
- key
101
- ]
102
- };
103
- } else {
104
- groupedOptions[value].flags.push(key);
105
- }
106
- }
107
- console.log();
108
- console.log("Options:");
109
- for (let { flags: flags1 , description , deprecated } of Object.values(groupedOptions)){
110
- if (deprecated) continue;
111
- if (flags1.length === 1) {
112
- console.log(" ".repeat(indent + 4 /* 4 = "-i, ".length */ ), flags1.slice().reverse().join(", ").padEnd(20, " "), description);
113
- } else {
114
- console.log(" ".repeat(indent), flags1.slice().reverse().join(", ").padEnd(24, " "), description);
115
- }
116
- }
17
+ function isESM() {
18
+ const pkgPath = _path.default.resolve("./package.json");
19
+ try {
20
+ let pkg = JSON.parse(_fs.default.readFileSync(pkgPath, "utf8"));
21
+ return pkg.type && pkg.type === "module";
22
+ } catch (err) {
23
+ return false;
117
24
  }
118
- console.log();
119
25
  }
26
+ let configs = isESM() ? {
27
+ tailwind: "tailwind.config.cjs",
28
+ postcss: "postcss.config.cjs"
29
+ } : {
30
+ tailwind: "tailwind.config.js",
31
+ postcss: "postcss.config.js"
32
+ };
33
+ // ---
120
34
  function oneOf(...options) {
121
35
  return Object.assign((value = true)=>{
122
36
  for (let option of options){
@@ -132,26 +46,22 @@ function oneOf(...options) {
132
46
  }
133
47
  let commands = {
134
48
  init: {
135
- run: init,
49
+ run: _init.init,
136
50
  args: {
137
51
  "--full": {
138
52
  type: Boolean,
139
- description: "Initialize a full `tailwind.config.js` file"
53
+ description: `Initialize a full \`${configs.tailwind}\` file`
140
54
  },
141
55
  "--postcss": {
142
56
  type: Boolean,
143
- description: "Initialize a `postcss.config.js` file"
144
- },
145
- "--types": {
146
- type: Boolean,
147
- description: "Add TypeScript types for the `tailwind.config.js` file"
57
+ description: `Initialize a \`${configs.postcss}\` file`
148
58
  },
149
59
  "-f": "--full",
150
60
  "-p": "--postcss"
151
61
  }
152
62
  },
153
63
  build: {
154
- run: build,
64
+ run: _build.build,
155
65
  args: {
156
66
  "--input": {
157
67
  type: String,
@@ -162,7 +72,7 @@ let commands = {
162
72
  description: "Output file"
163
73
  },
164
74
  "--watch": {
165
- type: Boolean,
75
+ type: oneOf(String, Boolean),
166
76
  description: "Watch for changes and rebuild as needed"
167
77
  },
168
78
  "--poll": {
@@ -209,16 +119,13 @@ let sharedFlags = {
209
119
  },
210
120
  "-h": "--help"
211
121
  };
212
- if (process.stdout.isTTY /* Detect redirecting output to a file */ && (process.argv[2] === undefined || process.argv.slice(2).every((flag)=>sharedFlags[flag] !== undefined
213
- ))) {
214
- help({
122
+ if (process.stdout.isTTY /* Detect redirecting output to a file */ && (process.argv[2] === undefined || process.argv.slice(2).every((flag)=>sharedFlags[flag] !== undefined))) {
123
+ (0, _help.help)({
215
124
  usage: [
216
125
  "tailwindcss [--input input.css] [--output output.css] [--watch] [options...]",
217
- "tailwindcss init [--full] [--postcss] [--types] [options...]",
126
+ "tailwindcss init [--full] [--postcss] [options...]"
218
127
  ],
219
- commands: Object.keys(commands).filter((command2)=>command2 !== "build"
220
- ).map((command3)=>`${command3} [options]`
221
- ),
128
+ commands: Object.keys(commands).filter((command)=>command !== "build").map((command)=>`${command} [options]`),
222
129
  options: {
223
130
  ...commands.build.args,
224
131
  ...sharedFlags
@@ -226,22 +133,19 @@ if (process.stdout.isTTY /* Detect redirecting output to a file */ && (process.
226
133
  });
227
134
  process.exit(0);
228
135
  }
229
- let command = ((arg = "")=>arg.startsWith("-") ? undefined : arg
230
- )(process.argv[2]) || "build";
136
+ let command = ((arg = "")=>arg.startsWith("-") ? undefined : arg)(process.argv[2]) || "build";
231
137
  if (commands[command] === undefined) {
232
138
  if (_fs.default.existsSync(_path.default.resolve(command))) {
233
139
  // TODO: Deprecate this in future versions
234
140
  // Check if non-existing command, might be a file.
235
141
  command = "build";
236
142
  } else {
237
- help({
143
+ (0, _help.help)({
238
144
  message: `Invalid command: ${command}`,
239
145
  usage: [
240
146
  "tailwindcss <command> [options]"
241
147
  ],
242
- commands: Object.keys(commands).filter((command4)=>command4 !== "build"
243
- ).map((command5)=>`${command5} [options]`
244
- ),
148
+ commands: Object.keys(commands).filter((command)=>command !== "build").map((command)=>`${command} [options]`),
245
149
  options: sharedFlags
246
150
  });
247
151
  process.exit(1);
@@ -251,41 +155,50 @@ if (commands[command] === undefined) {
251
155
  let { args: flags , run } = commands[command];
252
156
  let args = (()=>{
253
157
  try {
254
- let result = (0, _arg).default(Object.fromEntries(Object.entries({
158
+ let result = (0, _arg.default)(Object.fromEntries(Object.entries({
255
159
  ...flags,
256
160
  ...sharedFlags
257
161
  }).filter(([_key, value])=>{
258
- var ref;
259
- return !(value === null || value === void 0 ? void 0 : (ref = value.type) === null || ref === void 0 ? void 0 : ref.manualParsing);
162
+ var _value_type;
163
+ return !(value === null || value === void 0 ? void 0 : (_value_type = value.type) === null || _value_type === void 0 ? void 0 : _value_type.manualParsing);
260
164
  }).map(([key, value])=>[
261
165
  key,
262
166
  typeof value === "object" ? value.type : value
263
- ]
264
- )), {
167
+ ])), {
265
168
  permissive: true
266
169
  });
267
170
  // Manual parsing of flags to allow for special flags like oneOf(Boolean, String)
268
171
  for(let i = result["_"].length - 1; i >= 0; --i){
269
172
  let flag = result["_"][i];
270
173
  if (!flag.startsWith("-")) continue;
271
- let flagName = flag;
272
- let handler = flags[flag];
174
+ let [flagName, flagValue] = flag.split("=");
175
+ let handler = flags[flagName];
273
176
  // Resolve flagName & handler
274
177
  while(typeof handler === "string"){
275
178
  flagName = handler;
276
179
  handler = flags[handler];
277
180
  }
278
181
  if (!handler) continue;
279
- let args1 = [];
182
+ let args = [];
280
183
  let offset = i + 1;
281
- // Parse args for current flag
282
- while(result["_"][offset] && !result["_"][offset].startsWith("-")){
283
- args1.push(result["_"][offset++]);
184
+ // --flag value syntax was used so we need to pull `value` from `args`
185
+ if (flagValue === undefined) {
186
+ // Parse args for current flag
187
+ while(result["_"][offset] && !result["_"][offset].startsWith("-")){
188
+ args.push(result["_"][offset++]);
189
+ }
190
+ // Cleanup manually parsed flags + args
191
+ result["_"].splice(i, 1 + args.length);
192
+ // No args were provided, use default value defined in handler
193
+ // One arg was provided, use that directly
194
+ // Multiple args were provided so pass them all in an array
195
+ flagValue = args.length === 0 ? undefined : args.length === 1 ? args[0] : args;
196
+ } else {
197
+ // Remove the whole flag from the args array
198
+ result["_"].splice(i, 1);
284
199
  }
285
- // Cleanup manually parsed flags + args
286
- result["_"].splice(i, 1 + args1.length);
287
200
  // Set the resolved value in the `result` object
288
- result[flagName] = handler.type(args1.length === 0 ? undefined : args1.length === 1 ? args1[0] : args1, flagName);
201
+ result[flagName] = handler.type(flagValue, flagName);
289
202
  }
290
203
  // Ensure that the `command` is always the first argument in the `args`.
291
204
  // This is important so that we don't have to check if a default command
@@ -299,7 +212,7 @@ let args = (()=>{
299
212
  return result;
300
213
  } catch (err) {
301
214
  if (err.code === "ARG_UNKNOWN_OPTION") {
302
- help({
215
+ (0, _help.help)({
303
216
  message: err.message,
304
217
  usage: [
305
218
  "tailwindcss <command> [options]"
@@ -312,7 +225,7 @@ let args = (()=>{
312
225
  }
313
226
  })();
314
227
  if (args["--help"]) {
315
- help({
228
+ (0, _help.help)({
316
229
  options: {
317
230
  ...flags,
318
231
  ...sharedFlags
@@ -323,447 +236,4 @@ if (args["--help"]) {
323
236
  });
324
237
  process.exit(0);
325
238
  }
326
- run();
327
- // ---
328
- function init() {
329
- let messages = [];
330
- var ref;
331
- let tailwindConfigLocation = _path.default.resolve((ref = args["_"][1]) !== null && ref !== void 0 ? ref : "./tailwind.config.js");
332
- if (_fs.default.existsSync(tailwindConfigLocation)) {
333
- messages.push(`${_path.default.basename(tailwindConfigLocation)} already exists.`);
334
- } else {
335
- let stubFile = _fs.default.readFileSync(args["--full"] ? _path.default.resolve(__dirname, "../stubs/defaultConfig.stub.js") : _path.default.resolve(__dirname, "../stubs/simpleConfig.stub.js"), "utf8");
336
- if (args["--types"]) {
337
- let typesHeading = "/** @type {import('tailwindcss/types').Config} */";
338
- stubFile = stubFile.replace(`module.exports = `, `${typesHeading}\nconst config = `) + "\nmodule.exports = config";
339
- }
340
- // Change colors import
341
- stubFile = stubFile.replace("../colors", "tailwindcss/colors");
342
- _fs.default.writeFileSync(tailwindConfigLocation, stubFile, "utf8");
343
- messages.push(`Created Tailwind CSS config file: ${_path.default.basename(tailwindConfigLocation)}`);
344
- }
345
- if (args["--postcss"]) {
346
- let postcssConfigLocation = _path.default.resolve("./postcss.config.js");
347
- if (_fs.default.existsSync(postcssConfigLocation)) {
348
- messages.push(`${_path.default.basename(postcssConfigLocation)} already exists.`);
349
- } else {
350
- let stubFile = _fs.default.readFileSync(_path.default.resolve(__dirname, "../stubs/defaultPostCssConfig.stub.js"), "utf8");
351
- _fs.default.writeFileSync(postcssConfigLocation, stubFile, "utf8");
352
- messages.push(`Created PostCSS config file: ${_path.default.basename(postcssConfigLocation)}`);
353
- }
354
- }
355
- if (messages.length > 0) {
356
- console.log();
357
- for (let message of messages){
358
- console.log(message);
359
- }
360
- }
361
- }
362
- async function build() {
363
- let input = args["--input"];
364
- let output = args["--output"];
365
- let shouldWatch = args["--watch"];
366
- let shouldPoll = args["--poll"];
367
- let shouldCoalesceWriteEvents = shouldPoll || process.platform === "win32";
368
- let includePostCss = args["--postcss"];
369
- // Polling interval in milliseconds
370
- // Used only when polling or coalescing add/change events on Windows
371
- let pollInterval = 10;
372
- // TODO: Deprecate this in future versions
373
- if (!input && args["_"][1]) {
374
- console.error("[deprecation] Running tailwindcss without -i, please provide an input file.");
375
- input = args["--input"] = args["_"][1];
376
- }
377
- if (input && input !== "-" && !_fs.default.existsSync(input = _path.default.resolve(input))) {
378
- console.error(`Specified input file ${args["--input"]} does not exist.`);
379
- process.exit(9);
380
- }
381
- if (args["--config"] && !_fs.default.existsSync(args["--config"] = _path.default.resolve(args["--config"]))) {
382
- console.error(`Specified config file ${args["--config"]} does not exist.`);
383
- process.exit(9);
384
- }
385
- let configPath = args["--config"] ? args["--config"] : ((defaultPath)=>_fs.default.existsSync(defaultPath) ? defaultPath : null
386
- )(_path.default.resolve("./tailwind.config.js"));
387
- async function loadPostCssPlugins() {
388
- let customPostCssPath = typeof args["--postcss"] === "string" ? args["--postcss"] : undefined;
389
- let config1 = customPostCssPath ? await (async ()=>{
390
- let file = _path.default.resolve(customPostCssPath);
391
- // Implementation, see: https://unpkg.com/browse/postcss-load-config@3.1.0/src/index.js
392
- let { config ={} } = await (0, _lilconfig).lilconfig("postcss").load(file);
393
- if (typeof config === "function") {
394
- config = config();
395
- } else {
396
- config = Object.assign({}, config);
397
- }
398
- if (!config.plugins) {
399
- config.plugins = [];
400
- }
401
- return {
402
- file,
403
- plugins: (0, _plugins).default(config, file),
404
- options: (0, _options).default(config, file)
405
- };
406
- })() : await (0, _postcssLoadConfig).default();
407
- let configPlugins = config1.plugins;
408
- let configPluginTailwindIdx = configPlugins.findIndex((plugin)=>{
409
- if (typeof plugin === "function" && plugin.name === "tailwindcss") {
410
- return true;
411
- }
412
- if (typeof plugin === "object" && plugin !== null && plugin.postcssPlugin === "tailwindcss") {
413
- return true;
414
- }
415
- return false;
416
- });
417
- let beforePlugins = configPluginTailwindIdx === -1 ? [] : configPlugins.slice(0, configPluginTailwindIdx);
418
- let afterPlugins = configPluginTailwindIdx === -1 ? configPlugins : configPlugins.slice(configPluginTailwindIdx + 1);
419
- return [
420
- beforePlugins,
421
- afterPlugins,
422
- config1.options
423
- ];
424
- }
425
- function resolveConfig() {
426
- let config = configPath ? require(configPath) : {};
427
- if (args["--purge"]) {
428
- _log.default.warn("purge-flag-deprecated", [
429
- "The `--purge` flag has been deprecated.",
430
- "Please use `--content` instead.",
431
- ]);
432
- if (!args["--content"]) {
433
- args["--content"] = args["--purge"];
434
- }
435
- }
436
- if (args["--content"]) {
437
- let files = args["--content"].split(/(?<!{[^}]+),/);
438
- let resolvedConfig = (0, _resolveConfig).default(config, {
439
- content: {
440
- files
441
- }
442
- });
443
- resolvedConfig.content.files = files;
444
- return resolvedConfig;
445
- }
446
- return (0, _resolveConfig).default(config);
447
- }
448
- function extractFileGlobs(config) {
449
- return config.content.files.filter((file)=>{
450
- // Strings in this case are files / globs. If it is something else,
451
- // like an object it's probably a raw content object. But this object
452
- // is not watchable, so let's remove it.
453
- return typeof file === "string";
454
- }).map((glob)=>(0, _normalizePath).default(glob)
455
- );
456
- }
457
- function extractRawContent(config) {
458
- return config.content.files.filter((file)=>{
459
- return typeof file === "object" && file !== null;
460
- });
461
- }
462
- function getChangedContent(config) {
463
- let changedContent = [];
464
- // Resolve globs from the content config
465
- let globs = extractFileGlobs(config);
466
- let files = _fastGlob.default.sync(globs);
467
- for (let file of files){
468
- changedContent.push({
469
- content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
470
- extension: _path.default.extname(file).slice(1)
471
- });
472
- }
473
- // Resolve raw content in the tailwind config
474
- for (let { raw: content , extension ="html" } of extractRawContent(config)){
475
- changedContent.push({
476
- content,
477
- extension
478
- });
479
- }
480
- return changedContent;
481
- }
482
- async function buildOnce() {
483
- let config = resolveConfig();
484
- let changedContent = getChangedContent(config);
485
- let tailwindPlugin = ()=>{
486
- return {
487
- postcssPlugin: "tailwindcss",
488
- Once (root, { result }) {
489
- (0, _processTailwindFeatures).default(({ createContext })=>{
490
- return ()=>{
491
- return createContext(config, changedContent);
492
- };
493
- })(root, result);
494
- }
495
- };
496
- };
497
- tailwindPlugin.postcss = true;
498
- let [beforePlugins, afterPlugins, postcssOptions] = includePostCss ? await loadPostCssPlugins() : [
499
- [],
500
- [],
501
- {}
502
- ];
503
- let plugins = [
504
- ...beforePlugins,
505
- tailwindPlugin,
506
- !args["--minify"] && formatNodes,
507
- ...afterPlugins,
508
- !args["--no-autoprefixer"] && (()=>{
509
- // Try to load a local `autoprefixer` version first
510
- try {
511
- return require("autoprefixer");
512
- } catch {}
513
- return (0, _indexJs).lazyAutoprefixer();
514
- })(),
515
- args["--minify"] && (()=>{
516
- let options = {
517
- preset: [
518
- "default",
519
- {
520
- cssDeclarationSorter: false
521
- }
522
- ]
523
- };
524
- // Try to load a local `cssnano` version first
525
- try {
526
- return require("cssnano");
527
- } catch {}
528
- return (0, _indexJs).lazyCssnano()(options);
529
- })(),
530
- ].filter(Boolean);
531
- let processor = (0, _indexJs).postcss(plugins);
532
- function processCSS(css) {
533
- let start = process.hrtime.bigint();
534
- return Promise.resolve().then(()=>output ? _fs.default.promises.mkdir(_path.default.dirname(output), {
535
- recursive: true
536
- }) : null
537
- ).then(()=>processor.process(css, {
538
- ...postcssOptions,
539
- from: input,
540
- to: output
541
- })
542
- ).then((result)=>{
543
- if (!output) {
544
- return process.stdout.write(result.css);
545
- }
546
- return Promise.all([
547
- outputFile(output, result.css),
548
- result.map && outputFile(output + ".map", result.map.toString()),
549
- ].filter(Boolean));
550
- }).then(()=>{
551
- let end = process.hrtime.bigint();
552
- console.error();
553
- console.error("Done in", (end - start) / BigInt(1000000) + "ms.");
554
- });
555
- }
556
- let css1 = await (()=>{
557
- // Piping in data, let's drain the stdin
558
- if (input === "-") {
559
- return drainStdin();
560
- }
561
- // Input file has been provided
562
- if (input) {
563
- return _fs.default.readFileSync(_path.default.resolve(input), "utf8");
564
- }
565
- // No input file provided, fallback to default atrules
566
- return "@tailwind base; @tailwind components; @tailwind utilities";
567
- })();
568
- return processCSS(css1);
569
- }
570
- let context = null;
571
- async function startWatcher() {
572
- let changedContent = [];
573
- let configDependencies = [];
574
- let contextDependencies = new Set();
575
- let watcher = null;
576
- function refreshConfig() {
577
- env.DEBUG && console.time("Module dependencies");
578
- for (let file1 of configDependencies){
579
- delete require.cache[require.resolve(file1)];
580
- }
581
- if (configPath) {
582
- configDependencies = (0, _getModuleDependencies).default(configPath).map(({ file })=>file
583
- );
584
- for (let dependency of configDependencies){
585
- contextDependencies.add(dependency);
586
- }
587
- }
588
- env.DEBUG && console.timeEnd("Module dependencies");
589
- return resolveConfig();
590
- }
591
- let [beforePlugins, afterPlugins] = includePostCss ? await loadPostCssPlugins() : [
592
- [],
593
- []
594
- ];
595
- let plugins = [
596
- ...beforePlugins,
597
- "__TAILWIND_PLUGIN_POSITION__",
598
- !args["--minify"] && formatNodes,
599
- ...afterPlugins,
600
- !args["--no-autoprefixer"] && (()=>{
601
- // Try to load a local `autoprefixer` version first
602
- try {
603
- return require("autoprefixer");
604
- } catch {}
605
- return (0, _indexJs).lazyAutoprefixer();
606
- })(),
607
- args["--minify"] && (()=>{
608
- let options = {
609
- preset: [
610
- "default",
611
- {
612
- cssDeclarationSorter: false
613
- }
614
- ]
615
- };
616
- // Try to load a local `cssnano` version first
617
- try {
618
- return require("cssnano");
619
- } catch {}
620
- return (0, _indexJs).lazyCssnano()(options);
621
- })(),
622
- ].filter(Boolean);
623
- async function rebuild(config) {
624
- env.DEBUG && console.time("Finished in");
625
- let tailwindPlugin = ()=>{
626
- return {
627
- postcssPlugin: "tailwindcss",
628
- Once (root, { result }) {
629
- env.DEBUG && console.time("Compiling CSS");
630
- (0, _processTailwindFeatures).default(({ createContext })=>{
631
- console.error();
632
- console.error("Rebuilding...");
633
- return ()=>{
634
- if (context !== null) {
635
- context.changedContent = changedContent.splice(0);
636
- return context;
637
- }
638
- env.DEBUG && console.time("Creating context");
639
- context = createContext(config, changedContent.splice(0));
640
- env.DEBUG && console.timeEnd("Creating context");
641
- return context;
642
- };
643
- })(root, result);
644
- env.DEBUG && console.timeEnd("Compiling CSS");
645
- }
646
- };
647
- };
648
- tailwindPlugin.postcss = true;
649
- let tailwindPluginIdx = plugins.indexOf("__TAILWIND_PLUGIN_POSITION__");
650
- let copy = plugins.slice();
651
- copy.splice(tailwindPluginIdx, 1, tailwindPlugin);
652
- let processor = (0, _indexJs).postcss(copy);
653
- function processCSS(css) {
654
- let start = process.hrtime.bigint();
655
- return Promise.resolve().then(()=>output ? _fs.default.promises.mkdir(_path.default.dirname(output), {
656
- recursive: true
657
- }) : null
658
- ).then(()=>processor.process(css, {
659
- from: input,
660
- to: output
661
- })
662
- ).then(async (result)=>{
663
- for (let message of result.messages){
664
- if (message.type === "dependency") {
665
- contextDependencies.add(message.file);
666
- }
667
- }
668
- watcher.add([
669
- ...contextDependencies
670
- ]);
671
- if (!output) {
672
- return process.stdout.write(result.css);
673
- }
674
- return Promise.all([
675
- outputFile(output, result.css),
676
- result.map && outputFile(output + ".map", result.map.toString()),
677
- ].filter(Boolean));
678
- }).then(()=>{
679
- let end = process.hrtime.bigint();
680
- console.error("Done in", (end - start) / BigInt(1000000) + "ms.");
681
- }).catch((err)=>{
682
- if (err.name === "CssSyntaxError") {
683
- console.error(err.toString());
684
- } else {
685
- console.error(err);
686
- }
687
- });
688
- }
689
- let css2 = await (()=>{
690
- // Piping in data, let's drain the stdin
691
- if (input === "-") {
692
- return drainStdin();
693
- }
694
- // Input file has been provided
695
- if (input) {
696
- return _fs.default.readFileSync(_path.default.resolve(input), "utf8");
697
- }
698
- // No input file provided, fallback to default atrules
699
- return "@tailwind base; @tailwind components; @tailwind utilities";
700
- })();
701
- let result1 = await processCSS(css2);
702
- env.DEBUG && console.timeEnd("Finished in");
703
- return result1;
704
- }
705
- let config2 = refreshConfig(configPath);
706
- if (input) {
707
- contextDependencies.add(_path.default.resolve(input));
708
- }
709
- watcher = _chokidar.default.watch([
710
- ...contextDependencies,
711
- ...extractFileGlobs(config2)
712
- ], {
713
- usePolling: shouldPoll,
714
- interval: shouldPoll ? pollInterval : undefined,
715
- ignoreInitial: true,
716
- awaitWriteFinish: shouldCoalesceWriteEvents ? {
717
- stabilityThreshold: 50,
718
- pollInterval: pollInterval
719
- } : false
720
- });
721
- let chain = Promise.resolve();
722
- watcher.on("change", async (file)=>{
723
- if (contextDependencies.has(file)) {
724
- env.DEBUG && console.time("Resolve config");
725
- context = null;
726
- config2 = refreshConfig(configPath);
727
- env.DEBUG && console.timeEnd("Resolve config");
728
- env.DEBUG && console.time("Watch new files");
729
- let globs = extractFileGlobs(config2);
730
- watcher.add(configDependencies);
731
- watcher.add(globs);
732
- env.DEBUG && console.timeEnd("Watch new files");
733
- chain = chain.then(async ()=>{
734
- changedContent.push(...getChangedContent(config2));
735
- await rebuild(config2);
736
- });
737
- } else {
738
- chain = chain.then(async ()=>{
739
- changedContent.push({
740
- content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
741
- extension: _path.default.extname(file).slice(1)
742
- });
743
- await rebuild(config2);
744
- });
745
- }
746
- });
747
- watcher.on("add", async (file)=>{
748
- chain = chain.then(async ()=>{
749
- changedContent.push({
750
- content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
751
- extension: _path.default.extname(file).slice(1)
752
- });
753
- await rebuild(config2);
754
- });
755
- });
756
- chain = chain.then(()=>{
757
- changedContent.push(...getChangedContent(config2));
758
- return rebuild(config2);
759
- });
760
- }
761
- if (shouldWatch) {
762
- /* Abort the watcher if stdin is closed to avoid zombie processes */ process.stdin.on("end", ()=>process.exit(0)
763
- );
764
- process.stdin.resume();
765
- startWatcher();
766
- } else {
767
- buildOnce();
768
- }
769
- }
239
+ run(args, configs);