tailwindcss 0.0.0-insiders.f4635e0 → 0.0.0-insiders.f4a2ccd

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