tailwindcss 0.0.0-insiders.deefbf5 → 0.0.0-insiders.df96ea5

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