tailwindcss 0.0.0-insiders.ee945bb → 0.0.0-insiders.ef2ebb2

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