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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +4 -5
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
  4. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
  5. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
  6. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
  7. package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
  8. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  9. package/dist/bundlers/shared/generator-css/directives.d.ts +11 -0
  10. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  11. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  12. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  13. package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
  14. package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
  15. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
  16. package/dist/bundlers/shared/generator-css.d.ts +12 -22
  17. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  18. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  19. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
  20. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
  21. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  22. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  23. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  24. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  25. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  26. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  27. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  28. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  29. package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
  30. package/dist/bundlers/vite/index.d.ts +1 -1
  31. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  32. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  33. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  34. package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
  35. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  36. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
  37. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -1
  38. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +0 -1
  39. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
  40. package/dist/cache-DPN5yKSX.js +497 -0
  41. package/dist/cache-nq0_XJoS.mjs +429 -0
  42. package/dist/cli/context.d.ts +0 -3
  43. package/dist/cli/helpers.d.ts +1 -2
  44. package/dist/cli/mount-options.d.ts +2 -0
  45. package/dist/cli/types.d.ts +0 -2
  46. package/dist/cli.js +108 -598
  47. package/dist/cli.mjs +119 -608
  48. package/dist/constants.d.ts +1 -2
  49. package/dist/context/tailwindcss.d.ts +1 -1
  50. package/dist/core.js +13 -20
  51. package/dist/core.mjs +8 -14
  52. package/dist/css-macro/postcss.js +1 -1
  53. package/dist/css-macro/postcss.mjs +1 -1
  54. package/dist/css-macro.d.ts +1 -0
  55. package/dist/css-macro.js +2 -2
  56. package/dist/css-macro.mjs +2 -2
  57. package/dist/defaults.d.ts +15 -1
  58. package/dist/defaults.js +33 -14
  59. package/dist/defaults.mjs +30 -15
  60. package/dist/generator/index.d.ts +1 -1
  61. package/dist/generator/options.d.ts +3 -4
  62. package/dist/{generator-Y-Ikv4Fu.mjs → generator-CzfdCZyd.mjs} +277 -23
  63. package/dist/{generator-mmhXzZnv.js → generator-TOp4uz7c.js} +281 -27
  64. package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-B938WI9a.mjs} +694 -506
  65. package/dist/{generator-css-CRLrHW4F.js → generator-css-Dnpl-IY2.js} +699 -505
  66. package/dist/generator.js +1 -1
  67. package/dist/generator.mjs +1 -1
  68. package/dist/gulp.js +29 -28
  69. package/dist/gulp.mjs +25 -24
  70. package/dist/index.d.ts +1 -1
  71. package/dist/index.js +6 -6
  72. package/dist/index.mjs +5 -5
  73. package/dist/js/index.d.ts +1 -0
  74. package/dist/js/literal-transform.d.ts +2 -0
  75. package/dist/logger-BRy6XPQ2.js +1 -0
  76. package/dist/logger-Bub1jggA.mjs +2 -0
  77. package/dist/postcss/config-directive.d.ts +1 -0
  78. package/dist/postcss/context.d.ts +9 -0
  79. package/dist/postcss/source-files.d.ts +8 -0
  80. package/dist/postcss/tailwind-version.d.ts +3 -0
  81. package/dist/postcss-BtAP6sQO.mjs +288 -0
  82. package/dist/postcss-WsXlC7A-.js +298 -0
  83. package/dist/postcss.d.ts +2 -2
  84. package/dist/postcss.js +3 -276
  85. package/dist/postcss.mjs +1 -269
  86. package/dist/{recorder-GdTJ3QqX.js → precheck-Dka94ArV.js} +141 -283
  87. package/dist/{recorder-XdFvVASS.mjs → precheck-DlrmwCc-.mjs} +106 -247
  88. package/dist/presets.js +6 -4
  89. package/dist/presets.mjs +4 -2
  90. package/dist/reset.d.ts +1 -0
  91. package/dist/{css-imports-BbrbluP9.js → run-tasks-B50A3pxt.js} +6 -55
  92. package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DdNi-hkk.mjs} +5 -42
  93. package/dist/runtime-patch-pGdCqAEu.mjs +71 -0
  94. package/dist/runtime-patch-qwuisukL.js +85 -0
  95. package/dist/tailwindcss/miniprogram.d.ts +5 -1
  96. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  97. package/dist/tailwindcss/patcher.d.ts +1 -2
  98. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  99. package/dist/tailwindcss/runtime.d.ts +2 -3
  100. package/dist/tailwindcss/targets.d.ts +1 -5
  101. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  102. package/dist/tailwindcss/v4/patcher.d.ts +2 -1
  103. package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
  104. package/dist/tailwindcss/version.d.ts +4 -0
  105. package/dist/{logger-BoVx1Dbt.mjs → tailwindcss-BIJ185GB.mjs} +25 -434
  106. package/dist/{logger-BZ45DZJT.js → tailwindcss-T1U5T-iF.js} +30 -468
  107. package/dist/typedoc.export.d.ts +0 -2
  108. package/dist/types/index.d.ts +2 -9
  109. package/dist/types/shared.d.ts +3 -0
  110. package/dist/types/user-defined-options/general.d.ts +0 -2
  111. package/dist/types/user-defined-options/important.d.ts +3 -3
  112. package/dist/uni-app-x/vite.d.ts +1 -1
  113. package/dist/utils/disabled.d.ts +2 -3
  114. package/dist/{vite-BDywuCjn.mjs → vite-BXChkciE.mjs} +669 -481
  115. package/dist/{vite-DgRh_GXn.js → vite-D0CoRblu.js} +707 -519
  116. package/dist/vite.d.ts +1 -2
  117. package/dist/vite.js +3 -4
  118. package/dist/vite.mjs +2 -2
  119. package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
  120. package/dist/{webpack-CiHqVZTg.mjs → webpack-BNdGm9KL.mjs} +224 -38
  121. package/dist/{webpack-CAJR4hhP.js → webpack-D-sUCY0u.js} +250 -69
  122. package/dist/webpack.js +1 -1
  123. package/dist/webpack.mjs +1 -1
  124. package/package.json +23 -35
  125. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  126. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  127. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  128. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  129. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  130. package/dist/cli/config.d.ts +0 -5
  131. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  132. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  133. package/dist/cli/patch-options.d.ts +0 -6
  134. package/dist/cli/tokens.d.ts +0 -4
  135. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  136. package/dist/cli/workspace/patch-package.d.ts +0 -3
  137. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  138. package/dist/cli/workspace/types.d.ts +0 -11
  139. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  140. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  141. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  142. package/dist/cli/workspace.d.ts +0 -2
  143. package/dist/experimental/index.d.ts +0 -2
  144. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  145. package/dist/experimental/oxc/index.d.ts +0 -2
  146. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  147. package/dist/experimental/shared/cache.d.ts +0 -3
  148. package/dist/experimental/shared/transform.d.ts +0 -3
  149. package/dist/experimental/shared.d.ts +0 -8
  150. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  151. package/dist/experimental/swc/index.d.ts +0 -2
  152. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  153. package/dist/js/syntax.d.ts +0 -10
  154. package/dist/loader-anchors-1MumTAtA.mjs +0 -205
  155. package/dist/loader-anchors-TrFvT6g1.js +0 -273
  156. package/dist/patcher-options-6gJN2EXy.js +0 -115
  157. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  158. package/dist/tailwindcss/recorder.d.ts +0 -13
  159. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  160. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  161. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  162. package/dist/tailwindcss/targets/types.d.ts +0 -35
  163. package/dist/types/disabled-options.d.ts +0 -4
  164. package/dist/webpack4.d.ts +0 -4
  165. package/dist/webpack4.js +0 -387
  166. package/dist/webpack4.mjs +0 -379
  167. package/scripts/postinstall.mjs +0 -59
  168. /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
  169. /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
  170. /package/dist/{utils-7DUGTFED.mjs → utils-BJjKRQgf.mjs} +0 -0
  171. /package/dist/{utils-DmC9_In3.js → utils-VZvGusYs.js} +0 -0
package/dist/cli.mjs CHANGED
@@ -1,28 +1,25 @@
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
- import { md5 as md5Hash } from "@weapp-tailwindcss/shared/node";
9
+ import "@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
14
  import "@weapp-tailwindcss/postcss";
15
15
  import _babelTraverse from "@babel/traverse";
16
- import { parse as parse$1 } from "@babel/parser";
16
+ import { parse } from "@babel/parser";
17
17
  import { escapeStringRegexp } from "@weapp-core/regex";
18
18
  import MagicString from "magic-string";
19
19
  import { jsStringEscape } from "@ast-core/escape";
20
20
  import { splitCode } from "@weapp-tailwindcss/shared/extractors";
21
21
  import "@babel/types";
22
22
  import "htmlparser2";
23
- import { getPackageInfoSync } from "local-pkg";
24
- import fg from "fast-glob";
25
- import { parse } from "yaml";
26
23
  //#region src/debug/index.ts
27
24
  const _debug = _createDebug("weapp-tw");
28
25
  function createDebug(prefix) {
@@ -38,241 +35,21 @@ function createDebug(prefix) {
38
35
  });
39
36
  return debug;
40
37
  }
38
+ createDebug("[tailwindcss:runtime-patch] ");
39
+ createRequire(import.meta.url);
41
40
  createDebug("[tailwindcss:runtime] ");
42
41
  //#endregion
43
42
  //#region src/tailwindcss/runtime-logs.ts
44
43
  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
- //#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
- ])];
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;
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
- }
197
- //#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
- }
254
- //#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
- }
44
+ runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ = /* @__PURE__ */ new Set());
271
45
  //#endregion
272
46
  //#region src/context/compiler-context-cache.ts
273
47
  const globalCacheHolder = globalThis;
274
48
  globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
275
49
  //#endregion
50
+ //#region src/constants.ts
51
+ const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
52
+ //#endregion
276
53
  //#region src/babel/index.ts
277
54
  function _interopDefaultCompat(e) {
278
55
  return e && typeof e === "object" && "default" in e ? e.default : e;
@@ -348,7 +125,7 @@ function babelParse(code, opts = {}) {
348
125
  if (cache) result = parseCache.get(cacheKeyString);
349
126
  if (!result) {
350
127
  const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
351
- result = parse$1(code, parseOptions);
128
+ result = parse(code, parseOptions);
352
129
  if (cache) parseCache.set(cacheKeyString, result);
353
130
  }
354
131
  return result;
@@ -904,6 +681,44 @@ function walkEvalExpression(path, options, updater, handler) {
904
681
  }
905
682
  }
906
683
  //#endregion
684
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
685
+ function _typeof(o) {
686
+ "@babel/helpers - typeof";
687
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
688
+ return typeof o;
689
+ } : function(o) {
690
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
691
+ }, _typeof(o);
692
+ }
693
+ //#endregion
694
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
695
+ function toPrimitive(t, r) {
696
+ if ("object" != _typeof(t) || !t) return t;
697
+ var e = t[Symbol.toPrimitive];
698
+ if (void 0 !== e) {
699
+ var i = e.call(t, r || "default");
700
+ if ("object" != _typeof(i)) return i;
701
+ throw new TypeError("@@toPrimitive must return a primitive value.");
702
+ }
703
+ return ("string" === r ? String : Number)(t);
704
+ }
705
+ //#endregion
706
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
707
+ function toPropertyKey(t) {
708
+ var i = toPrimitive(t, "string");
709
+ return "symbol" == _typeof(i) ? i : i + "";
710
+ }
711
+ //#endregion
712
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
713
+ function _defineProperty(e, r, t) {
714
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
715
+ value: t,
716
+ enumerable: !0,
717
+ configurable: !0,
718
+ writable: !0
719
+ }) : e[r] = t, e;
720
+ }
721
+ //#endregion
907
722
  //#region src/js/JsTokenUpdater.ts
908
723
  /**
909
724
  * Lightweight helper that batches updates to {@link MagicString}.
@@ -912,6 +727,7 @@ function walkEvalExpression(path, options, updater, handler) {
912
727
  */
913
728
  var JsTokenUpdater = class {
914
729
  constructor({ value } = {}) {
730
+ _defineProperty(this, "tokens", void 0);
915
731
  this.tokens = value ? [...value] : [];
916
732
  }
917
733
  addToken(token) {
@@ -945,7 +761,7 @@ var JsTokenUpdater = class {
945
761
  var IgnoredExportsTracker = class {
946
762
  constructor(options) {
947
763
  this.options = options;
948
- this.ignoredExportNames = /* @__PURE__ */ new Map();
764
+ _defineProperty(this, "ignoredExportNames", /* @__PURE__ */ new Map());
949
765
  }
950
766
  addIgnoredExport(filename, exportName) {
951
767
  if (!exportName) return;
@@ -1064,8 +880,16 @@ var IgnoredExportsTracker = class {
1064
880
  //#region src/js/ModuleGraph.ts
1065
881
  var JsModuleGraph = class {
1066
882
  constructor(entry, graphOptions) {
1067
- this.modules = /* @__PURE__ */ new Map();
1068
- this.queue = [];
883
+ _defineProperty(this, "modules", /* @__PURE__ */ new Map());
884
+ _defineProperty(this, "queue", []);
885
+ _defineProperty(this, "resolve", void 0);
886
+ _defineProperty(this, "load", void 0);
887
+ _defineProperty(this, "filter", void 0);
888
+ _defineProperty(this, "maxDepth", void 0);
889
+ _defineProperty(this, "baseOptions", void 0);
890
+ _defineProperty(this, "parserOptions", void 0);
891
+ _defineProperty(this, "rootFilename", void 0);
892
+ _defineProperty(this, "ignoredExports", void 0);
1069
893
  this.resolve = graphOptions.resolve;
1070
894
  this.load = graphOptions.load;
1071
895
  this.filter = graphOptions.filter;
@@ -1237,6 +1061,12 @@ const NEVER_MATCH_NAME = () => false;
1237
1061
  */
1238
1062
  var NodePathWalker = class {
1239
1063
  constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
1064
+ _defineProperty(this, "ignoreCallExpressionIdentifiers", void 0);
1065
+ _defineProperty(this, "callback", void 0);
1066
+ _defineProperty(this, "isIgnoredCallIdentifier", void 0);
1067
+ _defineProperty(this, "hasIgnoredCallIdentifiers", void 0);
1068
+ _defineProperty(this, "importsStore", void 0);
1069
+ _defineProperty(this, "visitedStore", void 0);
1240
1070
  this.hasIgnoredCallIdentifiers = Boolean(ignoreCallExpressionIdentifiers && ignoreCallExpressionIdentifiers.length > 0);
1241
1071
  this.ignoreCallExpressionIdentifiers = ignoreCallExpressionIdentifiers ?? EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS;
1242
1072
  this.callback = callback ?? NOOP_STRING_PATH_CALLBACK;
@@ -1644,6 +1474,13 @@ function isWhitespace(char) {
1644
1474
  //#region src/wxml/Tokenizer.ts
1645
1475
  var Tokenizer = class {
1646
1476
  constructor() {
1477
+ _defineProperty(this, "state", void 0);
1478
+ _defineProperty(this, "buffer", void 0);
1479
+ _defineProperty(this, "tokens", void 0);
1480
+ _defineProperty(this, "bufferStartIndex", void 0);
1481
+ _defineProperty(this, "expressionStartIndex", void 0);
1482
+ _defineProperty(this, "expressionBuffer", void 0);
1483
+ _defineProperty(this, "expressions", void 0);
1647
1484
  this.reset();
1648
1485
  }
1649
1486
  processChar(char, index) {
@@ -1758,36 +1595,6 @@ var Tokenizer = class {
1758
1595
  };
1759
1596
  new Tokenizer();
1760
1597
  //#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
1598
  //#region src/cli/context.ts
1792
1599
  function formatOutputPath(target, baseDir) {
1793
1600
  const root = baseDir ?? process.cwd();
@@ -1831,7 +1638,7 @@ const FRAMEWORK_DEPS = [
1831
1638
  ];
1832
1639
  //#endregion
1833
1640
  //#region src/cli/doctor.ts
1834
- function tryReadJson$1(file) {
1641
+ function tryReadJson(file) {
1835
1642
  try {
1836
1643
  return JSON.parse(readFileSync(file, "utf8"));
1837
1644
  } catch {
@@ -1842,11 +1649,11 @@ function findFirstExisting(cwd, files) {
1842
1649
  return files.find((file) => existsSync(path.join(cwd, file)));
1843
1650
  }
1844
1651
  function readProjectPackageJson(cwd) {
1845
- return tryReadJson$1(path.join(cwd, "package.json"));
1652
+ return tryReadJson(path.join(cwd, "package.json"));
1846
1653
  }
1847
1654
  function readDependencyVersion(cwd, packageName) {
1848
1655
  try {
1849
- return tryReadJson$1(createRequire(path.join(cwd, "package.json")).resolve(`${packageName}/package.json`))?.version;
1656
+ return tryReadJson(createRequire(path.join(cwd, "package.json")).resolve(`${packageName}/package.json`))?.version;
1850
1657
  } catch {
1851
1658
  return;
1852
1659
  }
@@ -2089,52 +1896,15 @@ function resolveCliCwd(value) {
2089
1896
  return path.isAbsolute(raw) ? path.normalize(raw) : path.resolve(process.cwd(), raw);
2090
1897
  }
2091
1898
  //#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
1899
  //#region src/cli/helpers.ts
2130
1900
  async function ensureDir(dir) {
2131
1901
  await mkdir(dir, { recursive: true });
2132
1902
  }
2133
1903
  function handleCliError$1(error) {
2134
1904
  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));
1905
+ logger.error(error.message);
1906
+ if (error.stack && process.env.WEAPP_TW_DEBUG === "1") logger.error(error.stack);
1907
+ } else logger.error(String(error));
2138
1908
  }
2139
1909
  function commandAction(handler) {
2140
1910
  return async (...args) => {
@@ -2147,217 +1917,16 @@ function commandAction(handler) {
2147
1917
  };
2148
1918
  }
2149
1919
  //#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
1920
  //#region src/cli/mount-options.ts
1921
+ const PATCH_COMMAND_OBSOLETE_NOTICE = "提示:weapp-tailwindcss@5 已由构建运行时接管 Tailwind CSS 处理,weapp-tw patch 已无需执行;请移除 package.json 中的 postinstall 钩子。";
1922
+ function logPatchCommandObsoleteNotice() {
1923
+ logger.warn(PATCH_COMMAND_OBSOLETE_NOTICE);
1924
+ }
2356
1925
  function handleCliError(error) {
2357
1926
  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));
1927
+ logger.error(error.message);
1928
+ if (error.stack && process.env.WEAPP_TW_DEBUG === "1") logger.error(error.stack);
1929
+ } else logger.error(String(error));
2361
1930
  }
2362
1931
  function withCommandErrorHandling(handler) {
2363
1932
  return (async (ctx, next) => {
@@ -2370,92 +1939,17 @@ function withCommandErrorHandling(handler) {
2370
1939
  }
2371
1940
  });
2372
1941
  }
2373
- async function createPatcherWithDefaultExtendLengthUnits(ctx) {
2374
- const extendLengthUnitsOverride = buildExtendLengthUnitsOverride(await ctx.loadPatchOptions());
2375
- if (extendLengthUnitsOverride) return ctx.createPatcher(extendLengthUnitsOverride);
2376
- return ctx.createPatcher();
2377
- }
1942
+ const forwardedCommands = [
1943
+ "extract",
1944
+ "tokens",
1945
+ "init",
1946
+ "migrate",
1947
+ "restore",
1948
+ "validate"
1949
+ ];
2378
1950
  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
- }
1951
+ commands: [...forwardedCommands],
1952
+ commandHandlers: Object.fromEntries(forwardedCommands.map((command) => [command, withCommandErrorHandling(async (_ctx, next) => next())]))
2459
1953
  };
2460
1954
  //#endregion
2461
1955
  //#region src/cli/vscode-entry.ts
@@ -2558,11 +2052,28 @@ async function generateVscodeIntellisenseEntry(options) {
2558
2052
  //#endregion
2559
2053
  //#region src/cli.ts
2560
2054
  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.`);
2055
+ 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
2056
  const cli = createTailwindcssPatchCli({
2563
2057
  name: "weapp-tailwindcss",
2564
2058
  mountOptions
2565
2059
  });
2060
+ 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) => {
2061
+ logPatchCommandObsoleteNotice();
2062
+ logger.success("已跳过:当前版本不需要手动执行 Tailwind CSS patch。");
2063
+ }));
2064
+ 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) => {
2065
+ const payload = {
2066
+ required: false,
2067
+ status: "unnecessary",
2068
+ message: PATCH_COMMAND_OBSOLETE_NOTICE
2069
+ };
2070
+ if (toBoolean(options.json, false)) {
2071
+ logger.log(JSON.stringify(payload, null, 2));
2072
+ return;
2073
+ }
2074
+ logPatchCommandObsoleteNotice();
2075
+ logger.success("无需检查 Tailwind CSS patch 状态。");
2076
+ }));
2566
2077
  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
2078
  const resolvedCwd = resolveCliCwd(options.cwd);
2568
2079
  const baseDir = resolvedCwd ?? process.cwd();
@@ -2575,12 +2086,12 @@ cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliS
2575
2086
  sources: readStringArrayOption("source", options.source),
2576
2087
  force: toBoolean(options.force, false)
2577
2088
  });
2578
- logger$1.success(`VS Code helper generated -> ${formatOutputPath(result.outputPath, resolvedCwd)}`);
2089
+ logger.success(`VS Code helper generated -> ${formatOutputPath(result.outputPath, resolvedCwd)}`);
2579
2090
  }));
2580
2091
  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
2092
  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));
2093
+ if (toBoolean(options.json, false)) logger.log(JSON.stringify(report, null, 2));
2094
+ else logger.log(formatDoctorReport(report));
2584
2095
  if (hasDoctorFailure(report, toBoolean(options.strict, false))) process.exitCode = 1;
2585
2096
  }));
2586
2097
  cli.help();