tailwindcss 0.0.0-insiders.cd5cb00 → 0.0.0-insiders.cea3ccf

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