tailwindcss 0.0.0-insiders.fe08e91 → 0.0.0-oxide.956419c

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