weapp-tailwindcss 4.7.6 → 4.7.7
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-36GNZBVS.js → chunk-2WZP7EXP.js} +269 -130
- package/dist/{chunk-G4SYITSG.mjs → chunk-APVOYXRF.mjs} +2 -4
- package/dist/{chunk-MEX4EXZX.mjs → chunk-FZNEB7RC.mjs} +2 -2
- package/dist/{chunk-VL24RIGE.mjs → chunk-KGKHHXRC.mjs} +243 -104
- package/dist/{chunk-SXYSWJRO.js → chunk-MGHX7SCL.js} +11 -13
- package/dist/{chunk-3AAVIURI.js → chunk-MMBZHHNL.js} +1 -1
- package/dist/{chunk-EGX7MMTE.mjs → chunk-MNKR7BNZ.mjs} +1 -1
- package/dist/{chunk-6WB6H5P4.js → chunk-PP6KHC2I.js} +6 -6
- package/dist/{chunk-RTOKUKLA.js → chunk-VLM4KUZA.js} +4 -4
- package/dist/{chunk-UB5UEGVL.mjs → chunk-VPQLMV42.mjs} +1 -1
- package/dist/{chunk-JISOHATJ.js → chunk-X5SXNF7I.js} +10 -10
- package/dist/cli.js +23 -12
- package/dist/cli.mjs +17 -6
- package/dist/core.js +9 -10
- package/dist/core.mjs +2 -3
- 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 +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/escape.d.mts +4 -16
- package/dist/escape.d.ts +4 -16
- package/dist/escape.js +53 -9
- package/dist/escape.mjs +19 -5
- package/dist/gulp.js +5 -6
- package/dist/gulp.mjs +3 -4
- package/dist/index.js +7 -8
- package/dist/index.mjs +5 -6
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.js +3 -3
- package/dist/presets.mjs +1 -1
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.js +5 -6
- package/dist/vite.mjs +3 -4
- package/dist/webpack.js +5 -6
- package/dist/webpack.mjs +3 -4
- package/dist/webpack4.js +12 -13
- package/dist/webpack4.mjs +2 -3
- package/package.json +5 -5
- package/dist/chunk-DWAEHRHN.js +0 -21
- package/dist/chunk-VSRDBMDB.mjs +0 -21
|
@@ -14,12 +14,10 @@ import {
|
|
|
14
14
|
generateCode,
|
|
15
15
|
getCompilerContext,
|
|
16
16
|
refreshTailwindRuntimeState,
|
|
17
|
+
replaceWxml,
|
|
17
18
|
toCustomAttributesEntities,
|
|
18
19
|
vitePluginName
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import {
|
|
21
|
-
replaceWxml
|
|
22
|
-
} from "./chunk-VSRDBMDB.mjs";
|
|
20
|
+
} from "./chunk-KGKHHXRC.mjs";
|
|
23
21
|
import {
|
|
24
22
|
getGroupedEntries
|
|
25
23
|
} from "./chunk-ZNKIYZRQ.mjs";
|
|
@@ -16,13 +16,13 @@ import {
|
|
|
16
16
|
getCompilerContext,
|
|
17
17
|
pluginName,
|
|
18
18
|
refreshTailwindRuntimeState
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-KGKHHXRC.mjs";
|
|
20
20
|
import {
|
|
21
21
|
getGroupedEntries
|
|
22
22
|
} from "./chunk-ZNKIYZRQ.mjs";
|
|
23
23
|
import {
|
|
24
24
|
__dirname
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-MNKR7BNZ.mjs";
|
|
26
26
|
|
|
27
27
|
// src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
|
|
28
28
|
import fs from "fs";
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
replaceWxml
|
|
3
|
-
} from "./chunk-VSRDBMDB.mjs";
|
|
4
1
|
import {
|
|
5
2
|
createTailwindcssPatcherFromContext
|
|
6
3
|
} from "./chunk-SHMBWMDV.mjs";
|
|
@@ -173,6 +170,112 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
|
|
|
173
170
|
}
|
|
174
171
|
}
|
|
175
172
|
|
|
173
|
+
// src/tailwindcss/targets.ts
|
|
174
|
+
import { existsSync, readFileSync } from "fs";
|
|
175
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
176
|
+
import path from "path";
|
|
177
|
+
import process from "process";
|
|
178
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
179
|
+
var PATCH_INFO_DIRNAME = ".tw-patch";
|
|
180
|
+
var PATCH_INFO_FILENAME = "tailwindcss-target.json";
|
|
181
|
+
function formatRelativeToBase(targetPath, baseDir) {
|
|
182
|
+
if (!baseDir) {
|
|
183
|
+
return path.normalize(targetPath);
|
|
184
|
+
}
|
|
185
|
+
const relative = path.relative(baseDir, targetPath);
|
|
186
|
+
if (!relative || relative === ".") {
|
|
187
|
+
return ".";
|
|
188
|
+
}
|
|
189
|
+
if (relative.startsWith("..")) {
|
|
190
|
+
return path.normalize(targetPath);
|
|
191
|
+
}
|
|
192
|
+
return path.join(".", relative);
|
|
193
|
+
}
|
|
194
|
+
function getRecordFilePath(baseDir) {
|
|
195
|
+
return path.join(baseDir, PATCH_INFO_DIRNAME, PATCH_INFO_FILENAME);
|
|
196
|
+
}
|
|
197
|
+
function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
198
|
+
const packageInfo = patcher?.packageInfo;
|
|
199
|
+
const label = kind === "cli" ? "weapp-tw patch" : "tailwindcss-patcher";
|
|
200
|
+
if (!packageInfo?.rootPath) {
|
|
201
|
+
logger.warn(
|
|
202
|
+
"%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
|
|
203
|
+
label,
|
|
204
|
+
baseDir ?? process.cwd()
|
|
205
|
+
);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
|
|
209
|
+
const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
|
|
210
|
+
logger.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
|
|
211
|
+
}
|
|
212
|
+
function readPatchTargetRecord(baseDir) {
|
|
213
|
+
if (!baseDir) {
|
|
214
|
+
return void 0;
|
|
215
|
+
}
|
|
216
|
+
const recordPath = getRecordFilePath(baseDir);
|
|
217
|
+
if (!existsSync(recordPath)) {
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
const content = readFileSync(recordPath, "utf8");
|
|
222
|
+
const parsed = JSON.parse(content);
|
|
223
|
+
if (!parsed || typeof parsed.tailwindPackagePath !== "string") {
|
|
224
|
+
return void 0;
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
path: recordPath,
|
|
228
|
+
record: parsed
|
|
229
|
+
};
|
|
230
|
+
} catch (error) {
|
|
231
|
+
logger.debug("failed to read patch target record from %s: %O", recordPath, error);
|
|
232
|
+
return void 0;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function saveCliPatchTargetRecord(baseDir, patcher) {
|
|
236
|
+
if (!baseDir || !patcher?.packageInfo?.rootPath) {
|
|
237
|
+
return void 0;
|
|
238
|
+
}
|
|
239
|
+
const record = {
|
|
240
|
+
tailwindPackagePath: path.normalize(patcher.packageInfo.rootPath),
|
|
241
|
+
packageVersion: patcher.packageInfo.version,
|
|
242
|
+
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
243
|
+
source: "cli",
|
|
244
|
+
tailwindcssBasedir: path.normalize(baseDir)
|
|
245
|
+
};
|
|
246
|
+
const recordPath = getRecordFilePath(baseDir);
|
|
247
|
+
try {
|
|
248
|
+
await mkdir(path.dirname(recordPath), { recursive: true });
|
|
249
|
+
await writeFile(recordPath, `${JSON.stringify(record, null, 2)}
|
|
250
|
+
`, "utf8");
|
|
251
|
+
return recordPath;
|
|
252
|
+
} catch (error) {
|
|
253
|
+
logger.debug("failed to persist patch target record %s: %O", recordPath, error);
|
|
254
|
+
return void 0;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function warnIfCliPatchTargetMismatch(baseDir, patcher) {
|
|
258
|
+
if (!baseDir || !patcher?.packageInfo?.rootPath) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const recorded = readPatchTargetRecord(baseDir);
|
|
262
|
+
if (!recorded) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const normalizedRecorded = path.normalize(recorded.record.tailwindPackagePath);
|
|
266
|
+
const normalizedRuntime = path.normalize(patcher.packageInfo.rootPath);
|
|
267
|
+
if (normalizedRecorded === normalizedRuntime) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const recordedDisplay = formatRelativeToBase(normalizedRecorded, baseDir);
|
|
271
|
+
const runtimeDisplay = formatRelativeToBase(normalizedRuntime, baseDir);
|
|
272
|
+
const baseDisplay = formatRelativeToBase(path.normalize(baseDir), process.cwd());
|
|
273
|
+
const recordFileDisplay = formatRelativeToBase(recorded.path, baseDir);
|
|
274
|
+
logger.warn(
|
|
275
|
+
`\u68C0\u6D4B\u5230 ${baseDisplay} \u7684 Tailwind CSS \u76EE\u6807\u4E0D\u4E00\u81F4\uFF1ACLI \u6253\u8865\u4E01\u7684\u662F ${recordedDisplay}\uFF0C\u8FD0\u884C\u65F6\u8BFB\u53D6\u7684\u662F ${runtimeDisplay}\u3002\u8BF7\u5728\u5BF9\u5E94\u5B50\u5305\u6267\u884C "weapp-tw patch --cwd ${baseDir}"\uFF08\u8BB0\u5F55\u6587\u4EF6\uFF1A${recordFileDisplay}\uFF09\u3002`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
176
279
|
// src/constants.ts
|
|
177
280
|
var pluginName = "weapp-tailwindcss-webpack-plugin";
|
|
178
281
|
var vitePluginName = "weapp-tailwindcss:adaptor";
|
|
@@ -185,7 +288,7 @@ var DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
|
|
|
185
288
|
|
|
186
289
|
// src/context/index.ts
|
|
187
290
|
import { rm } from "fs/promises";
|
|
188
|
-
import { logger as
|
|
291
|
+
import { logger as logger3, pc } from "@weapp-tailwindcss/logger";
|
|
189
292
|
|
|
190
293
|
// src/cache/index.ts
|
|
191
294
|
import { LRUCache } from "lru-cache";
|
|
@@ -375,22 +478,22 @@ function createNameMatcher(list, { exact = false } = {}) {
|
|
|
375
478
|
|
|
376
479
|
// src/js/evalTransforms.ts
|
|
377
480
|
import { jsStringEscape } from "@ast-core/escape";
|
|
378
|
-
function isEvalPath(
|
|
379
|
-
if (
|
|
380
|
-
const calleePath =
|
|
481
|
+
function isEvalPath(path2) {
|
|
482
|
+
if (path2.isCallExpression()) {
|
|
483
|
+
const calleePath = path2.get("callee");
|
|
381
484
|
return calleePath.isIdentifier({ name: "eval" });
|
|
382
485
|
}
|
|
383
486
|
return false;
|
|
384
487
|
}
|
|
385
|
-
function createEvalReplacementToken(
|
|
386
|
-
const node =
|
|
488
|
+
function createEvalReplacementToken(path2, updated) {
|
|
489
|
+
const node = path2.node;
|
|
387
490
|
let offset = 0;
|
|
388
491
|
let original;
|
|
389
|
-
if (
|
|
492
|
+
if (path2.isStringLiteral()) {
|
|
390
493
|
offset = 1;
|
|
391
|
-
original =
|
|
392
|
-
} else if (
|
|
393
|
-
original =
|
|
494
|
+
original = path2.node.value;
|
|
495
|
+
} else if (path2.isTemplateElement()) {
|
|
496
|
+
original = path2.node.value.raw;
|
|
394
497
|
} else {
|
|
395
498
|
original = "";
|
|
396
499
|
}
|
|
@@ -405,16 +508,16 @@ function createEvalReplacementToken(path, updated) {
|
|
|
405
508
|
if (original === updated) {
|
|
406
509
|
return void 0;
|
|
407
510
|
}
|
|
408
|
-
const value =
|
|
511
|
+
const value = path2.isStringLiteral() ? jsStringEscape(updated) : updated;
|
|
409
512
|
return {
|
|
410
513
|
start,
|
|
411
514
|
end,
|
|
412
515
|
value,
|
|
413
|
-
path
|
|
516
|
+
path: path2
|
|
414
517
|
};
|
|
415
518
|
}
|
|
416
|
-
function handleEvalStringLiteral(
|
|
417
|
-
const { code } = handler(
|
|
519
|
+
function handleEvalStringLiteral(path2, options, updater, handler) {
|
|
520
|
+
const { code } = handler(path2.node.value, {
|
|
418
521
|
...options,
|
|
419
522
|
needEscaped: false,
|
|
420
523
|
generateMap: false
|
|
@@ -422,26 +525,26 @@ function handleEvalStringLiteral(path, options, updater, handler) {
|
|
|
422
525
|
if (!code) {
|
|
423
526
|
return;
|
|
424
527
|
}
|
|
425
|
-
const token = createEvalReplacementToken(
|
|
528
|
+
const token = createEvalReplacementToken(path2, code);
|
|
426
529
|
if (token) {
|
|
427
530
|
updater.addToken(token);
|
|
428
531
|
}
|
|
429
532
|
}
|
|
430
|
-
function handleEvalTemplateElement(
|
|
431
|
-
const { code } = handler(
|
|
533
|
+
function handleEvalTemplateElement(path2, options, updater, handler) {
|
|
534
|
+
const { code } = handler(path2.node.value.raw, {
|
|
432
535
|
...options,
|
|
433
536
|
generateMap: false
|
|
434
537
|
});
|
|
435
538
|
if (!code) {
|
|
436
539
|
return;
|
|
437
540
|
}
|
|
438
|
-
const token = createEvalReplacementToken(
|
|
541
|
+
const token = createEvalReplacementToken(path2, code);
|
|
439
542
|
if (token) {
|
|
440
543
|
updater.addToken(token);
|
|
441
544
|
}
|
|
442
545
|
}
|
|
443
|
-
function walkEvalExpression(
|
|
444
|
-
|
|
546
|
+
function walkEvalExpression(path2, options, updater, handler) {
|
|
547
|
+
path2.traverse({
|
|
445
548
|
StringLiteral(innerPath) {
|
|
446
549
|
handleEvalStringLiteral(innerPath, options, updater, handler);
|
|
447
550
|
},
|
|
@@ -479,6 +582,24 @@ function decodeUnicode2(input) {
|
|
|
479
582
|
}
|
|
480
583
|
}
|
|
481
584
|
|
|
585
|
+
// src/wxml/shared.ts
|
|
586
|
+
import { escape, MappingChars2String } from "@weapp-core/escape";
|
|
587
|
+
function replaceWxml(original, options = {
|
|
588
|
+
keepEOL: false,
|
|
589
|
+
escapeMap: MappingChars2String
|
|
590
|
+
}) {
|
|
591
|
+
const { keepEOL, escapeMap, ignoreHead } = options;
|
|
592
|
+
let res = original;
|
|
593
|
+
if (!keepEOL) {
|
|
594
|
+
res = res.replaceAll(/[\n\r]+/g, "");
|
|
595
|
+
}
|
|
596
|
+
res = escape(res, {
|
|
597
|
+
map: escapeMap,
|
|
598
|
+
ignoreHead
|
|
599
|
+
});
|
|
600
|
+
return res;
|
|
601
|
+
}
|
|
602
|
+
|
|
482
603
|
// src/js/handlers.ts
|
|
483
604
|
var patternCache = /* @__PURE__ */ new Map();
|
|
484
605
|
var replacementCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -531,15 +652,15 @@ function shouldTransformClassName(candidate, {
|
|
|
531
652
|
}
|
|
532
653
|
return !jsPreserveClass?.(candidate);
|
|
533
654
|
}
|
|
534
|
-
function extractLiteralValue(
|
|
655
|
+
function extractLiteralValue(path2, { unescapeUnicode, arbitraryValues }) {
|
|
535
656
|
const allowDoubleQuotes = arbitraryValues?.allowDoubleQuotes;
|
|
536
657
|
let offset = 0;
|
|
537
658
|
let original;
|
|
538
|
-
if (
|
|
659
|
+
if (path2.isStringLiteral()) {
|
|
539
660
|
offset = 1;
|
|
540
|
-
original =
|
|
541
|
-
} else if (
|
|
542
|
-
original =
|
|
661
|
+
original = path2.node.value;
|
|
662
|
+
} else if (path2.isTemplateElement()) {
|
|
663
|
+
original = path2.node.value.raw;
|
|
543
664
|
} else {
|
|
544
665
|
original = "";
|
|
545
666
|
}
|
|
@@ -554,7 +675,7 @@ function extractLiteralValue(path, { unescapeUnicode, arbitraryValues }) {
|
|
|
554
675
|
original
|
|
555
676
|
};
|
|
556
677
|
}
|
|
557
|
-
function replaceHandleValue(
|
|
678
|
+
function replaceHandleValue(path2, options) {
|
|
558
679
|
const {
|
|
559
680
|
escapeMap,
|
|
560
681
|
needEscaped = false
|
|
@@ -563,8 +684,8 @@ function replaceHandleValue(path, options) {
|
|
|
563
684
|
if (!alwaysEscape && (!classNameSet || classNameSet.size === 0)) {
|
|
564
685
|
return void 0;
|
|
565
686
|
}
|
|
566
|
-
const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(
|
|
567
|
-
if (hasIgnoreComment(
|
|
687
|
+
const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path2, options);
|
|
688
|
+
if (hasIgnoreComment(path2.node)) {
|
|
568
689
|
return void 0;
|
|
569
690
|
}
|
|
570
691
|
const candidates = splitCode(literal, allowDoubleQuotes);
|
|
@@ -588,7 +709,7 @@ function replaceHandleValue(path, options) {
|
|
|
588
709
|
mutated = true;
|
|
589
710
|
}
|
|
590
711
|
}
|
|
591
|
-
const node =
|
|
712
|
+
const node = path2.node;
|
|
592
713
|
if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
|
|
593
714
|
return void 0;
|
|
594
715
|
}
|
|
@@ -602,7 +723,7 @@ function replaceHandleValue(path, options) {
|
|
|
602
723
|
start,
|
|
603
724
|
end,
|
|
604
725
|
value,
|
|
605
|
-
path
|
|
726
|
+
path: path2
|
|
606
727
|
};
|
|
607
728
|
}
|
|
608
729
|
|
|
@@ -914,35 +1035,35 @@ var NodePathWalker = class {
|
|
|
914
1035
|
this.visited = /* @__PURE__ */ new WeakSet();
|
|
915
1036
|
this.isIgnoredCallIdentifier = createNameMatcher(this.ignoreCallExpressionIdentifiers, { exact: true });
|
|
916
1037
|
}
|
|
917
|
-
walkVariableDeclarator(
|
|
918
|
-
const init =
|
|
1038
|
+
walkVariableDeclarator(path2) {
|
|
1039
|
+
const init = path2.get("init");
|
|
919
1040
|
this.walkNode(init);
|
|
920
1041
|
}
|
|
921
|
-
walkTemplateLiteral(
|
|
922
|
-
for (const exp of
|
|
1042
|
+
walkTemplateLiteral(path2) {
|
|
1043
|
+
for (const exp of path2.get("expressions")) {
|
|
923
1044
|
this.walkNode(exp);
|
|
924
1045
|
}
|
|
925
|
-
for (const quasis of
|
|
1046
|
+
for (const quasis of path2.get("quasis")) {
|
|
926
1047
|
this.callback(quasis);
|
|
927
1048
|
}
|
|
928
1049
|
}
|
|
929
|
-
walkStringLiteral(
|
|
930
|
-
this.callback(
|
|
1050
|
+
walkStringLiteral(path2) {
|
|
1051
|
+
this.callback(path2);
|
|
931
1052
|
}
|
|
932
|
-
walkBinaryExpression(
|
|
933
|
-
const left =
|
|
1053
|
+
walkBinaryExpression(path2) {
|
|
1054
|
+
const left = path2.get("left");
|
|
934
1055
|
this.walkNode(left);
|
|
935
|
-
const right =
|
|
1056
|
+
const right = path2.get("right");
|
|
936
1057
|
this.walkNode(right);
|
|
937
1058
|
}
|
|
938
|
-
walkLogicalExpression(
|
|
939
|
-
const left =
|
|
1059
|
+
walkLogicalExpression(path2) {
|
|
1060
|
+
const left = path2.get("left");
|
|
940
1061
|
this.walkNode(left);
|
|
941
|
-
const right =
|
|
1062
|
+
const right = path2.get("right");
|
|
942
1063
|
this.walkNode(right);
|
|
943
1064
|
}
|
|
944
|
-
walkObjectExpression(
|
|
945
|
-
const props =
|
|
1065
|
+
walkObjectExpression(path2) {
|
|
1066
|
+
const props = path2.get("properties");
|
|
946
1067
|
for (const prop of props) {
|
|
947
1068
|
if (prop.isObjectProperty()) {
|
|
948
1069
|
const key = prop.get("key");
|
|
@@ -952,8 +1073,8 @@ var NodePathWalker = class {
|
|
|
952
1073
|
}
|
|
953
1074
|
}
|
|
954
1075
|
}
|
|
955
|
-
walkArrayExpression(
|
|
956
|
-
const elements =
|
|
1076
|
+
walkArrayExpression(path2) {
|
|
1077
|
+
const elements = path2.get("elements");
|
|
957
1078
|
for (const element of elements) {
|
|
958
1079
|
this.walkNode(element);
|
|
959
1080
|
}
|
|
@@ -1026,33 +1147,33 @@ var NodePathWalker = class {
|
|
|
1026
1147
|
/**
|
|
1027
1148
|
* Walk the arguments of a desired call expression so their bindings can be analysed.
|
|
1028
1149
|
*/
|
|
1029
|
-
walkCallExpression(
|
|
1030
|
-
const calleePath =
|
|
1150
|
+
walkCallExpression(path2) {
|
|
1151
|
+
const calleePath = path2.get("callee");
|
|
1031
1152
|
if (calleePath.isIdentifier() && this.isIgnoredCallIdentifier(calleePath.node.name)) {
|
|
1032
|
-
for (const arg of
|
|
1153
|
+
for (const arg of path2.get("arguments")) {
|
|
1033
1154
|
this.walkNode(arg);
|
|
1034
1155
|
}
|
|
1035
1156
|
}
|
|
1036
1157
|
}
|
|
1037
|
-
walkExportDeclaration(
|
|
1038
|
-
if (
|
|
1039
|
-
if (
|
|
1040
|
-
this.walkExportNamedDeclaration(
|
|
1041
|
-
} else if (
|
|
1042
|
-
this.walkExportDefaultDeclaration(
|
|
1043
|
-
} else if (
|
|
1044
|
-
this.walkExportAllDeclaration(
|
|
1158
|
+
walkExportDeclaration(path2) {
|
|
1159
|
+
if (path2.isExportDeclaration()) {
|
|
1160
|
+
if (path2.isExportNamedDeclaration()) {
|
|
1161
|
+
this.walkExportNamedDeclaration(path2);
|
|
1162
|
+
} else if (path2.isExportDefaultDeclaration()) {
|
|
1163
|
+
this.walkExportDefaultDeclaration(path2);
|
|
1164
|
+
} else if (path2.isExportAllDeclaration()) {
|
|
1165
|
+
this.walkExportAllDeclaration(path2);
|
|
1045
1166
|
}
|
|
1046
1167
|
}
|
|
1047
1168
|
}
|
|
1048
|
-
walkExportNamedDeclaration(
|
|
1049
|
-
const declaration =
|
|
1169
|
+
walkExportNamedDeclaration(path2) {
|
|
1170
|
+
const declaration = path2.get("declaration");
|
|
1050
1171
|
if (declaration.isVariableDeclaration()) {
|
|
1051
1172
|
for (const decl of declaration.get("declarations")) {
|
|
1052
1173
|
this.walkNode(decl);
|
|
1053
1174
|
}
|
|
1054
1175
|
}
|
|
1055
|
-
const specifiers =
|
|
1176
|
+
const specifiers = path2.get("specifiers");
|
|
1056
1177
|
for (const spec of specifiers) {
|
|
1057
1178
|
if (spec.isExportSpecifier()) {
|
|
1058
1179
|
const local = spec.get("local");
|
|
@@ -1062,20 +1183,20 @@ var NodePathWalker = class {
|
|
|
1062
1183
|
}
|
|
1063
1184
|
}
|
|
1064
1185
|
}
|
|
1065
|
-
walkExportDefaultDeclaration(
|
|
1066
|
-
const decl =
|
|
1186
|
+
walkExportDefaultDeclaration(path2) {
|
|
1187
|
+
const decl = path2.get("declaration");
|
|
1067
1188
|
if (decl.isIdentifier()) {
|
|
1068
1189
|
this.walkNode(decl);
|
|
1069
1190
|
} else {
|
|
1070
1191
|
this.walkNode(decl);
|
|
1071
1192
|
}
|
|
1072
1193
|
}
|
|
1073
|
-
walkExportAllDeclaration(
|
|
1074
|
-
const source =
|
|
1194
|
+
walkExportAllDeclaration(path2) {
|
|
1195
|
+
const source = path2.get("source");
|
|
1075
1196
|
if (source.isStringLiteral()) {
|
|
1076
1197
|
this.imports.add(
|
|
1077
1198
|
{
|
|
1078
|
-
declaration:
|
|
1199
|
+
declaration: path2,
|
|
1079
1200
|
source: source.node.value,
|
|
1080
1201
|
type: "ExportAllDeclaration"
|
|
1081
1202
|
}
|
|
@@ -1085,8 +1206,8 @@ var NodePathWalker = class {
|
|
|
1085
1206
|
};
|
|
1086
1207
|
|
|
1087
1208
|
// src/js/sourceAnalysis.ts
|
|
1088
|
-
function createModuleSpecifierReplacementToken(
|
|
1089
|
-
const node =
|
|
1209
|
+
function createModuleSpecifierReplacementToken(path2, replacement) {
|
|
1210
|
+
const node = path2.node;
|
|
1090
1211
|
if (node.value === replacement) {
|
|
1091
1212
|
return void 0;
|
|
1092
1213
|
}
|
|
@@ -1102,17 +1223,17 @@ function createModuleSpecifierReplacementToken(path, replacement) {
|
|
|
1102
1223
|
start,
|
|
1103
1224
|
end,
|
|
1104
1225
|
value: replacement,
|
|
1105
|
-
path
|
|
1226
|
+
path: path2
|
|
1106
1227
|
};
|
|
1107
1228
|
}
|
|
1108
1229
|
function collectModuleSpecifierReplacementTokens(analysis, replacements) {
|
|
1109
1230
|
const tokens = [];
|
|
1110
|
-
const applyReplacement = (
|
|
1111
|
-
const replacement = replacements[
|
|
1231
|
+
const applyReplacement = (path2) => {
|
|
1232
|
+
const replacement = replacements[path2.node.value];
|
|
1112
1233
|
if (!replacement) {
|
|
1113
1234
|
return;
|
|
1114
1235
|
}
|
|
1115
|
-
const token = createModuleSpecifierReplacementToken(
|
|
1236
|
+
const token = createModuleSpecifierReplacementToken(path2, replacement);
|
|
1116
1237
|
if (token) {
|
|
1117
1238
|
tokens.push(token);
|
|
1118
1239
|
}
|
|
@@ -1164,12 +1285,12 @@ function createTaggedTemplateIgnore({ matcher, names }) {
|
|
|
1164
1285
|
}
|
|
1165
1286
|
return false;
|
|
1166
1287
|
};
|
|
1167
|
-
const resolvesMemberExpressionToIgnore = (
|
|
1168
|
-
const propertyPath =
|
|
1288
|
+
const resolvesMemberExpressionToIgnore = (path2, seen) => {
|
|
1289
|
+
const propertyPath = path2.get("property");
|
|
1169
1290
|
if (propertyMatches(propertyPath)) {
|
|
1170
1291
|
return true;
|
|
1171
1292
|
}
|
|
1172
|
-
const objectPath =
|
|
1293
|
+
const objectPath = path2.get("object");
|
|
1173
1294
|
if (objectPath.isIdentifier()) {
|
|
1174
1295
|
const binding = objectPath.scope.getBinding(objectPath.node.name);
|
|
1175
1296
|
if (binding) {
|
|
@@ -1324,9 +1445,9 @@ function analyzeSource(ast, options, handler) {
|
|
|
1324
1445
|
const walker = new NodePathWalker(
|
|
1325
1446
|
{
|
|
1326
1447
|
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
1327
|
-
callback(
|
|
1328
|
-
if (
|
|
1329
|
-
ignoredPaths.add(
|
|
1448
|
+
callback(path2) {
|
|
1449
|
+
if (path2.isStringLiteral() || path2.isTemplateElement()) {
|
|
1450
|
+
ignoredPaths.add(path2);
|
|
1330
1451
|
}
|
|
1331
1452
|
}
|
|
1332
1453
|
}
|
|
@@ -1414,15 +1535,15 @@ function processUpdatedSource(rawSource, options, analysis) {
|
|
|
1414
1535
|
const ms = new MagicString(rawSource);
|
|
1415
1536
|
const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
|
|
1416
1537
|
const replacementTokens = [];
|
|
1417
|
-
for (const
|
|
1418
|
-
if (ignoredPaths.has(
|
|
1538
|
+
for (const path2 of targetPaths) {
|
|
1539
|
+
if (ignoredPaths.has(path2)) {
|
|
1419
1540
|
continue;
|
|
1420
1541
|
}
|
|
1421
1542
|
const token = replaceHandleValue(
|
|
1422
|
-
|
|
1543
|
+
path2,
|
|
1423
1544
|
{
|
|
1424
1545
|
...options,
|
|
1425
|
-
needEscaped:
|
|
1546
|
+
needEscaped: path2.isStringLiteral() ? options.needEscaped ?? true : false
|
|
1426
1547
|
}
|
|
1427
1548
|
);
|
|
1428
1549
|
if (token) {
|
|
@@ -1769,16 +1890,16 @@ function generateCode(match, options = {}) {
|
|
|
1769
1890
|
const ast = parseExpression(match);
|
|
1770
1891
|
const jsTokenUpdater = new JsTokenUpdater();
|
|
1771
1892
|
traverse(ast, {
|
|
1772
|
-
StringLiteral(
|
|
1773
|
-
if (t.isMemberExpression(
|
|
1893
|
+
StringLiteral(path2) {
|
|
1894
|
+
if (t.isMemberExpression(path2.parent)) {
|
|
1774
1895
|
return;
|
|
1775
1896
|
}
|
|
1776
|
-
if (t.isBinaryExpression(
|
|
1897
|
+
if (t.isBinaryExpression(path2.parent) && (t.isConditionalExpression(path2.parentPath?.parent) || t.isLogicalExpression(path2.parentPath?.parent))) {
|
|
1777
1898
|
return;
|
|
1778
1899
|
}
|
|
1779
1900
|
jsTokenUpdater.addToken(
|
|
1780
1901
|
replaceHandleValue(
|
|
1781
|
-
|
|
1902
|
+
path2,
|
|
1782
1903
|
{
|
|
1783
1904
|
escapeMap: options.escapeMap,
|
|
1784
1905
|
classNameSet: options.runtimeSet,
|
|
@@ -2016,7 +2137,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
2016
2137
|
}
|
|
2017
2138
|
|
|
2018
2139
|
// src/context/logger.ts
|
|
2019
|
-
import { logger } from "@weapp-tailwindcss/logger";
|
|
2140
|
+
import { logger as logger2 } from "@weapp-tailwindcss/logger";
|
|
2020
2141
|
var loggerLevelMap = {
|
|
2021
2142
|
error: 0,
|
|
2022
2143
|
warn: 1,
|
|
@@ -2024,7 +2145,7 @@ var loggerLevelMap = {
|
|
|
2024
2145
|
silent: -999
|
|
2025
2146
|
};
|
|
2026
2147
|
function applyLoggerLevel(logLevel) {
|
|
2027
|
-
|
|
2148
|
+
logger2.level = loggerLevelMap[logLevel ?? "info"] ?? loggerLevelMap.info;
|
|
2028
2149
|
}
|
|
2029
2150
|
|
|
2030
2151
|
// src/context/index.ts
|
|
@@ -2077,26 +2198,38 @@ function ensureDefaultsIncluded(value) {
|
|
|
2077
2198
|
}
|
|
2078
2199
|
return value;
|
|
2079
2200
|
}
|
|
2080
|
-
async function clearTailwindcssPatcherCache(patcher) {
|
|
2201
|
+
async function clearTailwindcssPatcherCache(patcher, options) {
|
|
2081
2202
|
if (!patcher) {
|
|
2082
2203
|
return;
|
|
2083
2204
|
}
|
|
2084
2205
|
const cacheOptions = patcher.options?.cache;
|
|
2085
|
-
if (
|
|
2206
|
+
if (cacheOptions == null || cacheOptions === false || typeof cacheOptions === "object" && cacheOptions.enabled === false) {
|
|
2086
2207
|
return;
|
|
2087
2208
|
}
|
|
2088
|
-
const
|
|
2089
|
-
|
|
2209
|
+
const cachePaths = /* @__PURE__ */ new Map();
|
|
2210
|
+
const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
|
|
2211
|
+
if (normalizedCacheOptions?.path) {
|
|
2212
|
+
cachePaths.set(normalizedCacheOptions.path, false);
|
|
2213
|
+
}
|
|
2214
|
+
if (patcher.cacheStore?.options?.path) {
|
|
2215
|
+
cachePaths.set(patcher.cacheStore.options.path, false);
|
|
2216
|
+
}
|
|
2217
|
+
if (options?.removeDirectory && normalizedCacheOptions?.dir) {
|
|
2218
|
+
cachePaths.set(normalizedCacheOptions.dir, true);
|
|
2219
|
+
}
|
|
2220
|
+
if (!cachePaths.size) {
|
|
2090
2221
|
return;
|
|
2091
2222
|
}
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2223
|
+
for (const [cachePath, recursive] of cachePaths.entries()) {
|
|
2224
|
+
try {
|
|
2225
|
+
await rm(cachePath, { force: true, recursive });
|
|
2226
|
+
} catch (error) {
|
|
2227
|
+
const err = error;
|
|
2228
|
+
if (err?.code === "ENOENT") {
|
|
2229
|
+
continue;
|
|
2230
|
+
}
|
|
2231
|
+
logger3.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
|
|
2098
2232
|
}
|
|
2099
|
-
logger2.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
|
|
2100
2233
|
}
|
|
2101
2234
|
}
|
|
2102
2235
|
function getCompilerContext(opts) {
|
|
@@ -2108,11 +2241,13 @@ function getCompilerContext(opts) {
|
|
|
2108
2241
|
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
2109
2242
|
applyLoggerLevel(ctx.logLevel);
|
|
2110
2243
|
const twPatcher = createTailwindcssPatcherFromContext(ctx);
|
|
2244
|
+
logTailwindcssTarget("runtime", twPatcher, ctx.tailwindcssBasedir);
|
|
2111
2245
|
if (twPatcher.packageInfo?.version) {
|
|
2112
|
-
|
|
2246
|
+
logger3.success(`\u5F53\u524D\u4F7F\u7528 ${pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${pc.underline(pc.bold(pc.green(twPatcher.packageInfo.version)))}`);
|
|
2113
2247
|
} else {
|
|
2114
|
-
|
|
2248
|
+
logger3.warn(`${pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
|
|
2115
2249
|
}
|
|
2250
|
+
warnIfCliPatchTargetMismatch(ctx.tailwindcssBasedir, twPatcher);
|
|
2116
2251
|
let cssCalcOptions = ctx.cssCalc ?? twPatcher.majorVersion === 4;
|
|
2117
2252
|
if (twPatcher.majorVersion === 4 && cssCalcOptions) {
|
|
2118
2253
|
cssCalcOptions = ensureDefaultsIncluded(cssCalcOptions);
|
|
@@ -2153,11 +2288,15 @@ export {
|
|
|
2153
2288
|
createTailwindPatchPromise,
|
|
2154
2289
|
refreshTailwindRuntimeState,
|
|
2155
2290
|
collectRuntimeClassSet,
|
|
2291
|
+
logTailwindcssTarget,
|
|
2292
|
+
saveCliPatchTargetRecord,
|
|
2156
2293
|
toCustomAttributesEntities,
|
|
2157
2294
|
pluginName,
|
|
2158
2295
|
vitePluginName,
|
|
2159
2296
|
WEAPP_TW_REQUIRED_NODE_VERSION,
|
|
2297
|
+
replaceWxml,
|
|
2160
2298
|
createAttributeMatcher,
|
|
2161
2299
|
generateCode,
|
|
2300
|
+
clearTailwindcssPatcherCache,
|
|
2162
2301
|
getCompilerContext
|
|
2163
2302
|
};
|