weapp-tailwindcss 5.0.0-next.2 → 5.0.0-next.20

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 (220) hide show
  1. package/README.md +6 -7
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/bundle-state-BlXvU4jl.js +530 -0
  4. package/dist/bundle-state-PO6MysTJ.mjs +414 -0
  5. package/dist/bundlers/shared/cache.d.ts +6 -6
  6. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
  7. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
  8. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +5 -0
  9. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
  10. package/dist/bundlers/shared/css-cleanup.d.ts +7 -3
  11. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  12. package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
  13. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  14. package/dist/bundlers/shared/generator-css/directives.d.ts +20 -0
  15. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  16. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  17. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  18. package/dist/bundlers/shared/generator-css/markers.d.ts +28 -0
  19. package/dist/bundlers/shared/generator-css/source-files.d.ts +14 -0
  20. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +24 -0
  21. package/dist/bundlers/shared/generator-css.d.ts +16 -22
  22. package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
  23. package/dist/bundlers/shared/style-requests.d.ts +2 -0
  24. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  25. package/dist/bundlers/vite/css-finalizer.d.ts +7 -1
  26. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  27. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +24 -0
  28. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +4 -0
  29. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  30. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  31. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  32. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  33. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  34. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  35. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  36. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  37. package/dist/bundlers/vite/generate-bundle.d.ts +14 -2
  38. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +5 -1
  39. package/dist/bundlers/vite/index.d.ts +1 -1
  40. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  41. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  42. package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
  43. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -3
  44. package/dist/bundlers/vite/runtime-class-set.d.ts +25 -0
  45. package/dist/bundlers/vite/source-candidates.d.ts +16 -1
  46. package/dist/bundlers/vite/source-scan.d.ts +26 -0
  47. package/dist/bundlers/vite/static-config-content.d.ts +5 -0
  48. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  49. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
  50. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +6 -2
  51. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +9 -3
  52. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
  53. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
  54. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -6
  55. package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
  56. package/dist/cache/index.d.ts +6 -6
  57. package/dist/cli/context.d.ts +1 -14
  58. package/dist/cli/doctor/types.d.ts +11 -11
  59. package/dist/cli/helpers.d.ts +1 -2
  60. package/dist/cli/mount-options.d.ts +2 -0
  61. package/dist/cli/types.d.ts +0 -2
  62. package/dist/cli/vscode-entry.d.ts +3 -3
  63. package/dist/cli.js +605 -611
  64. package/dist/cli.mjs +614 -620
  65. package/dist/constants.d.ts +1 -2
  66. package/dist/core.js +13 -20
  67. package/dist/core.mjs +8 -14
  68. package/dist/css-macro/postcss.js +3 -2
  69. package/dist/css-macro/postcss.mjs +3 -2
  70. package/dist/css-macro.d.ts +1 -0
  71. package/dist/css-macro.js +2 -2
  72. package/dist/css-macro.mjs +2 -2
  73. package/dist/defaults-B1igPF_e.mjs +150 -0
  74. package/dist/defaults-IHhYxNeU.js +193 -0
  75. package/dist/defaults.d.ts +15 -1
  76. package/dist/defaults.js +6 -131
  77. package/dist/defaults.mjs +2 -129
  78. package/dist/escape.js +10 -2
  79. package/dist/escape.mjs +10 -2
  80. package/dist/generator/index.d.ts +1 -1
  81. package/dist/generator/options.d.ts +9 -8
  82. package/dist/generator/types.d.ts +3 -3
  83. package/dist/generator-DIuglJub.mjs +32 -0
  84. package/dist/generator-N4jy1HCk.js +55 -0
  85. package/dist/generator.js +12 -11
  86. package/dist/generator.mjs +2 -1
  87. package/dist/gulp.js +185 -47
  88. package/dist/gulp.mjs +179 -41
  89. package/dist/incremental-runtime-class-set-CJ0Pnsw2.js +2348 -0
  90. package/dist/incremental-runtime-class-set-hF-uiw6W.mjs +2285 -0
  91. package/dist/index.d.ts +1 -1
  92. package/dist/index.js +6 -6
  93. package/dist/index.mjs +5 -5
  94. package/dist/js/babel/cache-options.d.ts +3 -0
  95. package/dist/js/babel/parse.d.ts +7 -4
  96. package/dist/js/index.d.ts +1 -0
  97. package/dist/js/literal-transform.d.ts +2 -0
  98. package/dist/js/precheck.d.ts +2 -2
  99. package/dist/lightningcss/style-handler/selector-transform.d.ts +1 -1
  100. package/dist/lightningcss/style-handler.d.ts +3 -3
  101. package/dist/logger-CZUxvJJD.mjs +2 -0
  102. package/dist/logger-EVNB9z7i.js +1 -0
  103. package/dist/postcss/config-directive.d.ts +1 -0
  104. package/dist/postcss/context.d.ts +9 -0
  105. package/dist/postcss/source-files.d.ts +8 -0
  106. package/dist/postcss/tailwind-version.d.ts +3 -0
  107. package/dist/postcss-D4UdbBQ6.mjs +228 -0
  108. package/dist/postcss-DlY-YRvA.js +237 -0
  109. package/dist/postcss.d.ts +2 -2
  110. package/dist/postcss.js +3 -276
  111. package/dist/postcss.mjs +1 -269
  112. package/dist/{recorder-gYSNLfOP.js → precheck-BjEbVEpX.js} +218 -314
  113. package/dist/{recorder-zsgatmkB.mjs → precheck-tbk626YL.mjs} +186 -281
  114. package/dist/presets.js +13 -11
  115. package/dist/presets.mjs +11 -9
  116. package/dist/reset.d.ts +1 -0
  117. package/dist/runtime-registry-D5qnaSpo.js +5516 -0
  118. package/dist/shared/mpx.d.ts +1 -0
  119. package/dist/source-candidates-BrvneDDd.mjs +209 -0
  120. package/dist/source-candidates-gxijpPI3.js +222 -0
  121. package/dist/tailwindcss/miniprogram.d.ts +5 -1
  122. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  123. package/dist/tailwindcss/patcher.d.ts +1 -2
  124. package/dist/tailwindcss/runtime/cache.d.ts +4 -3
  125. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  126. package/dist/tailwindcss/runtime.d.ts +11 -12
  127. package/dist/tailwindcss/source-scan.d.ts +35 -0
  128. package/dist/tailwindcss/targets.d.ts +1 -5
  129. package/dist/tailwindcss/v3-engine/types.d.ts +17 -14
  130. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  131. package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
  132. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  133. package/dist/tailwindcss/v4/patcher.d.ts +1 -0
  134. package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
  135. package/dist/tailwindcss/v4-engine/types.d.ts +17 -5
  136. package/dist/tailwindcss/version.d.ts +4 -0
  137. package/dist/tailwindcss-BhG7BtB-.js +651 -0
  138. package/dist/tailwindcss-c6ROlNNW.mjs +600 -0
  139. package/dist/typedoc.export.d.ts +0 -2
  140. package/dist/types/index.d.ts +51 -48
  141. package/dist/types/shared.d.ts +3 -0
  142. package/dist/types/user-defined-options/general.d.ts +23 -23
  143. package/dist/types/user-defined-options/important.d.ts +31 -28
  144. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  145. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  146. package/dist/uni-app-x/vite.d.ts +1 -1
  147. package/dist/utils/disabled.d.ts +2 -3
  148. package/dist/utils/object.d.ts +9 -0
  149. package/dist/{utils-DmC9_In3.js → utils-4ODFyoqD.js} +1 -1
  150. package/dist/{utils-7DUGTFED.mjs → utils-CGBVVNm6.mjs} +1 -1
  151. package/dist/v3-engine-5LoZUH-4.js +3695 -0
  152. package/dist/v3-engine-DIXDEDmL.mjs +3406 -0
  153. package/dist/{vite-CrlzCNqz.mjs → vite-B5faZcbE.mjs} +1256 -1088
  154. package/dist/vite-MyXBNux0.js +2368 -0
  155. package/dist/vite.d.ts +1 -2
  156. package/dist/vite.js +3 -4
  157. package/dist/vite.mjs +2 -2
  158. package/dist/weapp-tw-css-import-rewrite-loader.js +5157 -16
  159. package/dist/weapp-tw-runtime-classset-loader.js +32 -7
  160. package/dist/webpack-BnVyDmsD.mjs +836 -0
  161. package/dist/webpack-Mz1V0A9p.js +846 -0
  162. package/dist/webpack.js +1 -1
  163. package/dist/webpack.mjs +1 -1
  164. package/package.json +27 -37
  165. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  166. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  167. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  168. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  169. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  170. package/dist/cli/config.d.ts +0 -5
  171. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  172. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  173. package/dist/cli/patch-options.d.ts +0 -6
  174. package/dist/cli/tokens.d.ts +0 -4
  175. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  176. package/dist/cli/workspace/patch-package.d.ts +0 -3
  177. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  178. package/dist/cli/workspace/types.d.ts +0 -11
  179. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  180. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  181. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  182. package/dist/cli/workspace.d.ts +0 -2
  183. package/dist/css-imports-BbrbluP9.js +0 -177
  184. package/dist/css-imports-CSdPq_Sc.mjs +0 -128
  185. package/dist/experimental/index.d.ts +0 -2
  186. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  187. package/dist/experimental/oxc/index.d.ts +0 -2
  188. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  189. package/dist/experimental/shared/cache.d.ts +0 -3
  190. package/dist/experimental/shared/transform.d.ts +0 -3
  191. package/dist/experimental/shared.d.ts +0 -8
  192. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  193. package/dist/experimental/swc/index.d.ts +0 -2
  194. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  195. package/dist/generator-Y-Ikv4Fu.mjs +0 -1177
  196. package/dist/generator-css-B5ejWUMv.mjs +0 -1098
  197. package/dist/generator-css-D3OdPRiS.js +0 -1125
  198. package/dist/generator-mmhXzZnv.js +0 -1276
  199. package/dist/js/syntax.d.ts +0 -10
  200. package/dist/loader-anchors-CNkWT8hx.js +0 -273
  201. package/dist/loader-anchors-TrU7EUr7.mjs +0 -205
  202. package/dist/logger-BZ45DZJT.js +0 -1003
  203. package/dist/logger-BoVx1Dbt.mjs +0 -935
  204. package/dist/patcher-options-6gJN2EXy.js +0 -115
  205. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  206. package/dist/tailwindcss/recorder.d.ts +0 -13
  207. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  208. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  209. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  210. package/dist/tailwindcss/targets/types.d.ts +0 -35
  211. package/dist/types/disabled-options.d.ts +0 -4
  212. package/dist/vite-BC9U7ahn.js +0 -2199
  213. package/dist/webpack-Bu6M-Hbw.mjs +0 -441
  214. package/dist/webpack-DD7A6V0u.js +0 -456
  215. package/dist/webpack4.d.ts +0 -4
  216. package/dist/webpack4.js +0 -387
  217. package/dist/webpack4.mjs +0 -379
  218. package/scripts/postinstall.mjs +0 -59
  219. /package/dist/{constants-B-_T5UnW.mjs → constants-BG12WAKw.mjs} +0 -0
  220. /package/dist/{constants-p1dyh1x1.js → constants-BeeyfJ9k.js} +0 -0
package/dist/cli.mjs CHANGED
@@ -1,28 +1,33 @@
1
1
  import { createRequire } from "node:module";
2
2
  import process from "node:process";
3
3
  import semver from "semver";
4
- import { TailwindcssPatcher, createTailwindcssPatchCli, normalizeOptions } from "tailwindcss-patch";
4
+ import { createTailwindcssPatchCli } from "tailwindcss-patch";
5
5
  import path from "node:path";
6
- import { access, mkdir, rm, writeFile } from "node:fs/promises";
7
- import { logger, logger as logger$1 } from "@weapp-tailwindcss/logger";
6
+ import { access, mkdir, writeFile } from "node:fs/promises";
7
+ import { logger } from "@weapp-tailwindcss/logger";
8
8
  import { LRUCache } from "lru-cache";
9
9
  import { md5 as md5Hash } from "@weapp-tailwindcss/shared/node";
10
10
  import { MappingChars2String, escape } from "@weapp-core/escape";
11
11
  import "@weapp-tailwindcss/shared";
12
12
  import _createDebug from "debug";
13
13
  import { constants, existsSync, readFileSync } from "node:fs";
14
- import "@weapp-tailwindcss/postcss";
14
+ import "postcss";
15
+ import "micromatch";
16
+ import { createStyleHandler } from "@weapp-tailwindcss/postcss";
17
+ import "fast-glob";
18
+ import "tailwindcss-config";
15
19
  import _babelTraverse from "@babel/traverse";
16
- import { parse as parse$1 } from "@babel/parser";
20
+ import { parse } from "@babel/parser";
17
21
  import { escapeStringRegexp } from "@weapp-core/regex";
18
22
  import MagicString from "magic-string";
19
23
  import { jsStringEscape } from "@ast-core/escape";
20
24
  import { splitCode } from "@weapp-tailwindcss/shared/extractors";
21
25
  import "@babel/types";
22
26
  import "htmlparser2";
23
- import { getPackageInfoSync } from "local-pkg";
24
- import fg from "fast-glob";
25
- import { parse } from "yaml";
27
+ //#region src/js/babel/cache-options.ts
28
+ const DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH = 5e4;
29
+ const HARD_PARSE_CACHE_MAX_ENTRIES = 1024;
30
+ //#endregion
26
31
  //#region src/debug/index.ts
27
32
  const _debug = _createDebug("weapp-tw");
28
33
  function createDebug(prefix) {
@@ -38,241 +43,470 @@ function createDebug(prefix) {
38
43
  });
39
44
  return debug;
40
45
  }
41
- createDebug("[tailwindcss:runtime] ");
42
- //#endregion
43
- //#region src/tailwindcss/runtime-logs.ts
44
- const runtimeLogDedupeHolder = globalThis;
45
- const runtimeLogDedupe = runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ = /* @__PURE__ */ new Set());
46
- function createRuntimeLogKey(category, baseDir, rootPath, version) {
47
- return JSON.stringify([
48
- category,
49
- baseDir ?? process.cwd(),
50
- rootPath ?? "",
51
- version ?? ""
52
- ]);
53
- }
54
- function markRuntimeLog(category, baseDir, rootPath, version) {
55
- const key = createRuntimeLogKey(category, baseDir, rootPath, version);
56
- if (runtimeLogDedupe.has(key)) return false;
57
- runtimeLogDedupe.add(key);
58
- return true;
59
- }
60
- function logRuntimeTailwindcssTarget(baseDir, rootPath, version) {
61
- if (!markRuntimeLog("target", baseDir, rootPath, version)) return;
62
- const versionText = version ? ` (v${version})` : "";
63
- logger.info("%s 使用 Tailwind CSS%s", "Weapp-tailwindcss", versionText);
64
- }
65
- //#endregion
66
- //#region src/context/workspace.ts
67
- function findWorkspaceRoot(startDir) {
68
- if (!startDir) return;
69
- let current = path.resolve(startDir);
70
- while (true) {
71
- if (existsSync(path.join(current, "pnpm-workspace.yaml"))) return current;
72
- const parent = path.dirname(current);
73
- if (parent === current) return;
74
- current = parent;
75
- }
76
- }
77
- function findNearestPackageRoot(startDir) {
78
- if (!startDir) return;
79
- let current = path.resolve(startDir);
80
- while (true) {
81
- if (existsSync(path.join(current, "package.json"))) return current;
82
- const parent = path.dirname(current);
83
- if (parent === current) return;
84
- current = parent;
85
- }
86
- }
87
46
  //#endregion
88
- //#region src/tailwindcss/targets/paths.ts
89
- const PATCH_INFO_FILENAME = "tailwindcss-target.json";
90
- const PATCH_INFO_CACHE_RELATIVE_PATH = path.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
91
- const PATCH_INFO_LEGACY_RELATIVE_PATH = path.join(".tw-patch", PATCH_INFO_FILENAME);
92
- function toDisplayPath(value) {
93
- return path.normalize(value).replace(/\\/g, "/");
94
- }
95
- function formatRelativeToBase(targetPath, baseDir) {
96
- if (!baseDir) return toDisplayPath(targetPath);
97
- const relative = path.relative(baseDir, targetPath);
98
- if (!relative || relative === ".") return ".";
99
- if (relative.startsWith("..")) return toDisplayPath(targetPath);
100
- return toDisplayPath(path.join(".", relative));
101
- }
102
- function resolveRecordLocation(baseDir) {
103
- const normalizedBase = path.normalize(baseDir);
104
- const packageRoot = findNearestPackageRoot(normalizedBase) ?? normalizedBase;
105
- const packageJsonPath = path.join(packageRoot, "package.json");
106
- const hasPackageJson = existsSync(packageJsonPath);
107
- const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
108
- const recordKey = md5Hash(path.normalize(recordKeySource));
109
- const recordDir = path.join(packageRoot, "node_modules", ".cache", "weapp-tailwindcss", recordKey);
110
- return {
111
- normalizedBase,
112
- packageRoot,
113
- recordDir,
114
- recordKey,
115
- recordPath: path.join(recordDir, PATCH_INFO_FILENAME),
116
- packageJsonPath: hasPackageJson ? packageJsonPath : void 0
117
- };
118
- }
119
- function getRecordFileCandidates(baseDir) {
120
- const { normalizedBase, packageRoot, recordPath } = resolveRecordLocation(baseDir);
121
- return [...new Set([
122
- recordPath,
123
- path.join(packageRoot, PATCH_INFO_CACHE_RELATIVE_PATH),
124
- path.join(normalizedBase, PATCH_INFO_CACHE_RELATIVE_PATH),
125
- path.join(normalizedBase, PATCH_INFO_LEGACY_RELATIVE_PATH)
126
- ])];
47
+ //#region src/tailwindcss/source-scan.ts
48
+ const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
49
+ "html",
50
+ "wxml",
51
+ "axml",
52
+ "jxml",
53
+ "ksml",
54
+ "ttml",
55
+ "qml",
56
+ "tyml",
57
+ "xhsml",
58
+ "swan",
59
+ "vue",
60
+ "mpx",
61
+ "js",
62
+ "jsx",
63
+ "ts",
64
+ "tsx"
65
+ ];
66
+ const FULL_SOURCE_SCAN_EXTENSIONS = [
67
+ "js",
68
+ "jsx",
69
+ "mjs",
70
+ "cjs",
71
+ "ts",
72
+ "tsx",
73
+ "mts",
74
+ "cts",
75
+ "vue",
76
+ "uvue",
77
+ "nvue",
78
+ "svelte",
79
+ "mpx",
80
+ "html",
81
+ "wxml",
82
+ "axml",
83
+ "jxml",
84
+ "ksml",
85
+ "ttml",
86
+ "qml",
87
+ "tyml",
88
+ "xhsml",
89
+ "swan",
90
+ "css",
91
+ "wxss",
92
+ "acss",
93
+ "jxss",
94
+ "ttss",
95
+ "qss",
96
+ "tyss",
97
+ "scss",
98
+ "sass",
99
+ "less",
100
+ "styl",
101
+ "stylus"
102
+ ];
103
+ function createSourceScanPattern(extensions = DEFAULT_SOURCE_SCAN_EXTENSIONS) {
104
+ return `**/*.{${extensions.join(",")}}`;
127
105
  }
106
+ createSourceScanPattern(FULL_SOURCE_SCAN_EXTENSIONS);
107
+ new RegExp(`\\.(?:${FULL_SOURCE_SCAN_EXTENSIONS.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`);
128
108
  //#endregion
129
- //#region package.json
130
- var version = "5.0.0-next.2";
131
- //#endregion
132
- //#region src/constants.ts
133
- const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
134
- const WEAPP_TW_VERSION = version;
135
- //#endregion
136
- //#region src/tailwindcss/targets/record-io.ts
137
- const loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
138
- function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
139
- const normalizedPath = path.normalize(recordPath);
140
- if (loggedInvalidPatchRecords.has(normalizedPath)) return;
141
- loggedInvalidPatchRecords.add(normalizedPath);
142
- const fileDisplay = formatRelativeToBase(normalizedPath, baseDir);
143
- const baseDisplay = formatRelativeToBase(path.normalize(baseDir), process.cwd());
144
- const reasonMessage = reason ? `:${reason}` : "";
145
- logger.warn(`检测到损坏的 Tailwind CSS 目标记录 ${fileDisplay}${reasonMessage}。请在 ${baseDisplay} 重新执行 "weapp-tw patch --record-target" 或删除该文件后再运行。`);
146
- }
147
- function readPatchTargetRecord(baseDir) {
148
- if (!baseDir) return;
149
- const normalizedBase = path.normalize(baseDir);
150
- for (const recordPath of getRecordFileCandidates(normalizedBase)) {
151
- if (!existsSync(recordPath)) continue;
152
- try {
153
- const content = readFileSync(recordPath, "utf8");
154
- const parsed = JSON.parse(content);
155
- if (!parsed || typeof parsed.tailwindPackagePath !== "string") {
156
- warnInvalidPatchTargetRecord(normalizedBase, recordPath, "缺少 tailwindPackagePath 字段");
157
- continue;
158
- }
159
- return {
160
- baseDir: normalizedBase,
161
- path: recordPath,
162
- record: parsed
163
- };
164
- } catch (error) {
165
- warnInvalidPatchTargetRecord(normalizedBase, recordPath, error instanceof Error ? error.message : String(error));
166
- continue;
167
- }
168
- }
169
- }
170
- async function saveCliPatchTargetRecord(baseDir, patcher, options) {
171
- if (!baseDir || !patcher?.packageInfo?.rootPath) return;
172
- const normalizedBase = path.normalize(baseDir);
173
- const location = resolveRecordLocation(normalizedBase);
174
- const recordPath = options?.recordPath ? path.normalize(options.recordPath) : location.recordPath;
175
- const record = {
176
- tailwindPackagePath: path.normalize(patcher.packageInfo.rootPath),
177
- packageVersion: patcher.packageInfo.version,
178
- recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
179
- source: options?.source ?? "cli",
180
- tailwindcssBasedir: normalizedBase,
181
- cwd: options?.cwd ? path.normalize(options.cwd) : normalizedBase,
182
- patchVersion: WEAPP_TW_VERSION,
183
- packageJsonPath: options?.packageJsonPath ?? location.packageJsonPath,
184
- recordKey: options?.recordKey ?? location.recordKey
185
- };
186
- try {
187
- await mkdir(path.dirname(recordPath), { recursive: true });
188
- await writeFile(recordPath, `${JSON.stringify(record, null, 2)}\n`, "utf8");
189
- return recordPath;
190
- } catch (error) {
191
- const baseDisplay = formatRelativeToBase(normalizedBase, process.cwd());
192
- logger.warn("自动更新 Tailwind CSS 补丁记录失败,请在 %s 运行 \"weapp-tw patch --cwd %s\"。", baseDisplay, normalizedBase);
193
- logger.debug("failed to persist patch target record %s: %O", recordPath, error);
194
- return;
195
- }
196
- }
109
+ //#region src/utils/object.ts
110
+ function definedEntries(value) {
111
+ return Object.entries(value).filter(([, item]) => item !== void 0);
112
+ }
113
+ function omitUndefined(value) {
114
+ return Object.fromEntries(definedEntries(value));
115
+ }
116
+ createStyleHandler({
117
+ cssChildCombinatorReplaceValue: ["view", "text"],
118
+ cssRemoveHoverPseudoClass: true,
119
+ isMainChunk: true,
120
+ majorVersion: 4
121
+ });
197
122
  //#endregion
198
- //#region src/tailwindcss/targets/recorder.ts
199
- function findPatchTargetRecord(baseDir) {
200
- const visited = /* @__PURE__ */ new Set();
201
- const fallback = baseDir ?? process.cwd();
202
- let current = path.resolve(fallback);
203
- while (!visited.has(current)) {
204
- const record = readPatchTargetRecord(current);
205
- if (record) return record;
206
- const parent = path.dirname(current);
207
- if (parent === current) break;
208
- visited.add(current);
209
- current = parent;
210
- }
211
- }
212
- function createPatchTargetRecorder(baseDir, patcher, options) {
213
- if (!baseDir || !patcher?.packageInfo?.rootPath || options?.recordTarget === false) return;
214
- const normalizedBase = path.normalize(baseDir);
215
- const recorded = findPatchTargetRecord(normalizedBase);
216
- const location = resolveRecordLocation(normalizedBase);
217
- const expectedPath = path.normalize(patcher.packageInfo.rootPath);
218
- let reason;
219
- if (!recorded) reason = "missing";
220
- else if (path.normalize(recorded.record.tailwindPackagePath) !== expectedPath) reason = "mismatch";
221
- else if (path.normalize(recorded.path) !== path.normalize(location.recordPath) || !recorded.record.recordKey || recorded.record.recordKey !== location.recordKey) reason = "migrate";
222
- else if (!recorded.record.patchVersion || recorded.record.patchVersion !== WEAPP_TW_VERSION) reason = "stale";
223
- else if (options?.cwd && recorded.record.cwd && path.normalize(recorded.record.cwd) !== path.normalize(options.cwd)) reason = "metadata";
224
- else if (!recorded.record.cwd && options?.cwd) reason = "metadata";
225
- if (!(options?.alwaysRecord || !recorded || Boolean(reason))) return;
226
- let message;
227
- switch (reason) {
228
- case "mismatch":
229
- message = "检测到 Tailwind CSS 目标记录与当前解析结果不一致,正在自动重新 patch 并刷新缓存。";
230
- break;
231
- case "migrate":
232
- case "stale":
233
- message = "正在刷新当前子包的 Tailwind CSS 补丁记录,确保缓存隔离。";
234
- break;
235
- case "missing":
236
- message = "未找到当前子包的 Tailwind CSS 目标记录,正在生成。";
237
- break;
238
- default: break;
239
- }
240
- const onPatched = async () => saveCliPatchTargetRecord(normalizedBase, patcher, {
241
- cwd: options?.cwd ?? normalizedBase,
242
- source: options?.source ?? "cli",
243
- recordPath: location.recordPath,
244
- recordKey: location.recordKey,
245
- packageJsonPath: location.packageJsonPath
246
- });
247
- return {
248
- recordPath: location.recordPath,
249
- message,
250
- reason,
251
- onPatched
252
- };
253
- }
123
+ //#region src/tailwindcss/v4-engine/tailwind-v3-default-colors.ts
124
+ const TAILWIND_V3_COLOR_STEPS = [
125
+ "50",
126
+ "100",
127
+ "200",
128
+ "300",
129
+ "400",
130
+ "500",
131
+ "600",
132
+ "700",
133
+ "800",
134
+ "900",
135
+ "950"
136
+ ];
137
+ const TAILWIND_V3_COLOR_PALETTE = {
138
+ slate: [
139
+ "#f8fafc",
140
+ "#f1f5f9",
141
+ "#e2e8f0",
142
+ "#cbd5e1",
143
+ "#94a3b8",
144
+ "#64748b",
145
+ "#475569",
146
+ "#334155",
147
+ "#1e293b",
148
+ "#0f172a",
149
+ "#020617"
150
+ ],
151
+ gray: [
152
+ "#f9fafb",
153
+ "#f3f4f6",
154
+ "#e5e7eb",
155
+ "#d1d5db",
156
+ "#9ca3af",
157
+ "#6b7280",
158
+ "#4b5563",
159
+ "#374151",
160
+ "#1f2937",
161
+ "#111827",
162
+ "#030712"
163
+ ],
164
+ zinc: [
165
+ "#fafafa",
166
+ "#f4f4f5",
167
+ "#e4e4e7",
168
+ "#d4d4d8",
169
+ "#a1a1aa",
170
+ "#71717a",
171
+ "#52525b",
172
+ "#3f3f46",
173
+ "#27272a",
174
+ "#18181b",
175
+ "#09090b"
176
+ ],
177
+ neutral: [
178
+ "#fafafa",
179
+ "#f5f5f5",
180
+ "#e5e5e5",
181
+ "#d4d4d4",
182
+ "#a3a3a3",
183
+ "#737373",
184
+ "#525252",
185
+ "#404040",
186
+ "#262626",
187
+ "#171717",
188
+ "#0a0a0a"
189
+ ],
190
+ stone: [
191
+ "#fafaf9",
192
+ "#f5f5f4",
193
+ "#e7e5e4",
194
+ "#d6d3d1",
195
+ "#a8a29e",
196
+ "#78716c",
197
+ "#57534e",
198
+ "#44403c",
199
+ "#292524",
200
+ "#1c1917",
201
+ "#0c0a09"
202
+ ],
203
+ red: [
204
+ "#fef2f2",
205
+ "#fee2e2",
206
+ "#fecaca",
207
+ "#fca5a5",
208
+ "#f87171",
209
+ "#ef4444",
210
+ "#dc2626",
211
+ "#b91c1c",
212
+ "#991b1b",
213
+ "#7f1d1d",
214
+ "#450a0a"
215
+ ],
216
+ orange: [
217
+ "#fff7ed",
218
+ "#ffedd5",
219
+ "#fed7aa",
220
+ "#fdba74",
221
+ "#fb923c",
222
+ "#f97316",
223
+ "#ea580c",
224
+ "#c2410c",
225
+ "#9a3412",
226
+ "#7c2d12",
227
+ "#431407"
228
+ ],
229
+ amber: [
230
+ "#fffbeb",
231
+ "#fef3c7",
232
+ "#fde68a",
233
+ "#fcd34d",
234
+ "#fbbf24",
235
+ "#f59e0b",
236
+ "#d97706",
237
+ "#b45309",
238
+ "#92400e",
239
+ "#78350f",
240
+ "#451a03"
241
+ ],
242
+ yellow: [
243
+ "#fefce8",
244
+ "#fef9c3",
245
+ "#fef08a",
246
+ "#fde047",
247
+ "#facc15",
248
+ "#eab308",
249
+ "#ca8a04",
250
+ "#a16207",
251
+ "#854d0e",
252
+ "#713f12",
253
+ "#422006"
254
+ ],
255
+ lime: [
256
+ "#f7fee7",
257
+ "#ecfccb",
258
+ "#d9f99d",
259
+ "#bef264",
260
+ "#a3e635",
261
+ "#84cc16",
262
+ "#65a30d",
263
+ "#4d7c0f",
264
+ "#3f6212",
265
+ "#365314",
266
+ "#1a2e05"
267
+ ],
268
+ green: [
269
+ "#f0fdf4",
270
+ "#dcfce7",
271
+ "#bbf7d0",
272
+ "#86efac",
273
+ "#4ade80",
274
+ "#22c55e",
275
+ "#16a34a",
276
+ "#15803d",
277
+ "#166534",
278
+ "#14532d",
279
+ "#052e16"
280
+ ],
281
+ emerald: [
282
+ "#ecfdf5",
283
+ "#d1fae5",
284
+ "#a7f3d0",
285
+ "#6ee7b7",
286
+ "#34d399",
287
+ "#10b981",
288
+ "#059669",
289
+ "#047857",
290
+ "#065f46",
291
+ "#064e3b",
292
+ "#022c22"
293
+ ],
294
+ teal: [
295
+ "#f0fdfa",
296
+ "#ccfbf1",
297
+ "#99f6e4",
298
+ "#5eead4",
299
+ "#2dd4bf",
300
+ "#14b8a6",
301
+ "#0d9488",
302
+ "#0f766e",
303
+ "#115e59",
304
+ "#134e4a",
305
+ "#042f2e"
306
+ ],
307
+ cyan: [
308
+ "#ecfeff",
309
+ "#cffafe",
310
+ "#a5f3fc",
311
+ "#67e8f9",
312
+ "#22d3ee",
313
+ "#06b6d4",
314
+ "#0891b2",
315
+ "#0e7490",
316
+ "#155e75",
317
+ "#164e63",
318
+ "#083344"
319
+ ],
320
+ sky: [
321
+ "#f0f9ff",
322
+ "#e0f2fe",
323
+ "#bae6fd",
324
+ "#7dd3fc",
325
+ "#38bdf8",
326
+ "#0ea5e9",
327
+ "#0284c7",
328
+ "#0369a1",
329
+ "#075985",
330
+ "#0c4a6e",
331
+ "#082f49"
332
+ ],
333
+ blue: [
334
+ "#eff6ff",
335
+ "#dbeafe",
336
+ "#bfdbfe",
337
+ "#93c5fd",
338
+ "#60a5fa",
339
+ "#3b82f6",
340
+ "#2563eb",
341
+ "#1d4ed8",
342
+ "#1e40af",
343
+ "#1e3a8a",
344
+ "#172554"
345
+ ],
346
+ indigo: [
347
+ "#eef2ff",
348
+ "#e0e7ff",
349
+ "#c7d2fe",
350
+ "#a5b4fc",
351
+ "#818cf8",
352
+ "#6366f1",
353
+ "#4f46e5",
354
+ "#4338ca",
355
+ "#3730a3",
356
+ "#312e81",
357
+ "#1e1b4b"
358
+ ],
359
+ violet: [
360
+ "#f5f3ff",
361
+ "#ede9fe",
362
+ "#ddd6fe",
363
+ "#c4b5fd",
364
+ "#a78bfa",
365
+ "#8b5cf6",
366
+ "#7c3aed",
367
+ "#6d28d9",
368
+ "#5b21b6",
369
+ "#4c1d95",
370
+ "#2e1065"
371
+ ],
372
+ purple: [
373
+ "#faf5ff",
374
+ "#f3e8ff",
375
+ "#e9d5ff",
376
+ "#d8b4fe",
377
+ "#c084fc",
378
+ "#a855f7",
379
+ "#9333ea",
380
+ "#7e22ce",
381
+ "#6b21a8",
382
+ "#581c87",
383
+ "#3b0764"
384
+ ],
385
+ fuchsia: [
386
+ "#fdf4ff",
387
+ "#fae8ff",
388
+ "#f5d0fe",
389
+ "#f0abfc",
390
+ "#e879f9",
391
+ "#d946ef",
392
+ "#c026d3",
393
+ "#a21caf",
394
+ "#86198f",
395
+ "#701a75",
396
+ "#4a044e"
397
+ ],
398
+ pink: [
399
+ "#fdf2f8",
400
+ "#fce7f3",
401
+ "#fbcfe8",
402
+ "#f9a8d4",
403
+ "#f472b6",
404
+ "#ec4899",
405
+ "#db2777",
406
+ "#be185d",
407
+ "#9d174d",
408
+ "#831843",
409
+ "#500724"
410
+ ],
411
+ rose: [
412
+ "#fff1f2",
413
+ "#ffe4e6",
414
+ "#fecdd3",
415
+ "#fda4af",
416
+ "#fb7185",
417
+ "#f43f5e",
418
+ "#e11d48",
419
+ "#be123c",
420
+ "#9f1239",
421
+ "#881337",
422
+ "#4c0519"
423
+ ]
424
+ };
425
+ function createTailwindV3DefaultColorThemeCss() {
426
+ const declarations = [" --color-black: #000;", " --color-white: #fff;"];
427
+ for (const [color, values] of Object.entries(TAILWIND_V3_COLOR_PALETTE)) for (let index = 0; index < TAILWIND_V3_COLOR_STEPS.length; index++) declarations.push(` --color-${color}-${TAILWIND_V3_COLOR_STEPS[index]}: ${values[index]};`);
428
+ return [
429
+ "@theme {",
430
+ ...declarations,
431
+ "}"
432
+ ].join("\n");
433
+ }
434
+ [
435
+ "@theme {",
436
+ " --default-ring-width: 3px;",
437
+ " --default-ring-color: var(--color-blue-500, #3b82f6);",
438
+ " --default-outline-width: 3px;",
439
+ "",
440
+ " --shadow-xs: 0 1px rgb(0 0 0 / 0.05);",
441
+ " --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);",
442
+ " --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);",
443
+ " --drop-shadow-xs: 0 1px 1px rgb(0 0 0 / 0.05);",
444
+ " --drop-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.15);",
445
+ " --drop-shadow: 0 1px 2px rgb(0 0 0 / 0.1), 0 1px 1px rgb(0 0 0 / 0.06);",
446
+ "",
447
+ " --blur-xs: 4px;",
448
+ " --blur-sm: 4px;",
449
+ " --blur: 8px;",
450
+ " --backdrop-blur-xs: 4px;",
451
+ " --backdrop-blur-sm: 4px;",
452
+ " --backdrop-blur: 8px;",
453
+ "",
454
+ " --radius-xs: 0.125rem;",
455
+ " --radius-sm: 0.125rem;",
456
+ " --radius: 0.25rem;",
457
+ "}",
458
+ createTailwindV3DefaultColorThemeCss()
459
+ ].join("\n");
460
+ [
461
+ "*,",
462
+ "::after,",
463
+ "::before,",
464
+ "::backdrop,",
465
+ "::file-selector-button {",
466
+ " border-color: var(--color-gray-200, currentcolor);",
467
+ "}",
468
+ "",
469
+ "input::placeholder,",
470
+ "textarea::placeholder {",
471
+ " opacity: 1;",
472
+ " color: var(--color-gray-400, currentcolor);",
473
+ "}",
474
+ "",
475
+ "button:not(:disabled),",
476
+ "[role=\"button\"]:not(:disabled) {",
477
+ " cursor: pointer;",
478
+ "}",
479
+ "",
480
+ "dialog {",
481
+ " margin: auto;",
482
+ "}"
483
+ ].join("\n");
484
+ createStyleHandler({
485
+ cssChildCombinatorReplaceValue: ["view", "text"],
486
+ cssRemoveHoverPseudoClass: true,
487
+ isMainChunk: true,
488
+ majorVersion: 3
489
+ });
490
+ [
491
+ "@tailwind base;",
492
+ "@tailwind components;",
493
+ "@tailwind utilities;"
494
+ ].join("\n");
495
+ createDebug("[tailwindcss:runtime-patch] ");
496
+ createRequire(import.meta.url);
497
+ createDebug("[tailwindcss:runtime] ");
254
498
  //#endregion
255
- //#region src/tailwindcss/targets.ts
256
- function logTailwindcssTarget(kind, patcher, baseDir) {
257
- const packageInfo = patcher?.packageInfo;
258
- const label = kind === "cli" ? "weapp-tw patch" : "Weapp-tailwindcss";
259
- if (!packageInfo?.rootPath) {
260
- logger.warn("%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss", label, baseDir ?? process.cwd());
261
- return;
262
- }
263
- const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
264
- const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
265
- if (kind === "runtime") {
266
- logRuntimeTailwindcssTarget(baseDir, packageInfo.rootPath, packageInfo.version);
267
- return;
268
- }
269
- logger.info("%s 绑定 Tailwind CSS -> %s%s", label, displayPath, version);
270
- }
499
+ //#region src/tailwindcss/runtime-logs.ts
500
+ const runtimeLogDedupeHolder = globalThis;
501
+ runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ = /* @__PURE__ */ new Set());
271
502
  //#endregion
272
503
  //#region src/context/compiler-context-cache.ts
273
504
  const globalCacheHolder = globalThis;
274
505
  globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
275
506
  //#endregion
507
+ //#region src/constants.ts
508
+ const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
509
+ //#endregion
276
510
  //#region src/babel/index.ts
277
511
  function _interopDefaultCompat(e) {
278
512
  return e && typeof e === "object" && "default" in e ? e.default : e;
@@ -286,6 +520,7 @@ function buildFuzzyMatcher(fuzzyStrings) {
286
520
  if (fuzzyStrings.length === 0) return;
287
521
  if (fuzzyStrings.length === 1) {
288
522
  const [needle] = fuzzyStrings;
523
+ if (needle === void 0) return;
289
524
  return (value) => value.includes(needle);
290
525
  }
291
526
  const unique = [...new Set(fuzzyStrings)];
@@ -309,11 +544,13 @@ function createNameMatcher(list, { exact = false } = {}) {
309
544
  const exactStringCount = exactStrings?.size ?? 0;
310
545
  if (exactStringCount === 1 && regexList.length === 0) {
311
546
  const [needle] = exactStrings;
547
+ if (needle === void 0) return NEVER_MATCH_NAME$1;
312
548
  return (value) => value === needle;
313
549
  }
314
550
  if (regexList.length === 0) return (value) => exactStrings.has(value);
315
551
  if (exactStringCount === 0 && regexList.length === 1) {
316
552
  const [regex] = regexList;
553
+ if (!regex) return NEVER_MATCH_NAME$1;
317
554
  return (value) => regex.test(value);
318
555
  }
319
556
  return (value) => {
@@ -326,6 +563,7 @@ function createNameMatcher(list, { exact = false } = {}) {
326
563
  if (fuzzyMatcher && !hasRegex) return fuzzyMatcher;
327
564
  if (!fuzzyMatcher && regexList.length === 1) {
328
565
  const [regex] = regexList;
566
+ if (!regex) return NEVER_MATCH_NAME$1;
329
567
  return (value) => regex.test(value);
330
568
  }
331
569
  return (value) => {
@@ -336,20 +574,40 @@ function createNameMatcher(list, { exact = false } = {}) {
336
574
  }
337
575
  //#endregion
338
576
  //#region src/js/babel/parse.ts
339
- const parseCache = new LRUCache({ max: 1024 });
577
+ const parseCache = new LRUCache({ max: HARD_PARSE_CACHE_MAX_ENTRIES });
340
578
  function genCacheKey(source, options) {
341
- if (typeof options === "string") return source + options;
342
- return source + JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val);
579
+ if (typeof options === "string") return `${md5Hash(source)}:${options}`;
580
+ return `${md5Hash(source)}:${JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val)}`;
581
+ }
582
+ function normalizeCacheMaxEntries(value) {
583
+ if (typeof value !== "number" || !Number.isFinite(value)) return 128;
584
+ return Math.min(Math.max(Math.floor(value), 0), HARD_PARSE_CACHE_MAX_ENTRIES);
585
+ }
586
+ function normalizeCacheMaxSourceLength(value) {
587
+ if (typeof value !== "number" || !Number.isFinite(value)) return DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH;
588
+ return Math.max(Math.floor(value), 0);
589
+ }
590
+ function trimParseCache(maxEntries) {
591
+ while (parseCache.size > maxEntries) parseCache.pop();
343
592
  }
344
593
  function babelParse(code, opts = {}) {
345
- const { cache, cacheKey, ...rest } = opts;
346
- const cacheKeyString = genCacheKey(code, cacheKey ?? rest);
594
+ const { cache, cacheKey, cacheMaxEntries, cacheMaxSourceLength, ...rest } = opts;
595
+ const maxEntries = normalizeCacheMaxEntries(cacheMaxEntries);
596
+ const maxSourceLength = normalizeCacheMaxSourceLength(cacheMaxSourceLength);
597
+ const shouldCache = cache === true && maxEntries > 0 && code.length <= maxSourceLength;
598
+ const cacheKeyString = shouldCache ? genCacheKey(code, cacheKey ?? rest) : void 0;
347
599
  let result;
348
- if (cache) result = parseCache.get(cacheKeyString);
600
+ if (shouldCache) {
601
+ trimParseCache(maxEntries);
602
+ result = parseCache.get(cacheKeyString);
603
+ }
349
604
  if (!result) {
350
- const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
351
- result = parse$1(code, parseOptions);
352
- if (cache) parseCache.set(cacheKeyString, result);
605
+ const { cache: _cache, cacheKey: _cacheKey, cacheMaxEntries: _cacheMaxEntries, cacheMaxSourceLength: _cacheMaxSourceLength, ...parseOptions } = opts;
606
+ result = parse(code, parseOptions);
607
+ if (shouldCache) {
608
+ parseCache.set(cacheKeyString, result);
609
+ trimParseCache(maxEntries);
610
+ }
353
611
  }
354
612
  return result;
355
613
  }
@@ -363,10 +621,10 @@ function replaceWxml(original, options = {
363
621
  const { keepEOL, escapeMap, ignoreHead } = options;
364
622
  let res = original;
365
623
  if (!keepEOL) res = res.replaceAll(NEWLINE_RE, "");
366
- res = escape(res, {
624
+ res = escape(res, omitUndefined({
367
625
  map: escapeMap,
368
626
  ignoreHead
369
- });
627
+ }));
370
628
  return res;
371
629
  }
372
630
  //#endregion
@@ -904,6 +1162,44 @@ function walkEvalExpression(path, options, updater, handler) {
904
1162
  }
905
1163
  }
906
1164
  //#endregion
1165
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
1166
+ function _typeof(o) {
1167
+ "@babel/helpers - typeof";
1168
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
1169
+ return typeof o;
1170
+ } : function(o) {
1171
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1172
+ }, _typeof(o);
1173
+ }
1174
+ //#endregion
1175
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
1176
+ function toPrimitive(t, r) {
1177
+ if ("object" != _typeof(t) || !t) return t;
1178
+ var e = t[Symbol.toPrimitive];
1179
+ if (void 0 !== e) {
1180
+ var i = e.call(t, r || "default");
1181
+ if ("object" != _typeof(i)) return i;
1182
+ throw new TypeError("@@toPrimitive must return a primitive value.");
1183
+ }
1184
+ return ("string" === r ? String : Number)(t);
1185
+ }
1186
+ //#endregion
1187
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
1188
+ function toPropertyKey(t) {
1189
+ var i = toPrimitive(t, "string");
1190
+ return "symbol" == _typeof(i) ? i : i + "";
1191
+ }
1192
+ //#endregion
1193
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
1194
+ function _defineProperty(e, r, t) {
1195
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1196
+ value: t,
1197
+ enumerable: !0,
1198
+ configurable: !0,
1199
+ writable: !0
1200
+ }) : e[r] = t, e;
1201
+ }
1202
+ //#endregion
907
1203
  //#region src/js/JsTokenUpdater.ts
908
1204
  /**
909
1205
  * Lightweight helper that batches updates to {@link MagicString}.
@@ -912,6 +1208,7 @@ function walkEvalExpression(path, options, updater, handler) {
912
1208
  */
913
1209
  var JsTokenUpdater = class {
914
1210
  constructor({ value } = {}) {
1211
+ _defineProperty(this, "tokens", void 0);
915
1212
  this.tokens = value ? [...value] : [];
916
1213
  }
917
1214
  addToken(token) {
@@ -945,7 +1242,7 @@ var JsTokenUpdater = class {
945
1242
  var IgnoredExportsTracker = class {
946
1243
  constructor(options) {
947
1244
  this.options = options;
948
- this.ignoredExportNames = /* @__PURE__ */ new Map();
1245
+ _defineProperty(this, "ignoredExportNames", /* @__PURE__ */ new Map());
949
1246
  }
950
1247
  addIgnoredExport(filename, exportName) {
951
1248
  if (!exportName) return;
@@ -1064,8 +1361,16 @@ var IgnoredExportsTracker = class {
1064
1361
  //#region src/js/ModuleGraph.ts
1065
1362
  var JsModuleGraph = class {
1066
1363
  constructor(entry, graphOptions) {
1067
- this.modules = /* @__PURE__ */ new Map();
1068
- this.queue = [];
1364
+ _defineProperty(this, "modules", /* @__PURE__ */ new Map());
1365
+ _defineProperty(this, "queue", []);
1366
+ _defineProperty(this, "resolve", void 0);
1367
+ _defineProperty(this, "load", void 0);
1368
+ _defineProperty(this, "filter", void 0);
1369
+ _defineProperty(this, "maxDepth", void 0);
1370
+ _defineProperty(this, "baseOptions", void 0);
1371
+ _defineProperty(this, "parserOptions", void 0);
1372
+ _defineProperty(this, "rootFilename", void 0);
1373
+ _defineProperty(this, "ignoredExports", void 0);
1069
1374
  this.resolve = graphOptions.resolve;
1070
1375
  this.load = graphOptions.load;
1071
1376
  this.filter = graphOptions.filter;
@@ -1237,6 +1542,12 @@ const NEVER_MATCH_NAME = () => false;
1237
1542
  */
1238
1543
  var NodePathWalker = class {
1239
1544
  constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
1545
+ _defineProperty(this, "ignoreCallExpressionIdentifiers", void 0);
1546
+ _defineProperty(this, "callback", void 0);
1547
+ _defineProperty(this, "isIgnoredCallIdentifier", void 0);
1548
+ _defineProperty(this, "hasIgnoredCallIdentifiers", void 0);
1549
+ _defineProperty(this, "importsStore", void 0);
1550
+ _defineProperty(this, "visitedStore", void 0);
1240
1551
  this.hasIgnoredCallIdentifiers = Boolean(ignoreCallExpressionIdentifiers && ignoreCallExpressionIdentifiers.length > 0);
1241
1552
  this.ignoreCallExpressionIdentifiers = ignoreCallExpressionIdentifiers ?? EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS;
1242
1553
  this.callback = callback ?? NOOP_STRING_PATH_CALLBACK;
@@ -1499,7 +1810,7 @@ function analyzeSource(ast, options, handler, collectModuleMetadata = true) {
1499
1810
  const needScope = Boolean(options.ignoreCallExpressionIdentifiers && options.ignoreCallExpressionIdentifiers.length > 0);
1500
1811
  const ignoredPaths = needScope ? /* @__PURE__ */ new WeakSet() : EMPTY_IGNORED_PATHS;
1501
1812
  const walker = needScope ? new NodePathWalker({
1502
- ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
1813
+ ...options.ignoreCallExpressionIdentifiers === void 0 ? {} : { ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers },
1503
1814
  callback(path) {
1504
1815
  ignoredPaths.add(path);
1505
1816
  }
@@ -1509,7 +1820,7 @@ function analyzeSource(ast, options, handler, collectModuleMetadata = true) {
1509
1820
  function getTaggedTemplateIgnore() {
1510
1821
  if (!taggedTemplateIgnore) taggedTemplateIgnore = createTaggedTemplateIgnore({
1511
1822
  matcher: getIgnoredTaggedTemplateMatcher(options),
1512
- names: options.ignoreTaggedTemplateExpressionIdentifiers
1823
+ ...options.ignoreTaggedTemplateExpressionIdentifiers === void 0 ? {} : { names: options.ignoreTaggedTemplateExpressionIdentifiers }
1513
1824
  });
1514
1825
  return taggedTemplateIgnore;
1515
1826
  }
@@ -1644,6 +1955,13 @@ function isWhitespace(char) {
1644
1955
  //#region src/wxml/Tokenizer.ts
1645
1956
  var Tokenizer = class {
1646
1957
  constructor() {
1958
+ _defineProperty(this, "state", void 0);
1959
+ _defineProperty(this, "buffer", void 0);
1960
+ _defineProperty(this, "tokens", void 0);
1961
+ _defineProperty(this, "bufferStartIndex", void 0);
1962
+ _defineProperty(this, "expressionStartIndex", void 0);
1963
+ _defineProperty(this, "expressionBuffer", void 0);
1964
+ _defineProperty(this, "expressions", void 0);
1647
1965
  this.reset();
1648
1966
  }
1649
1967
  processChar(char, index) {
@@ -1734,6 +2052,7 @@ var Tokenizer = class {
1734
2052
  this.reset();
1735
2053
  for (let i = 0; i < input.length; i++) {
1736
2054
  const char = input[i];
2055
+ if (char === void 0) continue;
1737
2056
  this.processChar(char, i);
1738
2057
  }
1739
2058
  if (this.buffer.length > 0) this.tokens.push({
@@ -1758,36 +2077,6 @@ var Tokenizer = class {
1758
2077
  };
1759
2078
  new Tokenizer();
1760
2079
  //#endregion
1761
- //#region src/context/index.ts
1762
- async function clearTailwindcssPatcherCache(patcher, options) {
1763
- if (!patcher) return;
1764
- const cacheOptions = patcher.options?.cache;
1765
- if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) return;
1766
- if (typeof patcher.clearCache === "function") try {
1767
- await patcher.clearCache({ scope: "all" });
1768
- } catch (error) {
1769
- logger.debug("failed to clear tailwindcss patcher cache via clearCache(): %O", error);
1770
- }
1771
- if (!options?.removeDirectory) return;
1772
- const cachePaths = /* @__PURE__ */ new Map();
1773
- const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
1774
- if (normalizedCacheOptions?.path) cachePaths.set(normalizedCacheOptions.path, false);
1775
- const privateCachePath = patcher?.cacheStore?.options?.path;
1776
- if (privateCachePath) cachePaths.set(privateCachePath, false);
1777
- if (options?.removeDirectory && normalizedCacheOptions?.dir) cachePaths.set(normalizedCacheOptions.dir, true);
1778
- if (!cachePaths.size) return;
1779
- for (const [cachePath, recursive] of cachePaths.entries()) try {
1780
- await rm(cachePath, {
1781
- force: true,
1782
- recursive
1783
- });
1784
- } catch (error) {
1785
- const err = error;
1786
- if (err?.code === "ENOENT") continue;
1787
- logger.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
1788
- }
1789
- }
1790
- //#endregion
1791
2080
  //#region src/cli/context.ts
1792
2081
  function formatOutputPath(target, baseDir) {
1793
2082
  const root = baseDir ?? process.cwd();
@@ -1831,7 +2120,7 @@ const FRAMEWORK_DEPS = [
1831
2120
  ];
1832
2121
  //#endregion
1833
2122
  //#region src/cli/doctor.ts
1834
- function tryReadJson$1(file) {
2123
+ function tryReadJson(file) {
1835
2124
  try {
1836
2125
  return JSON.parse(readFileSync(file, "utf8"));
1837
2126
  } catch {
@@ -1842,11 +2131,11 @@ function findFirstExisting(cwd, files) {
1842
2131
  return files.find((file) => existsSync(path.join(cwd, file)));
1843
2132
  }
1844
2133
  function readProjectPackageJson(cwd) {
1845
- return tryReadJson$1(path.join(cwd, "package.json"));
2134
+ return tryReadJson(path.join(cwd, "package.json"));
1846
2135
  }
1847
2136
  function readDependencyVersion(cwd, packageName) {
1848
2137
  try {
1849
- return tryReadJson$1(createRequire(path.join(cwd, "package.json")).resolve(`${packageName}/package.json`))?.version;
2138
+ return tryReadJson(createRequire(path.join(cwd, "package.json")).resolve(`${packageName}/package.json`))?.version;
1850
2139
  } catch {
1851
2140
  return;
1852
2141
  }
@@ -2089,52 +2378,15 @@ function resolveCliCwd(value) {
2089
2378
  return path.isAbsolute(raw) ? path.normalize(raw) : path.resolve(process.cwd(), raw);
2090
2379
  }
2091
2380
  //#endregion
2092
- //#region src/tailwindcss/index.ts
2093
- function getTailwindcssPackageInfo(options) {
2094
- return getPackageInfoSync("tailwindcss", options);
2095
- }
2096
- //#endregion
2097
- //#region src/cli/helpers/patch-cwd.ts
2098
- /**
2099
- * Resolve default working directory for `weapp-tw patch`.
2100
- * Prefer explicit env overrides to avoid cross-package INIT_CWD pollution.
2101
- */
2102
- function normalizeCandidatePath(baseDir, candidate) {
2103
- if (!candidate) return;
2104
- return path.isAbsolute(candidate) ? path.normalize(candidate) : path.resolve(baseDir, candidate);
2105
- }
2106
- function detectTailwindWorkspace(paths) {
2107
- for (const candidate of paths) try {
2108
- if (getTailwindcssPackageInfo({ paths: [candidate] })?.rootPath) return candidate;
2109
- } catch {}
2110
- }
2111
- function resolvePatchDefaultCwd(currentCwd = process.cwd()) {
2112
- const baseDir = path.normalize(currentCwd);
2113
- const explicitCwd = normalizeCandidatePath(baseDir, process.env.WEAPP_TW_PATCH_CWD);
2114
- if (explicitCwd) return explicitCwd;
2115
- const workspaceRoot = findWorkspaceRoot(baseDir);
2116
- const initCwd = normalizeCandidatePath(baseDir, process.env.INIT_CWD);
2117
- const localPrefix = normalizeCandidatePath(baseDir, process.env.npm_config_local_prefix);
2118
- const candidates = [
2119
- baseDir,
2120
- workspaceRoot,
2121
- initCwd,
2122
- localPrefix
2123
- ].filter(Boolean);
2124
- const detected = detectTailwindWorkspace([...new Set(candidates)]);
2125
- if (detected) return detected;
2126
- return initCwd ?? localPrefix ?? workspaceRoot ?? baseDir;
2127
- }
2128
- //#endregion
2129
2381
  //#region src/cli/helpers.ts
2130
2382
  async function ensureDir(dir) {
2131
2383
  await mkdir(dir, { recursive: true });
2132
2384
  }
2133
2385
  function handleCliError$1(error) {
2134
2386
  if (error instanceof Error) {
2135
- logger$1.error(error.message);
2136
- if (error.stack && process.env.WEAPP_TW_DEBUG === "1") logger$1.error(error.stack);
2137
- } else logger$1.error(String(error));
2387
+ logger.error(error.message);
2388
+ if (error.stack && process.env["WEAPP_TW_DEBUG"] === "1") logger.error(error.stack);
2389
+ } else logger.error(String(error));
2138
2390
  }
2139
2391
  function commandAction(handler) {
2140
2392
  return async (...args) => {
@@ -2147,217 +2399,16 @@ function commandAction(handler) {
2147
2399
  };
2148
2400
  }
2149
2401
  //#endregion
2150
- //#region src/cli/mount-options/patch-status.ts
2151
- function formatStatusFilesHint(files) {
2152
- if (!files?.length) return "";
2153
- return ` (${files.join(", ")})`;
2154
- }
2155
- function logPatchStatusReport(report) {
2156
- const applied = report.entries.filter((entry) => entry.status === "applied");
2157
- const pending = report.entries.filter((entry) => entry.status === "not-applied");
2158
- const skipped = report.entries.filter((entry) => entry.status === "skipped" || entry.status === "unsupported");
2159
- const packageLabel = `${report.package.name ?? "tailwindcss"}@${report.package.version ?? "unknown"}`;
2160
- logger$1.info(`Patch status for ${packageLabel} (v${report.majorVersion})`);
2161
- if (applied.length) {
2162
- logger$1.success("Applied:");
2163
- applied.forEach((entry) => {
2164
- logger$1.success(` - ${entry.name}${formatStatusFilesHint(entry.files)}`);
2165
- });
2166
- }
2167
- if (pending.length) {
2168
- logger$1.warn("Needs attention:");
2169
- pending.forEach((entry) => {
2170
- const details = entry.reason ? ` - ${entry.reason}` : "";
2171
- logger$1.warn(` - ${entry.name}${formatStatusFilesHint(entry.files)}${details}`);
2172
- });
2173
- } else logger$1.success("All applicable patches are applied.");
2174
- if (skipped.length) {
2175
- logger$1.info("Skipped:");
2176
- skipped.forEach((entry) => {
2177
- const details = entry.reason ? ` - ${entry.reason}` : "";
2178
- logger$1.info(` - ${entry.name}${details}`);
2179
- });
2180
- }
2181
- }
2182
- //#endregion
2183
- //#region src/cli/patch-options.ts
2184
- const DEFAULT_EXTEND_LENGTH_UNITS_FEATURE = {
2185
- enabled: true,
2186
- units: ["rpx"],
2187
- overwrite: true
2188
- };
2189
- function withDefaultExtendLengthUnits(options) {
2190
- const normalized = options ?? {};
2191
- if (normalized.apply?.extendLengthUnits == null) return {
2192
- ...normalized,
2193
- apply: {
2194
- ...normalized.apply ?? {},
2195
- extendLengthUnits: DEFAULT_EXTEND_LENGTH_UNITS_FEATURE
2196
- }
2197
- };
2198
- return normalized;
2199
- }
2200
- function buildExtendLengthUnitsOverride(options) {
2201
- if (options?.apply?.extendLengthUnits == null) return { apply: {
2202
- ...options?.apply ?? {},
2203
- extendLengthUnits: DEFAULT_EXTEND_LENGTH_UNITS_FEATURE
2204
- } };
2205
- }
2206
- //#endregion
2207
- //#region src/cli/workspace/workspace-io.ts
2208
- function tryReadJson(file) {
2209
- try {
2210
- const content = readFileSync(file, "utf8");
2211
- return JSON.parse(content);
2212
- } catch {
2213
- return;
2214
- }
2215
- }
2216
- //#endregion
2217
- //#region src/cli/workspace/workspace-globs.ts
2218
- function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
2219
- const pkg = tryReadJson(path.join(workspaceRoot, "package.json"));
2220
- if (!pkg?.workspaces) return [];
2221
- if (Array.isArray(pkg.workspaces)) return pkg.workspaces.filter(Boolean);
2222
- if (Array.isArray(pkg.workspaces.packages)) return pkg.workspaces.packages.filter(Boolean);
2223
- return [];
2224
- }
2225
- function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
2226
- const workspaceFile = path.join(workspaceRoot, "pnpm-workspace.yaml");
2227
- if (!existsSync(workspaceFile)) return [];
2228
- try {
2229
- const parsed = parse(readFileSync(workspaceFile, "utf8"));
2230
- return Array.isArray(parsed?.packages) ? parsed.packages.filter(Boolean) : [];
2231
- } catch {
2232
- return [];
2233
- }
2234
- }
2235
- //#endregion
2236
- //#region src/cli/workspace/workspace-lock.ts
2237
- function parseImportersFromLock(workspaceRoot) {
2238
- const lockPath = path.join(workspaceRoot, "pnpm-lock.yaml");
2239
- if (!existsSync(lockPath)) return [];
2240
- try {
2241
- const importers = parse(readFileSync(lockPath, "utf8"))?.importers;
2242
- if (!importers) return [];
2243
- return Object.keys(importers).map((key) => {
2244
- if (!key || key === ".") return workspaceRoot;
2245
- return path.join(workspaceRoot, key);
2246
- });
2247
- } catch {
2248
- return [];
2249
- }
2250
- }
2251
- //#endregion
2252
- //#region src/cli/workspace/package-dirs.ts
2253
- const BACKSLASH_RE$1 = /\\/g;
2254
- const TRAILING_SLASH_RE = /\/+$/;
2255
- async function resolveWorkspacePackageDirs(workspaceRoot) {
2256
- const dirs = /* @__PURE__ */ new Set();
2257
- for (const importerDir of parseImportersFromLock(workspaceRoot)) dirs.add(path.normalize(importerDir));
2258
- if (!dirs.size) {
2259
- let globs = parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot);
2260
- if (!globs.length) globs = parseWorkspaceGlobsFromPackageJson(workspaceRoot);
2261
- if (globs.length > 0) {
2262
- const packageJsonFiles = await fg(globs.map((pattern) => {
2263
- const normalized = pattern.replace(BACKSLASH_RE$1, "/").replace(TRAILING_SLASH_RE, "");
2264
- return normalized.endsWith("package.json") ? normalized : `${normalized}/package.json`;
2265
- }), {
2266
- cwd: workspaceRoot,
2267
- absolute: true,
2268
- onlyFiles: true,
2269
- unique: true,
2270
- ignore: ["**/node_modules/**", "**/.git/**"]
2271
- });
2272
- for (const file of packageJsonFiles) dirs.add(path.normalize(path.dirname(file)));
2273
- }
2274
- }
2275
- if (existsSync(path.join(workspaceRoot, "package.json"))) dirs.add(path.normalize(workspaceRoot));
2276
- return [...dirs];
2277
- }
2278
- //#endregion
2279
- //#region src/cli/workspace/patch-utils.ts
2280
- function formatDisplayName(workspaceRoot, dir, name) {
2281
- const relative = path.relative(workspaceRoot, dir) || ".";
2282
- return name ? `${name} (${relative})` : relative;
2283
- }
2284
- function summarizeWorkspaceResults(results) {
2285
- const patched = results.filter((result) => result.status === "patched").length;
2286
- const skipped = results.filter((result) => result.status === "skipped").length;
2287
- const failed = results.filter((result) => result.status === "failed").length;
2288
- logger$1.info("[workspace] 汇总:已补丁 %d,跳过 %d,失败 %d", patched, skipped, failed);
2289
- }
2290
- //#endregion
2291
- //#region src/cli/workspace/patch-package.ts
2292
- function createWorkspacePatcher(cwd) {
2293
- return new TailwindcssPatcher(normalizeOptions(withDefaultExtendLengthUnits({ projectRoot: cwd })));
2294
- }
2295
- async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
2296
- const displayName = formatDisplayName(workspaceRoot, dir, pkgName);
2297
- if (!getTailwindcssPackageInfo({ paths: [dir] })?.rootPath) {
2298
- logger$1.info("[workspace] 跳过 %s(tailwindcss 未安装)。", displayName);
2299
- return {
2300
- dir,
2301
- name: pkgName,
2302
- status: "skipped",
2303
- message: "tailwindcss 未安装,已跳过。"
2304
- };
2305
- }
2306
- try {
2307
- const patcher = createWorkspacePatcher(dir);
2308
- if (options.clearCache) await clearTailwindcssPatcherCache(patcher, { removeDirectory: true });
2309
- const recorder = createPatchTargetRecorder(dir, patcher, {
2310
- source: "cli",
2311
- cwd: dir,
2312
- recordTarget: options.recordTarget !== false,
2313
- alwaysRecord: true
2314
- });
2315
- if (recorder?.message) logger$1.info("[workspace] %s %s", displayName, recorder.message);
2316
- logTailwindcssTarget("cli", patcher, dir);
2317
- await patcher.patch();
2318
- if (recorder?.onPatched) await recorder.onPatched();
2319
- logger$1.success("[workspace] 已补丁 %s", displayName);
2320
- return {
2321
- dir,
2322
- name: pkgName,
2323
- status: "patched",
2324
- message: "已完成 patch。"
2325
- };
2326
- } catch (error) {
2327
- const message = `${error instanceof Error ? error.message : String(error)},${`请在 ${dir} 运行 "weapp-tw patch --cwd ${dir}".`}`;
2328
- logger$1.error("[workspace] 补丁失败 %s:%s", displayName, message);
2329
- return {
2330
- dir,
2331
- name: pkgName,
2332
- status: "failed",
2333
- message
2334
- };
2335
- }
2336
- }
2337
- //#endregion
2338
- //#region src/cli/workspace.ts
2339
- async function patchWorkspace(options) {
2340
- const cwd = options.cwd ?? process.cwd();
2341
- const workspaceRoot = findWorkspaceRoot(cwd) ?? cwd;
2342
- const packageDirs = await resolveWorkspacePackageDirs(workspaceRoot);
2343
- if (packageDirs.length === 0) {
2344
- logger$1.warn("未在 %s 检测到 workspace 包,已跳过批量 patch。", workspaceRoot);
2345
- return;
2346
- }
2347
- const results = [];
2348
- for (const dir of packageDirs) {
2349
- const pkgJson = tryReadJson(path.join(dir, "package.json"));
2350
- results.push(await patchWorkspacePackage(workspaceRoot, dir, pkgJson?.name, options));
2351
- }
2352
- summarizeWorkspaceResults(results);
2353
- }
2354
- //#endregion
2355
2402
  //#region src/cli/mount-options.ts
2403
+ const PATCH_COMMAND_OBSOLETE_NOTICE = "提示:weapp-tailwindcss@5 已由构建运行时接管 Tailwind CSS 处理,weapp-tw patch 已无需执行;请移除 package.json 中的 postinstall 钩子。";
2404
+ function logPatchCommandObsoleteNotice() {
2405
+ logger.warn(PATCH_COMMAND_OBSOLETE_NOTICE);
2406
+ }
2356
2407
  function handleCliError(error) {
2357
2408
  if (error instanceof Error) {
2358
- logger$1.error(error.message);
2359
- if (error.stack && process.env.WEAPP_TW_DEBUG === "1") logger$1.error(error.stack);
2360
- } else logger$1.error(String(error));
2409
+ logger.error(error.message);
2410
+ if (error.stack && process.env["WEAPP_TW_DEBUG"] === "1") logger.error(error.stack);
2411
+ } else logger.error(String(error));
2361
2412
  }
2362
2413
  function withCommandErrorHandling(handler) {
2363
2414
  return (async (ctx, next) => {
@@ -2370,92 +2421,18 @@ function withCommandErrorHandling(handler) {
2370
2421
  }
2371
2422
  });
2372
2423
  }
2373
- async function createPatcherWithDefaultExtendLengthUnits(ctx) {
2374
- const extendLengthUnitsOverride = buildExtendLengthUnitsOverride(await ctx.loadPatchOptions());
2375
- if (extendLengthUnitsOverride) return ctx.createPatcher(extendLengthUnitsOverride);
2376
- return ctx.createPatcher();
2377
- }
2424
+ const forwardedCommands = [
2425
+ "extract",
2426
+ "tokens",
2427
+ "init",
2428
+ "migrate",
2429
+ "restore",
2430
+ "validate"
2431
+ ];
2432
+ const commandHandlers = Object.fromEntries(forwardedCommands.map((command) => [command, withCommandErrorHandling(async (_ctx, next) => next())]));
2378
2433
  const mountOptions = {
2379
- commandOptions: {
2380
- install: {
2381
- name: "patch",
2382
- aliases: ["install"],
2383
- appendDefaultOptions: false,
2384
- optionDefs: [
2385
- {
2386
- flags: "--cwd <dir>",
2387
- description: "Working directory",
2388
- config: { default: resolvePatchDefaultCwd() }
2389
- },
2390
- {
2391
- flags: "--record-target",
2392
- description: "Write tailwindcss target metadata (node_modules/.cache/weapp-tailwindcss/tailwindcss-target.json). Pass \"--record-target false\" to skip.",
2393
- config: { default: true }
2394
- },
2395
- {
2396
- flags: "--clear-cache",
2397
- description: "Clear tailwindcss-patch cache before patch (opt-in)"
2398
- },
2399
- {
2400
- flags: "--workspace",
2401
- description: "Scan pnpm workspace packages and patch each Tailwind CSS dependency"
2402
- }
2403
- ]
2404
- },
2405
- status: {
2406
- appendDefaultOptions: false,
2407
- optionDefs: [{
2408
- flags: "--cwd <dir>",
2409
- description: "Working directory",
2410
- config: { default: resolvePatchDefaultCwd() }
2411
- }, {
2412
- flags: "--json",
2413
- description: "Print a JSON report of patch status"
2414
- }]
2415
- }
2416
- },
2417
- commandHandlers: {
2418
- install: withCommandErrorHandling(async (ctx) => {
2419
- const shouldClearCache = toBoolean(ctx.args.clearCache, false);
2420
- const shouldRecordTarget = toBoolean(ctx.args.recordTarget, true);
2421
- if (toBoolean(ctx.args.workspace, false)) {
2422
- await patchWorkspace({
2423
- cwd: ctx.cwd,
2424
- clearCache: shouldClearCache,
2425
- recordTarget: shouldRecordTarget
2426
- });
2427
- return;
2428
- }
2429
- const patcher = await createPatcherWithDefaultExtendLengthUnits(ctx);
2430
- if (shouldClearCache) await clearTailwindcssPatcherCache(patcher, { removeDirectory: true });
2431
- const recorder = createPatchTargetRecorder(ctx.cwd, patcher, {
2432
- source: "cli",
2433
- cwd: ctx.cwd,
2434
- recordTarget: shouldRecordTarget,
2435
- alwaysRecord: true
2436
- });
2437
- if (recorder?.message) logger$1.info(recorder.message);
2438
- logTailwindcssTarget("cli", patcher, ctx.cwd);
2439
- await patcher.patch();
2440
- if (recorder?.onPatched) {
2441
- const recordPath = await recorder.onPatched();
2442
- if (recordPath) logger$1.info(`记录 weapp-tw patch 目标 -> ${formatOutputPath(recordPath, ctx.cwd)}`);
2443
- }
2444
- logger$1.success("Tailwind CSS 运行时补丁已完成。");
2445
- }),
2446
- extract: withCommandErrorHandling(async (_ctx, next) => next()),
2447
- tokens: withCommandErrorHandling(async (_ctx, next) => next()),
2448
- init: withCommandErrorHandling(async (_ctx, next) => next()),
2449
- status: withCommandErrorHandling(async (ctx) => {
2450
- const report = await (await createPatcherWithDefaultExtendLengthUnits(ctx)).getPatchStatus();
2451
- if (ctx.args.json) {
2452
- logger$1.log(JSON.stringify(report, null, 2));
2453
- return report;
2454
- }
2455
- logPatchStatusReport(report);
2456
- return report;
2457
- })
2458
- }
2434
+ commands: [...forwardedCommands],
2435
+ commandHandlers
2459
2436
  };
2460
2437
  //#endregion
2461
2438
  //#region src/cli/vscode-entry.ts
@@ -2558,11 +2535,28 @@ async function generateVscodeIntellisenseEntry(options) {
2558
2535
  //#endregion
2559
2536
  //#region src/cli.ts
2560
2537
  process.title = "node (weapp-tailwindcss)";
2561
- if (!semver.satisfies(process.versions.node, "^20.19.0 || >=22.12.0")) logger$1.warn(`You are using Node.js ${process.versions.node}. For weapp-tailwindcss, Node.js version ${WEAPP_TW_REQUIRED_NODE_VERSION_RANGE} is required.`);
2538
+ if (!semver.satisfies(process.versions.node, "^20.19.0 || >=22.12.0")) logger.warn(`You are using Node.js ${process.versions.node}. For weapp-tailwindcss, Node.js version ${WEAPP_TW_REQUIRED_NODE_VERSION_RANGE} is required.`);
2562
2539
  const cli = createTailwindcssPatchCli({
2563
2540
  name: "weapp-tailwindcss",
2564
2541
  mountOptions
2565
2542
  });
2543
+ cli.command("patch", "Deprecated no-op: v5 runtime handles Tailwind CSS automatically").alias("install").option("--cwd <dir>", "Ignored working directory").option("--clear-cache", "Ignored compatibility option").option("--record-target [enabled]", "Ignored compatibility option").option("--workspace", "Ignored compatibility option").action(commandAction(async (_options) => {
2544
+ logPatchCommandObsoleteNotice();
2545
+ logger.success("已跳过:当前版本不需要手动执行 Tailwind CSS patch。");
2546
+ }));
2547
+ cli.command("status", "Deprecated no-op: patch status is no longer required").option("--cwd <dir>", "Ignored working directory").option("--json", "Print a JSON no-op report").action(commandAction(async (options) => {
2548
+ const payload = {
2549
+ required: false,
2550
+ status: "unnecessary",
2551
+ message: PATCH_COMMAND_OBSOLETE_NOTICE
2552
+ };
2553
+ if (toBoolean(options.json, false)) {
2554
+ logger.log(JSON.stringify(payload, null, 2));
2555
+ return;
2556
+ }
2557
+ logPatchCommandObsoleteNotice();
2558
+ logger.success("无需检查 Tailwind CSS patch 状态。");
2559
+ }));
2566
2560
  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(commandAction(async (options) => {
2567
2561
  const resolvedCwd = resolveCliCwd(options.cwd);
2568
2562
  const baseDir = resolvedCwd ?? process.cwd();
@@ -2575,16 +2569,16 @@ cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliS
2575
2569
  sources: readStringArrayOption("source", options.source),
2576
2570
  force: toBoolean(options.force, false)
2577
2571
  });
2578
- logger$1.success(`VS Code helper generated -> ${formatOutputPath(result.outputPath, resolvedCwd)}`);
2572
+ logger.success(`VS Code helper generated -> ${formatOutputPath(result.outputPath, resolvedCwd)}`);
2579
2573
  }));
2580
2574
  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(commandAction(async (options) => {
2581
2575
  const report = createDoctorReport({ cwd: resolveCliCwd(options.cwd) });
2582
- if (toBoolean(options.json, false)) logger$1.log(JSON.stringify(report, null, 2));
2583
- else logger$1.log(formatDoctorReport(report));
2576
+ if (toBoolean(options.json, false)) logger.log(JSON.stringify(report, null, 2));
2577
+ else logger.log(formatDoctorReport(report));
2584
2578
  if (hasDoctorFailure(report, toBoolean(options.strict, false))) process.exitCode = 1;
2585
2579
  }));
2586
2580
  cli.help();
2587
- cli.version(process.env.npm_package_version ?? "0.0.0");
2581
+ cli.version(process.env["npm_package_version"] ?? "0.0.0");
2588
2582
  cli.parse();
2589
2583
  //#endregion
2590
2584
  export {};