tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.ca7b10e

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