tailwindcss-patch 5.0.1 → 6.0.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.
@@ -1,53 +1,20 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
-
26
- // ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.3.3_postcss@8.4.47_tsx@4.19.2_typescript@5.6.3_yaml@2.6.0/node_modules/tsup/assets/cjs_shims.js
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// ../../node_modules/.pnpm/tsup@8.3.6_jiti@2.4.2_postcss@8.5.2_tsx@4.19.2_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/cjs_shims.js
27
2
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
28
3
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
29
4
 
30
- // src/cli.ts
31
- var import_node_process4 = __toESM(require("process"), 1);
32
- var import_cac = __toESM(require("cac"), 1);
33
-
34
- // src/config.ts
35
- var config_exports = {};
36
- __reExport(config_exports, require("@tailwindcss-mangle/config"));
5
+ // src/logger.ts
6
+ var _consola = require('consola');
7
+ var logger = _consola.createConsola.call(void 0, );
8
+ var logger_default = logger;
37
9
 
38
10
  // src/core/cache.ts
39
- var import_node_process = __toESM(require("process"), 1);
40
- var import_fs_extra = __toESM(require("fs-extra"), 1);
41
- var import_pathe = __toESM(require("pathe"), 1);
11
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
12
+ var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
13
+ var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
42
14
 
43
15
  // src/constants.ts
44
16
  var pkgName = "tailwindcss-patch";
45
17
 
46
- // src/logger.ts
47
- var import_consola = require("consola");
48
- var logger = (0, import_consola.createConsola)();
49
- var logger_default = logger;
50
-
51
18
  // src/core/cache.ts
52
19
  function getCacheOptions(options) {
53
20
  let cache;
@@ -72,15 +39,15 @@ function getCacheOptions(options) {
72
39
  return cache;
73
40
  }
74
41
  var CacheManager = class {
75
- options;
42
+
76
43
  constructor(options = {}) {
77
44
  this.options = this.getOptions(options);
78
45
  }
79
46
  getOptions(options = {}) {
80
- const cwd = options.cwd ?? import_node_process.default.cwd();
81
- const dir = options.dir ?? import_pathe.default.resolve(cwd, "node_modules/.cache", pkgName);
82
- const file = options.file ?? "index.json";
83
- const filename = import_pathe.default.resolve(dir, file);
47
+ const cwd = _nullishCoalesce(options.cwd, () => ( _process2.default.cwd()));
48
+ const dir = _nullishCoalesce(options.dir, () => ( _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName)));
49
+ const file = _nullishCoalesce(options.file, () => ( "index.json"));
50
+ const filename = _pathe2.default.resolve(dir, file);
84
51
  return {
85
52
  cwd,
86
53
  dir,
@@ -92,38 +59,33 @@ var CacheManager = class {
92
59
  write(data) {
93
60
  try {
94
61
  const { dir, filename } = this.options;
95
- import_fs_extra.default.ensureDirSync(dir);
96
- import_fs_extra.default.outputFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
62
+ _fsextra2.default.ensureDirSync(dir);
63
+ _fsextra2.default.outputFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
97
64
  return filename;
98
- } catch {
65
+ } catch (e2) {
99
66
  logger_default.error("write cache file fail!");
100
67
  }
101
68
  }
102
69
  read() {
103
70
  const { filename } = this.options;
104
71
  try {
105
- if (import_fs_extra.default.existsSync(filename)) {
106
- const data = import_fs_extra.default.readFileSync(filename, "utf8");
72
+ if (_fsextra2.default.existsSync(filename)) {
73
+ const data = _fsextra2.default.readFileSync(filename, "utf8");
107
74
  return new Set(JSON.parse(data));
108
75
  }
109
- } catch {
76
+ } catch (e3) {
110
77
  logger_default.error(`parse cache content fail! path:${filename}`);
111
78
  try {
112
- import_fs_extra.default.unlinkSync(filename);
113
- } catch {
79
+ _fsextra2.default.unlinkSync(filename);
80
+ } catch (e4) {
114
81
  logger_default.error(`delete cache file fail! path:${filename}`);
115
82
  }
116
83
  }
117
84
  }
118
85
  };
119
86
 
120
- // src/core/patcher.ts
121
- var import_node_module3 = require("module");
122
- var import_fs_extra5 = __toESM(require("fs-extra"), 1);
123
- var import_pathe7 = __toESM(require("pathe"), 1);
124
-
125
87
  // src/defaults.ts
126
- var import_node_process2 = __toESM(require("process"), 1);
88
+
127
89
 
128
90
  // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
129
91
  function isPlainObject(value) {
@@ -229,149 +191,39 @@ function getPatchOptions(options) {
229
191
  return defu(
230
192
  options,
231
193
  {
232
- basedir: import_node_process2.default.cwd()
194
+ basedir: _process2.default.cwd()
233
195
  },
234
196
  getDefaultPatchOptions()
235
197
  );
236
198
  }
237
199
 
238
- // src/utils.ts
239
- var import_fs_extra2 = __toESM(require("fs-extra"), 1);
240
- var import_pathe2 = __toESM(require("pathe"), 1);
241
- var import_resolve = __toESM(require("resolve"), 1);
242
- var { sync } = import_resolve.default;
243
- function requireResolve(id, opts) {
244
- return sync(id, opts);
245
- }
246
- function searchPackageJSON(dir) {
247
- let packageJsonPath;
248
- while (true) {
249
- if (!dir) {
250
- return;
251
- }
252
- const newDir = import_pathe2.default.dirname(dir);
253
- if (newDir === dir) {
254
- return;
255
- }
256
- dir = newDir;
257
- packageJsonPath = import_pathe2.default.join(dir, "package.json");
258
- if (import_fs_extra2.default.existsSync(packageJsonPath)) {
259
- break;
260
- }
261
- }
262
- return packageJsonPath;
263
- }
264
- function getTailwindcssEntry(name = "tailwindcss", opts) {
265
- return requireResolve(name, opts);
266
- }
267
- function getPackageJsonPath(name, options = {}) {
268
- const entry = getTailwindcssEntry(name, options);
269
- if (!entry) {
270
- return;
271
- }
272
- return searchPackageJSON(entry);
273
- }
274
- function getPackageInfoSync(name, options = {}) {
275
- const packageJsonPath = getPackageJsonPath(name, options);
276
- if (!packageJsonPath) {
277
- return;
278
- }
279
- const packageJson = JSON.parse(import_fs_extra2.default.readFileSync(packageJsonPath, "utf8"));
280
- return {
281
- name,
282
- version: packageJson.version,
283
- rootPath: import_pathe2.default.dirname(packageJsonPath),
284
- packageJsonPath,
285
- packageJson
286
- };
287
- }
288
- function isObject(val) {
289
- return val !== null && typeof val === "object" && Array.isArray(val) === false;
290
- }
291
-
292
- // src/core/postcss.ts
293
- var import_node_module = require("module");
294
- var import_node_process3 = __toESM(require("process"), 1);
295
- var import_lilconfig = require("lilconfig");
296
- var import_pathe3 = __toESM(require("pathe"), 1);
297
- var import_postcss = __toESM(require("postcss"), 1);
298
- var require2 = (0, import_node_module.createRequire)(importMetaUrl);
299
- async function processTailwindcss(options) {
300
- const { config: userConfig, cwd } = defu(options, {
301
- cwd: import_node_process3.default.cwd()
302
- });
303
- let config = userConfig;
304
- if (!(typeof config === "string" && import_pathe3.default.isAbsolute(config))) {
305
- const moduleName = "tailwind";
306
- const tsx = (await import("tsx/cjs/api")).require;
307
- const result = await (0, import_lilconfig.lilconfig)("tailwindcss", {
308
- searchPlaces: [
309
- `${moduleName}.config.js`,
310
- `${moduleName}.config.cjs`,
311
- `${moduleName}.config.mjs`,
312
- `${moduleName}.config.ts`,
313
- `${moduleName}.config.cts`,
314
- `${moduleName}.config.mts`
315
- ],
316
- loaders: {
317
- // 默认支持 js 和 cjs 2种格式
318
- ".js": tsx,
319
- ".cjs": tsx,
320
- ".mjs": tsx,
321
- ".ts": tsx,
322
- ".cts": tsx,
323
- ".mts": tsx
324
- }
325
- }).search(cwd);
326
- if (!result) {
327
- throw new Error(`No TailwindCSS Config found in: ${cwd}`);
328
- }
329
- config = result.filepath;
330
- }
331
- const id = requireResolve("tailwindcss", {
332
- basedir: cwd
333
- });
334
- return await (0, import_postcss.default)([
335
- require2(id)({
336
- config
337
- })
338
- ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
339
- from: void 0
340
- });
341
- }
200
+ // src/core/patches/exportContext/index.ts
342
201
 
343
- // src/core/runtime.ts
344
- var import_node_module2 = require("module");
345
- var import_pathe6 = __toESM(require("pathe"), 1);
346
- var import_semver = require("semver");
347
202
 
348
- // src/core/patches/exportContext/index.ts
349
- var import_fs_extra3 = __toESM(require("fs-extra"), 1);
350
- var import_pathe4 = __toESM(require("pathe"), 1);
351
203
 
352
204
  // src/core/patches/exportContext/postcss-v2.ts
353
- var t = __toESM(require("@babel/types"), 1);
205
+ var _types = require('@babel/types'); var t = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types);
354
206
 
355
207
  // src/babel/index.ts
356
- var import_generator = __toESM(require("@babel/generator"), 1);
357
- var import_traverse = __toESM(require("@babel/traverse"), 1);
358
- var import_parser = require("@babel/parser");
208
+ var _generator = require('@babel/generator'); var _generator2 = _interopRequireDefault(_generator);
209
+ var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
210
+ var _parser = require('@babel/parser');
359
211
  function _interopDefaultCompat(e) {
360
212
  return e && typeof e === "object" && "default" in e ? e.default : e;
361
213
  }
362
- var generate = _interopDefaultCompat(import_generator.default);
363
- var traverse = _interopDefaultCompat(import_traverse.default);
214
+ var generate = _interopDefaultCompat(_generator2.default);
215
+ var traverse = _interopDefaultCompat(_traverse2.default);
364
216
 
365
217
  // src/core/patches/exportContext/postcss-v2.ts
366
218
  function inspectProcessTailwindFeaturesReturnContext(content) {
367
- const ast = (0, import_parser.parse)(content, {
219
+ const ast = _parser.parse.call(void 0, content, {
368
220
  sourceType: "unambiguous"
369
221
  });
370
222
  let hasPatched = false;
371
223
  traverse(ast, {
372
224
  FunctionDeclaration(p) {
373
225
  const n = p.node;
374
- if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
226
+ if (_optionalChain([n, 'access', _ => _.id, 'optionalAccess', _2 => _2.name]) === "processTailwindFeatures" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
375
227
  const rts = n.body.body[0];
376
228
  if (t.isFunctionExpression(rts.argument)) {
377
229
  const body = rts.argument.body.body;
@@ -391,7 +243,7 @@ function inspectProcessTailwindFeaturesReturnContext(content) {
391
243
  };
392
244
  }
393
245
  function inspectPostcssPlugin(content) {
394
- const ast = (0, import_parser.parse)(content);
246
+ const ast = _parser.parse.call(void 0, content);
395
247
  const exportKey = "contextRef";
396
248
  const variableName = "contextRef";
397
249
  const valueKey = "value";
@@ -400,7 +252,7 @@ function inspectPostcssPlugin(content) {
400
252
  Program(p) {
401
253
  const n = p.node;
402
254
  const idx = n.body.findIndex((x) => {
403
- return t.isFunctionDeclaration(x) && x.id?.name === "_default";
255
+ return t.isFunctionDeclaration(x) && _optionalChain([x, 'access', _3 => _3.id, 'optionalAccess', _4 => _4.name]) === "_default";
404
256
  });
405
257
  if (idx > -1) {
406
258
  const prevStatement = n.body[idx - 1];
@@ -433,7 +285,7 @@ function inspectPostcssPlugin(content) {
433
285
  return;
434
286
  }
435
287
  const n = p.node;
436
- if (n.id?.name === "_default" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
288
+ if (_optionalChain([n, 'access', _5 => _5.id, 'optionalAccess', _6 => _6.name]) === "_default" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
437
289
  const returnStatement3 = n.body.body[0];
438
290
  if (t.isCallExpression(returnStatement3.argument) && t.isMemberExpression(returnStatement3.argument.callee) && t.isArrayExpression(returnStatement3.argument.callee.object)) {
439
291
  const targetFn = returnStatement3.argument.callee.object.elements[1];
@@ -497,14 +349,14 @@ function inspectPostcssPlugin(content) {
497
349
  }
498
350
 
499
351
  // src/core/patches/exportContext/postcss-v3.ts
500
- var t2 = __toESM(require("@babel/types"), 1);
352
+
501
353
  function inspectProcessTailwindFeaturesReturnContext2(content) {
502
- const ast = (0, import_parser.parse)(content);
354
+ const ast = _parser.parse.call(void 0, content);
503
355
  let hasPatched = false;
504
356
  traverse(ast, {
505
357
  FunctionDeclaration(p) {
506
358
  const n = p.node;
507
- if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
359
+ if (_optionalChain([n, 'access', _7 => _7.id, 'optionalAccess', _8 => _8.name]) === "processTailwindFeatures" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
508
360
  const rts = n.body.body[0];
509
361
  if (t2.isFunctionExpression(rts.argument)) {
510
362
  const body = rts.argument.body.body;
@@ -524,7 +376,7 @@ function inspectProcessTailwindFeaturesReturnContext2(content) {
524
376
  };
525
377
  }
526
378
  function inspectPostcssPlugin2(content) {
527
- const ast = (0, import_parser.parse)(content);
379
+ const ast = _parser.parse.call(void 0, content);
528
380
  const exportKey = "contextRef";
529
381
  const variableName = "contextRef";
530
382
  const valueKey = "value";
@@ -533,7 +385,7 @@ function inspectPostcssPlugin2(content) {
533
385
  Program(p) {
534
386
  const n = p.node;
535
387
  const idx = n.body.findIndex((x) => {
536
- return t2.isExpressionStatement(x) && t2.isAssignmentExpression(x.expression) && t2.isMemberExpression(x.expression.left) && t2.isFunctionExpression(x.expression.right) && x.expression.right.id?.name === "tailwindcss";
388
+ return t2.isExpressionStatement(x) && t2.isAssignmentExpression(x.expression) && t2.isMemberExpression(x.expression.left) && t2.isFunctionExpression(x.expression.right) && _optionalChain([x, 'access', _9 => _9.expression, 'access', _10 => _10.right, 'access', _11 => _11.id, 'optionalAccess', _12 => _12.name]) === "tailwindcss";
537
389
  });
538
390
  if (idx > -1) {
539
391
  const prevStatement = n.body[idx - 1];
@@ -563,7 +415,7 @@ function inspectPostcssPlugin2(content) {
563
415
  return;
564
416
  }
565
417
  const n = p.node;
566
- if (n.id?.name === "tailwindcss" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
418
+ if (_optionalChain([n, 'access', _13 => _13.id, 'optionalAccess', _14 => _14.name]) === "tailwindcss" && n.body.body.length === 1 && t2.isReturnStatement(n.body.body[0])) {
567
419
  const returnStatement3 = n.body.body[0];
568
420
  if (t2.isObjectExpression(returnStatement3.argument) && returnStatement3.argument.properties.length === 2) {
569
421
  const properties = returnStatement3.argument.properties;
@@ -638,13 +490,13 @@ function inspectPostcssPlugin2(content) {
638
490
  // src/core/patches/exportContext/index.ts
639
491
  function monkeyPatchForExposingContextV3(twDir, opt) {
640
492
  const k0 = "lib/processTailwindFeatures.js";
641
- const processTailwindFeaturesFilePath = import_pathe4.default.resolve(twDir, k0);
642
- const processTailwindFeaturesContent = import_fs_extra3.default.readFileSync(processTailwindFeaturesFilePath, "utf8");
493
+ const processTailwindFeaturesFilePath = _pathe2.default.resolve(twDir, k0);
494
+ const processTailwindFeaturesContent = _fsextra2.default.readFileSync(processTailwindFeaturesFilePath, "utf8");
643
495
  const result = {};
644
496
  if (processTailwindFeaturesContent) {
645
497
  const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext2(processTailwindFeaturesContent);
646
498
  if (!hasPatched && opt.overwrite) {
647
- import_fs_extra3.default.writeFileSync(processTailwindFeaturesFilePath, code, {
499
+ _fsextra2.default.writeFileSync(processTailwindFeaturesFilePath, code, {
648
500
  encoding: "utf8"
649
501
  });
650
502
  logger_default.success("patch tailwindcss processTailwindFeatures for return context successfully!");
@@ -655,21 +507,21 @@ function monkeyPatchForExposingContextV3(twDir, opt) {
655
507
  let k1;
656
508
  const try0 = "lib/plugin.js";
657
509
  const try1 = "lib/index.js";
658
- const pluginFilePath = import_pathe4.default.resolve(twDir, try0);
659
- const indexFilePath = import_pathe4.default.resolve(twDir, try1);
660
- if (import_fs_extra3.default.existsSync(pluginFilePath)) {
510
+ const pluginFilePath = _pathe2.default.resolve(twDir, try0);
511
+ const indexFilePath = _pathe2.default.resolve(twDir, try1);
512
+ if (_fsextra2.default.existsSync(pluginFilePath)) {
661
513
  k1 = try0;
662
514
  injectFilepath = pluginFilePath;
663
- } else if (import_fs_extra3.default.existsSync(indexFilePath)) {
515
+ } else if (_fsextra2.default.existsSync(indexFilePath)) {
664
516
  k1 = try1;
665
517
  injectFilepath = indexFilePath;
666
518
  }
667
519
  if (injectFilepath && k1) {
668
- const pluginContent = import_fs_extra3.default.readFileSync(injectFilepath, "utf8");
520
+ const pluginContent = _fsextra2.default.readFileSync(injectFilepath, "utf8");
669
521
  if (pluginContent) {
670
522
  const { code, hasPatched } = inspectPostcssPlugin2(pluginContent);
671
523
  if (!hasPatched && opt.overwrite) {
672
- import_fs_extra3.default.writeFileSync(injectFilepath, code, {
524
+ _fsextra2.default.writeFileSync(injectFilepath, code, {
673
525
  encoding: "utf8"
674
526
  });
675
527
  logger_default.success("patch tailwindcss for expose runtime context successfully!");
@@ -681,13 +533,13 @@ function monkeyPatchForExposingContextV3(twDir, opt) {
681
533
  }
682
534
  function monkeyPatchForExposingContextV2(twDir, opt) {
683
535
  const k0 = "lib/jit/processTailwindFeatures.js";
684
- const processTailwindFeaturesFilePath = import_pathe4.default.resolve(twDir, k0);
685
- const processTailwindFeaturesContent = import_fs_extra3.default.readFileSync(processTailwindFeaturesFilePath, "utf8");
536
+ const processTailwindFeaturesFilePath = _pathe2.default.resolve(twDir, k0);
537
+ const processTailwindFeaturesContent = _fsextra2.default.readFileSync(processTailwindFeaturesFilePath, "utf8");
686
538
  const result = {};
687
539
  if (processTailwindFeaturesContent) {
688
540
  const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
689
541
  if (!hasPatched && opt.overwrite) {
690
- import_fs_extra3.default.writeFileSync(processTailwindFeaturesFilePath, code, {
542
+ _fsextra2.default.writeFileSync(processTailwindFeaturesFilePath, code, {
691
543
  encoding: "utf8"
692
544
  });
693
545
  logger_default.success("patch tailwindcss processTailwindFeatures for return content successfully!");
@@ -695,12 +547,12 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
695
547
  result[k0] = code;
696
548
  }
697
549
  const k1 = "lib/jit/index.js";
698
- const indexFilePath = import_pathe4.default.resolve(twDir, k1);
699
- const pluginContent = import_fs_extra3.default.readFileSync(indexFilePath, "utf8");
550
+ const indexFilePath = _pathe2.default.resolve(twDir, k1);
551
+ const pluginContent = _fsextra2.default.readFileSync(indexFilePath, "utf8");
700
552
  if (pluginContent) {
701
553
  const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
702
554
  if (!hasPatched && opt.overwrite) {
703
- import_fs_extra3.default.writeFileSync(indexFilePath, code, {
555
+ _fsextra2.default.writeFileSync(indexFilePath, code, {
704
556
  encoding: "utf8"
705
557
  });
706
558
  logger_default.success("patch tailwindcss for expose runtime content successfully!");
@@ -711,32 +563,32 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
711
563
  }
712
564
 
713
565
  // src/core/patches/supportCustomUnits/index.ts
714
- var t3 = __toESM(require("@babel/types"), 1);
715
- var import_fs_extra4 = __toESM(require("fs-extra"), 1);
716
- var import_pathe5 = __toESM(require("pathe"), 1);
566
+
567
+
568
+
717
569
  function findAstNode(content, options) {
718
570
  const { variableName, units } = options;
719
- const ast = (0, import_parser.parse)(content);
571
+ const ast = _parser.parse.call(void 0, content);
720
572
  let arrayRef;
721
573
  let changed = false;
722
574
  traverse(ast, {
723
- Identifier(path8) {
724
- if (path8.node.name === variableName && t3.isVariableDeclarator(path8.parent) && t3.isArrayExpression(path8.parent.init)) {
725
- arrayRef = path8.parent.init;
726
- const set = new Set(path8.parent.init.elements.map((x) => x.value));
575
+ Identifier(path7) {
576
+ if (path7.node.name === variableName && t3.isVariableDeclarator(path7.parent) && t3.isArrayExpression(path7.parent.init)) {
577
+ arrayRef = path7.parent.init;
578
+ const set = new Set(path7.parent.init.elements.map((x) => x.value));
727
579
  for (let i = 0; i < units.length; i++) {
728
580
  const unit = units[i];
729
581
  if (!set.has(unit)) {
730
- path8.parent.init.elements = path8.parent.init.elements.map((x) => {
582
+ path7.parent.init.elements = path7.parent.init.elements.map((x) => {
731
583
  if (t3.isStringLiteral(x)) {
732
584
  return {
733
- type: x?.type,
734
- value: x?.value
585
+ type: _optionalChain([x, 'optionalAccess', _15 => _15.type]),
586
+ value: _optionalChain([x, 'optionalAccess', _16 => _16.value])
735
587
  };
736
588
  }
737
589
  return x;
738
590
  });
739
- path8.parent.init.elements.push({
591
+ path7.parent.init.elements.push({
740
592
  type: "StringLiteral",
741
593
  value: unit
742
594
  });
@@ -759,8 +611,8 @@ function monkeyPatchForSupportingCustomUnit(rootDir, options) {
759
611
  overwrite: true
760
612
  });
761
613
  const { lengthUnitsFilePath, overwrite, destPath } = opts;
762
- const dataTypesFilePath = import_pathe5.default.resolve(rootDir, lengthUnitsFilePath);
763
- const dataTypesFileContent = import_fs_extra4.default.readFileSync(dataTypesFilePath, {
614
+ const dataTypesFilePath = _pathe2.default.resolve(rootDir, lengthUnitsFilePath);
615
+ const dataTypesFileContent = _fsextra2.default.readFileSync(dataTypesFilePath, {
764
616
  encoding: "utf8"
765
617
  });
766
618
  const { arrayRef, changed } = findAstNode(dataTypesFileContent, opts);
@@ -775,7 +627,7 @@ function monkeyPatchForSupportingCustomUnit(rootDir, options) {
775
627
  const next = dataTypesFileContent.slice(arrayRef.end);
776
628
  const newCode = prev + code + next;
777
629
  if (overwrite) {
778
- import_fs_extra4.default.writeFileSync(destPath ?? dataTypesFilePath, newCode, {
630
+ _fsextra2.default.writeFileSync(_nullishCoalesce(destPath, () => ( dataTypesFilePath)), newCode, {
779
631
  encoding: "utf8"
780
632
  });
781
633
  logger_default.success("patch tailwindcss for custom length unit successfully!");
@@ -788,28 +640,31 @@ function monkeyPatchForSupportingCustomUnit(rootDir, options) {
788
640
  }
789
641
 
790
642
  // src/core/runtime.ts
791
- var require3 = (0, import_node_module2.createRequire)(importMetaUrl);
643
+ var _module = require('module');
644
+
645
+ var _semver = require('semver');
646
+ var require2 = _module.createRequire.call(void 0, importMetaUrl);
792
647
  function internalPatch(pkgJsonPath, options) {
793
648
  if (pkgJsonPath) {
794
- const pkgJson = require3(pkgJsonPath);
795
- const twDir = import_pathe6.default.dirname(pkgJsonPath);
649
+ const pkgJson = require2(pkgJsonPath);
650
+ const twDir = _pathe2.default.dirname(pkgJsonPath);
796
651
  options.version = pkgJson.version;
797
- if ((0, import_semver.gte)(pkgJson.version, "3.0.0")) {
652
+ if (_semver.gte.call(void 0, pkgJson.version, "3.0.0")) {
798
653
  let result = {};
799
- if (options.applyPatches?.exportContext) {
654
+ if (_optionalChain([options, 'access', _17 => _17.applyPatches, 'optionalAccess', _18 => _18.exportContext])) {
800
655
  result = monkeyPatchForExposingContextV3(twDir, options);
801
656
  }
802
- if (options.applyPatches?.extendLengthUnits) {
657
+ if (_optionalChain([options, 'access', _19 => _19.applyPatches, 'optionalAccess', _20 => _20.extendLengthUnits])) {
803
658
  try {
804
- Object.assign(result ?? {}, monkeyPatchForSupportingCustomUnit(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
659
+ Object.assign(_nullishCoalesce(result, () => ( {})), monkeyPatchForSupportingCustomUnit(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
805
660
  overwrite: options.overwrite
806
661
  })));
807
- } catch {
662
+ } catch (e5) {
808
663
  }
809
664
  }
810
665
  return result;
811
- } else if ((0, import_semver.gte)(pkgJson.version, "2.0.0")) {
812
- if (options.applyPatches?.exportContext) {
666
+ } else if (_semver.gte.call(void 0, pkgJson.version, "2.0.0")) {
667
+ if (_optionalChain([options, 'access', _21 => _21.applyPatches, 'optionalAccess', _22 => _22.exportContext])) {
813
668
  return monkeyPatchForExposingContextV2(twDir, options);
814
669
  }
815
670
  }
@@ -817,27 +672,125 @@ function internalPatch(pkgJsonPath, options) {
817
672
  }
818
673
 
819
674
  // src/core/patcher.ts
820
- var require4 = (0, import_node_module3.createRequire)(importMetaUrl);
821
- var TailwindcssPatcher = class {
822
- rawOptions;
823
- cacheOptions;
824
- patchOptions;
825
- patch;
826
- cacheManager;
827
- packageInfo;
828
- majorVersion;
829
- constructor(options = {}) {
675
+
676
+
677
+
678
+ var _localpkg = require('local-pkg');
679
+
680
+
681
+ // src/utils.ts
682
+ function isObject(val) {
683
+ return val !== null && typeof val === "object" && Array.isArray(val) === false;
684
+ }
685
+
686
+ // src/core/candidates.ts
687
+
688
+ function importNode() {
689
+ return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/node")));
690
+ }
691
+ function importOxide() {
692
+ return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/oxide")));
693
+ }
694
+ async function extractRawCandidates(sources) {
695
+ const { Scanner } = await importOxide();
696
+ const scanner = new Scanner({
697
+ sources
698
+ });
699
+ const candidates = scanner.scan();
700
+ return candidates;
701
+ }
702
+ async function extractValidCandidates(options) {
703
+ const cwd = _process2.default.cwd();
704
+ const { sources, base, css } = defuOverrideArray(
705
+ // @ts-ignore
706
+ options,
707
+ {
708
+ css: '@import "tailwindcss";',
709
+ base: cwd,
710
+ sources: [
711
+ {
712
+ base: cwd,
713
+ pattern: "**/*"
714
+ }
715
+ ]
716
+ }
717
+ );
718
+ const { __unstable__loadDesignSystem } = await importNode();
719
+ const designSystem = await __unstable__loadDesignSystem(css, { base });
720
+ const candidates = await extractRawCandidates(sources);
721
+ const validCandidates = candidates.filter(
722
+ (rawCandidate) => designSystem.parseCandidate(rawCandidate).length > 0
723
+ );
724
+ return validCandidates;
725
+ }
726
+
727
+ // src/core/postcss.ts
728
+
729
+
730
+
731
+ var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
732
+ var _tailwindcssconfig = require('tailwindcss-config');
733
+ var require3 = _module.createRequire.call(void 0, importMetaUrl);
734
+ async function processTailwindcss(options) {
735
+ const { config: userConfig, cwd, majorVersion, postcssPlugin } = defu(options, {
736
+ cwd: _process2.default.cwd(),
737
+ majorVersion: 3
738
+ });
739
+ let config = userConfig;
740
+ if (!(typeof config === "string" && _pathe2.default.isAbsolute(config))) {
741
+ const result = await _tailwindcssconfig.loadConfig.call(void 0, {
742
+ cwd
743
+ });
744
+ if (!result) {
745
+ throw new Error(`No TailwindCSS Config found in: ${cwd}`);
746
+ }
747
+ config = result.filepath;
748
+ }
749
+ const targetPostcssPlugin = _nullishCoalesce(postcssPlugin, () => ( (majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
750
+ if (majorVersion === 4) {
751
+ return await _postcss2.default.call(void 0, [
752
+ require3(targetPostcssPlugin)({
753
+ config
754
+ })
755
+ ]).process("@import 'tailwindcss';", {
756
+ from: void 0
757
+ });
758
+ }
759
+ return await _postcss2.default.call(void 0, [
760
+ require3(targetPostcssPlugin)({
761
+ config
762
+ })
763
+ ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
764
+ from: void 0
765
+ });
766
+ }
767
+
768
+ // src/core/patcher.ts
769
+ var require4 = _module.createRequire.call(void 0, importMetaUrl);
770
+ var TailwindcssPatcher = (_class = class {
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+ constructor(options = {}) {;_class.prototype.__init.call(this);
830
779
  this.rawOptions = options;
831
780
  this.cacheOptions = getCacheOptions(options.cache);
832
781
  this.patchOptions = getPatchOptions(options.patch);
833
782
  this.cacheManager = new CacheManager(this.cacheOptions);
834
- this.packageInfo = getPackageInfoSync("tailwindcss", { basedir: this.patchOptions.basedir });
835
- if (this.packageInfo && this.packageInfo.version) {
836
- this.majorVersion = Number.parseInt(this.packageInfo.version[0]);
783
+ const packageInfo = _localpkg.getPackageInfoSync.call(void 0, "tailwindcss");
784
+ if (!packageInfo) {
785
+ throw new Error("tailwindcss not found");
837
786
  }
787
+ if (packageInfo.version) {
788
+ this.majorVersion = Number.parseInt(packageInfo.version[0]);
789
+ }
790
+ this.packageInfo = packageInfo;
838
791
  this.patch = () => {
839
792
  try {
840
- return internalPatch(this.packageInfo?.packageJsonPath, this.patchOptions);
793
+ return internalPatch(_optionalChain([this, 'access', _23 => _23.packageInfo, 'optionalAccess', _24 => _24.packageJsonPath]), this.patchOptions);
841
794
  } catch (error) {
842
795
  logger_default.error(`patch tailwindcss failed: ${error.message}`);
843
796
  }
@@ -853,14 +806,14 @@ var TailwindcssPatcher = class {
853
806
  }
854
807
  getContexts() {
855
808
  if (this.packageInfo) {
856
- const distPath = import_pathe7.default.join(this.packageInfo.rootPath, "lib");
809
+ const distPath = _pathe2.default.join(this.packageInfo.rootPath, "lib");
857
810
  let injectFilePath;
858
811
  if (this.majorVersion === 2) {
859
- injectFilePath = import_pathe7.default.join(distPath, "jit/index.js");
860
- } else {
861
- injectFilePath = import_pathe7.default.join(distPath, "plugin.js");
862
- if (!import_fs_extra5.default.existsSync(injectFilePath)) {
863
- injectFilePath = import_pathe7.default.join(distPath, "index.js");
812
+ injectFilePath = _pathe2.default.join(distPath, "jit/index.js");
813
+ } else if (this.majorVersion === 3) {
814
+ injectFilePath = _pathe2.default.join(distPath, "plugin.js");
815
+ if (!_fsextra2.default.existsSync(injectFilePath)) {
816
+ injectFilePath = _pathe2.default.join(distPath, "index.js");
864
817
  }
865
818
  }
866
819
  if (injectFilePath) {
@@ -876,17 +829,62 @@ var TailwindcssPatcher = class {
876
829
  const contexts = this.getContexts();
877
830
  return contexts.filter((x) => isObject(x)).map((x) => x.classCache);
878
831
  }
879
- getClassCacheSet(options) {
880
- const classCaches = this.getClassCaches();
832
+ async getClassCacheSet(options) {
881
833
  const classSet = /* @__PURE__ */ new Set();
882
- for (const classCacheMap of classCaches) {
883
- const keys = classCacheMap.keys();
884
- for (const key of keys) {
885
- const v = key.toString();
886
- if (options?.removeUniversalSelector && v === "*") {
887
- continue;
834
+ const { output, tailwindcss } = _nullishCoalesce(options, () => ( {}));
835
+ if (this.majorVersion === 4) {
836
+ const { v4 } = _nullishCoalesce(tailwindcss, () => ( {}));
837
+ if (Array.isArray(_optionalChain([v4, 'optionalAccess', _25 => _25.cssEntries]))) {
838
+ const results = (await Promise.all(
839
+ v4.cssEntries.map(async (x) => {
840
+ if (await _fsextra2.default.exists(x)) {
841
+ const css = await _fsextra2.default.readFile(x, "utf8");
842
+ return css;
843
+ }
844
+ return false;
845
+ })
846
+ )).filter((x) => x);
847
+ for (const css of results) {
848
+ const candidates = await extractValidCandidates({
849
+ base: _optionalChain([v4, 'optionalAccess', _26 => _26.base]),
850
+ css,
851
+ sources: _optionalChain([v4, 'optionalAccess', _27 => _27.sources, 'optionalAccess', _28 => _28.map, 'call', _29 => _29((x) => {
852
+ return {
853
+ base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _30 => _30.base]))), () => ( _process2.default.cwd())),
854
+ pattern: x.pattern
855
+ };
856
+ })])
857
+ });
858
+ for (const candidate of candidates) {
859
+ classSet.add(candidate);
860
+ }
861
+ }
862
+ } else {
863
+ const candidates = await extractValidCandidates({
864
+ base: _optionalChain([v4, 'optionalAccess', _31 => _31.base]),
865
+ css: _optionalChain([v4, 'optionalAccess', _32 => _32.css]),
866
+ sources: _optionalChain([v4, 'optionalAccess', _33 => _33.sources, 'optionalAccess', _34 => _34.map, 'call', _35 => _35((x) => {
867
+ return {
868
+ base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _36 => _36.base]))), () => ( _process2.default.cwd())),
869
+ pattern: x.pattern
870
+ };
871
+ })])
872
+ });
873
+ for (const candidate of candidates) {
874
+ classSet.add(candidate);
875
+ }
876
+ }
877
+ } else {
878
+ const classCaches = this.getClassCaches();
879
+ for (const classCacheMap of classCaches) {
880
+ const keys = classCacheMap.keys();
881
+ for (const key of keys) {
882
+ const v = key.toString();
883
+ if (_optionalChain([output, 'optionalAccess', _37 => _37.removeUniversalSelector]) && v === "*") {
884
+ continue;
885
+ }
886
+ classSet.add(v);
888
887
  }
889
- classSet.add(v);
890
888
  }
891
889
  }
892
890
  return classSet;
@@ -894,10 +892,12 @@ var TailwindcssPatcher = class {
894
892
  /**
895
893
  * @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
896
894
  */
897
- getClassSet(options) {
898
- const { cacheStrategy = this.cacheOptions.strategy ?? "merge", removeUniversalSelector = true } = options ?? {};
899
- const set = this.getClassCacheSet({
900
- removeUniversalSelector
895
+ async getClassSet(options) {
896
+ const { output, tailwindcss } = _nullishCoalesce(options, () => ( {}));
897
+ const cacheStrategy = _nullishCoalesce(this.cacheOptions.strategy, () => ( "merge"));
898
+ const set = await this.getClassCacheSet({
899
+ output,
900
+ tailwindcss
901
901
  });
902
902
  if (cacheStrategy === "overwrite") {
903
903
  set.size > 0 && this.setCache(set);
@@ -913,48 +913,39 @@ var TailwindcssPatcher = class {
913
913
  return set;
914
914
  }
915
915
  async extract(options) {
916
- const { output, tailwindcss } = options ?? {};
916
+ const { output, tailwindcss } = _nullishCoalesce(options, () => ( {}));
917
917
  if (output && tailwindcss) {
918
- const { removeUniversalSelector, filename, loose } = output;
919
- await processTailwindcss(tailwindcss);
920
- const set = this.getClassSet({
921
- removeUniversalSelector
918
+ const { filename, loose } = output;
919
+ if (this.majorVersion === 3) {
920
+ await processTailwindcss({
921
+ ...tailwindcss,
922
+ majorVersion: this.majorVersion
923
+ });
924
+ }
925
+ const set = await this.getClassSet({
926
+ output,
927
+ tailwindcss
922
928
  });
923
929
  if (filename) {
924
- await import_fs_extra5.default.ensureDir(import_pathe7.default.dirname(filename));
925
930
  const classList = [...set];
926
- await import_fs_extra5.default.outputJSON(filename, classList, {
931
+ await _fsextra2.default.outputJSON(filename, classList, {
927
932
  spaces: loose ? 2 : void 0
928
933
  });
929
934
  return filename;
930
935
  }
931
936
  }
932
937
  }
933
- };
938
+ __init() {this.extractValidCandidates = extractValidCandidates}
939
+ }, _class);
934
940
 
935
- // src/cli.ts
936
- function init() {
937
- const cwd = import_node_process4.default.cwd();
938
- return (0, config_exports.initConfig)(cwd);
939
- }
940
- var cli = (0, import_cac.default)();
941
- cli.command("install", "patch install").action(() => {
942
- const twPatcher = new TailwindcssPatcher({
943
- patch: getPatchOptions()
944
- });
945
- twPatcher.patch();
946
- });
947
- cli.command("init").action(async () => {
948
- await init();
949
- logger_default.success(`\u2728 ${config_exports.configName}.config.ts initialized!`);
950
- });
951
- cli.command("extract").action(async () => {
952
- const { config } = await (0, config_exports.getConfig)();
953
- if (config) {
954
- const twPatcher = new TailwindcssPatcher();
955
- const p = await twPatcher.extract(config.patch);
956
- logger_default.success(`\u2728 tailwindcss-patch extract success! file path: ${p}`);
957
- }
958
- });
959
- cli.help();
960
- cli.parse();
941
+
942
+
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+
951
+ exports.logger_default = logger_default; exports.getCacheOptions = getCacheOptions; exports.CacheManager = CacheManager; exports.getPatchOptions = getPatchOptions; exports.monkeyPatchForExposingContextV3 = monkeyPatchForExposingContextV3; exports.monkeyPatchForExposingContextV2 = monkeyPatchForExposingContextV2; exports.monkeyPatchForSupportingCustomUnit = monkeyPatchForSupportingCustomUnit; exports.internalPatch = internalPatch; exports.TailwindcssPatcher = TailwindcssPatcher;