weapp-tailwindcss 4.5.2 → 4.6.0
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.
- package/dist/{chunk-FOUWGCIJ.js → chunk-7CGHD2TI.js} +17 -15
- package/dist/{chunk-L4AXTSIM.mjs → chunk-7PGHZOTU.mjs} +10 -30
- package/dist/chunk-AXLRUW5H.js +776 -0
- package/dist/{chunk-PLMJW644.js → chunk-DWAEHRHN.js} +1 -4
- package/dist/{chunk-NHB7NFQC.js → chunk-E5PXIHDN.js} +1 -1
- package/dist/chunk-FB5P4TRH.js +70 -0
- package/dist/{chunk-ZUH5ZA7D.js → chunk-FVA7Y2YU.js} +21 -19
- package/dist/{chunk-FOSGDQZ7.js → chunk-I7FYDXN6.js} +3 -5
- package/dist/chunk-IY2OKZE6.mjs +773 -0
- package/dist/{chunk-CKTI35D3.mjs → chunk-JG5LBGLH.mjs} +27 -7
- package/dist/{chunk-FWIGQ4RY.mjs → chunk-KHILYAA4.mjs} +1 -1
- package/dist/chunk-LTJQUORK.js +32 -0
- package/dist/{chunk-TGTFIOJU.js → chunk-M6DWZX4H.js} +31 -11
- package/dist/{chunk-GGIH6WLF.mjs → chunk-MXVUK23K.mjs} +14 -12
- package/dist/{chunk-A3TJT6B6.js → chunk-OVDIACVK.js} +19 -39
- package/dist/{chunk-H4JTYYOI.mjs → chunk-RRHPTTCP.mjs} +0 -11
- package/dist/{chunk-WFZ73Q6S.mjs → chunk-TTDQ4TK2.mjs} +14 -12
- package/dist/{chunk-Q67IXIAH.mjs → chunk-VSRDBMDB.mjs} +1 -4
- package/dist/{chunk-IHKVNALD.mjs → chunk-YLNOOPZL.mjs} +3 -5
- package/dist/chunk-YPBRGP6K.mjs +70 -0
- package/dist/cli.js +11 -8
- package/dist/cli.mjs +11 -8
- package/dist/core.d.mts +0 -1
- package/dist/core.d.ts +0 -1
- package/dist/core.js +23 -12
- package/dist/core.mjs +21 -10
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/defaults.d.mts +0 -1
- package/dist/defaults.d.ts +0 -1
- package/dist/defaults.js +3 -3
- package/dist/defaults.mjs +2 -2
- package/dist/escape.d.mts +0 -1
- package/dist/escape.d.ts +0 -1
- package/dist/escape.js +3 -3
- package/dist/escape.mjs +2 -2
- package/dist/gulp.d.mts +0 -1
- package/dist/gulp.d.ts +0 -1
- package/dist/gulp.js +9 -8
- package/dist/gulp.mjs +8 -7
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +11 -10
- package/dist/index.mjs +10 -9
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.d.mts +0 -1
- package/dist/presets.d.ts +0 -1
- package/dist/presets.js +17 -23
- package/dist/presets.mjs +16 -22
- package/dist/types.d.mts +10 -30
- package/dist/types.d.ts +10 -30
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.d.mts +0 -1
- package/dist/vite.d.ts +0 -1
- package/dist/vite.js +9 -8
- package/dist/vite.mjs +8 -7
- package/dist/weapp-tw-runtime-loader.js +4 -1
- package/dist/webpack.d.mts +0 -1
- package/dist/webpack.d.ts +0 -1
- package/dist/webpack.js +9 -8
- package/dist/webpack.mjs +8 -7
- package/dist/webpack4.d.mts +0 -1
- package/dist/webpack4.d.ts +0 -1
- package/dist/webpack4.js +21 -19
- package/dist/webpack4.mjs +17 -15
- package/package.json +7 -8
- package/dist/chunk-2NRTWL47.js +0 -43
- package/dist/chunk-KBR4YB6N.js +0 -178
- package/dist/chunk-S2WEN6NJ.mjs +0 -175
|
@@ -0,0 +1,773 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defuOverrideArray
|
|
3
|
+
} from "./chunk-ZNKIYZRQ.mjs";
|
|
4
|
+
|
|
5
|
+
// src/context/tailwindcss.ts
|
|
6
|
+
import { createRequire as createRequire2 } from "module";
|
|
7
|
+
import path2 from "path";
|
|
8
|
+
import process2 from "process";
|
|
9
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
10
|
+
import { logger as logger2 } from "@weapp-tailwindcss/logger";
|
|
11
|
+
|
|
12
|
+
// src/tailwindcss/index.ts
|
|
13
|
+
import { getPackageInfoSync } from "local-pkg";
|
|
14
|
+
|
|
15
|
+
// src/tailwindcss/patcher.ts
|
|
16
|
+
import { existsSync } from "fs";
|
|
17
|
+
import { createRequire } from "module";
|
|
18
|
+
import path from "path";
|
|
19
|
+
import process from "process";
|
|
20
|
+
import { fileURLToPath } from "url";
|
|
21
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
22
|
+
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
23
|
+
import { TailwindcssPatcher } from "tailwindcss-patch";
|
|
24
|
+
var GENERIC_RELATIVE_SPECIFIERS = [".", ".."];
|
|
25
|
+
var DEFAULT_TAILWIND_CONFIG_SPECIFIERS = [
|
|
26
|
+
"stubs/config.full.js",
|
|
27
|
+
"defaultConfig.js"
|
|
28
|
+
];
|
|
29
|
+
function isPathSpecifier(specifier) {
|
|
30
|
+
if (!specifier) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (specifier.startsWith("file://")) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (path.isAbsolute(specifier)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return GENERIC_RELATIVE_SPECIFIERS.some((prefix) => specifier.startsWith(`${prefix}/`) || specifier.startsWith(`${prefix}\\`));
|
|
40
|
+
}
|
|
41
|
+
function resolveModuleFromPaths(specifier, paths) {
|
|
42
|
+
if (!specifier || isPathSpecifier(specifier) || paths.length === 0) {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const req = createRequire(import.meta.url);
|
|
47
|
+
return req.resolve(specifier, { paths });
|
|
48
|
+
} catch {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function resolveTailwindConfigFallback(packageName, paths) {
|
|
53
|
+
if (!packageName) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
for (const suffix of DEFAULT_TAILWIND_CONFIG_SPECIFIERS) {
|
|
57
|
+
const candidate = `${packageName}/${suffix}`;
|
|
58
|
+
const resolved = resolveModuleFromPaths(candidate, paths);
|
|
59
|
+
if (resolved) {
|
|
60
|
+
return resolved;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
function createFallbackTailwindcssPatcher() {
|
|
66
|
+
const packageInfo = {
|
|
67
|
+
name: "tailwindcss",
|
|
68
|
+
version: void 0,
|
|
69
|
+
rootPath: "",
|
|
70
|
+
packageJsonPath: "",
|
|
71
|
+
packageJson: {}
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
packageInfo,
|
|
75
|
+
async patch() {
|
|
76
|
+
return {
|
|
77
|
+
exposeContext: void 0,
|
|
78
|
+
extendLengthUnits: void 0
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
async getClassSet() {
|
|
82
|
+
return /* @__PURE__ */ new Set();
|
|
83
|
+
},
|
|
84
|
+
async extract(_options) {
|
|
85
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
86
|
+
return {
|
|
87
|
+
classList: [],
|
|
88
|
+
classSet
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
var hasLoggedMissingTailwind = false;
|
|
94
|
+
function findNearestPackageRoot(startDir) {
|
|
95
|
+
if (!startDir) {
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
let current = path.resolve(startDir);
|
|
99
|
+
while (true) {
|
|
100
|
+
const pkgPath = path.join(current, "package.json");
|
|
101
|
+
if (existsSync(pkgPath)) {
|
|
102
|
+
return current;
|
|
103
|
+
}
|
|
104
|
+
const parent = path.dirname(current);
|
|
105
|
+
if (parent === current) {
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
current = parent;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function appendNodeModules(paths, dir) {
|
|
112
|
+
if (!dir) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const nodeModulesDir = path.join(dir, "node_modules");
|
|
116
|
+
if (existsSync(nodeModulesDir)) {
|
|
117
|
+
paths.add(nodeModulesDir);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
var TAILWIND_CONFIG_FILES = [
|
|
121
|
+
"tailwind.config.js",
|
|
122
|
+
"tailwind.config.cjs",
|
|
123
|
+
"tailwind.config.mjs",
|
|
124
|
+
"tailwind.config.ts",
|
|
125
|
+
"tailwind.config.cts",
|
|
126
|
+
"tailwind.config.mts"
|
|
127
|
+
];
|
|
128
|
+
function findTailwindConfig(searchRoots) {
|
|
129
|
+
for (const root of searchRoots) {
|
|
130
|
+
for (const file of TAILWIND_CONFIG_FILES) {
|
|
131
|
+
const candidate = path.resolve(root, file);
|
|
132
|
+
if (existsSync(candidate)) {
|
|
133
|
+
return candidate;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
function createDefaultResolvePaths(basedir) {
|
|
140
|
+
const paths = /* @__PURE__ */ new Set();
|
|
141
|
+
let fallbackCandidates = [];
|
|
142
|
+
if (basedir) {
|
|
143
|
+
const resolvedBase = path.resolve(basedir);
|
|
144
|
+
appendNodeModules(paths, resolvedBase);
|
|
145
|
+
fallbackCandidates.push(resolvedBase);
|
|
146
|
+
const packageRoot = findNearestPackageRoot(resolvedBase);
|
|
147
|
+
if (packageRoot) {
|
|
148
|
+
appendNodeModules(paths, packageRoot);
|
|
149
|
+
fallbackCandidates.push(packageRoot);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const cwd = process.cwd();
|
|
153
|
+
appendNodeModules(paths, cwd);
|
|
154
|
+
try {
|
|
155
|
+
const modulePath = fileURLToPath(import.meta.url);
|
|
156
|
+
const candidate = existsSync(modulePath) && !path.extname(modulePath) ? modulePath : path.dirname(modulePath);
|
|
157
|
+
paths.add(candidate);
|
|
158
|
+
} catch {
|
|
159
|
+
paths.add(import.meta.url);
|
|
160
|
+
}
|
|
161
|
+
if (paths.size === 0) {
|
|
162
|
+
fallbackCandidates = fallbackCandidates.filter(Boolean);
|
|
163
|
+
if (fallbackCandidates.length === 0) {
|
|
164
|
+
fallbackCandidates.push(cwd);
|
|
165
|
+
}
|
|
166
|
+
for (const candidate of fallbackCandidates) {
|
|
167
|
+
paths.add(candidate);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return [...paths];
|
|
171
|
+
}
|
|
172
|
+
function normalizeExtendLengthUnits(value) {
|
|
173
|
+
if (value === false) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
if (value === true) {
|
|
177
|
+
return { enabled: true };
|
|
178
|
+
}
|
|
179
|
+
if (value && typeof value === "object") {
|
|
180
|
+
return {
|
|
181
|
+
enabled: true,
|
|
182
|
+
...value
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
function normalizeTailwindcssPatcherOptions(options) {
|
|
188
|
+
if (!options) {
|
|
189
|
+
return void 0;
|
|
190
|
+
}
|
|
191
|
+
if ("patch" in options) {
|
|
192
|
+
const { cache, patch } = options;
|
|
193
|
+
const normalized = {};
|
|
194
|
+
if (cache !== void 0) {
|
|
195
|
+
normalized.cache = cache;
|
|
196
|
+
}
|
|
197
|
+
if (patch?.overwrite !== void 0) {
|
|
198
|
+
normalized.overwrite = patch.overwrite;
|
|
199
|
+
}
|
|
200
|
+
if (patch?.filter) {
|
|
201
|
+
normalized.filter = patch.filter;
|
|
202
|
+
}
|
|
203
|
+
const extendLengthUnits = normalizeExtendLengthUnits(patch?.applyPatches?.extendLengthUnits);
|
|
204
|
+
const exposeContext = patch?.applyPatches?.exportContext;
|
|
205
|
+
if (extendLengthUnits !== void 0 || exposeContext !== void 0) {
|
|
206
|
+
normalized.features = {
|
|
207
|
+
exposeContext,
|
|
208
|
+
extendLengthUnits
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const cwd = patch?.cwd ?? patch?.basedir;
|
|
212
|
+
if (cwd) {
|
|
213
|
+
normalized.cwd = cwd;
|
|
214
|
+
}
|
|
215
|
+
const tailwindOptions = patch?.tailwindcss ? { ...patch.tailwindcss } : void 0;
|
|
216
|
+
const legacyResolve = patch?.resolve;
|
|
217
|
+
let nextTailwindOptions = tailwindOptions;
|
|
218
|
+
if (nextTailwindOptions?.version === 2 && !nextTailwindOptions.packageName) {
|
|
219
|
+
nextTailwindOptions = {
|
|
220
|
+
...nextTailwindOptions,
|
|
221
|
+
packageName: "@tailwindcss/postcss7-compat",
|
|
222
|
+
postcssPlugin: nextTailwindOptions.postcssPlugin
|
|
223
|
+
};
|
|
224
|
+
if (!nextTailwindOptions.postcssPlugin) {
|
|
225
|
+
nextTailwindOptions.postcssPlugin = "@tailwindcss/postcss7-compat";
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (nextTailwindOptions || legacyResolve) {
|
|
229
|
+
const resolveOptions = nextTailwindOptions?.resolve;
|
|
230
|
+
const mergedResolve = legacyResolve || resolveOptions ? {
|
|
231
|
+
...resolveOptions ?? {},
|
|
232
|
+
...legacyResolve ?? {}
|
|
233
|
+
} : void 0;
|
|
234
|
+
normalized.tailwind = {
|
|
235
|
+
...nextTailwindOptions ?? {},
|
|
236
|
+
...mergedResolve ? { resolve: mergedResolve } : {}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return normalized;
|
|
240
|
+
}
|
|
241
|
+
return options;
|
|
242
|
+
}
|
|
243
|
+
function createTailwindcssPatcher(options) {
|
|
244
|
+
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
245
|
+
const cache = {};
|
|
246
|
+
if (cacheDir) {
|
|
247
|
+
if (path.isAbsolute(cacheDir)) {
|
|
248
|
+
cache.dir = cacheDir;
|
|
249
|
+
} else if (basedir) {
|
|
250
|
+
cache.dir = path.resolve(basedir, cacheDir);
|
|
251
|
+
} else {
|
|
252
|
+
cache.dir = path.resolve(process.cwd(), cacheDir);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (basedir) {
|
|
256
|
+
cache.cwd = basedir;
|
|
257
|
+
}
|
|
258
|
+
const resolvePaths = createDefaultResolvePaths(cache.cwd ?? basedir ?? process.cwd());
|
|
259
|
+
const normalizedUserOptions = normalizeTailwindcssPatcherOptions(tailwindcssPatcherOptions);
|
|
260
|
+
const extendLengthUnits = normalizeExtendLengthUnits(supportCustomLengthUnitsPatch);
|
|
261
|
+
const baseTailwindOptions = defuOverrideArray2(
|
|
262
|
+
tailwindcss ?? {},
|
|
263
|
+
{
|
|
264
|
+
cwd: basedir,
|
|
265
|
+
resolve: {
|
|
266
|
+
paths: resolvePaths
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
if (baseTailwindOptions.version === 2) {
|
|
271
|
+
if (!baseTailwindOptions.packageName) {
|
|
272
|
+
baseTailwindOptions.packageName = "@tailwindcss/postcss7-compat";
|
|
273
|
+
}
|
|
274
|
+
if (!baseTailwindOptions.postcssPlugin) {
|
|
275
|
+
baseTailwindOptions.postcssPlugin = "@tailwindcss/postcss7-compat";
|
|
276
|
+
}
|
|
277
|
+
} else if (!baseTailwindOptions.packageName) {
|
|
278
|
+
baseTailwindOptions.packageName = "tailwindcss";
|
|
279
|
+
}
|
|
280
|
+
if (!baseTailwindOptions.postcssPlugin) {
|
|
281
|
+
baseTailwindOptions.postcssPlugin = baseTailwindOptions.version === 4 ? "@tailwindcss/postcss" : "tailwindcss";
|
|
282
|
+
}
|
|
283
|
+
if (typeof baseTailwindOptions.postcssPlugin === "string") {
|
|
284
|
+
const resolvedPlugin = resolveModuleFromPaths(baseTailwindOptions.postcssPlugin, resolvePaths);
|
|
285
|
+
if (resolvedPlugin) {
|
|
286
|
+
baseTailwindOptions.postcssPlugin = resolvedPlugin;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const baseOptions = {
|
|
290
|
+
cwd: basedir,
|
|
291
|
+
cache,
|
|
292
|
+
tailwind: baseTailwindOptions,
|
|
293
|
+
features: {
|
|
294
|
+
exposeContext: true,
|
|
295
|
+
extendLengthUnits
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
const resolvedOptions = defuOverrideArray2(
|
|
299
|
+
normalizedUserOptions ?? {},
|
|
300
|
+
baseOptions
|
|
301
|
+
);
|
|
302
|
+
if (resolvedOptions.tailwind) {
|
|
303
|
+
const existingResolve = resolvedOptions.tailwind.resolve ?? {};
|
|
304
|
+
const customPaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0;
|
|
305
|
+
const sourcePaths = customPaths ? existingResolve.paths : resolvePaths;
|
|
306
|
+
resolvedOptions.tailwind.resolve = {
|
|
307
|
+
...existingResolve,
|
|
308
|
+
paths: Array.from(new Set(sourcePaths))
|
|
309
|
+
};
|
|
310
|
+
logger.debug("Tailwind resolve config %O", {
|
|
311
|
+
packageName: resolvedOptions.tailwind.packageName,
|
|
312
|
+
version: resolvedOptions.tailwind.version,
|
|
313
|
+
resolve: resolvedOptions.tailwind.resolve,
|
|
314
|
+
cwd: resolvedOptions.tailwind.cwd
|
|
315
|
+
});
|
|
316
|
+
if (typeof resolvedOptions.tailwind.postcssPlugin === "string") {
|
|
317
|
+
const resolvedPlugin = resolveModuleFromPaths(
|
|
318
|
+
resolvedOptions.tailwind.postcssPlugin,
|
|
319
|
+
resolvedOptions.tailwind.resolve?.paths ?? resolvePaths
|
|
320
|
+
);
|
|
321
|
+
if (resolvedPlugin) {
|
|
322
|
+
resolvedOptions.tailwind.postcssPlugin = resolvedPlugin;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const searchRoots = /* @__PURE__ */ new Set();
|
|
326
|
+
if (resolvedOptions.tailwind.cwd) {
|
|
327
|
+
searchRoots.add(resolvedOptions.tailwind.cwd);
|
|
328
|
+
}
|
|
329
|
+
for (const resolvePath of resolvedOptions.tailwind.resolve?.paths ?? []) {
|
|
330
|
+
const parentDir = path.dirname(resolvePath);
|
|
331
|
+
searchRoots.add(parentDir);
|
|
332
|
+
}
|
|
333
|
+
const configPath = findTailwindConfig(searchRoots);
|
|
334
|
+
if (!resolvedOptions.tailwind.config) {
|
|
335
|
+
if (configPath) {
|
|
336
|
+
resolvedOptions.tailwind.config = configPath;
|
|
337
|
+
} else {
|
|
338
|
+
const fallbackConfig = resolveTailwindConfigFallback(
|
|
339
|
+
resolvedOptions.tailwind.packageName,
|
|
340
|
+
resolvedOptions.tailwind.resolve.paths ?? resolvePaths
|
|
341
|
+
);
|
|
342
|
+
if (fallbackConfig) {
|
|
343
|
+
resolvedOptions.tailwind.config = fallbackConfig;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (!resolvedOptions.tailwind.cwd && configPath) {
|
|
348
|
+
resolvedOptions.tailwind.cwd = path.dirname(configPath);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
return new TailwindcssPatcher(resolvedOptions);
|
|
353
|
+
} catch (error) {
|
|
354
|
+
const searchPaths = resolvedOptions.tailwind?.resolve?.paths;
|
|
355
|
+
if (error instanceof Error && /tailwindcss not found/i.test(error.message)) {
|
|
356
|
+
if (!hasLoggedMissingTailwind) {
|
|
357
|
+
logger.warn("Tailwind CSS \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7 Tailwind \u76F8\u5173\u8865\u4E01\u3002\u82E5\u9700\u4F7F\u7528 Tailwind \u80FD\u529B\uFF0C\u8BF7\u5B89\u88C5 tailwindcss\u3002");
|
|
358
|
+
hasLoggedMissingTailwind = true;
|
|
359
|
+
}
|
|
360
|
+
return createFallbackTailwindcssPatcher();
|
|
361
|
+
}
|
|
362
|
+
if (error instanceof Error && /unable to locate tailwind css package/i.test(error.message)) {
|
|
363
|
+
logger.error('\u65E0\u6CD5\u5B9A\u4F4D Tailwind CSS \u5305 "%s"\uFF0C\u5DF2\u5C1D\u8BD5\u8DEF\u5F84: %O', resolvedOptions.tailwind?.packageName, searchPaths);
|
|
364
|
+
}
|
|
365
|
+
throw error;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/context/tailwindcss.ts
|
|
370
|
+
var ENV_BASEDIR_KEYS = [
|
|
371
|
+
"WEAPP_TAILWINDCSS_BASEDIR",
|
|
372
|
+
"WEAPP_TAILWINDCSS_BASE_DIR",
|
|
373
|
+
"TAILWINDCSS_BASEDIR",
|
|
374
|
+
"TAILWINDCSS_BASE_DIR",
|
|
375
|
+
"UNI_INPUT_DIR",
|
|
376
|
+
"UNI_INPUT_ROOT",
|
|
377
|
+
"UNI_CLI_ROOT",
|
|
378
|
+
"UNI_APP_INPUT_DIR",
|
|
379
|
+
"INIT_CWD",
|
|
380
|
+
"PWD"
|
|
381
|
+
];
|
|
382
|
+
var GENERIC_ENV_BASEDIR_KEYS = /* @__PURE__ */ new Set(["INIT_CWD", "PWD"]);
|
|
383
|
+
function pickEnvBasedir() {
|
|
384
|
+
for (const key of ENV_BASEDIR_KEYS) {
|
|
385
|
+
const value = process2.env[key];
|
|
386
|
+
if (value && path2.isAbsolute(value)) {
|
|
387
|
+
return { key, value };
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return void 0;
|
|
391
|
+
}
|
|
392
|
+
function pickPackageEnvBasedir() {
|
|
393
|
+
const packageJsonPath = process2.env.npm_package_json;
|
|
394
|
+
if (packageJsonPath) {
|
|
395
|
+
const packageDir = path2.dirname(packageJsonPath);
|
|
396
|
+
if (packageDir && path2.isAbsolute(packageDir)) {
|
|
397
|
+
return packageDir;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const localPrefix = process2.env.npm_config_local_prefix;
|
|
401
|
+
if (localPrefix && path2.isAbsolute(localPrefix)) {
|
|
402
|
+
return localPrefix;
|
|
403
|
+
}
|
|
404
|
+
return void 0;
|
|
405
|
+
}
|
|
406
|
+
function detectCallerBasedir() {
|
|
407
|
+
const stack = new Error("resolveTailwindcssBasedir stack probe").stack;
|
|
408
|
+
if (!stack) {
|
|
409
|
+
return void 0;
|
|
410
|
+
}
|
|
411
|
+
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
412
|
+
logger2.debug("caller stack: %s", stack);
|
|
413
|
+
}
|
|
414
|
+
const lines = stack.split("\n");
|
|
415
|
+
for (const line of lines) {
|
|
416
|
+
const match = line.match(/\(([^)]+)\)/u) ?? line.match(/at\s+(\S.*)$/u);
|
|
417
|
+
const location = match?.[1];
|
|
418
|
+
if (!location) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
let filePath = location;
|
|
422
|
+
if (filePath.startsWith("file://")) {
|
|
423
|
+
try {
|
|
424
|
+
filePath = fileURLToPath2(filePath);
|
|
425
|
+
} catch {
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const [candidate] = filePath.split(":");
|
|
430
|
+
const resolvedPath = path2.isAbsolute(filePath) ? filePath : candidate;
|
|
431
|
+
if (!path2.isAbsolute(resolvedPath)) {
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (resolvedPath.includes("node_modules") && resolvedPath.includes("weapp-tailwindcss")) {
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
try {
|
|
438
|
+
return path2.dirname(resolvedPath);
|
|
439
|
+
} catch {
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return void 0;
|
|
444
|
+
}
|
|
445
|
+
function resolveTailwindcssBasedir(basedir) {
|
|
446
|
+
const envBasedirResult = pickEnvBasedir();
|
|
447
|
+
const envBasedir = envBasedirResult?.value;
|
|
448
|
+
const envBasedirKey = envBasedirResult?.key;
|
|
449
|
+
const envBasedirIsGeneric = envBasedirKey ? GENERIC_ENV_BASEDIR_KEYS.has(envBasedirKey) : false;
|
|
450
|
+
const packageEnvBasedir = pickPackageEnvBasedir();
|
|
451
|
+
const shouldDetectCaller = !envBasedir || envBasedirIsGeneric;
|
|
452
|
+
const callerBasedir = shouldDetectCaller ? detectCallerBasedir() : void 0;
|
|
453
|
+
const anchor = envBasedir ?? packageEnvBasedir ?? callerBasedir ?? process2.cwd();
|
|
454
|
+
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
455
|
+
logger2.debug("resolveTailwindcssBasedir anchor %O", {
|
|
456
|
+
basedir,
|
|
457
|
+
envBasedir,
|
|
458
|
+
envBasedirKey,
|
|
459
|
+
envBasedirIsGeneric,
|
|
460
|
+
packageEnvBasedir,
|
|
461
|
+
callerBasedir,
|
|
462
|
+
npm_package_json: process2.env.npm_package_json,
|
|
463
|
+
cwd: process2.cwd(),
|
|
464
|
+
anchor
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
if (basedir && basedir.trim().length > 0) {
|
|
468
|
+
if (path2.isAbsolute(basedir)) {
|
|
469
|
+
return path2.normalize(basedir);
|
|
470
|
+
}
|
|
471
|
+
return path2.resolve(anchor, basedir);
|
|
472
|
+
}
|
|
473
|
+
if (envBasedir && !envBasedirIsGeneric) {
|
|
474
|
+
return path2.normalize(envBasedir);
|
|
475
|
+
}
|
|
476
|
+
if (packageEnvBasedir) {
|
|
477
|
+
return path2.normalize(packageEnvBasedir);
|
|
478
|
+
}
|
|
479
|
+
if (callerBasedir) {
|
|
480
|
+
const normalizedCaller = path2.normalize(callerBasedir);
|
|
481
|
+
const librarySegment = `${path2.sep}weapp-tailwindcss${path2.sep}`;
|
|
482
|
+
if (!normalizedCaller.includes(librarySegment)) {
|
|
483
|
+
return normalizedCaller;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (envBasedir) {
|
|
487
|
+
return path2.normalize(envBasedir);
|
|
488
|
+
}
|
|
489
|
+
const packageName = process2.env.PNPM_PACKAGE_NAME;
|
|
490
|
+
if (packageName) {
|
|
491
|
+
try {
|
|
492
|
+
const anchorRequire = createRequire2(path2.join(anchor, "__resolve_tailwindcss_basedir__.cjs"));
|
|
493
|
+
const packageJsonPath = anchorRequire.resolve(`${packageName}/package.json`);
|
|
494
|
+
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
495
|
+
logger2.debug("package basedir resolved from PNPM_PACKAGE_NAME: %s", packageJsonPath);
|
|
496
|
+
}
|
|
497
|
+
return path2.normalize(path2.dirname(packageJsonPath));
|
|
498
|
+
} catch {
|
|
499
|
+
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
500
|
+
logger2.debug("failed to resolve package json for %s", packageName);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return path2.normalize(process2.cwd());
|
|
505
|
+
}
|
|
506
|
+
function normalizeCssEntries(entries, anchor) {
|
|
507
|
+
if (!entries || entries.length === 0) {
|
|
508
|
+
return void 0;
|
|
509
|
+
}
|
|
510
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
511
|
+
for (const entry of entries) {
|
|
512
|
+
if (typeof entry !== "string") {
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
const trimmed = entry.trim();
|
|
516
|
+
if (trimmed.length === 0) {
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
const resolved = path2.isAbsolute(trimmed) ? path2.normalize(trimmed) : path2.normalize(path2.resolve(anchor, trimmed));
|
|
520
|
+
normalized.add(resolved);
|
|
521
|
+
}
|
|
522
|
+
return normalized.size > 0 ? [...normalized] : void 0;
|
|
523
|
+
}
|
|
524
|
+
function groupCssEntriesByBase(entries) {
|
|
525
|
+
const groups = /* @__PURE__ */ new Map();
|
|
526
|
+
for (const entry of entries) {
|
|
527
|
+
const baseDir = path2.normalize(path2.dirname(entry));
|
|
528
|
+
const bucket = groups.get(baseDir);
|
|
529
|
+
if (bucket) {
|
|
530
|
+
bucket.push(entry);
|
|
531
|
+
} else {
|
|
532
|
+
groups.set(baseDir, [entry]);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return groups;
|
|
536
|
+
}
|
|
537
|
+
function overrideTailwindcssPatcherOptionsForBase(options, baseDir, cssEntries) {
|
|
538
|
+
if (!options) {
|
|
539
|
+
return options;
|
|
540
|
+
}
|
|
541
|
+
if ("patch" in options) {
|
|
542
|
+
const patchOptions = options.patch;
|
|
543
|
+
if (!patchOptions) {
|
|
544
|
+
return options;
|
|
545
|
+
}
|
|
546
|
+
const nextPatch = {
|
|
547
|
+
...patchOptions,
|
|
548
|
+
basedir: baseDir,
|
|
549
|
+
cwd: patchOptions.cwd ?? baseDir
|
|
550
|
+
};
|
|
551
|
+
if (patchOptions.tailwindcss) {
|
|
552
|
+
nextPatch.tailwindcss = {
|
|
553
|
+
...patchOptions.tailwindcss,
|
|
554
|
+
v4: {
|
|
555
|
+
...patchOptions.tailwindcss.v4 ?? {},
|
|
556
|
+
base: baseDir,
|
|
557
|
+
cssEntries
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
...options,
|
|
563
|
+
patch: nextPatch
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
if (!options.tailwind) {
|
|
567
|
+
return options;
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
...options,
|
|
571
|
+
tailwind: {
|
|
572
|
+
...options.tailwind,
|
|
573
|
+
v4: {
|
|
574
|
+
...options.tailwind.v4 ?? {},
|
|
575
|
+
base: baseDir,
|
|
576
|
+
cssEntries
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function createPatcherForBase(baseDir, cssEntries, options) {
|
|
582
|
+
const {
|
|
583
|
+
tailwindcss,
|
|
584
|
+
tailwindcssPatcherOptions,
|
|
585
|
+
supportCustomLengthUnitsPatch,
|
|
586
|
+
appType
|
|
587
|
+
} = options;
|
|
588
|
+
const defaultTailwindcssConfig = {
|
|
589
|
+
cwd: baseDir,
|
|
590
|
+
v2: {
|
|
591
|
+
cwd: baseDir
|
|
592
|
+
},
|
|
593
|
+
v3: {
|
|
594
|
+
cwd: baseDir
|
|
595
|
+
},
|
|
596
|
+
v4: {
|
|
597
|
+
base: baseDir,
|
|
598
|
+
cssEntries
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
if (cssEntries?.length && (tailwindcss == null || tailwindcss.version == null)) {
|
|
602
|
+
defaultTailwindcssConfig.version = 4;
|
|
603
|
+
}
|
|
604
|
+
const mergedTailwindOptions = defuOverrideArray(
|
|
605
|
+
tailwindcss ?? {},
|
|
606
|
+
defaultTailwindcssConfig
|
|
607
|
+
);
|
|
608
|
+
if (!mergedTailwindOptions.v4) {
|
|
609
|
+
mergedTailwindOptions.v4 = {
|
|
610
|
+
base: baseDir,
|
|
611
|
+
cssEntries: cssEntries ?? []
|
|
612
|
+
};
|
|
613
|
+
} else {
|
|
614
|
+
mergedTailwindOptions.v4.base = baseDir;
|
|
615
|
+
if (cssEntries?.length) {
|
|
616
|
+
mergedTailwindOptions.v4.cssEntries = cssEntries;
|
|
617
|
+
} else if (!mergedTailwindOptions.v4.cssEntries) {
|
|
618
|
+
mergedTailwindOptions.v4.cssEntries = [];
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
const patchedOptions = overrideTailwindcssPatcherOptionsForBase(
|
|
622
|
+
tailwindcssPatcherOptions,
|
|
623
|
+
baseDir,
|
|
624
|
+
cssEntries ?? []
|
|
625
|
+
);
|
|
626
|
+
return createTailwindcssPatcher({
|
|
627
|
+
basedir: baseDir,
|
|
628
|
+
cacheDir: appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0,
|
|
629
|
+
supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
|
|
630
|
+
tailwindcss: mergedTailwindOptions,
|
|
631
|
+
tailwindcssPatcherOptions: patchedOptions
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
function createMultiTailwindcssPatcher(patchers) {
|
|
635
|
+
if (patchers.length <= 1) {
|
|
636
|
+
return patchers[0];
|
|
637
|
+
}
|
|
638
|
+
const [first] = patchers;
|
|
639
|
+
const multiPatcher = {
|
|
640
|
+
packageInfo: first?.packageInfo,
|
|
641
|
+
majorVersion: first?.majorVersion,
|
|
642
|
+
options: first?.options,
|
|
643
|
+
async patch() {
|
|
644
|
+
let exposeContext;
|
|
645
|
+
let extendLengthUnits;
|
|
646
|
+
for (const patcher of patchers) {
|
|
647
|
+
const result = await patcher.patch();
|
|
648
|
+
if (result?.exposeContext && exposeContext == null) {
|
|
649
|
+
exposeContext = result.exposeContext;
|
|
650
|
+
}
|
|
651
|
+
if (result?.extendLengthUnits && extendLengthUnits == null) {
|
|
652
|
+
extendLengthUnits = result.extendLengthUnits;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return {
|
|
656
|
+
exposeContext,
|
|
657
|
+
extendLengthUnits
|
|
658
|
+
};
|
|
659
|
+
},
|
|
660
|
+
async getClassSet() {
|
|
661
|
+
const aggregated = /* @__PURE__ */ new Set();
|
|
662
|
+
for (const patcher of patchers) {
|
|
663
|
+
const current = await patcher.getClassSet();
|
|
664
|
+
for (const className of current) {
|
|
665
|
+
aggregated.add(className);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return aggregated;
|
|
669
|
+
},
|
|
670
|
+
async extract(options) {
|
|
671
|
+
const aggregatedSet = /* @__PURE__ */ new Set();
|
|
672
|
+
const aggregatedList = [];
|
|
673
|
+
let filename;
|
|
674
|
+
for (const patcher of patchers) {
|
|
675
|
+
const result = await patcher.extract(options);
|
|
676
|
+
if (!result) {
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
if (filename === void 0 && result.filename) {
|
|
680
|
+
filename = result.filename;
|
|
681
|
+
}
|
|
682
|
+
if (result.classList) {
|
|
683
|
+
for (const className of result.classList) {
|
|
684
|
+
if (!aggregatedSet.has(className)) {
|
|
685
|
+
aggregatedList.push(className);
|
|
686
|
+
}
|
|
687
|
+
aggregatedSet.add(className);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
if (result.classSet) {
|
|
691
|
+
for (const className of result.classSet) {
|
|
692
|
+
aggregatedSet.add(className);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return {
|
|
697
|
+
classList: aggregatedList,
|
|
698
|
+
classSet: aggregatedSet,
|
|
699
|
+
filename
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
if (patchers.every((patcher) => typeof patcher.getClassSetSync === "function")) {
|
|
704
|
+
multiPatcher.getClassSetSync = () => {
|
|
705
|
+
const aggregated = /* @__PURE__ */ new Set();
|
|
706
|
+
for (const patcher of patchers) {
|
|
707
|
+
const current = patcher.getClassSetSync?.();
|
|
708
|
+
if (!current) {
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
for (const className of current) {
|
|
712
|
+
aggregated.add(className);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return aggregated;
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
return multiPatcher;
|
|
719
|
+
}
|
|
720
|
+
function tryCreateMultiTailwindcssPatcher(cssEntries, options) {
|
|
721
|
+
const groups = groupCssEntriesByBase(cssEntries);
|
|
722
|
+
if (groups.size <= 1) {
|
|
723
|
+
return void 0;
|
|
724
|
+
}
|
|
725
|
+
logger2.debug("detected multiple Tailwind CSS entry bases: %O", [...groups.keys()]);
|
|
726
|
+
const patchers = [];
|
|
727
|
+
for (const [baseDir, entries] of groups) {
|
|
728
|
+
patchers.push(createPatcherForBase(baseDir, entries, options));
|
|
729
|
+
}
|
|
730
|
+
return createMultiTailwindcssPatcher(patchers);
|
|
731
|
+
}
|
|
732
|
+
function createTailwindcssPatcherFromContext(ctx) {
|
|
733
|
+
const {
|
|
734
|
+
tailwindcssBasedir,
|
|
735
|
+
supportCustomLengthUnitsPatch,
|
|
736
|
+
tailwindcss,
|
|
737
|
+
tailwindcssPatcherOptions,
|
|
738
|
+
cssEntries: rawCssEntries,
|
|
739
|
+
appType
|
|
740
|
+
} = ctx;
|
|
741
|
+
const resolvedTailwindcssBasedir = resolveTailwindcssBasedir(tailwindcssBasedir);
|
|
742
|
+
ctx.tailwindcssBasedir = resolvedTailwindcssBasedir;
|
|
743
|
+
logger2.debug("tailwindcss basedir resolved: %s", resolvedTailwindcssBasedir);
|
|
744
|
+
const normalizedCssEntries = normalizeCssEntries(rawCssEntries, resolvedTailwindcssBasedir);
|
|
745
|
+
if (normalizedCssEntries) {
|
|
746
|
+
ctx.cssEntries = normalizedCssEntries;
|
|
747
|
+
}
|
|
748
|
+
const multiPatcher = normalizedCssEntries ? tryCreateMultiTailwindcssPatcher(normalizedCssEntries, {
|
|
749
|
+
tailwindcss,
|
|
750
|
+
tailwindcssPatcherOptions,
|
|
751
|
+
supportCustomLengthUnitsPatch,
|
|
752
|
+
appType
|
|
753
|
+
}) : void 0;
|
|
754
|
+
if (multiPatcher) {
|
|
755
|
+
return multiPatcher;
|
|
756
|
+
}
|
|
757
|
+
const effectiveCssEntries = normalizedCssEntries ?? rawCssEntries;
|
|
758
|
+
return createPatcherForBase(
|
|
759
|
+
resolvedTailwindcssBasedir,
|
|
760
|
+
effectiveCssEntries,
|
|
761
|
+
{
|
|
762
|
+
tailwindcss,
|
|
763
|
+
tailwindcssPatcherOptions,
|
|
764
|
+
supportCustomLengthUnitsPatch,
|
|
765
|
+
appType
|
|
766
|
+
}
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
export {
|
|
771
|
+
resolveTailwindcssBasedir,
|
|
772
|
+
createTailwindcssPatcherFromContext
|
|
773
|
+
};
|