tailwindcss 0.0.0-insiders.bb4f5da → 0.0.0-insiders.bbc2f3f

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