weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.30

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 (243) hide show
  1. package/README.md +6 -7
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/auto-TH1jG2UW.js +115 -0
  4. package/dist/auto-XyKTOP7B.mjs +78 -0
  5. package/dist/bundle-state-Bi-cQua6.mjs +413 -0
  6. package/dist/bundle-state-Ct_8GcSR.js +529 -0
  7. package/dist/bundlers/shared/cache.d.ts +6 -6
  8. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -0
  9. package/dist/bundlers/shared/css-cleanup.d.ts +1 -4
  10. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  11. package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
  12. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  13. package/dist/bundlers/shared/generator-css/directives.d.ts +20 -0
  14. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  15. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  16. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  17. package/dist/bundlers/shared/generator-css/markers.d.ts +28 -0
  18. package/dist/bundlers/shared/generator-css/source-files.d.ts +14 -0
  19. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +24 -0
  20. package/dist/bundlers/shared/generator-css.d.ts +16 -22
  21. package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
  22. package/dist/bundlers/shared/style-requests.d.ts +2 -0
  23. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  24. package/dist/bundlers/vite/css-finalizer.d.ts +7 -1
  25. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  26. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +24 -0
  27. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +4 -0
  28. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  29. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  30. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  31. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  32. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  33. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  34. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  35. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  36. package/dist/bundlers/vite/generate-bundle.d.ts +14 -2
  37. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +5 -1
  38. package/dist/bundlers/vite/index.d.ts +5 -2
  39. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  40. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  41. package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
  42. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -3
  43. package/dist/bundlers/vite/runtime-class-set.d.ts +25 -0
  44. package/dist/bundlers/vite/serve-css-generation.d.ts +11 -0
  45. package/dist/bundlers/vite/source-candidates.d.ts +19 -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 +2 -1
  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/{chunk-8l464Juk.js → chunk-C5U5_Hdc.js} +14 -0
  58. package/dist/cli/context.d.ts +1 -14
  59. package/dist/cli/doctor/types.d.ts +11 -11
  60. package/dist/cli/helpers.d.ts +1 -2
  61. package/dist/cli/mount-options.d.ts +2 -0
  62. package/dist/cli/types.d.ts +0 -2
  63. package/dist/cli/vscode-entry.d.ts +3 -3
  64. package/dist/cli.js +758 -604
  65. package/dist/cli.mjs +766 -612
  66. package/dist/constants.d.ts +1 -2
  67. package/dist/context/runtime-package-replacements.d.ts +2 -0
  68. package/dist/context/style-options.d.ts +3 -0
  69. package/dist/core.js +12 -20
  70. package/dist/core.mjs +8 -14
  71. package/dist/css-macro/auto.d.ts +10 -0
  72. package/dist/css-macro/constants.d.ts +5 -2
  73. package/dist/css-macro/postcss.d.ts +1 -0
  74. package/dist/css-macro/postcss.js +7 -46
  75. package/dist/css-macro/postcss.mjs +2 -46
  76. package/dist/css-macro.d.ts +1 -0
  77. package/dist/css-macro.js +16 -7
  78. package/dist/css-macro.mjs +15 -6
  79. package/dist/defaults-8xrgzxFY.mjs +151 -0
  80. package/dist/defaults-zKUH2mDe.js +193 -0
  81. package/dist/defaults.d.ts +15 -1
  82. package/dist/defaults.js +6 -131
  83. package/dist/defaults.mjs +2 -129
  84. package/dist/escape.js +10 -2
  85. package/dist/escape.mjs +10 -2
  86. package/dist/generator/index.d.ts +1 -1
  87. package/dist/generator/options.d.ts +9 -8
  88. package/dist/generator/types.d.ts +3 -3
  89. package/dist/generator-CrU-Ghc1.js +90 -0
  90. package/dist/generator-Qw-tZ0Z2.mjs +65 -0
  91. package/dist/generator.js +12 -12
  92. package/dist/generator.mjs +2 -1
  93. package/dist/gulp.js +187 -48
  94. package/dist/gulp.mjs +180 -41
  95. package/dist/incremental-runtime-class-set-BdZHkoTs.mjs +1975 -0
  96. package/dist/incremental-runtime-class-set-BxvZONkv.js +2038 -0
  97. package/dist/index.d.ts +3 -2
  98. package/dist/index.js +19 -7
  99. package/dist/index.mjs +6 -5
  100. package/dist/js/babel/cache-options.d.ts +3 -0
  101. package/dist/js/babel/parse.d.ts +7 -4
  102. package/dist/js/index.d.ts +1 -0
  103. package/dist/js/literal-transform.d.ts +2 -0
  104. package/dist/js/precheck.d.ts +2 -2
  105. package/dist/logger-BNzxZbZj.mjs +2 -0
  106. package/dist/logger-TlKT3xmR.js +1 -0
  107. package/dist/postcss/config-directive.d.ts +1 -0
  108. package/dist/postcss/context.d.ts +9 -0
  109. package/dist/postcss/source-files.d.ts +8 -0
  110. package/dist/postcss/tailwind-version.d.ts +3 -0
  111. package/dist/postcss-C6zOQqlL.mjs +228 -0
  112. package/dist/postcss-C7BMYpEF.mjs +169 -0
  113. package/dist/postcss-CiYLsqZn.js +192 -0
  114. package/dist/postcss-DAWf9D3C.js +237 -0
  115. package/dist/postcss-html-transform.js +1 -1
  116. package/dist/postcss.d.ts +2 -2
  117. package/dist/postcss.js +3 -276
  118. package/dist/postcss.mjs +1 -269
  119. package/dist/precheck-D7K12zeX.mjs +4716 -0
  120. package/dist/precheck-D7gJSmJz.js +4842 -0
  121. package/dist/presets/index.d.ts +1 -0
  122. package/dist/presets/uni-app-x.d.ts +1 -0
  123. package/dist/presets.js +29 -13
  124. package/dist/presets.mjs +25 -11
  125. package/dist/reset.d.ts +1 -0
  126. package/dist/reset.js +1 -1
  127. package/dist/runtime-registry-DpcR3IHI.js +5496 -0
  128. package/dist/shared/mpx.d.ts +1 -0
  129. package/dist/source-candidates-CX2ozpKM.mjs +322 -0
  130. package/dist/source-candidates-DNM8iwXW.js +335 -0
  131. package/dist/tailwindcss/miniprogram.d.ts +1 -1
  132. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  133. package/dist/tailwindcss/patcher.d.ts +1 -2
  134. package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
  135. package/dist/tailwindcss/runtime/cache.d.ts +4 -3
  136. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  137. package/dist/tailwindcss/runtime.d.ts +11 -12
  138. package/dist/tailwindcss/source-scan.d.ts +35 -0
  139. package/dist/tailwindcss/targets.d.ts +1 -5
  140. package/dist/tailwindcss/v3-engine/types.d.ts +17 -14
  141. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  142. package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
  143. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  144. package/dist/tailwindcss/v4/patcher.d.ts +1 -0
  145. package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
  146. package/dist/tailwindcss/v4-engine/types.d.ts +17 -5
  147. package/dist/tailwindcss/version.d.ts +4 -0
  148. package/dist/tailwindcss-B-e2RiXr.js +642 -0
  149. package/dist/tailwindcss-C7dJHZ0G.mjs +591 -0
  150. package/dist/typedoc.export.d.ts +0 -2
  151. package/dist/types/index.d.ts +52 -49
  152. package/dist/types/shared.d.ts +6 -0
  153. package/dist/types/user-defined-options/general.d.ts +25 -24
  154. package/dist/types/user-defined-options/important.d.ts +33 -28
  155. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  156. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  157. package/dist/uni-app-x/vite.d.ts +1 -1
  158. package/dist/unocss/index.d.ts +2 -0
  159. package/dist/utils/disabled.d.ts +2 -3
  160. package/dist/utils/object.d.ts +9 -0
  161. package/dist/utils/options.d.ts +2 -0
  162. package/dist/utils/regex.d.ts +1 -0
  163. package/dist/{utils-DmC9_In3.js → utils-D7Ygohep.js} +2 -2
  164. package/dist/{utils-7DUGTFED.mjs → utils-DsaS975I.mjs} +1 -1
  165. package/dist/v3-engine-CHItlVq5.js +3616 -0
  166. package/dist/v3-engine-DcvCCHfs.mjs +3321 -0
  167. package/dist/vite-C65DdWEj.js +24439 -0
  168. package/dist/vite-rmL1rsA_.mjs +24425 -0
  169. package/dist/vite.d.ts +1 -2
  170. package/dist/vite.js +3 -4
  171. package/dist/vite.mjs +2 -2
  172. package/dist/weapp-tw-css-import-rewrite-loader.js +5032 -18
  173. package/dist/weapp-tw-runtime-classset-loader.js +32 -9
  174. package/dist/webpack-BU2Er4qg.mjs +841 -0
  175. package/dist/webpack-CqGvjvSQ.js +851 -0
  176. package/dist/webpack.d.ts +1 -3
  177. package/dist/webpack.js +3 -4
  178. package/dist/webpack.mjs +2 -2
  179. package/package.json +38 -48
  180. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  181. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  182. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  183. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  184. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  185. package/dist/cli/config.d.ts +0 -5
  186. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  187. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  188. package/dist/cli/patch-options.d.ts +0 -6
  189. package/dist/cli/tokens.d.ts +0 -4
  190. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  191. package/dist/cli/workspace/patch-package.d.ts +0 -3
  192. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  193. package/dist/cli/workspace/types.d.ts +0 -11
  194. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  195. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  196. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  197. package/dist/cli/workspace.d.ts +0 -2
  198. package/dist/constants-B-_T5UnW.mjs +0 -44
  199. package/dist/constants-p1dyh1x1.js +0 -73
  200. package/dist/css-imports-BbrbluP9.js +0 -177
  201. package/dist/css-imports-CSdPq_Sc.mjs +0 -128
  202. package/dist/experimental/index.d.ts +0 -2
  203. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  204. package/dist/experimental/oxc/index.d.ts +0 -2
  205. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  206. package/dist/experimental/shared/cache.d.ts +0 -3
  207. package/dist/experimental/shared/transform.d.ts +0 -3
  208. package/dist/experimental/shared.d.ts +0 -8
  209. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  210. package/dist/experimental/swc/index.d.ts +0 -2
  211. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  212. package/dist/generator-Y-Ikv4Fu.mjs +0 -1177
  213. package/dist/generator-css-Bwy_Uz89.mjs +0 -1097
  214. package/dist/generator-css-CRLrHW4F.js +0 -1124
  215. package/dist/generator-mmhXzZnv.js +0 -1276
  216. package/dist/js/syntax.d.ts +0 -10
  217. package/dist/lightningcss/index.d.ts +0 -8
  218. package/dist/lightningcss/style-handler/options.d.ts +0 -3
  219. package/dist/lightningcss/style-handler/selector-transform.d.ts +0 -10
  220. package/dist/lightningcss/style-handler/selector-utils.d.ts +0 -10
  221. package/dist/lightningcss/style-handler.d.ts +0 -17
  222. package/dist/loader-anchors-1MumTAtA.mjs +0 -205
  223. package/dist/loader-anchors-TrFvT6g1.js +0 -273
  224. package/dist/logger-BZ45DZJT.js +0 -1003
  225. package/dist/logger-BoVx1Dbt.mjs +0 -935
  226. package/dist/patcher-options-6gJN2EXy.js +0 -115
  227. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  228. package/dist/recorder-GdTJ3QqX.js +0 -2878
  229. package/dist/recorder-XdFvVASS.mjs +0 -2763
  230. package/dist/tailwindcss/recorder.d.ts +0 -13
  231. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  232. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  233. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  234. package/dist/tailwindcss/targets/types.d.ts +0 -35
  235. package/dist/types/disabled-options.d.ts +0 -4
  236. package/dist/vite-BDywuCjn.mjs +0 -2186
  237. package/dist/vite-DgRh_GXn.js +0 -2199
  238. package/dist/webpack-CAJR4hhP.js +0 -456
  239. package/dist/webpack-CiHqVZTg.mjs +0 -441
  240. package/dist/webpack4.d.ts +0 -4
  241. package/dist/webpack4.js +0 -387
  242. package/dist/webpack4.mjs +0 -379
  243. package/scripts/postinstall.mjs +0 -59
package/dist/cli.mjs CHANGED
@@ -1,28 +1,31 @@
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";
17
- import { escapeStringRegexp } from "@weapp-core/regex";
20
+ import { parse } from "@babel/parser";
18
21
  import MagicString from "magic-string";
19
22
  import { jsStringEscape } from "@ast-core/escape";
20
23
  import { splitCode } from "@weapp-tailwindcss/shared/extractors";
21
24
  import "@babel/types";
22
- import "htmlparser2";
23
- import { getPackageInfoSync } from "local-pkg";
24
- import fg from "fast-glob";
25
- import { parse } from "yaml";
25
+ //#region src/js/babel/cache-options.ts
26
+ const DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH = 5e4;
27
+ const HARD_PARSE_CACHE_MAX_ENTRIES = 1024;
28
+ //#endregion
26
29
  //#region src/debug/index.ts
27
30
  const _debug = _createDebug("weapp-tw");
28
31
  function createDebug(prefix) {
@@ -38,236 +41,619 @@ function createDebug(prefix) {
38
41
  });
39
42
  return debug;
40
43
  }
41
- createDebug("[tailwindcss:runtime] ");
42
44
  //#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;
45
+ //#region src/css-macro/constants.ts
46
+ const queryKey = "weapp-tw-platform";
47
+ const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
48
+ const WHITESPACE_RE = /\s+/g;
49
+ const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
50
+ function normalComment(text) {
51
+ if (typeof text === "string") {
52
+ const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
53
+ if (normalized.includes("\\")) return normalized;
54
+ return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
55
+ }
56
+ return text;
57
+ }
58
+ function ifdef(text) {
59
+ return {
60
+ start: `#ifdef ${normalComment(text)}`,
61
+ end: `#endif`
62
+ };
59
63
  }
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
+ function ifndef(text) {
65
+ return {
66
+ start: `#ifndef ${normalComment(text)}`,
67
+ end: `#endif`
68
+ };
64
69
  }
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;
70
+ const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
71
+ function matchCustomPropertyFromValue(str, cb) {
72
+ let index = 0;
73
+ QUERY_KEY_REGEX.lastIndex = 0;
74
+ let arr = QUERY_KEY_REGEX.exec(str);
75
+ while (arr !== null) {
76
+ cb(arr, index);
77
+ index++;
78
+ arr = QUERY_KEY_REGEX.exec(str);
75
79
  }
76
80
  }
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
- }
81
+ function parseConditionalAtRuleParam(params) {
82
+ const value = params.trim();
83
+ const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
84
+ if (!quoted) return value;
85
+ return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
86
86
  }
87
87
  //#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);
88
+ //#region src/css-macro/postcss.ts
89
+ const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
90
+ const CONDITIONAL_COMMENT_SPACING = " ";
91
+ const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
92
+ const creator = () => {
110
93
  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
- ])];
127
- }
128
- //#endregion
129
- //#region package.json
130
- var version = "5.0.0-next.3";
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;
94
+ postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
95
+ prepare() {
96
+ function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
97
+ const hasPreviousNode = Boolean(atRule.prev());
98
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
99
+ const startComment = helper.comment({
100
+ raws: {
101
+ left: CONDITIONAL_COMMENT_SPACING,
102
+ right: CONDITIONAL_COMMENT_SPACING
103
+ },
104
+ text: comment.start
105
+ });
106
+ const endComment = helper.comment({
107
+ raws: {
108
+ left: CONDITIONAL_COMMENT_SPACING,
109
+ right: CONDITIONAL_COMMENT_SPACING
110
+ },
111
+ text: comment.end
112
+ });
113
+ const nextNodes = [
114
+ startComment,
115
+ ...clonedNodes,
116
+ endComment
117
+ ];
118
+ atRule.replaceWith(nextNodes);
119
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
120
+ startComment.raws["after"] = "\n";
121
+ if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
122
+ endComment.raws.before = "\n";
123
+ endComment.raws["after"] = "\n";
124
+ const nextNode = endComment?.next();
125
+ if (nextNode) nextNode.raws.before = "\n";
126
+ }
127
+ function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
128
+ if (atRule.parent?.type !== "rule") return false;
129
+ const parentRule = atRule.parent;
130
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
131
+ const conditionalRule = parentRule.clone();
132
+ conditionalRule.removeAll();
133
+ conditionalRule.append(...clonedNodes);
134
+ const startComment = helper.comment({
135
+ raws: {
136
+ left: CONDITIONAL_COMMENT_SPACING,
137
+ right: CONDITIONAL_COMMENT_SPACING
138
+ },
139
+ text: comment.start
140
+ });
141
+ const endComment = helper.comment({
142
+ raws: {
143
+ left: CONDITIONAL_COMMENT_SPACING,
144
+ right: CONDITIONAL_COMMENT_SPACING
145
+ },
146
+ text: comment.end
147
+ });
148
+ const nextNodes = [
149
+ startComment,
150
+ conditionalRule,
151
+ endComment
152
+ ];
153
+ const hasPreviousNode = Boolean(parentRule.prev());
154
+ atRule.remove();
155
+ if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
156
+ else parentRule.after(nextNodes);
157
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
158
+ startComment.raws["after"] = "\n";
159
+ conditionalRule.raws.before = "\n";
160
+ endComment.raws.before = "\n";
161
+ endComment.raws["after"] = "\n";
162
+ const nextNode = endComment.next();
163
+ if (nextNode) nextNode.raws.before = "\n";
164
+ return true;
158
165
  }
159
166
  return {
160
- baseDir: normalizedBase,
161
- path: recordPath,
162
- record: parsed
167
+ AtRule(atRule, helper) {
168
+ if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
169
+ const text = parseConditionalAtRuleParam(atRule.params);
170
+ const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
171
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
172
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
173
+ return;
174
+ }
175
+ if (atRule.name === "media") {
176
+ const values = [];
177
+ matchCustomPropertyFromValue(atRule.params, (arr) => {
178
+ const value = arr[1];
179
+ if (value) values.push(value);
180
+ });
181
+ if (values.length > 0) {
182
+ const isNegative = atRule.params.includes("not");
183
+ const text = values.join(" ");
184
+ const comment = isNegative ? ifndef(text) : ifdef(text);
185
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
186
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
187
+ }
188
+ }
189
+ },
190
+ CommentExit(comment) {
191
+ if (IFDEF_ENDIF_RE.test(comment.text)) {
192
+ comment.raws.left = CONDITIONAL_COMMENT_SPACING;
193
+ comment.raws.right = CONDITIONAL_COMMENT_SPACING;
194
+ }
195
+ }
163
196
  };
164
- } catch (error) {
165
- warnInvalidPatchTargetRecord(normalizedBase, recordPath, error instanceof Error ? error.message : String(error));
166
- continue;
167
197
  }
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
198
  };
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
- }
199
+ };
200
+ creator.postcss = true;
197
201
  //#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
- };
202
+ //#region src/tailwindcss/source-scan.ts
203
+ const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
204
+ "html",
205
+ "wxml",
206
+ "axml",
207
+ "jxml",
208
+ "ksml",
209
+ "ttml",
210
+ "qml",
211
+ "tyml",
212
+ "xhsml",
213
+ "swan",
214
+ "vue",
215
+ "mpx",
216
+ "js",
217
+ "jsx",
218
+ "ts",
219
+ "tsx"
220
+ ];
221
+ const FULL_SOURCE_SCAN_EXTENSIONS = [
222
+ "js",
223
+ "jsx",
224
+ "mjs",
225
+ "cjs",
226
+ "ts",
227
+ "tsx",
228
+ "mts",
229
+ "cts",
230
+ "vue",
231
+ "uvue",
232
+ "nvue",
233
+ "svelte",
234
+ "mpx",
235
+ "html",
236
+ "wxml",
237
+ "axml",
238
+ "jxml",
239
+ "ksml",
240
+ "ttml",
241
+ "qml",
242
+ "tyml",
243
+ "xhsml",
244
+ "swan",
245
+ "css",
246
+ "wxss",
247
+ "acss",
248
+ "jxss",
249
+ "ttss",
250
+ "qss",
251
+ "tyss",
252
+ "scss",
253
+ "sass",
254
+ "less",
255
+ "styl",
256
+ "stylus"
257
+ ];
258
+ function createSourceScanPattern(extensions = DEFAULT_SOURCE_SCAN_EXTENSIONS) {
259
+ return `**/*.{${extensions.join(",")}}`;
253
260
  }
261
+ createSourceScanPattern(FULL_SOURCE_SCAN_EXTENSIONS);
262
+ new RegExp(`\\.(?:${FULL_SOURCE_SCAN_EXTENSIONS.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`);
254
263
  //#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
- }
264
+ //#region src/utils/object.ts
265
+ function definedEntries(value) {
266
+ return Object.entries(value).filter(([, item]) => item !== void 0);
267
+ }
268
+ function omitUndefined(value) {
269
+ return Object.fromEntries(definedEntries(value));
270
+ }
271
+ createStyleHandler({
272
+ cssChildCombinatorReplaceValue: ["view", "text"],
273
+ cssRemoveHoverPseudoClass: true,
274
+ isMainChunk: true,
275
+ majorVersion: 4
276
+ });
277
+ //#endregion
278
+ //#region src/tailwindcss/v4-engine/tailwind-v3-default-colors.ts
279
+ const TAILWIND_V3_COLOR_STEPS = [
280
+ "50",
281
+ "100",
282
+ "200",
283
+ "300",
284
+ "400",
285
+ "500",
286
+ "600",
287
+ "700",
288
+ "800",
289
+ "900",
290
+ "950"
291
+ ];
292
+ const TAILWIND_V3_COLOR_PALETTE = {
293
+ slate: [
294
+ "#f8fafc",
295
+ "#f1f5f9",
296
+ "#e2e8f0",
297
+ "#cbd5e1",
298
+ "#94a3b8",
299
+ "#64748b",
300
+ "#475569",
301
+ "#334155",
302
+ "#1e293b",
303
+ "#0f172a",
304
+ "#020617"
305
+ ],
306
+ gray: [
307
+ "#f9fafb",
308
+ "#f3f4f6",
309
+ "#e5e7eb",
310
+ "#d1d5db",
311
+ "#9ca3af",
312
+ "#6b7280",
313
+ "#4b5563",
314
+ "#374151",
315
+ "#1f2937",
316
+ "#111827",
317
+ "#030712"
318
+ ],
319
+ zinc: [
320
+ "#fafafa",
321
+ "#f4f4f5",
322
+ "#e4e4e7",
323
+ "#d4d4d8",
324
+ "#a1a1aa",
325
+ "#71717a",
326
+ "#52525b",
327
+ "#3f3f46",
328
+ "#27272a",
329
+ "#18181b",
330
+ "#09090b"
331
+ ],
332
+ neutral: [
333
+ "#fafafa",
334
+ "#f5f5f5",
335
+ "#e5e5e5",
336
+ "#d4d4d4",
337
+ "#a3a3a3",
338
+ "#737373",
339
+ "#525252",
340
+ "#404040",
341
+ "#262626",
342
+ "#171717",
343
+ "#0a0a0a"
344
+ ],
345
+ stone: [
346
+ "#fafaf9",
347
+ "#f5f5f4",
348
+ "#e7e5e4",
349
+ "#d6d3d1",
350
+ "#a8a29e",
351
+ "#78716c",
352
+ "#57534e",
353
+ "#44403c",
354
+ "#292524",
355
+ "#1c1917",
356
+ "#0c0a09"
357
+ ],
358
+ red: [
359
+ "#fef2f2",
360
+ "#fee2e2",
361
+ "#fecaca",
362
+ "#fca5a5",
363
+ "#f87171",
364
+ "#ef4444",
365
+ "#dc2626",
366
+ "#b91c1c",
367
+ "#991b1b",
368
+ "#7f1d1d",
369
+ "#450a0a"
370
+ ],
371
+ orange: [
372
+ "#fff7ed",
373
+ "#ffedd5",
374
+ "#fed7aa",
375
+ "#fdba74",
376
+ "#fb923c",
377
+ "#f97316",
378
+ "#ea580c",
379
+ "#c2410c",
380
+ "#9a3412",
381
+ "#7c2d12",
382
+ "#431407"
383
+ ],
384
+ amber: [
385
+ "#fffbeb",
386
+ "#fef3c7",
387
+ "#fde68a",
388
+ "#fcd34d",
389
+ "#fbbf24",
390
+ "#f59e0b",
391
+ "#d97706",
392
+ "#b45309",
393
+ "#92400e",
394
+ "#78350f",
395
+ "#451a03"
396
+ ],
397
+ yellow: [
398
+ "#fefce8",
399
+ "#fef9c3",
400
+ "#fef08a",
401
+ "#fde047",
402
+ "#facc15",
403
+ "#eab308",
404
+ "#ca8a04",
405
+ "#a16207",
406
+ "#854d0e",
407
+ "#713f12",
408
+ "#422006"
409
+ ],
410
+ lime: [
411
+ "#f7fee7",
412
+ "#ecfccb",
413
+ "#d9f99d",
414
+ "#bef264",
415
+ "#a3e635",
416
+ "#84cc16",
417
+ "#65a30d",
418
+ "#4d7c0f",
419
+ "#3f6212",
420
+ "#365314",
421
+ "#1a2e05"
422
+ ],
423
+ green: [
424
+ "#f0fdf4",
425
+ "#dcfce7",
426
+ "#bbf7d0",
427
+ "#86efac",
428
+ "#4ade80",
429
+ "#22c55e",
430
+ "#16a34a",
431
+ "#15803d",
432
+ "#166534",
433
+ "#14532d",
434
+ "#052e16"
435
+ ],
436
+ emerald: [
437
+ "#ecfdf5",
438
+ "#d1fae5",
439
+ "#a7f3d0",
440
+ "#6ee7b7",
441
+ "#34d399",
442
+ "#10b981",
443
+ "#059669",
444
+ "#047857",
445
+ "#065f46",
446
+ "#064e3b",
447
+ "#022c22"
448
+ ],
449
+ teal: [
450
+ "#f0fdfa",
451
+ "#ccfbf1",
452
+ "#99f6e4",
453
+ "#5eead4",
454
+ "#2dd4bf",
455
+ "#14b8a6",
456
+ "#0d9488",
457
+ "#0f766e",
458
+ "#115e59",
459
+ "#134e4a",
460
+ "#042f2e"
461
+ ],
462
+ cyan: [
463
+ "#ecfeff",
464
+ "#cffafe",
465
+ "#a5f3fc",
466
+ "#67e8f9",
467
+ "#22d3ee",
468
+ "#06b6d4",
469
+ "#0891b2",
470
+ "#0e7490",
471
+ "#155e75",
472
+ "#164e63",
473
+ "#083344"
474
+ ],
475
+ sky: [
476
+ "#f0f9ff",
477
+ "#e0f2fe",
478
+ "#bae6fd",
479
+ "#7dd3fc",
480
+ "#38bdf8",
481
+ "#0ea5e9",
482
+ "#0284c7",
483
+ "#0369a1",
484
+ "#075985",
485
+ "#0c4a6e",
486
+ "#082f49"
487
+ ],
488
+ blue: [
489
+ "#eff6ff",
490
+ "#dbeafe",
491
+ "#bfdbfe",
492
+ "#93c5fd",
493
+ "#60a5fa",
494
+ "#3b82f6",
495
+ "#2563eb",
496
+ "#1d4ed8",
497
+ "#1e40af",
498
+ "#1e3a8a",
499
+ "#172554"
500
+ ],
501
+ indigo: [
502
+ "#eef2ff",
503
+ "#e0e7ff",
504
+ "#c7d2fe",
505
+ "#a5b4fc",
506
+ "#818cf8",
507
+ "#6366f1",
508
+ "#4f46e5",
509
+ "#4338ca",
510
+ "#3730a3",
511
+ "#312e81",
512
+ "#1e1b4b"
513
+ ],
514
+ violet: [
515
+ "#f5f3ff",
516
+ "#ede9fe",
517
+ "#ddd6fe",
518
+ "#c4b5fd",
519
+ "#a78bfa",
520
+ "#8b5cf6",
521
+ "#7c3aed",
522
+ "#6d28d9",
523
+ "#5b21b6",
524
+ "#4c1d95",
525
+ "#2e1065"
526
+ ],
527
+ purple: [
528
+ "#faf5ff",
529
+ "#f3e8ff",
530
+ "#e9d5ff",
531
+ "#d8b4fe",
532
+ "#c084fc",
533
+ "#a855f7",
534
+ "#9333ea",
535
+ "#7e22ce",
536
+ "#6b21a8",
537
+ "#581c87",
538
+ "#3b0764"
539
+ ],
540
+ fuchsia: [
541
+ "#fdf4ff",
542
+ "#fae8ff",
543
+ "#f5d0fe",
544
+ "#f0abfc",
545
+ "#e879f9",
546
+ "#d946ef",
547
+ "#c026d3",
548
+ "#a21caf",
549
+ "#86198f",
550
+ "#701a75",
551
+ "#4a044e"
552
+ ],
553
+ pink: [
554
+ "#fdf2f8",
555
+ "#fce7f3",
556
+ "#fbcfe8",
557
+ "#f9a8d4",
558
+ "#f472b6",
559
+ "#ec4899",
560
+ "#db2777",
561
+ "#be185d",
562
+ "#9d174d",
563
+ "#831843",
564
+ "#500724"
565
+ ],
566
+ rose: [
567
+ "#fff1f2",
568
+ "#ffe4e6",
569
+ "#fecdd3",
570
+ "#fda4af",
571
+ "#fb7185",
572
+ "#f43f5e",
573
+ "#e11d48",
574
+ "#be123c",
575
+ "#9f1239",
576
+ "#881337",
577
+ "#4c0519"
578
+ ]
579
+ };
580
+ function createTailwindV3DefaultColorThemeCss() {
581
+ const declarations = [" --color-black: #000;", " --color-white: #fff;"];
582
+ 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]};`);
583
+ return [
584
+ "@theme {",
585
+ ...declarations,
586
+ "}"
587
+ ].join("\n");
588
+ }
589
+ [
590
+ "@theme {",
591
+ " --default-ring-width: 3px;",
592
+ " --default-ring-color: var(--color-blue-500, #3b82f6);",
593
+ " --default-outline-width: 3px;",
594
+ "",
595
+ " --shadow-xs: 0 1px rgb(0 0 0 / 0.05);",
596
+ " --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);",
597
+ " --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);",
598
+ " --drop-shadow-xs: 0 1px 1px rgb(0 0 0 / 0.05);",
599
+ " --drop-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.15);",
600
+ " --drop-shadow: 0 1px 2px rgb(0 0 0 / 0.1), 0 1px 1px rgb(0 0 0 / 0.06);",
601
+ "",
602
+ " --blur-xs: 4px;",
603
+ " --blur-sm: 4px;",
604
+ " --blur: 8px;",
605
+ " --backdrop-blur-xs: 4px;",
606
+ " --backdrop-blur-sm: 4px;",
607
+ " --backdrop-blur: 8px;",
608
+ "",
609
+ " --radius-xs: 0.125rem;",
610
+ " --radius-sm: 0.125rem;",
611
+ " --radius: 0.25rem;",
612
+ "}",
613
+ createTailwindV3DefaultColorThemeCss()
614
+ ].join("\n");
615
+ [
616
+ "*,",
617
+ "::after,",
618
+ "::before,",
619
+ "::backdrop,",
620
+ "::file-selector-button {",
621
+ " border-color: var(--color-gray-200, currentcolor);",
622
+ "}",
623
+ "",
624
+ "input::placeholder,",
625
+ "textarea::placeholder {",
626
+ " opacity: 1;",
627
+ " color: var(--color-gray-400, currentcolor);",
628
+ "}",
629
+ "",
630
+ "button:not(:disabled),",
631
+ "[role=\"button\"]:not(:disabled) {",
632
+ " cursor: pointer;",
633
+ "}",
634
+ "",
635
+ "dialog {",
636
+ " margin: auto;",
637
+ "}"
638
+ ].join("\n");
639
+ createStyleHandler({
640
+ cssChildCombinatorReplaceValue: ["view", "text"],
641
+ cssRemoveHoverPseudoClass: true,
642
+ isMainChunk: true,
643
+ majorVersion: 3
644
+ });
645
+ [
646
+ "@tailwind base;",
647
+ "@tailwind components;",
648
+ "@tailwind utilities;"
649
+ ].join("\n");
650
+ createDebug("[tailwindcss:runtime-patch] ");
651
+ createRequire(import.meta.url);
652
+ createDebug("[tailwindcss:runtime] ");
653
+ //#endregion
654
+ //#region src/tailwindcss/runtime-logs.ts
655
+ const runtimeLogDedupeHolder = globalThis;
656
+ runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ = /* @__PURE__ */ new Set());
271
657
  //#endregion
272
658
  //#region src/context/compiler-context-cache.ts
273
659
  const globalCacheHolder = globalThis;
@@ -279,6 +665,12 @@ function _interopDefaultCompat(e) {
279
665
  }
280
666
  const traverse = _interopDefaultCompat(_babelTraverse);
281
667
  //#endregion
668
+ //#region src/utils/regex.ts
669
+ function escapeStringRegexp(str) {
670
+ if (typeof str !== "string") throw new TypeError("Expected a string");
671
+ return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&").replaceAll("-", "\\x2d");
672
+ }
673
+ //#endregion
282
674
  //#region src/utils/nameMatcher.ts
283
675
  const NEVER_MATCH_NAME$1 = () => false;
284
676
  const GLOBAL_FLAG_REGEXP = /g/g;
@@ -286,6 +678,7 @@ function buildFuzzyMatcher(fuzzyStrings) {
286
678
  if (fuzzyStrings.length === 0) return;
287
679
  if (fuzzyStrings.length === 1) {
288
680
  const [needle] = fuzzyStrings;
681
+ if (needle === void 0) return;
289
682
  return (value) => value.includes(needle);
290
683
  }
291
684
  const unique = [...new Set(fuzzyStrings)];
@@ -309,11 +702,13 @@ function createNameMatcher(list, { exact = false } = {}) {
309
702
  const exactStringCount = exactStrings?.size ?? 0;
310
703
  if (exactStringCount === 1 && regexList.length === 0) {
311
704
  const [needle] = exactStrings;
705
+ if (needle === void 0) return NEVER_MATCH_NAME$1;
312
706
  return (value) => value === needle;
313
707
  }
314
708
  if (regexList.length === 0) return (value) => exactStrings.has(value);
315
709
  if (exactStringCount === 0 && regexList.length === 1) {
316
710
  const [regex] = regexList;
711
+ if (!regex) return NEVER_MATCH_NAME$1;
317
712
  return (value) => regex.test(value);
318
713
  }
319
714
  return (value) => {
@@ -326,6 +721,7 @@ function createNameMatcher(list, { exact = false } = {}) {
326
721
  if (fuzzyMatcher && !hasRegex) return fuzzyMatcher;
327
722
  if (!fuzzyMatcher && regexList.length === 1) {
328
723
  const [regex] = regexList;
724
+ if (!regex) return NEVER_MATCH_NAME$1;
329
725
  return (value) => regex.test(value);
330
726
  }
331
727
  return (value) => {
@@ -336,20 +732,40 @@ function createNameMatcher(list, { exact = false } = {}) {
336
732
  }
337
733
  //#endregion
338
734
  //#region src/js/babel/parse.ts
339
- const parseCache = new LRUCache({ max: 1024 });
735
+ const parseCache = new LRUCache({ max: HARD_PARSE_CACHE_MAX_ENTRIES });
340
736
  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);
737
+ if (typeof options === "string") return `${md5Hash(source)}:${options}`;
738
+ return `${md5Hash(source)}:${JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val)}`;
739
+ }
740
+ function normalizeCacheMaxEntries(value) {
741
+ if (typeof value !== "number" || !Number.isFinite(value)) return 128;
742
+ return Math.min(Math.max(Math.floor(value), 0), HARD_PARSE_CACHE_MAX_ENTRIES);
743
+ }
744
+ function normalizeCacheMaxSourceLength(value) {
745
+ if (typeof value !== "number" || !Number.isFinite(value)) return DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH;
746
+ return Math.max(Math.floor(value), 0);
747
+ }
748
+ function trimParseCache(maxEntries) {
749
+ while (parseCache.size > maxEntries) parseCache.pop();
343
750
  }
344
751
  function babelParse(code, opts = {}) {
345
- const { cache, cacheKey, ...rest } = opts;
346
- const cacheKeyString = genCacheKey(code, cacheKey ?? rest);
752
+ const { cache, cacheKey, cacheMaxEntries, cacheMaxSourceLength, ...rest } = opts;
753
+ const maxEntries = normalizeCacheMaxEntries(cacheMaxEntries);
754
+ const maxSourceLength = normalizeCacheMaxSourceLength(cacheMaxSourceLength);
755
+ const shouldCache = cache === true && maxEntries > 0 && code.length <= maxSourceLength;
756
+ const cacheKeyString = shouldCache ? genCacheKey(code, cacheKey ?? rest) : void 0;
347
757
  let result;
348
- if (cache) result = parseCache.get(cacheKeyString);
758
+ if (shouldCache) {
759
+ trimParseCache(maxEntries);
760
+ result = parseCache.get(cacheKeyString);
761
+ }
349
762
  if (!result) {
350
- const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
351
- result = parse$1(code, parseOptions);
352
- if (cache) parseCache.set(cacheKeyString, result);
763
+ const { cache: _cache, cacheKey: _cacheKey, cacheMaxEntries: _cacheMaxEntries, cacheMaxSourceLength: _cacheMaxSourceLength, ...parseOptions } = opts;
764
+ result = parse(code, parseOptions);
765
+ if (shouldCache) {
766
+ parseCache.set(cacheKeyString, result);
767
+ trimParseCache(maxEntries);
768
+ }
353
769
  }
354
770
  return result;
355
771
  }
@@ -363,10 +779,10 @@ function replaceWxml(original, options = {
363
779
  const { keepEOL, escapeMap, ignoreHead } = options;
364
780
  let res = original;
365
781
  if (!keepEOL) res = res.replaceAll(NEWLINE_RE, "");
366
- res = escape(res, {
782
+ res = escape(res, omitUndefined({
367
783
  map: escapeMap,
368
784
  ignoreHead
369
- });
785
+ }));
370
786
  return res;
371
787
  }
372
788
  //#endregion
@@ -904,6 +1320,44 @@ function walkEvalExpression(path, options, updater, handler) {
904
1320
  }
905
1321
  }
906
1322
  //#endregion
1323
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
1324
+ function _typeof(o) {
1325
+ "@babel/helpers - typeof";
1326
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
1327
+ return typeof o;
1328
+ } : function(o) {
1329
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1330
+ }, _typeof(o);
1331
+ }
1332
+ //#endregion
1333
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
1334
+ function toPrimitive(t, r) {
1335
+ if ("object" != _typeof(t) || !t) return t;
1336
+ var e = t[Symbol.toPrimitive];
1337
+ if (void 0 !== e) {
1338
+ var i = e.call(t, r || "default");
1339
+ if ("object" != _typeof(i)) return i;
1340
+ throw new TypeError("@@toPrimitive must return a primitive value.");
1341
+ }
1342
+ return ("string" === r ? String : Number)(t);
1343
+ }
1344
+ //#endregion
1345
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
1346
+ function toPropertyKey(t) {
1347
+ var i = toPrimitive(t, "string");
1348
+ return "symbol" == _typeof(i) ? i : i + "";
1349
+ }
1350
+ //#endregion
1351
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
1352
+ function _defineProperty(e, r, t) {
1353
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1354
+ value: t,
1355
+ enumerable: !0,
1356
+ configurable: !0,
1357
+ writable: !0
1358
+ }) : e[r] = t, e;
1359
+ }
1360
+ //#endregion
907
1361
  //#region src/js/JsTokenUpdater.ts
908
1362
  /**
909
1363
  * Lightweight helper that batches updates to {@link MagicString}.
@@ -912,6 +1366,7 @@ function walkEvalExpression(path, options, updater, handler) {
912
1366
  */
913
1367
  var JsTokenUpdater = class {
914
1368
  constructor({ value } = {}) {
1369
+ _defineProperty(this, "tokens", void 0);
915
1370
  this.tokens = value ? [...value] : [];
916
1371
  }
917
1372
  addToken(token) {
@@ -945,7 +1400,7 @@ var JsTokenUpdater = class {
945
1400
  var IgnoredExportsTracker = class {
946
1401
  constructor(options) {
947
1402
  this.options = options;
948
- this.ignoredExportNames = /* @__PURE__ */ new Map();
1403
+ _defineProperty(this, "ignoredExportNames", /* @__PURE__ */ new Map());
949
1404
  }
950
1405
  addIgnoredExport(filename, exportName) {
951
1406
  if (!exportName) return;
@@ -1064,8 +1519,16 @@ var IgnoredExportsTracker = class {
1064
1519
  //#region src/js/ModuleGraph.ts
1065
1520
  var JsModuleGraph = class {
1066
1521
  constructor(entry, graphOptions) {
1067
- this.modules = /* @__PURE__ */ new Map();
1068
- this.queue = [];
1522
+ _defineProperty(this, "modules", /* @__PURE__ */ new Map());
1523
+ _defineProperty(this, "queue", []);
1524
+ _defineProperty(this, "resolve", void 0);
1525
+ _defineProperty(this, "load", void 0);
1526
+ _defineProperty(this, "filter", void 0);
1527
+ _defineProperty(this, "maxDepth", void 0);
1528
+ _defineProperty(this, "baseOptions", void 0);
1529
+ _defineProperty(this, "parserOptions", void 0);
1530
+ _defineProperty(this, "rootFilename", void 0);
1531
+ _defineProperty(this, "ignoredExports", void 0);
1069
1532
  this.resolve = graphOptions.resolve;
1070
1533
  this.load = graphOptions.load;
1071
1534
  this.filter = graphOptions.filter;
@@ -1237,6 +1700,12 @@ const NEVER_MATCH_NAME = () => false;
1237
1700
  */
1238
1701
  var NodePathWalker = class {
1239
1702
  constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
1703
+ _defineProperty(this, "ignoreCallExpressionIdentifiers", void 0);
1704
+ _defineProperty(this, "callback", void 0);
1705
+ _defineProperty(this, "isIgnoredCallIdentifier", void 0);
1706
+ _defineProperty(this, "hasIgnoredCallIdentifiers", void 0);
1707
+ _defineProperty(this, "importsStore", void 0);
1708
+ _defineProperty(this, "visitedStore", void 0);
1240
1709
  this.hasIgnoredCallIdentifiers = Boolean(ignoreCallExpressionIdentifiers && ignoreCallExpressionIdentifiers.length > 0);
1241
1710
  this.ignoreCallExpressionIdentifiers = ignoreCallExpressionIdentifiers ?? EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS;
1242
1711
  this.callback = callback ?? NOOP_STRING_PATH_CALLBACK;
@@ -1499,7 +1968,7 @@ function analyzeSource(ast, options, handler, collectModuleMetadata = true) {
1499
1968
  const needScope = Boolean(options.ignoreCallExpressionIdentifiers && options.ignoreCallExpressionIdentifiers.length > 0);
1500
1969
  const ignoredPaths = needScope ? /* @__PURE__ */ new WeakSet() : EMPTY_IGNORED_PATHS;
1501
1970
  const walker = needScope ? new NodePathWalker({
1502
- ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
1971
+ ...options.ignoreCallExpressionIdentifiers === void 0 ? {} : { ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers },
1503
1972
  callback(path) {
1504
1973
  ignoredPaths.add(path);
1505
1974
  }
@@ -1509,7 +1978,7 @@ function analyzeSource(ast, options, handler, collectModuleMetadata = true) {
1509
1978
  function getTaggedTemplateIgnore() {
1510
1979
  if (!taggedTemplateIgnore) taggedTemplateIgnore = createTaggedTemplateIgnore({
1511
1980
  matcher: getIgnoredTaggedTemplateMatcher(options),
1512
- names: options.ignoreTaggedTemplateExpressionIdentifiers
1981
+ ...options.ignoreTaggedTemplateExpressionIdentifiers === void 0 ? {} : { names: options.ignoreTaggedTemplateExpressionIdentifiers }
1513
1982
  });
1514
1983
  return taggedTemplateIgnore;
1515
1984
  }
@@ -1598,9 +2067,8 @@ function jsHandler(rawSource, options) {
1598
2067
  if (shouldWrapExpression) {
1599
2068
  const start = 0;
1600
2069
  const end = source.length;
1601
- const prefixLength = 2;
1602
2070
  const suffixLength = 2;
1603
- ms.remove(start, start + prefixLength);
2071
+ ms.remove(start, 2);
1604
2072
  ms.remove(end - suffixLength, end);
1605
2073
  }
1606
2074
  const result = { code: ms.toString() };
@@ -1644,6 +2112,13 @@ function isWhitespace(char) {
1644
2112
  //#region src/wxml/Tokenizer.ts
1645
2113
  var Tokenizer = class {
1646
2114
  constructor() {
2115
+ _defineProperty(this, "state", void 0);
2116
+ _defineProperty(this, "buffer", void 0);
2117
+ _defineProperty(this, "tokens", void 0);
2118
+ _defineProperty(this, "bufferStartIndex", void 0);
2119
+ _defineProperty(this, "expressionStartIndex", void 0);
2120
+ _defineProperty(this, "expressionBuffer", void 0);
2121
+ _defineProperty(this, "expressions", void 0);
1647
2122
  this.reset();
1648
2123
  }
1649
2124
  processChar(char, index) {
@@ -1734,6 +2209,7 @@ var Tokenizer = class {
1734
2209
  this.reset();
1735
2210
  for (let i = 0; i < input.length; i++) {
1736
2211
  const char = input[i];
2212
+ if (char === void 0) continue;
1737
2213
  this.processChar(char, i);
1738
2214
  }
1739
2215
  if (this.buffer.length > 0) this.tokens.push({
@@ -1758,35 +2234,8 @@ var Tokenizer = class {
1758
2234
  };
1759
2235
  new Tokenizer();
1760
2236
  //#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
- }
2237
+ //#region src/constants.ts
2238
+ const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
1790
2239
  //#endregion
1791
2240
  //#region src/cli/context.ts
1792
2241
  function formatOutputPath(target, baseDir) {
@@ -1831,7 +2280,7 @@ const FRAMEWORK_DEPS = [
1831
2280
  ];
1832
2281
  //#endregion
1833
2282
  //#region src/cli/doctor.ts
1834
- function tryReadJson$1(file) {
2283
+ function tryReadJson(file) {
1835
2284
  try {
1836
2285
  return JSON.parse(readFileSync(file, "utf8"));
1837
2286
  } catch {
@@ -1842,11 +2291,11 @@ function findFirstExisting(cwd, files) {
1842
2291
  return files.find((file) => existsSync(path.join(cwd, file)));
1843
2292
  }
1844
2293
  function readProjectPackageJson(cwd) {
1845
- return tryReadJson$1(path.join(cwd, "package.json"));
2294
+ return tryReadJson(path.join(cwd, "package.json"));
1846
2295
  }
1847
2296
  function readDependencyVersion(cwd, packageName) {
1848
2297
  try {
1849
- return tryReadJson$1(createRequire(path.join(cwd, "package.json")).resolve(`${packageName}/package.json`))?.version;
2298
+ return tryReadJson(createRequire(path.join(cwd, "package.json")).resolve(`${packageName}/package.json`))?.version;
1850
2299
  } catch {
1851
2300
  return;
1852
2301
  }
@@ -2089,52 +2538,15 @@ function resolveCliCwd(value) {
2089
2538
  return path.isAbsolute(raw) ? path.normalize(raw) : path.resolve(process.cwd(), raw);
2090
2539
  }
2091
2540
  //#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
2541
  //#region src/cli/helpers.ts
2130
2542
  async function ensureDir(dir) {
2131
2543
  await mkdir(dir, { recursive: true });
2132
2544
  }
2133
2545
  function handleCliError$1(error) {
2134
2546
  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));
2547
+ logger.error(error.message);
2548
+ if (error.stack && process.env["WEAPP_TW_DEBUG"] === "1") logger.error(error.stack);
2549
+ } else logger.error(String(error));
2138
2550
  }
2139
2551
  function commandAction(handler) {
2140
2552
  return async (...args) => {
@@ -2147,217 +2559,16 @@ function commandAction(handler) {
2147
2559
  };
2148
2560
  }
2149
2561
  //#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
2562
  //#region src/cli/mount-options.ts
2563
+ const PATCH_COMMAND_OBSOLETE_NOTICE = "提示:weapp-tailwindcss@5 已由构建运行时接管 Tailwind CSS 处理,weapp-tw patch 已无需执行;请移除 package.json 中的 postinstall 钩子。";
2564
+ function logPatchCommandObsoleteNotice() {
2565
+ logger.warn(PATCH_COMMAND_OBSOLETE_NOTICE);
2566
+ }
2356
2567
  function handleCliError(error) {
2357
2568
  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));
2569
+ logger.error(error.message);
2570
+ if (error.stack && process.env["WEAPP_TW_DEBUG"] === "1") logger.error(error.stack);
2571
+ } else logger.error(String(error));
2361
2572
  }
2362
2573
  function withCommandErrorHandling(handler) {
2363
2574
  return (async (ctx, next) => {
@@ -2370,92 +2581,18 @@ function withCommandErrorHandling(handler) {
2370
2581
  }
2371
2582
  });
2372
2583
  }
2373
- async function createPatcherWithDefaultExtendLengthUnits(ctx) {
2374
- const extendLengthUnitsOverride = buildExtendLengthUnitsOverride(await ctx.loadPatchOptions());
2375
- if (extendLengthUnitsOverride) return ctx.createPatcher(extendLengthUnitsOverride);
2376
- return ctx.createPatcher();
2377
- }
2584
+ const forwardedCommands = [
2585
+ "extract",
2586
+ "tokens",
2587
+ "init",
2588
+ "migrate",
2589
+ "restore",
2590
+ "validate"
2591
+ ];
2592
+ const commandHandlers = Object.fromEntries(forwardedCommands.map((command) => [command, withCommandErrorHandling(async (_ctx, next) => next())]));
2378
2593
  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
- }
2594
+ commands: [...forwardedCommands],
2595
+ commandHandlers
2459
2596
  };
2460
2597
  //#endregion
2461
2598
  //#region src/cli/vscode-entry.ts
@@ -2558,11 +2695,28 @@ async function generateVscodeIntellisenseEntry(options) {
2558
2695
  //#endregion
2559
2696
  //#region src/cli.ts
2560
2697
  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.`);
2698
+ 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
2699
  const cli = createTailwindcssPatchCli({
2563
2700
  name: "weapp-tailwindcss",
2564
2701
  mountOptions
2565
2702
  });
2703
+ 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) => {
2704
+ logPatchCommandObsoleteNotice();
2705
+ logger.success("已跳过:当前版本不需要手动执行 Tailwind CSS patch。");
2706
+ }));
2707
+ 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) => {
2708
+ const payload = {
2709
+ required: false,
2710
+ status: "unnecessary",
2711
+ message: PATCH_COMMAND_OBSOLETE_NOTICE
2712
+ };
2713
+ if (toBoolean(options.json, false)) {
2714
+ logger.log(JSON.stringify(payload, null, 2));
2715
+ return;
2716
+ }
2717
+ logPatchCommandObsoleteNotice();
2718
+ logger.success("无需检查 Tailwind CSS patch 状态。");
2719
+ }));
2566
2720
  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
2721
  const resolvedCwd = resolveCliCwd(options.cwd);
2568
2722
  const baseDir = resolvedCwd ?? process.cwd();
@@ -2575,16 +2729,16 @@ cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliS
2575
2729
  sources: readStringArrayOption("source", options.source),
2576
2730
  force: toBoolean(options.force, false)
2577
2731
  });
2578
- logger$1.success(`VS Code helper generated -> ${formatOutputPath(result.outputPath, resolvedCwd)}`);
2732
+ logger.success(`VS Code helper generated -> ${formatOutputPath(result.outputPath, resolvedCwd)}`);
2579
2733
  }));
2580
2734
  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
2735
  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));
2736
+ if (toBoolean(options.json, false)) logger.log(JSON.stringify(report, null, 2));
2737
+ else logger.log(formatDoctorReport(report));
2584
2738
  if (hasDoctorFailure(report, toBoolean(options.strict, false))) process.exitCode = 1;
2585
2739
  }));
2586
2740
  cli.help();
2587
- cli.version(process.env.npm_package_version ?? "0.0.0");
2741
+ cli.version(process.env["npm_package_version"] ?? "0.0.0");
2588
2742
  cli.parse();
2589
2743
  //#endregion
2590
2744
  export {};