tailwindcss 3.1.8 → 3.2.0

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 (112) hide show
  1. package/README.md +6 -5
  2. package/lib/cli/build/deps.js +54 -0
  3. package/lib/cli/build/index.js +44 -0
  4. package/lib/cli/build/plugin.js +335 -0
  5. package/lib/cli/build/utils.js +78 -0
  6. package/lib/cli/build/watching.js +113 -0
  7. package/lib/cli/help/index.js +71 -0
  8. package/lib/cli/index.js +18 -0
  9. package/lib/cli/init/index.js +46 -0
  10. package/lib/cli/shared.js +12 -0
  11. package/lib/cli.js +11 -590
  12. package/lib/corePlugins.js +332 -108
  13. package/lib/css/preflight.css +5 -0
  14. package/lib/featureFlags.js +7 -4
  15. package/lib/index.js +6 -1
  16. package/lib/lib/content.js +167 -0
  17. package/lib/lib/defaultExtractor.js +15 -10
  18. package/lib/lib/detectNesting.js +2 -2
  19. package/lib/lib/evaluateTailwindFunctions.js +17 -1
  20. package/lib/lib/expandApplyAtRules.js +66 -37
  21. package/lib/lib/expandTailwindAtRules.js +10 -42
  22. package/lib/lib/findAtConfigPath.js +44 -0
  23. package/lib/lib/generateRules.js +180 -93
  24. package/lib/lib/normalizeTailwindDirectives.js +1 -1
  25. package/lib/lib/offsets.js +217 -0
  26. package/lib/lib/regex.js +1 -1
  27. package/lib/lib/setupContextUtils.js +339 -100
  28. package/lib/lib/setupTrackingContext.js +5 -39
  29. package/lib/lib/sharedState.js +2 -0
  30. package/lib/public/colors.js +1 -1
  31. package/lib/util/buildMediaQuery.js +6 -3
  32. package/lib/util/configurePlugins.js +1 -1
  33. package/lib/util/dataTypes.js +15 -19
  34. package/lib/util/formatVariantSelector.js +92 -8
  35. package/lib/util/getAllConfigs.js +14 -3
  36. package/lib/util/isValidArbitraryValue.js +1 -1
  37. package/lib/util/nameClass.js +3 -0
  38. package/lib/util/negateValue.js +15 -2
  39. package/lib/util/normalizeConfig.js +17 -3
  40. package/lib/util/normalizeScreens.js +100 -3
  41. package/lib/util/parseAnimationValue.js +1 -1
  42. package/lib/util/parseBoxShadowValue.js +1 -1
  43. package/lib/util/parseDependency.js +33 -54
  44. package/lib/util/parseGlob.js +34 -0
  45. package/lib/util/parseObjectStyles.js +1 -1
  46. package/lib/util/pluginUtils.js +86 -17
  47. package/lib/util/resolveConfig.js +2 -2
  48. package/lib/util/splitAtTopLevelOnly.js +31 -81
  49. package/lib/util/transformThemeValue.js +9 -2
  50. package/lib/util/validateConfig.js +1 -1
  51. package/lib/util/validateFormalSyntax.js +24 -0
  52. package/package.json +13 -11
  53. package/peers/.DS_Store +0 -0
  54. package/peers/.svgo.yml +75 -0
  55. package/peers/index.js +3332 -2032
  56. package/peers/orders/concentric-css.json +299 -0
  57. package/peers/orders/smacss.json +299 -0
  58. package/peers/orders/source.json +295 -0
  59. package/plugin.d.ts +3 -3
  60. package/scripts/release-channel.js +18 -0
  61. package/scripts/release-notes.js +21 -0
  62. package/src/.DS_Store +0 -0
  63. package/src/cli/build/deps.js +56 -0
  64. package/src/cli/build/index.js +45 -0
  65. package/src/cli/build/plugin.js +397 -0
  66. package/src/cli/build/utils.js +76 -0
  67. package/src/cli/build/watching.js +134 -0
  68. package/src/cli/help/index.js +70 -0
  69. package/src/cli/index.js +3 -0
  70. package/src/cli/init/index.js +50 -0
  71. package/src/cli/shared.js +5 -0
  72. package/src/cli.js +4 -696
  73. package/src/corePlugins.js +262 -39
  74. package/src/css/preflight.css +5 -0
  75. package/src/featureFlags.js +12 -2
  76. package/src/index.js +5 -0
  77. package/src/lib/content.js +205 -0
  78. package/src/lib/defaultExtractor.js +3 -0
  79. package/src/lib/evaluateTailwindFunctions.js +22 -1
  80. package/src/lib/expandApplyAtRules.js +70 -29
  81. package/src/lib/expandTailwindAtRules.js +8 -46
  82. package/src/lib/findAtConfigPath.js +48 -0
  83. package/src/lib/generateRules.js +223 -101
  84. package/src/lib/offsets.js +270 -0
  85. package/src/lib/setupContextUtils.js +376 -89
  86. package/src/lib/setupTrackingContext.js +4 -45
  87. package/src/lib/sharedState.js +2 -0
  88. package/src/util/buildMediaQuery.js +5 -3
  89. package/src/util/dataTypes.js +15 -17
  90. package/src/util/formatVariantSelector.js +113 -9
  91. package/src/util/getAllConfigs.js +14 -2
  92. package/src/util/nameClass.js +4 -0
  93. package/src/util/negateValue.js +10 -2
  94. package/src/util/normalizeConfig.js +22 -2
  95. package/src/util/normalizeScreens.js +99 -4
  96. package/src/util/parseBoxShadowValue.js +1 -1
  97. package/src/util/parseDependency.js +37 -42
  98. package/src/util/parseGlob.js +24 -0
  99. package/src/util/pluginUtils.js +90 -14
  100. package/src/util/resolveConfig.js +1 -1
  101. package/src/util/splitAtTopLevelOnly.js +23 -49
  102. package/src/util/transformThemeValue.js +9 -1
  103. package/src/util/validateFormalSyntax.js +34 -0
  104. package/stubs/defaultConfig.stub.js +19 -3
  105. package/tmp.css +11 -0
  106. package/tmp.dependency-graph.js +2 -0
  107. package/tmp.in.css +3 -0
  108. package/tmp.js +0 -0
  109. package/tmp.out.css +524 -0
  110. package/types/config.d.ts +47 -13
  111. package/types/generated/default-theme.d.ts +11 -0
  112. package/CHANGELOG.md +0 -2231
package/lib/cli.js CHANGED
@@ -3,33 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- const _indexJs = require("../peers/index.js");
7
- const _chokidar = /*#__PURE__*/ _interopRequireDefault(require("chokidar"));
8
6
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
9
7
  const _arg = /*#__PURE__*/ _interopRequireDefault(require("arg"));
10
8
  const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
11
- const _postcssLoadConfig = /*#__PURE__*/ _interopRequireDefault(require("postcss-load-config"));
12
- const _lilconfig = require("lilconfig");
13
- const _plugins = /*#__PURE__*/ _interopRequireDefault(require("postcss-load-config/src/plugins" // Little bit scary, looking at private/internal API
14
- ));
15
- const _options = /*#__PURE__*/ _interopRequireDefault(require("postcss-load-config/src/options" // Little bit scary, looking at private/internal API
16
- ));
17
- const _processTailwindFeatures = /*#__PURE__*/ _interopRequireDefault(require("./processTailwindFeatures"));
18
- const _resolveConfig = /*#__PURE__*/ _interopRequireDefault(require("../resolveConfig"));
19
- const _fastGlob = /*#__PURE__*/ _interopRequireDefault(require("fast-glob"));
20
- const _getModuleDependencies = /*#__PURE__*/ _interopRequireDefault(require("./lib/getModuleDependencies"));
21
- const _log = /*#__PURE__*/ _interopRequireDefault(require("./util/log"));
22
- const _packageJson = /*#__PURE__*/ _interopRequireDefault(require("../package.json"));
23
- const _normalizePath = /*#__PURE__*/ _interopRequireDefault(require("normalize-path"));
24
- const _validateConfigJs = require("./util/validateConfig.js");
9
+ const _build = require("./cli/build");
10
+ const _help = require("./cli/help");
11
+ const _init = require("./cli/init");
25
12
  function _interopRequireDefault(obj) {
26
13
  return obj && obj.__esModule ? obj : {
27
14
  default: obj
28
15
  };
29
16
  }
30
- let env = {
31
- DEBUG: process.env.DEBUG !== undefined && process.env.DEBUG !== "0"
32
- };
33
17
  function isESM() {
34
18
  const pkgPath = _path.default.resolve("./package.json");
35
19
  try {
@@ -47,94 +31,6 @@ let configs = isESM() ? {
47
31
  postcss: "postcss.config.js"
48
32
  };
49
33
  // ---
50
- function indentRecursive(node, indent = 0) {
51
- node.each && node.each((child, i)=>{
52
- if (!child.raws.before || !child.raws.before.trim() || child.raws.before.includes("\n")) {
53
- child.raws.before = `\n${node.type !== "rule" && i > 0 ? "\n" : ""}${" ".repeat(indent)}`;
54
- }
55
- child.raws.after = `\n${" ".repeat(indent)}`;
56
- indentRecursive(child, indent + 1);
57
- });
58
- }
59
- function formatNodes(root) {
60
- indentRecursive(root);
61
- if (root.first) {
62
- root.first.raws.before = "";
63
- }
64
- }
65
- async function outputFile(file, contents) {
66
- if (_fs.default.existsSync(file) && await _fs.default.promises.readFile(file, "utf8") === contents) {
67
- return; // Skip writing the file
68
- }
69
- // Write the file
70
- await _fs.default.promises.writeFile(file, contents, "utf8");
71
- }
72
- function drainStdin() {
73
- return new Promise((resolve, reject)=>{
74
- let result = "";
75
- process.stdin.on("data", (chunk)=>{
76
- result += chunk;
77
- });
78
- process.stdin.on("end", ()=>resolve(result));
79
- process.stdin.on("error", (err)=>reject(err));
80
- });
81
- }
82
- function help({ message , usage , commands , options }) {
83
- let indent = 2;
84
- // Render header
85
- console.log();
86
- console.log(`${_packageJson.default.name} v${_packageJson.default.version}`);
87
- // Render message
88
- if (message) {
89
- console.log();
90
- for (let msg of message.split("\n")){
91
- console.log(msg);
92
- }
93
- }
94
- // Render usage
95
- if (usage && usage.length > 0) {
96
- console.log();
97
- console.log("Usage:");
98
- for (let example of usage){
99
- console.log(" ".repeat(indent), example);
100
- }
101
- }
102
- // Render commands
103
- if (commands && commands.length > 0) {
104
- console.log();
105
- console.log("Commands:");
106
- for (let command of commands){
107
- console.log(" ".repeat(indent), command);
108
- }
109
- }
110
- // Render options
111
- if (options) {
112
- let groupedOptions = {};
113
- for (let [key, value] of Object.entries(options)){
114
- if (typeof value === "object") {
115
- groupedOptions[key] = {
116
- ...value,
117
- flags: [
118
- key
119
- ]
120
- };
121
- } else {
122
- groupedOptions[value].flags.push(key);
123
- }
124
- }
125
- console.log();
126
- console.log("Options:");
127
- for (let { flags , description , deprecated } of Object.values(groupedOptions)){
128
- if (deprecated) continue;
129
- if (flags.length === 1) {
130
- console.log(" ".repeat(indent + 4 /* 4 = "-i, ".length */ ), flags.slice().reverse().join(", ").padEnd(20, " "), description);
131
- } else {
132
- console.log(" ".repeat(indent), flags.slice().reverse().join(", ").padEnd(24, " "), description);
133
- }
134
- }
135
- }
136
- console.log();
137
- }
138
34
  function oneOf(...options) {
139
35
  return Object.assign((value = true)=>{
140
36
  for (let option of options){
@@ -148,16 +44,9 @@ function oneOf(...options) {
148
44
  manualParsing: true
149
45
  });
150
46
  }
151
- function loadPostcss() {
152
- // Try to load a local `postcss` version first
153
- try {
154
- return require("postcss");
155
- } catch {}
156
- return (0, _indexJs.lazyPostcss)();
157
- }
158
47
  let commands = {
159
48
  init: {
160
- run: init,
49
+ run: _init.init,
161
50
  args: {
162
51
  "--full": {
163
52
  type: Boolean,
@@ -172,7 +61,7 @@ let commands = {
172
61
  }
173
62
  },
174
63
  build: {
175
- run: build,
64
+ run: _build.build,
176
65
  args: {
177
66
  "--input": {
178
67
  type: String,
@@ -231,10 +120,10 @@ let sharedFlags = {
231
120
  "-h": "--help"
232
121
  };
233
122
  if (process.stdout.isTTY /* Detect redirecting output to a file */ && (process.argv[2] === undefined || process.argv.slice(2).every((flag)=>sharedFlags[flag] !== undefined))) {
234
- help({
123
+ (0, _help.help)({
235
124
  usage: [
236
125
  "tailwindcss [--input input.css] [--output output.css] [--watch] [options...]",
237
- "tailwindcss init [--full] [--postcss] [options...]",
126
+ "tailwindcss init [--full] [--postcss] [options...]"
238
127
  ],
239
128
  commands: Object.keys(commands).filter((command)=>command !== "build").map((command)=>`${command} [options]`),
240
129
  options: {
@@ -251,7 +140,7 @@ if (commands[command] === undefined) {
251
140
  // Check if non-existing command, might be a file.
252
141
  command = "build";
253
142
  } else {
254
- help({
143
+ (0, _help.help)({
255
144
  message: `Invalid command: ${command}`,
256
145
  usage: [
257
146
  "tailwindcss <command> [options]"
@@ -313,7 +202,7 @@ let args = (()=>{
313
202
  return result;
314
203
  } catch (err) {
315
204
  if (err.code === "ARG_UNKNOWN_OPTION") {
316
- help({
205
+ (0, _help.help)({
317
206
  message: err.message,
318
207
  usage: [
319
208
  "tailwindcss <command> [options]"
@@ -326,7 +215,7 @@ let args = (()=>{
326
215
  }
327
216
  })();
328
217
  if (args["--help"]) {
329
- help({
218
+ (0, _help.help)({
330
219
  options: {
331
220
  ...flags,
332
221
  ...sharedFlags
@@ -337,472 +226,4 @@ if (args["--help"]) {
337
226
  });
338
227
  process.exit(0);
339
228
  }
340
- run();
341
- // ---
342
- function init() {
343
- let messages = [];
344
- var ref;
345
- let tailwindConfigLocation = _path.default.resolve((ref = args["_"][1]) !== null && ref !== void 0 ? ref : `./${configs.tailwind}`);
346
- if (_fs.default.existsSync(tailwindConfigLocation)) {
347
- messages.push(`${_path.default.basename(tailwindConfigLocation)} already exists.`);
348
- } else {
349
- let stubFile = _fs.default.readFileSync(args["--full"] ? _path.default.resolve(__dirname, "../stubs/defaultConfig.stub.js") : _path.default.resolve(__dirname, "../stubs/simpleConfig.stub.js"), "utf8");
350
- // Change colors import
351
- stubFile = stubFile.replace("../colors", "tailwindcss/colors");
352
- _fs.default.writeFileSync(tailwindConfigLocation, stubFile, "utf8");
353
- messages.push(`Created Tailwind CSS config file: ${_path.default.basename(tailwindConfigLocation)}`);
354
- }
355
- if (args["--postcss"]) {
356
- let postcssConfigLocation = _path.default.resolve(`./${configs.postcss}`);
357
- if (_fs.default.existsSync(postcssConfigLocation)) {
358
- messages.push(`${_path.default.basename(postcssConfigLocation)} already exists.`);
359
- } else {
360
- let stubFile1 = _fs.default.readFileSync(_path.default.resolve(__dirname, "../stubs/defaultPostCssConfig.stub.js"), "utf8");
361
- _fs.default.writeFileSync(postcssConfigLocation, stubFile1, "utf8");
362
- messages.push(`Created PostCSS config file: ${_path.default.basename(postcssConfigLocation)}`);
363
- }
364
- }
365
- if (messages.length > 0) {
366
- console.log();
367
- for (let message of messages){
368
- console.log(message);
369
- }
370
- }
371
- }
372
- async function build() {
373
- let input = args["--input"];
374
- let output = args["--output"];
375
- let shouldWatch = args["--watch"];
376
- let shouldPoll = args["--poll"];
377
- let shouldCoalesceWriteEvents = shouldPoll || process.platform === "win32";
378
- let includePostCss = args["--postcss"];
379
- // Polling interval in milliseconds
380
- // Used only when polling or coalescing add/change events on Windows
381
- let pollInterval = 10;
382
- // TODO: Deprecate this in future versions
383
- if (!input && args["_"][1]) {
384
- console.error("[deprecation] Running tailwindcss without -i, please provide an input file.");
385
- input = args["--input"] = args["_"][1];
386
- }
387
- if (input && input !== "-" && !_fs.default.existsSync(input = _path.default.resolve(input))) {
388
- console.error(`Specified input file ${args["--input"]} does not exist.`);
389
- process.exit(9);
390
- }
391
- if (args["--config"] && !_fs.default.existsSync(args["--config"] = _path.default.resolve(args["--config"]))) {
392
- console.error(`Specified config file ${args["--config"]} does not exist.`);
393
- process.exit(9);
394
- }
395
- let configPath = args["--config"] ? args["--config"] : ((defaultPath)=>_fs.default.existsSync(defaultPath) ? defaultPath : null)(_path.default.resolve(`./${configs.tailwind}`));
396
- async function loadPostCssPlugins() {
397
- let customPostCssPath = typeof args["--postcss"] === "string" ? args["--postcss"] : undefined;
398
- let config = customPostCssPath ? await (async ()=>{
399
- let file = _path.default.resolve(customPostCssPath);
400
- // Implementation, see: https://unpkg.com/browse/postcss-load-config@3.1.0/src/index.js
401
- let { config ={} } = await (0, _lilconfig.lilconfig)("postcss").load(file);
402
- if (typeof config === "function") {
403
- config = config();
404
- } else {
405
- config = Object.assign({}, config);
406
- }
407
- if (!config.plugins) {
408
- config.plugins = [];
409
- }
410
- return {
411
- file,
412
- plugins: (0, _plugins.default)(config, file),
413
- options: (0, _options.default)(config, file)
414
- };
415
- })() : await (0, _postcssLoadConfig.default)();
416
- let configPlugins = config.plugins;
417
- let configPluginTailwindIdx = configPlugins.findIndex((plugin)=>{
418
- if (typeof plugin === "function" && plugin.name === "tailwindcss") {
419
- return true;
420
- }
421
- if (typeof plugin === "object" && plugin !== null && plugin.postcssPlugin === "tailwindcss") {
422
- return true;
423
- }
424
- return false;
425
- });
426
- let beforePlugins = configPluginTailwindIdx === -1 ? [] : configPlugins.slice(0, configPluginTailwindIdx);
427
- let afterPlugins = configPluginTailwindIdx === -1 ? configPlugins : configPlugins.slice(configPluginTailwindIdx + 1);
428
- return [
429
- beforePlugins,
430
- afterPlugins,
431
- config.options
432
- ];
433
- }
434
- function loadBuiltinPostcssPlugins() {
435
- let postcss = loadPostcss();
436
- let IMPORT_COMMENT = "__TAILWIND_RESTORE_IMPORT__: ";
437
- return [
438
- [
439
- (root)=>{
440
- root.walkAtRules("import", (rule)=>{
441
- if (rule.params.slice(1).startsWith("tailwindcss/")) {
442
- rule.after(postcss.comment({
443
- text: IMPORT_COMMENT + rule.params
444
- }));
445
- rule.remove();
446
- }
447
- });
448
- },
449
- (()=>{
450
- try {
451
- return require("postcss-import");
452
- } catch {}
453
- return (0, _indexJs.lazyPostcssImport)();
454
- })(),
455
- (root)=>{
456
- root.walkComments((rule)=>{
457
- if (rule.text.startsWith(IMPORT_COMMENT)) {
458
- rule.after(postcss.atRule({
459
- name: "import",
460
- params: rule.text.replace(IMPORT_COMMENT, "")
461
- }));
462
- rule.remove();
463
- }
464
- });
465
- },
466
- ],
467
- [],
468
- {},
469
- ];
470
- }
471
- function resolveConfig() {
472
- let config = configPath ? require(configPath) : {};
473
- if (args["--purge"]) {
474
- _log.default.warn("purge-flag-deprecated", [
475
- "The `--purge` flag has been deprecated.",
476
- "Please use `--content` instead.",
477
- ]);
478
- if (!args["--content"]) {
479
- args["--content"] = args["--purge"];
480
- }
481
- }
482
- if (args["--content"]) {
483
- let files = args["--content"].split(/(?<!{[^}]+),/);
484
- let resolvedConfig = (0, _resolveConfig.default)(config, {
485
- content: {
486
- files
487
- }
488
- });
489
- resolvedConfig.content.files = files;
490
- resolvedConfig = (0, _validateConfigJs.validateConfig)(resolvedConfig);
491
- return resolvedConfig;
492
- }
493
- let resolvedConfig1 = (0, _resolveConfig.default)(config);
494
- resolvedConfig1 = (0, _validateConfigJs.validateConfig)(resolvedConfig1);
495
- return resolvedConfig1;
496
- }
497
- function extractFileGlobs(config) {
498
- return config.content.files.filter((file)=>{
499
- // Strings in this case are files / globs. If it is something else,
500
- // like an object it's probably a raw content object. But this object
501
- // is not watchable, so let's remove it.
502
- return typeof file === "string";
503
- }).map((glob)=>(0, _normalizePath.default)(glob));
504
- }
505
- function extractRawContent(config) {
506
- return config.content.files.filter((file)=>{
507
- return typeof file === "object" && file !== null;
508
- });
509
- }
510
- function getChangedContent(config) {
511
- let changedContent = [];
512
- // Resolve globs from the content config
513
- let globs = extractFileGlobs(config);
514
- let files = _fastGlob.default.sync(globs);
515
- for (let file of files){
516
- changedContent.push({
517
- content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
518
- extension: _path.default.extname(file).slice(1)
519
- });
520
- }
521
- // Resolve raw content in the tailwind config
522
- for (let { raw: content , extension ="html" } of extractRawContent(config)){
523
- changedContent.push({
524
- content,
525
- extension
526
- });
527
- }
528
- return changedContent;
529
- }
530
- async function buildOnce() {
531
- let config = resolveConfig();
532
- let changedContent = getChangedContent(config);
533
- let tailwindPlugin = ()=>{
534
- return {
535
- postcssPlugin: "tailwindcss",
536
- Once (root, { result }) {
537
- (0, _processTailwindFeatures.default)(({ createContext })=>{
538
- return ()=>{
539
- return createContext(config, changedContent);
540
- };
541
- })(root, result);
542
- }
543
- };
544
- };
545
- tailwindPlugin.postcss = true;
546
- let [beforePlugins, afterPlugins, postcssOptions] = includePostCss ? await loadPostCssPlugins() : loadBuiltinPostcssPlugins();
547
- let plugins = [
548
- ...beforePlugins,
549
- tailwindPlugin,
550
- !args["--minify"] && formatNodes,
551
- ...afterPlugins,
552
- !args["--no-autoprefixer"] && (()=>{
553
- // Try to load a local `autoprefixer` version first
554
- try {
555
- return require("autoprefixer");
556
- } catch {}
557
- return (0, _indexJs.lazyAutoprefixer)();
558
- })(),
559
- args["--minify"] && (()=>{
560
- let options = {
561
- preset: [
562
- "default",
563
- {
564
- cssDeclarationSorter: false
565
- }
566
- ]
567
- };
568
- // Try to load a local `cssnano` version first
569
- try {
570
- return require("cssnano");
571
- } catch {}
572
- return (0, _indexJs.lazyCssnano)()(options);
573
- })(),
574
- ].filter(Boolean);
575
- let postcss = loadPostcss();
576
- let processor = postcss(plugins);
577
- function processCSS(css) {
578
- let start = process.hrtime.bigint();
579
- return Promise.resolve().then(()=>output ? _fs.default.promises.mkdir(_path.default.dirname(output), {
580
- recursive: true
581
- }) : null).then(()=>processor.process(css, {
582
- ...postcssOptions,
583
- from: input,
584
- to: output
585
- })).then((result)=>{
586
- if (!output) {
587
- return process.stdout.write(result.css);
588
- }
589
- return Promise.all([
590
- outputFile(output, result.css),
591
- result.map && outputFile(output + ".map", result.map.toString()),
592
- ].filter(Boolean));
593
- }).then(()=>{
594
- let end = process.hrtime.bigint();
595
- console.error();
596
- console.error("Done in", (end - start) / BigInt(1e6) + "ms.");
597
- });
598
- }
599
- let css = await (()=>{
600
- // Piping in data, let's drain the stdin
601
- if (input === "-") {
602
- return drainStdin();
603
- }
604
- // Input file has been provided
605
- if (input) {
606
- return _fs.default.readFileSync(_path.default.resolve(input), "utf8");
607
- }
608
- // No input file provided, fallback to default atrules
609
- return "@tailwind base; @tailwind components; @tailwind utilities";
610
- })();
611
- return processCSS(css);
612
- }
613
- let context = null;
614
- async function startWatcher() {
615
- let changedContent = [];
616
- let configDependencies = [];
617
- let contextDependencies = new Set();
618
- let watcher = null;
619
- function refreshConfig() {
620
- env.DEBUG && console.time("Module dependencies");
621
- for (let file of configDependencies){
622
- delete require.cache[require.resolve(file)];
623
- }
624
- if (configPath) {
625
- configDependencies = (0, _getModuleDependencies.default)(configPath).map(({ file })=>file);
626
- for (let dependency of configDependencies){
627
- contextDependencies.add(dependency);
628
- }
629
- }
630
- env.DEBUG && console.timeEnd("Module dependencies");
631
- return resolveConfig();
632
- }
633
- let [beforePlugins, afterPlugins] = includePostCss ? await loadPostCssPlugins() : loadBuiltinPostcssPlugins();
634
- let plugins = [
635
- ...beforePlugins,
636
- "__TAILWIND_PLUGIN_POSITION__",
637
- !args["--minify"] && formatNodes,
638
- ...afterPlugins,
639
- !args["--no-autoprefixer"] && (()=>{
640
- // Try to load a local `autoprefixer` version first
641
- try {
642
- return require("autoprefixer");
643
- } catch {}
644
- return (0, _indexJs.lazyAutoprefixer)();
645
- })(),
646
- args["--minify"] && (()=>{
647
- let options = {
648
- preset: [
649
- "default",
650
- {
651
- cssDeclarationSorter: false
652
- }
653
- ]
654
- };
655
- // Try to load a local `cssnano` version first
656
- try {
657
- return require("cssnano");
658
- } catch {}
659
- return (0, _indexJs.lazyCssnano)()(options);
660
- })(),
661
- ].filter(Boolean);
662
- async function rebuild(config) {
663
- env.DEBUG && console.time("Finished in");
664
- let tailwindPlugin = ()=>{
665
- return {
666
- postcssPlugin: "tailwindcss",
667
- Once (root, { result }) {
668
- env.DEBUG && console.time("Compiling CSS");
669
- (0, _processTailwindFeatures.default)(({ createContext })=>{
670
- console.error();
671
- console.error("Rebuilding...");
672
- return ()=>{
673
- if (context !== null) {
674
- context.changedContent = changedContent.splice(0);
675
- return context;
676
- }
677
- env.DEBUG && console.time("Creating context");
678
- context = createContext(config, changedContent.splice(0));
679
- env.DEBUG && console.timeEnd("Creating context");
680
- return context;
681
- };
682
- })(root, result);
683
- env.DEBUG && console.timeEnd("Compiling CSS");
684
- }
685
- };
686
- };
687
- tailwindPlugin.postcss = true;
688
- let tailwindPluginIdx = plugins.indexOf("__TAILWIND_PLUGIN_POSITION__");
689
- let copy = plugins.slice();
690
- copy.splice(tailwindPluginIdx, 1, tailwindPlugin);
691
- let postcss = loadPostcss();
692
- let processor = postcss(copy);
693
- function processCSS(css) {
694
- let start = process.hrtime.bigint();
695
- return Promise.resolve().then(()=>output ? _fs.default.promises.mkdir(_path.default.dirname(output), {
696
- recursive: true
697
- }) : null).then(()=>processor.process(css, {
698
- from: input,
699
- to: output
700
- })).then(async (result)=>{
701
- for (let message of result.messages){
702
- if (message.type === "dependency") {
703
- contextDependencies.add(message.file);
704
- }
705
- }
706
- watcher.add([
707
- ...contextDependencies
708
- ]);
709
- if (!output) {
710
- return process.stdout.write(result.css);
711
- }
712
- return Promise.all([
713
- outputFile(output, result.css),
714
- result.map && outputFile(output + ".map", result.map.toString()),
715
- ].filter(Boolean));
716
- }).then(()=>{
717
- let end = process.hrtime.bigint();
718
- console.error("Done in", (end - start) / BigInt(1e6) + "ms.");
719
- }).catch((err)=>{
720
- if (err.name === "CssSyntaxError") {
721
- console.error(err.toString());
722
- } else {
723
- console.error(err);
724
- }
725
- });
726
- }
727
- let css = await (()=>{
728
- // Piping in data, let's drain the stdin
729
- if (input === "-") {
730
- return drainStdin();
731
- }
732
- // Input file has been provided
733
- if (input) {
734
- return _fs.default.readFileSync(_path.default.resolve(input), "utf8");
735
- }
736
- // No input file provided, fallback to default atrules
737
- return "@tailwind base; @tailwind components; @tailwind utilities";
738
- })();
739
- let result = await processCSS(css);
740
- env.DEBUG && console.timeEnd("Finished in");
741
- return result;
742
- }
743
- let config = refreshConfig(configPath);
744
- if (input) {
745
- contextDependencies.add(_path.default.resolve(input));
746
- }
747
- watcher = _chokidar.default.watch([
748
- ...contextDependencies,
749
- ...extractFileGlobs(config)
750
- ], {
751
- usePolling: shouldPoll,
752
- interval: shouldPoll ? pollInterval : undefined,
753
- ignoreInitial: true,
754
- awaitWriteFinish: shouldCoalesceWriteEvents ? {
755
- stabilityThreshold: 50,
756
- pollInterval: pollInterval
757
- } : false
758
- });
759
- let chain = Promise.resolve();
760
- watcher.on("change", async (file)=>{
761
- if (contextDependencies.has(file)) {
762
- env.DEBUG && console.time("Resolve config");
763
- context = null;
764
- config = refreshConfig(configPath);
765
- env.DEBUG && console.timeEnd("Resolve config");
766
- env.DEBUG && console.time("Watch new files");
767
- let globs = extractFileGlobs(config);
768
- watcher.add(configDependencies);
769
- watcher.add(globs);
770
- env.DEBUG && console.timeEnd("Watch new files");
771
- chain = chain.then(async ()=>{
772
- changedContent.push(...getChangedContent(config));
773
- await rebuild(config);
774
- });
775
- } else {
776
- chain = chain.then(async ()=>{
777
- changedContent.push({
778
- content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
779
- extension: _path.default.extname(file).slice(1)
780
- });
781
- await rebuild(config);
782
- });
783
- }
784
- });
785
- watcher.on("add", async (file)=>{
786
- chain = chain.then(async ()=>{
787
- changedContent.push({
788
- content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
789
- extension: _path.default.extname(file).slice(1)
790
- });
791
- await rebuild(config);
792
- });
793
- });
794
- chain = chain.then(()=>{
795
- changedContent.push(...getChangedContent(config));
796
- return rebuild(config);
797
- });
798
- }
799
- if (shouldWatch) {
800
- /* Abort the watcher if stdin is closed to avoid zombie processes */ if (process.stdin.isTTY) {
801
- process.stdin.on("end", ()=>process.exit(0));
802
- process.stdin.resume();
803
- }
804
- startWatcher();
805
- } else {
806
- buildOnce();
807
- }
808
- }
229
+ run(args, configs);