tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cc69633

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