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,181 +1,62 @@
1
- import { n as normalizeTailwindcssPatcherOptions, r as resolveTailwindcssOptions, t as normalizeExtendLengthUnits } from "./patcher-options-GuOwX0-k.mjs";
2
- import { n as defuOverrideArray$1 } from "./utils-7DUGTFED.mjs";
3
- import { t as readInstalledPackageMajorVersion } from "./version-WNz3MwRv.mjs";
1
+ import { a as createTailwindcssPatcher, d as findWorkspaceRoot, i as runtimeSignaturePatchersSymbol, l as findNearestPackageRoot, o as readInstalledPackageMajorVersion, u as findWorkspacePackageDir } from "./cache-CHs4DXui.mjs";
2
+ import { n as defuOverrideArray } from "./utils-Btw1iOVV.mjs";
4
3
  import { createRequire } from "node:module";
5
4
  import path from "node:path";
6
5
  import process from "node:process";
7
- import { TailwindcssPatcher } from "tailwindcss-patch";
8
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
9
- import { logger, logger as logger$1 } from "@weapp-tailwindcss/logger";
10
- import { defuOverrideArray } from "@weapp-tailwindcss/shared";
6
+ import { logger } from "@weapp-tailwindcss/logger";
7
+ import { existsSync, readFileSync } from "node:fs";
11
8
  import { fileURLToPath } from "node:url";
12
- //#region src/tailwindcss/runtime/cache.ts
13
- const runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
14
- const runtimeFileSignatureCache = /* @__PURE__ */ new Map();
15
- let runtimeFileSignatureCacheClearTimer;
16
- const runtimeSignaturePatchersSymbol = Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
17
- function getCacheEntry(twPatcher) {
18
- let entry = runtimeClassSetCache.get(twPatcher);
19
- if (!entry) {
20
- entry = {};
21
- runtimeClassSetCache.set(twPatcher, entry);
22
- }
23
- return entry;
24
- }
25
- function scheduleRuntimeConfigSignatureCacheClear() {
26
- if (runtimeFileSignatureCacheClearTimer) return;
27
- runtimeFileSignatureCacheClearTimer = setTimeout(() => {
28
- runtimeFileSignatureCache.clear();
29
- runtimeFileSignatureCacheClearTimer = void 0;
30
- }, 0);
31
- runtimeFileSignatureCacheClearTimer.unref?.();
32
- }
33
- function getFileSignature(filePath) {
34
- const cached = runtimeFileSignatureCache.get(filePath);
35
- if (cached !== void 0) return cached;
36
- let signature;
37
- try {
38
- const stats = statSync(filePath);
39
- signature = `${filePath}:${stats.size}:${stats.mtimeMs}`;
40
- } catch {
41
- signature = `${filePath}:missing`;
42
- }
43
- runtimeFileSignatureCache.set(filePath, signature);
44
- scheduleRuntimeConfigSignatureCacheClear();
45
- return signature;
46
- }
47
- function getTailwindTrackedFiles(twPatcher) {
48
- const tailwindOptions = resolveTailwindcssOptions(twPatcher.options);
49
- const tracked = /* @__PURE__ */ new Set();
50
- const configPath = tailwindOptions?.config;
51
- if (typeof configPath === "string" && configPath.length > 0) tracked.add(configPath);
52
- for (const entry of tailwindOptions?.v4?.cssEntries ?? []) if (typeof entry === "string" && entry.length > 0) tracked.add(entry);
53
- return tracked;
54
- }
55
- function normalizeSignatureValue(value) {
56
- if (value == null) return "null";
57
- if (typeof value === "string") return value;
58
- if (typeof value === "number" || typeof value === "boolean") return String(value);
59
- if (Array.isArray(value)) return `[${value.map((item) => normalizeSignatureValue(item)).join(",")}]`;
60
- 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(",")}}`;
61
- return String(value);
62
- }
63
- function readOptionalProperty(value, key) {
64
- if (typeof value !== "object" || value === null || !(key in value)) return;
65
- return value[key];
66
- }
67
- function getTailwindOptionsSignature(twPatcher) {
68
- const options = twPatcher.options;
69
- const tailwindOptions = resolveTailwindcssOptions(options);
70
- return normalizeSignatureValue({
71
- projectRoot: options?.projectRoot,
72
- packageName: tailwindOptions?.packageName,
73
- versionHint: readOptionalProperty(tailwindOptions, "versionHint"),
74
- cwd: tailwindOptions?.cwd,
75
- config: tailwindOptions?.config,
76
- v2: tailwindOptions?.v2,
77
- v3: tailwindOptions?.v3,
78
- v4: {
79
- base: tailwindOptions?.v4?.base,
80
- configuredBase: readOptionalProperty(tailwindOptions?.v4, "configuredBase"),
81
- css: tailwindOptions?.v4?.css,
82
- cssEntries: tailwindOptions?.v4?.cssEntries,
83
- hasUserDefinedSources: readOptionalProperty(tailwindOptions?.v4, "hasUserDefinedSources"),
84
- sources: tailwindOptions?.v4?.sources
85
- }
9
+ //#region src/tailwindcss/v4/css-sources.ts
10
+ function hasCssEntriesValue(value) {
11
+ if (typeof value === "string") return value.trim().length > 0;
12
+ return Array.isArray(value) && value.some((entry) => typeof entry === "string" && entry.trim().length > 0);
13
+ }
14
+ function hasCssSourcesValue(value) {
15
+ return Array.isArray(value) && value.some((source) => {
16
+ return typeof source === "object" && source !== null && typeof source.css === "string" && source.css.trim().length > 0;
86
17
  });
87
18
  }
88
- function getPatchTargetSignature(twPatcher) {
89
- const packageInfo = twPatcher.packageInfo;
90
- return [
91
- packageInfo?.name ?? "missing",
92
- packageInfo?.rootPath ?? "missing",
93
- packageInfo?.version ?? "unknown",
94
- twPatcher.majorVersion ?? "unknown",
95
- getTailwindOptionsSignature(twPatcher)
96
- ].join(":");
97
- }
98
- function getNestedPatchers(twPatcher) {
99
- const nested = twPatcher[runtimeSignaturePatchersSymbol];
100
- return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
101
- }
102
- function getOwnRuntimeClassSetSignature(twPatcher) {
103
- const trackedFiles = [...getTailwindTrackedFiles(twPatcher)].sort((a, b) => a.localeCompare(b)).map(getFileSignature);
104
- return `${trackedFiles.length > 0 ? trackedFiles.join("|") : "files:missing"}|patch:${getPatchTargetSignature(twPatcher)}`;
105
- }
106
- function invalidateRuntimeClassSet(twPatcher) {
107
- if (!twPatcher) return;
108
- const nestedPatchers = getNestedPatchers(twPatcher);
109
- if (nestedPatchers) for (const patcher of nestedPatchers) invalidateRuntimeClassSet(patcher);
110
- for (const trackedFile of getTailwindTrackedFiles(twPatcher)) runtimeFileSignatureCache.delete(trackedFile);
111
- runtimeClassSetCache.delete(twPatcher);
112
- }
113
- function getRuntimeClassSetCacheEntry(twPatcher) {
114
- return getCacheEntry(twPatcher);
115
- }
116
- function getRuntimeClassSetSignature(twPatcher) {
117
- const nestedPatchers = getNestedPatchers(twPatcher);
118
- if (nestedPatchers) return nestedPatchers.map(getOwnRuntimeClassSetSignature).sort((a, b) => a.localeCompare(b)).join("||");
119
- return getOwnRuntimeClassSetSignature(twPatcher);
19
+ function hasConfiguredTailwindV4CssRoots(options) {
20
+ 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);
120
21
  }
121
- //#endregion
122
- //#region src/context/workspace.ts
123
- const IGNORED_WORKSPACE_DIRS = new Set([
124
- "node_modules",
125
- ".git",
126
- ".hg",
127
- ".svn",
128
- ".turbo",
129
- ".output",
130
- ".next",
131
- "dist",
132
- "build"
133
- ]);
134
- function findWorkspaceRoot(startDir) {
135
- if (!startDir) return;
136
- let current = path.resolve(startDir);
137
- while (true) {
138
- if (existsSync(path.join(current, "pnpm-workspace.yaml"))) return current;
139
- const parent = path.dirname(current);
140
- if (parent === current) return;
141
- current = parent;
142
- }
22
+ function normalizeCssSourceFile(file) {
23
+ if (!file) return;
24
+ return path.isAbsolute(file) ? path.normalize(file) : file;
143
25
  }
144
- function findNearestPackageRoot(startDir) {
145
- if (!startDir) return;
146
- let current = path.resolve(startDir);
147
- while (true) {
148
- if (existsSync(path.join(current, "package.json"))) return current;
149
- const parent = path.dirname(current);
150
- if (parent === current) return;
151
- current = parent;
152
- }
26
+ function normalizeDependencies(dependencies) {
27
+ return dependencies?.map(normalizeCssSourceFile).filter((dependency) => typeof dependency === "string" && dependency.length > 0);
153
28
  }
154
- function findWorkspacePackageDir(rootDir, packageName) {
155
- const visited = /* @__PURE__ */ new Set();
156
- const queue = [path.resolve(rootDir)];
157
- while (queue.length > 0) {
158
- const current = queue.shift();
159
- const normalized = path.normalize(current);
160
- if (visited.has(normalized)) continue;
161
- visited.add(normalized);
162
- try {
163
- const pkgPath = path.join(normalized, "package.json");
164
- if (existsSync(pkgPath)) {
165
- if (JSON.parse(readFileSync(pkgPath, "utf8"))?.name === packageName) return normalized;
166
- }
167
- } catch {}
168
- let entries;
169
- try {
170
- entries = readdirSync(normalized, { withFileTypes: true });
171
- } catch {
172
- continue;
173
- }
174
- for (const entry of entries) {
175
- if (!entry.isDirectory() || IGNORED_WORKSPACE_DIRS.has(entry.name) || entry.isSymbolicLink?.()) continue;
176
- queue.push(path.join(normalized, entry.name));
29
+ function isSameCssSource(a, b) {
30
+ 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));
31
+ }
32
+ function upsertTailwindV4CssSource(opts, source) {
33
+ const normalizedSource = {
34
+ ...source,
35
+ ...source.file === void 0 ? {} : { file: normalizeCssSourceFile(source.file) },
36
+ ...source.dependencies === void 0 ? {} : { dependencies: normalizeDependencies(source.dependencies) }
37
+ };
38
+ const tailwindcss = opts.tailwindcss ?? {};
39
+ const v4 = tailwindcss.v4 ?? {};
40
+ const cssSources = [...v4.cssSources ?? []];
41
+ const sourceFile = normalizeCssSourceFile(normalizedSource.file);
42
+ const existingIndex = cssSources.findIndex((candidate) => normalizeCssSourceFile(candidate.file) === sourceFile);
43
+ if (existingIndex >= 0) {
44
+ const existing = cssSources[existingIndex];
45
+ const nextSource = {
46
+ ...existing,
47
+ ...normalizedSource
48
+ };
49
+ if (isSameCssSource(existing, nextSource)) return false;
50
+ cssSources[existingIndex] = nextSource;
51
+ } else cssSources.push(normalizedSource);
52
+ opts.tailwindcss = {
53
+ ...tailwindcss,
54
+ v4: {
55
+ ...v4,
56
+ cssSources
177
57
  }
178
- }
58
+ };
59
+ return true;
179
60
  }
180
61
  //#endregion
181
62
  //#region src/tailwindcss/v4/config.ts
@@ -239,7 +120,7 @@ let hasWarnedMissingCssEntries = false;
239
120
  function warnMissingCssEntries(ctx, patcher) {
240
121
  if (hasWarnedMissingCssEntries) return;
241
122
  if (patcher?.majorVersion !== 4) return;
242
- if (hasConfiguredCssEntries(ctx)) return;
123
+ if (hasConfiguredCssEntries(ctx) || hasConfiguredTailwindV4CssRoots(ctx)) return;
243
124
  hasWarnedMissingCssEntries = true;
244
125
  logger.warn("[tailwindcss@4] 未检测到 cssEntries 配置。请传入包含 tailwindcss 引用的 CSS 绝对路径,例如 cssEntries: [\"/absolute/path/to/src/app.css\"],否则 tailwindcss 生成的类名不会参与转译。");
245
126
  }
@@ -249,224 +130,17 @@ function applyV4CssCalcDefaults(cssCalc, patcher) {
249
130
  return cssCalcOptions;
250
131
  }
251
132
  //#endregion
252
- //#region src/tailwindcss/patcher-resolve.ts
253
- const GENERIC_RELATIVE_SPECIFIERS = [".", ".."];
254
- const DEFAULT_TAILWIND_CONFIG_SPECIFIERS = ["stubs/config.full.js", "defaultConfig.js"];
255
- const TAILWIND_CONFIG_FILES = [
256
- "tailwind.config.js",
257
- "tailwind.config.cjs",
258
- "tailwind.config.mjs",
259
- "tailwind.config.ts",
260
- "tailwind.config.cts",
261
- "tailwind.config.mts"
262
- ];
263
- function isPathSpecifier(specifier) {
264
- if (!specifier) return false;
265
- if (specifier.startsWith("file://")) return true;
266
- if (path.isAbsolute(specifier)) return true;
267
- return GENERIC_RELATIVE_SPECIFIERS.some((prefix) => specifier.startsWith(`${prefix}/`) || specifier.startsWith(`${prefix}\\`));
268
- }
269
- function resolveModuleFromPaths(specifier, paths) {
270
- if (!specifier || isPathSpecifier(specifier) || paths.length === 0) return;
271
- try {
272
- return createRequire(import.meta.url).resolve(specifier, { paths });
273
- } catch {
274
- return;
275
- }
276
- }
277
- function resolveTailwindConfigFallback(packageName, paths) {
278
- if (!packageName) return;
279
- for (const suffix of DEFAULT_TAILWIND_CONFIG_SPECIFIERS) {
280
- const resolved = resolveModuleFromPaths(`${packageName}/${suffix}`, paths);
281
- if (resolved) return resolved;
282
- }
283
- }
284
- function appendNodeModules(paths, dir) {
285
- if (!dir) return;
286
- const nodeModulesDir = path.join(dir, "node_modules");
287
- if (existsSync(nodeModulesDir)) paths.add(nodeModulesDir);
288
- }
289
- function findTailwindConfig(searchRoots) {
290
- for (const root of searchRoots) for (const file of TAILWIND_CONFIG_FILES) {
291
- const candidate = path.resolve(root, file);
292
- if (existsSync(candidate)) return candidate;
293
- }
294
- }
295
- function createDefaultResolvePaths(basedir) {
296
- const paths = /* @__PURE__ */ new Set();
297
- let fallbackCandidates = [];
298
- if (basedir) {
299
- const resolvedBase = path.resolve(basedir);
300
- appendNodeModules(paths, resolvedBase);
301
- fallbackCandidates.push(resolvedBase);
302
- const packageRoot = findNearestPackageRoot(resolvedBase);
303
- if (packageRoot) {
304
- appendNodeModules(paths, packageRoot);
305
- fallbackCandidates.push(packageRoot);
306
- }
307
- }
308
- const cwd = process.cwd();
309
- appendNodeModules(paths, cwd);
310
- try {
311
- const modulePath = fileURLToPath(import.meta.url);
312
- const candidate = existsSync(modulePath) && !path.extname(modulePath) ? modulePath : path.dirname(modulePath);
313
- paths.add(candidate);
314
- } catch {
315
- paths.add(import.meta.url);
316
- }
317
- if (paths.size === 0) {
318
- fallbackCandidates = fallbackCandidates.filter(Boolean);
319
- if (fallbackCandidates.length === 0) fallbackCandidates.push(cwd);
320
- for (const candidate of fallbackCandidates) paths.add(candidate);
321
- }
322
- return [...paths];
323
- }
324
- //#endregion
325
- //#region src/tailwindcss/patcher.ts
326
- function createFallbackTailwindcssPatcher() {
327
- return {
328
- packageInfo: {
329
- name: "tailwindcss",
330
- version: void 0,
331
- rootPath: "",
332
- packageJsonPath: "",
333
- packageJson: {}
334
- },
335
- majorVersion: 4,
336
- async patch() {
337
- return {
338
- exposeContext: void 0,
339
- extendLengthUnits: void 0
340
- };
341
- },
342
- async getClassSet() {
343
- return /* @__PURE__ */ new Set();
344
- },
345
- async extract(_options) {
346
- return {
347
- classList: [],
348
- classSet: /* @__PURE__ */ new Set()
349
- };
350
- },
351
- async collectContentTokens() {
352
- return {
353
- entries: [],
354
- filesScanned: 0,
355
- sources: [],
356
- skippedFiles: []
357
- };
358
- }
359
- };
360
- }
361
- let hasLoggedMissingTailwind = false;
362
- const TAILWINDCSS_NOT_FOUND_RE = /tailwindcss not found/i;
363
- const UNABLE_TO_LOCATE_TAILWINDCSS_RE = /unable to locate tailwind css package/i;
364
- function isTailwindcssV4PackageName(packageName) {
365
- return packageName === "@tailwindcss/postcss" || packageName === "tailwindcss4" || Boolean(packageName && packageName.includes("tailwindcss4"));
366
- }
367
- function createTailwindcssPatcher(options) {
368
- const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
369
- const cache = { driver: "memory" };
370
- const normalizedBasedir = basedir ? path.resolve(basedir) : void 0;
371
- const cacheRoot = findNearestPackageRoot(normalizedBasedir) ?? normalizedBasedir ?? process.cwd();
372
- if (cacheDir) if (path.isAbsolute(cacheDir)) cache.dir = cacheDir;
373
- else if (normalizedBasedir) cache.dir = path.resolve(normalizedBasedir, cacheDir);
374
- else cache.dir = path.resolve(process.cwd(), cacheDir);
375
- else cache.dir = path.join(cacheRoot, "node_modules", ".cache", "tailwindcss-patch");
376
- if (normalizedBasedir) cache.cwd = normalizedBasedir;
377
- const resolvePaths = createDefaultResolvePaths(cache.cwd ?? normalizedBasedir ?? process.cwd());
378
- const normalizedUserOptions = normalizeTailwindcssPatcherOptions(tailwindcssPatcherOptions);
379
- const extendLengthUnits = normalizeExtendLengthUnits(supportCustomLengthUnitsPatch ?? true);
380
- const baseTailwindOptions = defuOverrideArray(tailwindcss ?? {}, {
381
- cwd: normalizedBasedir,
382
- resolve: { paths: resolvePaths }
383
- });
384
- if (!baseTailwindOptions.packageName) baseTailwindOptions.packageName = "tailwindcss";
385
- if (!baseTailwindOptions.postcssPlugin) baseTailwindOptions.postcssPlugin = baseTailwindOptions.version === 4 || isTailwindcssV4PackageName(baseTailwindOptions.packageName) ? "@tailwindcss/postcss" : "tailwindcss";
386
- if (typeof baseTailwindOptions.postcssPlugin === "string") {
387
- const resolvedPlugin = resolveModuleFromPaths(baseTailwindOptions.postcssPlugin, resolvePaths);
388
- if (resolvedPlugin) baseTailwindOptions.postcssPlugin = resolvedPlugin;
389
- }
390
- const resolvedOptions = defuOverrideArray(normalizedUserOptions ?? {}, {
391
- projectRoot: normalizedBasedir,
392
- cache,
393
- tailwindcss: baseTailwindOptions,
394
- apply: {
395
- exposeContext: true,
396
- extendLengthUnits
397
- }
398
- });
399
- const resolvedTailwindOptions = resolvedOptions.tailwindcss;
400
- if (resolvedTailwindOptions) {
401
- const existingResolve = resolvedTailwindOptions.resolve ?? {};
402
- const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? existingResolve.paths : resolvePaths;
403
- resolvedTailwindOptions.resolve = {
404
- ...existingResolve,
405
- paths: [...new Set(sourcePaths)]
406
- };
407
- logger.debug("Tailwind resolve config %O", {
408
- packageName: resolvedTailwindOptions.packageName,
409
- version: resolvedTailwindOptions.version,
410
- resolve: resolvedTailwindOptions.resolve,
411
- cwd: resolvedTailwindOptions.cwd
412
- });
413
- if (typeof resolvedTailwindOptions.postcssPlugin === "string") {
414
- const resolvedPlugin = resolveModuleFromPaths(resolvedTailwindOptions.postcssPlugin, resolvedTailwindOptions.resolve?.paths ?? resolvePaths);
415
- if (resolvedPlugin) resolvedTailwindOptions.postcssPlugin = resolvedPlugin;
416
- }
417
- const searchRoots = /* @__PURE__ */ new Set();
418
- if (resolvedTailwindOptions.cwd) searchRoots.add(resolvedTailwindOptions.cwd);
419
- for (const resolvePath of resolvedTailwindOptions.resolve?.paths ?? []) {
420
- const parentDir = path.dirname(resolvePath);
421
- searchRoots.add(parentDir);
422
- }
423
- const configPath = findTailwindConfig(searchRoots);
424
- if (!resolvedTailwindOptions.config) if (configPath) resolvedTailwindOptions.config = configPath;
425
- else {
426
- const fallbackConfig = resolveTailwindConfigFallback(resolvedTailwindOptions.packageName, resolvedTailwindOptions.resolve.paths ?? resolvePaths);
427
- if (fallbackConfig) resolvedTailwindOptions.config = fallbackConfig;
428
- }
429
- if (!resolvedTailwindOptions.cwd && configPath) resolvedTailwindOptions.cwd = path.dirname(configPath);
430
- resolvedOptions.tailwindcss = resolvedTailwindOptions;
431
- }
432
- try {
433
- return new TailwindcssPatcher(resolvedOptions);
434
- } catch (error) {
435
- const searchPaths = resolvedOptions.tailwindcss?.resolve?.paths;
436
- if (error instanceof Error && TAILWINDCSS_NOT_FOUND_RE.test(error.message)) {
437
- if (!hasLoggedMissingTailwind) {
438
- logger.warn("Tailwind CSS 未安装,已跳过 Tailwind 相关补丁。若需使用 Tailwind 能力,请安装 tailwindcss。");
439
- hasLoggedMissingTailwind = true;
440
- }
441
- return createFallbackTailwindcssPatcher();
442
- }
443
- if (error instanceof Error && UNABLE_TO_LOCATE_TAILWINDCSS_RE.test(error.message)) logger.error("无法定位 Tailwind CSS 包 \"%s\",已尝试路径: %O", resolvedOptions.tailwindcss?.packageName, searchPaths);
444
- throw error;
445
- }
446
- }
447
- //#endregion
448
133
  //#region src/tailwindcss/v4/multi-patcher.ts
449
134
  function createMultiTailwindcssPatcher(patchers) {
450
135
  if (patchers.length <= 1) return patchers[0];
451
- const [first] = patchers;
136
+ const first = patchers[0];
137
+ const firstWithoutPatch = { ...first };
138
+ delete firstWithoutPatch.patch;
452
139
  const multiPatcher = {
453
- ...first,
140
+ ...firstWithoutPatch,
454
141
  packageInfo: first?.packageInfo,
455
142
  majorVersion: first?.majorVersion,
456
143
  options: first?.options,
457
- async patch() {
458
- let exposeContext;
459
- let extendLengthUnits;
460
- for (const patcher of patchers) {
461
- const result = await patcher.patch();
462
- if (result?.exposeContext && exposeContext == null) exposeContext = result.exposeContext;
463
- if (result?.extendLengthUnits && extendLengthUnits == null) extendLengthUnits = result.extendLengthUnits;
464
- }
465
- return {
466
- exposeContext,
467
- extendLengthUnits
468
- };
469
- },
470
144
  async getClassSet() {
471
145
  const aggregated = /* @__PURE__ */ new Set();
472
146
  for (const patcher of patchers) {
@@ -604,7 +278,7 @@ function isTailwindVersionMismatchError(error) {
604
278
  function createPatcherForBase(baseDir, cssEntries, options) {
605
279
  const { tailwindcss, tailwindcssPatcherOptions, supportCustomLengthUnitsPatch, bareArbitraryValues } = options;
606
280
  const hasCssEntries = Boolean(cssEntries?.length);
607
- const mergedTailwindOptions = defuOverrideArray$1(tailwindcss ?? {}, {
281
+ const mergedTailwindOptions = defuOverrideArray(tailwindcss ?? {}, {
608
282
  cwd: baseDir,
609
283
  v2: { cwd: baseDir },
610
284
  v3: { cwd: baseDir },
@@ -902,4 +576,4 @@ function createTailwindcssPatcherFromContext(ctx) {
902
576
  return createPatcherForBase(resolvedTailwindcssBasedir, normalizedCssEntries ?? rawCssEntries, patcherOptions);
903
577
  }
904
578
  //#endregion
905
- export { resolveUniAppXOptions as a, warnMissingCssEntries as c, getRuntimeClassSetSignature as d, invalidateRuntimeClassSet as f, isUniAppXEnabled as i, findNearestPackageRoot as l, createTailwindcssPatcherFromContext as n, findTailwindConfig as o, resolveTailwindcssBasedir as r, applyV4CssCalcDefaults as s, logger$1 as t, getRuntimeClassSetCacheEntry as u };
579
+ export { applyV4CssCalcDefaults as a, upsertTailwindV4CssSource as c, resolveUniAppXOptions as i, resolveTailwindcssBasedir as n, warnMissingCssEntries as o, isUniAppXEnabled as r, hasConfiguredTailwindV4CssRoots as s, createTailwindcssPatcherFromContext as t };
@@ -23,7 +23,7 @@ export interface JsHandlerResult {
23
23
  export interface TailwindcssPatcherLike {
24
24
  packageInfo: TailwindcssPatcher['packageInfo'];
25
25
  majorVersion?: TailwindcssPatcher['majorVersion'];
26
- patch: TailwindcssPatcher['patch'];
26
+ patch?: TailwindcssPatcher['patch'];
27
27
  getClassSet: AsyncableMethod<TailwindcssPatcher['getClassSet']>;
28
28
  getClassSetSync?: TailwindcssPatcher['getClassSetSync'];
29
29
  extract: TailwindcssPatcher['extract'];
@@ -88,11 +88,6 @@ export interface IBaseWebpackPlugin {
88
88
  appType?: AppType;
89
89
  apply: (compiler: any) => void;
90
90
  }
91
- export interface InternalPatchResult {
92
- dataTypes?: string;
93
- processTailwindFeatures?: string;
94
- plugin?: string;
95
- }
96
91
  export type CreateJsHandlerOptions = Omit<IJsHandlerOptions, 'classNameSet'>;
97
92
  export interface JsModuleGraphOptions {
98
93
  resolve: (specifier: string, importer: string) => string | undefined;
@@ -3,7 +3,7 @@ import type { Plugin, ResolvedConfig } from 'vite';
3
3
  import type { ICreateCacheReturnType } from '../cache';
4
4
  import type { AppType, CreateJsHandlerOptions, ICustomAttributesEntities, InternalUserDefinedOptions, JsHandler, LinkedJsModuleResult } from '../types';
5
5
  interface UniAppXRuntimeState {
6
- patchPromise: Promise<unknown>;
6
+ readyPromise: Promise<unknown>;
7
7
  }
8
8
  interface CreateUniAppXPluginsOptions {
9
9
  appType: AppType;