tailwindcss 0.0.0-insiders.f4635e0 → 0.0.0-insiders.f84ee8b

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