tailwindcss 0.0.0-insiders.ea139f2 → 0.0.0-insiders.ea4e1cd

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 (236) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +15 -7
  3. package/colors.d.ts +3 -0
  4. package/colors.js +2 -1
  5. package/defaultConfig.d.ts +3 -0
  6. package/defaultConfig.js +2 -1
  7. package/defaultTheme.d.ts +4 -0
  8. package/defaultTheme.js +2 -1
  9. package/lib/cli/build/deps.js +62 -0
  10. package/lib/cli/build/index.js +54 -0
  11. package/lib/cli/build/plugin.js +378 -0
  12. package/lib/cli/build/utils.js +88 -0
  13. package/lib/cli/build/watching.js +182 -0
  14. package/lib/cli/help/index.js +73 -0
  15. package/lib/cli/index.js +230 -0
  16. package/lib/cli/init/index.js +63 -0
  17. package/lib/cli-peer-dependencies.js +28 -7
  18. package/lib/cli.js +4 -703
  19. package/lib/corePluginList.js +12 -3
  20. package/lib/corePlugins.js +2373 -1863
  21. package/lib/css/preflight.css +10 -8
  22. package/lib/featureFlags.js +49 -26
  23. package/lib/index.js +1 -31
  24. package/lib/lib/cacheInvalidation.js +92 -0
  25. package/lib/lib/collapseAdjacentRules.js +30 -10
  26. package/lib/lib/collapseDuplicateDeclarations.js +60 -4
  27. package/lib/lib/content.js +181 -0
  28. package/lib/lib/defaultExtractor.js +243 -0
  29. package/lib/lib/detectNesting.js +21 -10
  30. package/lib/lib/evaluateTailwindFunctions.js +115 -50
  31. package/lib/lib/expandApplyAtRules.js +467 -161
  32. package/lib/lib/expandTailwindAtRules.js +160 -133
  33. package/lib/lib/findAtConfigPath.js +46 -0
  34. package/lib/lib/generateRules.js +553 -200
  35. package/lib/lib/getModuleDependencies.js +88 -37
  36. package/lib/lib/load-config.js +42 -0
  37. package/lib/lib/normalizeTailwindDirectives.js +46 -33
  38. package/lib/lib/offsets.js +306 -0
  39. package/lib/lib/partitionApplyAtRules.js +58 -0
  40. package/lib/lib/regex.js +74 -0
  41. package/lib/lib/remap-bitfield.js +89 -0
  42. package/lib/lib/resolveDefaultsAtRules.js +98 -58
  43. package/lib/lib/setupContextUtils.js +773 -321
  44. package/lib/lib/setupTrackingContext.js +70 -75
  45. package/lib/lib/sharedState.js +78 -10
  46. package/lib/lib/substituteScreenAtRules.js +14 -10
  47. package/lib/oxide/cli/build/deps.js +89 -0
  48. package/lib/oxide/cli/build/index.js +53 -0
  49. package/lib/oxide/cli/build/plugin.js +375 -0
  50. package/lib/oxide/cli/build/utils.js +87 -0
  51. package/lib/oxide/cli/build/watching.js +179 -0
  52. package/lib/oxide/cli/help/index.js +72 -0
  53. package/lib/oxide/cli/index.js +214 -0
  54. package/lib/oxide/cli/init/index.js +52 -0
  55. package/lib/oxide/cli.js +5 -0
  56. package/lib/oxide/postcss-plugin.js +2 -0
  57. package/lib/plugin.js +98 -0
  58. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  59. package/lib/postcss-plugins/nesting/index.js +21 -0
  60. package/lib/postcss-plugins/nesting/plugin.js +89 -0
  61. package/lib/processTailwindFeatures.js +39 -26
  62. package/lib/public/colors.js +272 -246
  63. package/lib/public/create-plugin.js +9 -5
  64. package/lib/public/default-config.js +10 -6
  65. package/lib/public/default-theme.js +10 -6
  66. package/lib/public/load-config.js +12 -0
  67. package/lib/public/resolve-config.js +11 -6
  68. package/lib/util/applyImportantSelector.js +36 -0
  69. package/lib/util/bigSign.js +6 -1
  70. package/lib/util/buildMediaQuery.js +13 -6
  71. package/lib/util/cloneDeep.js +9 -6
  72. package/lib/util/cloneNodes.js +23 -3
  73. package/lib/util/color.js +70 -38
  74. package/lib/util/colorNames.js +752 -0
  75. package/lib/util/configurePlugins.js +7 -2
  76. package/lib/util/createPlugin.js +8 -6
  77. package/lib/util/createUtilityPlugin.js +16 -16
  78. package/lib/util/dataTypes.js +173 -108
  79. package/lib/util/defaults.js +14 -3
  80. package/lib/util/escapeClassName.js +13 -8
  81. package/lib/util/escapeCommas.js +7 -2
  82. package/lib/util/flattenColorPalette.js +11 -12
  83. package/lib/util/formatVariantSelector.js +228 -151
  84. package/lib/util/getAllConfigs.js +33 -12
  85. package/lib/util/hashConfig.js +9 -4
  86. package/lib/util/isKeyframeRule.js +7 -2
  87. package/lib/util/isPlainObject.js +7 -2
  88. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
  89. package/lib/util/log.js +27 -13
  90. package/lib/util/nameClass.js +27 -10
  91. package/lib/util/negateValue.js +25 -8
  92. package/lib/util/normalizeConfig.js +139 -65
  93. package/lib/util/normalizeScreens.js +131 -11
  94. package/lib/util/parseAnimationValue.js +44 -40
  95. package/lib/util/parseBoxShadowValue.js +34 -23
  96. package/lib/util/parseDependency.js +39 -55
  97. package/lib/util/parseGlob.js +36 -0
  98. package/lib/util/parseObjectStyles.js +15 -10
  99. package/lib/util/pluginUtils.js +159 -69
  100. package/lib/util/prefixSelector.js +30 -12
  101. package/lib/util/pseudoElements.js +229 -0
  102. package/lib/util/removeAlphaVariables.js +31 -0
  103. package/lib/util/resolveConfig.js +97 -75
  104. package/lib/util/resolveConfigPath.js +30 -12
  105. package/lib/util/responsive.js +11 -6
  106. package/lib/util/splitAtTopLevelOnly.js +51 -0
  107. package/lib/util/tap.js +6 -1
  108. package/lib/util/toColorValue.js +7 -3
  109. package/lib/util/toPath.js +26 -3
  110. package/lib/util/transformThemeValue.js +40 -30
  111. package/lib/util/validateConfig.js +37 -0
  112. package/lib/util/validateFormalSyntax.js +26 -0
  113. package/lib/util/withAlphaVariable.js +27 -15
  114. package/loadConfig.d.ts +4 -0
  115. package/loadConfig.js +2 -0
  116. package/nesting/index.js +2 -12
  117. package/package.json +66 -57
  118. package/peers/index.js +75964 -55560
  119. package/plugin.d.ts +11 -0
  120. package/plugin.js +2 -1
  121. package/resolveConfig.d.ts +12 -0
  122. package/resolveConfig.js +2 -1
  123. package/scripts/generate-types.js +105 -0
  124. package/scripts/release-channel.js +18 -0
  125. package/scripts/release-notes.js +21 -0
  126. package/scripts/swap-engines.js +40 -0
  127. package/scripts/type-utils.js +27 -0
  128. package/src/cli/build/deps.js +56 -0
  129. package/src/cli/build/index.js +49 -0
  130. package/src/cli/build/plugin.js +444 -0
  131. package/src/cli/build/utils.js +76 -0
  132. package/src/cli/build/watching.js +229 -0
  133. package/src/cli/help/index.js +70 -0
  134. package/src/cli/index.js +216 -0
  135. package/src/cli/init/index.js +79 -0
  136. package/src/cli-peer-dependencies.js +7 -1
  137. package/src/cli.js +4 -765
  138. package/src/corePluginList.js +1 -1
  139. package/src/corePlugins.js +786 -306
  140. package/src/css/preflight.css +10 -8
  141. package/src/featureFlags.js +21 -5
  142. package/src/index.js +1 -34
  143. package/src/lib/cacheInvalidation.js +52 -0
  144. package/src/lib/collapseAdjacentRules.js +21 -2
  145. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  146. package/src/lib/content.js +208 -0
  147. package/src/lib/defaultExtractor.js +217 -0
  148. package/src/lib/detectNesting.js +9 -1
  149. package/src/lib/evaluateTailwindFunctions.js +79 -8
  150. package/src/lib/expandApplyAtRules.js +515 -153
  151. package/src/lib/expandTailwindAtRules.js +115 -86
  152. package/src/lib/findAtConfigPath.js +48 -0
  153. package/src/lib/generateRules.js +545 -147
  154. package/src/lib/getModuleDependencies.js +70 -30
  155. package/src/lib/load-config.ts +31 -0
  156. package/src/lib/normalizeTailwindDirectives.js +7 -1
  157. package/src/lib/offsets.js +373 -0
  158. package/src/lib/partitionApplyAtRules.js +52 -0
  159. package/src/lib/regex.js +74 -0
  160. package/src/lib/remap-bitfield.js +82 -0
  161. package/src/lib/resolveDefaultsAtRules.js +59 -17
  162. package/src/lib/setupContextUtils.js +701 -175
  163. package/src/lib/setupTrackingContext.js +51 -62
  164. package/src/lib/sharedState.js +58 -7
  165. package/src/oxide/cli/build/deps.ts +91 -0
  166. package/src/oxide/cli/build/index.ts +47 -0
  167. package/src/oxide/cli/build/plugin.ts +442 -0
  168. package/src/oxide/cli/build/utils.ts +74 -0
  169. package/src/oxide/cli/build/watching.ts +225 -0
  170. package/src/oxide/cli/help/index.ts +69 -0
  171. package/src/oxide/cli/index.ts +204 -0
  172. package/src/oxide/cli/init/index.ts +59 -0
  173. package/src/oxide/cli.ts +1 -0
  174. package/src/oxide/postcss-plugin.ts +1 -0
  175. package/src/plugin.js +107 -0
  176. package/src/postcss-plugins/nesting/README.md +42 -0
  177. package/src/postcss-plugins/nesting/index.js +13 -0
  178. package/src/postcss-plugins/nesting/plugin.js +80 -0
  179. package/src/processTailwindFeatures.js +12 -2
  180. package/src/public/colors.js +22 -0
  181. package/src/public/default-config.js +1 -1
  182. package/src/public/default-theme.js +2 -2
  183. package/src/public/load-config.js +2 -0
  184. package/src/util/applyImportantSelector.js +27 -0
  185. package/src/util/buildMediaQuery.js +5 -3
  186. package/src/util/cloneNodes.js +19 -2
  187. package/src/util/color.js +44 -12
  188. package/src/util/colorNames.js +150 -0
  189. package/src/util/dataTypes.js +51 -16
  190. package/src/util/defaults.js +6 -0
  191. package/src/util/formatVariantSelector.js +264 -144
  192. package/src/util/getAllConfigs.js +21 -2
  193. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  194. package/src/util/log.js +11 -7
  195. package/src/util/nameClass.js +4 -0
  196. package/src/util/negateValue.js +11 -3
  197. package/src/util/normalizeConfig.js +57 -5
  198. package/src/util/normalizeScreens.js +105 -7
  199. package/src/util/parseBoxShadowValue.js +4 -3
  200. package/src/util/parseDependency.js +37 -42
  201. package/src/util/parseGlob.js +24 -0
  202. package/src/util/pluginUtils.js +123 -24
  203. package/src/util/prefixSelector.js +30 -10
  204. package/src/util/pseudoElements.js +170 -0
  205. package/src/util/removeAlphaVariables.js +24 -0
  206. package/src/util/resolveConfig.js +74 -26
  207. package/src/util/resolveConfigPath.js +12 -1
  208. package/src/util/splitAtTopLevelOnly.js +52 -0
  209. package/src/util/toPath.js +23 -1
  210. package/src/util/transformThemeValue.js +13 -3
  211. package/src/util/validateConfig.js +26 -0
  212. package/src/util/validateFormalSyntax.js +34 -0
  213. package/src/util/withAlphaVariable.js +1 -1
  214. package/stubs/.gitignore +1 -0
  215. package/stubs/.prettierrc.json +6 -0
  216. package/stubs/{defaultConfig.stub.js → config.full.js} +206 -166
  217. package/stubs/postcss.config.js +6 -0
  218. package/stubs/tailwind.config.cjs +2 -0
  219. package/stubs/tailwind.config.js +2 -0
  220. package/stubs/tailwind.config.ts +3 -0
  221. package/types/config.d.ts +368 -0
  222. package/types/generated/.gitkeep +0 -0
  223. package/types/generated/colors.d.ts +298 -0
  224. package/types/generated/corePluginList.d.ts +1 -0
  225. package/types/generated/default-theme.d.ts +371 -0
  226. package/types/index.d.ts +7 -0
  227. package/CHANGELOG.md +0 -1843
  228. package/lib/constants.js +0 -37
  229. package/lib/lib/setupWatchingContext.js +0 -288
  230. package/nesting/plugin.js +0 -41
  231. package/scripts/install-integrations.js +0 -27
  232. package/scripts/rebuildFixtures.js +0 -68
  233. package/src/constants.js +0 -17
  234. package/src/lib/setupWatchingContext.js +0 -311
  235. /package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -0
  236. /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
package/src/cli.js CHANGED
@@ -1,768 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { postcss, lazyCssnano, lazyAutoprefixer } from '../peers/index.js'
4
-
5
- import chokidar from 'chokidar'
6
- import path from 'path'
7
- import arg from 'arg'
8
- import fs from 'fs'
9
- import postcssrc from 'postcss-load-config'
10
- import { 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 && process.env.DEBUG !== '0',
22
- }
23
-
24
- // ---
25
-
26
- function indentRecursive(node, indent = 0) {
27
- node.each &&
28
- node.each((child, i) => {
29
- if (!child.raws.before || !child.raws.before.trim() || child.raws.before.includes('\n')) {
30
- child.raws.before = `\n${node.type !== 'rule' && i > 0 ? '\n' : ''}${' '.repeat(indent)}`
31
- }
32
- child.raws.after = `\n${' '.repeat(indent)}`
33
- indentRecursive(child, indent + 1)
34
- })
35
- }
36
-
37
- function formatNodes(root) {
38
- indentRecursive(root)
39
- if (root.first) {
40
- root.first.raws.before = ''
41
- }
42
- }
43
-
44
- 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('purge-flag-deprecated', [
424
- 'The `--purge` flag has been deprecated.',
425
- 'Please use `--content` instead.',
426
- ])
427
- if (!args['--content']) {
428
- args['--content'] = args['--purge']
429
- }
430
- }
431
-
432
- if (args['--content']) {
433
- resolvedConfig.content.files = args['--content'].split(/(?<!{[^}]+),/)
434
- }
435
-
436
- return resolvedConfig
437
- }
438
-
439
- function extractFileGlobs(config) {
440
- return config.content.files
441
- .filter((file) => {
442
- // Strings in this case are files / globs. If it is something else,
443
- // like an object it's probably a raw content object. But this object
444
- // is not watchable, so let's remove it.
445
- return typeof file === 'string'
446
- })
447
- .map((glob) => normalizePath(glob))
448
- }
449
-
450
- function extractRawContent(config) {
451
- return config.content.files.filter((file) => {
452
- return typeof file === 'object' && file !== null
453
- })
454
- }
455
-
456
- function getChangedContent(config) {
457
- let changedContent = []
458
-
459
- // Resolve globs from the content config
460
- let globs = extractFileGlobs(config)
461
- let files = fastGlob.sync(globs)
462
-
463
- for (let file of files) {
464
- changedContent.push({
465
- content: fs.readFileSync(path.resolve(file), 'utf8'),
466
- extension: path.extname(file).slice(1),
467
- })
468
- }
469
-
470
- // Resolve raw content in the tailwind config
471
- for (let { raw: content, extension = 'html' } of extractRawContent(config)) {
472
- changedContent.push({ content, extension })
473
- }
474
-
475
- return changedContent
476
- }
477
-
478
- async function buildOnce() {
479
- let config = resolveConfig()
480
- let changedContent = getChangedContent(config)
481
-
482
- let tailwindPlugin = () => {
483
- return {
484
- postcssPlugin: 'tailwindcss',
485
- Once(root, { result }) {
486
- tailwind(({ createContext }) => {
487
- return () => {
488
- return createContext(config, changedContent)
489
- }
490
- })(root, result)
491
- },
492
- }
493
- }
494
-
495
- tailwindPlugin.postcss = true
496
-
497
- let [beforePlugins, afterPlugins] = includePostCss ? await loadPostCssPlugins() : [[], []]
498
-
499
- let plugins = [
500
- ...beforePlugins,
501
- tailwindPlugin,
502
- !args['--minify'] && formatNodes,
503
- ...afterPlugins,
504
- !args['--no-autoprefixer'] &&
505
- (() => {
506
- // Try to load a local `autoprefixer` version first
507
- try {
508
- return require('autoprefixer')
509
- } catch {}
510
-
511
- return lazyAutoprefixer()
512
- })(),
513
- args['--minify'] &&
514
- (() => {
515
- let options = { preset: ['default', { cssDeclarationSorter: false }] }
516
-
517
- // Try to load a local `cssnano` version first
518
- try {
519
- return require('cssnano')
520
- } catch {}
521
-
522
- return lazyCssnano()(options)
523
- })(),
524
- ].filter(Boolean)
525
-
526
- let processor = postcss(plugins)
527
-
528
- function processCSS(css) {
529
- let start = process.hrtime.bigint()
530
- return Promise.resolve()
531
- .then(() => (output ? fs.promises.mkdir(path.dirname(output), { recursive: true }) : null))
532
- .then(() => processor.process(css, { from: input, to: output }))
533
- .then((result) => {
534
- if (!output) {
535
- return process.stdout.write(result.css)
536
- }
537
- return Promise.all(
538
- [
539
- fs.promises.writeFile(output, result.css, () => true),
540
- result.map && fs.writeFile(output + '.map', result.map.toString(), () => true),
541
- ].filter(Boolean)
542
- )
543
- })
544
- .then(() => {
545
- let end = process.hrtime.bigint()
546
- console.error()
547
- console.error('Done in', (end - start) / BigInt(1e6) + 'ms.')
548
- })
549
- }
550
-
551
- let css = input
552
- ? fs.readFileSync(path.resolve(input), 'utf8')
553
- : '@tailwind base; @tailwind components; @tailwind utilities'
554
- return processCSS(css)
555
- }
556
-
557
- let context = null
558
-
559
- async function startWatcher() {
560
- let changedContent = []
561
- let configDependencies = []
562
- let contextDependencies = new Set()
563
- let watcher = null
564
-
565
- function refreshConfig() {
566
- env.DEBUG && console.time('Module dependencies')
567
- for (let file of configDependencies) {
568
- delete require.cache[require.resolve(file)]
569
- }
570
-
571
- if (configPath) {
572
- configDependencies = getModuleDependencies(configPath).map(({ file }) => file)
573
-
574
- for (let dependency of configDependencies) {
575
- contextDependencies.add(dependency)
576
- }
577
- }
578
- env.DEBUG && console.timeEnd('Module dependencies')
579
-
580
- return resolveConfig()
581
- }
582
-
583
- let [beforePlugins, afterPlugins] = includePostCss ? await loadPostCssPlugins() : [[], []]
584
-
585
- let plugins = [
586
- ...beforePlugins,
587
- '__TAILWIND_PLUGIN_POSITION__',
588
- !args['--minify'] && formatNodes,
589
- ...afterPlugins,
590
- !args['--no-autoprefixer'] &&
591
- (() => {
592
- // Try to load a local `autoprefixer` version first
593
- try {
594
- return require('autoprefixer')
595
- } catch {}
596
-
597
- return lazyAutoprefixer()
598
- })(),
599
- args['--minify'] &&
600
- (() => {
601
- let options = { preset: ['default', { cssDeclarationSorter: false }] }
602
-
603
- // Try to load a local `cssnano` version first
604
- try {
605
- return require('cssnano')
606
- } catch {}
607
-
608
- return lazyCssnano()(options)
609
- })(),
610
- ].filter(Boolean)
611
-
612
- async function rebuild(config) {
613
- env.DEBUG && console.time('Finished in')
614
-
615
- let tailwindPlugin = () => {
616
- return {
617
- postcssPlugin: 'tailwindcss',
618
- Once(root, { result }) {
619
- env.DEBUG && console.time('Compiling CSS')
620
- tailwind(({ createContext }) => {
621
- console.error()
622
- console.error('Rebuilding...')
623
-
624
- return () => {
625
- if (context !== null) {
626
- context.changedContent = changedContent.splice(0)
627
- return context
628
- }
629
-
630
- env.DEBUG && console.time('Creating context')
631
- context = createContext(config, changedContent.splice(0))
632
- env.DEBUG && console.timeEnd('Creating context')
633
- return context
634
- }
635
- })(root, result)
636
- env.DEBUG && console.timeEnd('Compiling CSS')
637
- },
638
- }
639
- }
640
-
641
- tailwindPlugin.postcss = true
642
-
643
- let tailwindPluginIdx = plugins.indexOf('__TAILWIND_PLUGIN_POSITION__')
644
- let copy = plugins.slice()
645
- copy.splice(tailwindPluginIdx, 1, tailwindPlugin)
646
- let processor = postcss(copy)
647
-
648
- function processCSS(css) {
649
- let start = process.hrtime.bigint()
650
- return Promise.resolve()
651
- .then(() =>
652
- output ? fs.promises.mkdir(path.dirname(output), { recursive: true }) : null
653
- )
654
- .then(() => processor.process(css, { from: input, to: output }))
655
- .then(async (result) => {
656
- for (let message of result.messages) {
657
- if (message.type === 'dependency') {
658
- contextDependencies.add(message.file)
659
- }
660
- }
661
- watcher.add([...contextDependencies])
662
-
663
- if (!output) {
664
- return process.stdout.write(result.css)
665
- }
666
-
667
- await Promise.all(
668
- [
669
- fs.promises.writeFile(output, result.css, () => true),
670
- result.map && fs.writeFile(output + '.map', result.map.toString(), () => true),
671
- ].filter(Boolean)
672
- )
673
- })
674
- .then(() => {
675
- let end = process.hrtime.bigint()
676
- console.error('Done in', (end - start) / BigInt(1e6) + 'ms.')
677
- })
678
- .catch((err) => {
679
- if (err.name === 'CssSyntaxError') {
680
- console.error(err.toString())
681
- } else {
682
- console.error(err)
683
- }
684
- })
685
- }
686
-
687
- let css = input
688
- ? fs.readFileSync(path.resolve(input), 'utf8')
689
- : '@tailwind base; @tailwind components; @tailwind utilities'
690
- let result = await processCSS(css)
691
- env.DEBUG && console.timeEnd('Finished in')
692
- return result
693
- }
694
-
695
- let config = refreshConfig(configPath)
696
-
697
- if (input) {
698
- contextDependencies.add(path.resolve(input))
699
- }
700
-
701
- watcher = chokidar.watch([...contextDependencies, ...extractFileGlobs(config)], {
702
- ignoreInitial: true,
703
- awaitWriteFinish:
704
- process.platform === 'win32'
705
- ? {
706
- stabilityThreshold: 50,
707
- pollInterval: 10,
708
- }
709
- : false,
710
- })
711
-
712
- let chain = Promise.resolve()
713
-
714
- watcher.on('change', async (file) => {
715
- if (contextDependencies.has(file)) {
716
- env.DEBUG && console.time('Resolve config')
717
- context = null
718
- config = refreshConfig(configPath)
719
- env.DEBUG && console.timeEnd('Resolve config')
720
-
721
- env.DEBUG && console.time('Watch new files')
722
- let globs = extractFileGlobs(config)
723
- watcher.add(configDependencies)
724
- watcher.add(globs)
725
- env.DEBUG && console.timeEnd('Watch new files')
726
-
727
- chain = chain.then(async () => {
728
- changedContent.push(...getChangedContent(config))
729
- await rebuild(config)
730
- })
731
- } else {
732
- chain = chain.then(async () => {
733
- changedContent.push({
734
- content: fs.readFileSync(path.resolve(file), 'utf8'),
735
- extension: path.extname(file).slice(1),
736
- })
737
-
738
- await rebuild(config)
739
- })
740
- }
741
- })
742
-
743
- watcher.on('add', async (file) => {
744
- chain = chain.then(async () => {
745
- changedContent.push({
746
- content: fs.readFileSync(path.resolve(file), 'utf8'),
747
- extension: path.extname(file).slice(1),
748
- })
749
-
750
- await rebuild(config)
751
- })
752
- })
753
-
754
- chain = chain.then(() => {
755
- changedContent.push(...getChangedContent(config))
756
- return rebuild(config)
757
- })
758
- }
759
-
760
- if (shouldWatch) {
761
- /* Abort the watcher if stdin is closed to avoid zombie processes */
762
- process.stdin.on('end', () => process.exit(0))
763
- process.stdin.resume()
764
- startWatcher()
765
- } else {
766
- buildOnce()
767
- }
3
+ if (__OXIDE__) {
4
+ module.exports = require('./oxide/cli')
5
+ } else {
6
+ module.exports = require('./cli/index')
768
7
  }