tailwindcss 0.0.0-insiders.7b94fea → 0.0.0-insiders.7d8eb21

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