tailwindcss 0.0.0-insiders.fda68f7 → 0.0.0-oxide.6bf5e56

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 (195) hide show
  1. package/CHANGELOG.md +603 -2
  2. package/LICENSE +1 -2
  3. package/README.md +14 -6
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -304
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -4
  8. package/defaultTheme.d.ts +4 -0
  9. package/defaultTheme.js +2 -4
  10. package/lib/cli/build/deps.js +54 -0
  11. package/lib/cli/build/index.js +48 -0
  12. package/lib/cli/build/plugin.js +367 -0
  13. package/lib/cli/build/utils.js +78 -0
  14. package/lib/cli/build/watching.js +178 -0
  15. package/lib/cli/help/index.js +71 -0
  16. package/lib/cli/index.js +18 -0
  17. package/lib/cli/init/index.js +46 -0
  18. package/lib/cli/shared.js +13 -0
  19. package/lib/cli-peer-dependencies.js +22 -14
  20. package/lib/cli.js +217 -743
  21. package/lib/constants.js +41 -34
  22. package/lib/corePluginList.js +178 -5
  23. package/lib/corePlugins.js +3879 -2941
  24. package/lib/css/preflight.css +22 -9
  25. package/lib/featureFlags.js +61 -50
  26. package/lib/index.js +45 -28
  27. package/lib/lib/cacheInvalidation.js +90 -0
  28. package/lib/lib/collapseAdjacentRules.js +52 -36
  29. package/lib/lib/collapseDuplicateDeclarations.js +83 -0
  30. package/lib/lib/content.js +176 -0
  31. package/lib/lib/defaultExtractor.js +236 -0
  32. package/lib/lib/detectNesting.js +37 -0
  33. package/lib/lib/evaluateTailwindFunctions.js +203 -161
  34. package/lib/lib/expandApplyAtRules.js +502 -221
  35. package/lib/lib/expandTailwindAtRules.js +258 -243
  36. package/lib/lib/findAtConfigPath.js +44 -0
  37. package/lib/lib/generateRules.js +775 -320
  38. package/lib/lib/getModuleDependencies.js +44 -46
  39. package/lib/lib/normalizeTailwindDirectives.js +79 -60
  40. package/lib/lib/offsets.js +217 -0
  41. package/lib/lib/partitionApplyAtRules.js +56 -0
  42. package/lib/lib/regex.js +60 -0
  43. package/lib/lib/resolveDefaultsAtRules.js +150 -94
  44. package/lib/lib/setupContextUtils.js +1146 -599
  45. package/lib/lib/setupTrackingContext.js +129 -177
  46. package/lib/lib/sharedState.js +53 -21
  47. package/lib/lib/substituteScreenAtRules.js +26 -28
  48. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  49. package/lib/postcss-plugins/nesting/index.js +19 -0
  50. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  51. package/lib/processTailwindFeatures.js +58 -53
  52. package/lib/public/colors.js +331 -0
  53. package/lib/public/create-plugin.js +15 -0
  54. package/lib/public/default-config.js +16 -0
  55. package/lib/public/default-theme.js +16 -0
  56. package/lib/public/resolve-config.js +22 -0
  57. package/lib/util/bigSign.js +7 -6
  58. package/lib/util/buildMediaQuery.js +21 -32
  59. package/lib/util/cloneDeep.js +16 -14
  60. package/lib/util/cloneNodes.js +29 -15
  61. package/lib/util/color.js +90 -66
  62. package/lib/util/configurePlugins.js +17 -15
  63. package/lib/util/createPlugin.js +23 -26
  64. package/lib/util/createUtilityPlugin.js +46 -46
  65. package/lib/util/dataTypes.js +242 -0
  66. package/lib/util/defaults.js +20 -15
  67. package/lib/util/escapeClassName.js +18 -17
  68. package/lib/util/escapeCommas.js +7 -6
  69. package/lib/util/flattenColorPalette.js +13 -12
  70. package/lib/util/formatVariantSelector.js +285 -0
  71. package/lib/util/getAllConfigs.js +44 -18
  72. package/lib/util/hashConfig.js +15 -12
  73. package/lib/util/isKeyframeRule.js +7 -6
  74. package/lib/util/isPlainObject.js +11 -11
  75. package/lib/util/isSyntacticallyValidPropertyValue.js +72 -0
  76. package/lib/util/log.js +52 -33
  77. package/lib/util/nameClass.js +37 -26
  78. package/lib/util/negateValue.js +31 -17
  79. package/lib/util/normalizeConfig.js +281 -0
  80. package/lib/util/normalizeScreens.js +170 -0
  81. package/lib/util/parseAnimationValue.js +85 -54
  82. package/lib/util/parseBoxShadowValue.js +84 -0
  83. package/lib/util/parseDependency.js +41 -70
  84. package/lib/util/parseGlob.js +34 -0
  85. package/lib/util/parseObjectStyles.js +30 -24
  86. package/lib/util/pluginUtils.js +252 -287
  87. package/lib/util/prefixSelector.js +20 -20
  88. package/lib/util/removeAlphaVariables.js +29 -0
  89. package/lib/util/resolveConfig.js +221 -256
  90. package/lib/util/resolveConfigPath.js +43 -48
  91. package/lib/util/responsive.js +18 -14
  92. package/lib/util/splitAtTopLevelOnly.js +43 -0
  93. package/lib/util/tap.js +8 -7
  94. package/lib/util/toColorValue.js +7 -6
  95. package/lib/util/toPath.js +27 -8
  96. package/lib/util/transformThemeValue.js +67 -28
  97. package/lib/util/validateConfig.js +24 -0
  98. package/lib/util/validateFormalSyntax.js +24 -0
  99. package/lib/util/withAlphaVariable.js +67 -57
  100. package/nesting/index.js +2 -12
  101. package/package.json +60 -65
  102. package/peers/index.js +76445 -84221
  103. package/plugin.d.ts +11 -0
  104. package/plugin.js +1 -2
  105. package/resolveConfig.d.ts +12 -0
  106. package/resolveConfig.js +2 -7
  107. package/scripts/create-plugin-list.js +2 -2
  108. package/scripts/generate-types.js +105 -0
  109. package/scripts/release-channel.js +18 -0
  110. package/scripts/release-notes.js +21 -0
  111. package/scripts/type-utils.js +27 -0
  112. package/src/cli/build/deps.js +56 -0
  113. package/src/cli/build/index.js +49 -0
  114. package/src/cli/build/plugin.js +439 -0
  115. package/src/cli/build/utils.js +76 -0
  116. package/src/cli/build/watching.js +227 -0
  117. package/src/cli/help/index.js +70 -0
  118. package/src/cli/index.js +3 -0
  119. package/src/cli/init/index.js +50 -0
  120. package/src/cli/shared.js +6 -0
  121. package/src/cli-peer-dependencies.js +7 -1
  122. package/src/cli.js +50 -575
  123. package/src/corePluginList.js +1 -1
  124. package/src/corePlugins.js +2405 -1948
  125. package/src/css/preflight.css +22 -9
  126. package/src/featureFlags.js +26 -10
  127. package/src/index.js +19 -6
  128. package/src/lib/cacheInvalidation.js +52 -0
  129. package/src/lib/collapseAdjacentRules.js +21 -2
  130. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  131. package/src/lib/content.js +212 -0
  132. package/src/lib/defaultExtractor.js +211 -0
  133. package/src/lib/detectNesting.js +39 -0
  134. package/src/lib/evaluateTailwindFunctions.js +84 -10
  135. package/src/lib/expandApplyAtRules.js +508 -153
  136. package/src/lib/expandTailwindAtRules.js +130 -104
  137. package/src/lib/findAtConfigPath.js +48 -0
  138. package/src/lib/generateRules.js +596 -70
  139. package/src/lib/normalizeTailwindDirectives.js +10 -3
  140. package/src/lib/offsets.js +270 -0
  141. package/src/lib/partitionApplyAtRules.js +52 -0
  142. package/src/lib/regex.js +74 -0
  143. package/src/lib/resolveDefaultsAtRules.js +105 -47
  144. package/src/lib/setupContextUtils.js +828 -196
  145. package/src/lib/setupTrackingContext.js +19 -54
  146. package/src/lib/sharedState.js +45 -7
  147. package/src/lib/substituteScreenAtRules.js +6 -3
  148. package/src/postcss-plugins/nesting/README.md +42 -0
  149. package/src/postcss-plugins/nesting/index.js +13 -0
  150. package/src/postcss-plugins/nesting/plugin.js +80 -0
  151. package/src/processTailwindFeatures.js +19 -2
  152. package/src/public/colors.js +300 -0
  153. package/src/public/create-plugin.js +2 -0
  154. package/src/public/default-config.js +4 -0
  155. package/src/public/default-theme.js +4 -0
  156. package/src/public/resolve-config.js +7 -0
  157. package/src/util/buildMediaQuery.js +14 -16
  158. package/src/util/cloneNodes.js +19 -2
  159. package/src/util/color.js +31 -14
  160. package/src/util/createUtilityPlugin.js +2 -11
  161. package/src/util/dataTypes.js +256 -0
  162. package/src/util/defaults.js +6 -0
  163. package/src/util/formatVariantSelector.js +319 -0
  164. package/src/util/getAllConfigs.js +19 -0
  165. package/src/util/isSyntacticallyValidPropertyValue.js +61 -0
  166. package/src/util/log.js +23 -22
  167. package/src/util/nameClass.js +14 -6
  168. package/src/util/negateValue.js +15 -5
  169. package/src/util/normalizeConfig.js +300 -0
  170. package/src/util/normalizeScreens.js +140 -0
  171. package/src/util/parseAnimationValue.js +7 -1
  172. package/src/util/parseBoxShadowValue.js +72 -0
  173. package/src/util/parseDependency.js +37 -38
  174. package/src/util/parseGlob.js +24 -0
  175. package/src/util/pluginUtils.js +216 -197
  176. package/src/util/prefixSelector.js +7 -8
  177. package/src/util/removeAlphaVariables.js +24 -0
  178. package/src/util/resolveConfig.js +86 -91
  179. package/src/util/splitAtTopLevelOnly.js +45 -0
  180. package/src/util/toPath.js +23 -1
  181. package/src/util/transformThemeValue.js +33 -8
  182. package/src/util/validateConfig.js +13 -0
  183. package/src/util/validateFormalSyntax.js +34 -0
  184. package/src/util/withAlphaVariable.js +14 -9
  185. package/stubs/defaultConfig.stub.js +186 -117
  186. package/stubs/simpleConfig.stub.js +1 -1
  187. package/types/config.d.ts +362 -0
  188. package/types/generated/.gitkeep +0 -0
  189. package/types/generated/colors.d.ts +276 -0
  190. package/types/generated/corePluginList.d.ts +1 -0
  191. package/types/generated/default-theme.d.ts +342 -0
  192. package/types/index.d.ts +7 -0
  193. package/lib/lib/setupWatchingContext.js +0 -331
  194. package/nesting/plugin.js +0 -41
  195. package/src/lib/setupWatchingContext.js +0 -306
package/src/cli.js CHANGED
@@ -1,112 +1,35 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { postcss, lazyCssnano, lazyAutoprefixer } from '../peers/index.js'
4
-
5
- import chokidar from 'chokidar'
6
3
  import path from 'path'
7
4
  import arg from 'arg'
8
5
  import fs from 'fs'
9
- import postcssrc from 'postcss-load-config'
10
- import { cosmiconfig } from 'cosmiconfig'
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
6
 
19
- let env = {
20
- DEBUG: process.env.DEBUG !== undefined,
21
- }
7
+ import { build } from './cli/build'
8
+ import { help } from './cli/help'
9
+ import { init } from './cli/init'
22
10
 
23
- // ---
11
+ function isESM() {
12
+ const pkgPath = path.resolve('./package.json')
24
13
 
25
- function indentRecursive(node, indent = 0) {
26
- node.each &&
27
- node.each((child, i) => {
28
- if (!child.raws.before || !child.raws.before.trim() || child.raws.before.includes('\n')) {
29
- child.raws.before = `\n${node.type !== 'rule' && i > 0 ? '\n' : ''}${' '.repeat(indent)}`
30
- }
31
- child.raws.after = `\n${' '.repeat(indent)}`
32
- indentRecursive(child, indent + 1)
33
- })
34
- }
35
-
36
- function formatNodes(root) {
37
- indentRecursive(root)
38
- if (root.first) {
39
- root.first.raws.before = ''
14
+ try {
15
+ let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
16
+ return pkg.type && pkg.type === 'module'
17
+ } catch (err) {
18
+ return false
40
19
  }
41
20
  }
42
21
 
43
- function help({ message, usage, commands, options }) {
44
- let indent = 2
45
-
46
- // Render header
47
- console.log()
48
- console.log(`${packageJson.name} v${packageJson.version}`)
49
-
50
- // Render message
51
- if (message) {
52
- console.log()
53
- for (let msg of message.split('\n')) {
54
- console.log(msg)
22
+ let configs = isESM()
23
+ ? {
24
+ tailwind: 'tailwind.config.cjs',
25
+ postcss: 'postcss.config.cjs',
55
26
  }
56
- }
57
-
58
- // Render usage
59
- if (usage && usage.length > 0) {
60
- console.log()
61
- console.log('Usage:')
62
- for (let example of usage) {
63
- console.log(' '.repeat(indent), example)
64
- }
65
- }
66
-
67
- // Render commands
68
- if (commands && commands.length > 0) {
69
- console.log()
70
- console.log('Commands:')
71
- for (let command of commands) {
72
- console.log(' '.repeat(indent), command)
27
+ : {
28
+ tailwind: 'tailwind.config.js',
29
+ postcss: 'postcss.config.js',
73
30
  }
74
- }
75
-
76
- // Render options
77
- if (options) {
78
- let groupedOptions = {}
79
- for (let [key, value] of Object.entries(options)) {
80
- if (typeof value === 'object') {
81
- groupedOptions[key] = { ...value, flags: [key] }
82
- } else {
83
- groupedOptions[value].flags.push(key)
84
- }
85
- }
86
-
87
- console.log()
88
- console.log('Options:')
89
- for (let { flags, description, deprecated } of Object.values(groupedOptions)) {
90
- if (deprecated) continue
91
31
 
92
- if (flags.length === 1) {
93
- console.log(
94
- ' '.repeat(indent + 4 /* 4 = "-i, ".length */),
95
- flags.slice().reverse().join(', ').padEnd(20, ' '),
96
- description
97
- )
98
- } else {
99
- console.log(
100
- ' '.repeat(indent),
101
- flags.slice().reverse().join(', ').padEnd(24, ' '),
102
- description
103
- )
104
- }
105
- }
106
- }
107
-
108
- console.log()
109
- }
32
+ // ---
110
33
 
111
34
  function oneOf(...options) {
112
35
  return Object.assign(
@@ -128,8 +51,8 @@ let commands = {
128
51
  init: {
129
52
  run: init,
130
53
  args: {
131
- '--full': { type: Boolean, description: 'Initialize a full `tailwind.config.js` file' },
132
- '--postcss': { type: Boolean, description: 'Initialize a `postcss.config.js` file' },
54
+ '--full': { type: Boolean, description: `Initialize a full \`${configs.tailwind}\` file` },
55
+ '--postcss': { type: Boolean, description: `Initialize a \`${configs.postcss}\` file` },
133
56
  '-f': '--full',
134
57
  '-p': '--postcss',
135
58
  },
@@ -139,7 +62,14 @@ let commands = {
139
62
  args: {
140
63
  '--input': { type: String, description: 'Input file' },
141
64
  '--output': { type: String, description: 'Output file' },
142
- '--watch': { type: Boolean, description: 'Watch for changes and rebuild as needed' },
65
+ '--watch': {
66
+ type: oneOf(String, Boolean),
67
+ description: 'Watch for changes and rebuild as needed',
68
+ },
69
+ '--poll': {
70
+ type: Boolean,
71
+ description: 'Use polling instead of filesystem events when watching',
72
+ },
143
73
  '--content': {
144
74
  type: String,
145
75
  description: 'Content paths to use for removing unused classes',
@@ -166,6 +96,7 @@ let commands = {
166
96
  '-o': '--output',
167
97
  '-m': '--minify',
168
98
  '-w': '--watch',
99
+ '-p': '--poll',
169
100
  },
170
101
  },
171
102
  }
@@ -231,8 +162,8 @@ let args = (() => {
231
162
  let flag = result['_'][i]
232
163
  if (!flag.startsWith('-')) continue
233
164
 
234
- let flagName = flag
235
- let handler = flags[flag]
165
+ let [flagName, flagValue] = flag.split('=')
166
+ let handler = flags[flagName]
236
167
 
237
168
  // Resolve flagName & handler
238
169
  while (typeof handler === 'string') {
@@ -245,19 +176,27 @@ let args = (() => {
245
176
  let args = []
246
177
  let offset = i + 1
247
178
 
248
- // Parse args for current flag
249
- while (result['_'][offset] && !result['_'][offset].startsWith('-')) {
250
- args.push(result['_'][offset++])
251
- }
179
+ // --flag value syntax was used so we need to pull `value` from `args`
180
+ if (flagValue === undefined) {
181
+ // Parse args for current flag
182
+ while (result['_'][offset] && !result['_'][offset].startsWith('-')) {
183
+ args.push(result['_'][offset++])
184
+ }
185
+
186
+ // Cleanup manually parsed flags + args
187
+ result['_'].splice(i, 1 + args.length)
252
188
 
253
- // Cleanup manually parsed flags + args
254
- result['_'].splice(i, 1 + args.length)
189
+ // No args were provided, use default value defined in handler
190
+ // One arg was provided, use that directly
191
+ // Multiple args were provided so pass them all in an array
192
+ flagValue = args.length === 0 ? undefined : args.length === 1 ? args[0] : args
193
+ } else {
194
+ // Remove the whole flag from the args array
195
+ result['_'].splice(i, 1)
196
+ }
255
197
 
256
198
  // Set the resolved value in the `result` object
257
- result[flagName] = handler.type(
258
- args.length === 0 ? undefined : args.length === 1 ? args[0] : args,
259
- flagName
260
- )
199
+ result[flagName] = handler.type(flagValue, flagName)
261
200
  }
262
201
 
263
202
  // Ensure that the `command` is always the first argument in the `args`.
@@ -292,468 +231,4 @@ if (args['--help']) {
292
231
  process.exit(0)
293
232
  }
294
233
 
295
- run()
296
-
297
- // ---
298
-
299
- function init() {
300
- let messages = []
301
-
302
- let tailwindConfigLocation = path.resolve(args['_'][1] ?? './tailwind.config.js')
303
- if (fs.existsSync(tailwindConfigLocation)) {
304
- messages.push(`${path.basename(tailwindConfigLocation)} already exists.`)
305
- } else {
306
- let stubFile = fs.readFileSync(
307
- args['--full']
308
- ? path.resolve(__dirname, '../stubs/defaultConfig.stub.js')
309
- : path.resolve(__dirname, '../stubs/simpleConfig.stub.js'),
310
- 'utf8'
311
- )
312
-
313
- // Change colors import
314
- stubFile = stubFile.replace('../colors', 'tailwindcss/colors')
315
-
316
- fs.writeFileSync(tailwindConfigLocation, stubFile, 'utf8')
317
-
318
- messages.push(`Created Tailwind CSS config file: ${path.basename(tailwindConfigLocation)}`)
319
- }
320
-
321
- if (args['--postcss']) {
322
- let postcssConfigLocation = path.resolve('./postcss.config.js')
323
- if (fs.existsSync(postcssConfigLocation)) {
324
- messages.push(`${path.basename(postcssConfigLocation)} already exists.`)
325
- } else {
326
- let stubFile = fs.readFileSync(
327
- path.resolve(__dirname, '../stubs/defaultPostCssConfig.stub.js'),
328
- 'utf8'
329
- )
330
-
331
- fs.writeFileSync(postcssConfigLocation, stubFile, 'utf8')
332
-
333
- messages.push(`Created PostCSS config file: ${path.basename(postcssConfigLocation)}`)
334
- }
335
- }
336
-
337
- if (messages.length > 0) {
338
- console.log()
339
- for (let message of messages) {
340
- console.log(message)
341
- }
342
- }
343
- }
344
-
345
- async function build() {
346
- let input = args['--input']
347
- let output = args['--output']
348
- let shouldWatch = args['--watch']
349
- let includePostCss = args['--postcss']
350
-
351
- // TODO: Deprecate this in future versions
352
- if (!input && args['_'][1]) {
353
- console.error('[deprecation] Running tailwindcss without -i, please provide an input file.')
354
- input = args['--input'] = args['_'][1]
355
- }
356
-
357
- if (input && !fs.existsSync((input = path.resolve(input)))) {
358
- console.error(`Specified input file ${args['--input']} does not exist.`)
359
- process.exit(9)
360
- }
361
-
362
- if (args['--config'] && !fs.existsSync((args['--config'] = path.resolve(args['--config'])))) {
363
- console.error(`Specified config file ${args['--config']} does not exist.`)
364
- process.exit(9)
365
- }
366
-
367
- let configPath = args['--config']
368
- ? args['--config']
369
- : ((defaultPath) => (fs.existsSync(defaultPath) ? defaultPath : null))(
370
- path.resolve('./tailwind.config.js')
371
- )
372
-
373
- async function loadPostCssPlugins() {
374
- let customPostCssPath = typeof args['--postcss'] === 'string' ? args['--postcss'] : undefined
375
- let { plugins: configPlugins } = customPostCssPath
376
- ? await (async () => {
377
- let file = path.resolve(customPostCssPath)
378
-
379
- // Implementation, see: https://unpkg.com/browse/postcss-load-config@3.0.1/src/index.js
380
- let { config = {} } = await cosmiconfig('postcss').load(file)
381
- if (typeof config === 'function') {
382
- config = config()
383
- } else {
384
- config = Object.assign({}, config)
385
- }
386
-
387
- if (!config.plugins) {
388
- config.plugins = []
389
- }
390
-
391
- return { plugins: loadPlugins(config, file) }
392
- })()
393
- : await postcssrc()
394
-
395
- let configPluginTailwindIdx = configPlugins.findIndex((plugin) => {
396
- if (typeof plugin === 'function' && plugin.name === 'tailwindcss') {
397
- return true
398
- }
399
-
400
- if (typeof plugin === 'object' && plugin !== null && plugin.postcssPlugin === 'tailwindcss') {
401
- return true
402
- }
403
-
404
- return false
405
- })
406
-
407
- let beforePlugins =
408
- configPluginTailwindIdx === -1 ? [] : configPlugins.slice(0, configPluginTailwindIdx)
409
- let afterPlugins =
410
- configPluginTailwindIdx === -1
411
- ? configPlugins
412
- : configPlugins.slice(configPluginTailwindIdx + 1)
413
-
414
- return [beforePlugins, afterPlugins]
415
- }
416
-
417
- function resolveConfig() {
418
- let config = configPath ? require(configPath) : {}
419
- let resolvedConfig = resolveConfigInternal(config)
420
-
421
- if (args['--purge']) {
422
- log.warn(['The `--purge` flag has been deprecated.', 'Please use `--content` instead.'])
423
- if (!args['--content']) {
424
- args['--content'] = ['--purge']
425
- }
426
- }
427
-
428
- if (args['--content']) {
429
- resolvedConfig.content = args['--content'].split(/(?<!{[^}]+),/)
430
- }
431
-
432
- return resolvedConfig
433
- }
434
-
435
- function extractContent(config) {
436
- return config.content.content.concat(config.content.safelist)
437
- }
438
-
439
- function extractFileGlobs(config) {
440
- return extractContent(config).filter((file) => {
441
- // Strings in this case are files / globs. If it is something else,
442
- // like an object it's probably a raw content object. But this object
443
- // is not watchable, so let's remove it.
444
- return typeof file === 'string'
445
- })
446
- }
447
-
448
- function extractRawContent(config) {
449
- return extractContent(config).filter((file) => {
450
- return typeof file === 'object' && file !== null
451
- })
452
- }
453
-
454
- function getChangedContent(config) {
455
- let changedContent = []
456
-
457
- // Resolve globs from the content config
458
- let globs = extractFileGlobs(config)
459
- let files = fastGlob.sync(globs)
460
-
461
- for (let file of files) {
462
- changedContent.push({
463
- content: fs.readFileSync(path.resolve(file), 'utf8'),
464
- extension: path.extname(file),
465
- })
466
- }
467
-
468
- // Resolve raw content in the tailwind config
469
- for (let { raw: content, extension = 'html' } of extractRawContent(config)) {
470
- changedContent.push({ content, extension })
471
- }
472
-
473
- return changedContent
474
- }
475
-
476
- async function buildOnce() {
477
- let config = resolveConfig()
478
- let changedContent = getChangedContent(config)
479
-
480
- let tailwindPlugin = () => {
481
- return {
482
- postcssPlugin: 'tailwindcss',
483
- Once(root, { result }) {
484
- tailwind(({ createContext }) => {
485
- return () => {
486
- return createContext(config, changedContent)
487
- }
488
- })(root, result)
489
- },
490
- }
491
- }
492
-
493
- tailwindPlugin.postcss = true
494
-
495
- let [beforePlugins, afterPlugins] = includePostCss ? await loadPostCssPlugins() : [[], []]
496
-
497
- let plugins = [
498
- ...beforePlugins,
499
- tailwindPlugin,
500
- !args['--minify'] && formatNodes,
501
- ...afterPlugins,
502
- !args['--no-autoprefixer'] &&
503
- (() => {
504
- // Try to load a local `autoprefixer` version first
505
- try {
506
- return require('autoprefixer')
507
- } catch {}
508
-
509
- return lazyAutoprefixer()
510
- })(),
511
- args['--minify'] &&
512
- (() => {
513
- let options = { preset: ['default', { cssDeclarationSorter: false }] }
514
-
515
- // Try to load a local `cssnano` version first
516
- try {
517
- return require('cssnano')
518
- } catch {}
519
-
520
- return lazyCssnano()(options)
521
- })(),
522
- ].filter(Boolean)
523
-
524
- let processor = postcss(plugins)
525
-
526
- function processCSS(css) {
527
- let start = process.hrtime.bigint()
528
- return Promise.resolve()
529
- .then(() => (output ? fs.promises.mkdir(path.dirname(output), { recursive: true }) : null))
530
- .then(() => processor.process(css, { from: input, to: output }))
531
- .then((result) => {
532
- if (!output) {
533
- return process.stdout.write(result.css)
534
- }
535
- return Promise.all(
536
- [
537
- fs.promises.writeFile(output, result.css, () => true),
538
- result.map && fs.writeFile(output + '.map', result.map.toString(), () => true),
539
- ].filter(Boolean)
540
- )
541
- })
542
- .then(() => {
543
- let end = process.hrtime.bigint()
544
- console.error()
545
- console.error('Done in', (end - start) / BigInt(1e6) + 'ms.')
546
- })
547
- }
548
-
549
- let css = input
550
- ? fs.readFileSync(path.resolve(input), 'utf8')
551
- : '@tailwind base; @tailwind components; @tailwind utilities'
552
- return processCSS(css)
553
- }
554
-
555
- let context = null
556
-
557
- async function startWatcher() {
558
- let changedContent = []
559
- let configDependencies = []
560
- let contextDependencies = new Set()
561
- let watcher = null
562
-
563
- function refreshConfig() {
564
- env.DEBUG && console.time('Module dependencies')
565
- for (let file of configDependencies) {
566
- delete require.cache[require.resolve(file)]
567
- }
568
-
569
- if (configPath) {
570
- configDependencies = getModuleDependencies(configPath).map(({ file }) => file)
571
-
572
- for (let dependency of configDependencies) {
573
- contextDependencies.add(dependency)
574
- }
575
- }
576
- env.DEBUG && console.timeEnd('Module dependencies')
577
-
578
- return resolveConfig()
579
- }
580
-
581
- let [beforePlugins, afterPlugins] = includePostCss ? await loadPostCssPlugins() : [[], []]
582
-
583
- let plugins = [
584
- ...beforePlugins,
585
- '__TAILWIND_PLUGIN_POSITION__',
586
- !args['--minify'] && formatNodes,
587
- ...afterPlugins,
588
- !args['--no-autoprefixer'] &&
589
- (() => {
590
- // Try to load a local `autoprefixer` version first
591
- try {
592
- return require('autoprefixer')
593
- } catch {}
594
-
595
- return lazyAutoprefixer()
596
- })(),
597
- args['--minify'] &&
598
- (() => {
599
- let options = { preset: ['default', { cssDeclarationSorter: false }] }
600
-
601
- // Try to load a local `cssnano` version first
602
- try {
603
- return require('cssnano')
604
- } catch {}
605
-
606
- return lazyCssnano()(options)
607
- })(),
608
- ].filter(Boolean)
609
-
610
- async function rebuild(config) {
611
- env.DEBUG && console.time('Finished in')
612
-
613
- let tailwindPlugin = () => {
614
- return {
615
- postcssPlugin: 'tailwindcss',
616
- Once(root, { result }) {
617
- env.DEBUG && console.time('Compiling CSS')
618
- tailwind(({ createContext }) => {
619
- console.error()
620
- console.error('Rebuilding...')
621
-
622
- return () => {
623
- if (context !== null) {
624
- context.changedContent = changedContent.splice(0)
625
- return context
626
- }
627
-
628
- env.DEBUG && console.time('Creating context')
629
- context = createContext(config, changedContent.splice(0))
630
- env.DEBUG && console.timeEnd('Creating context')
631
- return context
632
- }
633
- })(root, result)
634
- env.DEBUG && console.timeEnd('Compiling CSS')
635
- },
636
- }
637
- }
638
-
639
- tailwindPlugin.postcss = true
640
-
641
- let tailwindPluginIdx = plugins.indexOf('__TAILWIND_PLUGIN_POSITION__')
642
- let copy = plugins.slice()
643
- copy.splice(tailwindPluginIdx, 1, tailwindPlugin)
644
- let processor = postcss(copy)
645
-
646
- function processCSS(css) {
647
- let start = process.hrtime.bigint()
648
- return Promise.resolve()
649
- .then(() =>
650
- output ? fs.promises.mkdir(path.dirname(output), { recursive: true }) : null
651
- )
652
- .then(() => processor.process(css, { from: input, to: output }))
653
- .then(async (result) => {
654
- for (let message of result.messages) {
655
- if (message.type === 'dependency') {
656
- contextDependencies.add(message.file)
657
- }
658
- }
659
- watcher.add([...contextDependencies])
660
-
661
- if (!output) {
662
- return process.stdout.write(result.css)
663
- }
664
-
665
- await Promise.all(
666
- [
667
- fs.promises.writeFile(output, result.css, () => true),
668
- result.map && fs.writeFile(output + '.map', result.map.toString(), () => true),
669
- ].filter(Boolean)
670
- )
671
- })
672
- .then(() => {
673
- let end = process.hrtime.bigint()
674
- console.error('Done in', (end - start) / BigInt(1e6) + 'ms.')
675
- })
676
- .catch((err) => {
677
- if (err.name === 'CssSyntaxError') {
678
- console.error(err.toString())
679
- } else {
680
- console.error(err)
681
- }
682
- })
683
- }
684
-
685
- let css = input
686
- ? fs.readFileSync(path.resolve(input), 'utf8')
687
- : '@tailwind base; @tailwind components; @tailwind utilities'
688
- let result = await processCSS(css)
689
- env.DEBUG && console.timeEnd('Finished in')
690
- return result
691
- }
692
-
693
- let config = refreshConfig(configPath)
694
-
695
- if (input) {
696
- contextDependencies.add(path.resolve(input))
697
- }
698
-
699
- watcher = chokidar.watch([...contextDependencies, ...extractFileGlobs(config)], {
700
- ignoreInitial: true,
701
- })
702
-
703
- let chain = Promise.resolve()
704
-
705
- watcher.on('change', async (file) => {
706
- if (contextDependencies.has(file)) {
707
- env.DEBUG && console.time('Resolve config')
708
- context = null
709
- config = refreshConfig(configPath)
710
- env.DEBUG && console.timeEnd('Resolve config')
711
-
712
- env.DEBUG && console.time('Watch new files')
713
- let globs = extractFileGlobs(config)
714
- watcher.add(configDependencies)
715
- watcher.add(globs)
716
- env.DEBUG && console.timeEnd('Watch new files')
717
-
718
- chain = chain.then(async () => {
719
- changedContent.push(...getChangedContent(config))
720
- await rebuild(config)
721
- })
722
- } else {
723
- chain = chain.then(async () => {
724
- changedContent.push({
725
- content: fs.readFileSync(path.resolve(file), 'utf8'),
726
- extension: path.extname(file),
727
- })
728
-
729
- await rebuild(config)
730
- })
731
- }
732
- })
733
-
734
- watcher.on('add', async (file) => {
735
- chain = chain.then(async () => {
736
- changedContent.push({
737
- content: fs.readFileSync(path.resolve(file), 'utf8'),
738
- extension: path.extname(file),
739
- })
740
-
741
- await rebuild(config)
742
- })
743
- })
744
-
745
- chain = chain.then(() => {
746
- changedContent.push(...getChangedContent(config))
747
- return rebuild(config)
748
- })
749
- }
750
-
751
- if (shouldWatch) {
752
- /* Abort the watcher if stdin is closed to avoid zombie processes */
753
- process.stdin.on('end', () => process.exit(0))
754
- process.stdin.resume()
755
- startWatcher()
756
- } else {
757
- buildOnce()
758
- }
759
- }
234
+ run(args, configs)
@@ -1 +1 @@
1
- export default ["preflight","container","accessibility","pointerEvents","visibility","position","inset","isolation","zIndex","order","gridColumn","gridColumnStart","gridColumnEnd","gridRow","gridRowStart","gridRowEnd","float","clear","margin","boxSizing","display","aspectRatio","height","maxHeight","minHeight","width","minWidth","maxWidth","flex","flexShrink","flexGrow","tableLayout","borderCollapse","transformOrigin","translate","rotate","skew","scale","transform","animation","cursor","userSelect","resize","listStylePosition","listStyleType","appearance","columns","gridAutoColumns","gridAutoFlow","gridAutoRows","gridTemplateColumns","gridTemplateRows","flexDirection","flexWrap","placeContent","placeItems","alignContent","alignItems","justifyContent","justifyItems","gap","space","divideWidth","divideStyle","divideColor","divideOpacity","placeSelf","alignSelf","justifySelf","overflow","overscrollBehavior","scrollBehavior","textOverflow","whitespace","wordBreak","borderRadius","borderWidth","borderStyle","borderColor","borderOpacity","backgroundColor","backgroundOpacity","backgroundImage","gradientColorStops","boxDecorationBreak","backgroundSize","backgroundAttachment","backgroundClip","backgroundPosition","backgroundRepeat","backgroundOrigin","fill","stroke","strokeWidth","objectFit","objectPosition","padding","textAlign","textIndent","verticalAlign","fontFamily","fontSize","fontWeight","textTransform","fontStyle","fontVariantNumeric","lineHeight","letterSpacing","textColor","textOpacity","textDecoration","fontSmoothing","placeholderColor","placeholderOpacity","caretColor","accentColor","opacity","backgroundBlendMode","mixBlendMode","boxShadow","outline","ringWidth","ringColor","ringOpacity","ringOffsetWidth","ringOffsetColor","blur","brightness","contrast","dropShadow","grayscale","hueRotate","invert","saturate","sepia","filter","backdropBlur","backdropBrightness","backdropContrast","backdropGrayscale","backdropHueRotate","backdropInvert","backdropOpacity","backdropSaturate","backdropSepia","backdropFilter","transitionProperty","transitionDelay","transitionDuration","transitionTimingFunction","willChange","content"]
1
+ export default ["preflight","container","accessibility","pointerEvents","visibility","position","inset","isolation","zIndex","order","gridColumn","gridColumnStart","gridColumnEnd","gridRow","gridRowStart","gridRowEnd","float","clear","margin","boxSizing","display","aspectRatio","height","maxHeight","minHeight","width","minWidth","maxWidth","flex","flexShrink","flexGrow","flexBasis","tableLayout","borderCollapse","borderSpacing","transformOrigin","translate","rotate","skew","scale","transform","animation","cursor","touchAction","userSelect","resize","scrollSnapType","scrollSnapAlign","scrollSnapStop","scrollMargin","scrollPadding","listStylePosition","listStyleType","appearance","columns","breakBefore","breakInside","breakAfter","gridAutoColumns","gridAutoFlow","gridAutoRows","gridTemplateColumns","gridTemplateRows","flexDirection","flexWrap","placeContent","placeItems","alignContent","alignItems","justifyContent","justifyItems","gap","space","divideWidth","divideStyle","divideColor","divideOpacity","placeSelf","alignSelf","justifySelf","overflow","overscrollBehavior","scrollBehavior","textOverflow","whitespace","wordBreak","borderRadius","borderWidth","borderStyle","borderColor","borderOpacity","backgroundColor","backgroundOpacity","backgroundImage","gradientColorStops","boxDecorationBreak","backgroundSize","backgroundAttachment","backgroundClip","backgroundPosition","backgroundRepeat","backgroundOrigin","fill","stroke","strokeWidth","objectFit","objectPosition","padding","textAlign","textIndent","verticalAlign","fontFamily","fontSize","fontWeight","textTransform","fontStyle","fontVariantNumeric","lineHeight","letterSpacing","textColor","textOpacity","textDecoration","textDecorationColor","textDecorationStyle","textDecorationThickness","textUnderlineOffset","fontSmoothing","placeholderColor","placeholderOpacity","caretColor","accentColor","opacity","backgroundBlendMode","mixBlendMode","boxShadow","boxShadowColor","outlineStyle","outlineWidth","outlineOffset","outlineColor","ringWidth","ringColor","ringOpacity","ringOffsetWidth","ringOffsetColor","blur","brightness","contrast","dropShadow","grayscale","hueRotate","invert","saturate","sepia","filter","backdropBlur","backdropBrightness","backdropContrast","backdropGrayscale","backdropHueRotate","backdropInvert","backdropOpacity","backdropSaturate","backdropSepia","backdropFilter","transitionProperty","transitionDelay","transitionDuration","transitionTimingFunction","willChange","content"]