weapp-tailwindcss 4.8.7 → 4.8.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.
- package/dist/chunk-2E724WCE.js +138 -0
- package/dist/{chunk-7BASRP3P.js → chunk-2KZ4VTIA.js} +18 -116
- package/dist/{chunk-ZB6MFKXJ.mjs → chunk-3IP5JCFZ.mjs} +1 -1
- package/dist/{chunk-ZSTF2AEN.js → chunk-3URI7W6X.js} +11 -1
- package/dist/{chunk-3XGTIDA6.mjs → chunk-6TO3GT5S.mjs} +476 -190
- package/dist/chunk-BYXBJQAS.js +1 -0
- package/dist/{chunk-WUJAJ42W.js → chunk-E7PFK6BW.js} +120 -47
- package/dist/{chunk-YQQ3HDQD.mjs → chunk-FB3ASCHC.mjs} +2 -2
- package/dist/{chunk-KRRIFURM.mjs → chunk-IH3HQU7U.mjs} +191 -127
- package/dist/{chunk-5F64FE7K.js → chunk-L5ER4544.js} +5 -5
- package/dist/{chunk-GORSBZA2.js → chunk-M4NERJO7.js} +1 -1
- package/dist/{chunk-JYHBNTYH.mjs → chunk-M5UEOYBI.mjs} +2 -2
- package/dist/{chunk-ESYZLHZI.js → chunk-P3AQCOOM.js} +471 -185
- package/dist/chunk-PVJDRL3I.mjs +138 -0
- package/dist/{chunk-DKPIYG24.mjs → chunk-QF65JGNW.mjs} +11 -1
- package/dist/{chunk-BMUQ4OAB.mjs → chunk-RUXC4E2M.mjs} +7 -105
- package/dist/{chunk-JW7P34IH.mjs → chunk-RYGPCUUT.mjs} +65 -58
- package/dist/{chunk-MIC6E7DV.mjs → chunk-UTCO4JMJ.mjs} +102 -29
- package/dist/{chunk-VONLQCG7.js → chunk-WF4UE272.js} +211 -147
- package/dist/{chunk-322IEI2K.js → chunk-XHR5K5ZT.js} +57 -51
- package/dist/{chunk-U4WEDSBF.js → chunk-Y5XG47XY.js} +7 -7
- package/dist/cli.js +39 -32
- package/dist/cli.mjs +12 -5
- package/dist/core.js +11 -11
- package/dist/core.mjs +5 -5
- 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.js +3 -3
- package/dist/defaults.mjs +2 -2
- package/dist/gulp.js +7 -7
- package/dist/gulp.mjs +6 -6
- package/dist/index.js +11 -11
- package/dist/index.mjs +10 -10
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.js +4 -4
- package/dist/presets.mjs +2 -2
- package/dist/reset.js +1 -1
- package/dist/reset.mjs +1 -1
- package/dist/types.d.mts +7 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.js +8 -8
- package/dist/vite.mjs +7 -7
- package/dist/{weapp-tw-runtime-loader.js → weapp-tw-css-import-rewrite-loader.js} +49 -18
- package/dist/weapp-tw-runtime-classset-loader.js +23 -0
- package/dist/webpack.d.mts +0 -1
- package/dist/webpack.d.ts +0 -1
- package/dist/webpack.js +9 -9
- package/dist/webpack.mjs +8 -8
- package/dist/webpack4.d.mts +0 -1
- package/dist/webpack4.d.ts +0 -1
- package/dist/webpack4.js +124 -48
- package/dist/webpack4.mjs +106 -30
- package/package.json +3 -3
- package/dist/chunk-PFUB74BL.mjs +0 -61
- package/dist/chunk-WYXD5IW7.js +0 -61
|
@@ -3,11 +3,12 @@ import {
|
|
|
3
3
|
} from "./chunk-ZNKIYZRQ.mjs";
|
|
4
4
|
|
|
5
5
|
// src/context/tailwindcss.ts
|
|
6
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
6
7
|
import { createRequire as createRequire2 } from "module";
|
|
7
|
-
import
|
|
8
|
+
import path6 from "path";
|
|
8
9
|
import process2 from "process";
|
|
9
10
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
10
|
-
import { logger as
|
|
11
|
+
import { logger as logger4 } from "@weapp-tailwindcss/logger";
|
|
11
12
|
|
|
12
13
|
// src/context/workspace.ts
|
|
13
14
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
@@ -93,16 +94,235 @@ function findWorkspacePackageDir(rootDir, packageName) {
|
|
|
93
94
|
return void 0;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
// src/tailwindcss/
|
|
97
|
-
import {
|
|
97
|
+
// src/tailwindcss/v4/config.ts
|
|
98
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
99
|
+
var DEFAULT_CSS_CALC_CUSTOM_PROPERTIES = [];
|
|
100
|
+
function includesToken(list, token) {
|
|
101
|
+
return list.some((candidate) => {
|
|
102
|
+
if (typeof token === "string") {
|
|
103
|
+
if (typeof candidate === "string") {
|
|
104
|
+
return candidate === token;
|
|
105
|
+
}
|
|
106
|
+
candidate.lastIndex = 0;
|
|
107
|
+
return candidate.test(token);
|
|
108
|
+
}
|
|
109
|
+
if (typeof candidate === "string") {
|
|
110
|
+
token.lastIndex = 0;
|
|
111
|
+
return token.test(candidate);
|
|
112
|
+
}
|
|
113
|
+
return candidate.source === token.source && candidate.flags === token.flags;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function ensureDefaultsIncluded(value) {
|
|
117
|
+
if (value === true) {
|
|
118
|
+
return {
|
|
119
|
+
includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES]
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) {
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(value, token));
|
|
127
|
+
return missing.length > 0 ? [...value, ...missing] : value;
|
|
128
|
+
}
|
|
129
|
+
if (value && typeof value === "object") {
|
|
130
|
+
const include = value.includeCustomProperties;
|
|
131
|
+
if (!Array.isArray(include)) {
|
|
132
|
+
return {
|
|
133
|
+
...value,
|
|
134
|
+
includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES]
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) {
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(include, token));
|
|
141
|
+
return missing.length > 0 ? {
|
|
142
|
+
...value,
|
|
143
|
+
includeCustomProperties: [...include, ...missing]
|
|
144
|
+
} : value;
|
|
145
|
+
}
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
function normalizeCssEntriesConfig(entries) {
|
|
149
|
+
if (!entries) {
|
|
150
|
+
return void 0;
|
|
151
|
+
}
|
|
152
|
+
if (typeof entries === "string") {
|
|
153
|
+
const trimmed = entries.trim();
|
|
154
|
+
return trimmed ? [trimmed] : void 0;
|
|
155
|
+
}
|
|
156
|
+
if (!Array.isArray(entries)) {
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
const normalized = entries.map((entry) => typeof entry === "string" ? entry.trim() : "").filter((entry) => entry.length > 0);
|
|
160
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
161
|
+
}
|
|
162
|
+
function hasConfiguredCssEntries(ctx) {
|
|
163
|
+
if (normalizeCssEntriesConfig(ctx.cssEntries)) {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
if (normalizeCssEntriesConfig(ctx.tailwindcss?.v4?.cssEntries)) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
const patcherOptions = ctx.tailwindcssPatcherOptions;
|
|
170
|
+
if (patcherOptions) {
|
|
171
|
+
if (normalizeCssEntriesConfig(patcherOptions.tailwind?.v4?.cssEntries)) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
if (normalizeCssEntriesConfig(patcherOptions.patch?.tailwindcss?.v4?.cssEntries)) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
var hasWarnedMissingCssEntries = false;
|
|
181
|
+
function warnMissingCssEntries(ctx, patcher) {
|
|
182
|
+
if (hasWarnedMissingCssEntries) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (patcher?.majorVersion !== 4) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (hasConfiguredCssEntries(ctx)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
hasWarnedMissingCssEntries = true;
|
|
192
|
+
logger.warn(
|
|
193
|
+
'[tailwindcss@4] \u672A\u68C0\u6D4B\u5230 cssEntries \u914D\u7F6E\u3002\u8BF7\u4F20\u5165\u5305\u542B tailwindcss \u5F15\u7528\u7684 CSS \u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u4F8B\u5982 cssEntries: ["/absolute/path/to/src/app.css"]\uFF0C\u5426\u5219 tailwindcss \u751F\u6210\u7684\u7C7B\u540D\u4E0D\u4F1A\u53C2\u4E0E\u8F6C\u8BD1\u3002'
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
function applyV4CssCalcDefaults(cssCalc, patcher) {
|
|
197
|
+
const cssCalcOptions = cssCalc ?? patcher?.majorVersion === 4;
|
|
198
|
+
if (patcher?.majorVersion === 4 && cssCalcOptions) {
|
|
199
|
+
return ensureDefaultsIncluded(cssCalcOptions);
|
|
200
|
+
}
|
|
201
|
+
return cssCalcOptions;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/tailwindcss/v4/patcher.ts
|
|
205
|
+
import path5 from "path";
|
|
206
|
+
import { logger as logger3 } from "@weapp-tailwindcss/logger";
|
|
207
|
+
|
|
208
|
+
// src/shared/mpx.ts
|
|
209
|
+
import path3 from "path";
|
|
210
|
+
|
|
211
|
+
// src/shared/tailwindcss-css-redirect.ts
|
|
212
|
+
import Module from "module";
|
|
213
|
+
import path2 from "path";
|
|
214
|
+
var moduleWithMutableResolve = Module;
|
|
215
|
+
var patched = /* @__PURE__ */ new WeakSet();
|
|
216
|
+
function installTailwindcssCssRedirect(pkgDir) {
|
|
217
|
+
const target = path2.join(pkgDir, "index.css");
|
|
218
|
+
const original = moduleWithMutableResolve._resolveFilename;
|
|
219
|
+
if (patched.has(original)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const replacements = /* @__PURE__ */ new Set(["tailwindcss", "tailwindcss$"]);
|
|
223
|
+
const resolveTailwindcssCss = (request, parent, isMain, options) => {
|
|
224
|
+
if (replacements.has(request)) {
|
|
225
|
+
return target;
|
|
226
|
+
}
|
|
227
|
+
if (request.startsWith("tailwindcss/")) {
|
|
228
|
+
return path2.join(pkgDir, request.slice("tailwindcss/".length));
|
|
229
|
+
}
|
|
230
|
+
return original(request, parent, isMain, options);
|
|
231
|
+
};
|
|
232
|
+
moduleWithMutableResolve._resolveFilename = resolveTailwindcssCss;
|
|
233
|
+
patched.add(moduleWithMutableResolve._resolveFilename);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/shared/mpx.ts
|
|
237
|
+
var MPX_STYLE_RESOURCE_QUERY_RE = /(?:^|[?&])type=styles(?:&|$)/;
|
|
238
|
+
function isMpxStyleResourceQuery(query) {
|
|
239
|
+
if (typeof query !== "string") {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
return MPX_STYLE_RESOURCE_QUERY_RE.test(query);
|
|
243
|
+
}
|
|
244
|
+
function isMpx(appType) {
|
|
245
|
+
return appType === "mpx";
|
|
246
|
+
}
|
|
247
|
+
function getTailwindcssCssEntry(pkgDir) {
|
|
248
|
+
return path3.join(pkgDir, "index.css");
|
|
249
|
+
}
|
|
250
|
+
function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
251
|
+
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
252
|
+
compiler.options = compiler.options || {};
|
|
253
|
+
compiler.options.resolve = compiler.options.resolve || {};
|
|
254
|
+
const alias = compiler.options.resolve.alias ?? {};
|
|
255
|
+
if (Array.isArray(alias)) {
|
|
256
|
+
alias.push(
|
|
257
|
+
{ name: "tailwindcss", alias: tailwindcssCssEntry },
|
|
258
|
+
{ name: "tailwindcss$", alias: tailwindcssCssEntry }
|
|
259
|
+
);
|
|
260
|
+
} else {
|
|
261
|
+
compiler.options.resolve.alias = alias;
|
|
262
|
+
alias.tailwindcss = tailwindcssCssEntry;
|
|
263
|
+
alias.tailwindcss$ = tailwindcssCssEntry;
|
|
264
|
+
}
|
|
265
|
+
return tailwindcssCssEntry;
|
|
266
|
+
}
|
|
267
|
+
function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
268
|
+
if (!enabled || typeof loaderContext.resolve !== "function") {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const originalResolve = loaderContext.resolve;
|
|
272
|
+
if (originalResolve.__weappTwPatched) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
276
|
+
const wrappedResolve = function(context, request, callback) {
|
|
277
|
+
if (request === "tailwindcss" || request === "tailwindcss$") {
|
|
278
|
+
return callback(null, tailwindcssCssEntry);
|
|
279
|
+
}
|
|
280
|
+
if (request?.startsWith("tailwindcss/")) {
|
|
281
|
+
return callback(null, path3.join(pkgDir, request.slice("tailwindcss/".length)));
|
|
282
|
+
}
|
|
283
|
+
return originalResolve.call(this, context, request, callback);
|
|
284
|
+
};
|
|
285
|
+
wrappedResolve.__weappTwPatched = true;
|
|
286
|
+
loaderContext.resolve = wrappedResolve;
|
|
287
|
+
}
|
|
288
|
+
function setupMpxTailwindcssRedirect(pkgDir, enabled) {
|
|
289
|
+
if (enabled) {
|
|
290
|
+
installTailwindcssCssRedirect(pkgDir);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function injectMpxCssRewritePreRules(compiler, loader, loaderOptions) {
|
|
294
|
+
var _a;
|
|
295
|
+
if (!loader) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const moduleOptions = (_a = compiler.options).module ?? (_a.module = { rules: [] });
|
|
299
|
+
moduleOptions.rules = moduleOptions.rules || [];
|
|
300
|
+
const createRule = (match) => ({
|
|
301
|
+
...match,
|
|
302
|
+
enforce: "pre",
|
|
303
|
+
use: [
|
|
304
|
+
{
|
|
305
|
+
loader,
|
|
306
|
+
options: loaderOptions
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
});
|
|
310
|
+
moduleOptions.rules.unshift(
|
|
311
|
+
createRule({ resourceQuery: (query) => isMpxStyleResourceQuery(query) }),
|
|
312
|
+
createRule({
|
|
313
|
+
test: /\.css$/i,
|
|
314
|
+
resourceQuery: (query) => !isMpxStyleResourceQuery(query)
|
|
315
|
+
})
|
|
316
|
+
);
|
|
317
|
+
}
|
|
98
318
|
|
|
99
319
|
// src/tailwindcss/patcher.ts
|
|
100
320
|
import { existsSync as existsSync2 } from "fs";
|
|
101
321
|
import { createRequire } from "module";
|
|
102
|
-
import
|
|
322
|
+
import path4 from "path";
|
|
103
323
|
import process from "process";
|
|
104
324
|
import { fileURLToPath } from "url";
|
|
105
|
-
import { logger } from "@weapp-tailwindcss/logger";
|
|
325
|
+
import { logger as logger2 } from "@weapp-tailwindcss/logger";
|
|
106
326
|
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
107
327
|
import { TailwindcssPatcher } from "tailwindcss-patch";
|
|
108
328
|
var GENERIC_RELATIVE_SPECIFIERS = [".", ".."];
|
|
@@ -117,7 +337,7 @@ function isPathSpecifier(specifier) {
|
|
|
117
337
|
if (specifier.startsWith("file://")) {
|
|
118
338
|
return true;
|
|
119
339
|
}
|
|
120
|
-
if (
|
|
340
|
+
if (path4.isAbsolute(specifier)) {
|
|
121
341
|
return true;
|
|
122
342
|
}
|
|
123
343
|
return GENERIC_RELATIVE_SPECIFIERS.some((prefix) => specifier.startsWith(`${prefix}/`) || specifier.startsWith(`${prefix}\\`));
|
|
@@ -187,7 +407,7 @@ function appendNodeModules(paths, dir) {
|
|
|
187
407
|
if (!dir) {
|
|
188
408
|
return;
|
|
189
409
|
}
|
|
190
|
-
const nodeModulesDir =
|
|
410
|
+
const nodeModulesDir = path4.join(dir, "node_modules");
|
|
191
411
|
if (existsSync2(nodeModulesDir)) {
|
|
192
412
|
paths.add(nodeModulesDir);
|
|
193
413
|
}
|
|
@@ -203,7 +423,7 @@ var TAILWIND_CONFIG_FILES = [
|
|
|
203
423
|
function findTailwindConfig(searchRoots) {
|
|
204
424
|
for (const root of searchRoots) {
|
|
205
425
|
for (const file of TAILWIND_CONFIG_FILES) {
|
|
206
|
-
const candidate =
|
|
426
|
+
const candidate = path4.resolve(root, file);
|
|
207
427
|
if (existsSync2(candidate)) {
|
|
208
428
|
return candidate;
|
|
209
429
|
}
|
|
@@ -215,7 +435,7 @@ function createDefaultResolvePaths(basedir) {
|
|
|
215
435
|
const paths = /* @__PURE__ */ new Set();
|
|
216
436
|
let fallbackCandidates = [];
|
|
217
437
|
if (basedir) {
|
|
218
|
-
const resolvedBase =
|
|
438
|
+
const resolvedBase = path4.resolve(basedir);
|
|
219
439
|
appendNodeModules(paths, resolvedBase);
|
|
220
440
|
fallbackCandidates.push(resolvedBase);
|
|
221
441
|
const packageRoot = findNearestPackageRoot(resolvedBase);
|
|
@@ -228,7 +448,7 @@ function createDefaultResolvePaths(basedir) {
|
|
|
228
448
|
appendNodeModules(paths, cwd);
|
|
229
449
|
try {
|
|
230
450
|
const modulePath = fileURLToPath(import.meta.url);
|
|
231
|
-
const candidate = existsSync2(modulePath) && !
|
|
451
|
+
const candidate = existsSync2(modulePath) && !path4.extname(modulePath) ? modulePath : path4.dirname(modulePath);
|
|
232
452
|
paths.add(candidate);
|
|
233
453
|
} catch {
|
|
234
454
|
paths.add(import.meta.url);
|
|
@@ -318,18 +538,18 @@ function normalizeTailwindcssPatcherOptions(options) {
|
|
|
318
538
|
function createTailwindcssPatcher(options) {
|
|
319
539
|
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
320
540
|
const cache = {};
|
|
321
|
-
const normalizedBasedir = basedir ?
|
|
541
|
+
const normalizedBasedir = basedir ? path4.resolve(basedir) : void 0;
|
|
322
542
|
const cacheRoot = findNearestPackageRoot(normalizedBasedir) ?? normalizedBasedir ?? process.cwd();
|
|
323
543
|
if (cacheDir) {
|
|
324
|
-
if (
|
|
544
|
+
if (path4.isAbsolute(cacheDir)) {
|
|
325
545
|
cache.dir = cacheDir;
|
|
326
546
|
} else if (normalizedBasedir) {
|
|
327
|
-
cache.dir =
|
|
547
|
+
cache.dir = path4.resolve(normalizedBasedir, cacheDir);
|
|
328
548
|
} else {
|
|
329
|
-
cache.dir =
|
|
549
|
+
cache.dir = path4.resolve(process.cwd(), cacheDir);
|
|
330
550
|
}
|
|
331
551
|
} else {
|
|
332
|
-
cache.dir =
|
|
552
|
+
cache.dir = path4.join(cacheRoot, "node_modules", ".cache", "tailwindcss-patch");
|
|
333
553
|
}
|
|
334
554
|
if (normalizedBasedir) {
|
|
335
555
|
cache.cwd = normalizedBasedir;
|
|
@@ -386,7 +606,7 @@ function createTailwindcssPatcher(options) {
|
|
|
386
606
|
...existingResolve,
|
|
387
607
|
paths: Array.from(new Set(sourcePaths))
|
|
388
608
|
};
|
|
389
|
-
|
|
609
|
+
logger2.debug("Tailwind resolve config %O", {
|
|
390
610
|
packageName: resolvedOptions.tailwind.packageName,
|
|
391
611
|
version: resolvedOptions.tailwind.version,
|
|
392
612
|
resolve: resolvedOptions.tailwind.resolve,
|
|
@@ -406,7 +626,7 @@ function createTailwindcssPatcher(options) {
|
|
|
406
626
|
searchRoots.add(resolvedOptions.tailwind.cwd);
|
|
407
627
|
}
|
|
408
628
|
for (const resolvePath of resolvedOptions.tailwind.resolve?.paths ?? []) {
|
|
409
|
-
const parentDir =
|
|
629
|
+
const parentDir = path4.dirname(resolvePath);
|
|
410
630
|
searchRoots.add(parentDir);
|
|
411
631
|
}
|
|
412
632
|
const configPath = findTailwindConfig(searchRoots);
|
|
@@ -424,7 +644,7 @@ function createTailwindcssPatcher(options) {
|
|
|
424
644
|
}
|
|
425
645
|
}
|
|
426
646
|
if (!resolvedOptions.tailwind.cwd && configPath) {
|
|
427
|
-
resolvedOptions.tailwind.cwd =
|
|
647
|
+
resolvedOptions.tailwind.cwd = path4.dirname(configPath);
|
|
428
648
|
}
|
|
429
649
|
}
|
|
430
650
|
try {
|
|
@@ -433,176 +653,25 @@ function createTailwindcssPatcher(options) {
|
|
|
433
653
|
const searchPaths = resolvedOptions.tailwind?.resolve?.paths;
|
|
434
654
|
if (error instanceof Error && /tailwindcss not found/i.test(error.message)) {
|
|
435
655
|
if (!hasLoggedMissingTailwind) {
|
|
436
|
-
|
|
656
|
+
logger2.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");
|
|
437
657
|
hasLoggedMissingTailwind = true;
|
|
438
658
|
}
|
|
439
659
|
return createFallbackTailwindcssPatcher();
|
|
440
660
|
}
|
|
441
661
|
if (error instanceof Error && /unable to locate tailwind css package/i.test(error.message)) {
|
|
442
|
-
|
|
662
|
+
logger2.error('\u65E0\u6CD5\u5B9A\u4F4D Tailwind CSS \u5305 "%s"\uFF0C\u5DF2\u5C1D\u8BD5\u8DEF\u5F84: %O', resolvedOptions.tailwind?.packageName, searchPaths);
|
|
443
663
|
}
|
|
444
664
|
throw error;
|
|
445
665
|
}
|
|
446
666
|
}
|
|
447
667
|
|
|
448
|
-
// src/tailwindcss/
|
|
449
|
-
function getTailwindcssPackageInfo(options) {
|
|
450
|
-
return getPackageInfoSync("tailwindcss", options);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// src/context/tailwindcss.ts
|
|
454
|
-
var ENV_BASEDIR_KEYS = [
|
|
455
|
-
"WEAPP_TAILWINDCSS_BASEDIR",
|
|
456
|
-
"WEAPP_TAILWINDCSS_BASE_DIR",
|
|
457
|
-
"TAILWINDCSS_BASEDIR",
|
|
458
|
-
"TAILWINDCSS_BASE_DIR",
|
|
459
|
-
"UNI_INPUT_DIR",
|
|
460
|
-
"UNI_INPUT_ROOT",
|
|
461
|
-
"UNI_CLI_ROOT",
|
|
462
|
-
"UNI_APP_INPUT_DIR",
|
|
463
|
-
"INIT_CWD",
|
|
464
|
-
"PWD"
|
|
465
|
-
];
|
|
466
|
-
var GENERIC_ENV_BASEDIR_KEYS = /* @__PURE__ */ new Set(["INIT_CWD", "PWD"]);
|
|
668
|
+
// src/tailwindcss/v4/patcher.ts
|
|
467
669
|
function isLegacyTailwindcssPatcherOptions(options) {
|
|
468
670
|
return typeof options === "object" && options !== null && "patch" in options;
|
|
469
671
|
}
|
|
470
672
|
function isModernTailwindcssPatchOptions(options) {
|
|
471
673
|
return typeof options === "object" && options !== null && !("patch" in options);
|
|
472
674
|
}
|
|
473
|
-
function pickEnvBasedir() {
|
|
474
|
-
for (const key of ENV_BASEDIR_KEYS) {
|
|
475
|
-
const value = process2.env[key];
|
|
476
|
-
if (value && path3.isAbsolute(value)) {
|
|
477
|
-
return { key, value };
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return void 0;
|
|
481
|
-
}
|
|
482
|
-
function pickPackageEnvBasedir() {
|
|
483
|
-
const packageJsonPath = process2.env.npm_package_json;
|
|
484
|
-
if (packageJsonPath) {
|
|
485
|
-
const packageDir = path3.dirname(packageJsonPath);
|
|
486
|
-
if (packageDir && path3.isAbsolute(packageDir)) {
|
|
487
|
-
return packageDir;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
const localPrefix = process2.env.npm_config_local_prefix;
|
|
491
|
-
if (localPrefix && path3.isAbsolute(localPrefix)) {
|
|
492
|
-
return localPrefix;
|
|
493
|
-
}
|
|
494
|
-
return void 0;
|
|
495
|
-
}
|
|
496
|
-
function detectCallerBasedir() {
|
|
497
|
-
const stack = new Error("resolveTailwindcssBasedir stack probe").stack;
|
|
498
|
-
if (!stack) {
|
|
499
|
-
return void 0;
|
|
500
|
-
}
|
|
501
|
-
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
502
|
-
logger2.debug("caller stack: %s", stack);
|
|
503
|
-
}
|
|
504
|
-
const lines = stack.split("\n");
|
|
505
|
-
for (const line of lines) {
|
|
506
|
-
const match = line.match(/\(([^)]+)\)/u) ?? line.match(/at\s+(\S.*)$/u);
|
|
507
|
-
const location = match?.[1];
|
|
508
|
-
if (!location) {
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
let filePath = location;
|
|
512
|
-
if (filePath.startsWith("file://")) {
|
|
513
|
-
try {
|
|
514
|
-
filePath = fileURLToPath2(filePath);
|
|
515
|
-
} catch {
|
|
516
|
-
continue;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
const [candidate] = filePath.split(":");
|
|
520
|
-
const resolvedPath = path3.isAbsolute(filePath) ? filePath : candidate;
|
|
521
|
-
if (!path3.isAbsolute(resolvedPath)) {
|
|
522
|
-
continue;
|
|
523
|
-
}
|
|
524
|
-
if (resolvedPath.includes("node_modules") && resolvedPath.includes("weapp-tailwindcss")) {
|
|
525
|
-
continue;
|
|
526
|
-
}
|
|
527
|
-
try {
|
|
528
|
-
return path3.dirname(resolvedPath);
|
|
529
|
-
} catch {
|
|
530
|
-
continue;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
return void 0;
|
|
534
|
-
}
|
|
535
|
-
function resolveTailwindcssBasedir(basedir, fallback) {
|
|
536
|
-
const envBasedirResult = pickEnvBasedir();
|
|
537
|
-
const envBasedir = envBasedirResult?.value;
|
|
538
|
-
const envBasedirKey = envBasedirResult?.key;
|
|
539
|
-
const envBasedirIsGeneric = envBasedirKey ? GENERIC_ENV_BASEDIR_KEYS.has(envBasedirKey) : false;
|
|
540
|
-
const packageEnvBasedir = pickPackageEnvBasedir();
|
|
541
|
-
const shouldDetectCaller = !envBasedir || envBasedirIsGeneric;
|
|
542
|
-
const callerBasedir = shouldDetectCaller ? detectCallerBasedir() : void 0;
|
|
543
|
-
const cwd = process2.cwd();
|
|
544
|
-
const anchor = envBasedir ?? packageEnvBasedir ?? fallback ?? callerBasedir ?? cwd;
|
|
545
|
-
const resolveRelative = (value) => path3.isAbsolute(value) ? path3.normalize(value) : path3.normalize(path3.resolve(anchor, value));
|
|
546
|
-
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
547
|
-
logger2.debug("resolveTailwindcssBasedir anchor %O", {
|
|
548
|
-
basedir,
|
|
549
|
-
envBasedir,
|
|
550
|
-
envBasedirKey,
|
|
551
|
-
envBasedirIsGeneric,
|
|
552
|
-
packageEnvBasedir,
|
|
553
|
-
fallback,
|
|
554
|
-
callerBasedir,
|
|
555
|
-
npm_package_json: process2.env.npm_package_json,
|
|
556
|
-
cwd,
|
|
557
|
-
anchor
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
if (basedir && basedir.trim().length > 0) {
|
|
561
|
-
return resolveRelative(basedir);
|
|
562
|
-
}
|
|
563
|
-
if (envBasedir && !envBasedirIsGeneric) {
|
|
564
|
-
return path3.normalize(envBasedir);
|
|
565
|
-
}
|
|
566
|
-
if (fallback && fallback.trim().length > 0) {
|
|
567
|
-
return resolveRelative(fallback);
|
|
568
|
-
}
|
|
569
|
-
if (packageEnvBasedir) {
|
|
570
|
-
return path3.normalize(packageEnvBasedir);
|
|
571
|
-
}
|
|
572
|
-
if (callerBasedir) {
|
|
573
|
-
const normalizedCaller = path3.normalize(callerBasedir);
|
|
574
|
-
const librarySegment = `${path3.sep}weapp-tailwindcss${path3.sep}`;
|
|
575
|
-
if (!normalizedCaller.includes(librarySegment)) {
|
|
576
|
-
return normalizedCaller;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
const packageName = process2.env.PNPM_PACKAGE_NAME;
|
|
580
|
-
if (packageName) {
|
|
581
|
-
try {
|
|
582
|
-
const anchorRequire = createRequire2(path3.join(anchor, "__resolve_tailwindcss_basedir__.cjs"));
|
|
583
|
-
const packageJsonPath = anchorRequire.resolve(`${packageName}/package.json`);
|
|
584
|
-
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
585
|
-
logger2.debug("package basedir resolved from PNPM_PACKAGE_NAME: %s", packageJsonPath);
|
|
586
|
-
}
|
|
587
|
-
return path3.normalize(path3.dirname(packageJsonPath));
|
|
588
|
-
} catch {
|
|
589
|
-
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
590
|
-
logger2.debug("failed to resolve package json for %s", packageName);
|
|
591
|
-
}
|
|
592
|
-
const workspaceRoot = findWorkspaceRoot(anchor);
|
|
593
|
-
if (workspaceRoot) {
|
|
594
|
-
const packageDir = findWorkspacePackageDir(workspaceRoot, packageName);
|
|
595
|
-
if (packageDir) {
|
|
596
|
-
return packageDir;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
if (envBasedir) {
|
|
602
|
-
return path3.normalize(envBasedir);
|
|
603
|
-
}
|
|
604
|
-
return path3.normalize(cwd);
|
|
605
|
-
}
|
|
606
675
|
function guessBasedirFromEntries(entries) {
|
|
607
676
|
if (!entries) {
|
|
608
677
|
return void 0;
|
|
@@ -612,10 +681,10 @@ function guessBasedirFromEntries(entries) {
|
|
|
612
681
|
continue;
|
|
613
682
|
}
|
|
614
683
|
const trimmed = entry.trim();
|
|
615
|
-
if (!trimmed || !
|
|
684
|
+
if (!trimmed || !path5.isAbsolute(trimmed)) {
|
|
616
685
|
continue;
|
|
617
686
|
}
|
|
618
|
-
const entryDir =
|
|
687
|
+
const entryDir = path5.dirname(trimmed);
|
|
619
688
|
const resolved = findNearestPackageRoot(entryDir) ?? entryDir;
|
|
620
689
|
if (resolved) {
|
|
621
690
|
return resolved;
|
|
@@ -636,7 +705,7 @@ function normalizeCssEntries(entries, anchor) {
|
|
|
636
705
|
if (trimmed.length === 0) {
|
|
637
706
|
continue;
|
|
638
707
|
}
|
|
639
|
-
const resolved =
|
|
708
|
+
const resolved = path5.isAbsolute(trimmed) ? path5.normalize(trimmed) : path5.normalize(path5.resolve(anchor, trimmed));
|
|
640
709
|
normalized.add(resolved);
|
|
641
710
|
}
|
|
642
711
|
return normalized.size > 0 ? [...normalized] : void 0;
|
|
@@ -645,11 +714,11 @@ function isSubPath(parent, child) {
|
|
|
645
714
|
if (!parent || !child) {
|
|
646
715
|
return false;
|
|
647
716
|
}
|
|
648
|
-
const relative =
|
|
649
|
-
return relative === "" || !relative.startsWith("..") && !
|
|
717
|
+
const relative = path5.relative(parent, child);
|
|
718
|
+
return relative === "" || !relative.startsWith("..") && !path5.isAbsolute(relative);
|
|
650
719
|
}
|
|
651
720
|
function resolveCssEntryBase(entryDir, options) {
|
|
652
|
-
const normalizedDir =
|
|
721
|
+
const normalizedDir = path5.normalize(entryDir);
|
|
653
722
|
const { preferredBaseDir, workspaceRoot } = options;
|
|
654
723
|
if (preferredBaseDir && isSubPath(preferredBaseDir, normalizedDir)) {
|
|
655
724
|
return preferredBaseDir;
|
|
@@ -659,18 +728,18 @@ function resolveCssEntryBase(entryDir, options) {
|
|
|
659
728
|
}
|
|
660
729
|
const packageRoot = findNearestPackageRoot(normalizedDir);
|
|
661
730
|
if (packageRoot) {
|
|
662
|
-
return
|
|
731
|
+
return path5.normalize(packageRoot);
|
|
663
732
|
}
|
|
664
733
|
return normalizedDir;
|
|
665
734
|
}
|
|
666
735
|
function groupCssEntriesByBase(entries, options = {}) {
|
|
667
736
|
const normalizedOptions = {
|
|
668
|
-
preferredBaseDir: options.preferredBaseDir ?
|
|
669
|
-
workspaceRoot: options.workspaceRoot ?
|
|
737
|
+
preferredBaseDir: options.preferredBaseDir ? path5.normalize(options.preferredBaseDir) : void 0,
|
|
738
|
+
workspaceRoot: options.workspaceRoot ? path5.normalize(options.workspaceRoot) : void 0
|
|
670
739
|
};
|
|
671
740
|
const groups = /* @__PURE__ */ new Map();
|
|
672
741
|
for (const entry of entries) {
|
|
673
|
-
const entryDir =
|
|
742
|
+
const entryDir = path5.dirname(entry);
|
|
674
743
|
const baseDir = resolveCssEntryBase(entryDir, normalizedOptions);
|
|
675
744
|
const bucket = groups.get(baseDir);
|
|
676
745
|
if (bucket) {
|
|
@@ -775,7 +844,7 @@ function createPatcherForBase(baseDir, cssEntries, options) {
|
|
|
775
844
|
);
|
|
776
845
|
return createTailwindcssPatcher({
|
|
777
846
|
basedir: baseDir,
|
|
778
|
-
cacheDir: appType
|
|
847
|
+
cacheDir: isMpx(appType) ? "node_modules/tailwindcss-patch/.cache" : void 0,
|
|
779
848
|
supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
|
|
780
849
|
tailwindcss: mergedTailwindOptions,
|
|
781
850
|
tailwindcssPatcherOptions: patchedOptions
|
|
@@ -871,13 +940,221 @@ function tryCreateMultiTailwindcssPatcher(groups, options) {
|
|
|
871
940
|
if (groups.size <= 1) {
|
|
872
941
|
return void 0;
|
|
873
942
|
}
|
|
874
|
-
|
|
943
|
+
logger3.debug("detected multiple Tailwind CSS entry bases: %O", [...groups.keys()]);
|
|
875
944
|
const patchers = [];
|
|
876
945
|
for (const [baseDir, entries] of groups) {
|
|
877
946
|
patchers.push(createPatcherForBase(baseDir, entries, options));
|
|
878
947
|
}
|
|
879
948
|
return createMultiTailwindcssPatcher(patchers);
|
|
880
949
|
}
|
|
950
|
+
|
|
951
|
+
// src/context/tailwindcss.ts
|
|
952
|
+
var ENV_BASEDIR_KEYS = [
|
|
953
|
+
"WEAPP_TAILWINDCSS_BASEDIR",
|
|
954
|
+
"WEAPP_TAILWINDCSS_BASE_DIR",
|
|
955
|
+
"TAILWINDCSS_BASEDIR",
|
|
956
|
+
"TAILWINDCSS_BASE_DIR",
|
|
957
|
+
"UNI_INPUT_DIR",
|
|
958
|
+
"UNI_INPUT_ROOT",
|
|
959
|
+
"UNI_CLI_ROOT",
|
|
960
|
+
"UNI_APP_INPUT_DIR",
|
|
961
|
+
"INIT_CWD",
|
|
962
|
+
"PWD"
|
|
963
|
+
];
|
|
964
|
+
var GENERIC_ENV_BASEDIR_KEYS = /* @__PURE__ */ new Set(["INIT_CWD", "PWD"]);
|
|
965
|
+
function pickEnvBasedir() {
|
|
966
|
+
for (const key of ENV_BASEDIR_KEYS) {
|
|
967
|
+
const value = process2.env[key];
|
|
968
|
+
if (value && path6.isAbsolute(value)) {
|
|
969
|
+
return { key, value };
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return void 0;
|
|
973
|
+
}
|
|
974
|
+
function pickPackageEnvBasedir() {
|
|
975
|
+
const packageJsonPath = process2.env.npm_package_json;
|
|
976
|
+
if (packageJsonPath) {
|
|
977
|
+
const packageDir = path6.dirname(packageJsonPath);
|
|
978
|
+
if (packageDir && path6.isAbsolute(packageDir)) {
|
|
979
|
+
return packageDir;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
const localPrefix = process2.env.npm_config_local_prefix;
|
|
983
|
+
if (localPrefix && path6.isAbsolute(localPrefix)) {
|
|
984
|
+
return localPrefix;
|
|
985
|
+
}
|
|
986
|
+
return void 0;
|
|
987
|
+
}
|
|
988
|
+
function detectCallerBasedir() {
|
|
989
|
+
const stack = new Error("resolveTailwindcssBasedir stack probe").stack;
|
|
990
|
+
if (!stack) {
|
|
991
|
+
return void 0;
|
|
992
|
+
}
|
|
993
|
+
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
994
|
+
logger4.debug("caller stack: %s", stack);
|
|
995
|
+
}
|
|
996
|
+
const lines = stack.split("\n");
|
|
997
|
+
for (const line of lines) {
|
|
998
|
+
const match = line.match(/\(([^)]+)\)/u) ?? line.match(/at\s+(\S.*)$/u);
|
|
999
|
+
const location = match?.[1];
|
|
1000
|
+
if (!location) {
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
let filePath = location;
|
|
1004
|
+
if (filePath.startsWith("file://")) {
|
|
1005
|
+
try {
|
|
1006
|
+
filePath = fileURLToPath2(filePath);
|
|
1007
|
+
} catch {
|
|
1008
|
+
continue;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
const [candidate] = filePath.split(":");
|
|
1012
|
+
const resolvedPath = path6.isAbsolute(filePath) ? filePath : candidate;
|
|
1013
|
+
if (!path6.isAbsolute(resolvedPath)) {
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
if (resolvedPath.includes("node_modules") && resolvedPath.includes("weapp-tailwindcss")) {
|
|
1017
|
+
continue;
|
|
1018
|
+
}
|
|
1019
|
+
try {
|
|
1020
|
+
return path6.dirname(resolvedPath);
|
|
1021
|
+
} catch {
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return void 0;
|
|
1026
|
+
}
|
|
1027
|
+
function resolveTailwindcssBasedir(basedir, fallback) {
|
|
1028
|
+
const envBasedirResult = pickEnvBasedir();
|
|
1029
|
+
const envBasedir = envBasedirResult?.value;
|
|
1030
|
+
const envBasedirKey = envBasedirResult?.key;
|
|
1031
|
+
const envBasedirIsGeneric = envBasedirKey ? GENERIC_ENV_BASEDIR_KEYS.has(envBasedirKey) : false;
|
|
1032
|
+
const packageEnvBasedir = pickPackageEnvBasedir();
|
|
1033
|
+
const shouldDetectCaller = !envBasedir || envBasedirIsGeneric;
|
|
1034
|
+
const callerBasedir = shouldDetectCaller ? detectCallerBasedir() : void 0;
|
|
1035
|
+
const cwd = process2.cwd();
|
|
1036
|
+
const anchor = envBasedir ?? packageEnvBasedir ?? fallback ?? callerBasedir ?? cwd;
|
|
1037
|
+
const resolveRelative = (value) => path6.isAbsolute(value) ? path6.normalize(value) : path6.normalize(path6.resolve(anchor, value));
|
|
1038
|
+
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
1039
|
+
logger4.debug("resolveTailwindcssBasedir anchor %O", {
|
|
1040
|
+
basedir,
|
|
1041
|
+
envBasedir,
|
|
1042
|
+
envBasedirKey,
|
|
1043
|
+
envBasedirIsGeneric,
|
|
1044
|
+
packageEnvBasedir,
|
|
1045
|
+
fallback,
|
|
1046
|
+
callerBasedir,
|
|
1047
|
+
npm_package_json: process2.env.npm_package_json,
|
|
1048
|
+
cwd,
|
|
1049
|
+
anchor
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
if (basedir && basedir.trim().length > 0) {
|
|
1053
|
+
return resolveRelative(basedir);
|
|
1054
|
+
}
|
|
1055
|
+
if (envBasedir && !envBasedirIsGeneric) {
|
|
1056
|
+
return path6.normalize(envBasedir);
|
|
1057
|
+
}
|
|
1058
|
+
if (fallback && fallback.trim().length > 0) {
|
|
1059
|
+
return resolveRelative(fallback);
|
|
1060
|
+
}
|
|
1061
|
+
if (packageEnvBasedir) {
|
|
1062
|
+
return path6.normalize(packageEnvBasedir);
|
|
1063
|
+
}
|
|
1064
|
+
if (callerBasedir) {
|
|
1065
|
+
const normalizedCaller = path6.normalize(callerBasedir);
|
|
1066
|
+
const librarySegment = `${path6.sep}weapp-tailwindcss${path6.sep}`;
|
|
1067
|
+
if (!normalizedCaller.includes(librarySegment)) {
|
|
1068
|
+
return normalizedCaller;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
const packageName = process2.env.PNPM_PACKAGE_NAME;
|
|
1072
|
+
if (packageName) {
|
|
1073
|
+
try {
|
|
1074
|
+
const anchorRequire = createRequire2(path6.join(anchor, "__resolve_tailwindcss_basedir__.cjs"));
|
|
1075
|
+
const packageJsonPath = anchorRequire.resolve(`${packageName}/package.json`);
|
|
1076
|
+
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
1077
|
+
logger4.debug("package basedir resolved from PNPM_PACKAGE_NAME: %s", packageJsonPath);
|
|
1078
|
+
}
|
|
1079
|
+
return path6.normalize(path6.dirname(packageJsonPath));
|
|
1080
|
+
} catch {
|
|
1081
|
+
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
1082
|
+
logger4.debug("failed to resolve package json for %s", packageName);
|
|
1083
|
+
}
|
|
1084
|
+
const workspaceRoot = findWorkspaceRoot(anchor);
|
|
1085
|
+
if (workspaceRoot) {
|
|
1086
|
+
const packageDir = findWorkspacePackageDir(workspaceRoot, packageName);
|
|
1087
|
+
if (packageDir) {
|
|
1088
|
+
return packageDir;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
if (envBasedir) {
|
|
1094
|
+
return path6.normalize(envBasedir);
|
|
1095
|
+
}
|
|
1096
|
+
return path6.normalize(cwd);
|
|
1097
|
+
}
|
|
1098
|
+
function isRaxWorkspace(appType, baseDir) {
|
|
1099
|
+
if (appType === "rax") {
|
|
1100
|
+
return true;
|
|
1101
|
+
}
|
|
1102
|
+
try {
|
|
1103
|
+
const pkgPath = path6.join(baseDir, "package.json");
|
|
1104
|
+
if (!existsSync3(pkgPath)) {
|
|
1105
|
+
return false;
|
|
1106
|
+
}
|
|
1107
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf8"));
|
|
1108
|
+
const deps = {
|
|
1109
|
+
...pkg.dependencies ?? {},
|
|
1110
|
+
...pkg.devDependencies ?? {}
|
|
1111
|
+
};
|
|
1112
|
+
if (deps["rax-app"] || deps.rax) {
|
|
1113
|
+
return true;
|
|
1114
|
+
}
|
|
1115
|
+
} catch {
|
|
1116
|
+
return false;
|
|
1117
|
+
}
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1120
|
+
function collectRaxStyleEntries(baseDir) {
|
|
1121
|
+
const STYLE_CANDIDATES = [
|
|
1122
|
+
"src/global.css",
|
|
1123
|
+
"src/global.scss",
|
|
1124
|
+
"src/global.less",
|
|
1125
|
+
"src/global.sass",
|
|
1126
|
+
"src/global.styl",
|
|
1127
|
+
"src/global.stylus"
|
|
1128
|
+
];
|
|
1129
|
+
const discovered = [];
|
|
1130
|
+
for (const relative of STYLE_CANDIDATES) {
|
|
1131
|
+
const candidate = path6.resolve(baseDir, relative);
|
|
1132
|
+
if (existsSync3(candidate)) {
|
|
1133
|
+
discovered.push(path6.normalize(candidate));
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
return discovered;
|
|
1137
|
+
}
|
|
1138
|
+
function detectImplicitCssEntries(appType, baseDir) {
|
|
1139
|
+
const baseCandidates = /* @__PURE__ */ new Set();
|
|
1140
|
+
baseCandidates.add(path6.normalize(baseDir));
|
|
1141
|
+
const envCandidates = [process2.cwd(), process2.env.INIT_CWD, process2.env.PWD];
|
|
1142
|
+
for (const candidate of envCandidates) {
|
|
1143
|
+
if (candidate) {
|
|
1144
|
+
baseCandidates.add(path6.normalize(candidate));
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
for (const candidateBase of baseCandidates) {
|
|
1148
|
+
if (!isRaxWorkspace(appType, candidateBase)) {
|
|
1149
|
+
continue;
|
|
1150
|
+
}
|
|
1151
|
+
const entries = collectRaxStyleEntries(candidateBase);
|
|
1152
|
+
if (entries.length) {
|
|
1153
|
+
return entries;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return void 0;
|
|
1157
|
+
}
|
|
881
1158
|
function createTailwindcssPatcherFromContext(ctx) {
|
|
882
1159
|
const {
|
|
883
1160
|
tailwindcssBasedir,
|
|
@@ -890,8 +1167,11 @@ function createTailwindcssPatcherFromContext(ctx) {
|
|
|
890
1167
|
const absoluteCssEntryBasedir = guessBasedirFromEntries(rawCssEntries);
|
|
891
1168
|
const resolvedTailwindcssBasedir = resolveTailwindcssBasedir(tailwindcssBasedir, absoluteCssEntryBasedir);
|
|
892
1169
|
ctx.tailwindcssBasedir = resolvedTailwindcssBasedir;
|
|
893
|
-
|
|
894
|
-
|
|
1170
|
+
logger4.debug("tailwindcss basedir resolved: %s", resolvedTailwindcssBasedir);
|
|
1171
|
+
let normalizedCssEntries = normalizeCssEntries(rawCssEntries, resolvedTailwindcssBasedir);
|
|
1172
|
+
if (!normalizedCssEntries) {
|
|
1173
|
+
normalizedCssEntries = detectImplicitCssEntries(ctx.appType, resolvedTailwindcssBasedir);
|
|
1174
|
+
}
|
|
895
1175
|
if (normalizedCssEntries) {
|
|
896
1176
|
ctx.cssEntries = normalizedCssEntries;
|
|
897
1177
|
}
|
|
@@ -926,13 +1206,19 @@ function createTailwindcssPatcherFromContext(ctx) {
|
|
|
926
1206
|
}
|
|
927
1207
|
|
|
928
1208
|
// src/logger/index.ts
|
|
929
|
-
import { logger as
|
|
1209
|
+
import { logger as logger5 } from "@weapp-tailwindcss/logger";
|
|
930
1210
|
|
|
931
1211
|
export {
|
|
932
1212
|
findWorkspaceRoot,
|
|
933
1213
|
findNearestPackageRoot,
|
|
934
|
-
|
|
1214
|
+
warnMissingCssEntries,
|
|
1215
|
+
applyV4CssCalcDefaults,
|
|
1216
|
+
isMpx,
|
|
1217
|
+
ensureMpxTailwindcssAliases,
|
|
1218
|
+
patchMpxLoaderResolve,
|
|
1219
|
+
setupMpxTailwindcssRedirect,
|
|
1220
|
+
injectMpxCssRewritePreRules,
|
|
935
1221
|
resolveTailwindcssBasedir,
|
|
936
1222
|
createTailwindcssPatcherFromContext,
|
|
937
|
-
|
|
1223
|
+
logger5 as logger
|
|
938
1224
|
};
|