tailwindcss 0.0.0-insiders.cbbfa82 → 0.0.0-insiders.cc1eec6

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 (140) hide show
  1. package/README.md +1 -1
  2. package/lib/cli/build/index.js +7 -3
  3. package/lib/cli/build/plugin.js +65 -51
  4. package/lib/cli/build/watching.js +4 -2
  5. package/lib/cli/index.js +222 -10
  6. package/lib/cli/init/index.js +22 -7
  7. package/lib/cli.js +4 -236
  8. package/lib/corePluginList.js +4 -0
  9. package/lib/corePlugins.js +319 -52
  10. package/lib/css/preflight.css +2 -0
  11. package/lib/featureFlags.js +16 -9
  12. package/lib/index.js +4 -46
  13. package/lib/lib/collapseAdjacentRules.js +2 -2
  14. package/lib/lib/collapseDuplicateDeclarations.js +2 -2
  15. package/lib/lib/content.js +16 -16
  16. package/lib/lib/defaultExtractor.js +10 -5
  17. package/lib/lib/detectNesting.js +7 -1
  18. package/lib/lib/evaluateTailwindFunctions.js +4 -4
  19. package/lib/lib/expandApplyAtRules.js +14 -3
  20. package/lib/lib/expandTailwindAtRules.js +34 -9
  21. package/lib/lib/findAtConfigPath.js +3 -3
  22. package/lib/lib/generateRules.js +123 -64
  23. package/lib/lib/getModuleDependencies.js +79 -33
  24. package/lib/lib/load-config.js +40 -0
  25. package/lib/lib/offsets.js +88 -1
  26. package/lib/lib/remap-bitfield.js +87 -0
  27. package/lib/lib/resolveDefaultsAtRules.js +4 -4
  28. package/lib/lib/setupContextUtils.js +123 -68
  29. package/lib/lib/setupTrackingContext.js +29 -8
  30. package/lib/lib/sharedState.js +25 -2
  31. package/lib/oxide/cli/build/deps.js +81 -0
  32. package/lib/oxide/cli/build/index.js +51 -0
  33. package/lib/oxide/cli/build/plugin.js +373 -0
  34. package/lib/oxide/cli/build/utils.js +77 -0
  35. package/lib/oxide/cli/build/watching.js +177 -0
  36. package/lib/oxide/cli/help/index.js +70 -0
  37. package/lib/oxide/cli/index.js +214 -0
  38. package/lib/oxide/cli/init/index.js +50 -0
  39. package/lib/oxide/cli.js +5 -0
  40. package/lib/oxide/postcss-plugin.js +2 -0
  41. package/lib/plugin.js +98 -0
  42. package/lib/postcss-plugins/nesting/plugin.js +2 -2
  43. package/lib/public/colors.js +44 -22
  44. package/lib/public/default-config.js +2 -2
  45. package/lib/public/default-theme.js +2 -2
  46. package/lib/public/load-config.js +10 -0
  47. package/lib/util/applyImportantSelector.js +37 -0
  48. package/lib/util/cloneNodes.js +2 -2
  49. package/lib/util/color.js +20 -6
  50. package/lib/util/createUtilityPlugin.js +2 -2
  51. package/lib/util/dataTypes.js +26 -2
  52. package/lib/util/defaults.js +4 -4
  53. package/lib/util/escapeClassName.js +3 -3
  54. package/lib/util/formatVariantSelector.js +173 -115
  55. package/lib/util/getAllConfigs.js +4 -4
  56. package/lib/util/negateValue.js +2 -2
  57. package/lib/util/normalizeConfig.js +21 -22
  58. package/lib/util/pluginUtils.js +20 -39
  59. package/lib/util/prefixSelector.js +22 -8
  60. package/lib/util/resolveConfig.js +7 -7
  61. package/lib/util/resolveConfigPath.js +19 -7
  62. package/lib/util/splitAtTopLevelOnly.js +7 -1
  63. package/lib/util/validateConfig.js +11 -0
  64. package/loadConfig.d.ts +4 -0
  65. package/loadConfig.js +2 -0
  66. package/package.json +33 -21
  67. package/peers/index.js +108 -173
  68. package/resolveConfig.d.ts +11 -2
  69. package/scripts/swap-engines.js +40 -0
  70. package/src/cli/build/index.js +7 -7
  71. package/src/cli/build/plugin.js +40 -30
  72. package/src/cli/build/watching.js +4 -2
  73. package/src/cli/index.js +216 -3
  74. package/src/cli/init/index.js +37 -8
  75. package/src/cli.js +4 -231
  76. package/src/corePluginList.js +1 -1
  77. package/src/corePlugins.js +205 -29
  78. package/src/css/preflight.css +2 -0
  79. package/src/featureFlags.js +7 -0
  80. package/src/index.js +4 -46
  81. package/src/lib/content.js +12 -17
  82. package/src/lib/defaultExtractor.js +9 -3
  83. package/src/lib/detectNesting.js +9 -1
  84. package/src/lib/expandApplyAtRules.js +14 -1
  85. package/src/lib/expandTailwindAtRules.js +35 -6
  86. package/src/lib/generateRules.js +124 -42
  87. package/src/lib/getModuleDependencies.js +70 -30
  88. package/src/lib/load-config.ts +31 -0
  89. package/src/lib/offsets.js +104 -1
  90. package/src/lib/remap-bitfield.js +82 -0
  91. package/src/lib/setupContextUtils.js +99 -43
  92. package/src/lib/setupTrackingContext.js +35 -10
  93. package/src/lib/sharedState.js +30 -4
  94. package/src/oxide/cli/build/deps.ts +91 -0
  95. package/src/oxide/cli/build/index.ts +47 -0
  96. package/src/oxide/cli/build/plugin.ts +442 -0
  97. package/src/oxide/cli/build/utils.ts +74 -0
  98. package/src/oxide/cli/build/watching.ts +225 -0
  99. package/src/oxide/cli/help/index.ts +69 -0
  100. package/src/oxide/cli/index.ts +204 -0
  101. package/src/oxide/cli/init/index.ts +59 -0
  102. package/src/oxide/cli.ts +1 -0
  103. package/src/oxide/postcss-plugin.ts +1 -0
  104. package/src/plugin.js +107 -0
  105. package/src/public/colors.js +22 -0
  106. package/src/public/default-config.js +1 -1
  107. package/src/public/default-theme.js +2 -2
  108. package/src/public/load-config.js +2 -0
  109. package/src/util/applyImportantSelector.js +30 -0
  110. package/src/util/color.js +17 -2
  111. package/src/util/dataTypes.js +29 -4
  112. package/src/util/formatVariantSelector.js +240 -121
  113. package/src/util/getAllConfigs.js +2 -2
  114. package/src/util/negateValue.js +1 -1
  115. package/src/util/normalizeConfig.js +2 -1
  116. package/src/util/pluginUtils.js +10 -29
  117. package/src/util/prefixSelector.js +28 -10
  118. package/src/util/resolveConfigPath.js +12 -1
  119. package/src/util/splitAtTopLevelOnly.js +8 -1
  120. package/src/util/validateConfig.js +13 -0
  121. package/stubs/.gitignore +1 -0
  122. package/stubs/.prettierrc.json +6 -0
  123. package/stubs/{defaultConfig.stub.js → config.full.js} +183 -146
  124. package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -1
  125. package/stubs/postcss.config.js +6 -0
  126. package/stubs/tailwind.config.cjs +2 -0
  127. package/stubs/tailwind.config.js +2 -0
  128. package/stubs/tailwind.config.ts +3 -0
  129. package/types/config.d.ts +15 -9
  130. package/types/generated/colors.d.ts +22 -0
  131. package/types/generated/corePluginList.d.ts +1 -1
  132. package/types/generated/default-theme.d.ts +108 -79
  133. package/CHANGELOG.md +0 -2339
  134. package/lib/cli/shared.js +0 -12
  135. package/lib/constants.js +0 -44
  136. package/scripts/install-integrations.js +0 -27
  137. package/scripts/rebuildFixtures.js +0 -68
  138. package/src/cli/shared.js +0 -5
  139. package/src/constants.js +0 -17
  140. /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
 
16
16
  <p align="center">
17
- <a href="https://github.com/tailwindlabs/tailwindcss/actions"><img src="https://img.shields.io/github/workflow/status/tailwindlabs/tailwindcss/Node.js%20CI" alt="Build Status"></a>
17
+ <a href="https://github.com/tailwindlabs/tailwindcss/actions"><img src="https://img.shields.io/github/actions/workflow/status/tailwindlabs/tailwindcss/ci-stable.yml?branch=master" alt="Build Status"></a>
18
18
  <a href="https://www.npmjs.com/package/tailwindcss"><img src="https://img.shields.io/npm/dt/tailwindcss.svg" alt="Total Downloads"></a>
19
19
  <a href="https://github.com/tailwindcss/tailwindcss/releases"><img src="https://img.shields.io/npm/v/tailwindcss.svg" alt="Latest Release"></a>
20
20
  <a href="https://github.com/tailwindcss/tailwindcss/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/tailwindcss.svg" alt="License"></a>
@@ -9,13 +9,14 @@ Object.defineProperty(exports, "build", {
9
9
  });
10
10
  const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
11
11
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
12
+ const _resolveConfigPathJs = require("../../util/resolveConfigPath.js");
12
13
  const _pluginJs = require("./plugin.js");
13
14
  function _interopRequireDefault(obj) {
14
15
  return obj && obj.__esModule ? obj : {
15
16
  default: obj
16
17
  };
17
18
  }
18
- async function build(args, configs) {
19
+ async function build(args) {
19
20
  let input = args["--input"];
20
21
  let shouldWatch = args["--watch"];
21
22
  // TODO: Deprecate this in future versions
@@ -32,7 +33,7 @@ async function build(args, configs) {
32
33
  process.exit(9);
33
34
  }
34
35
  // TODO: Reference the @config path here if exists
35
- let configPath = args["--config"] ? args["--config"] : ((defaultPath)=>_fs.default.existsSync(defaultPath) ? defaultPath : null)(_path.default.resolve(`./${configs.tailwind}`));
36
+ let configPath = args["--config"] ? args["--config"] : (0, _resolveConfigPathJs.resolveDefaultConfigPath)();
36
37
  let processor = await (0, _pluginJs.createProcessor)(args, configPath);
37
38
  if (shouldWatch) {
38
39
  // Abort the watcher if stdin is closed to avoid zombie processes
@@ -43,6 +44,9 @@ async function build(args, configs) {
43
44
  process.stdin.resume();
44
45
  await processor.watch();
45
46
  } else {
46
- await processor.build();
47
+ await processor.build().catch((e)=>{
48
+ console.error(e);
49
+ process.exit(1);
50
+ });
47
51
  }
48
52
  }
@@ -18,14 +18,15 @@ const _options = /*#__PURE__*/ _interopRequireDefault(require("postcss-load-conf
18
18
  const _processTailwindFeatures = /*#__PURE__*/ _interopRequireDefault(require("../../processTailwindFeatures"));
19
19
  const _deps = require("./deps");
20
20
  const _utils = require("./utils");
21
- const _shared = require("../shared");
21
+ const _sharedState = require("../../lib/sharedState");
22
22
  const _resolveConfigJs = /*#__PURE__*/ _interopRequireDefault(require("../../../resolveConfig.js"));
23
- const _getModuleDependenciesJs = /*#__PURE__*/ _interopRequireDefault(require("../../lib/getModuleDependencies.js"));
24
23
  const _contentJs = require("../../lib/content.js");
25
24
  const _watchingJs = require("./watching.js");
26
25
  const _fastGlob = /*#__PURE__*/ _interopRequireDefault(require("fast-glob"));
27
26
  const _findAtConfigPathJs = require("../../lib/findAtConfigPath.js");
28
27
  const _log = /*#__PURE__*/ _interopRequireDefault(require("../../util/log"));
28
+ const _loadConfig = require("../../lib/load-config");
29
+ const _getModuleDependencies = /*#__PURE__*/ _interopRequireDefault(require("../../lib/getModuleDependencies"));
29
30
  function _interopRequireDefault(obj) {
30
31
  return obj && obj.__esModule ? obj : {
31
32
  default: obj
@@ -109,12 +110,12 @@ let state = {
109
110
  /** @type {any} */ context: null,
110
111
  /** @type {ReturnType<typeof createWatcher> | null} */ watcher: null,
111
112
  /** @type {{content: string, extension: string}[]} */ changedContent: [],
112
- configDependencies: new Set(),
113
+ /** @type {ReturnType<typeof load> | null} */ configBag: null,
113
114
  contextDependencies: new Set(),
114
115
  /** @type {import('../../lib/content.js').ContentPath[]} */ contentPaths: [],
115
116
  refreshContentPaths () {
116
- var ref;
117
- this.contentPaths = (0, _contentJs.parseCandidateFiles)(this.context, (ref = this.context) === null || ref === void 0 ? void 0 : ref.tailwindConfig);
117
+ var _this_context;
118
+ this.contentPaths = (0, _contentJs.parseCandidateFiles)(this.context, (_this_context = this.context) === null || _this_context === void 0 ? void 0 : _this_context.tailwindConfig);
118
119
  },
119
120
  get config () {
120
121
  return this.context.tailwindConfig;
@@ -127,33 +128,36 @@ let state = {
127
128
  },
128
129
  loadConfig (configPath, content) {
129
130
  if (this.watcher && configPath) {
130
- this.refreshConfigDependencies(configPath);
131
+ this.refreshConfigDependencies();
131
132
  }
132
- let config = configPath ? require(configPath) : {};
133
+ let config = (0, _loadConfig.loadConfig)(configPath);
134
+ let dependencies = (0, _getModuleDependencies.default)(configPath);
135
+ this.configBag = {
136
+ config,
137
+ dependencies,
138
+ dispose () {
139
+ for (let file of dependencies){
140
+ delete require.cache[require.resolve(file)];
141
+ }
142
+ }
143
+ };
133
144
  // @ts-ignore
134
- config = (0, _resolveConfigJs.default)(config, {
145
+ this.configBag.config = (0, _resolveConfigJs.default)(this.configBag.config, {
135
146
  content: {
136
147
  files: []
137
148
  }
138
149
  });
139
150
  // Override content files if `--content` has been passed explicitly
140
151
  if ((content === null || content === void 0 ? void 0 : content.length) > 0) {
141
- config.content.files = content;
152
+ this.configBag.config.content.files = content;
142
153
  }
143
- return config;
154
+ return this.configBag.config;
144
155
  },
145
- refreshConfigDependencies (configPath) {
146
- _shared.env.DEBUG && console.time("Module dependencies");
147
- for (let file of this.configDependencies){
148
- delete require.cache[require.resolve(file)];
149
- }
150
- if (configPath) {
151
- let deps = (0, _getModuleDependenciesJs.default)(configPath).map(({ file })=>file);
152
- for (let dependency of deps){
153
- this.configDependencies.add(dependency);
154
- }
155
- }
156
- _shared.env.DEBUG && console.timeEnd("Module dependencies");
156
+ refreshConfigDependencies () {
157
+ var _this_configBag;
158
+ _sharedState.env.DEBUG && console.time("Module dependencies");
159
+ (_this_configBag = this.configBag) === null || _this_configBag === void 0 ? void 0 : _this_configBag.dispose();
160
+ _sharedState.env.DEBUG && console.timeEnd("Module dependencies");
157
161
  },
158
162
  readContentPaths () {
159
163
  let content = [];
@@ -161,10 +165,17 @@ let state = {
161
165
  // TODO: When we make the postcss plugin async-capable this can become async
162
166
  let files = _fastGlob.default.sync(this.contentPatterns.all);
163
167
  for (let file of files){
164
- content.push({
165
- content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
166
- extension: _path.default.extname(file).slice(1)
167
- });
168
+ if (_sharedState.env.OXIDE) {
169
+ content.push({
170
+ file,
171
+ extension: _path.default.extname(file).slice(1)
172
+ });
173
+ } else {
174
+ content.push({
175
+ content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
176
+ extension: _path.default.extname(file).slice(1)
177
+ });
178
+ }
168
179
  }
169
180
  // Resolve raw content in the tailwind config
170
181
  let rawContent = this.config.content.files.filter((file)=>{
@@ -183,37 +194,35 @@ let state = {
183
194
  this.context.changedContent = this.changedContent.splice(0);
184
195
  return this.context;
185
196
  }
186
- _shared.env.DEBUG && console.time("Searching for config");
187
- var ref;
188
- let configPath = (ref = (0, _findAtConfigPathJs.findAtConfigPath)(root, result)) !== null && ref !== void 0 ? ref : cliConfigPath;
189
- _shared.env.DEBUG && console.timeEnd("Searching for config");
190
- _shared.env.DEBUG && console.time("Loading config");
197
+ _sharedState.env.DEBUG && console.time("Searching for config");
198
+ var _findAtConfigPath;
199
+ let configPath = (_findAtConfigPath = (0, _findAtConfigPathJs.findAtConfigPath)(root, result)) !== null && _findAtConfigPath !== void 0 ? _findAtConfigPath : cliConfigPath;
200
+ _sharedState.env.DEBUG && console.timeEnd("Searching for config");
201
+ _sharedState.env.DEBUG && console.time("Loading config");
191
202
  let config = this.loadConfig(configPath, content);
192
- _shared.env.DEBUG && console.timeEnd("Loading config");
193
- _shared.env.DEBUG && console.time("Creating context");
203
+ _sharedState.env.DEBUG && console.timeEnd("Loading config");
204
+ _sharedState.env.DEBUG && console.time("Creating context");
194
205
  this.context = createContext(config, []);
195
206
  Object.assign(this.context, {
196
207
  userConfigPath: configPath
197
208
  });
198
- _shared.env.DEBUG && console.timeEnd("Creating context");
199
- _shared.env.DEBUG && console.time("Resolving content paths");
209
+ _sharedState.env.DEBUG && console.timeEnd("Creating context");
210
+ _sharedState.env.DEBUG && console.time("Resolving content paths");
200
211
  this.refreshContentPaths();
201
- _shared.env.DEBUG && console.timeEnd("Resolving content paths");
212
+ _sharedState.env.DEBUG && console.timeEnd("Resolving content paths");
202
213
  if (this.watcher) {
203
- _shared.env.DEBUG && console.time("Watch new files");
214
+ _sharedState.env.DEBUG && console.time("Watch new files");
204
215
  this.watcher.refreshWatchedFiles();
205
- _shared.env.DEBUG && console.timeEnd("Watch new files");
216
+ _sharedState.env.DEBUG && console.timeEnd("Watch new files");
206
217
  }
207
- _shared.env.DEBUG && console.time("Reading content files");
208
218
  for (let file of this.readContentPaths()){
209
219
  this.context.changedContent.push(file);
210
220
  }
211
- _shared.env.DEBUG && console.timeEnd("Reading content files");
212
221
  return this.context;
213
222
  }
214
223
  };
215
224
  async function createProcessor(args, cliConfigPath) {
216
- var ref;
225
+ var _args_content;
217
226
  let postcss = (0, _deps.loadPostcss)();
218
227
  let input = args["--input"];
219
228
  let output = args["--output"];
@@ -229,13 +238,13 @@ async function createProcessor(args, cliConfigPath) {
229
238
  args["--content"] = args["--purge"];
230
239
  }
231
240
  }
232
- var ref1;
233
- let content = (ref1 = (ref = args["--content"]) === null || ref === void 0 ? void 0 : ref.split(/(?<!{[^}]+),/)) !== null && ref1 !== void 0 ? ref1 : [];
241
+ var _args_content_split;
242
+ let content = (_args_content_split = (_args_content = args["--content"]) === null || _args_content === void 0 ? void 0 : _args_content.split(/(?<!{[^}]+),/)) !== null && _args_content_split !== void 0 ? _args_content_split : [];
234
243
  let tailwindPlugin = ()=>{
235
244
  return {
236
245
  postcssPlugin: "tailwindcss",
237
246
  Once (root, { result }) {
238
- _shared.env.DEBUG && console.time("Compiling CSS");
247
+ _sharedState.env.DEBUG && console.time("Compiling CSS");
239
248
  (0, _processTailwindFeatures.default)(({ createContext })=>{
240
249
  console.error();
241
250
  console.error("Rebuilding...");
@@ -249,7 +258,7 @@ async function createProcessor(args, cliConfigPath) {
249
258
  });
250
259
  };
251
260
  })(root, result);
252
- _shared.env.DEBUG && console.timeEnd("Compiling CSS");
261
+ _sharedState.env.DEBUG && console.timeEnd("Compiling CSS");
253
262
  }
254
263
  };
255
264
  };
@@ -286,17 +295,17 @@ async function createProcessor(args, cliConfigPath) {
286
295
  if (!state.watcher) {
287
296
  return result;
288
297
  }
289
- _shared.env.DEBUG && console.time("Recording PostCSS dependencies");
298
+ _sharedState.env.DEBUG && console.time("Recording PostCSS dependencies");
290
299
  for (let message of result.messages){
291
300
  if (message.type === "dependency") {
292
301
  state.contextDependencies.add(message.file);
293
302
  }
294
303
  }
295
- _shared.env.DEBUG && console.timeEnd("Recording PostCSS dependencies");
304
+ _sharedState.env.DEBUG && console.timeEnd("Recording PostCSS dependencies");
296
305
  // TODO: This needs to be in a different spot
297
- _shared.env.DEBUG && console.time("Watch new files");
306
+ _sharedState.env.DEBUG && console.time("Watch new files");
298
307
  state.watcher.refreshWatchedFiles();
299
- _shared.env.DEBUG && console.timeEnd("Watch new files");
308
+ _sharedState.env.DEBUG && console.timeEnd("Watch new files");
300
309
  return result;
301
310
  }).then((result)=>{
302
311
  if (!output) {
@@ -321,7 +330,11 @@ async function createProcessor(args, cliConfigPath) {
321
330
  // If you fix it and then save the main CSS file so there's no error
322
331
  // The watcher will start watching the imported CSS files and will be
323
332
  // resilient to future errors.
324
- console.error(err);
333
+ if (state.watcher) {
334
+ console.error(err);
335
+ } else {
336
+ return Promise.reject(err);
337
+ }
325
338
  });
326
339
  }
327
340
  /**
@@ -344,7 +357,8 @@ async function createProcessor(args, cliConfigPath) {
344
357
  * @param {{file: string, content(): Promise<string>, extension: string}[]} changes
345
358
  */ async rebuild (changes) {
346
359
  let needsNewContext = changes.some((change)=>{
347
- return state.configDependencies.has(change.file) || state.contextDependencies.has(change.file);
360
+ var _state_configBag;
361
+ return ((_state_configBag = state.configBag) === null || _state_configBag === void 0 ? void 0 : _state_configBag.dependencies.has(change.file)) || state.contextDependencies.has(change.file);
348
362
  });
349
363
  if (needsNewContext) {
350
364
  state.context = null;
@@ -64,7 +64,9 @@ function createWatcher(args, { state , rebuild }) {
64
64
  // Clear all pending rebuilds for the about-to-be-built files
65
65
  changes.forEach((change)=>pendingRebuilds.delete(change.file));
66
66
  // Resolve the promise even when the rebuild fails
67
- return rebuild(changes).then(()=>{}, ()=>{});
67
+ return rebuild(changes).then(()=>{}, (e)=>{
68
+ console.error(e.toString());
69
+ });
68
70
  }
69
71
  /**
70
72
  *
@@ -171,7 +173,7 @@ function createWatcher(args, { state , rebuild }) {
171
173
  fswatcher: watcher,
172
174
  refreshWatchedFiles () {
173
175
  watcher.add(Array.from(state.contextDependencies));
174
- watcher.add(Array.from(state.configDependencies));
176
+ watcher.add(Array.from(state.configBag.dependencies));
175
177
  watcher.add(state.contentPatterns.all);
176
178
  }
177
179
  };
package/lib/cli/index.js CHANGED
@@ -1,18 +1,230 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", {
3
4
  value: true
4
5
  });
5
- _exportStar(require("./build"), exports);
6
- _exportStar(require("./config"), exports);
7
- _exportStar(require("./content"), exports);
8
- function _exportStar(from, to) {
9
- Object.keys(from).forEach(function(k) {
10
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
11
- enumerable: true,
12
- get: function() {
13
- return from[k];
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("./build");
10
+ const _help = require("./help");
11
+ const _init = require("./init");
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ function oneOf(...options) {
18
+ return Object.assign((value = true)=>{
19
+ for (let option of options){
20
+ let parsed = option(value);
21
+ if (parsed === value) {
22
+ return parsed;
14
23
  }
24
+ }
25
+ throw new Error("...");
26
+ }, {
27
+ manualParsing: true
28
+ });
29
+ }
30
+ let commands = {
31
+ init: {
32
+ run: _init.init,
33
+ args: {
34
+ "--esm": {
35
+ type: Boolean,
36
+ description: `Initialize configuration file as ESM`
37
+ },
38
+ "--ts": {
39
+ type: Boolean,
40
+ description: `Initialize configuration file as TypeScript`
41
+ },
42
+ "--postcss": {
43
+ type: Boolean,
44
+ description: `Initialize a \`postcss.config.js\` file`
45
+ },
46
+ "--full": {
47
+ type: Boolean,
48
+ description: `Include the default values for all options in the generated configuration file`
49
+ },
50
+ "-f": "--full",
51
+ "-p": "--postcss"
52
+ }
53
+ },
54
+ build: {
55
+ run: _build.build,
56
+ args: {
57
+ "--input": {
58
+ type: String,
59
+ description: "Input file"
60
+ },
61
+ "--output": {
62
+ type: String,
63
+ description: "Output file"
64
+ },
65
+ "--watch": {
66
+ type: oneOf(String, Boolean),
67
+ description: "Watch for changes and rebuild as needed"
68
+ },
69
+ "--poll": {
70
+ type: Boolean,
71
+ description: "Use polling instead of filesystem events when watching"
72
+ },
73
+ "--content": {
74
+ type: String,
75
+ description: "Content paths to use for removing unused classes"
76
+ },
77
+ "--purge": {
78
+ type: String,
79
+ deprecated: true
80
+ },
81
+ "--postcss": {
82
+ type: oneOf(String, Boolean),
83
+ description: "Load custom PostCSS configuration"
84
+ },
85
+ "--minify": {
86
+ type: Boolean,
87
+ description: "Minify the output"
88
+ },
89
+ "--config": {
90
+ type: String,
91
+ description: "Path to a custom config file"
92
+ },
93
+ "--no-autoprefixer": {
94
+ type: Boolean,
95
+ description: "Disable autoprefixer"
96
+ },
97
+ "-c": "--config",
98
+ "-i": "--input",
99
+ "-o": "--output",
100
+ "-m": "--minify",
101
+ "-w": "--watch",
102
+ "-p": "--poll"
103
+ }
104
+ }
105
+ };
106
+ let sharedFlags = {
107
+ "--help": {
108
+ type: Boolean,
109
+ description: "Display usage information"
110
+ },
111
+ "-h": "--help"
112
+ };
113
+ if (process.stdout.isTTY /* Detect redirecting output to a file */ && (process.argv[2] === undefined || process.argv.slice(2).every((flag)=>sharedFlags[flag] !== undefined))) {
114
+ (0, _help.help)({
115
+ usage: [
116
+ "tailwindcss [--input input.css] [--output output.css] [--watch] [options...]",
117
+ "tailwindcss init [--full] [--postcss] [options...]"
118
+ ],
119
+ commands: Object.keys(commands).filter((command)=>command !== "build").map((command)=>`${command} [options]`),
120
+ options: {
121
+ ...commands.build.args,
122
+ ...sharedFlags
123
+ }
124
+ });
125
+ process.exit(0);
126
+ }
127
+ let command = ((arg = "")=>arg.startsWith("-") ? undefined : arg)(process.argv[2]) || "build";
128
+ if (commands[command] === undefined) {
129
+ if (_fs.default.existsSync(_path.default.resolve(command))) {
130
+ // TODO: Deprecate this in future versions
131
+ // Check if non-existing command, might be a file.
132
+ command = "build";
133
+ } else {
134
+ (0, _help.help)({
135
+ message: `Invalid command: ${command}`,
136
+ usage: [
137
+ "tailwindcss <command> [options]"
138
+ ],
139
+ commands: Object.keys(commands).filter((command)=>command !== "build").map((command)=>`${command} [options]`),
140
+ options: sharedFlags
15
141
  });
142
+ process.exit(1);
143
+ }
144
+ }
145
+ // Execute command
146
+ let { args: flags , run } = commands[command];
147
+ let args = (()=>{
148
+ try {
149
+ let result = (0, _arg.default)(Object.fromEntries(Object.entries({
150
+ ...flags,
151
+ ...sharedFlags
152
+ }).filter(([_key, value])=>{
153
+ var _value_type;
154
+ return !(value === null || value === void 0 ? void 0 : (_value_type = value.type) === null || _value_type === void 0 ? void 0 : _value_type.manualParsing);
155
+ }).map(([key, value])=>[
156
+ key,
157
+ typeof value === "object" ? value.type : value
158
+ ])), {
159
+ permissive: true
160
+ });
161
+ // Manual parsing of flags to allow for special flags like oneOf(Boolean, String)
162
+ for(let i = result["_"].length - 1; i >= 0; --i){
163
+ let flag = result["_"][i];
164
+ if (!flag.startsWith("-")) continue;
165
+ let [flagName, flagValue] = flag.split("=");
166
+ let handler = flags[flagName];
167
+ // Resolve flagName & handler
168
+ while(typeof handler === "string"){
169
+ flagName = handler;
170
+ handler = flags[handler];
171
+ }
172
+ if (!handler) continue;
173
+ let args = [];
174
+ let offset = i + 1;
175
+ // --flag value syntax was used so we need to pull `value` from `args`
176
+ if (flagValue === undefined) {
177
+ // Parse args for current flag
178
+ while(result["_"][offset] && !result["_"][offset].startsWith("-")){
179
+ args.push(result["_"][offset++]);
180
+ }
181
+ // Cleanup manually parsed flags + args
182
+ result["_"].splice(i, 1 + args.length);
183
+ // No args were provided, use default value defined in handler
184
+ // One arg was provided, use that directly
185
+ // Multiple args were provided so pass them all in an array
186
+ flagValue = args.length === 0 ? undefined : args.length === 1 ? args[0] : args;
187
+ } else {
188
+ // Remove the whole flag from the args array
189
+ result["_"].splice(i, 1);
190
+ }
191
+ // Set the resolved value in the `result` object
192
+ result[flagName] = handler.type(flagValue, flagName);
193
+ }
194
+ // Ensure that the `command` is always the first argument in the `args`.
195
+ // This is important so that we don't have to check if a default command
196
+ // (build) was used or not from within each plugin.
197
+ //
198
+ // E.g.: tailwindcss input.css -> _: ['build', 'input.css']
199
+ // E.g.: tailwindcss build input.css -> _: ['build', 'input.css']
200
+ if (result["_"][0] !== command) {
201
+ result["_"].unshift(command);
202
+ }
203
+ return result;
204
+ } catch (err) {
205
+ if (err.code === "ARG_UNKNOWN_OPTION") {
206
+ (0, _help.help)({
207
+ message: err.message,
208
+ usage: [
209
+ "tailwindcss <command> [options]"
210
+ ],
211
+ options: sharedFlags
212
+ });
213
+ process.exit(1);
214
+ }
215
+ throw err;
216
+ }
217
+ })();
218
+ if (args["--help"]) {
219
+ (0, _help.help)({
220
+ options: {
221
+ ...flags,
222
+ ...sharedFlags
223
+ },
224
+ usage: [
225
+ `tailwindcss ${command} [options]`
226
+ ]
16
227
  });
17
- return from;
228
+ process.exit(0);
18
229
  }
230
+ run(args);
@@ -14,25 +14,40 @@ function _interopRequireDefault(obj) {
14
14
  default: obj
15
15
  };
16
16
  }
17
- function init(args, configs) {
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;
24
+ }
25
+ }
26
+ function init(args) {
18
27
  let messages = [];
19
- var ref;
20
- let tailwindConfigLocation = _path.default.resolve((ref = args["_"][1]) !== null && ref !== void 0 ? ref : `./${configs.tailwind}`);
28
+ let isProjectESM = args["--ts"] || args["--esm"] || isESM();
29
+ let syntax = args["--ts"] ? "ts" : isProjectESM ? "js" : "cjs";
30
+ let extension = args["--ts"] ? "ts" : "js";
31
+ var _args___;
32
+ let tailwindConfigLocation = _path.default.resolve((_args___ = args["_"][1]) !== null && _args___ !== void 0 ? _args___ : `./tailwind.config.${extension}`);
21
33
  if (_fs.default.existsSync(tailwindConfigLocation)) {
22
34
  messages.push(`${_path.default.basename(tailwindConfigLocation)} already exists.`);
23
35
  } else {
24
- let stubFile = _fs.default.readFileSync(args["--full"] ? _path.default.resolve(__dirname, "../../../stubs/defaultConfig.stub.js") : _path.default.resolve(__dirname, "../../../stubs/simpleConfig.stub.js"), "utf8");
36
+ let stubContentsFile = _fs.default.readFileSync(args["--full"] ? _path.default.resolve(__dirname, "../../../stubs/config.full.js") : _path.default.resolve(__dirname, "../../../stubs/config.simple.js"), "utf8");
37
+ let stubFile = _fs.default.readFileSync(_path.default.resolve(__dirname, `../../../stubs/tailwind.config.${syntax}`), "utf8");
25
38
  // Change colors import
26
- stubFile = stubFile.replace("../colors", "tailwindcss/colors");
39
+ stubContentsFile = stubContentsFile.replace("../colors", "tailwindcss/colors");
40
+ // Replace contents of {ts,js,cjs} file with the stub {simple,full}.
41
+ stubFile = stubFile.replace("__CONFIG__", stubContentsFile.replace("module.exports =", "").trim()).trim() + "\n\n";
27
42
  _fs.default.writeFileSync(tailwindConfigLocation, stubFile, "utf8");
28
43
  messages.push(`Created Tailwind CSS config file: ${_path.default.basename(tailwindConfigLocation)}`);
29
44
  }
30
45
  if (args["--postcss"]) {
31
- let postcssConfigLocation = _path.default.resolve(`./${configs.postcss}`);
46
+ let postcssConfigLocation = _path.default.resolve("./postcss.config.js");
32
47
  if (_fs.default.existsSync(postcssConfigLocation)) {
33
48
  messages.push(`${_path.default.basename(postcssConfigLocation)} already exists.`);
34
49
  } else {
35
- let stubFile1 = _fs.default.readFileSync(_path.default.resolve(__dirname, "../../../stubs/defaultPostCssConfig.stub.js"), "utf8");
50
+ let stubFile1 = _fs.default.readFileSync(isProjectESM ? _path.default.resolve(__dirname, "../../../stubs/postcss.config.js") : _path.default.resolve(__dirname, "../../../stubs/postcss.config.cjs"), "utf8");
36
51
  _fs.default.writeFileSync(postcssConfigLocation, stubFile1, "utf8");
37
52
  messages.push(`Created PostCSS config file: ${_path.default.basename(postcssConfigLocation)}`);
38
53
  }