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