weapp-tailwindcss 5.0.0-next.5 → 5.0.0-next.8

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 (131) hide show
  1. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
  2. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
  3. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
  4. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
  5. package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
  6. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  7. package/dist/bundlers/shared/generator-css/directives.d.ts +12 -0
  8. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  9. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  10. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  11. package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
  12. package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
  13. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
  14. package/dist/bundlers/shared/generator-css.d.ts +10 -23
  15. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  16. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  17. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
  18. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
  19. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  20. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  21. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  22. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  23. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  24. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  25. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  26. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  27. package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
  28. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  29. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  30. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  31. package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
  32. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  33. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
  34. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -1
  35. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
  36. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
  37. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -0
  38. package/dist/cache-BVAiJV3J.js +502 -0
  39. package/dist/cache-CHs4DXui.mjs +434 -0
  40. package/dist/cli/helpers.d.ts +1 -2
  41. package/dist/cli/mount-options.d.ts +2 -2
  42. package/dist/cli/types.d.ts +0 -2
  43. package/dist/cli.js +107 -603
  44. package/dist/cli.mjs +118 -613
  45. package/dist/constants.d.ts +0 -1
  46. package/dist/context/tailwindcss.d.ts +1 -1
  47. package/dist/core.js +13 -20
  48. package/dist/core.mjs +8 -14
  49. package/dist/css-macro/postcss.js +1 -1
  50. package/dist/css-macro/postcss.mjs +1 -1
  51. package/dist/css-macro.js +2 -2
  52. package/dist/css-macro.mjs +2 -2
  53. package/dist/defaults.d.ts +15 -1
  54. package/dist/defaults.js +28 -7
  55. package/dist/defaults.mjs +25 -8
  56. package/dist/{generator-9UEp8OoQ.js → generator-DKkhJbOg.js} +24 -7
  57. package/dist/{generator-Dpp-5s8z.mjs → generator-UBmfduYg.mjs} +20 -3
  58. package/dist/{generator-css-MyjZhF0z.mjs → generator-css-BIapP56i.mjs} +691 -606
  59. package/dist/{generator-css-CGueCYbX.js → generator-css-Mksw8PgB.js} +703 -606
  60. package/dist/generator.js +1 -1
  61. package/dist/generator.mjs +1 -1
  62. package/dist/gulp.js +33 -21
  63. package/dist/gulp.mjs +29 -17
  64. package/dist/index.js +5 -5
  65. package/dist/index.mjs +4 -4
  66. package/dist/logger-BRy6XPQ2.js +1 -0
  67. package/dist/logger-Bub1jggA.mjs +2 -0
  68. package/dist/postcss/config-directive.d.ts +1 -0
  69. package/dist/postcss/context.d.ts +9 -0
  70. package/dist/postcss/source-files.d.ts +8 -0
  71. package/dist/postcss/tailwind-version.d.ts +3 -0
  72. package/dist/postcss-QIXwT40c.js +298 -0
  73. package/dist/postcss-w48mGIhe.mjs +288 -0
  74. package/dist/postcss.js +3 -285
  75. package/dist/postcss.mjs +1 -278
  76. package/dist/{recorder-D4BKt75Q.js → precheck-B32p-gLI.js} +139 -274
  77. package/dist/{recorder-BIW3Kuke.mjs → precheck-B4RH6ZNN.mjs} +105 -239
  78. package/dist/presets.js +6 -4
  79. package/dist/presets.mjs +4 -2
  80. package/dist/runtime-patch-CwN5ya72.mjs +71 -0
  81. package/dist/runtime-patch-D6mBo_KB.js +85 -0
  82. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  83. package/dist/tailwindcss/runtime.d.ts +2 -3
  84. package/dist/tailwindcss/targets.d.ts +1 -5
  85. package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
  86. package/dist/tailwindcss/v4/patcher.d.ts +1 -1
  87. package/dist/{logger-D9clu_3f.js → tailwindcss-Bu-RWIHx.js} +70 -413
  88. package/dist/{logger-1gx9UllH.mjs → tailwindcss-C5IgPlQ0.mjs} +56 -382
  89. package/dist/types/index.d.ts +1 -6
  90. package/dist/uni-app-x/vite.d.ts +1 -1
  91. package/dist/{vite-fDM-UQpR.mjs → vite-BwgRVgxH.mjs} +677 -525
  92. package/dist/{vite-BkMGwDeH.js → vite-DyZuiyap.js} +704 -552
  93. package/dist/vite.js +1 -1
  94. package/dist/vite.mjs +1 -1
  95. package/dist/weapp-tw-css-import-rewrite-loader.js +10 -1
  96. package/dist/{webpack-CICGEKT9.js → webpack-CNV2dx3Q.js} +72 -37
  97. package/dist/{webpack-D2Wdk28V.mjs → webpack-CT6EEENx.mjs} +58 -23
  98. package/dist/webpack.js +1 -1
  99. package/dist/webpack.mjs +1 -1
  100. package/package.json +6 -9
  101. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  102. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  103. package/dist/cli/config.d.ts +0 -5
  104. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  105. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  106. package/dist/cli/patch-options.d.ts +0 -6
  107. package/dist/cli/tokens.d.ts +0 -4
  108. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  109. package/dist/cli/workspace/patch-package.d.ts +0 -3
  110. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  111. package/dist/cli/workspace/types.d.ts +0 -11
  112. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  113. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  114. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  115. package/dist/cli/workspace.d.ts +0 -2
  116. package/dist/js/syntax.d.ts +0 -10
  117. package/dist/patcher-options-DnqazL9E.js +0 -34
  118. package/dist/patcher-options-GuOwX0-k.mjs +0 -17
  119. package/dist/tailwindcss/recorder.d.ts +0 -13
  120. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  121. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  122. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  123. package/dist/tailwindcss/targets/types.d.ts +0 -35
  124. package/dist/version-CWBxRFPB.js +0 -56
  125. package/dist/version-WNz3MwRv.mjs +0 -49
  126. /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
  127. /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
  128. /package/dist/{run-tasks-Cq5A5nVD.js → run-tasks-B50A3pxt.js} +0 -0
  129. /package/dist/{run-tasks-DUVrDJGl.mjs → run-tasks-DdNi-hkk.mjs} +0 -0
  130. /package/dist/{utils-DmC9_In3.js → utils-BiShvil9.js} +0 -0
  131. /package/dist/{utils-7DUGTFED.mjs → utils-Btw1iOVV.mjs} +0 -0
@@ -1,184 +1,66 @@
1
1
  const require_chunk = require("./chunk-8l464Juk.js");
2
- const require_patcher_options = require("./patcher-options-DnqazL9E.js");
3
- require("./utils-DmC9_In3.js");
4
- const require_version = require("./version-CWBxRFPB.js");
2
+ const require_cache = require("./cache-BVAiJV3J.js");
3
+ require("./utils-BiShvil9.js");
5
4
  let node_module = require("node:module");
6
5
  let node_path = require("node:path");
7
6
  node_path = require_chunk.__toESM(node_path);
8
7
  let node_process = require("node:process");
9
8
  node_process = require_chunk.__toESM(node_process);
10
- let tailwindcss_patch = require("tailwindcss-patch");
11
- let node_fs = require("node:fs");
12
9
  let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
13
- let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
10
+ let node_fs = require("node:fs");
14
11
  let node_url = require("node:url");
15
- //#region src/tailwindcss/runtime/cache.ts
16
- const runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
17
- const runtimeFileSignatureCache = /* @__PURE__ */ new Map();
18
- let runtimeFileSignatureCacheClearTimer;
19
- const runtimeSignaturePatchersSymbol = Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
20
- function getCacheEntry(twPatcher) {
21
- let entry = runtimeClassSetCache.get(twPatcher);
22
- if (!entry) {
23
- entry = {};
24
- runtimeClassSetCache.set(twPatcher, entry);
25
- }
26
- return entry;
27
- }
28
- function scheduleRuntimeConfigSignatureCacheClear() {
29
- if (runtimeFileSignatureCacheClearTimer) return;
30
- runtimeFileSignatureCacheClearTimer = setTimeout(() => {
31
- runtimeFileSignatureCache.clear();
32
- runtimeFileSignatureCacheClearTimer = void 0;
33
- }, 0);
34
- runtimeFileSignatureCacheClearTimer.unref?.();
35
- }
36
- function getFileSignature(filePath) {
37
- const cached = runtimeFileSignatureCache.get(filePath);
38
- if (cached !== void 0) return cached;
39
- let signature;
40
- try {
41
- const stats = (0, node_fs.statSync)(filePath);
42
- signature = `${filePath}:${stats.size}:${stats.mtimeMs}`;
43
- } catch {
44
- signature = `${filePath}:missing`;
45
- }
46
- runtimeFileSignatureCache.set(filePath, signature);
47
- scheduleRuntimeConfigSignatureCacheClear();
48
- return signature;
49
- }
50
- function getTailwindTrackedFiles(twPatcher) {
51
- const tailwindOptions = require_patcher_options.resolveTailwindcssOptions(twPatcher.options);
52
- const tracked = /* @__PURE__ */ new Set();
53
- const configPath = tailwindOptions?.config;
54
- if (typeof configPath === "string" && configPath.length > 0) tracked.add(configPath);
55
- for (const entry of tailwindOptions?.v4?.cssEntries ?? []) if (typeof entry === "string" && entry.length > 0) tracked.add(entry);
56
- return tracked;
57
- }
58
- function normalizeSignatureValue(value) {
59
- if (value == null) return "null";
60
- if (typeof value === "string") return value;
61
- if (typeof value === "number" || typeof value === "boolean") return String(value);
62
- if (Array.isArray(value)) return `[${value.map((item) => normalizeSignatureValue(item)).join(",")}]`;
63
- if (typeof value === "object") return `{${Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => `${key}:${normalizeSignatureValue(item)}`).join(",")}}`;
64
- return String(value);
65
- }
66
- function readOptionalProperty(value, key) {
67
- if (typeof value !== "object" || value === null || !(key in value)) return;
68
- return value[key];
69
- }
70
- function getTailwindOptionsSignature(twPatcher) {
71
- const options = twPatcher.options;
72
- const tailwindOptions = require_patcher_options.resolveTailwindcssOptions(options);
73
- return normalizeSignatureValue({
74
- projectRoot: options?.projectRoot,
75
- packageName: tailwindOptions?.packageName,
76
- versionHint: readOptionalProperty(tailwindOptions, "versionHint"),
77
- cwd: tailwindOptions?.cwd,
78
- config: tailwindOptions?.config,
79
- v2: tailwindOptions?.v2,
80
- v3: tailwindOptions?.v3,
81
- v4: {
82
- base: tailwindOptions?.v4?.base,
83
- configuredBase: readOptionalProperty(tailwindOptions?.v4, "configuredBase"),
84
- css: tailwindOptions?.v4?.css,
85
- cssEntries: tailwindOptions?.v4?.cssEntries,
86
- hasUserDefinedSources: readOptionalProperty(tailwindOptions?.v4, "hasUserDefinedSources"),
87
- sources: tailwindOptions?.v4?.sources
88
- }
12
+ let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
13
+ //#region src/tailwindcss/v4/css-sources.ts
14
+ function hasCssEntriesValue(value) {
15
+ if (typeof value === "string") return value.trim().length > 0;
16
+ return Array.isArray(value) && value.some((entry) => typeof entry === "string" && entry.trim().length > 0);
17
+ }
18
+ function hasCssSourcesValue(value) {
19
+ return Array.isArray(value) && value.some((source) => {
20
+ return typeof source === "object" && source !== null && typeof source.css === "string" && source.css.trim().length > 0;
89
21
  });
90
22
  }
91
- function getPatchTargetSignature(twPatcher) {
92
- const packageInfo = twPatcher.packageInfo;
93
- return [
94
- packageInfo?.name ?? "missing",
95
- packageInfo?.rootPath ?? "missing",
96
- packageInfo?.version ?? "unknown",
97
- twPatcher.majorVersion ?? "unknown",
98
- getTailwindOptionsSignature(twPatcher)
99
- ].join(":");
100
- }
101
- function getNestedPatchers(twPatcher) {
102
- const nested = twPatcher[runtimeSignaturePatchersSymbol];
103
- return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
104
- }
105
- function getOwnRuntimeClassSetSignature(twPatcher) {
106
- const trackedFiles = [...getTailwindTrackedFiles(twPatcher)].sort((a, b) => a.localeCompare(b)).map(getFileSignature);
107
- return `${trackedFiles.length > 0 ? trackedFiles.join("|") : "files:missing"}|patch:${getPatchTargetSignature(twPatcher)}`;
108
- }
109
- function invalidateRuntimeClassSet(twPatcher) {
110
- if (!twPatcher) return;
111
- const nestedPatchers = getNestedPatchers(twPatcher);
112
- if (nestedPatchers) for (const patcher of nestedPatchers) invalidateRuntimeClassSet(patcher);
113
- for (const trackedFile of getTailwindTrackedFiles(twPatcher)) runtimeFileSignatureCache.delete(trackedFile);
114
- runtimeClassSetCache.delete(twPatcher);
115
- }
116
- function getRuntimeClassSetCacheEntry(twPatcher) {
117
- return getCacheEntry(twPatcher);
118
- }
119
- function getRuntimeClassSetSignature(twPatcher) {
120
- const nestedPatchers = getNestedPatchers(twPatcher);
121
- if (nestedPatchers) return nestedPatchers.map(getOwnRuntimeClassSetSignature).sort((a, b) => a.localeCompare(b)).join("||");
122
- return getOwnRuntimeClassSetSignature(twPatcher);
23
+ function hasConfiguredTailwindV4CssRoots(options) {
24
+ return hasCssEntriesValue(options.cssEntries) || hasCssEntriesValue(options.tailwindcss?.v4?.cssEntries) || hasCssEntriesValue(options.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssEntries) || hasCssSourcesValue(options.tailwindcss?.v4?.cssSources) || hasCssSourcesValue(options.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssSources);
123
25
  }
124
- //#endregion
125
- //#region src/context/workspace.ts
126
- const IGNORED_WORKSPACE_DIRS = new Set([
127
- "node_modules",
128
- ".git",
129
- ".hg",
130
- ".svn",
131
- ".turbo",
132
- ".output",
133
- ".next",
134
- "dist",
135
- "build"
136
- ]);
137
- function findWorkspaceRoot(startDir) {
138
- if (!startDir) return;
139
- let current = node_path.default.resolve(startDir);
140
- while (true) {
141
- if ((0, node_fs.existsSync)(node_path.default.join(current, "pnpm-workspace.yaml"))) return current;
142
- const parent = node_path.default.dirname(current);
143
- if (parent === current) return;
144
- current = parent;
145
- }
26
+ function normalizeCssSourceFile(file) {
27
+ if (!file) return;
28
+ return node_path.default.isAbsolute(file) ? node_path.default.normalize(file) : file;
146
29
  }
147
- function findNearestPackageRoot(startDir) {
148
- if (!startDir) return;
149
- let current = node_path.default.resolve(startDir);
150
- while (true) {
151
- if ((0, node_fs.existsSync)(node_path.default.join(current, "package.json"))) return current;
152
- const parent = node_path.default.dirname(current);
153
- if (parent === current) return;
154
- current = parent;
155
- }
30
+ function normalizeDependencies(dependencies) {
31
+ return dependencies?.map(normalizeCssSourceFile).filter((dependency) => typeof dependency === "string" && dependency.length > 0);
156
32
  }
157
- function findWorkspacePackageDir(rootDir, packageName) {
158
- const visited = /* @__PURE__ */ new Set();
159
- const queue = [node_path.default.resolve(rootDir)];
160
- while (queue.length > 0) {
161
- const current = queue.shift();
162
- const normalized = node_path.default.normalize(current);
163
- if (visited.has(normalized)) continue;
164
- visited.add(normalized);
165
- try {
166
- const pkgPath = node_path.default.join(normalized, "package.json");
167
- if ((0, node_fs.existsSync)(pkgPath)) {
168
- if (JSON.parse((0, node_fs.readFileSync)(pkgPath, "utf8"))?.name === packageName) return normalized;
169
- }
170
- } catch {}
171
- let entries;
172
- try {
173
- entries = (0, node_fs.readdirSync)(normalized, { withFileTypes: true });
174
- } catch {
175
- continue;
176
- }
177
- for (const entry of entries) {
178
- if (!entry.isDirectory() || IGNORED_WORKSPACE_DIRS.has(entry.name) || entry.isSymbolicLink?.()) continue;
179
- queue.push(node_path.default.join(normalized, entry.name));
33
+ function isSameCssSource(a, b) {
34
+ return a.css === b.css && a.base === b.base && normalizeCssSourceFile(a.file) === normalizeCssSourceFile(b.file) && JSON.stringify(normalizeDependencies(a.dependencies)) === JSON.stringify(normalizeDependencies(b.dependencies));
35
+ }
36
+ function upsertTailwindV4CssSource(opts, source) {
37
+ const normalizedSource = {
38
+ ...source,
39
+ ...source.file === void 0 ? {} : { file: normalizeCssSourceFile(source.file) },
40
+ ...source.dependencies === void 0 ? {} : { dependencies: normalizeDependencies(source.dependencies) }
41
+ };
42
+ const tailwindcss = opts.tailwindcss ?? {};
43
+ const v4 = tailwindcss.v4 ?? {};
44
+ const cssSources = [...v4.cssSources ?? []];
45
+ const sourceFile = normalizeCssSourceFile(normalizedSource.file);
46
+ const existingIndex = cssSources.findIndex((candidate) => normalizeCssSourceFile(candidate.file) === sourceFile);
47
+ if (existingIndex >= 0) {
48
+ const existing = cssSources[existingIndex];
49
+ const nextSource = {
50
+ ...existing,
51
+ ...normalizedSource
52
+ };
53
+ if (isSameCssSource(existing, nextSource)) return false;
54
+ cssSources[existingIndex] = nextSource;
55
+ } else cssSources.push(normalizedSource);
56
+ opts.tailwindcss = {
57
+ ...tailwindcss,
58
+ v4: {
59
+ ...v4,
60
+ cssSources
180
61
  }
181
- }
62
+ };
63
+ return true;
182
64
  }
183
65
  //#endregion
184
66
  //#region src/tailwindcss/v4/config.ts
@@ -242,7 +124,7 @@ let hasWarnedMissingCssEntries = false;
242
124
  function warnMissingCssEntries(ctx, patcher) {
243
125
  if (hasWarnedMissingCssEntries) return;
244
126
  if (patcher?.majorVersion !== 4) return;
245
- if (hasConfiguredCssEntries(ctx)) return;
127
+ if (hasConfiguredCssEntries(ctx) || hasConfiguredTailwindV4CssRoots(ctx)) return;
246
128
  hasWarnedMissingCssEntries = true;
247
129
  _weapp_tailwindcss_logger.logger.warn("[tailwindcss@4] 未检测到 cssEntries 配置。请传入包含 tailwindcss 引用的 CSS 绝对路径,例如 cssEntries: [\"/absolute/path/to/src/app.css\"],否则 tailwindcss 生成的类名不会参与转译。");
248
130
  }
@@ -252,224 +134,17 @@ function applyV4CssCalcDefaults(cssCalc, patcher) {
252
134
  return cssCalcOptions;
253
135
  }
254
136
  //#endregion
255
- //#region src/tailwindcss/patcher-resolve.ts
256
- const GENERIC_RELATIVE_SPECIFIERS = [".", ".."];
257
- const DEFAULT_TAILWIND_CONFIG_SPECIFIERS = ["stubs/config.full.js", "defaultConfig.js"];
258
- const TAILWIND_CONFIG_FILES = [
259
- "tailwind.config.js",
260
- "tailwind.config.cjs",
261
- "tailwind.config.mjs",
262
- "tailwind.config.ts",
263
- "tailwind.config.cts",
264
- "tailwind.config.mts"
265
- ];
266
- function isPathSpecifier(specifier) {
267
- if (!specifier) return false;
268
- if (specifier.startsWith("file://")) return true;
269
- if (node_path.default.isAbsolute(specifier)) return true;
270
- return GENERIC_RELATIVE_SPECIFIERS.some((prefix) => specifier.startsWith(`${prefix}/`) || specifier.startsWith(`${prefix}\\`));
271
- }
272
- function resolveModuleFromPaths(specifier, paths) {
273
- if (!specifier || isPathSpecifier(specifier) || paths.length === 0) return;
274
- try {
275
- return (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href).resolve(specifier, { paths });
276
- } catch {
277
- return;
278
- }
279
- }
280
- function resolveTailwindConfigFallback(packageName, paths) {
281
- if (!packageName) return;
282
- for (const suffix of DEFAULT_TAILWIND_CONFIG_SPECIFIERS) {
283
- const resolved = resolveModuleFromPaths(`${packageName}/${suffix}`, paths);
284
- if (resolved) return resolved;
285
- }
286
- }
287
- function appendNodeModules(paths, dir) {
288
- if (!dir) return;
289
- const nodeModulesDir = node_path.default.join(dir, "node_modules");
290
- if ((0, node_fs.existsSync)(nodeModulesDir)) paths.add(nodeModulesDir);
291
- }
292
- function findTailwindConfig(searchRoots) {
293
- for (const root of searchRoots) for (const file of TAILWIND_CONFIG_FILES) {
294
- const candidate = node_path.default.resolve(root, file);
295
- if ((0, node_fs.existsSync)(candidate)) return candidate;
296
- }
297
- }
298
- function createDefaultResolvePaths(basedir) {
299
- const paths = /* @__PURE__ */ new Set();
300
- let fallbackCandidates = [];
301
- if (basedir) {
302
- const resolvedBase = node_path.default.resolve(basedir);
303
- appendNodeModules(paths, resolvedBase);
304
- fallbackCandidates.push(resolvedBase);
305
- const packageRoot = findNearestPackageRoot(resolvedBase);
306
- if (packageRoot) {
307
- appendNodeModules(paths, packageRoot);
308
- fallbackCandidates.push(packageRoot);
309
- }
310
- }
311
- const cwd = node_process.default.cwd();
312
- appendNodeModules(paths, cwd);
313
- try {
314
- const modulePath = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
315
- const candidate = (0, node_fs.existsSync)(modulePath) && !node_path.default.extname(modulePath) ? modulePath : node_path.default.dirname(modulePath);
316
- paths.add(candidate);
317
- } catch {
318
- paths.add(require("url").pathToFileURL(__filename).href);
319
- }
320
- if (paths.size === 0) {
321
- fallbackCandidates = fallbackCandidates.filter(Boolean);
322
- if (fallbackCandidates.length === 0) fallbackCandidates.push(cwd);
323
- for (const candidate of fallbackCandidates) paths.add(candidate);
324
- }
325
- return [...paths];
326
- }
327
- //#endregion
328
- //#region src/tailwindcss/patcher.ts
329
- function createFallbackTailwindcssPatcher() {
330
- return {
331
- packageInfo: {
332
- name: "tailwindcss",
333
- version: void 0,
334
- rootPath: "",
335
- packageJsonPath: "",
336
- packageJson: {}
337
- },
338
- majorVersion: 4,
339
- async patch() {
340
- return {
341
- exposeContext: void 0,
342
- extendLengthUnits: void 0
343
- };
344
- },
345
- async getClassSet() {
346
- return /* @__PURE__ */ new Set();
347
- },
348
- async extract(_options) {
349
- return {
350
- classList: [],
351
- classSet: /* @__PURE__ */ new Set()
352
- };
353
- },
354
- async collectContentTokens() {
355
- return {
356
- entries: [],
357
- filesScanned: 0,
358
- sources: [],
359
- skippedFiles: []
360
- };
361
- }
362
- };
363
- }
364
- let hasLoggedMissingTailwind = false;
365
- const TAILWINDCSS_NOT_FOUND_RE = /tailwindcss not found/i;
366
- const UNABLE_TO_LOCATE_TAILWINDCSS_RE = /unable to locate tailwind css package/i;
367
- function isTailwindcssV4PackageName(packageName) {
368
- return packageName === "@tailwindcss/postcss" || packageName === "tailwindcss4" || Boolean(packageName && packageName.includes("tailwindcss4"));
369
- }
370
- function createTailwindcssPatcher(options) {
371
- const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
372
- const cache = { driver: "memory" };
373
- const normalizedBasedir = basedir ? node_path.default.resolve(basedir) : void 0;
374
- const cacheRoot = findNearestPackageRoot(normalizedBasedir) ?? normalizedBasedir ?? node_process.default.cwd();
375
- if (cacheDir) if (node_path.default.isAbsolute(cacheDir)) cache.dir = cacheDir;
376
- else if (normalizedBasedir) cache.dir = node_path.default.resolve(normalizedBasedir, cacheDir);
377
- else cache.dir = node_path.default.resolve(node_process.default.cwd(), cacheDir);
378
- else cache.dir = node_path.default.join(cacheRoot, "node_modules", ".cache", "tailwindcss-patch");
379
- if (normalizedBasedir) cache.cwd = normalizedBasedir;
380
- const resolvePaths = createDefaultResolvePaths(cache.cwd ?? normalizedBasedir ?? node_process.default.cwd());
381
- const normalizedUserOptions = require_patcher_options.normalizeTailwindcssPatcherOptions(tailwindcssPatcherOptions);
382
- const extendLengthUnits = require_patcher_options.normalizeExtendLengthUnits(supportCustomLengthUnitsPatch ?? true);
383
- const baseTailwindOptions = (0, _weapp_tailwindcss_shared.defuOverrideArray)(tailwindcss ?? {}, {
384
- cwd: normalizedBasedir,
385
- resolve: { paths: resolvePaths }
386
- });
387
- if (!baseTailwindOptions.packageName) baseTailwindOptions.packageName = "tailwindcss";
388
- if (!baseTailwindOptions.postcssPlugin) baseTailwindOptions.postcssPlugin = baseTailwindOptions.version === 4 || isTailwindcssV4PackageName(baseTailwindOptions.packageName) ? "@tailwindcss/postcss" : "tailwindcss";
389
- if (typeof baseTailwindOptions.postcssPlugin === "string") {
390
- const resolvedPlugin = resolveModuleFromPaths(baseTailwindOptions.postcssPlugin, resolvePaths);
391
- if (resolvedPlugin) baseTailwindOptions.postcssPlugin = resolvedPlugin;
392
- }
393
- const resolvedOptions = (0, _weapp_tailwindcss_shared.defuOverrideArray)(normalizedUserOptions ?? {}, {
394
- projectRoot: normalizedBasedir,
395
- cache,
396
- tailwindcss: baseTailwindOptions,
397
- apply: {
398
- exposeContext: true,
399
- extendLengthUnits
400
- }
401
- });
402
- const resolvedTailwindOptions = resolvedOptions.tailwindcss;
403
- if (resolvedTailwindOptions) {
404
- const existingResolve = resolvedTailwindOptions.resolve ?? {};
405
- const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? existingResolve.paths : resolvePaths;
406
- resolvedTailwindOptions.resolve = {
407
- ...existingResolve,
408
- paths: [...new Set(sourcePaths)]
409
- };
410
- _weapp_tailwindcss_logger.logger.debug("Tailwind resolve config %O", {
411
- packageName: resolvedTailwindOptions.packageName,
412
- version: resolvedTailwindOptions.version,
413
- resolve: resolvedTailwindOptions.resolve,
414
- cwd: resolvedTailwindOptions.cwd
415
- });
416
- if (typeof resolvedTailwindOptions.postcssPlugin === "string") {
417
- const resolvedPlugin = resolveModuleFromPaths(resolvedTailwindOptions.postcssPlugin, resolvedTailwindOptions.resolve?.paths ?? resolvePaths);
418
- if (resolvedPlugin) resolvedTailwindOptions.postcssPlugin = resolvedPlugin;
419
- }
420
- const searchRoots = /* @__PURE__ */ new Set();
421
- if (resolvedTailwindOptions.cwd) searchRoots.add(resolvedTailwindOptions.cwd);
422
- for (const resolvePath of resolvedTailwindOptions.resolve?.paths ?? []) {
423
- const parentDir = node_path.default.dirname(resolvePath);
424
- searchRoots.add(parentDir);
425
- }
426
- const configPath = findTailwindConfig(searchRoots);
427
- if (!resolvedTailwindOptions.config) if (configPath) resolvedTailwindOptions.config = configPath;
428
- else {
429
- const fallbackConfig = resolveTailwindConfigFallback(resolvedTailwindOptions.packageName, resolvedTailwindOptions.resolve.paths ?? resolvePaths);
430
- if (fallbackConfig) resolvedTailwindOptions.config = fallbackConfig;
431
- }
432
- if (!resolvedTailwindOptions.cwd && configPath) resolvedTailwindOptions.cwd = node_path.default.dirname(configPath);
433
- resolvedOptions.tailwindcss = resolvedTailwindOptions;
434
- }
435
- try {
436
- return new tailwindcss_patch.TailwindcssPatcher(resolvedOptions);
437
- } catch (error) {
438
- const searchPaths = resolvedOptions.tailwindcss?.resolve?.paths;
439
- if (error instanceof Error && TAILWINDCSS_NOT_FOUND_RE.test(error.message)) {
440
- if (!hasLoggedMissingTailwind) {
441
- _weapp_tailwindcss_logger.logger.warn("Tailwind CSS 未安装,已跳过 Tailwind 相关补丁。若需使用 Tailwind 能力,请安装 tailwindcss。");
442
- hasLoggedMissingTailwind = true;
443
- }
444
- return createFallbackTailwindcssPatcher();
445
- }
446
- if (error instanceof Error && UNABLE_TO_LOCATE_TAILWINDCSS_RE.test(error.message)) _weapp_tailwindcss_logger.logger.error("无法定位 Tailwind CSS 包 \"%s\",已尝试路径: %O", resolvedOptions.tailwindcss?.packageName, searchPaths);
447
- throw error;
448
- }
449
- }
450
- //#endregion
451
137
  //#region src/tailwindcss/v4/multi-patcher.ts
452
138
  function createMultiTailwindcssPatcher(patchers) {
453
139
  if (patchers.length <= 1) return patchers[0];
454
- const [first] = patchers;
140
+ const first = patchers[0];
141
+ const firstWithoutPatch = { ...first };
142
+ delete firstWithoutPatch.patch;
455
143
  const multiPatcher = {
456
- ...first,
144
+ ...firstWithoutPatch,
457
145
  packageInfo: first?.packageInfo,
458
146
  majorVersion: first?.majorVersion,
459
147
  options: first?.options,
460
- async patch() {
461
- let exposeContext;
462
- let extendLengthUnits;
463
- for (const patcher of patchers) {
464
- const result = await patcher.patch();
465
- if (result?.exposeContext && exposeContext == null) exposeContext = result.exposeContext;
466
- if (result?.extendLengthUnits && extendLengthUnits == null) extendLengthUnits = result.extendLengthUnits;
467
- }
468
- return {
469
- exposeContext,
470
- extendLengthUnits
471
- };
472
- },
473
148
  async getClassSet() {
474
149
  const aggregated = /* @__PURE__ */ new Set();
475
150
  for (const patcher of patchers) {
@@ -508,7 +183,7 @@ function createMultiTailwindcssPatcher(patchers) {
508
183
  }
509
184
  return aggregated;
510
185
  };
511
- Object.defineProperty(multiPatcher, runtimeSignaturePatchersSymbol, {
186
+ Object.defineProperty(multiPatcher, require_cache.runtimeSignaturePatchersSymbol, {
512
187
  value: [...patchers],
513
188
  configurable: true
514
189
  });
@@ -542,7 +217,7 @@ function guessBasedirFromEntries(entries) {
542
217
  const trimmed = entry.trim();
543
218
  if (!trimmed || !node_path.default.isAbsolute(trimmed)) continue;
544
219
  const entryDir = node_path.default.dirname(trimmed);
545
- const resolved = findNearestPackageRoot(entryDir) ?? entryDir;
220
+ const resolved = require_cache.findNearestPackageRoot(entryDir) ?? entryDir;
546
221
  if (resolved) return resolved;
547
222
  }
548
223
  }
@@ -568,7 +243,7 @@ function resolveCssEntryBase(entryDir, options) {
568
243
  const { preferredBaseDir, workspaceRoot } = options;
569
244
  if (preferredBaseDir && isSubPath(preferredBaseDir, normalizedDir)) return preferredBaseDir;
570
245
  if (workspaceRoot && isSubPath(workspaceRoot, normalizedDir)) return workspaceRoot;
571
- const packageRoot = findNearestPackageRoot(normalizedDir);
246
+ const packageRoot = require_cache.findNearestPackageRoot(normalizedDir);
572
247
  if (packageRoot) return node_path.default.normalize(packageRoot);
573
248
  return normalizedDir;
574
249
  }
@@ -633,7 +308,7 @@ function createPatcherForBase(baseDir, cssEntries, options) {
633
308
  const explicitTailwindVersion = resolveExplicitTailwindVersion(tailwindcss?.version || tailwindcssPatcherOptions?.tailwindcss?.version || mergedTailwindOptions.version, configuredPackageName);
634
309
  const hasExplicitV4Signals = hasCssEntries || hasOwnV4Signal(tailwindcss) || hasOwnV4Signal(tailwindcssPatcherOptions?.tailwindcss);
635
310
  const packageNameForVersionDetection = configuredPackageName ?? mergedTailwindOptions.packageName ?? "tailwindcss";
636
- const installedTailwindVersion = require_version.readInstalledPackageMajorVersion(packageNameForVersionDetection, baseDir);
311
+ const installedTailwindVersion = require_cache.readInstalledPackageMajorVersion(packageNameForVersionDetection, baseDir);
637
312
  const resolvedTailwindVersion = installedTailwindVersion ?? explicitTailwindVersion;
638
313
  const shouldPatchV4PostcssPackage = (resolvedTailwindVersion === 4 && (installedTailwindVersion === 4 || explicitTailwindVersion === 4 || hasExplicitV4Signals && isTailwindcss4Package(packageNameForVersionDetection)) || resolvedTailwindVersion === void 0 && (hasCssEntries || hasOwnV4Signal(tailwindcss) || hasOwnV4Signal(tailwindcssPatcherOptions?.tailwindcss))) && !Boolean(configuredPackageName);
639
314
  const packageCandidates = /* @__PURE__ */ new Set();
@@ -649,7 +324,7 @@ function createPatcherForBase(baseDir, cssEntries, options) {
649
324
  };
650
325
  if (resolvedTailwindVersion) tailwindOptionsForPackage.version = resolvedTailwindVersion;
651
326
  try {
652
- patchers.push(createTailwindcssPatcher({
327
+ patchers.push(require_cache.createTailwindcssPatcher({
653
328
  basedir: baseDir,
654
329
  supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
655
330
  tailwindcss: tailwindOptionsForPackage,
@@ -812,9 +487,9 @@ function resolveTailwindcssBasedir(basedir, fallback) {
812
487
  return node_path.default.normalize(node_path.default.dirname(packageJsonPath));
813
488
  } catch {
814
489
  if (node_process.default.env.WEAPP_TW_DEBUG_STACK === "1") _weapp_tailwindcss_logger.logger.debug("failed to resolve package json for %s", packageName);
815
- const workspaceRoot = findWorkspaceRoot(anchor);
490
+ const workspaceRoot = require_cache.findWorkspaceRoot(anchor);
816
491
  if (workspaceRoot) {
817
- const packageDir = findWorkspacePackageDir(workspaceRoot, packageName);
492
+ const packageDir = require_cache.findWorkspacePackageDir(workspaceRoot, packageName);
818
493
  if (packageDir) return packageDir;
819
494
  }
820
495
  }
@@ -888,7 +563,7 @@ function createTailwindcssPatcherFromContext(ctx) {
888
563
  appType,
889
564
  bareArbitraryValues: arbitraryValues?.bareArbitraryValues
890
565
  };
891
- const workspaceRoot = findWorkspaceRoot(resolvedTailwindcssBasedir) ?? (absoluteCssEntryBasedir ? findWorkspaceRoot(absoluteCssEntryBasedir) : void 0);
566
+ const workspaceRoot = require_cache.findWorkspaceRoot(resolvedTailwindcssBasedir) ?? (absoluteCssEntryBasedir ? require_cache.findWorkspaceRoot(absoluteCssEntryBasedir) : void 0);
892
567
  const groupedCssEntries = normalizedCssEntries ? groupCssEntriesByBase(normalizedCssEntries, {
893
568
  preferredBaseDir: resolvedTailwindcssBasedir,
894
569
  workspaceRoot
@@ -917,34 +592,10 @@ Object.defineProperty(exports, "createTailwindcssPatcherFromContext", {
917
592
  return createTailwindcssPatcherFromContext;
918
593
  }
919
594
  });
920
- Object.defineProperty(exports, "findNearestPackageRoot", {
921
- enumerable: true,
922
- get: function() {
923
- return findNearestPackageRoot;
924
- }
925
- });
926
- Object.defineProperty(exports, "findTailwindConfig", {
927
- enumerable: true,
928
- get: function() {
929
- return findTailwindConfig;
930
- }
931
- });
932
- Object.defineProperty(exports, "getRuntimeClassSetCacheEntry", {
595
+ Object.defineProperty(exports, "hasConfiguredTailwindV4CssRoots", {
933
596
  enumerable: true,
934
597
  get: function() {
935
- return getRuntimeClassSetCacheEntry;
936
- }
937
- });
938
- Object.defineProperty(exports, "getRuntimeClassSetSignature", {
939
- enumerable: true,
940
- get: function() {
941
- return getRuntimeClassSetSignature;
942
- }
943
- });
944
- Object.defineProperty(exports, "invalidateRuntimeClassSet", {
945
- enumerable: true,
946
- get: function() {
947
- return invalidateRuntimeClassSet;
598
+ return hasConfiguredTailwindV4CssRoots;
948
599
  }
949
600
  });
950
601
  Object.defineProperty(exports, "isUniAppXEnabled", {
@@ -965,6 +616,12 @@ Object.defineProperty(exports, "resolveUniAppXOptions", {
965
616
  return resolveUniAppXOptions;
966
617
  }
967
618
  });
619
+ Object.defineProperty(exports, "upsertTailwindV4CssSource", {
620
+ enumerable: true,
621
+ get: function() {
622
+ return upsertTailwindV4CssSource;
623
+ }
624
+ });
968
625
  Object.defineProperty(exports, "warnMissingCssEntries", {
969
626
  enumerable: true,
970
627
  get: function() {