weapp-tailwindcss 4.7.5 → 4.7.7

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 (48) hide show
  1. package/dist/{chunk-E5LRICST.js → chunk-2WZP7EXP.js} +280 -165
  2. package/dist/{chunk-PUFKPENL.mjs → chunk-APVOYXRF.mjs} +6 -15
  3. package/dist/{chunk-42FXROX4.mjs → chunk-FZNEB7RC.mjs} +2 -2
  4. package/dist/{chunk-XEQBYGBX.mjs → chunk-KGKHHXRC.mjs} +252 -137
  5. package/dist/{chunk-RLWIDWTA.js → chunk-MGHX7SCL.js} +15 -24
  6. package/dist/{chunk-R7GWRQDJ.js → chunk-MMBZHHNL.js} +1 -1
  7. package/dist/{chunk-SCOGAO45.mjs → chunk-MNKR7BNZ.mjs} +1 -1
  8. package/dist/{chunk-SJV6DCNZ.js → chunk-PP6KHC2I.js} +6 -6
  9. package/dist/{chunk-WXBFAARR.js → chunk-USAH2CX5.js} +1 -1
  10. package/dist/{chunk-GGD75A34.js → chunk-VLM4KUZA.js} +4 -4
  11. package/dist/{chunk-TK5LOBHZ.mjs → chunk-VPQLMV42.mjs} +1 -1
  12. package/dist/{chunk-24ADBRZN.js → chunk-X5SXNF7I.js} +10 -10
  13. package/dist/{chunk-KZJLIZIK.mjs → chunk-XVJBQIVY.mjs} +1 -1
  14. package/dist/cli.js +24 -13
  15. package/dist/cli.mjs +18 -7
  16. package/dist/core.js +10 -11
  17. package/dist/core.mjs +3 -4
  18. package/dist/css-macro/postcss.js +1 -1
  19. package/dist/css-macro/postcss.mjs +1 -1
  20. package/dist/css-macro.js +1 -1
  21. package/dist/css-macro.mjs +1 -1
  22. package/dist/defaults.js +3 -3
  23. package/dist/defaults.mjs +2 -2
  24. package/dist/escape.d.mts +4 -16
  25. package/dist/escape.d.ts +4 -16
  26. package/dist/escape.js +53 -9
  27. package/dist/escape.mjs +19 -5
  28. package/dist/gulp.js +6 -7
  29. package/dist/gulp.mjs +4 -5
  30. package/dist/index.js +8 -9
  31. package/dist/index.mjs +6 -7
  32. package/dist/postcss-html-transform.js +1 -1
  33. package/dist/postcss-html-transform.mjs +1 -1
  34. package/dist/presets.js +3 -3
  35. package/dist/presets.mjs +1 -1
  36. package/dist/types.d.mts +10 -11
  37. package/dist/types.d.ts +10 -11
  38. package/dist/types.js +1 -1
  39. package/dist/types.mjs +1 -1
  40. package/dist/vite.js +6 -7
  41. package/dist/vite.mjs +4 -5
  42. package/dist/webpack.js +6 -7
  43. package/dist/webpack.mjs +4 -5
  44. package/dist/webpack4.js +13 -14
  45. package/dist/webpack4.mjs +3 -4
  46. package/package.json +7 -7
  47. package/dist/chunk-DWAEHRHN.js +0 -21
  48. package/dist/chunk-VSRDBMDB.mjs +0 -21
@@ -1,12 +1,9 @@
1
- import {
2
- replaceWxml
3
- } from "./chunk-VSRDBMDB.mjs";
4
1
  import {
5
2
  createTailwindcssPatcherFromContext
6
3
  } from "./chunk-SHMBWMDV.mjs";
7
4
  import {
8
5
  getDefaultOptions
9
- } from "./chunk-KZJLIZIK.mjs";
6
+ } from "./chunk-XVJBQIVY.mjs";
10
7
  import {
11
8
  defuOverrideArray,
12
9
  isMap
@@ -109,26 +106,6 @@ function tryGetRuntimeClassSetSync(twPatcher) {
109
106
  return void 0;
110
107
  }
111
108
  }
112
- async function mergeContentTokensIntoSet(twPatcher, target) {
113
- if (typeof twPatcher.collectContentTokens !== "function") {
114
- return;
115
- }
116
- try {
117
- const report = await twPatcher.collectContentTokens();
118
- const entries = report?.entries;
119
- if (!Array.isArray(entries)) {
120
- return;
121
- }
122
- for (const entry of entries) {
123
- const candidate = entry?.rawCandidate;
124
- if (typeof candidate === "string" && candidate.length > 0) {
125
- target.add(candidate);
126
- }
127
- }
128
- } catch (error) {
129
- debug("collectContentTokens() failed, continuing without merged tokens: %O", error);
130
- }
131
- }
132
109
  async function collectRuntimeClassSet(twPatcher, options = {}) {
133
110
  let activePatcher = twPatcher;
134
111
  if (options.force && !options.skipRefresh) {
@@ -146,7 +123,6 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
146
123
  }
147
124
  const entry = getCacheEntry(activePatcher);
148
125
  const signature = getTailwindConfigSignature(activePatcher);
149
- const shouldAugmentWithTokens = options.force || !entry.value;
150
126
  if (!options.force) {
151
127
  if (entry.value && entry.signature === signature) {
152
128
  return entry.value;
@@ -184,9 +160,6 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
184
160
  entry.signature = signature;
185
161
  try {
186
162
  const resolved = await task;
187
- if (shouldAugmentWithTokens) {
188
- await mergeContentTokensIntoSet(activePatcher, resolved);
189
- }
190
163
  entry.value = resolved;
191
164
  entry.promise = void 0;
192
165
  entry.signature = signature;
@@ -197,6 +170,112 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
197
170
  }
198
171
  }
199
172
 
173
+ // src/tailwindcss/targets.ts
174
+ import { existsSync, readFileSync } from "fs";
175
+ import { mkdir, writeFile } from "fs/promises";
176
+ import path from "path";
177
+ import process from "process";
178
+ import { logger } from "@weapp-tailwindcss/logger";
179
+ var PATCH_INFO_DIRNAME = ".tw-patch";
180
+ var PATCH_INFO_FILENAME = "tailwindcss-target.json";
181
+ function formatRelativeToBase(targetPath, baseDir) {
182
+ if (!baseDir) {
183
+ return path.normalize(targetPath);
184
+ }
185
+ const relative = path.relative(baseDir, targetPath);
186
+ if (!relative || relative === ".") {
187
+ return ".";
188
+ }
189
+ if (relative.startsWith("..")) {
190
+ return path.normalize(targetPath);
191
+ }
192
+ return path.join(".", relative);
193
+ }
194
+ function getRecordFilePath(baseDir) {
195
+ return path.join(baseDir, PATCH_INFO_DIRNAME, PATCH_INFO_FILENAME);
196
+ }
197
+ function logTailwindcssTarget(kind, patcher, baseDir) {
198
+ const packageInfo = patcher?.packageInfo;
199
+ const label = kind === "cli" ? "weapp-tw patch" : "tailwindcss-patcher";
200
+ if (!packageInfo?.rootPath) {
201
+ logger.warn(
202
+ "%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
203
+ label,
204
+ baseDir ?? process.cwd()
205
+ );
206
+ return;
207
+ }
208
+ const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
209
+ const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
210
+ logger.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
211
+ }
212
+ function readPatchTargetRecord(baseDir) {
213
+ if (!baseDir) {
214
+ return void 0;
215
+ }
216
+ const recordPath = getRecordFilePath(baseDir);
217
+ if (!existsSync(recordPath)) {
218
+ return void 0;
219
+ }
220
+ try {
221
+ const content = readFileSync(recordPath, "utf8");
222
+ const parsed = JSON.parse(content);
223
+ if (!parsed || typeof parsed.tailwindPackagePath !== "string") {
224
+ return void 0;
225
+ }
226
+ return {
227
+ path: recordPath,
228
+ record: parsed
229
+ };
230
+ } catch (error) {
231
+ logger.debug("failed to read patch target record from %s: %O", recordPath, error);
232
+ return void 0;
233
+ }
234
+ }
235
+ async function saveCliPatchTargetRecord(baseDir, patcher) {
236
+ if (!baseDir || !patcher?.packageInfo?.rootPath) {
237
+ return void 0;
238
+ }
239
+ const record = {
240
+ tailwindPackagePath: path.normalize(patcher.packageInfo.rootPath),
241
+ packageVersion: patcher.packageInfo.version,
242
+ recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
243
+ source: "cli",
244
+ tailwindcssBasedir: path.normalize(baseDir)
245
+ };
246
+ const recordPath = getRecordFilePath(baseDir);
247
+ try {
248
+ await mkdir(path.dirname(recordPath), { recursive: true });
249
+ await writeFile(recordPath, `${JSON.stringify(record, null, 2)}
250
+ `, "utf8");
251
+ return recordPath;
252
+ } catch (error) {
253
+ logger.debug("failed to persist patch target record %s: %O", recordPath, error);
254
+ return void 0;
255
+ }
256
+ }
257
+ function warnIfCliPatchTargetMismatch(baseDir, patcher) {
258
+ if (!baseDir || !patcher?.packageInfo?.rootPath) {
259
+ return;
260
+ }
261
+ const recorded = readPatchTargetRecord(baseDir);
262
+ if (!recorded) {
263
+ return;
264
+ }
265
+ const normalizedRecorded = path.normalize(recorded.record.tailwindPackagePath);
266
+ const normalizedRuntime = path.normalize(patcher.packageInfo.rootPath);
267
+ if (normalizedRecorded === normalizedRuntime) {
268
+ return;
269
+ }
270
+ const recordedDisplay = formatRelativeToBase(normalizedRecorded, baseDir);
271
+ const runtimeDisplay = formatRelativeToBase(normalizedRuntime, baseDir);
272
+ const baseDisplay = formatRelativeToBase(path.normalize(baseDir), process.cwd());
273
+ const recordFileDisplay = formatRelativeToBase(recorded.path, baseDir);
274
+ logger.warn(
275
+ `\u68C0\u6D4B\u5230 ${baseDisplay} \u7684 Tailwind CSS \u76EE\u6807\u4E0D\u4E00\u81F4\uFF1ACLI \u6253\u8865\u4E01\u7684\u662F ${recordedDisplay}\uFF0C\u8FD0\u884C\u65F6\u8BFB\u53D6\u7684\u662F ${runtimeDisplay}\u3002\u8BF7\u5728\u5BF9\u5E94\u5B50\u5305\u6267\u884C "weapp-tw patch --cwd ${baseDir}"\uFF08\u8BB0\u5F55\u6587\u4EF6\uFF1A${recordFileDisplay}\uFF09\u3002`
276
+ );
277
+ }
278
+
200
279
  // src/constants.ts
201
280
  var pluginName = "weapp-tailwindcss-webpack-plugin";
202
281
  var vitePluginName = "weapp-tailwindcss:adaptor";
@@ -209,7 +288,7 @@ var DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
209
288
 
210
289
  // src/context/index.ts
211
290
  import { rm } from "fs/promises";
212
- import { logger as logger2, pc } from "@weapp-tailwindcss/logger";
291
+ import { logger as logger3, pc } from "@weapp-tailwindcss/logger";
213
292
 
214
293
  // src/cache/index.ts
215
294
  import { LRUCache } from "lru-cache";
@@ -399,22 +478,22 @@ function createNameMatcher(list, { exact = false } = {}) {
399
478
 
400
479
  // src/js/evalTransforms.ts
401
480
  import { jsStringEscape } from "@ast-core/escape";
402
- function isEvalPath(path) {
403
- if (path.isCallExpression()) {
404
- const calleePath = path.get("callee");
481
+ function isEvalPath(path2) {
482
+ if (path2.isCallExpression()) {
483
+ const calleePath = path2.get("callee");
405
484
  return calleePath.isIdentifier({ name: "eval" });
406
485
  }
407
486
  return false;
408
487
  }
409
- function createEvalReplacementToken(path, updated) {
410
- const node = path.node;
488
+ function createEvalReplacementToken(path2, updated) {
489
+ const node = path2.node;
411
490
  let offset = 0;
412
491
  let original;
413
- if (path.isStringLiteral()) {
492
+ if (path2.isStringLiteral()) {
414
493
  offset = 1;
415
- original = path.node.value;
416
- } else if (path.isTemplateElement()) {
417
- original = path.node.value.raw;
494
+ original = path2.node.value;
495
+ } else if (path2.isTemplateElement()) {
496
+ original = path2.node.value.raw;
418
497
  } else {
419
498
  original = "";
420
499
  }
@@ -429,16 +508,16 @@ function createEvalReplacementToken(path, updated) {
429
508
  if (original === updated) {
430
509
  return void 0;
431
510
  }
432
- const value = path.isStringLiteral() ? jsStringEscape(updated) : updated;
511
+ const value = path2.isStringLiteral() ? jsStringEscape(updated) : updated;
433
512
  return {
434
513
  start,
435
514
  end,
436
515
  value,
437
- path
516
+ path: path2
438
517
  };
439
518
  }
440
- function handleEvalStringLiteral(path, options, updater, handler) {
441
- const { code } = handler(path.node.value, {
519
+ function handleEvalStringLiteral(path2, options, updater, handler) {
520
+ const { code } = handler(path2.node.value, {
442
521
  ...options,
443
522
  needEscaped: false,
444
523
  generateMap: false
@@ -446,26 +525,26 @@ function handleEvalStringLiteral(path, options, updater, handler) {
446
525
  if (!code) {
447
526
  return;
448
527
  }
449
- const token = createEvalReplacementToken(path, code);
528
+ const token = createEvalReplacementToken(path2, code);
450
529
  if (token) {
451
530
  updater.addToken(token);
452
531
  }
453
532
  }
454
- function handleEvalTemplateElement(path, options, updater, handler) {
455
- const { code } = handler(path.node.value.raw, {
533
+ function handleEvalTemplateElement(path2, options, updater, handler) {
534
+ const { code } = handler(path2.node.value.raw, {
456
535
  ...options,
457
536
  generateMap: false
458
537
  });
459
538
  if (!code) {
460
539
  return;
461
540
  }
462
- const token = createEvalReplacementToken(path, code);
541
+ const token = createEvalReplacementToken(path2, code);
463
542
  if (token) {
464
543
  updater.addToken(token);
465
544
  }
466
545
  }
467
- function walkEvalExpression(path, options, updater, handler) {
468
- path.traverse({
546
+ function walkEvalExpression(path2, options, updater, handler) {
547
+ path2.traverse({
469
548
  StringLiteral(innerPath) {
470
549
  handleEvalStringLiteral(innerPath, options, updater, handler);
471
550
  },
@@ -503,6 +582,24 @@ function decodeUnicode2(input) {
503
582
  }
504
583
  }
505
584
 
585
+ // src/wxml/shared.ts
586
+ import { escape, MappingChars2String } from "@weapp-core/escape";
587
+ function replaceWxml(original, options = {
588
+ keepEOL: false,
589
+ escapeMap: MappingChars2String
590
+ }) {
591
+ const { keepEOL, escapeMap, ignoreHead } = options;
592
+ let res = original;
593
+ if (!keepEOL) {
594
+ res = res.replaceAll(/[\n\r]+/g, "");
595
+ }
596
+ res = escape(res, {
597
+ map: escapeMap,
598
+ ignoreHead
599
+ });
600
+ return res;
601
+ }
602
+
506
603
  // src/js/handlers.ts
507
604
  var patternCache = /* @__PURE__ */ new Map();
508
605
  var replacementCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
@@ -555,15 +652,15 @@ function shouldTransformClassName(candidate, {
555
652
  }
556
653
  return !jsPreserveClass?.(candidate);
557
654
  }
558
- function extractLiteralValue(path, { unescapeUnicode, arbitraryValues }) {
655
+ function extractLiteralValue(path2, { unescapeUnicode, arbitraryValues }) {
559
656
  const allowDoubleQuotes = arbitraryValues?.allowDoubleQuotes;
560
657
  let offset = 0;
561
658
  let original;
562
- if (path.isStringLiteral()) {
659
+ if (path2.isStringLiteral()) {
563
660
  offset = 1;
564
- original = path.node.value;
565
- } else if (path.isTemplateElement()) {
566
- original = path.node.value.raw;
661
+ original = path2.node.value;
662
+ } else if (path2.isTemplateElement()) {
663
+ original = path2.node.value.raw;
567
664
  } else {
568
665
  original = "";
569
666
  }
@@ -578,7 +675,7 @@ function extractLiteralValue(path, { unescapeUnicode, arbitraryValues }) {
578
675
  original
579
676
  };
580
677
  }
581
- function replaceHandleValue(path, options) {
678
+ function replaceHandleValue(path2, options) {
582
679
  const {
583
680
  escapeMap,
584
681
  needEscaped = false
@@ -587,8 +684,8 @@ function replaceHandleValue(path, options) {
587
684
  if (!alwaysEscape && (!classNameSet || classNameSet.size === 0)) {
588
685
  return void 0;
589
686
  }
590
- const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path, options);
591
- if (hasIgnoreComment(path.node)) {
687
+ const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path2, options);
688
+ if (hasIgnoreComment(path2.node)) {
592
689
  return void 0;
593
690
  }
594
691
  const candidates = splitCode(literal, allowDoubleQuotes);
@@ -612,7 +709,7 @@ function replaceHandleValue(path, options) {
612
709
  mutated = true;
613
710
  }
614
711
  }
615
- const node = path.node;
712
+ const node = path2.node;
616
713
  if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
617
714
  return void 0;
618
715
  }
@@ -626,7 +723,7 @@ function replaceHandleValue(path, options) {
626
723
  start,
627
724
  end,
628
725
  value,
629
- path
726
+ path: path2
630
727
  };
631
728
  }
632
729
 
@@ -938,35 +1035,35 @@ var NodePathWalker = class {
938
1035
  this.visited = /* @__PURE__ */ new WeakSet();
939
1036
  this.isIgnoredCallIdentifier = createNameMatcher(this.ignoreCallExpressionIdentifiers, { exact: true });
940
1037
  }
941
- walkVariableDeclarator(path) {
942
- const init = path.get("init");
1038
+ walkVariableDeclarator(path2) {
1039
+ const init = path2.get("init");
943
1040
  this.walkNode(init);
944
1041
  }
945
- walkTemplateLiteral(path) {
946
- for (const exp of path.get("expressions")) {
1042
+ walkTemplateLiteral(path2) {
1043
+ for (const exp of path2.get("expressions")) {
947
1044
  this.walkNode(exp);
948
1045
  }
949
- for (const quasis of path.get("quasis")) {
1046
+ for (const quasis of path2.get("quasis")) {
950
1047
  this.callback(quasis);
951
1048
  }
952
1049
  }
953
- walkStringLiteral(path) {
954
- this.callback(path);
1050
+ walkStringLiteral(path2) {
1051
+ this.callback(path2);
955
1052
  }
956
- walkBinaryExpression(path) {
957
- const left = path.get("left");
1053
+ walkBinaryExpression(path2) {
1054
+ const left = path2.get("left");
958
1055
  this.walkNode(left);
959
- const right = path.get("right");
1056
+ const right = path2.get("right");
960
1057
  this.walkNode(right);
961
1058
  }
962
- walkLogicalExpression(path) {
963
- const left = path.get("left");
1059
+ walkLogicalExpression(path2) {
1060
+ const left = path2.get("left");
964
1061
  this.walkNode(left);
965
- const right = path.get("right");
1062
+ const right = path2.get("right");
966
1063
  this.walkNode(right);
967
1064
  }
968
- walkObjectExpression(path) {
969
- const props = path.get("properties");
1065
+ walkObjectExpression(path2) {
1066
+ const props = path2.get("properties");
970
1067
  for (const prop of props) {
971
1068
  if (prop.isObjectProperty()) {
972
1069
  const key = prop.get("key");
@@ -976,8 +1073,8 @@ var NodePathWalker = class {
976
1073
  }
977
1074
  }
978
1075
  }
979
- walkArrayExpression(path) {
980
- const elements = path.get("elements");
1076
+ walkArrayExpression(path2) {
1077
+ const elements = path2.get("elements");
981
1078
  for (const element of elements) {
982
1079
  this.walkNode(element);
983
1080
  }
@@ -1050,33 +1147,33 @@ var NodePathWalker = class {
1050
1147
  /**
1051
1148
  * Walk the arguments of a desired call expression so their bindings can be analysed.
1052
1149
  */
1053
- walkCallExpression(path) {
1054
- const calleePath = path.get("callee");
1150
+ walkCallExpression(path2) {
1151
+ const calleePath = path2.get("callee");
1055
1152
  if (calleePath.isIdentifier() && this.isIgnoredCallIdentifier(calleePath.node.name)) {
1056
- for (const arg of path.get("arguments")) {
1153
+ for (const arg of path2.get("arguments")) {
1057
1154
  this.walkNode(arg);
1058
1155
  }
1059
1156
  }
1060
1157
  }
1061
- walkExportDeclaration(path) {
1062
- if (path.isExportDeclaration()) {
1063
- if (path.isExportNamedDeclaration()) {
1064
- this.walkExportNamedDeclaration(path);
1065
- } else if (path.isExportDefaultDeclaration()) {
1066
- this.walkExportDefaultDeclaration(path);
1067
- } else if (path.isExportAllDeclaration()) {
1068
- this.walkExportAllDeclaration(path);
1158
+ walkExportDeclaration(path2) {
1159
+ if (path2.isExportDeclaration()) {
1160
+ if (path2.isExportNamedDeclaration()) {
1161
+ this.walkExportNamedDeclaration(path2);
1162
+ } else if (path2.isExportDefaultDeclaration()) {
1163
+ this.walkExportDefaultDeclaration(path2);
1164
+ } else if (path2.isExportAllDeclaration()) {
1165
+ this.walkExportAllDeclaration(path2);
1069
1166
  }
1070
1167
  }
1071
1168
  }
1072
- walkExportNamedDeclaration(path) {
1073
- const declaration = path.get("declaration");
1169
+ walkExportNamedDeclaration(path2) {
1170
+ const declaration = path2.get("declaration");
1074
1171
  if (declaration.isVariableDeclaration()) {
1075
1172
  for (const decl of declaration.get("declarations")) {
1076
1173
  this.walkNode(decl);
1077
1174
  }
1078
1175
  }
1079
- const specifiers = path.get("specifiers");
1176
+ const specifiers = path2.get("specifiers");
1080
1177
  for (const spec of specifiers) {
1081
1178
  if (spec.isExportSpecifier()) {
1082
1179
  const local = spec.get("local");
@@ -1086,20 +1183,20 @@ var NodePathWalker = class {
1086
1183
  }
1087
1184
  }
1088
1185
  }
1089
- walkExportDefaultDeclaration(path) {
1090
- const decl = path.get("declaration");
1186
+ walkExportDefaultDeclaration(path2) {
1187
+ const decl = path2.get("declaration");
1091
1188
  if (decl.isIdentifier()) {
1092
1189
  this.walkNode(decl);
1093
1190
  } else {
1094
1191
  this.walkNode(decl);
1095
1192
  }
1096
1193
  }
1097
- walkExportAllDeclaration(path) {
1098
- const source = path.get("source");
1194
+ walkExportAllDeclaration(path2) {
1195
+ const source = path2.get("source");
1099
1196
  if (source.isStringLiteral()) {
1100
1197
  this.imports.add(
1101
1198
  {
1102
- declaration: path,
1199
+ declaration: path2,
1103
1200
  source: source.node.value,
1104
1201
  type: "ExportAllDeclaration"
1105
1202
  }
@@ -1109,8 +1206,8 @@ var NodePathWalker = class {
1109
1206
  };
1110
1207
 
1111
1208
  // src/js/sourceAnalysis.ts
1112
- function createModuleSpecifierReplacementToken(path, replacement) {
1113
- const node = path.node;
1209
+ function createModuleSpecifierReplacementToken(path2, replacement) {
1210
+ const node = path2.node;
1114
1211
  if (node.value === replacement) {
1115
1212
  return void 0;
1116
1213
  }
@@ -1126,17 +1223,17 @@ function createModuleSpecifierReplacementToken(path, replacement) {
1126
1223
  start,
1127
1224
  end,
1128
1225
  value: replacement,
1129
- path
1226
+ path: path2
1130
1227
  };
1131
1228
  }
1132
1229
  function collectModuleSpecifierReplacementTokens(analysis, replacements) {
1133
1230
  const tokens = [];
1134
- const applyReplacement = (path) => {
1135
- const replacement = replacements[path.node.value];
1231
+ const applyReplacement = (path2) => {
1232
+ const replacement = replacements[path2.node.value];
1136
1233
  if (!replacement) {
1137
1234
  return;
1138
1235
  }
1139
- const token = createModuleSpecifierReplacementToken(path, replacement);
1236
+ const token = createModuleSpecifierReplacementToken(path2, replacement);
1140
1237
  if (token) {
1141
1238
  tokens.push(token);
1142
1239
  }
@@ -1188,12 +1285,12 @@ function createTaggedTemplateIgnore({ matcher, names }) {
1188
1285
  }
1189
1286
  return false;
1190
1287
  };
1191
- const resolvesMemberExpressionToIgnore = (path, seen) => {
1192
- const propertyPath = path.get("property");
1288
+ const resolvesMemberExpressionToIgnore = (path2, seen) => {
1289
+ const propertyPath = path2.get("property");
1193
1290
  if (propertyMatches(propertyPath)) {
1194
1291
  return true;
1195
1292
  }
1196
- const objectPath = path.get("object");
1293
+ const objectPath = path2.get("object");
1197
1294
  if (objectPath.isIdentifier()) {
1198
1295
  const binding = objectPath.scope.getBinding(objectPath.node.name);
1199
1296
  if (binding) {
@@ -1348,9 +1445,9 @@ function analyzeSource(ast, options, handler) {
1348
1445
  const walker = new NodePathWalker(
1349
1446
  {
1350
1447
  ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
1351
- callback(path) {
1352
- if (path.isStringLiteral() || path.isTemplateElement()) {
1353
- ignoredPaths.add(path);
1448
+ callback(path2) {
1449
+ if (path2.isStringLiteral() || path2.isTemplateElement()) {
1450
+ ignoredPaths.add(path2);
1354
1451
  }
1355
1452
  }
1356
1453
  }
@@ -1438,15 +1535,15 @@ function processUpdatedSource(rawSource, options, analysis) {
1438
1535
  const ms = new MagicString(rawSource);
1439
1536
  const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
1440
1537
  const replacementTokens = [];
1441
- for (const path of targetPaths) {
1442
- if (ignoredPaths.has(path)) {
1538
+ for (const path2 of targetPaths) {
1539
+ if (ignoredPaths.has(path2)) {
1443
1540
  continue;
1444
1541
  }
1445
1542
  const token = replaceHandleValue(
1446
- path,
1543
+ path2,
1447
1544
  {
1448
1545
  ...options,
1449
- needEscaped: path.isStringLiteral() ? options.needEscaped ?? true : false
1546
+ needEscaped: path2.isStringLiteral() ? options.needEscaped ?? true : false
1450
1547
  }
1451
1548
  );
1452
1549
  if (token) {
@@ -1628,21 +1725,21 @@ function createAttributeMatcher(entities) {
1628
1725
  // src/wxml/whitespace.ts
1629
1726
  var WHITESPACE_CODES = /* @__PURE__ */ new Set([
1630
1727
  9,
1631
- // \t
1728
+ // 制表符 \t
1632
1729
  10,
1633
- // \n
1730
+ // 换行符 \n
1634
1731
  11,
1635
- // \v
1732
+ // 垂直制表符 \v
1636
1733
  12,
1637
- // \f
1734
+ // 换页符 \f
1638
1735
  13,
1639
- // \r
1736
+ // 回车符 \r
1640
1737
  32,
1641
- // space
1738
+ // 空格
1642
1739
  160,
1643
- // \u00A0
1740
+ // 不间断空格 \u00A0
1644
1741
  65279
1645
- // \uFEFF
1742
+ // 零宽无断行空格 \uFEFF
1646
1743
  ]);
1647
1744
  function isWhitespace(char) {
1648
1745
  if (char.length === 0) {
@@ -1793,16 +1890,16 @@ function generateCode(match, options = {}) {
1793
1890
  const ast = parseExpression(match);
1794
1891
  const jsTokenUpdater = new JsTokenUpdater();
1795
1892
  traverse(ast, {
1796
- StringLiteral(path) {
1797
- if (t.isMemberExpression(path.parent)) {
1893
+ StringLiteral(path2) {
1894
+ if (t.isMemberExpression(path2.parent)) {
1798
1895
  return;
1799
1896
  }
1800
- if (t.isBinaryExpression(path.parent) && (t.isConditionalExpression(path.parentPath?.parent) || t.isLogicalExpression(path.parentPath?.parent))) {
1897
+ if (t.isBinaryExpression(path2.parent) && (t.isConditionalExpression(path2.parentPath?.parent) || t.isLogicalExpression(path2.parentPath?.parent))) {
1801
1898
  return;
1802
1899
  }
1803
1900
  jsTokenUpdater.addToken(
1804
1901
  replaceHandleValue(
1805
- path,
1902
+ path2,
1806
1903
  {
1807
1904
  escapeMap: options.escapeMap,
1808
1905
  classNameSet: options.runtimeSet,
@@ -2040,7 +2137,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
2040
2137
  }
2041
2138
 
2042
2139
  // src/context/logger.ts
2043
- import { logger } from "@weapp-tailwindcss/logger";
2140
+ import { logger as logger2 } from "@weapp-tailwindcss/logger";
2044
2141
  var loggerLevelMap = {
2045
2142
  error: 0,
2046
2143
  warn: 1,
@@ -2048,7 +2145,7 @@ var loggerLevelMap = {
2048
2145
  silent: -999
2049
2146
  };
2050
2147
  function applyLoggerLevel(logLevel) {
2051
- logger.level = loggerLevelMap[logLevel ?? "info"] ?? loggerLevelMap.info;
2148
+ logger2.level = loggerLevelMap[logLevel ?? "info"] ?? loggerLevelMap.info;
2052
2149
  }
2053
2150
 
2054
2151
  // src/context/index.ts
@@ -2101,26 +2198,38 @@ function ensureDefaultsIncluded(value) {
2101
2198
  }
2102
2199
  return value;
2103
2200
  }
2104
- async function clearTailwindcssPatcherCache(patcher) {
2201
+ async function clearTailwindcssPatcherCache(patcher, options) {
2105
2202
  if (!patcher) {
2106
2203
  return;
2107
2204
  }
2108
2205
  const cacheOptions = patcher.options?.cache;
2109
- if (!cacheOptions || cacheOptions.enabled === false) {
2206
+ if (cacheOptions == null || cacheOptions === false || typeof cacheOptions === "object" && cacheOptions.enabled === false) {
2110
2207
  return;
2111
2208
  }
2112
- const cachePath = cacheOptions.path ?? patcher.cacheStore?.options?.path;
2113
- if (!cachePath) {
2209
+ const cachePaths = /* @__PURE__ */ new Map();
2210
+ const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
2211
+ if (normalizedCacheOptions?.path) {
2212
+ cachePaths.set(normalizedCacheOptions.path, false);
2213
+ }
2214
+ if (patcher.cacheStore?.options?.path) {
2215
+ cachePaths.set(patcher.cacheStore.options.path, false);
2216
+ }
2217
+ if (options?.removeDirectory && normalizedCacheOptions?.dir) {
2218
+ cachePaths.set(normalizedCacheOptions.dir, true);
2219
+ }
2220
+ if (!cachePaths.size) {
2114
2221
  return;
2115
2222
  }
2116
- try {
2117
- await rm(cachePath, { force: true });
2118
- } catch (error) {
2119
- const err = error;
2120
- if (err?.code === "ENOENT") {
2121
- return;
2223
+ for (const [cachePath, recursive] of cachePaths.entries()) {
2224
+ try {
2225
+ await rm(cachePath, { force: true, recursive });
2226
+ } catch (error) {
2227
+ const err = error;
2228
+ if (err?.code === "ENOENT") {
2229
+ continue;
2230
+ }
2231
+ logger3.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
2122
2232
  }
2123
- logger2.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
2124
2233
  }
2125
2234
  }
2126
2235
  function getCompilerContext(opts) {
@@ -2132,11 +2241,13 @@ function getCompilerContext(opts) {
2132
2241
  ctx.escapeMap = ctx.customReplaceDictionary;
2133
2242
  applyLoggerLevel(ctx.logLevel);
2134
2243
  const twPatcher = createTailwindcssPatcherFromContext(ctx);
2244
+ logTailwindcssTarget("runtime", twPatcher, ctx.tailwindcssBasedir);
2135
2245
  if (twPatcher.packageInfo?.version) {
2136
- logger2.success(`\u5F53\u524D\u4F7F\u7528 ${pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${pc.underline(pc.bold(pc.green(twPatcher.packageInfo.version)))}`);
2246
+ logger3.success(`\u5F53\u524D\u4F7F\u7528 ${pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${pc.underline(pc.bold(pc.green(twPatcher.packageInfo.version)))}`);
2137
2247
  } else {
2138
- logger2.warn(`${pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
2248
+ logger3.warn(`${pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
2139
2249
  }
2250
+ warnIfCliPatchTargetMismatch(ctx.tailwindcssBasedir, twPatcher);
2140
2251
  let cssCalcOptions = ctx.cssCalc ?? twPatcher.majorVersion === 4;
2141
2252
  if (twPatcher.majorVersion === 4 && cssCalcOptions) {
2142
2253
  cssCalcOptions = ensureDefaultsIncluded(cssCalcOptions);
@@ -2177,11 +2288,15 @@ export {
2177
2288
  createTailwindPatchPromise,
2178
2289
  refreshTailwindRuntimeState,
2179
2290
  collectRuntimeClassSet,
2291
+ logTailwindcssTarget,
2292
+ saveCliPatchTargetRecord,
2180
2293
  toCustomAttributesEntities,
2181
2294
  pluginName,
2182
2295
  vitePluginName,
2183
2296
  WEAPP_TW_REQUIRED_NODE_VERSION,
2297
+ replaceWxml,
2184
2298
  createAttributeMatcher,
2185
2299
  generateCode,
2300
+ clearTailwindcssPatcherCache,
2186
2301
  getCompilerContext
2187
2302
  };