weapp-tailwindcss 4.11.2 → 4.12.0-alpha.1
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/README.md +38 -0
- package/dist/{chunk-WJIRXC26.js → chunk-4LBAL3RE.js} +117 -119
- package/dist/{chunk-JIERVBTX.mjs → chunk-5CF3HTTN.mjs} +1 -1
- package/dist/{chunk-OMARW5NC.mjs → chunk-AYJ4HLWZ.mjs} +4 -2
- package/dist/{chunk-VGPAKLMZ.mjs → chunk-C2E5ZLNI.mjs} +12 -7
- package/dist/{chunk-3QHYEMEW.js → chunk-CAZQZPMY.js} +45 -40
- package/dist/{chunk-AV3XB6EQ.js → chunk-CTGWJGKJ.js} +5 -5
- package/dist/{chunk-7LKMJZD2.js → chunk-GMKSBLNY.js} +2 -2
- package/dist/{chunk-EFBQ4SQR.mjs → chunk-HL3US2OT.mjs} +1 -1
- package/dist/{chunk-SUKOZ6OG.js → chunk-IUYO6NQO.js} +10 -6
- package/dist/{chunk-ZZ36BKM5.mjs → chunk-JRLWGMVZ.mjs} +6 -2
- package/dist/{chunk-QK6VNNNL.js → chunk-NIS74SI6.js} +8 -6
- package/dist/{chunk-CRDOWYG4.js → chunk-ONLKZIRQ.js} +1 -1
- package/dist/{chunk-TT5WHNGS.js → chunk-RQWWSU4U.js} +136 -77
- package/dist/{chunk-W3DXDWYC.mjs → chunk-V34LWQTS.mjs} +49 -51
- package/dist/{chunk-AB2RGZQO.mjs → chunk-ZABCOAAS.mjs} +131 -72
- package/dist/cli.js +8 -1
- package/dist/cli.mjs +8 -1
- package/dist/core.d.mts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +14 -9
- package/dist/core.mjs +10 -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.d.mts +1 -1
- package/dist/defaults.d.ts +1 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/gulp.d.mts +1 -1
- package/dist/gulp.d.ts +1 -1
- package/dist/gulp.js +5 -5
- package/dist/gulp.mjs +4 -4
- package/dist/{index-CoXntW_P.d.mts → index-BXrmQelt.d.mts} +29 -1
- package/dist/{index-CoXntW_P.d.ts → index-BXrmQelt.d.ts} +29 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/index.mjs +7 -7
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.d.mts +8 -1
- package/dist/presets.d.ts +8 -1
- package/dist/presets.js +7 -6
- package/dist/presets.mjs +3 -2
- package/dist/reset.d.mts +1 -31
- package/dist/reset.d.ts +3 -32
- package/dist/reset.js +3 -160
- package/dist/reset.mjs +3 -160
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +6 -6
- package/dist/vite.mjs +4 -4
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +7 -7
- package/dist/webpack.mjs +5 -5
- package/dist/webpack4.d.mts +1 -1
- package/dist/webpack4.d.ts +1 -1
- package/dist/webpack4.js +41 -36
- package/dist/webpack4.mjs +12 -7
- package/package.json +8 -4
|
@@ -23,18 +23,20 @@ import {
|
|
|
23
23
|
refreshTailwindRuntimeState,
|
|
24
24
|
replaceWxml,
|
|
25
25
|
setupPatchRecorder,
|
|
26
|
+
shouldSkipJsTransform,
|
|
26
27
|
toCustomAttributesEntities,
|
|
27
28
|
traverse,
|
|
28
29
|
vitePluginName
|
|
29
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-ZABCOAAS.mjs";
|
|
30
31
|
import {
|
|
31
32
|
findNearestPackageRoot,
|
|
32
33
|
findTailwindConfig,
|
|
33
34
|
getRuntimeClassSetSignature,
|
|
34
35
|
isUniAppXEnabled,
|
|
36
|
+
logger,
|
|
35
37
|
resolveTailwindcssOptions,
|
|
36
38
|
resolveUniAppXOptions
|
|
37
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-AYJ4HLWZ.mjs";
|
|
38
40
|
import {
|
|
39
41
|
resolveUniUtsPlatform
|
|
40
42
|
} from "./chunk-OOHJLO5M.mjs";
|
|
@@ -43,7 +45,7 @@ import {
|
|
|
43
45
|
import { existsSync as existsSync2 } from "fs";
|
|
44
46
|
import path6 from "path";
|
|
45
47
|
import process4 from "process";
|
|
46
|
-
import { logger as
|
|
48
|
+
import { logger as logger3 } from "@weapp-tailwindcss/logger";
|
|
47
49
|
import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
|
|
48
50
|
|
|
49
51
|
// src/uni-app-x/transform.ts
|
|
@@ -239,28 +241,28 @@ function traverse2(node, visitor) {
|
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
243
|
}
|
|
242
|
-
function updateStaticAttribute(ms, prop) {
|
|
244
|
+
function updateStaticAttribute(ms, prop, content = prop.value?.content) {
|
|
243
245
|
if (!prop.value) {
|
|
244
246
|
return;
|
|
245
247
|
}
|
|
246
248
|
const start = prop.value.loc.start.offset + 1;
|
|
247
249
|
const end = prop.value.loc.end.offset - 1;
|
|
248
250
|
if (start < end) {
|
|
249
|
-
ms.update(start, end, replaceWxml(
|
|
251
|
+
ms.update(start, end, replaceWxml(content ?? ""));
|
|
250
252
|
}
|
|
251
253
|
}
|
|
252
|
-
function updateStaticAttributeWithLocalStyle(ms, prop, collector) {
|
|
254
|
+
function updateStaticAttributeWithLocalStyle(ms, prop, collector, content = prop.value?.content) {
|
|
253
255
|
if (!prop.value) {
|
|
254
256
|
return;
|
|
255
257
|
}
|
|
256
258
|
const start = prop.value.loc.start.offset + 1;
|
|
257
259
|
const end = prop.value.loc.end.offset - 1;
|
|
258
260
|
if (start < end) {
|
|
259
|
-
ms.update(start, end, collector.collectAndRewriteStaticClass(
|
|
261
|
+
ms.update(start, end, collector.collectAndRewriteStaticClass(content ?? ""));
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
|
-
function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
|
|
263
|
-
if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) {
|
|
264
|
+
function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet, expression = prop.exp?.content) {
|
|
265
|
+
if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION || expression === void 0) {
|
|
264
266
|
return;
|
|
265
267
|
}
|
|
266
268
|
const start = prop.exp.loc.start.offset;
|
|
@@ -268,15 +270,15 @@ function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
|
|
|
268
270
|
if (start >= end) {
|
|
269
271
|
return;
|
|
270
272
|
}
|
|
271
|
-
const generated = generateCode(
|
|
273
|
+
const generated = generateCode(expression, {
|
|
272
274
|
jsHandler,
|
|
273
275
|
runtimeSet,
|
|
274
276
|
wrapExpression: true
|
|
275
277
|
});
|
|
276
278
|
ms.update(start, end, generated);
|
|
277
279
|
}
|
|
278
|
-
function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector, runtimeSet) {
|
|
279
|
-
if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) {
|
|
280
|
+
function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector, runtimeSet, expression = prop.exp?.content) {
|
|
281
|
+
if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION || expression === void 0) {
|
|
280
282
|
return;
|
|
281
283
|
}
|
|
282
284
|
const start = prop.exp.loc.start.offset;
|
|
@@ -284,10 +286,10 @@ function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector,
|
|
|
284
286
|
if (start >= end) {
|
|
285
287
|
return;
|
|
286
288
|
}
|
|
287
|
-
collector.collectRuntimeClasses(
|
|
289
|
+
collector.collectRuntimeClasses(expression, {
|
|
288
290
|
wrapExpression: true
|
|
289
291
|
});
|
|
290
|
-
const generated = generateCode(
|
|
292
|
+
const generated = generateCode(expression, {
|
|
291
293
|
jsHandler,
|
|
292
294
|
runtimeSet,
|
|
293
295
|
wrapExpression: true
|
|
@@ -359,7 +361,13 @@ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
|
|
|
359
361
|
continue;
|
|
360
362
|
}
|
|
361
363
|
if (attrName.toLowerCase() === "class" && localStyleCollector) {
|
|
362
|
-
updateDirectiveExpressionWithLocalStyle(
|
|
364
|
+
updateDirectiveExpressionWithLocalStyle(
|
|
365
|
+
ms,
|
|
366
|
+
prop,
|
|
367
|
+
jsHandler,
|
|
368
|
+
localStyleCollector,
|
|
369
|
+
runtimeSet
|
|
370
|
+
);
|
|
363
371
|
} else {
|
|
364
372
|
updateDirectiveExpression(ms, prop, jsHandler, runtimeSet);
|
|
365
373
|
}
|
|
@@ -509,6 +517,9 @@ function isPreprocessorRequest(id, lang) {
|
|
|
509
517
|
}
|
|
510
518
|
return PREPROCESSOR_EXT_RE.test(id);
|
|
511
519
|
}
|
|
520
|
+
function resolveUniAppXCssTarget(id) {
|
|
521
|
+
return UVUE_NVUE_RE2.test(cleanUrl(id)) ? "uvue" : void 0;
|
|
522
|
+
}
|
|
512
523
|
function createUniAppXPlugins(options) {
|
|
513
524
|
const {
|
|
514
525
|
appType,
|
|
@@ -551,6 +562,8 @@ function createUniAppXPlugins(options) {
|
|
|
551
562
|
if (!styleHandlerOptions) {
|
|
552
563
|
styleHandlerOptions = {
|
|
553
564
|
isMainChunk: mainCssChunkMatcher(id, appType),
|
|
565
|
+
uniAppXCssTarget: resolveUniAppXCssTarget(id),
|
|
566
|
+
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
554
567
|
postcssOptions: {
|
|
555
568
|
options: {
|
|
556
569
|
from: id,
|
|
@@ -567,6 +580,10 @@ function createUniAppXPlugins(options) {
|
|
|
567
580
|
cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
|
|
568
581
|
}
|
|
569
582
|
const postcssResult = await styleHandler(code, styleHandlerOptions);
|
|
583
|
+
const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
|
|
584
|
+
for (const warning of warnings) {
|
|
585
|
+
logger.warn(warning.toString());
|
|
586
|
+
}
|
|
570
587
|
const rawPostcssMap = postcssResult.map.toJSON();
|
|
571
588
|
const postcssMap = await formatPostcssSourceMap(
|
|
572
589
|
rawPostcssMap,
|
|
@@ -708,7 +725,7 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
708
725
|
// src/bundlers/vite/generate-bundle.ts
|
|
709
726
|
import path3 from "path";
|
|
710
727
|
import process2 from "process";
|
|
711
|
-
import { logger } from "@weapp-tailwindcss/logger";
|
|
728
|
+
import { logger as logger2 } from "@weapp-tailwindcss/logger";
|
|
712
729
|
import { splitCode as splitCode2 } from "@weapp-tailwindcss/shared/extractors";
|
|
713
730
|
|
|
714
731
|
// src/bundlers/vite/bundle-entries.ts
|
|
@@ -1029,28 +1046,6 @@ function updateBundleBuildState(state, snapshot, linkedByEntry, options = {}) {
|
|
|
1029
1046
|
state.dependentsByLinkedFile = invertLinkedByEntry(state.linkedByEntry);
|
|
1030
1047
|
}
|
|
1031
1048
|
|
|
1032
|
-
// src/bundlers/vite/js-precheck.ts
|
|
1033
|
-
var FAST_JS_TRANSFORM_HINT_RE = /className\b|class\s*=|classList\.|\b(?:twMerge|clsx|classnames|cn|cva)\b|\[["'`]class["'`]\]|text-\[|bg-\[|\b(?:[whpm]|px|py|mx|my|rounded|flex|grid|gap)-/;
|
|
1034
|
-
var DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
|
|
1035
|
-
function shouldSkipViteJsTransform(rawSource, options) {
|
|
1036
|
-
if (!rawSource) {
|
|
1037
|
-
return true;
|
|
1038
|
-
}
|
|
1039
|
-
if (options?.alwaysEscape) {
|
|
1040
|
-
return false;
|
|
1041
|
-
}
|
|
1042
|
-
if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) {
|
|
1043
|
-
return false;
|
|
1044
|
-
}
|
|
1045
|
-
if (options?.wrapExpression) {
|
|
1046
|
-
return false;
|
|
1047
|
-
}
|
|
1048
|
-
if (DEPENDENCY_HINT_RE.test(rawSource)) {
|
|
1049
|
-
return false;
|
|
1050
|
-
}
|
|
1051
|
-
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
1049
|
// src/bundlers/vite/generate-bundle.ts
|
|
1055
1050
|
function formatDebugFileList(files, limit = 8) {
|
|
1056
1051
|
if (files.size === 0) {
|
|
@@ -1336,7 +1331,7 @@ function createGenerateBundleHook(context) {
|
|
|
1336
1331
|
let transformed = await templateHandler(rawSource, defaultTemplateHandlerOptions);
|
|
1337
1332
|
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
1338
1333
|
if (unresolvedDynamicCandidates.length > 0) {
|
|
1339
|
-
|
|
1334
|
+
logger2.warn(
|
|
1340
1335
|
"\u68C0\u6D4B\u5230 WXML \u52A8\u6001\u7C7B\u540D\u672A\u5B8C\u6210\u8F6C\u8BD1\uFF0C\u5DF2\u56DE\u9000\u5230\u5B8C\u6574 runtimeSet \u91CD\u8BD5: %s -> %O",
|
|
1341
1336
|
file,
|
|
1342
1337
|
unresolvedDynamicCandidates
|
|
@@ -1347,7 +1342,7 @@ function createGenerateBundleHook(context) {
|
|
|
1347
1342
|
});
|
|
1348
1343
|
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
1349
1344
|
if (unresolvedDynamicCandidates.length > 0) {
|
|
1350
|
-
|
|
1345
|
+
logger2.warn(
|
|
1351
1346
|
"WXML \u52A8\u6001\u7C7B\u540D\u5728\u5B8C\u6574 runtimeSet \u91CD\u8BD5\u540E\u4ECD\u672A\u5B8C\u6210\u8F6C\u8BD1: %s -> %O",
|
|
1352
1347
|
file,
|
|
1353
1348
|
unresolvedDynamicCandidates
|
|
@@ -1466,7 +1461,7 @@ function createGenerateBundleHook(context) {
|
|
|
1466
1461
|
debug3("js cache replay miss, fallback transform: %s", file);
|
|
1467
1462
|
}
|
|
1468
1463
|
const handlerOptions = createHandlerOptions(absoluteFile);
|
|
1469
|
-
if (!disableJsPrecheck &&
|
|
1464
|
+
if (!disableJsPrecheck && shouldSkipJsTransform(rawSource, handlerOptions)) {
|
|
1470
1465
|
metrics.js.elapsed += measureElapsed(start);
|
|
1471
1466
|
metrics.js.transformed++;
|
|
1472
1467
|
return {
|
|
@@ -1552,7 +1547,7 @@ function createGenerateBundleHook(context) {
|
|
|
1552
1547
|
sourceType: "unambiguous"
|
|
1553
1548
|
}
|
|
1554
1549
|
});
|
|
1555
|
-
if (!disableJsPrecheck &&
|
|
1550
|
+
if (!disableJsPrecheck && shouldSkipJsTransform(currentSource, precheckOptions)) {
|
|
1556
1551
|
metrics.js.elapsed += measureElapsed(start);
|
|
1557
1552
|
metrics.js.transformed++;
|
|
1558
1553
|
return;
|
|
@@ -2335,7 +2330,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2335
2330
|
if (nextAppType && opts.appType !== nextAppType) {
|
|
2336
2331
|
const previousAppType = opts.appType;
|
|
2337
2332
|
opts.appType = nextAppType;
|
|
2338
|
-
|
|
2333
|
+
logger3.info("\u6839\u636E Vite \u9879\u76EE\u6839\u76EE\u5F55\u81EA\u52A8\u63A8\u65AD appType -> %s", nextAppType);
|
|
2339
2334
|
debug2(
|
|
2340
2335
|
"align appType with vite root: %s -> %s",
|
|
2341
2336
|
previousAppType ?? "undefined",
|
|
@@ -2359,14 +2354,17 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2359
2354
|
}
|
|
2360
2355
|
}
|
|
2361
2356
|
},
|
|
2362
|
-
generateBundle:
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2357
|
+
generateBundle: {
|
|
2358
|
+
order: "post",
|
|
2359
|
+
handler: createGenerateBundleHook({
|
|
2360
|
+
opts,
|
|
2361
|
+
runtimeState,
|
|
2362
|
+
ensureRuntimeClassSet,
|
|
2363
|
+
ensureBundleRuntimeClassSet,
|
|
2364
|
+
debug: debug2,
|
|
2365
|
+
getResolvedConfig
|
|
2366
|
+
})
|
|
2367
|
+
}
|
|
2370
2368
|
}
|
|
2371
2369
|
];
|
|
2372
2370
|
if (uniAppXPlugins) {
|
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
invalidateRuntimeClassSet,
|
|
8
8
|
isUniAppXEnabled,
|
|
9
9
|
logger,
|
|
10
|
+
resolveUniAppXOptions,
|
|
10
11
|
warnMissingCssEntries
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-AYJ4HLWZ.mjs";
|
|
12
13
|
import {
|
|
13
14
|
getDefaultOptions
|
|
14
15
|
} from "./chunk-XAKAD2CR.mjs";
|
|
@@ -362,14 +363,14 @@ function initializeCache(cacheConfig) {
|
|
|
362
363
|
}
|
|
363
364
|
|
|
364
365
|
// src/tailwindcss/runtime-logs.ts
|
|
365
|
-
import
|
|
366
|
+
import process2 from "process";
|
|
366
367
|
import { logger as logger2, pc } from "@weapp-tailwindcss/logger";
|
|
367
368
|
var runtimeLogDedupeHolder = globalThis;
|
|
368
369
|
var runtimeLogDedupe = runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ = /* @__PURE__ */ new Set());
|
|
369
370
|
function createRuntimeLogKey(category, baseDir, rootPath, version) {
|
|
370
371
|
return JSON.stringify([
|
|
371
372
|
category,
|
|
372
|
-
baseDir ??
|
|
373
|
+
baseDir ?? process2.cwd(),
|
|
373
374
|
rootPath ?? "",
|
|
374
375
|
version ?? ""
|
|
375
376
|
]);
|
|
@@ -404,7 +405,7 @@ function logRuntimeTailwindcssVersion(baseDir, rootPath, version) {
|
|
|
404
405
|
}
|
|
405
406
|
|
|
406
407
|
// src/tailwindcss/targets.ts
|
|
407
|
-
import
|
|
408
|
+
import process5 from "process";
|
|
408
409
|
import { logger as logger4 } from "@weapp-tailwindcss/logger";
|
|
409
410
|
|
|
410
411
|
// src/tailwindcss/targets/paths.ts
|
|
@@ -459,13 +460,13 @@ function getRecordFileCandidates(baseDir) {
|
|
|
459
460
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
460
461
|
import { mkdir, writeFile } from "fs/promises";
|
|
461
462
|
import path2 from "path";
|
|
462
|
-
import
|
|
463
|
+
import process3 from "process";
|
|
463
464
|
import { logger as logger3 } from "@weapp-tailwindcss/logger";
|
|
464
465
|
|
|
465
466
|
// package.json
|
|
466
467
|
var package_default = {
|
|
467
468
|
name: "weapp-tailwindcss",
|
|
468
|
-
version: "4.
|
|
469
|
+
version: "4.12.0-alpha.1",
|
|
469
470
|
description: "\u628A tailwindcss \u539F\u5B50\u5316\u6837\u5F0F\u601D\u60F3\uFF0C\u5E26\u7ED9\u5C0F\u7A0B\u5E8F\u5F00\u53D1\u8005\u4EEC! bring tailwindcss to miniprogram developers!",
|
|
470
471
|
author: "ice breaker <1324318532@qq.com>",
|
|
471
472
|
license: "MIT",
|
|
@@ -667,6 +668,7 @@ var package_default = {
|
|
|
667
668
|
"@weapp-core/regex": "~1.0.1",
|
|
668
669
|
"@weapp-tailwindcss/logger": "workspace:*",
|
|
669
670
|
"@weapp-tailwindcss/postcss": "workspace:*",
|
|
671
|
+
"@weapp-tailwindcss/reset": "workspace:*",
|
|
670
672
|
"@weapp-tailwindcss/shared": "workspace:*",
|
|
671
673
|
cac: "6.7.14",
|
|
672
674
|
"comment-json": "^4.6.2",
|
|
@@ -681,6 +683,9 @@ var package_default = {
|
|
|
681
683
|
"tailwindcss-patch": "catalog:tailwindcssPatch",
|
|
682
684
|
"webpack-sources": "3.3.4",
|
|
683
685
|
yaml: "^2.8.3"
|
|
686
|
+
},
|
|
687
|
+
devDependencies: {
|
|
688
|
+
"fast-check": "^4.7.0"
|
|
684
689
|
}
|
|
685
690
|
};
|
|
686
691
|
|
|
@@ -703,7 +708,7 @@ function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
|
|
|
703
708
|
}
|
|
704
709
|
loggedInvalidPatchRecords.add(normalizedPath);
|
|
705
710
|
const fileDisplay = formatRelativeToBase(normalizedPath, baseDir);
|
|
706
|
-
const baseDisplay = formatRelativeToBase(path2.normalize(baseDir),
|
|
711
|
+
const baseDisplay = formatRelativeToBase(path2.normalize(baseDir), process3.cwd());
|
|
707
712
|
const reasonMessage = reason ? `\uFF1A${reason}` : "";
|
|
708
713
|
logger3.warn(
|
|
709
714
|
`\u68C0\u6D4B\u5230\u635F\u574F\u7684 Tailwind CSS \u76EE\u6807\u8BB0\u5F55 ${fileDisplay}${reasonMessage}\u3002\u8BF7\u5728 ${baseDisplay} \u91CD\u65B0\u6267\u884C "weapp-tw patch --record-target" \u6216\u5220\u9664\u8BE5\u6587\u4EF6\u540E\u518D\u8FD0\u884C\u3002`
|
|
@@ -762,7 +767,7 @@ async function saveCliPatchTargetRecord(baseDir, patcher, options) {
|
|
|
762
767
|
`, "utf8");
|
|
763
768
|
return recordPath;
|
|
764
769
|
} catch (error) {
|
|
765
|
-
const baseDisplay = formatRelativeToBase(normalizedBase,
|
|
770
|
+
const baseDisplay = formatRelativeToBase(normalizedBase, process3.cwd());
|
|
766
771
|
logger3.warn(
|
|
767
772
|
'\u81EA\u52A8\u66F4\u65B0 Tailwind CSS \u8865\u4E01\u8BB0\u5F55\u5931\u8D25\uFF0C\u8BF7\u5728 %s \u8FD0\u884C "weapp-tw patch --cwd %s"\u3002',
|
|
768
773
|
baseDisplay,
|
|
@@ -775,10 +780,10 @@ async function saveCliPatchTargetRecord(baseDir, patcher, options) {
|
|
|
775
780
|
|
|
776
781
|
// src/tailwindcss/targets/recorder.ts
|
|
777
782
|
import path3 from "path";
|
|
778
|
-
import
|
|
783
|
+
import process4 from "process";
|
|
779
784
|
function findPatchTargetRecord(baseDir) {
|
|
780
785
|
const visited = /* @__PURE__ */ new Set();
|
|
781
|
-
const fallback = baseDir ??
|
|
786
|
+
const fallback = baseDir ?? process4.cwd();
|
|
782
787
|
let current = path3.resolve(fallback);
|
|
783
788
|
while (!visited.has(current)) {
|
|
784
789
|
const record = readPatchTargetRecord(current);
|
|
@@ -861,7 +866,7 @@ function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
|
861
866
|
logger4.warn(
|
|
862
867
|
"%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
|
|
863
868
|
label,
|
|
864
|
-
baseDir ??
|
|
869
|
+
baseDir ?? process5.cwd()
|
|
865
870
|
);
|
|
866
871
|
return;
|
|
867
872
|
}
|
|
@@ -877,7 +882,7 @@ function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
|
877
882
|
// src/context/compiler-context-cache.ts
|
|
878
883
|
import { Buffer } from "buffer";
|
|
879
884
|
import path4 from "path";
|
|
880
|
-
import
|
|
885
|
+
import process6 from "process";
|
|
881
886
|
import { logger as logger5 } from "@weapp-tailwindcss/logger";
|
|
882
887
|
var PAREN_CONTENT_RE = /\(([^)]+)\)/u;
|
|
883
888
|
var AT_LOCATION_RE = /at\s+(\S.*)$/u;
|
|
@@ -911,7 +916,7 @@ function shouldProbeCallerLocation(opts) {
|
|
|
911
916
|
if (hasExplicitOptionBasedir(opts)) {
|
|
912
917
|
return false;
|
|
913
918
|
}
|
|
914
|
-
return !(
|
|
919
|
+
return !(process6.env.WEAPP_TAILWINDCSS_BASEDIR || process6.env.WEAPP_TAILWINDCSS_BASE_DIR || process6.env.TAILWINDCSS_BASEDIR || process6.env.TAILWINDCSS_BASE_DIR);
|
|
915
920
|
}
|
|
916
921
|
function detectCallerLocation() {
|
|
917
922
|
const stack = new Error("compiler-context-cache stack probe").stack;
|
|
@@ -944,20 +949,20 @@ function getRuntimeCacheScope(opts) {
|
|
|
944
949
|
}
|
|
945
950
|
const runtimeScope = {
|
|
946
951
|
caller: void 0,
|
|
947
|
-
cwd:
|
|
948
|
-
init_cwd:
|
|
949
|
-
npm_config_local_prefix:
|
|
950
|
-
npm_package_json:
|
|
951
|
-
pnpm_package_name:
|
|
952
|
-
pwd:
|
|
953
|
-
tailwindcss_base_dir:
|
|
954
|
-
tailwindcss_basedir:
|
|
955
|
-
uni_app_input_dir:
|
|
956
|
-
uni_cli_root:
|
|
957
|
-
uni_input_dir:
|
|
958
|
-
uni_input_root:
|
|
959
|
-
weapp_tailwindcss_base_dir:
|
|
960
|
-
weapp_tailwindcss_basedir:
|
|
952
|
+
cwd: process6.cwd(),
|
|
953
|
+
init_cwd: process6.env.INIT_CWD,
|
|
954
|
+
npm_config_local_prefix: process6.env.npm_config_local_prefix,
|
|
955
|
+
npm_package_json: process6.env.npm_package_json,
|
|
956
|
+
pnpm_package_name: process6.env.PNPM_PACKAGE_NAME,
|
|
957
|
+
pwd: process6.env.PWD,
|
|
958
|
+
tailwindcss_base_dir: process6.env.TAILWINDCSS_BASE_DIR,
|
|
959
|
+
tailwindcss_basedir: process6.env.TAILWINDCSS_BASEDIR,
|
|
960
|
+
uni_app_input_dir: process6.env.UNI_APP_INPUT_DIR,
|
|
961
|
+
uni_cli_root: process6.env.UNI_CLI_ROOT,
|
|
962
|
+
uni_input_dir: process6.env.UNI_INPUT_DIR,
|
|
963
|
+
uni_input_root: process6.env.UNI_INPUT_ROOT,
|
|
964
|
+
weapp_tailwindcss_base_dir: process6.env.WEAPP_TAILWINDCSS_BASE_DIR,
|
|
965
|
+
weapp_tailwindcss_basedir: process6.env.WEAPP_TAILWINDCSS_BASEDIR
|
|
961
966
|
};
|
|
962
967
|
if (shouldProbeCallerLocation(opts)) {
|
|
963
968
|
runtimeScope.caller = detectCallerLocation();
|
|
@@ -1164,6 +1169,9 @@ function toCustomAttributesEntities(customAttributes) {
|
|
|
1164
1169
|
// src/context/handlers.ts
|
|
1165
1170
|
import { createStyleHandler } from "@weapp-tailwindcss/postcss";
|
|
1166
1171
|
|
|
1172
|
+
// src/js/index.ts
|
|
1173
|
+
import { LRUCache as LRUCache3 } from "lru-cache";
|
|
1174
|
+
|
|
1167
1175
|
// src/babel/index.ts
|
|
1168
1176
|
import _babelTraverse from "@babel/traverse";
|
|
1169
1177
|
import { parse, parseExpression } from "@babel/parser";
|
|
@@ -2981,6 +2989,49 @@ function jsHandler(rawSource, options) {
|
|
|
2981
2989
|
}
|
|
2982
2990
|
|
|
2983
2991
|
// src/js/index.ts
|
|
2992
|
+
var RESULT_CACHE_MAX = 512;
|
|
2993
|
+
var classNameSetIds = /* @__PURE__ */ new WeakMap();
|
|
2994
|
+
var nextClassNameSetId = 0;
|
|
2995
|
+
function getClassNameSetId(set) {
|
|
2996
|
+
if (!set) {
|
|
2997
|
+
return "none";
|
|
2998
|
+
}
|
|
2999
|
+
const existing = classNameSetIds.get(set);
|
|
3000
|
+
if (existing !== void 0) {
|
|
3001
|
+
return String(existing);
|
|
3002
|
+
}
|
|
3003
|
+
const id = nextClassNameSetId++;
|
|
3004
|
+
classNameSetIds.set(set, id);
|
|
3005
|
+
return String(id);
|
|
3006
|
+
}
|
|
3007
|
+
var fingerprintCache = /* @__PURE__ */ new WeakMap();
|
|
3008
|
+
function getOptionsFingerprint(options) {
|
|
3009
|
+
const cached = fingerprintCache.get(options);
|
|
3010
|
+
if (cached) {
|
|
3011
|
+
return cached;
|
|
3012
|
+
}
|
|
3013
|
+
const parts = [
|
|
3014
|
+
getClassNameSetId(options.classNameSet),
|
|
3015
|
+
JSON.stringify(options.escapeMap ?? null),
|
|
3016
|
+
options.needEscaped ? "1" : "0",
|
|
3017
|
+
options.alwaysEscape ? "1" : "0",
|
|
3018
|
+
options.unescapeUnicode ? "1" : "0",
|
|
3019
|
+
options.generateMap ? "1" : "0",
|
|
3020
|
+
options.uniAppX ? "1" : "0",
|
|
3021
|
+
options.wrapExpression ? "1" : "0",
|
|
3022
|
+
String(options.tailwindcssMajorVersion ?? ""),
|
|
3023
|
+
String(options.staleClassNameFallback ?? ""),
|
|
3024
|
+
String(options.jsArbitraryValueFallback ?? ""),
|
|
3025
|
+
JSON.stringify(options.arbitraryValues ?? null),
|
|
3026
|
+
JSON.stringify(options.ignoreCallExpressionIdentifiers ?? null),
|
|
3027
|
+
JSON.stringify(options.ignoreTaggedTemplateExpressionIdentifiers?.map((v) => v instanceof RegExp ? v.source : v) ?? null),
|
|
3028
|
+
JSON.stringify(options.moduleSpecifierReplacements ?? null),
|
|
3029
|
+
JSON.stringify(options.babelParserOptions ?? null)
|
|
3030
|
+
];
|
|
3031
|
+
const fingerprint = parts.join("|");
|
|
3032
|
+
fingerprintCache.set(options, fingerprint);
|
|
3033
|
+
return fingerprint;
|
|
3034
|
+
}
|
|
2984
3035
|
function hasDefinedOverrides(options) {
|
|
2985
3036
|
if (!options) {
|
|
2986
3037
|
return false;
|
|
@@ -2992,17 +3043,6 @@ function hasDefinedOverrides(options) {
|
|
|
2992
3043
|
}
|
|
2993
3044
|
return false;
|
|
2994
3045
|
}
|
|
2995
|
-
var CACHEABLE_SOURCE_MAX_LENGTH = 512;
|
|
2996
|
-
var RESULT_CACHE_LIMIT = 256;
|
|
2997
|
-
function shouldCacheJsResult(rawSource, options) {
|
|
2998
|
-
if (rawSource.length === 0 || rawSource.length > CACHEABLE_SOURCE_MAX_LENGTH) {
|
|
2999
|
-
return false;
|
|
3000
|
-
}
|
|
3001
|
-
if (options.moduleGraph || options.filename) {
|
|
3002
|
-
return false;
|
|
3003
|
-
}
|
|
3004
|
-
return true;
|
|
3005
|
-
}
|
|
3006
3046
|
function createJsHandler(options) {
|
|
3007
3047
|
const defaults = {
|
|
3008
3048
|
escapeMap: options.escapeMap,
|
|
@@ -3021,11 +3061,10 @@ function createJsHandler(options) {
|
|
|
3021
3061
|
uniAppX: options.uniAppX,
|
|
3022
3062
|
moduleSpecifierReplacements: options.moduleSpecifierReplacements
|
|
3023
3063
|
};
|
|
3024
|
-
const
|
|
3064
|
+
const defaultOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
3025
3065
|
let resolvedOptionsWithoutClassNameSet;
|
|
3026
|
-
const
|
|
3027
|
-
const
|
|
3028
|
-
const resultCache = /* @__PURE__ */ new WeakMap();
|
|
3066
|
+
const overrideOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
3067
|
+
const resultCache = new LRUCache3({ max: RESULT_CACHE_MAX });
|
|
3029
3068
|
function resolveDefaultOptions(classNameSet) {
|
|
3030
3069
|
if (!classNameSet) {
|
|
3031
3070
|
if (!resolvedOptionsWithoutClassNameSet) {
|
|
@@ -3036,7 +3075,7 @@ function createJsHandler(options) {
|
|
|
3036
3075
|
}
|
|
3037
3076
|
return resolvedOptionsWithoutClassNameSet;
|
|
3038
3077
|
}
|
|
3039
|
-
const cached =
|
|
3078
|
+
const cached = defaultOptionsCache.get(classNameSet);
|
|
3040
3079
|
if (cached) {
|
|
3041
3080
|
return cached;
|
|
3042
3081
|
}
|
|
@@ -3044,42 +3083,36 @@ function createJsHandler(options) {
|
|
|
3044
3083
|
...defaults,
|
|
3045
3084
|
classNameSet
|
|
3046
3085
|
};
|
|
3047
|
-
|
|
3086
|
+
defaultOptionsCache.set(classNameSet, created);
|
|
3048
3087
|
return created;
|
|
3049
3088
|
}
|
|
3050
3089
|
function getCachedJsResult(rawSource, resolvedOptions) {
|
|
3051
|
-
if (
|
|
3090
|
+
if (rawSource.length === 0) {
|
|
3052
3091
|
return void 0;
|
|
3053
3092
|
}
|
|
3054
|
-
const
|
|
3055
|
-
return
|
|
3093
|
+
const key = `${getOptionsFingerprint(resolvedOptions)}:${md5(rawSource)}`;
|
|
3094
|
+
return resultCache.get(key);
|
|
3056
3095
|
}
|
|
3057
3096
|
function setCachedJsResult(rawSource, resolvedOptions, result) {
|
|
3058
|
-
if (
|
|
3097
|
+
if (rawSource.length === 0 || result.error || result.linked) {
|
|
3059
3098
|
return result;
|
|
3060
3099
|
}
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
cache = /* @__PURE__ */ new Map();
|
|
3064
|
-
resultCache.set(resolvedOptions, cache);
|
|
3065
|
-
}
|
|
3066
|
-
cache.set(rawSource, result);
|
|
3067
|
-
if (cache.size > RESULT_CACHE_LIMIT) {
|
|
3068
|
-
const firstKey = cache.keys().next().value;
|
|
3069
|
-
if (typeof firstKey === "string") {
|
|
3070
|
-
cache.delete(firstKey);
|
|
3071
|
-
}
|
|
3072
|
-
}
|
|
3100
|
+
const key = `${getOptionsFingerprint(resolvedOptions)}:${md5(rawSource)}`;
|
|
3101
|
+
resultCache.set(key, result);
|
|
3073
3102
|
return result;
|
|
3074
3103
|
}
|
|
3075
3104
|
function resolveOptions(classNameSet, overrideOptions) {
|
|
3076
3105
|
if (!hasDefinedOverrides(overrideOptions)) {
|
|
3077
3106
|
return resolveDefaultOptions(classNameSet);
|
|
3078
3107
|
}
|
|
3108
|
+
let entry = overrideOptionsCache.get(overrideOptions);
|
|
3109
|
+
if (!entry) {
|
|
3110
|
+
entry = { bySet: /* @__PURE__ */ new WeakMap() };
|
|
3111
|
+
overrideOptionsCache.set(overrideOptions, entry);
|
|
3112
|
+
}
|
|
3079
3113
|
if (!classNameSet) {
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
return cached2;
|
|
3114
|
+
if (entry.noSet) {
|
|
3115
|
+
return entry.noSet;
|
|
3083
3116
|
}
|
|
3084
3117
|
const created2 = defuOverrideArray(
|
|
3085
3118
|
{
|
|
@@ -3088,15 +3121,10 @@ function createJsHandler(options) {
|
|
|
3088
3121
|
},
|
|
3089
3122
|
defaults
|
|
3090
3123
|
);
|
|
3091
|
-
|
|
3124
|
+
entry.noSet = created2;
|
|
3092
3125
|
return created2;
|
|
3093
3126
|
}
|
|
3094
|
-
|
|
3095
|
-
if (!cache) {
|
|
3096
|
-
cache = /* @__PURE__ */ new WeakMap();
|
|
3097
|
-
resolvedOverrideOptionsByClassNameSet.set(overrideOptions, cache);
|
|
3098
|
-
}
|
|
3099
|
-
const cached = cache.get(classNameSet);
|
|
3127
|
+
const cached = entry.bySet.get(classNameSet);
|
|
3100
3128
|
if (cached) {
|
|
3101
3129
|
return cached;
|
|
3102
3130
|
}
|
|
@@ -3107,7 +3135,7 @@ function createJsHandler(options) {
|
|
|
3107
3135
|
},
|
|
3108
3136
|
defaults
|
|
3109
3137
|
);
|
|
3110
|
-
|
|
3138
|
+
entry.bySet.set(classNameSet, created);
|
|
3111
3139
|
return created;
|
|
3112
3140
|
}
|
|
3113
3141
|
function handler(rawSource, classNameSet, options2) {
|
|
@@ -3637,6 +3665,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
3637
3665
|
cssRemoveProperty,
|
|
3638
3666
|
cssRemoveHoverPseudoClass,
|
|
3639
3667
|
cssPresetEnv,
|
|
3668
|
+
autoprefixer,
|
|
3640
3669
|
uniAppX,
|
|
3641
3670
|
px2rpx,
|
|
3642
3671
|
unitsToPx,
|
|
@@ -3652,6 +3681,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
3652
3681
|
replaceRuntimePackages
|
|
3653
3682
|
} = ctx;
|
|
3654
3683
|
const uniAppXEnabled = isUniAppXEnabled(uniAppX);
|
|
3684
|
+
const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
|
|
3655
3685
|
const moduleSpecifierReplacements = resolveRuntimePackageReplacements(replaceRuntimePackages);
|
|
3656
3686
|
const styleHandler = createStyleHandler({
|
|
3657
3687
|
cssPreflight,
|
|
@@ -3665,10 +3695,13 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
3665
3695
|
cssRemoveProperty,
|
|
3666
3696
|
cssRemoveHoverPseudoClass,
|
|
3667
3697
|
cssPresetEnv,
|
|
3698
|
+
autoprefixer,
|
|
3668
3699
|
uniAppX: uniAppXEnabled,
|
|
3700
|
+
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
3669
3701
|
cssCalc: cssCalcOptions,
|
|
3670
3702
|
px2rpx,
|
|
3671
|
-
unitsToPx
|
|
3703
|
+
unitsToPx,
|
|
3704
|
+
majorVersion: tailwindcssMajorVersion
|
|
3672
3705
|
});
|
|
3673
3706
|
const jsHandler2 = createJsHandler({
|
|
3674
3707
|
escapeMap,
|
|
@@ -3808,6 +3841,31 @@ function getCompilerContext(opts) {
|
|
|
3808
3841
|
return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
|
|
3809
3842
|
}
|
|
3810
3843
|
|
|
3844
|
+
// src/js/precheck.ts
|
|
3845
|
+
var FAST_JS_TRANSFORM_HINT_RE = /className\b|class\s*=|classList\.|\b(?:twMerge|clsx|classnames|cn|cva)\b|\[["'`]class["'`]\]|text-\[|bg-\[|\b(?:[whpm]|px|py|mx|my|rounded|flex|grid|gap)-/;
|
|
3846
|
+
var DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
|
|
3847
|
+
function shouldSkipJsTransform(rawSource, options) {
|
|
3848
|
+
if (process.env.WEAPP_TW_DISABLE_JS_PRECHECK === "1") {
|
|
3849
|
+
return false;
|
|
3850
|
+
}
|
|
3851
|
+
if (!rawSource) {
|
|
3852
|
+
return true;
|
|
3853
|
+
}
|
|
3854
|
+
if (options?.alwaysEscape) {
|
|
3855
|
+
return false;
|
|
3856
|
+
}
|
|
3857
|
+
if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) {
|
|
3858
|
+
return false;
|
|
3859
|
+
}
|
|
3860
|
+
if (options?.wrapExpression) {
|
|
3861
|
+
return false;
|
|
3862
|
+
}
|
|
3863
|
+
if (DEPENDENCY_HINT_RE.test(rawSource)) {
|
|
3864
|
+
return false;
|
|
3865
|
+
}
|
|
3866
|
+
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
3867
|
+
}
|
|
3868
|
+
|
|
3811
3869
|
// src/tailwindcss/recorder.ts
|
|
3812
3870
|
function setupPatchRecorder(patcher, baseDir, options) {
|
|
3813
3871
|
const recorder = createPatchTargetRecorder(baseDir, patcher, options);
|
|
@@ -3843,5 +3901,6 @@ export {
|
|
|
3843
3901
|
createAttributeMatcher,
|
|
3844
3902
|
generateCode,
|
|
3845
3903
|
getCompilerContext,
|
|
3904
|
+
shouldSkipJsTransform,
|
|
3846
3905
|
setupPatchRecorder
|
|
3847
3906
|
};
|