weapp-tailwindcss 4.11.0-alpha.1 → 4.11.0-alpha.2
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-35EI5JMK.mjs → chunk-23K4XDKF.mjs} +3 -1
- package/dist/{chunk-W2EMGF7H.js → chunk-2W24MRCQ.js} +10 -12
- package/dist/chunk-4AFQP74Z.js +24 -0
- package/dist/{chunk-SQG2MOFQ.js → chunk-4TTPYMVM.js} +12 -8
- package/dist/{chunk-4LPOQMFS.js → chunk-5KSBT6GU.js} +396 -219
- package/dist/{chunk-LD7LZ4IK.mjs → chunk-66E76FQE.mjs} +91 -50
- package/dist/{chunk-GWDHNCL2.js → chunk-6O7HJU2F.js} +123 -42
- package/dist/{chunk-RRHPTTCP.mjs → chunk-76S2EME4.mjs} +2 -0
- package/dist/{chunk-G3G437UE.js → chunk-7LKMJZD2.js} +2 -2
- package/dist/{chunk-OV7FX6XR.js → chunk-CRDOWYG4.js} +1 -1
- package/dist/{chunk-DOH7FULQ.mjs → chunk-EFBQ4SQR.mjs} +1 -1
- package/dist/{chunk-IEZ5RBMG.mjs → chunk-EW2K6CO5.mjs} +365 -188
- package/dist/{chunk-FZNYV7VH.mjs → chunk-HADJCWHU.mjs} +212 -258
- package/dist/{chunk-CZLXTEHN.js → chunk-K7CZXT46.js} +132 -91
- package/dist/{chunk-ACTJYB33.js → chunk-LL3QUKJI.js} +3 -1
- package/dist/{chunk-G5NLM3AL.js → chunk-LYGLQCWI.js} +278 -324
- package/dist/{chunk-LTJQUORK.js → chunk-OF6MFURR.js} +2 -0
- package/dist/{chunk-KKT2DKMW.mjs → chunk-RED7Y22U.mjs} +91 -10
- package/dist/{chunk-R6KEYO3F.mjs → chunk-SJ3SG6DU.mjs} +5 -1
- package/dist/{chunk-JBM3HGHP.mjs → chunk-UCUAXK7F.mjs} +4 -6
- package/dist/cli.js +1006 -147
- package/dist/cli.mjs +942 -107
- package/dist/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +9 -11
- package/dist/core.mjs +6 -8
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +3 -3
- package/dist/css-macro.mjs +4 -4
- package/dist/defaults.d.mts +2 -2
- package/dist/defaults.d.ts +2 -2
- package/dist/defaults.js +3 -3
- package/dist/defaults.mjs +2 -2
- package/dist/gulp.d.mts +2 -2
- package/dist/gulp.d.ts +2 -2
- package/dist/gulp.js +7 -8
- package/dist/gulp.mjs +6 -7
- package/dist/{index-t_VBjwYm.d.ts → index-BMwzhITq.d.mts} +6 -6
- package/dist/{index-t_VBjwYm.d.mts → index-BMwzhITq.d.ts} +6 -6
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -12
- package/dist/index.mjs +9 -10
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.d.mts +2 -2
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +5 -5
- package/dist/presets.mjs +2 -2
- package/dist/reset.js +1 -1
- package/dist/reset.mjs +1 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.d.ts +4 -4
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.d.mts +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +8 -9
- package/dist/vite.mjs +6 -7
- package/dist/weapp-tw-css-import-rewrite-loader.js +3 -1
- package/dist/weapp-tw-runtime-classset-loader.js +29 -2
- package/dist/webpack.d.mts +2 -2
- package/dist/webpack.d.ts +2 -2
- package/dist/webpack.js +9 -10
- package/dist/webpack.mjs +7 -8
- package/dist/webpack4.d.mts +2 -2
- package/dist/webpack4.d.ts +2 -2
- package/dist/webpack4.js +41 -41
- package/dist/webpack4.mjs +12 -12
- package/package.json +8 -8
- package/dist/chunk-NOKJXG3W.js +0 -29
- package/dist/chunk-QYZCRG7F.mjs +0 -29
|
@@ -2,11 +2,15 @@ import {
|
|
|
2
2
|
applyV4CssCalcDefaults,
|
|
3
3
|
createTailwindcssPatcherFromContext,
|
|
4
4
|
findNearestPackageRoot,
|
|
5
|
+
getRuntimeClassSetCacheEntry,
|
|
6
|
+
getRuntimeClassSetSignature,
|
|
7
|
+
invalidateRuntimeClassSet,
|
|
8
|
+
logger,
|
|
5
9
|
warnMissingCssEntries
|
|
6
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-EW2K6CO5.mjs";
|
|
7
11
|
import {
|
|
8
12
|
getDefaultOptions
|
|
9
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-23K4XDKF.mjs";
|
|
10
14
|
import {
|
|
11
15
|
defuOverrideArray,
|
|
12
16
|
isMap
|
|
@@ -29,72 +33,6 @@ function createDebug(prefix) {
|
|
|
29
33
|
return debug3;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
// src/tailwindcss/runtime/cache.ts
|
|
33
|
-
import { statSync } from "fs";
|
|
34
|
-
var runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
|
|
35
|
-
var runtimeConfigSignatureCache = /* @__PURE__ */ new Map();
|
|
36
|
-
var runtimeConfigSignatureCacheClearTimer;
|
|
37
|
-
function getCacheEntry(twPatcher) {
|
|
38
|
-
let entry = runtimeClassSetCache.get(twPatcher);
|
|
39
|
-
if (!entry) {
|
|
40
|
-
entry = {};
|
|
41
|
-
runtimeClassSetCache.set(twPatcher, entry);
|
|
42
|
-
}
|
|
43
|
-
return entry;
|
|
44
|
-
}
|
|
45
|
-
function scheduleRuntimeConfigSignatureCacheClear() {
|
|
46
|
-
if (runtimeConfigSignatureCacheClearTimer) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
runtimeConfigSignatureCacheClearTimer = setTimeout(() => {
|
|
50
|
-
runtimeConfigSignatureCache.clear();
|
|
51
|
-
runtimeConfigSignatureCacheClearTimer = void 0;
|
|
52
|
-
}, 0);
|
|
53
|
-
runtimeConfigSignatureCacheClearTimer.unref?.();
|
|
54
|
-
}
|
|
55
|
-
function getTailwindConfigSignature(twPatcher) {
|
|
56
|
-
const configPath = twPatcher.options?.tailwind?.config;
|
|
57
|
-
if (typeof configPath !== "string" || configPath.length === 0) {
|
|
58
|
-
return void 0;
|
|
59
|
-
}
|
|
60
|
-
const cached = runtimeConfigSignatureCache.get(configPath);
|
|
61
|
-
if (cached !== void 0) {
|
|
62
|
-
return cached;
|
|
63
|
-
}
|
|
64
|
-
let signature;
|
|
65
|
-
try {
|
|
66
|
-
const stats = statSync(configPath);
|
|
67
|
-
signature = `${configPath}:${stats.size}:${stats.mtimeMs}`;
|
|
68
|
-
} catch {
|
|
69
|
-
signature = `${configPath}:missing`;
|
|
70
|
-
}
|
|
71
|
-
runtimeConfigSignatureCache.set(configPath, signature);
|
|
72
|
-
scheduleRuntimeConfigSignatureCacheClear();
|
|
73
|
-
return signature;
|
|
74
|
-
}
|
|
75
|
-
function getPatchTargetSignature(twPatcher) {
|
|
76
|
-
const packageInfo = twPatcher.packageInfo;
|
|
77
|
-
return `${packageInfo?.rootPath ?? "missing"}:${packageInfo?.version ?? "unknown"}:${twPatcher.majorVersion ?? "unknown"}`;
|
|
78
|
-
}
|
|
79
|
-
function invalidateRuntimeClassSet(twPatcher) {
|
|
80
|
-
if (!twPatcher) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const configPath = twPatcher.options?.tailwind?.config;
|
|
84
|
-
if (typeof configPath === "string" && configPath.length > 0) {
|
|
85
|
-
runtimeConfigSignatureCache.delete(configPath);
|
|
86
|
-
}
|
|
87
|
-
runtimeClassSetCache.delete(twPatcher);
|
|
88
|
-
}
|
|
89
|
-
function getRuntimeClassSetCacheEntry(twPatcher) {
|
|
90
|
-
return getCacheEntry(twPatcher);
|
|
91
|
-
}
|
|
92
|
-
function getRuntimeClassSetSignature(twPatcher) {
|
|
93
|
-
const configSignature = getTailwindConfigSignature(twPatcher) ?? "config:missing";
|
|
94
|
-
const patchTargetSignature = getPatchTargetSignature(twPatcher);
|
|
95
|
-
return `${configSignature}|patch:${patchTargetSignature}`;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
36
|
// src/tailwindcss/runtime.ts
|
|
99
37
|
var debug = createDebug("[tailwindcss:runtime] ");
|
|
100
38
|
var refreshTailwindcssPatcherSymbol = /* @__PURE__ */ Symbol.for("weapp-tailwindcss.refreshTailwindcssPatcher");
|
|
@@ -126,6 +64,7 @@ async function refreshTailwindRuntimeState(state, forceOrOptions) {
|
|
|
126
64
|
if (!force) {
|
|
127
65
|
return false;
|
|
128
66
|
}
|
|
67
|
+
debug("refresh runtime state start, clearCache=%s major=%s", clearCache, state.twPatcher.majorVersion ?? "unknown");
|
|
129
68
|
await state.patchPromise;
|
|
130
69
|
let refreshed = false;
|
|
131
70
|
if (typeof state.refreshTailwindcssPatcher === "function") {
|
|
@@ -138,6 +77,7 @@ async function refreshTailwindRuntimeState(state, forceOrOptions) {
|
|
|
138
77
|
if (refreshed) {
|
|
139
78
|
state.patchPromise = createTailwindPatchPromise(state.twPatcher, state.onPatchCompleted);
|
|
140
79
|
}
|
|
80
|
+
debug("refresh runtime state end, refreshed=%s major=%s", refreshed, state.twPatcher.majorVersion ?? "unknown");
|
|
141
81
|
return refreshed;
|
|
142
82
|
}
|
|
143
83
|
async function ensureRuntimeClassSet(state, options = {}) {
|
|
@@ -313,10 +253,176 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
|
|
|
313
253
|
}
|
|
314
254
|
}
|
|
315
255
|
|
|
256
|
+
// src/context/index.ts
|
|
257
|
+
import { rm } from "fs/promises";
|
|
258
|
+
import { logger as logger6, pc } from "@weapp-tailwindcss/logger";
|
|
259
|
+
|
|
260
|
+
// src/cache/index.ts
|
|
261
|
+
import { LRUCache } from "lru-cache";
|
|
262
|
+
|
|
263
|
+
// src/cache/md5.ts
|
|
264
|
+
import { md5 } from "@weapp-tailwindcss/shared/node";
|
|
265
|
+
|
|
266
|
+
// src/cache/index.ts
|
|
267
|
+
function isProcessResult(value) {
|
|
268
|
+
return typeof value === "object" && value !== null && "result" in value;
|
|
269
|
+
}
|
|
270
|
+
function createCache(options) {
|
|
271
|
+
const disabled = options === false;
|
|
272
|
+
const hashMap = /* @__PURE__ */ new Map();
|
|
273
|
+
const instance = new LRUCache({
|
|
274
|
+
// 可能会添加和删除一些页面和组件, 先设定 1024 吧
|
|
275
|
+
max: 1024,
|
|
276
|
+
ttl: 0,
|
|
277
|
+
ttlAutopurge: false
|
|
278
|
+
});
|
|
279
|
+
const cache = {
|
|
280
|
+
hashMap,
|
|
281
|
+
instance,
|
|
282
|
+
hasHashKey(key) {
|
|
283
|
+
return hashMap.has(key);
|
|
284
|
+
},
|
|
285
|
+
getHashValue(key) {
|
|
286
|
+
return hashMap.get(key);
|
|
287
|
+
},
|
|
288
|
+
setHashValue(key, value) {
|
|
289
|
+
return hashMap.set(key, value);
|
|
290
|
+
},
|
|
291
|
+
get(key) {
|
|
292
|
+
return instance.get(key);
|
|
293
|
+
},
|
|
294
|
+
set(key, value) {
|
|
295
|
+
return instance.set(key, value);
|
|
296
|
+
},
|
|
297
|
+
computeHash(message) {
|
|
298
|
+
return md5(message);
|
|
299
|
+
},
|
|
300
|
+
calcHashValueChanged(key, hash) {
|
|
301
|
+
const hit = hashMap.get(key);
|
|
302
|
+
if (hit) {
|
|
303
|
+
hashMap.set(key, {
|
|
304
|
+
changed: hash !== hit.hash,
|
|
305
|
+
hash
|
|
306
|
+
});
|
|
307
|
+
} else {
|
|
308
|
+
hashMap.set(key, {
|
|
309
|
+
changed: true,
|
|
310
|
+
hash
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
return cache;
|
|
314
|
+
},
|
|
315
|
+
has(key) {
|
|
316
|
+
return instance.has(key);
|
|
317
|
+
},
|
|
318
|
+
async process({
|
|
319
|
+
key,
|
|
320
|
+
hashKey,
|
|
321
|
+
rawSource,
|
|
322
|
+
hash,
|
|
323
|
+
resolveCache,
|
|
324
|
+
transform,
|
|
325
|
+
onCacheHit
|
|
326
|
+
}) {
|
|
327
|
+
if (disabled) {
|
|
328
|
+
const value2 = await transform();
|
|
329
|
+
return isProcessResult(value2) ? value2.result : value2;
|
|
330
|
+
}
|
|
331
|
+
const cacheHashKey = hashKey ?? key;
|
|
332
|
+
let hasChanged = true;
|
|
333
|
+
if (hash != null || rawSource != null) {
|
|
334
|
+
const nextHash = hash ?? cache.computeHash(rawSource);
|
|
335
|
+
cache.calcHashValueChanged(cacheHashKey, nextHash);
|
|
336
|
+
const entry = cache.getHashValue(cacheHashKey);
|
|
337
|
+
hasChanged = entry?.changed ?? true;
|
|
338
|
+
}
|
|
339
|
+
const readCache = resolveCache ?? (() => cache.get(key));
|
|
340
|
+
if (!hasChanged) {
|
|
341
|
+
const cached = readCache();
|
|
342
|
+
if (cached !== void 0) {
|
|
343
|
+
await onCacheHit?.(cached);
|
|
344
|
+
return cached;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const value = await transform();
|
|
348
|
+
const normalized = isProcessResult(value) ? value : { result: value };
|
|
349
|
+
const stored = normalized.cacheValue ?? normalized.result;
|
|
350
|
+
cache.set(key, stored);
|
|
351
|
+
return normalized.result;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
return cache;
|
|
355
|
+
}
|
|
356
|
+
function initializeCache(cacheConfig) {
|
|
357
|
+
if (typeof cacheConfig === "boolean" || cacheConfig === void 0) {
|
|
358
|
+
return createCache(cacheConfig);
|
|
359
|
+
}
|
|
360
|
+
return cacheConfig;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/tailwindcss/targets.ts
|
|
364
|
+
import process3 from "process";
|
|
365
|
+
import { logger as logger3 } from "@weapp-tailwindcss/logger";
|
|
366
|
+
|
|
367
|
+
// src/tailwindcss/targets/paths.ts
|
|
368
|
+
import { existsSync } from "fs";
|
|
369
|
+
import path from "path";
|
|
370
|
+
var PATCH_INFO_FILENAME = "tailwindcss-target.json";
|
|
371
|
+
var PATCH_INFO_CACHE_RELATIVE_PATH = path.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
|
|
372
|
+
var PATCH_INFO_LEGACY_RELATIVE_PATH = path.join(".tw-patch", PATCH_INFO_FILENAME);
|
|
373
|
+
function formatRelativeToBase(targetPath, baseDir) {
|
|
374
|
+
if (!baseDir) {
|
|
375
|
+
return path.normalize(targetPath);
|
|
376
|
+
}
|
|
377
|
+
const relative = path.relative(baseDir, targetPath);
|
|
378
|
+
if (!relative || relative === ".") {
|
|
379
|
+
return ".";
|
|
380
|
+
}
|
|
381
|
+
if (relative.startsWith("..")) {
|
|
382
|
+
return path.normalize(targetPath);
|
|
383
|
+
}
|
|
384
|
+
return path.join(".", relative);
|
|
385
|
+
}
|
|
386
|
+
function resolveRecordLocation(baseDir) {
|
|
387
|
+
const normalizedBase = path.normalize(baseDir);
|
|
388
|
+
const packageRoot = findNearestPackageRoot(normalizedBase) ?? normalizedBase;
|
|
389
|
+
const packageJsonPath = path.join(packageRoot, "package.json");
|
|
390
|
+
const hasPackageJson = existsSync(packageJsonPath);
|
|
391
|
+
const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
|
|
392
|
+
const recordKey = md5(path.normalize(recordKeySource));
|
|
393
|
+
const recordDir = path.join(packageRoot, "node_modules", ".cache", "weapp-tailwindcss", recordKey);
|
|
394
|
+
const recordPath = path.join(recordDir, PATCH_INFO_FILENAME);
|
|
395
|
+
return {
|
|
396
|
+
normalizedBase,
|
|
397
|
+
packageRoot,
|
|
398
|
+
recordDir,
|
|
399
|
+
recordKey,
|
|
400
|
+
recordPath,
|
|
401
|
+
packageJsonPath: hasPackageJson ? packageJsonPath : void 0
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function getRecordFileCandidates(baseDir) {
|
|
405
|
+
const { normalizedBase, packageRoot, recordPath } = resolveRecordLocation(baseDir);
|
|
406
|
+
const candidates = /* @__PURE__ */ new Set([
|
|
407
|
+
recordPath,
|
|
408
|
+
path.join(packageRoot, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
409
|
+
path.join(normalizedBase, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
410
|
+
path.join(normalizedBase, PATCH_INFO_LEGACY_RELATIVE_PATH)
|
|
411
|
+
]);
|
|
412
|
+
return [...candidates];
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// src/tailwindcss/targets/record-io.ts
|
|
416
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
417
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
418
|
+
import path2 from "path";
|
|
419
|
+
import process from "process";
|
|
420
|
+
import { logger as logger2 } from "@weapp-tailwindcss/logger";
|
|
421
|
+
|
|
316
422
|
// package.json
|
|
317
423
|
var package_default = {
|
|
318
424
|
name: "weapp-tailwindcss",
|
|
319
|
-
version: "4.11.0-alpha.
|
|
425
|
+
version: "4.11.0-alpha.2",
|
|
320
426
|
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!",
|
|
321
427
|
author: "ice breaker <1324318532@qq.com>",
|
|
322
428
|
license: "MIT",
|
|
@@ -472,7 +578,7 @@ var package_default = {
|
|
|
472
578
|
"with-layer.css"
|
|
473
579
|
],
|
|
474
580
|
engines: {
|
|
475
|
-
node: "^
|
|
581
|
+
node: "^18.17.0 || >=20.5.0"
|
|
476
582
|
},
|
|
477
583
|
scripts: {
|
|
478
584
|
dev: "tsup --watch --sourcemap",
|
|
@@ -508,7 +614,7 @@ var package_default = {
|
|
|
508
614
|
},
|
|
509
615
|
dependencies: {
|
|
510
616
|
"@ast-core/escape": "~1.0.1",
|
|
511
|
-
"@babel/parser": "~7.29.
|
|
617
|
+
"@babel/parser": "~7.29.2",
|
|
512
618
|
"@babel/traverse": "~7.29.0",
|
|
513
619
|
"@babel/types": "~7.29.0",
|
|
514
620
|
"@tailwindcss-mangle/config": "^6.1.3",
|
|
@@ -519,7 +625,7 @@ var package_default = {
|
|
|
519
625
|
"@weapp-tailwindcss/logger": "workspace:*",
|
|
520
626
|
"@weapp-tailwindcss/postcss": "workspace:*",
|
|
521
627
|
"@weapp-tailwindcss/shared": "workspace:*",
|
|
522
|
-
cac: "
|
|
628
|
+
cac: "6.7.14",
|
|
523
629
|
debug: "~4.4.3",
|
|
524
630
|
"fast-glob": "^3.3.3",
|
|
525
631
|
htmlparser2: "10.1.0",
|
|
@@ -530,14 +636,13 @@ var package_default = {
|
|
|
530
636
|
semver: "~7.7.4",
|
|
531
637
|
"tailwindcss-patch": "catalog:tailwindcssPatch",
|
|
532
638
|
"webpack-sources": "3.3.4",
|
|
533
|
-
yaml: "^2.8.
|
|
639
|
+
yaml: "^2.8.3"
|
|
534
640
|
}
|
|
535
641
|
};
|
|
536
642
|
|
|
537
643
|
// src/constants.ts
|
|
538
644
|
var pluginName = "weapp-tailwindcss-webpack-plugin";
|
|
539
645
|
var vitePluginName = "weapp-tailwindcss:adaptor";
|
|
540
|
-
var WEAPP_TW_REQUIRED_NODE_VERSION = "18.17.0";
|
|
541
646
|
var WEAPP_TW_VERSION = package_default.version;
|
|
542
647
|
var DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
|
|
543
648
|
"tailwind-merge": "@weapp-tailwindcss/merge",
|
|
@@ -545,171 +650,7 @@ var DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
|
|
|
545
650
|
"tailwind-variants": "@weapp-tailwindcss/variants"
|
|
546
651
|
};
|
|
547
652
|
|
|
548
|
-
// src/context/index.ts
|
|
549
|
-
import { rm } from "fs/promises";
|
|
550
|
-
import { logger as logger5, pc } from "@weapp-tailwindcss/logger";
|
|
551
|
-
|
|
552
|
-
// src/cache/index.ts
|
|
553
|
-
import { LRUCache } from "lru-cache";
|
|
554
|
-
|
|
555
|
-
// src/cache/md5.ts
|
|
556
|
-
import { md5 } from "@weapp-tailwindcss/shared/node";
|
|
557
|
-
|
|
558
|
-
// src/cache/index.ts
|
|
559
|
-
function isProcessResult(value) {
|
|
560
|
-
return typeof value === "object" && value !== null && "result" in value;
|
|
561
|
-
}
|
|
562
|
-
function createCache(options) {
|
|
563
|
-
const disabled = options === false;
|
|
564
|
-
const hashMap = /* @__PURE__ */ new Map();
|
|
565
|
-
const instance = new LRUCache({
|
|
566
|
-
// 可能会添加和删除一些页面和组件, 先设定 1024 吧
|
|
567
|
-
max: 1024,
|
|
568
|
-
ttl: 0,
|
|
569
|
-
ttlAutopurge: false
|
|
570
|
-
});
|
|
571
|
-
const cache = {
|
|
572
|
-
hashMap,
|
|
573
|
-
instance,
|
|
574
|
-
hasHashKey(key) {
|
|
575
|
-
return hashMap.has(key);
|
|
576
|
-
},
|
|
577
|
-
getHashValue(key) {
|
|
578
|
-
return hashMap.get(key);
|
|
579
|
-
},
|
|
580
|
-
setHashValue(key, value) {
|
|
581
|
-
return hashMap.set(key, value);
|
|
582
|
-
},
|
|
583
|
-
get(key) {
|
|
584
|
-
return instance.get(key);
|
|
585
|
-
},
|
|
586
|
-
set(key, value) {
|
|
587
|
-
return instance.set(key, value);
|
|
588
|
-
},
|
|
589
|
-
computeHash(message) {
|
|
590
|
-
return md5(message);
|
|
591
|
-
},
|
|
592
|
-
calcHashValueChanged(key, hash) {
|
|
593
|
-
const hit = hashMap.get(key);
|
|
594
|
-
if (hit) {
|
|
595
|
-
hashMap.set(key, {
|
|
596
|
-
changed: hash !== hit.hash,
|
|
597
|
-
hash
|
|
598
|
-
});
|
|
599
|
-
} else {
|
|
600
|
-
hashMap.set(key, {
|
|
601
|
-
changed: true,
|
|
602
|
-
hash
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
return cache;
|
|
606
|
-
},
|
|
607
|
-
has(key) {
|
|
608
|
-
return instance.has(key);
|
|
609
|
-
},
|
|
610
|
-
async process({
|
|
611
|
-
key,
|
|
612
|
-
hashKey,
|
|
613
|
-
rawSource,
|
|
614
|
-
hash,
|
|
615
|
-
resolveCache,
|
|
616
|
-
transform,
|
|
617
|
-
onCacheHit
|
|
618
|
-
}) {
|
|
619
|
-
if (disabled) {
|
|
620
|
-
const value2 = await transform();
|
|
621
|
-
return isProcessResult(value2) ? value2.result : value2;
|
|
622
|
-
}
|
|
623
|
-
const cacheHashKey = hashKey ?? key;
|
|
624
|
-
let hasChanged = true;
|
|
625
|
-
if (hash != null || rawSource != null) {
|
|
626
|
-
const nextHash = hash ?? cache.computeHash(rawSource);
|
|
627
|
-
cache.calcHashValueChanged(cacheHashKey, nextHash);
|
|
628
|
-
const entry = cache.getHashValue(cacheHashKey);
|
|
629
|
-
hasChanged = entry?.changed ?? true;
|
|
630
|
-
}
|
|
631
|
-
const readCache = resolveCache ?? (() => cache.get(key));
|
|
632
|
-
if (!hasChanged) {
|
|
633
|
-
const cached = readCache();
|
|
634
|
-
if (cached !== void 0) {
|
|
635
|
-
await onCacheHit?.(cached);
|
|
636
|
-
return cached;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
const value = await transform();
|
|
640
|
-
const normalized = isProcessResult(value) ? value : { result: value };
|
|
641
|
-
const stored = normalized.cacheValue ?? normalized.result;
|
|
642
|
-
cache.set(key, stored);
|
|
643
|
-
return normalized.result;
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
return cache;
|
|
647
|
-
}
|
|
648
|
-
function initializeCache(cacheConfig) {
|
|
649
|
-
if (typeof cacheConfig === "boolean" || cacheConfig === void 0) {
|
|
650
|
-
return createCache(cacheConfig);
|
|
651
|
-
}
|
|
652
|
-
return cacheConfig;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
// src/tailwindcss/targets.ts
|
|
656
|
-
import process3 from "process";
|
|
657
|
-
import { logger as logger2 } from "@weapp-tailwindcss/logger";
|
|
658
|
-
|
|
659
|
-
// src/tailwindcss/targets/paths.ts
|
|
660
|
-
import { existsSync } from "fs";
|
|
661
|
-
import path from "path";
|
|
662
|
-
var PATCH_INFO_FILENAME = "tailwindcss-target.json";
|
|
663
|
-
var PATCH_INFO_CACHE_RELATIVE_PATH = path.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
|
|
664
|
-
var PATCH_INFO_LEGACY_RELATIVE_PATH = path.join(".tw-patch", PATCH_INFO_FILENAME);
|
|
665
|
-
function formatRelativeToBase(targetPath, baseDir) {
|
|
666
|
-
if (!baseDir) {
|
|
667
|
-
return path.normalize(targetPath);
|
|
668
|
-
}
|
|
669
|
-
const relative = path.relative(baseDir, targetPath);
|
|
670
|
-
if (!relative || relative === ".") {
|
|
671
|
-
return ".";
|
|
672
|
-
}
|
|
673
|
-
if (relative.startsWith("..")) {
|
|
674
|
-
return path.normalize(targetPath);
|
|
675
|
-
}
|
|
676
|
-
return path.join(".", relative);
|
|
677
|
-
}
|
|
678
|
-
function resolveRecordLocation(baseDir) {
|
|
679
|
-
const normalizedBase = path.normalize(baseDir);
|
|
680
|
-
const packageRoot = findNearestPackageRoot(normalizedBase) ?? normalizedBase;
|
|
681
|
-
const packageJsonPath = path.join(packageRoot, "package.json");
|
|
682
|
-
const hasPackageJson = existsSync(packageJsonPath);
|
|
683
|
-
const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
|
|
684
|
-
const recordKey = md5(path.normalize(recordKeySource));
|
|
685
|
-
const recordDir = path.join(packageRoot, "node_modules", ".cache", "weapp-tailwindcss", recordKey);
|
|
686
|
-
const recordPath = path.join(recordDir, PATCH_INFO_FILENAME);
|
|
687
|
-
return {
|
|
688
|
-
normalizedBase,
|
|
689
|
-
packageRoot,
|
|
690
|
-
recordDir,
|
|
691
|
-
recordKey,
|
|
692
|
-
recordPath,
|
|
693
|
-
packageJsonPath: hasPackageJson ? packageJsonPath : void 0
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
function getRecordFileCandidates(baseDir) {
|
|
697
|
-
const { normalizedBase, packageRoot, recordPath } = resolveRecordLocation(baseDir);
|
|
698
|
-
const candidates = /* @__PURE__ */ new Set([
|
|
699
|
-
recordPath,
|
|
700
|
-
path.join(packageRoot, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
701
|
-
path.join(normalizedBase, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
702
|
-
path.join(normalizedBase, PATCH_INFO_LEGACY_RELATIVE_PATH)
|
|
703
|
-
]);
|
|
704
|
-
return [...candidates];
|
|
705
|
-
}
|
|
706
|
-
|
|
707
653
|
// src/tailwindcss/targets/record-io.ts
|
|
708
|
-
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
709
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
710
|
-
import path2 from "path";
|
|
711
|
-
import process from "process";
|
|
712
|
-
import { logger } from "@weapp-tailwindcss/logger";
|
|
713
654
|
var loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
|
|
714
655
|
function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
|
|
715
656
|
const normalizedPath = path2.normalize(recordPath);
|
|
@@ -720,7 +661,7 @@ function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
|
|
|
720
661
|
const fileDisplay = formatRelativeToBase(normalizedPath, baseDir);
|
|
721
662
|
const baseDisplay = formatRelativeToBase(path2.normalize(baseDir), process.cwd());
|
|
722
663
|
const reasonMessage = reason ? `\uFF1A${reason}` : "";
|
|
723
|
-
|
|
664
|
+
logger2.warn(
|
|
724
665
|
`\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`
|
|
725
666
|
);
|
|
726
667
|
}
|
|
@@ -778,12 +719,12 @@ async function saveCliPatchTargetRecord(baseDir, patcher, options) {
|
|
|
778
719
|
return recordPath;
|
|
779
720
|
} catch (error) {
|
|
780
721
|
const baseDisplay = formatRelativeToBase(normalizedBase, process.cwd());
|
|
781
|
-
|
|
722
|
+
logger2.warn(
|
|
782
723
|
'\u81EA\u52A8\u66F4\u65B0 Tailwind CSS \u8865\u4E01\u8BB0\u5F55\u5931\u8D25\uFF0C\u8BF7\u5728 %s \u8FD0\u884C "weapp-tw patch --cwd %s"\u3002',
|
|
783
724
|
baseDisplay,
|
|
784
725
|
normalizedBase
|
|
785
726
|
);
|
|
786
|
-
|
|
727
|
+
logger2.debug("failed to persist patch target record %s: %O", recordPath, error);
|
|
787
728
|
return void 0;
|
|
788
729
|
}
|
|
789
730
|
}
|
|
@@ -873,7 +814,7 @@ function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
|
873
814
|
const packageInfo = patcher?.packageInfo;
|
|
874
815
|
const label = kind === "cli" ? "weapp-tw patch" : "tailwindcss-patcher";
|
|
875
816
|
if (!packageInfo?.rootPath) {
|
|
876
|
-
|
|
817
|
+
logger3.warn(
|
|
877
818
|
"%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
|
|
878
819
|
label,
|
|
879
820
|
baseDir ?? process3.cwd()
|
|
@@ -882,14 +823,14 @@ function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
|
882
823
|
}
|
|
883
824
|
const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
|
|
884
825
|
const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
|
|
885
|
-
|
|
826
|
+
logger3.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
|
|
886
827
|
}
|
|
887
828
|
|
|
888
829
|
// src/context/compiler-context-cache.ts
|
|
889
830
|
import { Buffer } from "buffer";
|
|
890
831
|
import path4 from "path";
|
|
891
832
|
import process4 from "process";
|
|
892
|
-
import { logger as
|
|
833
|
+
import { logger as logger4 } from "@weapp-tailwindcss/logger";
|
|
893
834
|
var PAREN_CONTENT_RE = /\(([^)]+)\)/u;
|
|
894
835
|
var AT_LOCATION_RE = /at\s+(\S.*)$/u;
|
|
895
836
|
var TRAILING_LINE_COL_RE = /:\d+(?::\d+)?$/u;
|
|
@@ -1140,7 +1081,7 @@ function createCompilerContextCacheKey(opts) {
|
|
|
1140
1081
|
keyStore.set(runtimeCacheScopeKey, cacheKey);
|
|
1141
1082
|
return cacheKey;
|
|
1142
1083
|
} catch (error) {
|
|
1143
|
-
|
|
1084
|
+
logger4.debug("skip compiler context cache: %O", error);
|
|
1144
1085
|
return void 0;
|
|
1145
1086
|
}
|
|
1146
1087
|
}
|
|
@@ -3709,7 +3650,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
3709
3650
|
}
|
|
3710
3651
|
|
|
3711
3652
|
// src/context/logger.ts
|
|
3712
|
-
import { logger as
|
|
3653
|
+
import { logger as logger5 } from "@weapp-tailwindcss/logger";
|
|
3713
3654
|
var loggerLevelMap = {
|
|
3714
3655
|
error: 0,
|
|
3715
3656
|
warn: 1,
|
|
@@ -3717,7 +3658,7 @@ var loggerLevelMap = {
|
|
|
3717
3658
|
silent: -999
|
|
3718
3659
|
};
|
|
3719
3660
|
function applyLoggerLevel(logLevel) {
|
|
3720
|
-
|
|
3661
|
+
logger5.level = loggerLevelMap[logLevel ?? "info"] ?? loggerLevelMap.info;
|
|
3721
3662
|
}
|
|
3722
3663
|
|
|
3723
3664
|
// src/context/index.ts
|
|
@@ -3733,7 +3674,7 @@ async function clearTailwindcssPatcherCache(patcher, options) {
|
|
|
3733
3674
|
try {
|
|
3734
3675
|
await patcher.clearCache({ scope: "all" });
|
|
3735
3676
|
} catch (error) {
|
|
3736
|
-
|
|
3677
|
+
logger6.debug("failed to clear tailwindcss patcher cache via clearCache(): %O", error);
|
|
3737
3678
|
}
|
|
3738
3679
|
}
|
|
3739
3680
|
if (!options?.removeDirectory) {
|
|
@@ -3762,7 +3703,7 @@ async function clearTailwindcssPatcherCache(patcher, options) {
|
|
|
3762
3703
|
if (err?.code === "ENOENT") {
|
|
3763
3704
|
continue;
|
|
3764
3705
|
}
|
|
3765
|
-
|
|
3706
|
+
logger6.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
|
|
3766
3707
|
}
|
|
3767
3708
|
}
|
|
3768
3709
|
}
|
|
@@ -3777,9 +3718,9 @@ function createInternalCompilerContext(opts) {
|
|
|
3777
3718
|
const twPatcher = createTailwindcssPatcherFromContext(ctx);
|
|
3778
3719
|
logTailwindcssTarget("runtime", twPatcher, ctx.tailwindcssBasedir);
|
|
3779
3720
|
if (twPatcher.packageInfo?.version) {
|
|
3780
|
-
|
|
3721
|
+
logger6.success(`\u5F53\u524D\u4F7F\u7528 ${pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${pc.underline(pc.bold(pc.green(twPatcher.packageInfo.version)))}`);
|
|
3781
3722
|
} else {
|
|
3782
|
-
|
|
3723
|
+
logger6.warn(`${pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
|
|
3783
3724
|
}
|
|
3784
3725
|
warnMissingCssEntries(ctx, twPatcher);
|
|
3785
3726
|
const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc, twPatcher);
|
|
@@ -3818,24 +3759,37 @@ function getCompilerContext(opts) {
|
|
|
3818
3759
|
return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
|
|
3819
3760
|
}
|
|
3820
3761
|
|
|
3762
|
+
// src/tailwindcss/recorder.ts
|
|
3763
|
+
function setupPatchRecorder(patcher, baseDir, options) {
|
|
3764
|
+
const recorder = createPatchTargetRecorder(baseDir, patcher, options);
|
|
3765
|
+
if (recorder?.message && options?.logMessage !== false) {
|
|
3766
|
+
const prefix = options?.messagePrefix ? `${options.messagePrefix} ` : "";
|
|
3767
|
+
logger.info("%s%s", prefix, recorder.message);
|
|
3768
|
+
}
|
|
3769
|
+
const onPatchCompleted = recorder?.onPatched ? async () => {
|
|
3770
|
+
await recorder.onPatched();
|
|
3771
|
+
} : void 0;
|
|
3772
|
+
const patchPromise = patcher ? createTailwindPatchPromise(patcher, onPatchCompleted) : Promise.resolve();
|
|
3773
|
+
return {
|
|
3774
|
+
recorder,
|
|
3775
|
+
patchPromise,
|
|
3776
|
+
onPatchCompleted
|
|
3777
|
+
};
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3821
3780
|
export {
|
|
3822
3781
|
createDebug,
|
|
3823
|
-
getRuntimeClassSetSignature,
|
|
3824
|
-
createTailwindPatchPromise,
|
|
3825
3782
|
refreshTailwindRuntimeState,
|
|
3826
3783
|
ensureRuntimeClassSet,
|
|
3827
3784
|
collectRuntimeClassSet,
|
|
3828
3785
|
pluginName,
|
|
3829
3786
|
vitePluginName,
|
|
3830
|
-
WEAPP_TW_REQUIRED_NODE_VERSION,
|
|
3831
|
-
createPatchTargetRecorder,
|
|
3832
|
-
logTailwindcssTarget,
|
|
3833
3787
|
toCustomAttributesEntities,
|
|
3834
3788
|
traverse,
|
|
3835
3789
|
babelParse,
|
|
3836
3790
|
replaceWxml,
|
|
3837
3791
|
createAttributeMatcher,
|
|
3838
3792
|
generateCode,
|
|
3839
|
-
|
|
3840
|
-
|
|
3793
|
+
getCompilerContext,
|
|
3794
|
+
setupPatchRecorder
|
|
3841
3795
|
};
|