weapp-tailwindcss 4.11.0-alpha.0 → 4.11.0-alpha.2

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 (73) hide show
  1. package/dist/{chunk-35EI5JMK.mjs → chunk-23K4XDKF.mjs} +3 -1
  2. package/dist/{chunk-FV4ZRTAK.js → chunk-2W24MRCQ.js} +10 -12
  3. package/dist/chunk-4AFQP74Z.js +24 -0
  4. package/dist/{chunk-7XQXBJL6.js → chunk-4TTPYMVM.js} +12 -8
  5. package/dist/{chunk-RXNSOSCT.js → chunk-5KSBT6GU.js} +448 -270
  6. package/dist/{chunk-QX2A7SBB.mjs → chunk-66E76FQE.mjs} +666 -102
  7. package/dist/{chunk-WGFNCK5B.js → chunk-6O7HJU2F.js} +123 -42
  8. package/dist/{chunk-RRHPTTCP.mjs → chunk-76S2EME4.mjs} +2 -0
  9. package/dist/{chunk-G3G437UE.js → chunk-7LKMJZD2.js} +2 -2
  10. package/dist/{chunk-OV7FX6XR.js → chunk-CRDOWYG4.js} +1 -1
  11. package/dist/{chunk-DOH7FULQ.mjs → chunk-EFBQ4SQR.mjs} +1 -1
  12. package/dist/{chunk-XGUD52TA.mjs → chunk-EW2K6CO5.mjs} +413 -235
  13. package/dist/{chunk-FMWKBZWX.mjs → chunk-HADJCWHU.mjs} +291 -265
  14. package/dist/{chunk-FKUPQQYX.js → chunk-K7CZXT46.js} +692 -125
  15. package/dist/{chunk-ACTJYB33.js → chunk-LL3QUKJI.js} +3 -1
  16. package/dist/{chunk-I4EOMKX2.js → chunk-LYGLQCWI.js} +356 -330
  17. package/dist/{chunk-LTJQUORK.js → chunk-OF6MFURR.js} +2 -0
  18. package/dist/{chunk-W3JO6LBC.mjs → chunk-RED7Y22U.mjs} +91 -10
  19. package/dist/{chunk-CLNUBO3Q.mjs → chunk-SJ3SG6DU.mjs} +5 -1
  20. package/dist/{chunk-OIDFSOER.mjs → chunk-UCUAXK7F.mjs} +4 -6
  21. package/dist/cli.js +1006 -147
  22. package/dist/cli.mjs +942 -107
  23. package/dist/core.d.mts +2 -2
  24. package/dist/core.d.ts +2 -2
  25. package/dist/core.js +9 -11
  26. package/dist/core.mjs +6 -8
  27. package/dist/css-macro/postcss.js +1 -1
  28. package/dist/css-macro/postcss.mjs +1 -1
  29. package/dist/css-macro.js +3 -3
  30. package/dist/css-macro.mjs +4 -4
  31. package/dist/defaults.d.mts +2 -2
  32. package/dist/defaults.d.ts +2 -2
  33. package/dist/defaults.js +3 -3
  34. package/dist/defaults.mjs +2 -2
  35. package/dist/gulp.d.mts +2 -2
  36. package/dist/gulp.d.ts +2 -2
  37. package/dist/gulp.js +7 -8
  38. package/dist/gulp.mjs +6 -7
  39. package/dist/{index-t_VBjwYm.d.ts → index-BMwzhITq.d.mts} +6 -6
  40. package/dist/{index-t_VBjwYm.d.mts → index-BMwzhITq.d.ts} +6 -6
  41. package/dist/index.d.mts +2 -2
  42. package/dist/index.d.ts +2 -2
  43. package/dist/index.js +11 -12
  44. package/dist/index.mjs +9 -10
  45. package/dist/postcss-html-transform.js +1 -1
  46. package/dist/postcss-html-transform.mjs +1 -1
  47. package/dist/presets.d.mts +2 -2
  48. package/dist/presets.d.ts +2 -2
  49. package/dist/presets.js +5 -5
  50. package/dist/presets.mjs +2 -2
  51. package/dist/reset.js +1 -1
  52. package/dist/reset.mjs +1 -1
  53. package/dist/types.d.mts +4 -4
  54. package/dist/types.d.ts +4 -4
  55. package/dist/types.js +1 -1
  56. package/dist/types.mjs +1 -1
  57. package/dist/vite.d.mts +2 -2
  58. package/dist/vite.d.ts +2 -2
  59. package/dist/vite.js +8 -9
  60. package/dist/vite.mjs +6 -7
  61. package/dist/weapp-tw-css-import-rewrite-loader.js +3 -1
  62. package/dist/weapp-tw-runtime-classset-loader.js +29 -2
  63. package/dist/webpack.d.mts +2 -2
  64. package/dist/webpack.d.ts +2 -2
  65. package/dist/webpack.js +9 -10
  66. package/dist/webpack.mjs +7 -8
  67. package/dist/webpack4.d.mts +2 -2
  68. package/dist/webpack4.d.ts +2 -2
  69. package/dist/webpack4.js +41 -41
  70. package/dist/webpack4.mjs +12 -12
  71. package/package.json +9 -9
  72. package/dist/chunk-EOK3NZVC.mjs +0 -29
  73. package/dist/chunk-PXZUQ7RR.js +0 -29
@@ -2,11 +2,15 @@ import {
2
2
  applyV4CssCalcDefaults,
3
3
  createTailwindcssPatcherFromContext,
4
4
  findNearestPackageRoot,
5
+ getRuntimeClassSetCacheEntry,
6
+ getRuntimeClassSetSignature,
7
+ invalidateRuntimeClassSet,
8
+ logger,
5
9
  warnMissingCssEntries
6
- } from "./chunk-XGUD52TA.mjs";
10
+ } from "./chunk-EW2K6CO5.mjs";
7
11
  import {
8
12
  getDefaultOptions
9
- } from "./chunk-35EI5JMK.mjs";
13
+ } from "./chunk-23K4XDKF.mjs";
10
14
  import {
11
15
  defuOverrideArray,
12
16
  isMap
@@ -29,72 +33,6 @@ function createDebug(prefix) {
29
33
  return debug3;
30
34
  }
31
35
 
32
- // src/tailwindcss/runtime/cache.ts
33
- import { statSync } from "fs";
34
- var runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
35
- var runtimeConfigSignatureCache = /* @__PURE__ */ new Map();
36
- var runtimeConfigSignatureCacheClearTimer;
37
- function getCacheEntry(twPatcher) {
38
- let entry = runtimeClassSetCache.get(twPatcher);
39
- if (!entry) {
40
- entry = {};
41
- runtimeClassSetCache.set(twPatcher, entry);
42
- }
43
- return entry;
44
- }
45
- function scheduleRuntimeConfigSignatureCacheClear() {
46
- if (runtimeConfigSignatureCacheClearTimer) {
47
- return;
48
- }
49
- runtimeConfigSignatureCacheClearTimer = setTimeout(() => {
50
- runtimeConfigSignatureCache.clear();
51
- runtimeConfigSignatureCacheClearTimer = void 0;
52
- }, 0);
53
- runtimeConfigSignatureCacheClearTimer.unref?.();
54
- }
55
- function getTailwindConfigSignature(twPatcher) {
56
- const configPath = twPatcher.options?.tailwind?.config;
57
- if (typeof configPath !== "string" || configPath.length === 0) {
58
- return void 0;
59
- }
60
- const cached = runtimeConfigSignatureCache.get(configPath);
61
- if (cached !== void 0) {
62
- return cached;
63
- }
64
- let signature;
65
- try {
66
- const stats = statSync(configPath);
67
- signature = `${configPath}:${stats.size}:${stats.mtimeMs}`;
68
- } catch {
69
- signature = `${configPath}:missing`;
70
- }
71
- runtimeConfigSignatureCache.set(configPath, signature);
72
- scheduleRuntimeConfigSignatureCacheClear();
73
- return signature;
74
- }
75
- function getPatchTargetSignature(twPatcher) {
76
- const packageInfo = twPatcher.packageInfo;
77
- return `${packageInfo?.rootPath ?? "missing"}:${packageInfo?.version ?? "unknown"}:${twPatcher.majorVersion ?? "unknown"}`;
78
- }
79
- function invalidateRuntimeClassSet(twPatcher) {
80
- if (!twPatcher) {
81
- return;
82
- }
83
- const configPath = twPatcher.options?.tailwind?.config;
84
- if (typeof configPath === "string" && configPath.length > 0) {
85
- runtimeConfigSignatureCache.delete(configPath);
86
- }
87
- runtimeClassSetCache.delete(twPatcher);
88
- }
89
- function getRuntimeClassSetCacheEntry(twPatcher) {
90
- return getCacheEntry(twPatcher);
91
- }
92
- function getRuntimeClassSetSignature(twPatcher) {
93
- const configSignature = getTailwindConfigSignature(twPatcher) ?? "config:missing";
94
- const patchTargetSignature = getPatchTargetSignature(twPatcher);
95
- return `${configSignature}|patch:${patchTargetSignature}`;
96
- }
97
-
98
36
  // src/tailwindcss/runtime.ts
99
37
  var debug = createDebug("[tailwindcss:runtime] ");
100
38
  var refreshTailwindcssPatcherSymbol = /* @__PURE__ */ Symbol.for("weapp-tailwindcss.refreshTailwindcssPatcher");
@@ -126,6 +64,7 @@ async function refreshTailwindRuntimeState(state, forceOrOptions) {
126
64
  if (!force) {
127
65
  return false;
128
66
  }
67
+ debug("refresh runtime state start, clearCache=%s major=%s", clearCache, state.twPatcher.majorVersion ?? "unknown");
129
68
  await state.patchPromise;
130
69
  let refreshed = false;
131
70
  if (typeof state.refreshTailwindcssPatcher === "function") {
@@ -138,6 +77,7 @@ async function refreshTailwindRuntimeState(state, forceOrOptions) {
138
77
  if (refreshed) {
139
78
  state.patchPromise = createTailwindPatchPromise(state.twPatcher, state.onPatchCompleted);
140
79
  }
80
+ debug("refresh runtime state end, refreshed=%s major=%s", refreshed, state.twPatcher.majorVersion ?? "unknown");
141
81
  return refreshed;
142
82
  }
143
83
  async function ensureRuntimeClassSet(state, options = {}) {
@@ -313,10 +253,176 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
313
253
  }
314
254
  }
315
255
 
256
+ // src/context/index.ts
257
+ import { rm } from "fs/promises";
258
+ import { logger as logger6, pc } from "@weapp-tailwindcss/logger";
259
+
260
+ // src/cache/index.ts
261
+ import { LRUCache } from "lru-cache";
262
+
263
+ // src/cache/md5.ts
264
+ import { md5 } from "@weapp-tailwindcss/shared/node";
265
+
266
+ // src/cache/index.ts
267
+ function isProcessResult(value) {
268
+ return typeof value === "object" && value !== null && "result" in value;
269
+ }
270
+ function createCache(options) {
271
+ const disabled = options === false;
272
+ const hashMap = /* @__PURE__ */ new Map();
273
+ const instance = new LRUCache({
274
+ // 可能会添加和删除一些页面和组件, 先设定 1024 吧
275
+ max: 1024,
276
+ ttl: 0,
277
+ ttlAutopurge: false
278
+ });
279
+ const cache = {
280
+ hashMap,
281
+ instance,
282
+ hasHashKey(key) {
283
+ return hashMap.has(key);
284
+ },
285
+ getHashValue(key) {
286
+ return hashMap.get(key);
287
+ },
288
+ setHashValue(key, value) {
289
+ return hashMap.set(key, value);
290
+ },
291
+ get(key) {
292
+ return instance.get(key);
293
+ },
294
+ set(key, value) {
295
+ return instance.set(key, value);
296
+ },
297
+ computeHash(message) {
298
+ return md5(message);
299
+ },
300
+ calcHashValueChanged(key, hash) {
301
+ const hit = hashMap.get(key);
302
+ if (hit) {
303
+ hashMap.set(key, {
304
+ changed: hash !== hit.hash,
305
+ hash
306
+ });
307
+ } else {
308
+ hashMap.set(key, {
309
+ changed: true,
310
+ hash
311
+ });
312
+ }
313
+ return cache;
314
+ },
315
+ has(key) {
316
+ return instance.has(key);
317
+ },
318
+ async process({
319
+ key,
320
+ hashKey,
321
+ rawSource,
322
+ hash,
323
+ resolveCache,
324
+ transform,
325
+ onCacheHit
326
+ }) {
327
+ if (disabled) {
328
+ const value2 = await transform();
329
+ return isProcessResult(value2) ? value2.result : value2;
330
+ }
331
+ const cacheHashKey = hashKey ?? key;
332
+ let hasChanged = true;
333
+ if (hash != null || rawSource != null) {
334
+ const nextHash = hash ?? cache.computeHash(rawSource);
335
+ cache.calcHashValueChanged(cacheHashKey, nextHash);
336
+ const entry = cache.getHashValue(cacheHashKey);
337
+ hasChanged = entry?.changed ?? true;
338
+ }
339
+ const readCache = resolveCache ?? (() => cache.get(key));
340
+ if (!hasChanged) {
341
+ const cached = readCache();
342
+ if (cached !== void 0) {
343
+ await onCacheHit?.(cached);
344
+ return cached;
345
+ }
346
+ }
347
+ const value = await transform();
348
+ const normalized = isProcessResult(value) ? value : { result: value };
349
+ const stored = normalized.cacheValue ?? normalized.result;
350
+ cache.set(key, stored);
351
+ return normalized.result;
352
+ }
353
+ };
354
+ return cache;
355
+ }
356
+ function initializeCache(cacheConfig) {
357
+ if (typeof cacheConfig === "boolean" || cacheConfig === void 0) {
358
+ return createCache(cacheConfig);
359
+ }
360
+ return cacheConfig;
361
+ }
362
+
363
+ // src/tailwindcss/targets.ts
364
+ import process3 from "process";
365
+ import { logger as logger3 } from "@weapp-tailwindcss/logger";
366
+
367
+ // src/tailwindcss/targets/paths.ts
368
+ import { existsSync } from "fs";
369
+ import path from "path";
370
+ var PATCH_INFO_FILENAME = "tailwindcss-target.json";
371
+ var PATCH_INFO_CACHE_RELATIVE_PATH = path.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
372
+ var PATCH_INFO_LEGACY_RELATIVE_PATH = path.join(".tw-patch", PATCH_INFO_FILENAME);
373
+ function formatRelativeToBase(targetPath, baseDir) {
374
+ if (!baseDir) {
375
+ return path.normalize(targetPath);
376
+ }
377
+ const relative = path.relative(baseDir, targetPath);
378
+ if (!relative || relative === ".") {
379
+ return ".";
380
+ }
381
+ if (relative.startsWith("..")) {
382
+ return path.normalize(targetPath);
383
+ }
384
+ return path.join(".", relative);
385
+ }
386
+ function resolveRecordLocation(baseDir) {
387
+ const normalizedBase = path.normalize(baseDir);
388
+ const packageRoot = findNearestPackageRoot(normalizedBase) ?? normalizedBase;
389
+ const packageJsonPath = path.join(packageRoot, "package.json");
390
+ const hasPackageJson = existsSync(packageJsonPath);
391
+ const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
392
+ const recordKey = md5(path.normalize(recordKeySource));
393
+ const recordDir = path.join(packageRoot, "node_modules", ".cache", "weapp-tailwindcss", recordKey);
394
+ const recordPath = path.join(recordDir, PATCH_INFO_FILENAME);
395
+ return {
396
+ normalizedBase,
397
+ packageRoot,
398
+ recordDir,
399
+ recordKey,
400
+ recordPath,
401
+ packageJsonPath: hasPackageJson ? packageJsonPath : void 0
402
+ };
403
+ }
404
+ function getRecordFileCandidates(baseDir) {
405
+ const { normalizedBase, packageRoot, recordPath } = resolveRecordLocation(baseDir);
406
+ const candidates = /* @__PURE__ */ new Set([
407
+ recordPath,
408
+ path.join(packageRoot, PATCH_INFO_CACHE_RELATIVE_PATH),
409
+ path.join(normalizedBase, PATCH_INFO_CACHE_RELATIVE_PATH),
410
+ path.join(normalizedBase, PATCH_INFO_LEGACY_RELATIVE_PATH)
411
+ ]);
412
+ return [...candidates];
413
+ }
414
+
415
+ // src/tailwindcss/targets/record-io.ts
416
+ import { existsSync as existsSync2, readFileSync } from "fs";
417
+ import { mkdir, writeFile } from "fs/promises";
418
+ import path2 from "path";
419
+ import process from "process";
420
+ import { logger as logger2 } from "@weapp-tailwindcss/logger";
421
+
316
422
  // package.json
317
423
  var package_default = {
318
424
  name: "weapp-tailwindcss",
319
- version: "4.11.0-alpha.0",
425
+ version: "4.11.0-alpha.2",
320
426
  description: "\u628A tailwindcss \u539F\u5B50\u5316\u6837\u5F0F\u601D\u60F3\uFF0C\u5E26\u7ED9\u5C0F\u7A0B\u5E8F\u5F00\u53D1\u8005\u4EEC! bring tailwindcss to miniprogram developers!",
321
427
  author: "ice breaker <1324318532@qq.com>",
322
428
  license: "MIT",
@@ -472,7 +578,7 @@ var package_default = {
472
578
  "with-layer.css"
473
579
  ],
474
580
  engines: {
475
- node: "^20.19.0 || >=22.12.0"
581
+ node: "^18.17.0 || >=20.5.0"
476
582
  },
477
583
  scripts: {
478
584
  dev: "tsup --watch --sourcemap",
@@ -500,7 +606,7 @@ var package_default = {
500
606
  "lint:fix": "eslint ./src --fix",
501
607
  postinstall: "node bin/weapp-tailwindcss.js patch",
502
608
  "bench:vite-dev-hmr": "tsx scripts/vite-dev-hmr-bench.ts",
503
- "test:watch-hmr": "tsx scripts/watch-hmr-regression/index.ts"
609
+ "test:watch-hmr": "node --import tsx scripts/watch-hmr-regression/index.ts"
504
610
  },
505
611
  publishConfig: {
506
612
  access: "public",
@@ -508,7 +614,7 @@ var package_default = {
508
614
  },
509
615
  dependencies: {
510
616
  "@ast-core/escape": "~1.0.1",
511
- "@babel/parser": "~7.29.0",
617
+ "@babel/parser": "~7.29.2",
512
618
  "@babel/traverse": "~7.29.0",
513
619
  "@babel/types": "~7.29.0",
514
620
  "@tailwindcss-mangle/config": "^6.1.3",
@@ -519,7 +625,7 @@ var package_default = {
519
625
  "@weapp-tailwindcss/logger": "workspace:*",
520
626
  "@weapp-tailwindcss/postcss": "workspace:*",
521
627
  "@weapp-tailwindcss/shared": "workspace:*",
522
- cac: "^6.7.14",
628
+ cac: "6.7.14",
523
629
  debug: "~4.4.3",
524
630
  "fast-glob": "^3.3.3",
525
631
  htmlparser2: "10.1.0",
@@ -530,14 +636,13 @@ var package_default = {
530
636
  semver: "~7.7.4",
531
637
  "tailwindcss-patch": "catalog:tailwindcssPatch",
532
638
  "webpack-sources": "3.3.4",
533
- yaml: "^2.8.2"
639
+ yaml: "^2.8.3"
534
640
  }
535
641
  };
536
642
 
537
643
  // src/constants.ts
538
644
  var pluginName = "weapp-tailwindcss-webpack-plugin";
539
645
  var vitePluginName = "weapp-tailwindcss:adaptor";
540
- var WEAPP_TW_REQUIRED_NODE_VERSION = "18.17.0";
541
646
  var WEAPP_TW_VERSION = package_default.version;
542
647
  var DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
543
648
  "tailwind-merge": "@weapp-tailwindcss/merge",
@@ -545,171 +650,7 @@ var DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
545
650
  "tailwind-variants": "@weapp-tailwindcss/variants"
546
651
  };
547
652
 
548
- // src/context/index.ts
549
- import { rm } from "fs/promises";
550
- import { logger as logger5, pc } from "@weapp-tailwindcss/logger";
551
-
552
- // src/cache/index.ts
553
- import { LRUCache } from "lru-cache";
554
-
555
- // src/cache/md5.ts
556
- import { md5 } from "@weapp-tailwindcss/shared/node";
557
-
558
- // src/cache/index.ts
559
- function isProcessResult(value) {
560
- return typeof value === "object" && value !== null && "result" in value;
561
- }
562
- function createCache(options) {
563
- const disabled = options === false;
564
- const hashMap = /* @__PURE__ */ new Map();
565
- const instance = new LRUCache({
566
- // 可能会添加和删除一些页面和组件, 先设定 1024 吧
567
- max: 1024,
568
- ttl: 0,
569
- ttlAutopurge: false
570
- });
571
- const cache = {
572
- hashMap,
573
- instance,
574
- hasHashKey(key) {
575
- return hashMap.has(key);
576
- },
577
- getHashValue(key) {
578
- return hashMap.get(key);
579
- },
580
- setHashValue(key, value) {
581
- return hashMap.set(key, value);
582
- },
583
- get(key) {
584
- return instance.get(key);
585
- },
586
- set(key, value) {
587
- return instance.set(key, value);
588
- },
589
- computeHash(message) {
590
- return md5(message);
591
- },
592
- calcHashValueChanged(key, hash) {
593
- const hit = hashMap.get(key);
594
- if (hit) {
595
- hashMap.set(key, {
596
- changed: hash !== hit.hash,
597
- hash
598
- });
599
- } else {
600
- hashMap.set(key, {
601
- changed: true,
602
- hash
603
- });
604
- }
605
- return cache;
606
- },
607
- has(key) {
608
- return instance.has(key);
609
- },
610
- async process({
611
- key,
612
- hashKey,
613
- rawSource,
614
- hash,
615
- resolveCache,
616
- transform,
617
- onCacheHit
618
- }) {
619
- if (disabled) {
620
- const value2 = await transform();
621
- return isProcessResult(value2) ? value2.result : value2;
622
- }
623
- const cacheHashKey = hashKey ?? key;
624
- let hasChanged = true;
625
- if (hash != null || rawSource != null) {
626
- const nextHash = hash ?? cache.computeHash(rawSource);
627
- cache.calcHashValueChanged(cacheHashKey, nextHash);
628
- const entry = cache.getHashValue(cacheHashKey);
629
- hasChanged = entry?.changed ?? true;
630
- }
631
- const readCache = resolveCache ?? (() => cache.get(key));
632
- if (!hasChanged) {
633
- const cached = readCache();
634
- if (cached !== void 0) {
635
- await onCacheHit?.(cached);
636
- return cached;
637
- }
638
- }
639
- const value = await transform();
640
- const normalized = isProcessResult(value) ? value : { result: value };
641
- const stored = normalized.cacheValue ?? normalized.result;
642
- cache.set(key, stored);
643
- return normalized.result;
644
- }
645
- };
646
- return cache;
647
- }
648
- function initializeCache(cacheConfig) {
649
- if (typeof cacheConfig === "boolean" || cacheConfig === void 0) {
650
- return createCache(cacheConfig);
651
- }
652
- return cacheConfig;
653
- }
654
-
655
- // src/tailwindcss/targets.ts
656
- import process3 from "process";
657
- import { logger as logger2 } from "@weapp-tailwindcss/logger";
658
-
659
- // src/tailwindcss/targets/paths.ts
660
- import { existsSync } from "fs";
661
- import path from "path";
662
- var PATCH_INFO_FILENAME = "tailwindcss-target.json";
663
- var PATCH_INFO_CACHE_RELATIVE_PATH = path.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
664
- var PATCH_INFO_LEGACY_RELATIVE_PATH = path.join(".tw-patch", PATCH_INFO_FILENAME);
665
- function formatRelativeToBase(targetPath, baseDir) {
666
- if (!baseDir) {
667
- return path.normalize(targetPath);
668
- }
669
- const relative = path.relative(baseDir, targetPath);
670
- if (!relative || relative === ".") {
671
- return ".";
672
- }
673
- if (relative.startsWith("..")) {
674
- return path.normalize(targetPath);
675
- }
676
- return path.join(".", relative);
677
- }
678
- function resolveRecordLocation(baseDir) {
679
- const normalizedBase = path.normalize(baseDir);
680
- const packageRoot = findNearestPackageRoot(normalizedBase) ?? normalizedBase;
681
- const packageJsonPath = path.join(packageRoot, "package.json");
682
- const hasPackageJson = existsSync(packageJsonPath);
683
- const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
684
- const recordKey = md5(path.normalize(recordKeySource));
685
- const recordDir = path.join(packageRoot, "node_modules", ".cache", "weapp-tailwindcss", recordKey);
686
- const recordPath = path.join(recordDir, PATCH_INFO_FILENAME);
687
- return {
688
- normalizedBase,
689
- packageRoot,
690
- recordDir,
691
- recordKey,
692
- recordPath,
693
- packageJsonPath: hasPackageJson ? packageJsonPath : void 0
694
- };
695
- }
696
- function getRecordFileCandidates(baseDir) {
697
- const { normalizedBase, packageRoot, recordPath } = resolveRecordLocation(baseDir);
698
- const candidates = /* @__PURE__ */ new Set([
699
- recordPath,
700
- path.join(packageRoot, PATCH_INFO_CACHE_RELATIVE_PATH),
701
- path.join(normalizedBase, PATCH_INFO_CACHE_RELATIVE_PATH),
702
- path.join(normalizedBase, PATCH_INFO_LEGACY_RELATIVE_PATH)
703
- ]);
704
- return [...candidates];
705
- }
706
-
707
653
  // src/tailwindcss/targets/record-io.ts
708
- import { existsSync as existsSync2, readFileSync } from "fs";
709
- import { mkdir, writeFile } from "fs/promises";
710
- import path2 from "path";
711
- import process from "process";
712
- import { logger } from "@weapp-tailwindcss/logger";
713
654
  var loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
714
655
  function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
715
656
  const normalizedPath = path2.normalize(recordPath);
@@ -720,7 +661,7 @@ function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
720
661
  const fileDisplay = formatRelativeToBase(normalizedPath, baseDir);
721
662
  const baseDisplay = formatRelativeToBase(path2.normalize(baseDir), process.cwd());
722
663
  const reasonMessage = reason ? `\uFF1A${reason}` : "";
723
- logger.warn(
664
+ logger2.warn(
724
665
  `\u68C0\u6D4B\u5230\u635F\u574F\u7684 Tailwind CSS \u76EE\u6807\u8BB0\u5F55 ${fileDisplay}${reasonMessage}\u3002\u8BF7\u5728 ${baseDisplay} \u91CD\u65B0\u6267\u884C "weapp-tw patch --record-target" \u6216\u5220\u9664\u8BE5\u6587\u4EF6\u540E\u518D\u8FD0\u884C\u3002`
725
666
  );
726
667
  }
@@ -778,12 +719,12 @@ async function saveCliPatchTargetRecord(baseDir, patcher, options) {
778
719
  return recordPath;
779
720
  } catch (error) {
780
721
  const baseDisplay = formatRelativeToBase(normalizedBase, process.cwd());
781
- logger.warn(
722
+ logger2.warn(
782
723
  '\u81EA\u52A8\u66F4\u65B0 Tailwind CSS \u8865\u4E01\u8BB0\u5F55\u5931\u8D25\uFF0C\u8BF7\u5728 %s \u8FD0\u884C "weapp-tw patch --cwd %s"\u3002',
783
724
  baseDisplay,
784
725
  normalizedBase
785
726
  );
786
- logger.debug("failed to persist patch target record %s: %O", recordPath, error);
727
+ logger2.debug("failed to persist patch target record %s: %O", recordPath, error);
787
728
  return void 0;
788
729
  }
789
730
  }
@@ -873,7 +814,7 @@ function logTailwindcssTarget(kind, patcher, baseDir) {
873
814
  const packageInfo = patcher?.packageInfo;
874
815
  const label = kind === "cli" ? "weapp-tw patch" : "tailwindcss-patcher";
875
816
  if (!packageInfo?.rootPath) {
876
- logger2.warn(
817
+ logger3.warn(
877
818
  "%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
878
819
  label,
879
820
  baseDir ?? process3.cwd()
@@ -882,14 +823,14 @@ function logTailwindcssTarget(kind, patcher, baseDir) {
882
823
  }
883
824
  const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
884
825
  const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
885
- logger2.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
826
+ logger3.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
886
827
  }
887
828
 
888
829
  // src/context/compiler-context-cache.ts
889
830
  import { Buffer } from "buffer";
890
831
  import path4 from "path";
891
832
  import process4 from "process";
892
- import { logger as logger3 } from "@weapp-tailwindcss/logger";
833
+ import { logger as logger4 } from "@weapp-tailwindcss/logger";
893
834
  var PAREN_CONTENT_RE = /\(([^)]+)\)/u;
894
835
  var AT_LOCATION_RE = /at\s+(\S.*)$/u;
895
836
  var TRAILING_LINE_COL_RE = /:\d+(?::\d+)?$/u;
@@ -1140,7 +1081,7 @@ function createCompilerContextCacheKey(opts) {
1140
1081
  keyStore.set(runtimeCacheScopeKey, cacheKey);
1141
1082
  return cacheKey;
1142
1083
  } catch (error) {
1143
- logger3.debug("skip compiler context cache: %O", error);
1084
+ logger4.debug("skip compiler context cache: %O", error);
1144
1085
  return void 0;
1145
1086
  }
1146
1087
  }
@@ -3003,6 +2944,17 @@ function hasDefinedOverrides(options) {
3003
2944
  }
3004
2945
  return false;
3005
2946
  }
2947
+ var CACHEABLE_SOURCE_MAX_LENGTH = 512;
2948
+ var RESULT_CACHE_LIMIT = 256;
2949
+ function shouldCacheJsResult(rawSource, options) {
2950
+ if (rawSource.length === 0 || rawSource.length > CACHEABLE_SOURCE_MAX_LENGTH) {
2951
+ return false;
2952
+ }
2953
+ if (options.moduleGraph || options.filename) {
2954
+ return false;
2955
+ }
2956
+ return true;
2957
+ }
3006
2958
  function createJsHandler(options) {
3007
2959
  const defaults = {
3008
2960
  escapeMap: options.escapeMap,
@@ -3023,6 +2975,9 @@ function createJsHandler(options) {
3023
2975
  };
3024
2976
  const resolvedOptionsByClassNameSet = /* @__PURE__ */ new WeakMap();
3025
2977
  let resolvedOptionsWithoutClassNameSet;
2978
+ const resolvedOverrideOptions = /* @__PURE__ */ new WeakMap();
2979
+ const resolvedOverrideOptionsByClassNameSet = /* @__PURE__ */ new WeakMap();
2980
+ const resultCache = /* @__PURE__ */ new WeakMap();
3026
2981
  function resolveDefaultOptions(classNameSet) {
3027
2982
  if (!classNameSet) {
3028
2983
  if (!resolvedOptionsWithoutClassNameSet) {
@@ -3044,18 +2999,76 @@ function createJsHandler(options) {
3044
2999
  resolvedOptionsByClassNameSet.set(classNameSet, created);
3045
3000
  return created;
3046
3001
  }
3047
- function handler(rawSource, classNameSet, options2) {
3048
- if (!hasDefinedOverrides(options2)) {
3049
- return jsHandler(rawSource, resolveDefaultOptions(classNameSet));
3002
+ function getCachedJsResult(rawSource, resolvedOptions) {
3003
+ if (!shouldCacheJsResult(rawSource, resolvedOptions)) {
3004
+ return void 0;
3005
+ }
3006
+ const cache = resultCache.get(resolvedOptions);
3007
+ return cache?.get(rawSource);
3008
+ }
3009
+ function setCachedJsResult(rawSource, resolvedOptions, result) {
3010
+ if (!shouldCacheJsResult(rawSource, resolvedOptions) || result.error || result.linked) {
3011
+ return result;
3012
+ }
3013
+ let cache = resultCache.get(resolvedOptions);
3014
+ if (!cache) {
3015
+ cache = /* @__PURE__ */ new Map();
3016
+ resultCache.set(resolvedOptions, cache);
3017
+ }
3018
+ cache.set(rawSource, result);
3019
+ if (cache.size > RESULT_CACHE_LIMIT) {
3020
+ const firstKey = cache.keys().next().value;
3021
+ if (typeof firstKey === "string") {
3022
+ cache.delete(firstKey);
3023
+ }
3024
+ }
3025
+ return result;
3026
+ }
3027
+ function resolveOptions(classNameSet, overrideOptions) {
3028
+ if (!hasDefinedOverrides(overrideOptions)) {
3029
+ return resolveDefaultOptions(classNameSet);
3050
3030
  }
3051
- const resolvedOptions = defuOverrideArray(
3031
+ if (!classNameSet) {
3032
+ const cached2 = resolvedOverrideOptions.get(overrideOptions);
3033
+ if (cached2) {
3034
+ return cached2;
3035
+ }
3036
+ const created2 = defuOverrideArray(
3037
+ {
3038
+ ...overrideOptions,
3039
+ classNameSet
3040
+ },
3041
+ defaults
3042
+ );
3043
+ resolvedOverrideOptions.set(overrideOptions, created2);
3044
+ return created2;
3045
+ }
3046
+ let cache = resolvedOverrideOptionsByClassNameSet.get(overrideOptions);
3047
+ if (!cache) {
3048
+ cache = /* @__PURE__ */ new WeakMap();
3049
+ resolvedOverrideOptionsByClassNameSet.set(overrideOptions, cache);
3050
+ }
3051
+ const cached = cache.get(classNameSet);
3052
+ if (cached) {
3053
+ return cached;
3054
+ }
3055
+ const created = defuOverrideArray(
3052
3056
  {
3053
- ...options2,
3057
+ ...overrideOptions,
3054
3058
  classNameSet
3055
3059
  },
3056
3060
  defaults
3057
3061
  );
3058
- return jsHandler(rawSource, resolvedOptions);
3062
+ cache.set(classNameSet, created);
3063
+ return created;
3064
+ }
3065
+ function handler(rawSource, classNameSet, options2) {
3066
+ const resolvedOptions = resolveOptions(classNameSet, options2);
3067
+ const cached = getCachedJsResult(rawSource, resolvedOptions);
3068
+ if (cached) {
3069
+ return cached;
3070
+ }
3071
+ return setCachedJsResult(rawSource, resolvedOptions, jsHandler(rawSource, resolvedOptions));
3059
3072
  }
3060
3073
  return handler;
3061
3074
  }
@@ -3637,7 +3650,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
3637
3650
  }
3638
3651
 
3639
3652
  // src/context/logger.ts
3640
- import { logger as logger4 } from "@weapp-tailwindcss/logger";
3653
+ import { logger as logger5 } from "@weapp-tailwindcss/logger";
3641
3654
  var loggerLevelMap = {
3642
3655
  error: 0,
3643
3656
  warn: 1,
@@ -3645,7 +3658,7 @@ var loggerLevelMap = {
3645
3658
  silent: -999
3646
3659
  };
3647
3660
  function applyLoggerLevel(logLevel) {
3648
- logger4.level = loggerLevelMap[logLevel ?? "info"] ?? loggerLevelMap.info;
3661
+ logger5.level = loggerLevelMap[logLevel ?? "info"] ?? loggerLevelMap.info;
3649
3662
  }
3650
3663
 
3651
3664
  // src/context/index.ts
@@ -3661,7 +3674,7 @@ async function clearTailwindcssPatcherCache(patcher, options) {
3661
3674
  try {
3662
3675
  await patcher.clearCache({ scope: "all" });
3663
3676
  } catch (error) {
3664
- logger5.debug("failed to clear tailwindcss patcher cache via clearCache(): %O", error);
3677
+ logger6.debug("failed to clear tailwindcss patcher cache via clearCache(): %O", error);
3665
3678
  }
3666
3679
  }
3667
3680
  if (!options?.removeDirectory) {
@@ -3690,7 +3703,7 @@ async function clearTailwindcssPatcherCache(patcher, options) {
3690
3703
  if (err?.code === "ENOENT") {
3691
3704
  continue;
3692
3705
  }
3693
- logger5.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
3706
+ logger6.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
3694
3707
  }
3695
3708
  }
3696
3709
  }
@@ -3705,9 +3718,9 @@ function createInternalCompilerContext(opts) {
3705
3718
  const twPatcher = createTailwindcssPatcherFromContext(ctx);
3706
3719
  logTailwindcssTarget("runtime", twPatcher, ctx.tailwindcssBasedir);
3707
3720
  if (twPatcher.packageInfo?.version) {
3708
- logger5.success(`\u5F53\u524D\u4F7F\u7528 ${pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${pc.underline(pc.bold(pc.green(twPatcher.packageInfo.version)))}`);
3721
+ logger6.success(`\u5F53\u524D\u4F7F\u7528 ${pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${pc.underline(pc.bold(pc.green(twPatcher.packageInfo.version)))}`);
3709
3722
  } else {
3710
- logger5.warn(`${pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
3723
+ logger6.warn(`${pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
3711
3724
  }
3712
3725
  warnMissingCssEntries(ctx, twPatcher);
3713
3726
  const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc, twPatcher);
@@ -3746,24 +3759,37 @@ function getCompilerContext(opts) {
3746
3759
  return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
3747
3760
  }
3748
3761
 
3762
+ // src/tailwindcss/recorder.ts
3763
+ function setupPatchRecorder(patcher, baseDir, options) {
3764
+ const recorder = createPatchTargetRecorder(baseDir, patcher, options);
3765
+ if (recorder?.message && options?.logMessage !== false) {
3766
+ const prefix = options?.messagePrefix ? `${options.messagePrefix} ` : "";
3767
+ logger.info("%s%s", prefix, recorder.message);
3768
+ }
3769
+ const onPatchCompleted = recorder?.onPatched ? async () => {
3770
+ await recorder.onPatched();
3771
+ } : void 0;
3772
+ const patchPromise = patcher ? createTailwindPatchPromise(patcher, onPatchCompleted) : Promise.resolve();
3773
+ return {
3774
+ recorder,
3775
+ patchPromise,
3776
+ onPatchCompleted
3777
+ };
3778
+ }
3779
+
3749
3780
  export {
3750
3781
  createDebug,
3751
- getRuntimeClassSetSignature,
3752
- createTailwindPatchPromise,
3753
3782
  refreshTailwindRuntimeState,
3754
3783
  ensureRuntimeClassSet,
3755
3784
  collectRuntimeClassSet,
3756
3785
  pluginName,
3757
3786
  vitePluginName,
3758
- WEAPP_TW_REQUIRED_NODE_VERSION,
3759
- createPatchTargetRecorder,
3760
- logTailwindcssTarget,
3761
3787
  toCustomAttributesEntities,
3762
3788
  traverse,
3763
3789
  babelParse,
3764
3790
  replaceWxml,
3765
3791
  createAttributeMatcher,
3766
3792
  generateCode,
3767
- clearTailwindcssPatcherCache,
3768
- getCompilerContext
3793
+ getCompilerContext,
3794
+ setupPatchRecorder
3769
3795
  };