weapp-tailwindcss 4.11.2 → 4.12.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/README.md +38 -0
  2. package/bin/weapp-tailwindcss.js +21 -1
  3. package/dist/{chunk-AV3XB6EQ.js → chunk-2A4NRLSY.js} +5 -5
  4. package/dist/{chunk-WJIRXC26.js → chunk-6JBFHYFM.js} +134 -128
  5. package/dist/{chunk-OMARW5NC.mjs → chunk-AYJ4HLWZ.mjs} +4 -2
  6. package/dist/{chunk-W3DXDWYC.mjs → chunk-CMNCGACY.mjs} +66 -60
  7. package/dist/{chunk-ZZ36BKM5.mjs → chunk-CQMHHQRN.mjs} +6 -2
  8. package/dist/{chunk-OYSABARD.js → chunk-E7I5TW5K.js} +3 -2
  9. package/dist/{chunk-7LKMJZD2.js → chunk-GMKSBLNY.js} +2 -2
  10. package/dist/{chunk-EFBQ4SQR.mjs → chunk-HL3US2OT.mjs} +1 -1
  11. package/dist/{chunk-AB2RGZQO.mjs → chunk-LWEVOVRD.mjs} +144 -76
  12. package/dist/{chunk-QK6VNNNL.js → chunk-NIS74SI6.js} +8 -6
  13. package/dist/{chunk-CRDOWYG4.js → chunk-ONLKZIRQ.js} +1 -1
  14. package/dist/{chunk-3QHYEMEW.js → chunk-PAAX4FDD.js} +45 -40
  15. package/dist/{chunk-JIERVBTX.mjs → chunk-SHDJA4GG.mjs} +1 -1
  16. package/dist/{chunk-SUKOZ6OG.js → chunk-SRAG3FST.js} +10 -6
  17. package/dist/{chunk-TT5WHNGS.js → chunk-YVRX3F6S.js} +149 -81
  18. package/dist/{chunk-2LH6PZH3.mjs → chunk-ZCH4YINE.mjs} +3 -2
  19. package/dist/{chunk-VGPAKLMZ.mjs → chunk-ZGIN2OAY.mjs} +12 -7
  20. package/dist/cli.js +2233 -158
  21. package/dist/cli.mjs +2238 -163
  22. package/dist/core.d.mts +1 -1
  23. package/dist/core.d.ts +1 -1
  24. package/dist/core.js +14 -9
  25. package/dist/core.mjs +10 -5
  26. package/dist/css-macro/postcss.js +4 -4
  27. package/dist/css-macro/postcss.mjs +2 -2
  28. package/dist/css-macro.js +5 -5
  29. package/dist/css-macro.mjs +2 -2
  30. package/dist/defaults.d.mts +1 -1
  31. package/dist/defaults.d.ts +1 -1
  32. package/dist/defaults.js +1 -1
  33. package/dist/defaults.mjs +1 -1
  34. package/dist/gulp.d.mts +1 -1
  35. package/dist/gulp.d.ts +1 -1
  36. package/dist/gulp.js +5 -5
  37. package/dist/gulp.mjs +4 -4
  38. package/dist/{index-CoXntW_P.d.mts → index-BXrmQelt.d.mts} +29 -1
  39. package/dist/{index-CoXntW_P.d.ts → index-BXrmQelt.d.ts} +29 -1
  40. package/dist/index.d.mts +1 -1
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.js +9 -9
  43. package/dist/index.mjs +7 -7
  44. package/dist/postcss-html-transform.js +1 -1
  45. package/dist/postcss-html-transform.mjs +1 -1
  46. package/dist/presets.d.mts +8 -1
  47. package/dist/presets.d.ts +8 -1
  48. package/dist/presets.js +7 -6
  49. package/dist/presets.mjs +3 -2
  50. package/dist/reset.d.mts +1 -31
  51. package/dist/reset.d.ts +3 -32
  52. package/dist/reset.js +3 -160
  53. package/dist/reset.mjs +3 -160
  54. package/dist/types.d.mts +2 -2
  55. package/dist/types.d.ts +2 -2
  56. package/dist/types.js +1 -1
  57. package/dist/types.mjs +1 -1
  58. package/dist/vite.d.mts +1 -1
  59. package/dist/vite.d.ts +1 -1
  60. package/dist/vite.js +6 -6
  61. package/dist/vite.mjs +4 -4
  62. package/dist/weapp-tw-css-import-rewrite-loader.js +10 -5
  63. package/dist/weapp-tw-runtime-classset-loader.js +9 -4
  64. package/dist/webpack.d.mts +1 -1
  65. package/dist/webpack.d.ts +1 -1
  66. package/dist/webpack.js +7 -7
  67. package/dist/webpack.mjs +5 -5
  68. package/dist/webpack4.d.mts +1 -1
  69. package/dist/webpack4.d.ts +1 -1
  70. package/dist/webpack4.js +65 -56
  71. package/dist/webpack4.mjs +35 -26
  72. package/package.json +12 -7
  73. package/scripts/postinstall.mjs +59 -0
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/cli.ts
2
- import process18 from "process";
3
- import semver from "semver";
2
+ import process19 from "process";
3
+ import semver2 from "semver";
4
4
  import { createTailwindcssPatchCli } from "tailwindcss-patch";
5
5
 
6
6
  // src/cli/context.ts
@@ -184,7 +184,7 @@ import { logger as logger2 } from "@weapp-tailwindcss/logger";
184
184
  // package.json
185
185
  var package_default = {
186
186
  name: "weapp-tailwindcss",
187
- version: "4.11.2",
187
+ version: "4.12.0-alpha.2",
188
188
  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!",
189
189
  author: "ice breaker <1324318532@qq.com>",
190
190
  license: "MIT",
@@ -334,13 +334,14 @@ var package_default = {
334
334
  "dist",
335
335
  "index.css",
336
336
  "preflight.css",
337
+ "scripts/postinstall.mjs",
337
338
  "theme.css",
338
339
  "uni-app-x.css",
339
340
  "utilities.css",
340
341
  "with-layer.css"
341
342
  ],
342
343
  engines: {
343
- node: "^18.17.0 || >=20.5.0"
344
+ node: "^20.19.0 || >=22.12.0"
344
345
  },
345
346
  scripts: {
346
347
  dev: "tsup --watch --sourcemap",
@@ -349,7 +350,7 @@ var package_default = {
349
350
  "build:cli": "cd plugins/cli && pnpm run build",
350
351
  "build:css": "tsx scripts/build-css.ts",
351
352
  "build:weapp-theme": "tsx scripts/build-weapp-theme.ts",
352
- test: "npm run postinstall && vitest run",
353
+ test: "pnpm run cli:patch && vitest run",
353
354
  "test:dev": "vitest",
354
355
  "test:ui": "vitest --ui",
355
356
  bench: "vitest bench --config ./vitest.config.ts",
@@ -366,7 +367,7 @@ var package_default = {
366
367
  release: "tsx scripts/release.ts",
367
368
  lint: "eslint .",
368
369
  "lint:fix": "eslint ./src --fix",
369
- postinstall: "node bin/weapp-tailwindcss.js patch",
370
+ postinstall: "node scripts/postinstall.mjs",
370
371
  "bench:vite-dev-hmr": "tsx scripts/vite-dev-hmr-bench.ts",
371
372
  "test:watch-hmr": "node --import tsx scripts/watch-hmr-regression/index.ts"
372
373
  },
@@ -386,6 +387,7 @@ var package_default = {
386
387
  "@weapp-core/regex": "~1.0.1",
387
388
  "@weapp-tailwindcss/logger": "workspace:*",
388
389
  "@weapp-tailwindcss/postcss": "workspace:*",
390
+ "@weapp-tailwindcss/reset": "workspace:*",
389
391
  "@weapp-tailwindcss/shared": "workspace:*",
390
392
  cac: "6.7.14",
391
393
  "comment-json": "^4.6.2",
@@ -400,11 +402,14 @@ var package_default = {
400
402
  "tailwindcss-patch": "catalog:tailwindcssPatch",
401
403
  "webpack-sources": "3.3.4",
402
404
  yaml: "^2.8.3"
405
+ },
406
+ devDependencies: {
407
+ "fast-check": "^4.7.0"
403
408
  }
404
409
  };
405
410
 
406
411
  // src/constants.ts
407
- var WEAPP_TW_REQUIRED_NODE_VERSION = "18.17.0";
412
+ var WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
408
413
  var WEAPP_TW_VERSION = package_default.version;
409
414
 
410
415
  // src/tailwindcss/targets/record-io.ts
@@ -550,111 +555,1903 @@ function createPatchTargetRecorder(baseDir, patcher, options) {
550
555
  break;
551
556
  default:
552
557
  break;
553
- }
554
- const onPatched = async () => saveCliPatchTargetRecord(normalizedBase, patcher, {
555
- cwd: options?.cwd ?? normalizedBase,
556
- source: options?.source ?? "cli",
557
- recordPath: location.recordPath,
558
- recordKey: location.recordKey,
559
- packageJsonPath: location.packageJsonPath
560
- });
558
+ }
559
+ const onPatched = async () => saveCliPatchTargetRecord(normalizedBase, patcher, {
560
+ cwd: options?.cwd ?? normalizedBase,
561
+ source: options?.source ?? "cli",
562
+ recordPath: location.recordPath,
563
+ recordKey: location.recordKey,
564
+ packageJsonPath: location.packageJsonPath
565
+ });
566
+ return {
567
+ recordPath: location.recordPath,
568
+ message,
569
+ reason,
570
+ onPatched
571
+ };
572
+ }
573
+
574
+ // src/tailwindcss/targets.ts
575
+ function logTailwindcssTarget(kind, patcher, baseDir) {
576
+ const packageInfo = patcher?.packageInfo;
577
+ const label = kind === "cli" ? "weapp-tw patch" : "Weapp-tailwindcss";
578
+ if (!packageInfo?.rootPath) {
579
+ logger3.warn(
580
+ "%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
581
+ label,
582
+ baseDir ?? process6.cwd()
583
+ );
584
+ return;
585
+ }
586
+ const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
587
+ const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
588
+ if (kind === "runtime") {
589
+ logRuntimeTailwindcssTarget(baseDir, packageInfo.rootPath, packageInfo.version);
590
+ return;
591
+ }
592
+ logger3.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
593
+ }
594
+
595
+ // src/tailwindcss/v4/config.ts
596
+ import { logger as logger4 } from "@weapp-tailwindcss/logger";
597
+
598
+ // src/tailwindcss/v4/patcher.ts
599
+ import { logger as logger6 } from "@weapp-tailwindcss/logger";
600
+
601
+ // src/tailwindcss/patcher.ts
602
+ import path7 from "path";
603
+ import process8 from "process";
604
+ import { logger as logger5 } from "@weapp-tailwindcss/logger";
605
+ import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
606
+ import { TailwindcssPatcher } from "tailwindcss-patch";
607
+
608
+ // src/tailwindcss/patcher-resolve.ts
609
+ import { existsSync as existsSync4 } from "fs";
610
+ import { createRequire } from "module";
611
+ import path6 from "path";
612
+ import process7 from "process";
613
+ import { fileURLToPath } from "url";
614
+
615
+ // src/tailwindcss/v4/css-entries.ts
616
+ import path8 from "path";
617
+
618
+ // src/context/compiler-context-cache.ts
619
+ import { Buffer } from "buffer";
620
+ import path9 from "path";
621
+ import process9 from "process";
622
+ import { logger as logger7 } from "@weapp-tailwindcss/logger";
623
+ var globalCacheHolder = globalThis;
624
+ var compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
625
+
626
+ // src/context/handlers.ts
627
+ import { createStyleHandler } from "@weapp-tailwindcss/postcss";
628
+
629
+ // src/js/index.ts
630
+ import { LRUCache as LRUCache3 } from "lru-cache";
631
+
632
+ // src/babel/index.ts
633
+ import _babelTraverse from "@babel/traverse";
634
+ import { parse, parseExpression } from "@babel/parser";
635
+ function _interopDefaultCompat(e) {
636
+ return e && typeof e === "object" && "default" in e ? e.default : e;
637
+ }
638
+ var traverse = _interopDefaultCompat(_babelTraverse);
639
+
640
+ // src/utils/nameMatcher.ts
641
+ import { escapeStringRegexp } from "@weapp-core/regex";
642
+ var NEVER_MATCH_NAME = () => false;
643
+ var GLOBAL_FLAG_REGEXP = /g/g;
644
+ function buildFuzzyMatcher(fuzzyStrings) {
645
+ if (fuzzyStrings.length === 0) {
646
+ return void 0;
647
+ }
648
+ if (fuzzyStrings.length === 1) {
649
+ const [needle] = fuzzyStrings;
650
+ return (value) => value.includes(needle);
651
+ }
652
+ const unique = [...new Set(fuzzyStrings)];
653
+ const pattern = new RegExp(unique.map(escapeStringRegexp).join("|"));
654
+ return (value) => pattern.test(value);
655
+ }
656
+ function normaliseRegex(regex) {
657
+ const { source, flags } = regex;
658
+ if (!flags.includes("g")) {
659
+ return regex;
660
+ }
661
+ return new RegExp(source, flags.replace(GLOBAL_FLAG_REGEXP, ""));
662
+ }
663
+ function createNameMatcher(list, { exact = false } = {}) {
664
+ if (!list || list.length === 0) {
665
+ return NEVER_MATCH_NAME;
666
+ }
667
+ const exactStrings = exact ? /* @__PURE__ */ new Set() : void 0;
668
+ const fuzzyStrings = [];
669
+ const regexList = [];
670
+ for (const item of list) {
671
+ if (typeof item === "string") {
672
+ if (exact) {
673
+ exactStrings.add(item);
674
+ } else {
675
+ fuzzyStrings.push(item);
676
+ }
677
+ } else {
678
+ regexList.push(normaliseRegex(item));
679
+ }
680
+ }
681
+ if (exact) {
682
+ const exactStringCount = exactStrings?.size ?? 0;
683
+ if (exactStringCount === 1 && regexList.length === 0) {
684
+ const [needle] = exactStrings;
685
+ return (value) => value === needle;
686
+ }
687
+ if (regexList.length === 0) {
688
+ return (value) => exactStrings.has(value);
689
+ }
690
+ if (exactStringCount === 0 && regexList.length === 1) {
691
+ const [regex] = regexList;
692
+ return (value) => regex.test(value);
693
+ }
694
+ return (value) => {
695
+ if (exactStrings?.has(value)) {
696
+ return true;
697
+ }
698
+ return regexList.some((regex) => regex.test(value));
699
+ };
700
+ }
701
+ const fuzzyMatcher = exact ? void 0 : buildFuzzyMatcher(fuzzyStrings);
702
+ const hasRegex = regexList.length > 0;
703
+ if (fuzzyMatcher && !hasRegex) {
704
+ return fuzzyMatcher;
705
+ }
706
+ if (!fuzzyMatcher && regexList.length === 1) {
707
+ const [regex] = regexList;
708
+ return (value) => regex.test(value);
709
+ }
710
+ return (value) => {
711
+ if (fuzzyMatcher?.(value)) {
712
+ return true;
713
+ }
714
+ if (!hasRegex) {
715
+ return false;
716
+ }
717
+ return regexList.some((regex) => regex.test(value));
718
+ };
719
+ }
720
+
721
+ // src/js/babel/parse.ts
722
+ import { LRUCache as LRUCache2 } from "lru-cache";
723
+ var parseCache = new LRUCache2(
724
+ {
725
+ max: 1024
726
+ }
727
+ );
728
+ function genCacheKey(source, options) {
729
+ if (typeof options === "string") {
730
+ return source + options;
731
+ }
732
+ return source + JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val);
733
+ }
734
+ function babelParse(code, opts = {}) {
735
+ const { cache, cacheKey, ...rest } = opts;
736
+ const cacheKeyString = genCacheKey(code, cacheKey ?? rest);
737
+ let result;
738
+ if (cache) {
739
+ result = parseCache.get(cacheKeyString);
740
+ }
741
+ if (!result) {
742
+ const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
743
+ result = parse(code, parseOptions);
744
+ if (cache) {
745
+ parseCache.set(cacheKeyString, result);
746
+ }
747
+ }
748
+ return result;
749
+ }
750
+
751
+ // src/js/babel/process.ts
752
+ import MagicString from "magic-string";
753
+
754
+ // src/js/handlers.ts
755
+ import { jsStringEscape } from "@ast-core/escape";
756
+ import { splitCode } from "@weapp-tailwindcss/shared/extractors";
757
+
758
+ // src/wxml/shared.ts
759
+ import { escape, MappingChars2String as MappingChars2String2 } from "@weapp-core/escape";
760
+ var NEWLINE_RE = /[\n\r]+/g;
761
+ function replaceWxml(original, options = {
762
+ keepEOL: false,
763
+ escapeMap: MappingChars2String2
764
+ }) {
765
+ const { keepEOL, escapeMap, ignoreHead } = options;
766
+ let res = original;
767
+ if (!keepEOL) {
768
+ res = res.replaceAll(NEWLINE_RE, "");
769
+ }
770
+ res = escape(res, {
771
+ map: escapeMap,
772
+ ignoreHead
773
+ });
774
+ return res;
775
+ }
776
+
777
+ // src/shared/classname-transform.ts
778
+ var escapedCandidateCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
779
+ var defaultEscapedCandidateCache = /* @__PURE__ */ new Map();
780
+ var lastEscapedCandidateEscapeMap;
781
+ var lastEscapedCandidateCacheStore;
782
+ function isUrlLikeCandidate(candidate) {
783
+ return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
784
+ }
785
+ function isArbitraryValueCandidate(candidate) {
786
+ let hasOpenBracket = false;
787
+ let hasCloseBracket = false;
788
+ for (let i = 0; i < candidate.length; i++) {
789
+ const char = candidate[i];
790
+ if (char === "[") {
791
+ hasOpenBracket = true;
792
+ } else if (char === "]") {
793
+ hasCloseBracket = true;
794
+ }
795
+ if (hasOpenBracket && hasCloseBracket) {
796
+ break;
797
+ }
798
+ }
799
+ if (!hasOpenBracket || !hasCloseBracket) {
800
+ return false;
801
+ }
802
+ const normalized = candidate.trim();
803
+ if (isUrlLikeCandidate(normalized)) {
804
+ return false;
805
+ }
806
+ return true;
807
+ }
808
+ function shouldEnableArbitraryValueFallbackByInputs(classNameSet, jsArbitraryValueFallback, tailwindcssMajorVersion) {
809
+ if (jsArbitraryValueFallback === true) {
810
+ return true;
811
+ }
812
+ if (jsArbitraryValueFallback === false) {
813
+ return false;
814
+ }
815
+ return tailwindcssMajorVersion === 4 && (!classNameSet || classNameSet.size === 0);
816
+ }
817
+ function shouldEnableArbitraryValueFallback({
818
+ classNameSet,
819
+ jsArbitraryValueFallback,
820
+ tailwindcssMajorVersion
821
+ }) {
822
+ return shouldEnableArbitraryValueFallbackByInputs(
823
+ classNameSet,
824
+ jsArbitraryValueFallback,
825
+ tailwindcssMajorVersion
826
+ );
827
+ }
828
+ var SKIP_RESULT = { decision: "skip" };
829
+ var DIRECT_RESULT = { decision: "direct" };
830
+ var FALLBACK_RESULT = { decision: "fallback" };
831
+ function getEscapedCandidateCacheStore(escapeMap) {
832
+ if (!escapeMap) {
833
+ return defaultEscapedCandidateCache;
834
+ }
835
+ if (escapeMap === lastEscapedCandidateEscapeMap && lastEscapedCandidateCacheStore) {
836
+ return lastEscapedCandidateCacheStore;
837
+ }
838
+ let store = escapedCandidateCacheByEscapeMap.get(escapeMap);
839
+ if (!store) {
840
+ store = /* @__PURE__ */ new Map();
841
+ escapedCandidateCacheByEscapeMap.set(escapeMap, store);
842
+ }
843
+ lastEscapedCandidateEscapeMap = escapeMap;
844
+ lastEscapedCandidateCacheStore = store;
845
+ return store;
846
+ }
847
+ function getEscapedCandidate(candidate, escapeMap, store = getEscapedCandidateCacheStore(escapeMap)) {
848
+ let cached = store.get(candidate);
849
+ if (cached === void 0) {
850
+ cached = replaceWxml(candidate, { escapeMap });
851
+ store.set(candidate, cached);
852
+ }
853
+ return cached;
854
+ }
855
+ function resolveClassNameTransformWithResult(candidate, {
856
+ alwaysEscape,
857
+ classNameSet,
858
+ escapeMap,
859
+ jsArbitraryValueFallback,
860
+ jsPreserveClass,
861
+ tailwindcssMajorVersion,
862
+ classContext
863
+ }) {
864
+ if (alwaysEscape) {
865
+ return DIRECT_RESULT;
866
+ }
867
+ if (jsPreserveClass?.(candidate)) {
868
+ return SKIP_RESULT;
869
+ }
870
+ if (classNameSet?.has(candidate)) {
871
+ return DIRECT_RESULT;
872
+ }
873
+ if (classNameSet && classNameSet.size > 0) {
874
+ const escapedCandidate = getEscapedCandidate(candidate, escapeMap);
875
+ if (escapedCandidate !== candidate && classNameSet.has(escapedCandidate)) {
876
+ return { decision: "escaped", escapedValue: escapedCandidate };
877
+ }
878
+ }
879
+ if (classContext && shouldEnableArbitraryValueFallbackByInputs(classNameSet, jsArbitraryValueFallback, tailwindcssMajorVersion) && isArbitraryValueCandidate(candidate)) {
880
+ return FALLBACK_RESULT;
881
+ }
882
+ return SKIP_RESULT;
883
+ }
884
+
885
+ // src/utils/decode.ts
886
+ var unicodeEscapeRE = /\\u([\dA-Fa-f]{4})/g;
887
+ var unicodeEscapeTestRE = /\\u[\dA-Fa-f]{4}/;
888
+ function decodeUnicode(value) {
889
+ if (!unicodeEscapeTestRE.test(value)) {
890
+ return value;
891
+ }
892
+ return value.replace(unicodeEscapeRE, (_match, hex) => {
893
+ const codePoint = Number.parseInt(hex, 16);
894
+ return Number.isNaN(codePoint) ? _match : String.fromCharCode(codePoint);
895
+ });
896
+ }
897
+ function decodeUnicode2(input) {
898
+ if (!unicodeEscapeTestRE.test(input)) {
899
+ return input;
900
+ }
901
+ try {
902
+ return JSON.parse(`"${input}"`);
903
+ } catch (_error) {
904
+ return decodeUnicode(input);
905
+ }
906
+ }
907
+
908
+ // src/js/class-context.ts
909
+ var CLASS_LIKE_KEYWORDS = /* @__PURE__ */ new Set([
910
+ "class",
911
+ "classname",
912
+ "hoverclass",
913
+ "virtualhostclass",
914
+ "rootclass"
915
+ ]);
916
+ var CLASS_HELPER_IDENTIFIERS = /* @__PURE__ */ new Set([
917
+ "cn",
918
+ "clsx",
919
+ "classnames",
920
+ "twmerge",
921
+ "cva",
922
+ "tv",
923
+ "cx",
924
+ "r"
925
+ ]);
926
+ var DASH_CODE = 45;
927
+ var COLON_CODE = 58;
928
+ var UPPERCASE_A_CODE = 65;
929
+ var UPPERCASE_Z_CODE = 90;
930
+ var UNDERSCORE_CODE = 95;
931
+ var ASCII_MAX_CODE = 127;
932
+ var NORMALIZE_KEYWORD_REGEXP = /[-_:]/g;
933
+ function normalizeKeyword(name) {
934
+ const length = name.length;
935
+ let firstNormalizedIndex = -1;
936
+ for (let i = 0; i < length; i++) {
937
+ const code = name.charCodeAt(i);
938
+ if (code === DASH_CODE || code === UNDERSCORE_CODE || code === COLON_CODE || code >= UPPERCASE_A_CODE && code <= UPPERCASE_Z_CODE) {
939
+ firstNormalizedIndex = i;
940
+ break;
941
+ }
942
+ if (code > ASCII_MAX_CODE) {
943
+ return name.replace(NORMALIZE_KEYWORD_REGEXP, "").toLowerCase();
944
+ }
945
+ }
946
+ if (firstNormalizedIndex === -1) {
947
+ return name;
948
+ }
949
+ let normalized = name.slice(0, firstNormalizedIndex);
950
+ for (let i = firstNormalizedIndex; i < length; i++) {
951
+ const code = name.charCodeAt(i);
952
+ if (code === DASH_CODE || code === UNDERSCORE_CODE || code === COLON_CODE) {
953
+ continue;
954
+ }
955
+ if (code >= UPPERCASE_A_CODE && code <= UPPERCASE_Z_CODE) {
956
+ normalized += String.fromCharCode(code + 32);
957
+ continue;
958
+ }
959
+ if (code > ASCII_MAX_CODE) {
960
+ return name.replace(NORMALIZE_KEYWORD_REGEXP, "").toLowerCase();
961
+ }
962
+ normalized += name[i];
963
+ }
964
+ return normalized;
965
+ }
966
+ function readObjectKeyName(path22) {
967
+ if (path22.isIdentifier()) {
968
+ return path22.node.name;
969
+ }
970
+ if (path22.isStringLiteral()) {
971
+ return path22.node.value;
972
+ }
973
+ if (path22.isTemplateLiteral() && path22.node.expressions.length === 0) {
974
+ return path22.node.quasis[0]?.value.cooked ?? path22.node.quasis[0]?.value.raw;
975
+ }
976
+ return void 0;
977
+ }
978
+ function isClassLikeObjectProperty(path22, valuePath) {
979
+ if (!path22.isObjectProperty()) {
980
+ return false;
981
+ }
982
+ if (path22.get("value") !== valuePath) {
983
+ return false;
984
+ }
985
+ const keyName = readObjectKeyName(path22.get("key"));
986
+ if (!keyName) {
987
+ return false;
988
+ }
989
+ return CLASS_LIKE_KEYWORDS.has(normalizeKeyword(keyName));
990
+ }
991
+ function isClassLikeJsxAttribute(path22) {
992
+ if (!path22.isJSXAttribute()) {
993
+ return false;
994
+ }
995
+ const namePath = path22.get("name");
996
+ if (!namePath.isJSXIdentifier()) {
997
+ return false;
998
+ }
999
+ return CLASS_LIKE_KEYWORDS.has(normalizeKeyword(namePath.node.name));
1000
+ }
1001
+ function readCallHelperName(calleePath) {
1002
+ if (calleePath.isIdentifier()) {
1003
+ return calleePath.node.name;
1004
+ }
1005
+ if (calleePath.isMemberExpression()) {
1006
+ const propertyPath = calleePath.get("property");
1007
+ if (propertyPath.isIdentifier()) {
1008
+ return propertyPath.node.name;
1009
+ }
1010
+ if (propertyPath.isStringLiteral()) {
1011
+ return propertyPath.node.value;
1012
+ }
1013
+ }
1014
+ return void 0;
1015
+ }
1016
+ function isClassLikeCallExpression(path22, valuePath) {
1017
+ if (!path22.isCallExpression()) {
1018
+ return false;
1019
+ }
1020
+ const helperName = readCallHelperName(path22.get("callee"));
1021
+ if (!helperName || !CLASS_HELPER_IDENTIFIERS.has(normalizeKeyword(helperName))) {
1022
+ return false;
1023
+ }
1024
+ return path22.get("arguments").includes(valuePath);
1025
+ }
1026
+ function isClassContextLiteralPath(path22) {
1027
+ let current = path22;
1028
+ while (current.parentPath) {
1029
+ const parent = current.parentPath;
1030
+ if (isClassLikeObjectProperty(parent, current)) {
1031
+ return true;
1032
+ }
1033
+ if (isClassLikeJsxAttribute(parent)) {
1034
+ return true;
1035
+ }
1036
+ if (isClassLikeCallExpression(parent, current)) {
1037
+ return true;
1038
+ }
1039
+ current = parent;
1040
+ }
1041
+ return false;
1042
+ }
1043
+
1044
+ // src/js/handlers.ts
1045
+ var debug2 = createDebug("[js:handlers] ");
1046
+ var replacementCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
1047
+ var defaultReplacementCache = /* @__PURE__ */ new Map();
1048
+ var WEAPP_TW_IGNORE_MARKER = "weapp-tw";
1049
+ var IGNORE_MARKER = "ignore";
1050
+ function getReplacementCacheStore(escapeMap) {
1051
+ if (!escapeMap) {
1052
+ return defaultReplacementCache;
1053
+ }
1054
+ let store = replacementCacheByEscapeMap.get(escapeMap);
1055
+ if (!store) {
1056
+ store = /* @__PURE__ */ new Map();
1057
+ replacementCacheByEscapeMap.set(escapeMap, store);
1058
+ }
1059
+ return store;
1060
+ }
1061
+ function getReplacement(candidate, escapeMap, store = getReplacementCacheStore(escapeMap)) {
1062
+ let cached = store.get(candidate);
1063
+ if (cached === void 0) {
1064
+ cached = replaceWxml(candidate, { escapeMap });
1065
+ store.set(candidate, cached);
1066
+ }
1067
+ return cached;
1068
+ }
1069
+ function hasIgnoreComment(node) {
1070
+ const { leadingComments } = node;
1071
+ if (!Array.isArray(leadingComments) || leadingComments.length === 0) {
1072
+ return false;
1073
+ }
1074
+ for (const comment of leadingComments) {
1075
+ const { value } = comment;
1076
+ if (value.includes(WEAPP_TW_IGNORE_MARKER) && value.includes(IGNORE_MARKER)) {
1077
+ return true;
1078
+ }
1079
+ }
1080
+ return false;
1081
+ }
1082
+ function extractLiteralValue(path22, { unescapeUnicode, arbitraryValues }) {
1083
+ const allowDoubleQuotes = arbitraryValues?.allowDoubleQuotes;
1084
+ const { node } = path22;
1085
+ let offset = 0;
1086
+ let original;
1087
+ if (node.type === "StringLiteral") {
1088
+ offset = 1;
1089
+ original = node.value;
1090
+ } else if (node.type === "TemplateElement") {
1091
+ original = node.value.raw;
1092
+ } else {
1093
+ original = "";
1094
+ }
1095
+ let literal = original;
1096
+ if (unescapeUnicode && original.includes("\\u")) {
1097
+ literal = decodeUnicode2(original);
1098
+ }
1099
+ return {
1100
+ allowDoubleQuotes,
1101
+ literal,
1102
+ offset,
1103
+ original
1104
+ };
1105
+ }
1106
+ function createCandidatePlanResolver(options, classContext) {
1107
+ const { escapeMap } = options;
1108
+ const replacementCache = getReplacementCacheStore(escapeMap);
1109
+ const transformOptions = classContext ? {
1110
+ ...options,
1111
+ classContext
1112
+ } : options;
1113
+ let firstCandidate = "";
1114
+ let firstPlan;
1115
+ let cache;
1116
+ const buildCandidatePlan = (candidate) => {
1117
+ const result = resolveClassNameTransformWithResult(candidate, transformOptions);
1118
+ if (result.decision === "skip") {
1119
+ return { result };
1120
+ }
1121
+ let replacement;
1122
+ if (result.decision === "escaped" && result.escapedValue) {
1123
+ replacement = result.escapedValue;
1124
+ replacementCache.set(candidate, replacement);
1125
+ } else {
1126
+ replacement = getReplacement(candidate, escapeMap, replacementCache);
1127
+ }
1128
+ return {
1129
+ result,
1130
+ replacement
1131
+ };
1132
+ };
1133
+ return (candidate) => {
1134
+ if (cache) {
1135
+ const cached = cache.get(candidate);
1136
+ if (cached) {
1137
+ return cached;
1138
+ }
1139
+ } else if (firstPlan && candidate === firstCandidate) {
1140
+ return firstPlan;
1141
+ }
1142
+ const plan = buildCandidatePlan(candidate);
1143
+ if (!firstPlan) {
1144
+ firstCandidate = candidate;
1145
+ firstPlan = plan;
1146
+ return plan;
1147
+ }
1148
+ if (!cache) {
1149
+ cache = /* @__PURE__ */ new Map();
1150
+ cache.set(firstCandidate, firstPlan);
1151
+ }
1152
+ cache.set(candidate, plan);
1153
+ return plan;
1154
+ };
1155
+ }
1156
+ function replaceHandleValue(path22, options) {
1157
+ const { needEscaped = false } = options;
1158
+ const { classNameSet, alwaysEscape } = options;
1159
+ const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
1160
+ if (!alwaysEscape && !fallbackEnabled && (!classNameSet || classNameSet.size === 0)) {
1161
+ return void 0;
1162
+ }
1163
+ if (hasIgnoreComment(path22.node)) {
1164
+ return void 0;
1165
+ }
1166
+ const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path22, options);
1167
+ const candidates = splitCode(literal, allowDoubleQuotes);
1168
+ if (candidates.length === 0) {
1169
+ return void 0;
1170
+ }
1171
+ const debugEnabled = debug2.enabled;
1172
+ const classContext = options.wrapExpression || isClassContextLiteralPath(path22);
1173
+ let transformed = literal;
1174
+ let mutated = false;
1175
+ let matchedCandidateCount = 0;
1176
+ let escapedDecisionCount = 0;
1177
+ let fallbackDecisionCount = 0;
1178
+ let escapedSamples;
1179
+ let skippedSamples;
1180
+ const resolveCandidatePlan = createCandidatePlanResolver(options, classContext);
1181
+ for (const candidate of candidates) {
1182
+ const plan = resolveCandidatePlan(candidate);
1183
+ if (plan.result.decision === "skip") {
1184
+ if (debugEnabled) {
1185
+ if (!skippedSamples) {
1186
+ skippedSamples = [];
1187
+ }
1188
+ if (skippedSamples.length < 6) {
1189
+ skippedSamples.push(candidate);
1190
+ }
1191
+ }
1192
+ continue;
1193
+ }
1194
+ if (debugEnabled) {
1195
+ matchedCandidateCount += 1;
1196
+ if (plan.result.decision === "escaped") {
1197
+ escapedDecisionCount += 1;
1198
+ if (!escapedSamples) {
1199
+ escapedSamples = [];
1200
+ }
1201
+ if (escapedSamples.length < 6) {
1202
+ escapedSamples.push(candidate);
1203
+ }
1204
+ }
1205
+ if (plan.result.decision === "fallback") {
1206
+ fallbackDecisionCount += 1;
1207
+ }
1208
+ }
1209
+ const replaced = transformed.replace(candidate, plan.replacement);
1210
+ if (replaced !== transformed) {
1211
+ transformed = replaced;
1212
+ mutated = true;
1213
+ }
1214
+ }
1215
+ const node = path22.node;
1216
+ if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
1217
+ return void 0;
1218
+ }
1219
+ if (debugEnabled) {
1220
+ debug2(
1221
+ "runtimeSet size=%d fallbackTriggered=%s candidates=%d matched=%d escapedHits=%d skipped=%d file=%s escapedSamples=%s skippedSamples=%s",
1222
+ classNameSet?.size ?? 0,
1223
+ fallbackDecisionCount > 0,
1224
+ candidates.length,
1225
+ matchedCandidateCount,
1226
+ escapedDecisionCount,
1227
+ skippedSamples?.length ?? 0,
1228
+ options.filename ?? "unknown",
1229
+ escapedSamples?.join(",") || "-",
1230
+ skippedSamples?.join(",") || "-"
1231
+ );
1232
+ }
1233
+ const start = node.start + offset;
1234
+ const end = node.end - offset;
1235
+ if (start >= end || transformed === original) {
1236
+ return void 0;
1237
+ }
1238
+ const value = needEscaped ? jsStringEscape(transformed) : transformed;
1239
+ return {
1240
+ start,
1241
+ end,
1242
+ value,
1243
+ path: path22
1244
+ };
1245
+ }
1246
+
1247
+ // src/js/sourceAnalysis.ts
1248
+ function hasReplacementEntries(replacements) {
1249
+ for (const key in replacements) {
1250
+ if (Object.hasOwn(replacements, key)) {
1251
+ return true;
1252
+ }
1253
+ }
1254
+ return false;
1255
+ }
1256
+ function createModuleSpecifierReplacementToken(path22, replacement) {
1257
+ const node = path22.node;
1258
+ if (node.value === replacement) {
1259
+ return void 0;
1260
+ }
1261
+ if (typeof node.start !== "number" || typeof node.end !== "number") {
1262
+ return void 0;
1263
+ }
1264
+ const start = node.start + 1;
1265
+ const end = node.end - 1;
1266
+ if (start >= end) {
1267
+ return void 0;
1268
+ }
1269
+ return {
1270
+ start,
1271
+ end,
1272
+ value: replacement,
1273
+ path: path22
1274
+ };
1275
+ }
1276
+ function collectModuleSpecifierReplacementTokens(analysis, replacements) {
1277
+ if (!hasReplacementEntries(replacements)) {
1278
+ return [];
1279
+ }
1280
+ if (analysis.importDeclarations.size === 0 && analysis.exportDeclarations.size === 0 && analysis.requireCallPaths.length === 0 && analysis.walker.imports.size === 0) {
1281
+ return [];
1282
+ }
1283
+ const tokens = [];
1284
+ const applyReplacement = (path22) => {
1285
+ const replacement = replacements[path22.node.value];
1286
+ if (!replacement) {
1287
+ return;
1288
+ }
1289
+ const token = createModuleSpecifierReplacementToken(path22, replacement);
1290
+ if (token) {
1291
+ tokens.push(token);
1292
+ }
1293
+ };
1294
+ for (const importPath of analysis.importDeclarations) {
1295
+ const source = importPath.get("source");
1296
+ if (source.isStringLiteral()) {
1297
+ applyReplacement(source);
1298
+ }
1299
+ }
1300
+ for (const exportPath of analysis.exportDeclarations) {
1301
+ if (exportPath.isExportNamedDeclaration() || exportPath.isExportAllDeclaration()) {
1302
+ const source = exportPath.get("source");
1303
+ if (source && !Array.isArray(source) && source.isStringLiteral()) {
1304
+ applyReplacement(source);
1305
+ }
1306
+ }
1307
+ }
1308
+ for (const literalPath of analysis.requireCallPaths) {
1309
+ applyReplacement(literalPath);
1310
+ }
1311
+ for (const token of analysis.walker.imports) {
1312
+ const replacement = replacements[token.source];
1313
+ if (replacement) {
1314
+ token.source = replacement;
1315
+ }
1316
+ }
1317
+ return tokens;
1318
+ }
1319
+
1320
+ // src/js/babel/process.ts
1321
+ var optionVariantsCache = /* @__PURE__ */ new WeakMap();
1322
+ function getNeedEscapedOptions(options, needEscaped) {
1323
+ if (options.needEscaped === needEscaped) {
1324
+ return options;
1325
+ }
1326
+ let cached = optionVariantsCache.get(options);
1327
+ if (!cached) {
1328
+ cached = {};
1329
+ optionVariantsCache.set(options, cached);
1330
+ }
1331
+ if (needEscaped) {
1332
+ if (!cached.stringLiteralOptions) {
1333
+ cached.stringLiteralOptions = {
1334
+ ...options,
1335
+ needEscaped: true
1336
+ };
1337
+ }
1338
+ return cached.stringLiteralOptions;
1339
+ }
1340
+ if (!cached.templateLiteralOptions) {
1341
+ cached.templateLiteralOptions = {
1342
+ ...options,
1343
+ needEscaped: false
1344
+ };
1345
+ }
1346
+ return cached.templateLiteralOptions;
1347
+ }
1348
+ function processUpdatedSource(rawSource, options, analysis) {
1349
+ const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
1350
+ if (targetPaths.length === 0 && !options.moduleSpecifierReplacements && jsTokenUpdater.length === 0) {
1351
+ return new MagicString(rawSource);
1352
+ }
1353
+ const replacementTokens = [];
1354
+ for (const path22 of targetPaths) {
1355
+ if (ignoredPaths.has(path22)) {
1356
+ continue;
1357
+ }
1358
+ const token = replaceHandleValue(
1359
+ path22,
1360
+ path22.isStringLiteral() ? getNeedEscapedOptions(options, true) : getNeedEscapedOptions(options, false)
1361
+ );
1362
+ if (token) {
1363
+ replacementTokens.push(token);
1364
+ }
1365
+ }
1366
+ if (options.moduleSpecifierReplacements) {
1367
+ replacementTokens.push(
1368
+ ...collectModuleSpecifierReplacementTokens(analysis, options.moduleSpecifierReplacements)
1369
+ );
1370
+ }
1371
+ if (jsTokenUpdater.length + replacementTokens.length === 0) {
1372
+ return new MagicString(rawSource);
1373
+ }
1374
+ const ms = new MagicString(rawSource);
1375
+ jsTokenUpdater.push(...replacementTokens).filter((token) => !ignoredPaths.has(token.path)).updateMagicString(ms);
1376
+ return ms;
1377
+ }
1378
+
1379
+ // src/js/evalTransforms.ts
1380
+ import { jsStringEscape as jsStringEscape2 } from "@ast-core/escape";
1381
+ var evalHandlerOptionsCache = /* @__PURE__ */ new WeakMap();
1382
+ var EVAL_SCOPE_ERROR_REGEXP = /pass a scope and parentPath|traversing a Program\/File/i;
1383
+ function isEvalPath(path22) {
1384
+ if (path22.isCallExpression()) {
1385
+ const calleePath = path22.get("callee");
1386
+ return calleePath.isIdentifier({ name: "eval" });
1387
+ }
1388
+ return false;
1389
+ }
1390
+ function createEvalReplacementToken(path22, updated) {
1391
+ const node = path22.node;
1392
+ let offset = 0;
1393
+ let original;
1394
+ if (path22.isStringLiteral()) {
1395
+ offset = 1;
1396
+ original = path22.node.value;
1397
+ } else if (path22.isTemplateElement()) {
1398
+ original = path22.node.value.raw;
1399
+ } else {
1400
+ original = "";
1401
+ }
1402
+ if (typeof node.start !== "number" || typeof node.end !== "number") {
1403
+ return void 0;
1404
+ }
1405
+ const start = node.start + offset;
1406
+ const end = node.end - offset;
1407
+ if (start >= end) {
1408
+ return void 0;
1409
+ }
1410
+ if (original === updated) {
1411
+ return void 0;
1412
+ }
1413
+ const value = path22.isStringLiteral() ? jsStringEscape2(updated) : updated;
1414
+ return {
1415
+ start,
1416
+ end,
1417
+ value,
1418
+ path: path22
1419
+ };
1420
+ }
1421
+ function handleEvalStringLiteral(path22, handlerOptions, updater, handler) {
1422
+ const { code } = handler(path22.node.value, handlerOptions);
1423
+ if (!code) {
1424
+ return;
1425
+ }
1426
+ const token = createEvalReplacementToken(path22, code);
1427
+ if (token) {
1428
+ updater.addToken(token);
1429
+ }
1430
+ }
1431
+ function handleEvalTemplateElement(path22, handlerOptions, updater, handler) {
1432
+ const { code } = handler(path22.node.value.raw, handlerOptions);
1433
+ if (!code) {
1434
+ return;
1435
+ }
1436
+ const token = createEvalReplacementToken(path22, code);
1437
+ if (token) {
1438
+ updater.addToken(token);
1439
+ }
1440
+ }
1441
+ function getEvalStringHandlerOptions(options) {
1442
+ if (options.needEscaped === false && options.generateMap === false) {
1443
+ return options;
1444
+ }
1445
+ let cached = evalHandlerOptionsCache.get(options);
1446
+ if (!cached) {
1447
+ cached = {};
1448
+ evalHandlerOptionsCache.set(options, cached);
1449
+ }
1450
+ if (!cached.stringLiteralOptions) {
1451
+ cached.stringLiteralOptions = {
1452
+ ...options,
1453
+ needEscaped: false,
1454
+ generateMap: false
1455
+ };
1456
+ }
1457
+ return cached.stringLiteralOptions;
1458
+ }
1459
+ function getEvalTemplateHandlerOptions(options) {
1460
+ if (options.generateMap === false) {
1461
+ return options;
1462
+ }
1463
+ let cached = evalHandlerOptionsCache.get(options);
1464
+ if (!cached) {
1465
+ cached = {};
1466
+ evalHandlerOptionsCache.set(options, cached);
1467
+ }
1468
+ if (!cached.templateLiteralOptions) {
1469
+ cached.templateLiteralOptions = {
1470
+ ...options,
1471
+ generateMap: false
1472
+ };
1473
+ }
1474
+ return cached.templateLiteralOptions;
1475
+ }
1476
+ function walkEvalExpression(path22, options, updater, handler) {
1477
+ const stringHandlerOptions = getEvalStringHandlerOptions(options);
1478
+ const templateHandlerOptions = getEvalTemplateHandlerOptions(options);
1479
+ const maybeTraverse = path22?.traverse;
1480
+ if (typeof maybeTraverse === "function") {
1481
+ try {
1482
+ return maybeTraverse.call(path22, {
1483
+ StringLiteral(innerPath) {
1484
+ handleEvalStringLiteral(innerPath, stringHandlerOptions, updater, handler);
1485
+ },
1486
+ TemplateElement(innerPath) {
1487
+ handleEvalTemplateElement(innerPath, templateHandlerOptions, updater, handler);
1488
+ }
1489
+ });
1490
+ } catch (error) {
1491
+ const msg = error?.message ?? "";
1492
+ const scopeError = EVAL_SCOPE_ERROR_REGEXP.test(msg);
1493
+ if (!scopeError) {
1494
+ throw error;
1495
+ }
1496
+ }
1497
+ }
1498
+ const getArgs = path22?.get?.("arguments");
1499
+ if (Array.isArray(getArgs)) {
1500
+ for (const arg of getArgs) {
1501
+ if (arg?.isStringLiteral?.()) {
1502
+ handleEvalStringLiteral(arg, stringHandlerOptions, updater, handler);
1503
+ continue;
1504
+ }
1505
+ if (arg?.isTemplateLiteral?.()) {
1506
+ for (const quasi of arg.get("quasis")) {
1507
+ handleEvalTemplateElement(quasi, templateHandlerOptions, updater, handler);
1508
+ }
1509
+ }
1510
+ }
1511
+ return;
1512
+ }
1513
+ const nodeArgs = path22?.node?.arguments;
1514
+ if (Array.isArray(nodeArgs)) {
1515
+ for (const n of nodeArgs) {
1516
+ if (n?.type === "StringLiteral") {
1517
+ const stub = {
1518
+ node: n,
1519
+ isStringLiteral: () => true
1520
+ };
1521
+ handleEvalStringLiteral(stub, stringHandlerOptions, updater, handler);
1522
+ } else if (n?.type === "TemplateLiteral" && Array.isArray(n.quasis)) {
1523
+ for (const q of n.quasis) {
1524
+ const stub = {
1525
+ node: q,
1526
+ isTemplateElement: () => true
1527
+ };
1528
+ handleEvalTemplateElement(stub, templateHandlerOptions, updater, handler);
1529
+ }
1530
+ }
1531
+ }
1532
+ }
1533
+ }
1534
+
1535
+ // src/js/JsTokenUpdater.ts
1536
+ var JsTokenUpdater = class {
1537
+ constructor({ value } = {}) {
1538
+ this.tokens = value ? [...value] : [];
1539
+ }
1540
+ addToken(token) {
1541
+ if (token) {
1542
+ this.tokens.push(token);
1543
+ }
1544
+ }
1545
+ push(...args) {
1546
+ this.tokens.push(...args);
1547
+ return this;
1548
+ }
1549
+ /**
1550
+ * 待写入的 token 数量。
1551
+ */
1552
+ get length() {
1553
+ return this.tokens.length;
1554
+ }
1555
+ map(callbackfn) {
1556
+ this.tokens = this.tokens.map(callbackfn);
1557
+ return this;
1558
+ }
1559
+ filter(callbackfn) {
1560
+ this.tokens = this.tokens.filter(callbackfn);
1561
+ return this;
1562
+ }
1563
+ updateMagicString(ms) {
1564
+ for (const { start, end, value } of this.tokens) {
1565
+ ms.update(start, end, value);
1566
+ }
1567
+ return ms;
1568
+ }
1569
+ };
1570
+
1571
+ // src/js/module-graph/ignored-exports.ts
1572
+ var IgnoredExportsTracker = class {
1573
+ constructor(options) {
1574
+ this.options = options;
1575
+ this.ignoredExportNames = /* @__PURE__ */ new Map();
1576
+ }
1577
+ addIgnoredExport(filename, exportName) {
1578
+ if (!exportName) {
1579
+ return;
1580
+ }
1581
+ let pending = this.ignoredExportNames.get(filename);
1582
+ if (!pending) {
1583
+ pending = /* @__PURE__ */ new Set();
1584
+ this.ignoredExportNames.set(filename, pending);
1585
+ }
1586
+ if (pending.has(exportName)) {
1587
+ return;
1588
+ }
1589
+ pending.add(exportName);
1590
+ const existing = this.options.modules.get(filename);
1591
+ if (existing) {
1592
+ this.applyIgnoredExportsToAnalysis(filename, existing.analysis);
1593
+ }
1594
+ }
1595
+ registerIgnoredExportsFromTokens(resolved, tokens) {
1596
+ for (const token of tokens) {
1597
+ if (token.type === "ImportSpecifier") {
1598
+ this.addIgnoredExport(resolved, token.imported);
1599
+ } else if (token.type === "ImportDefaultSpecifier") {
1600
+ this.addIgnoredExport(resolved, "default");
1601
+ }
1602
+ }
1603
+ }
1604
+ applyIgnoredExportsToAnalysis(filename, analysis) {
1605
+ const pending = this.ignoredExportNames.get(filename);
1606
+ if (!pending || pending.size === 0) {
1607
+ return;
1608
+ }
1609
+ const names = new Set(pending);
1610
+ pending.clear();
1611
+ const propagate = [];
1612
+ for (const exportPath of analysis.exportDeclarations) {
1613
+ if (names.size === 0) {
1614
+ break;
1615
+ }
1616
+ if (exportPath.isExportDefaultDeclaration()) {
1617
+ if (names.has("default")) {
1618
+ analysis.walker.walkExportDefaultDeclaration(exportPath);
1619
+ names.delete("default");
1620
+ }
1621
+ continue;
1622
+ }
1623
+ if (exportPath.isExportNamedDeclaration()) {
1624
+ const source = exportPath.node.source?.value;
1625
+ if (typeof source === "string") {
1626
+ for (const spec of exportPath.get("specifiers")) {
1627
+ if (!spec.isExportSpecifier()) {
1628
+ continue;
1629
+ }
1630
+ const exported = spec.get("exported");
1631
+ let exportedName;
1632
+ if (exported.isIdentifier()) {
1633
+ exportedName = exported.node.name;
1634
+ } else if (exported.isStringLiteral()) {
1635
+ exportedName = exported.node.value;
1636
+ }
1637
+ if (!exportedName || !names.has(exportedName)) {
1638
+ continue;
1639
+ }
1640
+ const local = spec.get("local");
1641
+ if (local.isIdentifier()) {
1642
+ propagate.push({
1643
+ specifier: source,
1644
+ exportName: local.node.name
1645
+ });
1646
+ names.delete(exportedName);
1647
+ } else if (local.isStringLiteral()) {
1648
+ propagate.push({
1649
+ specifier: source,
1650
+ exportName: local.node.value
1651
+ });
1652
+ names.delete(exportedName);
1653
+ }
1654
+ }
1655
+ continue;
1656
+ }
1657
+ const declaration = exportPath.get("declaration");
1658
+ if (declaration.isVariableDeclaration()) {
1659
+ for (const decl of declaration.get("declarations")) {
1660
+ const id = decl.get("id");
1661
+ if (id.isIdentifier()) {
1662
+ const exportName = id.node.name;
1663
+ if (names.has(exportName)) {
1664
+ analysis.walker.walkVariableDeclarator(decl);
1665
+ names.delete(exportName);
1666
+ }
1667
+ }
1668
+ }
1669
+ }
1670
+ for (const spec of exportPath.get("specifiers")) {
1671
+ if (!spec.isExportSpecifier()) {
1672
+ continue;
1673
+ }
1674
+ const exported = spec.get("exported");
1675
+ let exportedName;
1676
+ if (exported.isIdentifier()) {
1677
+ exportedName = exported.node.name;
1678
+ } else if (exported.isStringLiteral()) {
1679
+ exportedName = exported.node.value;
1680
+ }
1681
+ if (!exportedName || !names.has(exportedName)) {
1682
+ continue;
1683
+ }
1684
+ const local = spec.get("local");
1685
+ analysis.walker.walkNode(local);
1686
+ names.delete(exportedName);
1687
+ }
1688
+ continue;
1689
+ }
1690
+ if (exportPath.isExportAllDeclaration()) {
1691
+ const source = exportPath.node.source?.value;
1692
+ if (typeof source === "string") {
1693
+ for (const exportName of names) {
1694
+ propagate.push({
1695
+ specifier: source,
1696
+ exportName
1697
+ });
1698
+ }
1699
+ names.clear();
1700
+ }
1701
+ }
1702
+ }
1703
+ for (const { specifier, exportName } of propagate) {
1704
+ let resolved;
1705
+ try {
1706
+ resolved = this.options.resolve(specifier, filename);
1707
+ } catch {
1708
+ resolved = void 0;
1709
+ }
1710
+ if (!resolved) {
1711
+ pending.add(exportName);
1712
+ continue;
1713
+ }
1714
+ if (this.options.filter && !this.options.filter(resolved, specifier, filename)) {
1715
+ pending.add(exportName);
1716
+ continue;
1717
+ }
1718
+ this.addIgnoredExport(resolved, exportName);
1719
+ }
1720
+ for (const name of names) {
1721
+ pending.add(name);
1722
+ }
1723
+ }
1724
+ };
1725
+
1726
+ // src/js/ModuleGraph.ts
1727
+ var JsModuleGraph = class {
1728
+ constructor(entry, graphOptions) {
1729
+ this.modules = /* @__PURE__ */ new Map();
1730
+ this.queue = [];
1731
+ this.resolve = graphOptions.resolve;
1732
+ this.load = graphOptions.load;
1733
+ this.filter = graphOptions.filter;
1734
+ this.maxDepth = graphOptions.maxDepth ?? Number.POSITIVE_INFINITY;
1735
+ const { moduleGraph: _moduleGraph, filename: _ignoredFilename, ...rest } = entry.handlerOptions;
1736
+ this.baseOptions = {
1737
+ ...rest,
1738
+ filename: entry.filename
1739
+ };
1740
+ this.parserOptions = entry.handlerOptions.babelParserOptions;
1741
+ this.rootFilename = entry.filename;
1742
+ this.ignoredExports = new IgnoredExportsTracker({
1743
+ resolve: this.resolve,
1744
+ filter: this.filter,
1745
+ modules: this.modules
1746
+ });
1747
+ this.modules.set(entry.filename, {
1748
+ filename: entry.filename,
1749
+ source: entry.source,
1750
+ analysis: entry.analysis
1751
+ });
1752
+ this.queue.push({ filename: entry.filename, depth: 0 });
1753
+ }
1754
+ build() {
1755
+ this.collectDependencies();
1756
+ let linked;
1757
+ for (const [filename, state] of this.modules) {
1758
+ if (filename === this.rootFilename) {
1759
+ continue;
1760
+ }
1761
+ const childOptions = {
1762
+ ...this.baseOptions,
1763
+ filename
1764
+ };
1765
+ const ms = processUpdatedSource(state.source, childOptions, state.analysis);
1766
+ const code = ms.toString();
1767
+ if (code !== state.source) {
1768
+ if (!linked) {
1769
+ linked = {};
1770
+ }
1771
+ linked[filename] = { code };
1772
+ }
1773
+ }
1774
+ return linked;
1775
+ }
1776
+ collectDependencies() {
1777
+ while (this.queue.length > 0) {
1778
+ const { filename, depth } = this.queue.shift();
1779
+ if (depth >= this.maxDepth) {
1780
+ continue;
1781
+ }
1782
+ const state = this.modules.get(filename);
1783
+ if (!state) {
1784
+ continue;
1785
+ }
1786
+ const dependencySpecifiers = /* @__PURE__ */ new Map();
1787
+ for (const token of state.analysis.walker.imports) {
1788
+ if (!dependencySpecifiers.has(token.source)) {
1789
+ dependencySpecifiers.set(token.source, []);
1790
+ }
1791
+ dependencySpecifiers.get(token.source).push(token);
1792
+ }
1793
+ for (const exportPath of state.analysis.exportDeclarations) {
1794
+ if (exportPath.isExportAllDeclaration() || exportPath.isExportNamedDeclaration()) {
1795
+ const source = exportPath.node.source?.value;
1796
+ if (typeof source === "string" && !dependencySpecifiers.has(source)) {
1797
+ dependencySpecifiers.set(source, []);
1798
+ }
1799
+ }
1800
+ }
1801
+ for (const [specifier, tokens] of dependencySpecifiers) {
1802
+ let resolved;
1803
+ try {
1804
+ resolved = this.resolve(specifier, filename);
1805
+ } catch {
1806
+ continue;
1807
+ }
1808
+ if (!resolved) {
1809
+ continue;
1810
+ }
1811
+ if (this.filter && !this.filter(resolved, specifier, filename)) {
1812
+ continue;
1813
+ }
1814
+ if (tokens.length > 0) {
1815
+ this.ignoredExports.registerIgnoredExportsFromTokens(resolved, tokens);
1816
+ }
1817
+ if (this.modules.has(resolved)) {
1818
+ continue;
1819
+ }
1820
+ let source;
1821
+ try {
1822
+ source = this.load(resolved);
1823
+ } catch {
1824
+ continue;
1825
+ }
1826
+ if (typeof source !== "string") {
1827
+ continue;
1828
+ }
1829
+ let analysis;
1830
+ try {
1831
+ const ast = babelParse(source, {
1832
+ ...this.parserOptions,
1833
+ sourceFilename: resolved
1834
+ });
1835
+ analysis = analyzeSource(ast, {
1836
+ ...this.baseOptions,
1837
+ filename: resolved
1838
+ });
1839
+ this.ignoredExports.applyIgnoredExportsToAnalysis(resolved, analysis);
1840
+ } catch {
1841
+ continue;
1842
+ }
1843
+ this.modules.set(resolved, {
1844
+ filename: resolved,
1845
+ source,
1846
+ analysis
1847
+ });
1848
+ this.queue.push({ filename: resolved, depth: depth + 1 });
1849
+ }
1850
+ }
1851
+ }
1852
+ };
1853
+
1854
+ // src/js/node-path-walker/export-handlers.ts
1855
+ function walkExportDeclaration(ctx, path22) {
1856
+ if (path22.isExportDeclaration()) {
1857
+ if (path22.isExportNamedDeclaration()) {
1858
+ walkExportNamedDeclaration(ctx, path22);
1859
+ } else if (path22.isExportDefaultDeclaration()) {
1860
+ walkExportDefaultDeclaration(ctx, path22);
1861
+ } else if (path22.isExportAllDeclaration()) {
1862
+ walkExportAllDeclaration(ctx, path22);
1863
+ }
1864
+ }
1865
+ }
1866
+ function walkExportNamedDeclaration(ctx, path22) {
1867
+ const declaration = path22.get("declaration");
1868
+ if (declaration.isVariableDeclaration()) {
1869
+ for (const decl of declaration.get("declarations")) {
1870
+ ctx.walkNode(decl);
1871
+ }
1872
+ }
1873
+ const specifiers = path22.get("specifiers");
1874
+ for (const spec of specifiers) {
1875
+ if (spec.isExportSpecifier()) {
1876
+ const local = spec.get("local");
1877
+ if (local.isIdentifier()) {
1878
+ ctx.walkNode(local);
1879
+ }
1880
+ }
1881
+ }
1882
+ }
1883
+ function walkExportDefaultDeclaration(ctx, path22) {
1884
+ const decl = path22.get("declaration");
1885
+ if (decl.isIdentifier()) {
1886
+ ctx.walkNode(decl);
1887
+ } else {
1888
+ ctx.walkNode(decl);
1889
+ }
1890
+ }
1891
+ function walkExportAllDeclaration(ctx, path22) {
1892
+ const source = path22.get("source");
1893
+ if (source.isStringLiteral()) {
1894
+ ctx.addImportToken(
1895
+ {
1896
+ declaration: path22,
1897
+ source: source.node.value,
1898
+ type: "ExportAllDeclaration"
1899
+ }
1900
+ );
1901
+ }
1902
+ }
1903
+
1904
+ // src/js/node-path-walker/import-tokens.ts
1905
+ function maybeAddImportToken(imports, arg) {
1906
+ if (!(arg.isImportSpecifier() && arg.node.importKind !== "type" || arg.isImportDefaultSpecifier())) {
1907
+ return false;
1908
+ }
1909
+ const importDeclaration = arg.parentPath;
1910
+ if (!importDeclaration.isImportDeclaration() || importDeclaration.node.importKind === "type") {
1911
+ return false;
1912
+ }
1913
+ if (arg.isImportSpecifier()) {
1914
+ const imported = arg.get("imported");
1915
+ if (imported.isIdentifier()) {
1916
+ imports.add(
1917
+ {
1918
+ declaration: importDeclaration,
1919
+ specifier: arg,
1920
+ imported: imported.node.name,
1921
+ local: arg.node.local.name,
1922
+ source: importDeclaration.node.source.value,
1923
+ type: "ImportSpecifier"
1924
+ }
1925
+ );
1926
+ }
1927
+ return true;
1928
+ }
1929
+ imports.add(
1930
+ {
1931
+ declaration: importDeclaration,
1932
+ specifier: arg,
1933
+ local: arg.node.local.name,
1934
+ source: importDeclaration.node.source.value,
1935
+ type: "ImportDefaultSpecifier"
1936
+ }
1937
+ );
1938
+ return true;
1939
+ }
1940
+
1941
+ // src/js/NodePathWalker.ts
1942
+ var EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS = [];
1943
+ var EMPTY_IMPORT_TOKENS = /* @__PURE__ */ new Set();
1944
+ function NOOP_STRING_PATH_CALLBACK() {
1945
+ }
1946
+ var NEVER_MATCH_NAME2 = () => false;
1947
+ var NodePathWalker = class {
1948
+ constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
1949
+ this.hasIgnoredCallIdentifiers = Boolean(ignoreCallExpressionIdentifiers && ignoreCallExpressionIdentifiers.length > 0);
1950
+ this.ignoreCallExpressionIdentifiers = ignoreCallExpressionIdentifiers ?? EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS;
1951
+ this.callback = callback ?? NOOP_STRING_PATH_CALLBACK;
1952
+ this.isIgnoredCallIdentifier = this.hasIgnoredCallIdentifiers ? createNameMatcher(this.ignoreCallExpressionIdentifiers, { exact: true }) : NEVER_MATCH_NAME2;
1953
+ }
1954
+ get imports() {
1955
+ return this.importsStore ?? EMPTY_IMPORT_TOKENS;
1956
+ }
1957
+ getWritableImports() {
1958
+ if (!this.importsStore) {
1959
+ this.importsStore = /* @__PURE__ */ new Set();
1960
+ }
1961
+ return this.importsStore;
1962
+ }
1963
+ addImportToken(token) {
1964
+ this.getWritableImports().add(token);
1965
+ }
1966
+ getVisited() {
1967
+ if (!this.visitedStore) {
1968
+ this.visitedStore = /* @__PURE__ */ new WeakSet();
1969
+ }
1970
+ return this.visitedStore;
1971
+ }
1972
+ walkVariableDeclarator(path22) {
1973
+ const init = path22.get("init");
1974
+ this.walkNode(init);
1975
+ }
1976
+ walkTemplateLiteral(path22) {
1977
+ for (const exp of path22.get("expressions")) {
1978
+ this.walkNode(exp);
1979
+ }
1980
+ for (const quasis of path22.get("quasis")) {
1981
+ this.callback(quasis);
1982
+ }
1983
+ }
1984
+ walkStringLiteral(path22) {
1985
+ this.callback(path22);
1986
+ }
1987
+ walkBinaryExpression(path22) {
1988
+ const left = path22.get("left");
1989
+ this.walkNode(left);
1990
+ const right = path22.get("right");
1991
+ this.walkNode(right);
1992
+ }
1993
+ walkLogicalExpression(path22) {
1994
+ const left = path22.get("left");
1995
+ this.walkNode(left);
1996
+ const right = path22.get("right");
1997
+ this.walkNode(right);
1998
+ }
1999
+ walkObjectExpression(path22) {
2000
+ const props = path22.get("properties");
2001
+ for (const prop of props) {
2002
+ if (prop.isObjectProperty()) {
2003
+ const key = prop.get("key");
2004
+ this.walkNode(key);
2005
+ const value = prop.get("value");
2006
+ this.walkNode(value);
2007
+ }
2008
+ }
2009
+ }
2010
+ walkArrayExpression(path22) {
2011
+ const elements = path22.get("elements");
2012
+ for (const element of elements) {
2013
+ this.walkNode(element);
2014
+ }
2015
+ }
2016
+ walkNode(arg) {
2017
+ const visited = this.getVisited();
2018
+ if (visited.has(arg)) {
2019
+ return;
2020
+ }
2021
+ visited.add(arg);
2022
+ if (arg.isIdentifier()) {
2023
+ const binding = arg?.scope?.getBinding?.(arg.node.name);
2024
+ if (binding) {
2025
+ this.walkNode(binding.path);
2026
+ }
2027
+ } else if (arg.isMemberExpression()) {
2028
+ const objectPath = arg.get("object");
2029
+ if (objectPath.isIdentifier()) {
2030
+ const binding = arg?.scope?.getBinding?.(objectPath.node.name);
2031
+ if (binding) {
2032
+ if (binding.path.isVariableDeclarator()) {
2033
+ this.walkVariableDeclarator(binding.path);
2034
+ }
2035
+ }
2036
+ }
2037
+ } else if (arg.isTemplateLiteral()) {
2038
+ this.walkTemplateLiteral(arg);
2039
+ } else if (arg.isStringLiteral()) {
2040
+ this.walkStringLiteral(arg);
2041
+ } else if (arg.isBinaryExpression()) {
2042
+ this.walkBinaryExpression(arg);
2043
+ } else if (arg.isLogicalExpression()) {
2044
+ this.walkLogicalExpression(arg);
2045
+ } else if (arg.isObjectExpression()) {
2046
+ this.walkObjectExpression(arg);
2047
+ } else if (arg.isArrayExpression()) {
2048
+ this.walkArrayExpression(arg);
2049
+ } else if (arg.isVariableDeclarator()) {
2050
+ this.walkVariableDeclarator(arg);
2051
+ } else if (maybeAddImportToken(this.getWritableImports(), arg)) {
2052
+ }
2053
+ }
2054
+ /**
2055
+ * Walk the arguments of a desired call expression so their bindings can be analysed.
2056
+ */
2057
+ walkCallExpression(path22) {
2058
+ if (!this.hasIgnoredCallIdentifiers) {
2059
+ return;
2060
+ }
2061
+ const calleePath = path22.get("callee");
2062
+ if (calleePath.isIdentifier() && this.isIgnoredCallIdentifier(calleePath.node.name)) {
2063
+ for (const arg of path22.get("arguments")) {
2064
+ this.walkNode(arg);
2065
+ }
2066
+ }
2067
+ }
2068
+ walkExportDeclaration(path22) {
2069
+ walkExportDeclaration(this, path22);
2070
+ }
2071
+ walkExportNamedDeclaration(path22) {
2072
+ walkExportNamedDeclaration(this, path22);
2073
+ }
2074
+ walkExportDefaultDeclaration(path22) {
2075
+ walkExportDefaultDeclaration(this, path22);
2076
+ }
2077
+ walkExportAllDeclaration(path22) {
2078
+ walkExportAllDeclaration(this, path22);
2079
+ }
2080
+ };
2081
+
2082
+ // src/js/taggedTemplateIgnore.ts
2083
+ function createTaggedTemplateIgnore({ matcher, names }) {
2084
+ const bindingIgnoreCache = /* @__PURE__ */ new Map();
2085
+ const taggedTemplateIgnoreCache = /* @__PURE__ */ new WeakMap();
2086
+ const seenBindings = /* @__PURE__ */ new Set();
2087
+ let singleCanonicalIgnoreName;
2088
+ let canonicalIgnoreNames;
2089
+ for (const item of names ?? []) {
2090
+ if (typeof item !== "string") {
2091
+ continue;
2092
+ }
2093
+ if (singleCanonicalIgnoreName === void 0) {
2094
+ singleCanonicalIgnoreName = item;
2095
+ continue;
2096
+ }
2097
+ if (item === singleCanonicalIgnoreName) {
2098
+ continue;
2099
+ }
2100
+ if (!canonicalIgnoreNames) {
2101
+ canonicalIgnoreNames = /* @__PURE__ */ new Set([singleCanonicalIgnoreName, item]);
2102
+ continue;
2103
+ }
2104
+ canonicalIgnoreNames.add(item);
2105
+ }
2106
+ const hasCanonicalIgnoreNames = singleCanonicalIgnoreName !== void 0;
2107
+ const matchesIgnoreName = (value) => {
2108
+ if (hasCanonicalIgnoreNames) {
2109
+ if (canonicalIgnoreNames) {
2110
+ if (canonicalIgnoreNames.has(value)) {
2111
+ return true;
2112
+ }
2113
+ } else if (value === singleCanonicalIgnoreName) {
2114
+ return true;
2115
+ }
2116
+ }
2117
+ return matcher(value);
2118
+ };
2119
+ const propertyMatches = (propertyPath) => {
2120
+ if (!propertyPath) {
2121
+ return false;
2122
+ }
2123
+ if (propertyPath.isIdentifier()) {
2124
+ return matchesIgnoreName(propertyPath.node.name);
2125
+ }
2126
+ if (propertyPath.isStringLiteral()) {
2127
+ return matchesIgnoreName(propertyPath.node.value);
2128
+ }
2129
+ return false;
2130
+ };
2131
+ const resolvesMemberExpressionToIgnore = (path22, seen) => {
2132
+ const propertyPath = path22.get("property");
2133
+ if (propertyMatches(propertyPath)) {
2134
+ return true;
2135
+ }
2136
+ const objectPath = path22.get("object");
2137
+ if (objectPath.isIdentifier()) {
2138
+ const scope = objectPath?.scope;
2139
+ const binding = scope?.getBinding?.(objectPath.node.name);
2140
+ if (binding) {
2141
+ return resolvesToWeappTwIgnore(binding, seen);
2142
+ }
2143
+ }
2144
+ return false;
2145
+ };
2146
+ const resolvesToWeappTwIgnore = (binding, seen) => {
2147
+ const cached = bindingIgnoreCache.get(binding);
2148
+ if (cached !== void 0) {
2149
+ return cached;
2150
+ }
2151
+ if (seen.has(binding)) {
2152
+ return false;
2153
+ }
2154
+ seen.add(binding);
2155
+ let result = false;
2156
+ const bindingPath = binding.path;
2157
+ if (bindingPath.isImportSpecifier()) {
2158
+ const imported = bindingPath.node.imported;
2159
+ if (imported.type === "Identifier" && matchesIgnoreName(imported.name)) {
2160
+ result = true;
2161
+ } else if (imported.type === "StringLiteral" && matchesIgnoreName(imported.value)) {
2162
+ result = true;
2163
+ }
2164
+ } else if (bindingPath.isVariableDeclarator()) {
2165
+ const init = bindingPath.get("init");
2166
+ if (init && init.node) {
2167
+ if (init.isIdentifier()) {
2168
+ const target = binding?.scope?.getBinding?.(init.node.name);
2169
+ if (target) {
2170
+ result = resolvesToWeappTwIgnore(target, seen);
2171
+ }
2172
+ } else if (init.isMemberExpression()) {
2173
+ result = resolvesMemberExpressionToIgnore(init, seen);
2174
+ }
2175
+ }
2176
+ }
2177
+ bindingIgnoreCache.set(binding, result);
2178
+ seen.delete(binding);
2179
+ return result;
2180
+ };
2181
+ const getEffectiveTagPath = (tagPath) => {
2182
+ let current = tagPath;
2183
+ while (true) {
2184
+ if (current.isParenthesizedExpression?.() || current.node.type === "ParenthesizedExpression") {
2185
+ current = current.get("expression");
2186
+ continue;
2187
+ }
2188
+ if (current.isTSAsExpression() || current.isTSTypeAssertion()) {
2189
+ current = current.get("expression");
2190
+ continue;
2191
+ }
2192
+ if (current.isTSNonNullExpression()) {
2193
+ current = current.get("expression");
2194
+ continue;
2195
+ }
2196
+ if (current.isTypeCastExpression?.()) {
2197
+ current = current.get("expression");
2198
+ continue;
2199
+ }
2200
+ if (current.isSequenceExpression()) {
2201
+ const expressions = current.get("expressions");
2202
+ const last = expressions.at(-1);
2203
+ if (last) {
2204
+ current = last;
2205
+ continue;
2206
+ }
2207
+ }
2208
+ if (current.isCallExpression?.() || current.node.type === "CallExpression") {
2209
+ const callee = current.get("callee");
2210
+ current = callee;
2211
+ continue;
2212
+ }
2213
+ break;
2214
+ }
2215
+ return current;
2216
+ };
2217
+ const evaluateTagPath = (tagPath, seen) => {
2218
+ if (tagPath.isCallExpression?.() || tagPath.node.type === "CallExpression") {
2219
+ const calleePath = tagPath.get("callee");
2220
+ return evaluateTagPath(calleePath, seen);
2221
+ }
2222
+ if (tagPath.isIdentifier()) {
2223
+ if (matchesIgnoreName(tagPath.node.name)) {
2224
+ return true;
2225
+ }
2226
+ const binding = tagPath?.scope?.getBinding?.(tagPath.node.name);
2227
+ if (binding) {
2228
+ return resolvesToWeappTwIgnore(binding, seen);
2229
+ }
2230
+ return false;
2231
+ }
2232
+ if (tagPath.isMemberExpression()) {
2233
+ return resolvesMemberExpressionToIgnore(tagPath, seen);
2234
+ }
2235
+ return false;
2236
+ };
2237
+ const computeIgnore = (tagPath) => {
2238
+ const cached = taggedTemplateIgnoreCache.get(tagPath.node);
2239
+ if (cached !== void 0) {
2240
+ return cached;
2241
+ }
2242
+ const effectiveTagPath = getEffectiveTagPath(tagPath);
2243
+ const effectiveCached = taggedTemplateIgnoreCache.get(effectiveTagPath.node);
2244
+ if (effectiveCached !== void 0) {
2245
+ taggedTemplateIgnoreCache.set(tagPath.node, effectiveCached);
2246
+ return effectiveCached;
2247
+ }
2248
+ seenBindings.clear();
2249
+ const result = evaluateTagPath(effectiveTagPath, seenBindings);
2250
+ taggedTemplateIgnoreCache.set(effectiveTagPath.node, result);
2251
+ taggedTemplateIgnoreCache.set(tagPath.node, result);
2252
+ return result;
2253
+ };
561
2254
  return {
562
- recordPath: location.recordPath,
563
- message,
564
- reason,
565
- onPatched
2255
+ shouldIgnore(tagPath) {
2256
+ return computeIgnore(tagPath);
2257
+ },
2258
+ getEffectiveTagPath
566
2259
  };
567
2260
  }
568
2261
 
569
- // src/tailwindcss/targets.ts
570
- function logTailwindcssTarget(kind, patcher, baseDir) {
571
- const packageInfo = patcher?.packageInfo;
572
- const label = kind === "cli" ? "weapp-tw patch" : "Weapp-tailwindcss";
573
- if (!packageInfo?.rootPath) {
574
- logger3.warn(
575
- "%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
576
- label,
577
- baseDir ?? process6.cwd()
578
- );
579
- return;
580
- }
581
- const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
582
- const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
583
- if (kind === "runtime") {
584
- logRuntimeTailwindcssTarget(baseDir, packageInfo.rootPath, packageInfo.version);
585
- return;
2262
+ // src/js/babel.ts
2263
+ var EXPRESSION_WRAPPER_PREFIX = "(\n";
2264
+ var EXPRESSION_WRAPPER_SUFFIX = "\n)";
2265
+ var EMPTY_IGNORED_PATHS = /* @__PURE__ */ new WeakSet();
2266
+ var EMPTY_IMPORT_DECLARATIONS = /* @__PURE__ */ new Set();
2267
+ var EMPTY_EXPORT_DECLARATIONS = /* @__PURE__ */ new Set();
2268
+ var EMPTY_REQUIRE_CALL_PATHS = [];
2269
+ var ignoredTaggedTemplateMatcherCache = /* @__PURE__ */ new WeakMap();
2270
+ var defaultEvalHandler;
2271
+ function getIgnoredTaggedTemplateMatcher(options) {
2272
+ const cached = ignoredTaggedTemplateMatcherCache.get(options);
2273
+ if (cached) {
2274
+ return cached;
2275
+ }
2276
+ const created = createNameMatcher(options.ignoreTaggedTemplateExpressionIdentifiers, { exact: true });
2277
+ ignoredTaggedTemplateMatcherCache.set(options, created);
2278
+ return created;
2279
+ }
2280
+ function getDefaultEvalHandler() {
2281
+ if (!defaultEvalHandler) {
2282
+ throw new Error("Default JS eval handler is not initialized.");
586
2283
  }
587
- logger3.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
2284
+ return defaultEvalHandler;
588
2285
  }
589
-
590
- // src/tailwindcss/v4/config.ts
591
- import { logger as logger4 } from "@weapp-tailwindcss/logger";
592
-
593
- // src/tailwindcss/v4/patcher.ts
594
- import { logger as logger6 } from "@weapp-tailwindcss/logger";
595
-
596
- // src/tailwindcss/patcher.ts
597
- import path7 from "path";
598
- import process8 from "process";
599
- import { logger as logger5 } from "@weapp-tailwindcss/logger";
600
- import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
601
- import { TailwindcssPatcher } from "tailwindcss-patch";
602
-
603
- // src/tailwindcss/patcher-resolve.ts
604
- import { existsSync as existsSync4 } from "fs";
605
- import { createRequire } from "module";
606
- import path6 from "path";
607
- import process7 from "process";
608
- import { fileURLToPath } from "url";
609
-
610
- // src/tailwindcss/v4/css-entries.ts
611
- import path8 from "path";
612
-
613
- // src/context/compiler-context-cache.ts
614
- import { Buffer } from "buffer";
615
- import path9 from "path";
616
- import process9 from "process";
617
- import { logger as logger7 } from "@weapp-tailwindcss/logger";
618
- var globalCacheHolder = globalThis;
619
- var compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
620
-
621
- // src/context/handlers.ts
622
- import { createStyleHandler } from "@weapp-tailwindcss/postcss";
623
-
624
- // src/babel/index.ts
625
- import _babelTraverse from "@babel/traverse";
626
- import { parse, parseExpression } from "@babel/parser";
627
- function _interopDefaultCompat(e) {
628
- return e && typeof e === "object" && "default" in e ? e.default : e;
2286
+ function analyzeSource(ast, options, handler, collectModuleMetadata = true) {
2287
+ const jsTokenUpdater = new JsTokenUpdater();
2288
+ const needScope = Boolean(options.ignoreCallExpressionIdentifiers && options.ignoreCallExpressionIdentifiers.length > 0);
2289
+ const ignoredPaths = needScope ? /* @__PURE__ */ new WeakSet() : EMPTY_IGNORED_PATHS;
2290
+ const walker = needScope ? new NodePathWalker({
2291
+ ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
2292
+ callback(path22) {
2293
+ ignoredPaths.add(path22);
2294
+ }
2295
+ }) : new NodePathWalker();
2296
+ let taggedTemplateIgnore;
2297
+ const hasTaggedTemplateIgnoreIdentifiers = Boolean(
2298
+ options.ignoreTaggedTemplateExpressionIdentifiers && options.ignoreTaggedTemplateExpressionIdentifiers.length > 0
2299
+ );
2300
+ function getTaggedTemplateIgnore() {
2301
+ if (!taggedTemplateIgnore) {
2302
+ taggedTemplateIgnore = createTaggedTemplateIgnore({
2303
+ matcher: getIgnoredTaggedTemplateMatcher(options),
2304
+ names: options.ignoreTaggedTemplateExpressionIdentifiers
2305
+ });
2306
+ }
2307
+ return taggedTemplateIgnore;
2308
+ }
2309
+ const targetPaths = [];
2310
+ const importDeclarations = collectModuleMetadata ? /* @__PURE__ */ new Set() : EMPTY_IMPORT_DECLARATIONS;
2311
+ const exportDeclarations = collectModuleMetadata ? /* @__PURE__ */ new Set() : EMPTY_EXPORT_DECLARATIONS;
2312
+ const requireCallPaths = collectModuleMetadata ? [] : EMPTY_REQUIRE_CALL_PATHS;
2313
+ const evalHandler = handler ?? getDefaultEvalHandler();
2314
+ const templateElementEnter = hasTaggedTemplateIgnoreIdentifiers ? (p) => {
2315
+ const pp = p.parentPath;
2316
+ if (pp.isTemplateLiteral()) {
2317
+ const ppp = pp.parentPath;
2318
+ if (isEvalPath(ppp)) {
2319
+ return;
2320
+ }
2321
+ if (ppp.isTaggedTemplateExpression()) {
2322
+ const tagPath = ppp.get("tag");
2323
+ if (getTaggedTemplateIgnore().shouldIgnore(tagPath)) {
2324
+ return;
2325
+ }
2326
+ }
2327
+ }
2328
+ targetPaths.push(p);
2329
+ } : (p) => {
2330
+ const pp = p.parentPath;
2331
+ if (pp.isTemplateLiteral()) {
2332
+ const ppp = pp.parentPath;
2333
+ if (isEvalPath(ppp)) {
2334
+ return;
2335
+ }
2336
+ }
2337
+ targetPaths.push(p);
2338
+ };
2339
+ const callExpressionEnter = !collectModuleMetadata && !needScope ? (p) => {
2340
+ if (isEvalPath(p)) {
2341
+ walkEvalExpression(p, options, jsTokenUpdater, evalHandler);
2342
+ }
2343
+ } : (p) => {
2344
+ if (isEvalPath(p)) {
2345
+ walkEvalExpression(p, options, jsTokenUpdater, evalHandler);
2346
+ return;
2347
+ }
2348
+ const calleePath = p.get("callee");
2349
+ if (collectModuleMetadata && calleePath.isIdentifier({ name: "require" }) && !p?.scope?.hasBinding?.("require")) {
2350
+ const args = p.get("arguments");
2351
+ if (Array.isArray(args) && args.length > 0) {
2352
+ const first = args[0];
2353
+ if (first?.isStringLiteral()) {
2354
+ requireCallPaths.push(first);
2355
+ }
2356
+ }
2357
+ }
2358
+ if (needScope) {
2359
+ walker.walkCallExpression(p);
2360
+ }
2361
+ };
2362
+ const traverseOptions = {
2363
+ StringLiteral: {
2364
+ enter(p) {
2365
+ if (isEvalPath(p.parentPath)) {
2366
+ return;
2367
+ }
2368
+ targetPaths.push(p);
2369
+ }
2370
+ },
2371
+ TemplateElement: {
2372
+ enter: templateElementEnter
2373
+ },
2374
+ CallExpression: {
2375
+ enter: callExpressionEnter
2376
+ },
2377
+ ...collectModuleMetadata ? {
2378
+ ImportDeclaration: {
2379
+ enter(p) {
2380
+ importDeclarations.add(p);
2381
+ }
2382
+ },
2383
+ ExportDeclaration: {
2384
+ enter(p) {
2385
+ exportDeclarations.add(p);
2386
+ }
2387
+ }
2388
+ } : {}
2389
+ };
2390
+ traverse(ast, { ...traverseOptions, noScope: !needScope });
2391
+ return {
2392
+ walker,
2393
+ jsTokenUpdater,
2394
+ ast,
2395
+ targetPaths,
2396
+ importDeclarations,
2397
+ exportDeclarations,
2398
+ requireCallPaths,
2399
+ ignoredPaths
2400
+ };
629
2401
  }
630
- var traverse = _interopDefaultCompat(_babelTraverse);
631
-
632
- // src/utils/nameMatcher.ts
633
- import { escapeStringRegexp } from "@weapp-core/regex";
634
-
635
- // src/js/babel/parse.ts
636
- import { LRUCache as LRUCache2 } from "lru-cache";
637
- var parseCache = new LRUCache2(
638
- {
639
- max: 1024
2402
+ function jsHandler(rawSource, options) {
2403
+ const shouldWrapExpression = Boolean(options.wrapExpression);
2404
+ const source = shouldWrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
2405
+ let ast;
2406
+ try {
2407
+ ast = babelParse(source, options.babelParserOptions);
2408
+ } catch (error) {
2409
+ return {
2410
+ code: rawSource,
2411
+ error
2412
+ };
640
2413
  }
641
- );
642
-
643
- // src/js/babel/process.ts
644
- import MagicString from "magic-string";
645
-
646
- // src/js/handlers.ts
647
- import { jsStringEscape } from "@ast-core/escape";
648
- import { splitCode } from "@weapp-tailwindcss/shared/extractors";
649
-
650
- // src/wxml/shared.ts
651
- import { escape, MappingChars2String as MappingChars2String2 } from "@weapp-core/escape";
652
-
653
- // src/js/handlers.ts
654
- var debug2 = createDebug("[js:handlers] ");
655
-
656
- // src/js/evalTransforms.ts
657
- import { jsStringEscape as jsStringEscape2 } from "@ast-core/escape";
2414
+ const needsModuleMetadata = Boolean(options.moduleSpecifierReplacements || options.moduleGraph && options.filename);
2415
+ const analysis = analyzeSource(ast, options, jsHandler, needsModuleMetadata);
2416
+ const ms = processUpdatedSource(source, options, analysis);
2417
+ if (shouldWrapExpression) {
2418
+ const start = 0;
2419
+ const end = source.length;
2420
+ const prefixLength = EXPRESSION_WRAPPER_PREFIX.length;
2421
+ const suffixLength = EXPRESSION_WRAPPER_SUFFIX.length;
2422
+ ms.remove(start, start + prefixLength);
2423
+ ms.remove(end - suffixLength, end);
2424
+ }
2425
+ const result = {
2426
+ code: ms.toString()
2427
+ };
2428
+ if (options.generateMap) {
2429
+ Object.defineProperty(result, "map", {
2430
+ configurable: true,
2431
+ enumerable: true,
2432
+ get() {
2433
+ return ms.generateMap();
2434
+ }
2435
+ });
2436
+ }
2437
+ if (options.moduleGraph && options.filename) {
2438
+ const graph = new JsModuleGraph(
2439
+ {
2440
+ filename: options.filename,
2441
+ source: rawSource,
2442
+ analysis,
2443
+ handlerOptions: options
2444
+ },
2445
+ options.moduleGraph
2446
+ );
2447
+ const linked = graph.build();
2448
+ if (linked) {
2449
+ result.linked = linked;
2450
+ }
2451
+ }
2452
+ return result;
2453
+ }
2454
+ defaultEvalHandler = jsHandler;
658
2455
 
659
2456
  // src/wxml/utils/codegen/legacy-rewriter.ts
660
2457
  import MagicString2 from "magic-string";
@@ -898,9 +2695,273 @@ function formatOutputPath(target, baseDir) {
898
2695
  return relative.startsWith(".") ? relative : `.${path12.sep}${relative}`;
899
2696
  }
900
2697
 
2698
+ // src/cli/doctor.ts
2699
+ import { existsSync as existsSync6, readFileSync as readFileSync4 } from "fs";
2700
+ import { createRequire as createRequire3 } from "module";
2701
+ import path13 from "path";
2702
+ import process13 from "process";
2703
+ import semver from "semver";
2704
+
2705
+ // src/cli/doctor/constants.ts
2706
+ var CONFIG_FILES = {
2707
+ tailwind: [
2708
+ "tailwind.config.js",
2709
+ "tailwind.config.cjs",
2710
+ "tailwind.config.mjs",
2711
+ "tailwind.config.ts"
2712
+ ],
2713
+ postcss: [
2714
+ "postcss.config.js",
2715
+ "postcss.config.cjs",
2716
+ "postcss.config.mjs",
2717
+ "postcss.config.ts"
2718
+ ],
2719
+ vite: ["vite.config.js", "vite.config.mjs", "vite.config.ts"],
2720
+ webpack: ["webpack.config.js", "webpack.config.cjs", "webpack.config.ts"]
2721
+ };
2722
+ var FRAMEWORK_DEPS = [
2723
+ ["@tarojs/taro", "Taro"],
2724
+ ["@dcloudio/uni-app", "uni-app"],
2725
+ ["@mpxjs/core", "MPX"],
2726
+ ["remax", "Remax"],
2727
+ ["rax", "Rax"]
2728
+ ];
2729
+
2730
+ // src/cli/doctor.ts
2731
+ function tryReadJson(file) {
2732
+ try {
2733
+ return JSON.parse(readFileSync4(file, "utf8"));
2734
+ } catch {
2735
+ return void 0;
2736
+ }
2737
+ }
2738
+ function findFirstExisting(cwd, files) {
2739
+ return files.find((file) => existsSync6(path13.join(cwd, file)));
2740
+ }
2741
+ function readProjectPackageJson(cwd) {
2742
+ return tryReadJson(path13.join(cwd, "package.json"));
2743
+ }
2744
+ function readDependencyVersion(cwd, packageName) {
2745
+ try {
2746
+ const requireFromCwd = createRequire3(path13.join(cwd, "package.json"));
2747
+ const packageJsonPath = requireFromCwd.resolve(`${packageName}/package.json`);
2748
+ return tryReadJson(packageJsonPath)?.version;
2749
+ } catch {
2750
+ return void 0;
2751
+ }
2752
+ }
2753
+ function collectDependencySpecs(pkg) {
2754
+ return {
2755
+ ...pkg?.dependencies ?? {},
2756
+ ...pkg?.devDependencies ?? {},
2757
+ ...pkg?.optionalDependencies ?? {},
2758
+ ...pkg?.peerDependencies ?? {}
2759
+ };
2760
+ }
2761
+ function detectPackageManager(cwd, pkg) {
2762
+ if (pkg?.packageManager) {
2763
+ return pkg.packageManager;
2764
+ }
2765
+ if (existsSync6(path13.join(cwd, "pnpm-lock.yaml"))) {
2766
+ return "pnpm";
2767
+ }
2768
+ if (existsSync6(path13.join(cwd, "package-lock.json"))) {
2769
+ return "npm";
2770
+ }
2771
+ if (existsSync6(path13.join(cwd, "yarn.lock"))) {
2772
+ return "yarn";
2773
+ }
2774
+ return void 0;
2775
+ }
2776
+ function detectFrameworks(deps) {
2777
+ return FRAMEWORK_DEPS.filter(([dependency]) => dependency in deps).map(([, label]) => label);
2778
+ }
2779
+ function addCheck(checks, check) {
2780
+ checks.push(check);
2781
+ }
2782
+ function summarizeChecks(checks) {
2783
+ return checks.reduce((summary, check) => {
2784
+ summary[check.status] += 1;
2785
+ return summary;
2786
+ }, { ok: 0, warn: 0, error: 0, info: 0 });
2787
+ }
2788
+ function hasDependency(deps, packageName) {
2789
+ return packageName in deps;
2790
+ }
2791
+ function getMajorVersion(version) {
2792
+ if (!version) {
2793
+ return void 0;
2794
+ }
2795
+ return semver.parse(version)?.major;
2796
+ }
2797
+ function getDependencyMajor(deps, packageName) {
2798
+ const spec = deps[packageName];
2799
+ return spec ? semver.minVersion(spec)?.major : void 0;
2800
+ }
2801
+ function createDoctorReport(options = {}) {
2802
+ const cwd = path13.resolve(options.cwd ?? process13.cwd());
2803
+ const nodeVersion = options.nodeVersion ?? process13.versions.node;
2804
+ const pkg = readProjectPackageJson(cwd);
2805
+ const deps = collectDependencySpecs(pkg);
2806
+ const checks = [];
2807
+ const packageManager = detectPackageManager(cwd, pkg);
2808
+ const frameworks = detectFrameworks(deps);
2809
+ const tailwindcssVersion = readDependencyVersion(cwd, "tailwindcss");
2810
+ const weappTailwindcssVersion = readDependencyVersion(cwd, "weapp-tailwindcss");
2811
+ const tailwindMajor = getMajorVersion(tailwindcssVersion) ?? getDependencyMajor(deps, "tailwindcss");
2812
+ const tailwindConfig = findFirstExisting(cwd, CONFIG_FILES.tailwind);
2813
+ const postcssConfig = findFirstExisting(cwd, CONFIG_FILES.postcss);
2814
+ const viteConfig = findFirstExisting(cwd, CONFIG_FILES.vite);
2815
+ const webpackConfig = findFirstExisting(cwd, CONFIG_FILES.webpack);
2816
+ addCheck(checks, pkg ? {
2817
+ id: "package-json",
2818
+ title: "package.json",
2819
+ status: "ok",
2820
+ message: "\u5DF2\u627E\u5230\u9879\u76EE package.json\u3002"
2821
+ } : {
2822
+ id: "package-json",
2823
+ title: "package.json",
2824
+ status: "error",
2825
+ message: "\u5F53\u524D\u76EE\u5F55\u6CA1\u6709 package.json\u3002",
2826
+ suggestion: "\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u8FD0\u884C doctor\uFF0C\u6216\u901A\u8FC7 --cwd \u6307\u5411\u9879\u76EE\u6839\u76EE\u5F55\u3002"
2827
+ });
2828
+ addCheck(checks, semver.satisfies(nodeVersion, WEAPP_TW_REQUIRED_NODE_VERSION_RANGE) ? {
2829
+ id: "node-version",
2830
+ title: "Node.js",
2831
+ status: "ok",
2832
+ message: `\u5F53\u524D Node.js ${nodeVersion} \u6EE1\u8DB3\u7248\u672C\u8981\u6C42 ${WEAPP_TW_REQUIRED_NODE_VERSION_RANGE}\u3002`
2833
+ } : {
2834
+ id: "node-version",
2835
+ title: "Node.js",
2836
+ status: "error",
2837
+ message: `\u5F53\u524D Node.js ${nodeVersion} \u4E0D\u6EE1\u8DB3\u7248\u672C\u8981\u6C42 ${WEAPP_TW_REQUIRED_NODE_VERSION_RANGE}\u3002`,
2838
+ suggestion: "\u8BF7\u5347\u7EA7 Node.js \u540E\u518D\u5B89\u88C5\u6216\u6784\u5EFA weapp-tailwindcss \u9879\u76EE\u3002"
2839
+ });
2840
+ addCheck(checks, packageManager ? {
2841
+ id: "package-manager",
2842
+ title: "\u5305\u7BA1\u7406\u5668",
2843
+ status: packageManager.startsWith("pnpm") ? "ok" : "info",
2844
+ message: `\u68C0\u6D4B\u5230 ${packageManager}\u3002`
2845
+ } : {
2846
+ id: "package-manager",
2847
+ title: "\u5305\u7BA1\u7406\u5668",
2848
+ status: "info",
2849
+ message: "\u672A\u68C0\u6D4B\u5230 lockfile \u6216 packageManager \u5B57\u6BB5\u3002"
2850
+ });
2851
+ addCheck(checks, hasDependency(deps, "weapp-tailwindcss") || Boolean(weappTailwindcssVersion) ? {
2852
+ id: "weapp-tailwindcss",
2853
+ title: "weapp-tailwindcss",
2854
+ status: "ok",
2855
+ message: `\u68C0\u6D4B\u5230 weapp-tailwindcss${weappTailwindcssVersion ? `@${weappTailwindcssVersion}` : ""}\u3002`
2856
+ } : {
2857
+ id: "weapp-tailwindcss",
2858
+ title: "weapp-tailwindcss",
2859
+ status: "warn",
2860
+ message: "\u672A\u5728\u5F53\u524D\u9879\u76EE\u4F9D\u8D56\u4E2D\u68C0\u6D4B\u5230 weapp-tailwindcss\u3002",
2861
+ suggestion: "\u5982\u679C\u8FD9\u662F\u4E1A\u52A1\u9879\u76EE\uFF0C\u8BF7\u5B89\u88C5 weapp-tailwindcss \u5E76\u786E\u8BA4\u547D\u4EE4\u8FD0\u884C\u5728\u9879\u76EE\u6839\u76EE\u5F55\u3002"
2862
+ });
2863
+ addCheck(checks, hasDependency(deps, "tailwindcss") || Boolean(tailwindcssVersion) ? {
2864
+ id: "tailwindcss",
2865
+ title: "Tailwind CSS",
2866
+ status: "ok",
2867
+ message: `\u68C0\u6D4B\u5230 tailwindcss${tailwindcssVersion ? `@${tailwindcssVersion}` : ""}\u3002`
2868
+ } : {
2869
+ id: "tailwindcss",
2870
+ title: "Tailwind CSS",
2871
+ status: "error",
2872
+ message: "\u672A\u68C0\u6D4B\u5230 tailwindcss\u3002",
2873
+ suggestion: "\u8BF7\u5B89\u88C5 tailwindcss\uFF0C\u5E76\u786E\u8BA4\u4F9D\u8D56\u53EF\u4EE5\u4ECE\u5F53\u524D\u9879\u76EE\u89E3\u6790\u3002"
2874
+ });
2875
+ addCheck(checks, tailwindConfig ? {
2876
+ id: "tailwind-config",
2877
+ title: "Tailwind \u914D\u7F6E",
2878
+ status: "ok",
2879
+ message: `\u68C0\u6D4B\u5230 ${tailwindConfig}\u3002`
2880
+ } : {
2881
+ id: "tailwind-config",
2882
+ title: "Tailwind \u914D\u7F6E",
2883
+ status: tailwindMajor === 4 ? "info" : "warn",
2884
+ message: "\u672A\u68C0\u6D4B\u5230 tailwind.config.*\u3002",
2885
+ suggestion: tailwindMajor === 4 ? "Tailwind CSS v4 \u53EF\u4EE5\u91C7\u7528 CSS-first \u914D\u7F6E\uFF1B\u5982\u679C\u4F7F\u7528 v3 \u6216\u590D\u6742 content/source\uFF0C\u8BF7\u8865\u5145\u914D\u7F6E\u6587\u4EF6\u3002" : "\u8BF7\u786E\u8BA4 Tailwind content/source \u914D\u7F6E\u80FD\u591F\u8986\u76D6\u5C0F\u7A0B\u5E8F\u9875\u9762\u3001\u7EC4\u4EF6\u548C\u811A\u672C\u6587\u4EF6\u3002"
2886
+ });
2887
+ addCheck(checks, postcssConfig ? {
2888
+ id: "postcss-config",
2889
+ title: "PostCSS \u914D\u7F6E",
2890
+ status: "ok",
2891
+ message: `\u68C0\u6D4B\u5230 ${postcssConfig}\u3002`
2892
+ } : {
2893
+ id: "postcss-config",
2894
+ title: "PostCSS \u914D\u7F6E",
2895
+ status: viteConfig ? "info" : "warn",
2896
+ message: "\u672A\u68C0\u6D4B\u5230 postcss.config.*\u3002",
2897
+ suggestion: "\u5982\u679C\u901A\u8FC7 PostCSS \u63A5\u5165\uFF0C\u8BF7\u8865\u5145 postcss.config.*\uFF1B\u5982\u679C\u901A\u8FC7 Vite/Taro \u63D2\u4EF6\u63A5\u5165\uFF0C\u53EF\u5FFD\u7565\u6B64\u9879\u3002"
2898
+ });
2899
+ if (tailwindMajor === 4 && postcssConfig && !hasDependency(deps, "@tailwindcss/postcss")) {
2900
+ addCheck(checks, {
2901
+ id: "tailwindcss-v4-postcss",
2902
+ title: "Tailwind v4 PostCSS",
2903
+ status: "warn",
2904
+ message: "Tailwind CSS v4 \u9879\u76EE\u5B58\u5728 PostCSS \u914D\u7F6E\uFF0C\u4F46\u672A\u68C0\u6D4B\u5230 @tailwindcss/postcss\u3002",
2905
+ suggestion: "\u5982\u679C PostCSS \u914D\u7F6E\u4E2D\u4ECD\u76F4\u63A5\u4F7F\u7528 tailwindcss\uFF0C\u8BF7\u8FC1\u79FB\u5230 @tailwindcss/postcss\u3002"
2906
+ });
2907
+ }
2908
+ addCheck(checks, frameworks.length > 0 ? {
2909
+ id: "framework",
2910
+ title: "\u6846\u67B6\u8BC6\u522B",
2911
+ status: "ok",
2912
+ message: `\u68C0\u6D4B\u5230 ${frameworks.join(", ")}\u3002`
2913
+ } : {
2914
+ id: "framework",
2915
+ title: "\u6846\u67B6\u8BC6\u522B",
2916
+ status: "info",
2917
+ message: "\u672A\u4ECE\u4F9D\u8D56\u4E2D\u8BC6\u522B\u51FA Taro\u3001uni-app\u3001MPX\u3001Remax \u6216 Rax\u3002"
2918
+ });
2919
+ addCheck(checks, viteConfig || webpackConfig ? {
2920
+ id: "bundler-config",
2921
+ title: "\u6784\u5EFA\u5668\u914D\u7F6E",
2922
+ status: "ok",
2923
+ message: `\u68C0\u6D4B\u5230 ${[viteConfig, webpackConfig].filter(Boolean).join(", ")}\u3002`
2924
+ } : {
2925
+ id: "bundler-config",
2926
+ title: "\u6784\u5EFA\u5668\u914D\u7F6E",
2927
+ status: "info",
2928
+ message: "\u672A\u68C0\u6D4B\u5230 vite.config.* \u6216 webpack.config.*\u3002"
2929
+ });
2930
+ return {
2931
+ cwd,
2932
+ nodeVersion,
2933
+ detected: {
2934
+ packageManager,
2935
+ frameworks,
2936
+ tailwindcssVersion,
2937
+ weappTailwindcssVersion
2938
+ },
2939
+ summary: summarizeChecks(checks),
2940
+ checks
2941
+ };
2942
+ }
2943
+ function hasDoctorFailure(report, strict = false) {
2944
+ return report.summary.error > 0 || strict && report.summary.warn > 0;
2945
+ }
2946
+ function formatDoctorReport(report) {
2947
+ const lines = [
2948
+ `weapp-tailwindcss doctor`,
2949
+ `cwd: ${report.cwd}`,
2950
+ `summary: ${report.summary.error} error, ${report.summary.warn} warn, ${report.summary.ok} ok, ${report.summary.info} info`,
2951
+ ""
2952
+ ];
2953
+ for (const check of report.checks) {
2954
+ lines.push(`[${check.status}] ${check.title}: ${check.message}`);
2955
+ if (check.suggestion) {
2956
+ lines.push(` -> ${check.suggestion}`);
2957
+ }
2958
+ }
2959
+ return lines.join("\n");
2960
+ }
2961
+
901
2962
  // src/cli/helpers.ts
902
2963
  import { mkdir as mkdir2 } from "fs/promises";
903
- import process15 from "process";
2964
+ import process16 from "process";
904
2965
 
905
2966
  // src/logger/index.ts
906
2967
  import { logger as logger12 } from "@weapp-tailwindcss/logger";
@@ -958,19 +3019,19 @@ function toBoolean(value, fallback) {
958
3019
  }
959
3020
 
960
3021
  // src/cli/helpers/options/resolve.ts
961
- import path13 from "path";
962
- import process13 from "process";
3022
+ import path14 from "path";
3023
+ import process14 from "process";
963
3024
  function resolveCliCwd(value) {
964
3025
  const raw = readStringOption("cwd", value);
965
3026
  if (!raw) {
966
3027
  return void 0;
967
3028
  }
968
- return path13.isAbsolute(raw) ? path13.normalize(raw) : path13.resolve(process13.cwd(), raw);
3029
+ return path14.isAbsolute(raw) ? path14.normalize(raw) : path14.resolve(process14.cwd(), raw);
969
3030
  }
970
3031
 
971
3032
  // src/cli/helpers/patch-cwd.ts
972
- import path14 from "path";
973
- import process14 from "process";
3033
+ import path15 from "path";
3034
+ import process15 from "process";
974
3035
 
975
3036
  // src/tailwindcss/index.ts
976
3037
  import { getPackageInfoSync } from "local-pkg";
@@ -983,7 +3044,7 @@ function normalizeCandidatePath(baseDir, candidate) {
983
3044
  if (!candidate) {
984
3045
  return void 0;
985
3046
  }
986
- return path14.isAbsolute(candidate) ? path14.normalize(candidate) : path14.resolve(baseDir, candidate);
3047
+ return path15.isAbsolute(candidate) ? path15.normalize(candidate) : path15.resolve(baseDir, candidate);
987
3048
  }
988
3049
  function detectTailwindWorkspace(paths) {
989
3050
  for (const candidate of paths) {
@@ -997,15 +3058,15 @@ function detectTailwindWorkspace(paths) {
997
3058
  }
998
3059
  return void 0;
999
3060
  }
1000
- function resolvePatchDefaultCwd(currentCwd = process14.cwd()) {
1001
- const baseDir = path14.normalize(currentCwd);
1002
- const explicitCwd = normalizeCandidatePath(baseDir, process14.env.WEAPP_TW_PATCH_CWD);
3061
+ function resolvePatchDefaultCwd(currentCwd = process15.cwd()) {
3062
+ const baseDir = path15.normalize(currentCwd);
3063
+ const explicitCwd = normalizeCandidatePath(baseDir, process15.env.WEAPP_TW_PATCH_CWD);
1003
3064
  if (explicitCwd) {
1004
3065
  return explicitCwd;
1005
3066
  }
1006
3067
  const workspaceRoot = findWorkspaceRoot(baseDir);
1007
- const initCwd = normalizeCandidatePath(baseDir, process14.env.INIT_CWD);
1008
- const localPrefix = normalizeCandidatePath(baseDir, process14.env.npm_config_local_prefix);
3068
+ const initCwd = normalizeCandidatePath(baseDir, process15.env.INIT_CWD);
3069
+ const localPrefix = normalizeCandidatePath(baseDir, process15.env.npm_config_local_prefix);
1009
3070
  const candidates = [
1010
3071
  baseDir,
1011
3072
  workspaceRoot,
@@ -1026,7 +3087,7 @@ async function ensureDir(dir) {
1026
3087
  function handleCliError(error) {
1027
3088
  if (error instanceof Error) {
1028
3089
  logger12.error(error.message);
1029
- if (error.stack && process15.env.WEAPP_TW_DEBUG === "1") {
3090
+ if (error.stack && process16.env.WEAPP_TW_DEBUG === "1") {
1030
3091
  logger12.error(error.stack);
1031
3092
  }
1032
3093
  } else {
@@ -1039,13 +3100,13 @@ function commandAction(handler) {
1039
3100
  await handler(...args);
1040
3101
  } catch (error) {
1041
3102
  handleCliError(error);
1042
- process15.exitCode = 1;
3103
+ process16.exitCode = 1;
1043
3104
  }
1044
3105
  };
1045
3106
  }
1046
3107
 
1047
3108
  // src/cli/mount-options.ts
1048
- import process17 from "process";
3109
+ import process18 from "process";
1049
3110
 
1050
3111
  // src/cli/mount-options/patch-status.ts
1051
3112
  function formatStatusFilesHint(files) {
@@ -1120,24 +3181,24 @@ function buildExtendLengthUnitsOverride(options) {
1120
3181
  }
1121
3182
 
1122
3183
  // src/cli/workspace.ts
1123
- import path19 from "path";
1124
- import process16 from "process";
3184
+ import path20 from "path";
3185
+ import process17 from "process";
1125
3186
 
1126
3187
  // src/cli/workspace/package-dirs.ts
1127
- import { existsSync as existsSync8 } from "fs";
1128
- import path17 from "path";
3188
+ import { existsSync as existsSync9 } from "fs";
3189
+ import path18 from "path";
1129
3190
  import fg from "fast-glob";
1130
3191
 
1131
3192
  // src/cli/workspace/workspace-globs.ts
1132
- import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
1133
- import path15 from "path";
3193
+ import { existsSync as existsSync7, readFileSync as readFileSync6 } from "fs";
3194
+ import path16 from "path";
1134
3195
  import { parse as parseYaml } from "yaml";
1135
3196
 
1136
3197
  // src/cli/workspace/workspace-io.ts
1137
- import { readFileSync as readFileSync4 } from "fs";
1138
- function tryReadJson(file) {
3198
+ import { readFileSync as readFileSync5 } from "fs";
3199
+ function tryReadJson2(file) {
1139
3200
  try {
1140
- const content = readFileSync4(file, "utf8");
3201
+ const content = readFileSync5(file, "utf8");
1141
3202
  return JSON.parse(content);
1142
3203
  } catch {
1143
3204
  return void 0;
@@ -1146,8 +3207,8 @@ function tryReadJson(file) {
1146
3207
 
1147
3208
  // src/cli/workspace/workspace-globs.ts
1148
3209
  function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
1149
- const pkgJsonPath = path15.join(workspaceRoot, "package.json");
1150
- const pkg = tryReadJson(pkgJsonPath);
3210
+ const pkgJsonPath = path16.join(workspaceRoot, "package.json");
3211
+ const pkg = tryReadJson2(pkgJsonPath);
1151
3212
  if (!pkg?.workspaces) {
1152
3213
  return [];
1153
3214
  }
@@ -1160,12 +3221,12 @@ function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
1160
3221
  return [];
1161
3222
  }
1162
3223
  function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
1163
- const workspaceFile = path15.join(workspaceRoot, "pnpm-workspace.yaml");
1164
- if (!existsSync6(workspaceFile)) {
3224
+ const workspaceFile = path16.join(workspaceRoot, "pnpm-workspace.yaml");
3225
+ if (!existsSync7(workspaceFile)) {
1165
3226
  return [];
1166
3227
  }
1167
3228
  try {
1168
- const parsed = parseYaml(readFileSync5(workspaceFile, "utf8"));
3229
+ const parsed = parseYaml(readFileSync6(workspaceFile, "utf8"));
1169
3230
  return Array.isArray(parsed?.packages) ? parsed.packages.filter(Boolean) : [];
1170
3231
  } catch {
1171
3232
  return [];
@@ -1173,16 +3234,16 @@ function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
1173
3234
  }
1174
3235
 
1175
3236
  // src/cli/workspace/workspace-lock.ts
1176
- import { existsSync as existsSync7, readFileSync as readFileSync6 } from "fs";
1177
- import path16 from "path";
3237
+ import { existsSync as existsSync8, readFileSync as readFileSync7 } from "fs";
3238
+ import path17 from "path";
1178
3239
  import { parse as parseYaml2 } from "yaml";
1179
3240
  function parseImportersFromLock(workspaceRoot) {
1180
- const lockPath = path16.join(workspaceRoot, "pnpm-lock.yaml");
1181
- if (!existsSync7(lockPath)) {
3241
+ const lockPath = path17.join(workspaceRoot, "pnpm-lock.yaml");
3242
+ if (!existsSync8(lockPath)) {
1182
3243
  return [];
1183
3244
  }
1184
3245
  try {
1185
- const parsed = parseYaml2(readFileSync6(lockPath, "utf8"));
3246
+ const parsed = parseYaml2(readFileSync7(lockPath, "utf8"));
1186
3247
  const importers = parsed?.importers;
1187
3248
  if (!importers) {
1188
3249
  return [];
@@ -1191,7 +3252,7 @@ function parseImportersFromLock(workspaceRoot) {
1191
3252
  if (!key || key === ".") {
1192
3253
  return workspaceRoot;
1193
3254
  }
1194
- return path16.join(workspaceRoot, key);
3255
+ return path17.join(workspaceRoot, key);
1195
3256
  });
1196
3257
  } catch {
1197
3258
  return [];
@@ -1204,7 +3265,7 @@ var TRAILING_SLASH_RE = /\/+$/;
1204
3265
  async function resolveWorkspacePackageDirs(workspaceRoot) {
1205
3266
  const dirs = /* @__PURE__ */ new Set();
1206
3267
  for (const importerDir of parseImportersFromLock(workspaceRoot)) {
1207
- dirs.add(path17.normalize(importerDir));
3268
+ dirs.add(path18.normalize(importerDir));
1208
3269
  }
1209
3270
  if (!dirs.size) {
1210
3271
  let globs = parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot);
@@ -1224,13 +3285,13 @@ async function resolveWorkspacePackageDirs(workspaceRoot) {
1224
3285
  ignore: ["**/node_modules/**", "**/.git/**"]
1225
3286
  });
1226
3287
  for (const file of packageJsonFiles) {
1227
- dirs.add(path17.normalize(path17.dirname(file)));
3288
+ dirs.add(path18.normalize(path18.dirname(file)));
1228
3289
  }
1229
3290
  }
1230
3291
  }
1231
- const rootPkg = path17.join(workspaceRoot, "package.json");
1232
- if (existsSync8(rootPkg)) {
1233
- dirs.add(path17.normalize(workspaceRoot));
3292
+ const rootPkg = path18.join(workspaceRoot, "package.json");
3293
+ if (existsSync9(rootPkg)) {
3294
+ dirs.add(path18.normalize(workspaceRoot));
1234
3295
  }
1235
3296
  return [...dirs];
1236
3297
  }
@@ -1239,9 +3300,9 @@ async function resolveWorkspacePackageDirs(workspaceRoot) {
1239
3300
  import { normalizeOptions, TailwindcssPatcher as TailwindcssPatcher2 } from "tailwindcss-patch";
1240
3301
 
1241
3302
  // src/cli/workspace/patch-utils.ts
1242
- import path18 from "path";
3303
+ import path19 from "path";
1243
3304
  function formatDisplayName(workspaceRoot, dir, name) {
1244
- const relative = path18.relative(workspaceRoot, dir) || ".";
3305
+ const relative = path19.relative(workspaceRoot, dir) || ".";
1245
3306
  return name ? `${name} (${relative})` : relative;
1246
3307
  }
1247
3308
  function summarizeWorkspaceResults(results) {
@@ -1314,7 +3375,7 @@ async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
1314
3375
 
1315
3376
  // src/cli/workspace.ts
1316
3377
  async function patchWorkspace(options) {
1317
- const cwd = options.cwd ?? process16.cwd();
3378
+ const cwd = options.cwd ?? process17.cwd();
1318
3379
  const workspaceRoot = findWorkspaceRoot(cwd) ?? cwd;
1319
3380
  const packageDirs = await resolveWorkspacePackageDirs(workspaceRoot);
1320
3381
  if (packageDirs.length === 0) {
@@ -1323,8 +3384,8 @@ async function patchWorkspace(options) {
1323
3384
  }
1324
3385
  const results = [];
1325
3386
  for (const dir of packageDirs) {
1326
- const pkgJsonPath = path19.join(dir, "package.json");
1327
- const pkgJson = tryReadJson(pkgJsonPath);
3387
+ const pkgJsonPath = path20.join(dir, "package.json");
3388
+ const pkgJson = tryReadJson2(pkgJsonPath);
1328
3389
  results.push(await patchWorkspacePackage(workspaceRoot, dir, pkgJson?.name, options));
1329
3390
  }
1330
3391
  summarizeWorkspaceResults(results);
@@ -1334,7 +3395,7 @@ async function patchWorkspace(options) {
1334
3395
  function handleCliError2(error) {
1335
3396
  if (error instanceof Error) {
1336
3397
  logger12.error(error.message);
1337
- if (error.stack && process17.env.WEAPP_TW_DEBUG === "1") {
3398
+ if (error.stack && process18.env.WEAPP_TW_DEBUG === "1") {
1338
3399
  logger12.error(error.stack);
1339
3400
  }
1340
3401
  } else {
@@ -1347,7 +3408,7 @@ function withCommandErrorHandling(handler) {
1347
3408
  return await handler(ctx, next);
1348
3409
  } catch (error) {
1349
3410
  handleCliError2(error);
1350
- process17.exitCode = 1;
3411
+ process18.exitCode = 1;
1351
3412
  return void 0;
1352
3413
  }
1353
3414
  });
@@ -1457,7 +3518,7 @@ var mountOptions = {
1457
3518
  // src/cli/vscode-entry.ts
1458
3519
  import { constants } from "fs";
1459
3520
  import { access, writeFile as writeFile2 } from "fs/promises";
1460
- import path20 from "path";
3521
+ import path21 from "path";
1461
3522
  var DEFAULT_VSCODE_ENTRY_OUTPUT = ".vscode/weapp-tailwindcss.intellisense.css";
1462
3523
  var DEFAULT_VSCODE_SOURCES = [
1463
3524
  'not "./dist"',
@@ -1530,16 +3591,16 @@ function formatSource(pattern) {
1530
3591
  }
1531
3592
  function resolveOutputPath(baseDir, output) {
1532
3593
  const target = output ?? DEFAULT_VSCODE_ENTRY_OUTPUT;
1533
- return path20.isAbsolute(target) ? path20.normalize(target) : path20.resolve(baseDir, target);
3594
+ return path21.isAbsolute(target) ? path21.normalize(target) : path21.resolve(baseDir, target);
1534
3595
  }
1535
3596
  function resolveCssEntry(baseDir, entry) {
1536
- return path20.isAbsolute(entry) ? path20.normalize(entry) : path20.resolve(baseDir, entry);
3597
+ return path21.isAbsolute(entry) ? path21.normalize(entry) : path21.resolve(baseDir, entry);
1537
3598
  }
1538
3599
  function toRelativeImport(fromFile, targetFile) {
1539
- const fromDir = path20.dirname(fromFile);
1540
- let relative = path20.relative(fromDir, targetFile);
3600
+ const fromDir = path21.dirname(fromFile);
3601
+ let relative = path21.relative(fromDir, targetFile);
1541
3602
  if (!relative) {
1542
- relative = path20.basename(targetFile);
3603
+ relative = path21.basename(targetFile);
1543
3604
  }
1544
3605
  if (!relative.startsWith(".")) {
1545
3606
  relative = `./${relative}`;
@@ -1551,7 +3612,7 @@ async function generateVscodeIntellisenseEntry(options) {
1551
3612
  const cssEntryPath = resolveCssEntry(baseDir, options.cssEntry);
1552
3613
  await assertFileExists(cssEntryPath);
1553
3614
  const outputPath = resolveOutputPath(baseDir, options.output);
1554
- await ensureDir(path20.dirname(outputPath));
3615
+ await ensureDir(path21.dirname(outputPath));
1555
3616
  await assertCanWrite(outputPath, options.force);
1556
3617
  const sources = options.sources && options.sources.length > 0 ? options.sources : DEFAULT_VSCODE_SOURCES;
1557
3618
  const formattedSources = sources.map(formatSource).filter((statement) => Boolean(statement));
@@ -1576,10 +3637,10 @@ async function generateVscodeIntellisenseEntry(options) {
1576
3637
  }
1577
3638
 
1578
3639
  // src/cli.ts
1579
- process18.title = "node (weapp-tailwindcss)";
1580
- if (semver.lt(process18.versions.node, WEAPP_TW_REQUIRED_NODE_VERSION)) {
3640
+ process19.title = "node (weapp-tailwindcss)";
3641
+ if (!semver2.satisfies(process19.versions.node, WEAPP_TW_REQUIRED_NODE_VERSION_RANGE)) {
1581
3642
  logger12.warn(
1582
- `You are using Node.js ${process18.versions.node}. For weapp-tailwindcss, Node.js version >= v${WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
3643
+ `You are using Node.js ${process19.versions.node}. For weapp-tailwindcss, Node.js version ${WEAPP_TW_REQUIRED_NODE_VERSION_RANGE} is required.`
1583
3644
  );
1584
3645
  }
1585
3646
  var cli = createTailwindcssPatchCli({
@@ -1589,7 +3650,7 @@ var cli = createTailwindcssPatchCli({
1589
3650
  cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliSense").option("--cwd <dir>", "Working directory").option("--css <file>", "Path to the CSS file that imports weapp-tailwindcss (required)").option("--output <file>", `Helper output path. Defaults to ${DEFAULT_VSCODE_ENTRY_OUTPUT}`).option("--source <pattern>", "Additional @source glob (can be repeated)").option("--force", "Overwrite the helper file when it already exists").action(
1590
3651
  commandAction(async (options) => {
1591
3652
  const resolvedCwd = resolveCliCwd(options.cwd);
1592
- const baseDir = resolvedCwd ?? process18.cwd();
3653
+ const baseDir = resolvedCwd ?? process19.cwd();
1593
3654
  const cssEntry = readStringOption("css", options.css);
1594
3655
  if (!cssEntry) {
1595
3656
  throw new Error('Option "--css" is required.');
@@ -1609,6 +3670,20 @@ cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliS
1609
3670
  );
1610
3671
  })
1611
3672
  );
3673
+ cli.command("doctor", "Check project setup for weapp-tailwindcss").option("--cwd <dir>", "Working directory").option("--json", "Print a JSON report").option("--strict", "Exit with code 1 when warnings are found").action(
3674
+ commandAction(async (options) => {
3675
+ const resolvedCwd = resolveCliCwd(options.cwd);
3676
+ const report = createDoctorReport({ cwd: resolvedCwd });
3677
+ if (toBoolean(options.json, false)) {
3678
+ logger12.log(JSON.stringify(report, null, 2));
3679
+ } else {
3680
+ logger12.log(formatDoctorReport(report));
3681
+ }
3682
+ if (hasDoctorFailure(report, toBoolean(options.strict, false))) {
3683
+ process19.exitCode = 1;
3684
+ }
3685
+ })
3686
+ );
1612
3687
  cli.help();
1613
- cli.version(process18.env.npm_package_version ?? "0.0.0");
3688
+ cli.version(process19.env.npm_package_version ?? "0.0.0");
1614
3689
  cli.parse();