weapp-tailwindcss 4.12.0-next.0 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/weapp-tailwindcss.js +21 -1
- package/dist/{chunk-GMKSBLNY.js → chunk-24AGZQVR.js} +15 -7
- package/dist/{chunk-F2CKKG6Q.mjs → chunk-3VQKDHGP.mjs} +12 -4
- package/dist/{chunk-F5XJWJYO.mjs → chunk-57SOQCAU.mjs} +5 -5
- package/dist/{chunk-GD4SQMVF.mjs → chunk-5ZYHNDEK.mjs} +98 -37
- package/dist/{chunk-FMK6SFQQ.js → chunk-DUHYLR2R.js} +7 -7
- package/dist/{chunk-OYSABARD.js → chunk-E7I5TW5K.js} +3 -2
- package/dist/{chunk-WSS26HZS.js → chunk-FS2NOOEB.js} +5 -5
- package/dist/{chunk-GC7WXUOW.js → chunk-HVNGIKLS.js} +55 -31
- package/dist/{chunk-LVSUBDJC.js → chunk-JZQBZHN5.js} +39 -39
- package/dist/{chunk-QNRJCEZN.mjs → chunk-KGTVD4EP.mjs} +66 -42
- package/dist/{chunk-HL3US2OT.mjs → chunk-NNOQDMUP.mjs} +1 -1
- package/dist/{chunk-5ONE75V7.js → chunk-OFB2KBRP.js} +175 -114
- package/dist/{chunk-AYJ4HLWZ.mjs → chunk-PCDYXXSK.mjs} +11 -4
- package/dist/{chunk-ONLKZIRQ.js → chunk-RKISS72P.js} +1 -1
- package/dist/{chunk-ZR3KN3FG.mjs → chunk-RRQZL7FQ.mjs} +2 -2
- package/dist/{chunk-UUJWDME4.mjs → chunk-XZP3MREK.mjs} +1 -1
- package/dist/{chunk-NIS74SI6.js → chunk-ZAA5ZG3D.js} +60 -53
- package/dist/{chunk-2LH6PZH3.mjs → chunk-ZCH4YINE.mjs} +3 -2
- package/dist/cli.js +2241 -169
- package/dist/cli.mjs +2246 -174
- package/dist/core.js +9 -9
- package/dist/core.mjs +3 -3
- package/dist/css-macro/postcss.js +4 -4
- package/dist/css-macro/postcss.mjs +2 -2
- package/dist/css-macro.js +5 -5
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/gulp.js +5 -5
- package/dist/gulp.mjs +4 -4
- package/dist/index.js +9 -9
- package/dist/index.mjs +8 -8
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.js +6 -6
- package/dist/presets.mjs +2 -2
- package/dist/reset.js +1 -1
- package/dist/reset.mjs +1 -1
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.js +6 -6
- package/dist/vite.mjs +5 -5
- package/dist/weapp-tw-css-import-rewrite-loader.js +10 -5
- package/dist/weapp-tw-runtime-classset-loader.js +9 -4
- package/dist/webpack.js +7 -7
- package/dist/webpack.mjs +6 -6
- package/dist/webpack4.js +59 -55
- package/dist/webpack4.mjs +28 -24
- package/package.json +11 -10
- package/scripts/postinstall.mjs +59 -0
package/dist/cli.js
CHANGED
|
@@ -23,8 +23,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
|
|
25
25
|
// src/cli.ts
|
|
26
|
-
var
|
|
27
|
-
var
|
|
26
|
+
var import_node_process19 = __toESM(require("process"));
|
|
27
|
+
var import_semver2 = __toESM(require("semver"));
|
|
28
28
|
var import_tailwindcss_patch3 = require("tailwindcss-patch");
|
|
29
29
|
|
|
30
30
|
// src/cli/context.ts
|
|
@@ -156,18 +156,21 @@ function findNearestPackageRoot(startDir) {
|
|
|
156
156
|
var PATCH_INFO_FILENAME = "tailwindcss-target.json";
|
|
157
157
|
var PATCH_INFO_CACHE_RELATIVE_PATH = import_node_path3.default.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
|
|
158
158
|
var PATCH_INFO_LEGACY_RELATIVE_PATH = import_node_path3.default.join(".tw-patch", PATCH_INFO_FILENAME);
|
|
159
|
+
function toDisplayPath(value) {
|
|
160
|
+
return import_node_path3.default.normalize(value).replace(/\\/g, "/");
|
|
161
|
+
}
|
|
159
162
|
function formatRelativeToBase(targetPath, baseDir) {
|
|
160
163
|
if (!baseDir) {
|
|
161
|
-
return
|
|
164
|
+
return toDisplayPath(targetPath);
|
|
162
165
|
}
|
|
163
166
|
const relative = import_node_path3.default.relative(baseDir, targetPath);
|
|
164
167
|
if (!relative || relative === ".") {
|
|
165
168
|
return ".";
|
|
166
169
|
}
|
|
167
170
|
if (relative.startsWith("..")) {
|
|
168
|
-
return
|
|
171
|
+
return toDisplayPath(targetPath);
|
|
169
172
|
}
|
|
170
|
-
return import_node_path3.default.join(".", relative);
|
|
173
|
+
return toDisplayPath(import_node_path3.default.join(".", relative));
|
|
171
174
|
}
|
|
172
175
|
function resolveRecordLocation(baseDir) {
|
|
173
176
|
const normalizedBase = import_node_path3.default.normalize(baseDir);
|
|
@@ -208,7 +211,7 @@ var import_logger2 = require("@weapp-tailwindcss/logger");
|
|
|
208
211
|
// package.json
|
|
209
212
|
var package_default = {
|
|
210
213
|
name: "weapp-tailwindcss",
|
|
211
|
-
version: "4.12.0
|
|
214
|
+
version: "4.12.0",
|
|
212
215
|
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!",
|
|
213
216
|
author: "ice breaker <1324318532@qq.com>",
|
|
214
217
|
license: "MIT",
|
|
@@ -358,13 +361,14 @@ var package_default = {
|
|
|
358
361
|
"dist",
|
|
359
362
|
"index.css",
|
|
360
363
|
"preflight.css",
|
|
364
|
+
"scripts/postinstall.mjs",
|
|
361
365
|
"theme.css",
|
|
362
366
|
"uni-app-x.css",
|
|
363
367
|
"utilities.css",
|
|
364
368
|
"with-layer.css"
|
|
365
369
|
],
|
|
366
370
|
engines: {
|
|
367
|
-
node: "^
|
|
371
|
+
node: "^20.19.0 || >=22.12.0"
|
|
368
372
|
},
|
|
369
373
|
scripts: {
|
|
370
374
|
dev: "tsup --watch --sourcemap",
|
|
@@ -373,7 +377,7 @@ var package_default = {
|
|
|
373
377
|
"build:cli": "cd plugins/cli && pnpm run build",
|
|
374
378
|
"build:css": "tsx scripts/build-css.ts",
|
|
375
379
|
"build:weapp-theme": "tsx scripts/build-weapp-theme.ts",
|
|
376
|
-
test: "
|
|
380
|
+
test: "pnpm run cli:patch && vitest run",
|
|
377
381
|
"test:dev": "vitest",
|
|
378
382
|
"test:ui": "vitest --ui",
|
|
379
383
|
bench: "vitest bench --config ./vitest.config.ts",
|
|
@@ -390,7 +394,7 @@ var package_default = {
|
|
|
390
394
|
release: "tsx scripts/release.ts",
|
|
391
395
|
lint: "eslint .",
|
|
392
396
|
"lint:fix": "eslint ./src --fix",
|
|
393
|
-
postinstall: "node
|
|
397
|
+
postinstall: "node scripts/postinstall.mjs",
|
|
394
398
|
"bench:vite-dev-hmr": "tsx scripts/vite-dev-hmr-bench.ts",
|
|
395
399
|
"test:watch-hmr": "node --import tsx scripts/watch-hmr-regression/index.ts"
|
|
396
400
|
},
|
|
@@ -400,10 +404,10 @@ var package_default = {
|
|
|
400
404
|
},
|
|
401
405
|
dependencies: {
|
|
402
406
|
"@ast-core/escape": "~1.0.1",
|
|
403
|
-
"@babel/parser": "~7.29.
|
|
407
|
+
"@babel/parser": "~7.29.3",
|
|
404
408
|
"@babel/traverse": "~7.29.0",
|
|
405
409
|
"@babel/types": "~7.29.0",
|
|
406
|
-
"@tailwindcss-mangle/config": "^7.0.
|
|
410
|
+
"@tailwindcss-mangle/config": "^7.0.1",
|
|
407
411
|
"@vue/compiler-dom": "catalog:vue3",
|
|
408
412
|
"@vue/compiler-sfc": "catalog:vue3",
|
|
409
413
|
"@weapp-core/escape": "~7.0.0",
|
|
@@ -424,7 +428,7 @@ var package_default = {
|
|
|
424
428
|
semver: "~7.7.4",
|
|
425
429
|
"tailwindcss-patch": "catalog:tailwindcssPatch",
|
|
426
430
|
"webpack-sources": "3.3.4",
|
|
427
|
-
yaml: "^2.8.
|
|
431
|
+
yaml: "^2.8.4"
|
|
428
432
|
},
|
|
429
433
|
devDependencies: {
|
|
430
434
|
"fast-check": "^4.7.0"
|
|
@@ -432,7 +436,7 @@ var package_default = {
|
|
|
432
436
|
};
|
|
433
437
|
|
|
434
438
|
// src/constants.ts
|
|
435
|
-
var
|
|
439
|
+
var WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
436
440
|
var WEAPP_TW_VERSION = package_default.version;
|
|
437
441
|
|
|
438
442
|
// src/tailwindcss/targets/record-io.ts
|
|
@@ -587,105 +591,1895 @@ function createPatchTargetRecorder(baseDir, patcher, options) {
|
|
|
587
591
|
packageJsonPath: location.packageJsonPath
|
|
588
592
|
});
|
|
589
593
|
return {
|
|
590
|
-
recordPath: location.recordPath,
|
|
591
|
-
message,
|
|
592
|
-
reason,
|
|
593
|
-
onPatched
|
|
594
|
+
recordPath: location.recordPath,
|
|
595
|
+
message,
|
|
596
|
+
reason,
|
|
597
|
+
onPatched
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// src/tailwindcss/targets.ts
|
|
602
|
+
function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
603
|
+
const packageInfo = patcher?.packageInfo;
|
|
604
|
+
const label = kind === "cli" ? "weapp-tw patch" : "Weapp-tailwindcss";
|
|
605
|
+
if (!packageInfo?.rootPath) {
|
|
606
|
+
import_logger3.logger.warn(
|
|
607
|
+
"%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
|
|
608
|
+
label,
|
|
609
|
+
baseDir ?? import_node_process6.default.cwd()
|
|
610
|
+
);
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
|
|
614
|
+
const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
|
|
615
|
+
if (kind === "runtime") {
|
|
616
|
+
logRuntimeTailwindcssTarget(baseDir, packageInfo.rootPath, packageInfo.version);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
import_logger3.logger.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/tailwindcss/v4/config.ts
|
|
623
|
+
var import_logger4 = require("@weapp-tailwindcss/logger");
|
|
624
|
+
|
|
625
|
+
// src/tailwindcss/v4/patcher.ts
|
|
626
|
+
var import_logger6 = require("@weapp-tailwindcss/logger");
|
|
627
|
+
|
|
628
|
+
// src/tailwindcss/patcher.ts
|
|
629
|
+
var import_node_path7 = __toESM(require("path"));
|
|
630
|
+
var import_node_process8 = __toESM(require("process"));
|
|
631
|
+
var import_logger5 = require("@weapp-tailwindcss/logger");
|
|
632
|
+
var import_shared2 = require("@weapp-tailwindcss/shared");
|
|
633
|
+
var import_tailwindcss_patch = require("tailwindcss-patch");
|
|
634
|
+
|
|
635
|
+
// src/tailwindcss/patcher-resolve.ts
|
|
636
|
+
var import_node_fs5 = require("fs");
|
|
637
|
+
var import_node_module = require("module");
|
|
638
|
+
var import_node_path6 = __toESM(require("path"));
|
|
639
|
+
var import_node_process7 = __toESM(require("process"));
|
|
640
|
+
var import_node_url = require("url");
|
|
641
|
+
|
|
642
|
+
// src/tailwindcss/v4/css-entries.ts
|
|
643
|
+
var import_node_path8 = __toESM(require("path"));
|
|
644
|
+
|
|
645
|
+
// src/context/compiler-context-cache.ts
|
|
646
|
+
var import_node_buffer = require("buffer");
|
|
647
|
+
var import_node_path9 = __toESM(require("path"));
|
|
648
|
+
var import_node_process9 = __toESM(require("process"));
|
|
649
|
+
var import_logger7 = require("@weapp-tailwindcss/logger");
|
|
650
|
+
var globalCacheHolder = globalThis;
|
|
651
|
+
var compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
652
|
+
|
|
653
|
+
// src/context/handlers.ts
|
|
654
|
+
var import_postcss = require("@weapp-tailwindcss/postcss");
|
|
655
|
+
|
|
656
|
+
// src/js/index.ts
|
|
657
|
+
var import_lru_cache3 = require("lru-cache");
|
|
658
|
+
|
|
659
|
+
// src/babel/index.ts
|
|
660
|
+
var import_traverse = __toESM(require("@babel/traverse"));
|
|
661
|
+
var import_parser = require("@babel/parser");
|
|
662
|
+
function _interopDefaultCompat(e) {
|
|
663
|
+
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
664
|
+
}
|
|
665
|
+
var traverse = _interopDefaultCompat(import_traverse.default);
|
|
666
|
+
|
|
667
|
+
// src/utils/nameMatcher.ts
|
|
668
|
+
var import_regex = require("@weapp-core/regex");
|
|
669
|
+
var NEVER_MATCH_NAME = () => false;
|
|
670
|
+
var GLOBAL_FLAG_REGEXP = /g/g;
|
|
671
|
+
function buildFuzzyMatcher(fuzzyStrings) {
|
|
672
|
+
if (fuzzyStrings.length === 0) {
|
|
673
|
+
return void 0;
|
|
674
|
+
}
|
|
675
|
+
if (fuzzyStrings.length === 1) {
|
|
676
|
+
const [needle] = fuzzyStrings;
|
|
677
|
+
return (value) => value.includes(needle);
|
|
678
|
+
}
|
|
679
|
+
const unique = [...new Set(fuzzyStrings)];
|
|
680
|
+
const pattern = new RegExp(unique.map(import_regex.escapeStringRegexp).join("|"));
|
|
681
|
+
return (value) => pattern.test(value);
|
|
682
|
+
}
|
|
683
|
+
function normaliseRegex(regex) {
|
|
684
|
+
const { source, flags } = regex;
|
|
685
|
+
if (!flags.includes("g")) {
|
|
686
|
+
return regex;
|
|
687
|
+
}
|
|
688
|
+
return new RegExp(source, flags.replace(GLOBAL_FLAG_REGEXP, ""));
|
|
689
|
+
}
|
|
690
|
+
function createNameMatcher(list, { exact = false } = {}) {
|
|
691
|
+
if (!list || list.length === 0) {
|
|
692
|
+
return NEVER_MATCH_NAME;
|
|
693
|
+
}
|
|
694
|
+
const exactStrings = exact ? /* @__PURE__ */ new Set() : void 0;
|
|
695
|
+
const fuzzyStrings = [];
|
|
696
|
+
const regexList = [];
|
|
697
|
+
for (const item of list) {
|
|
698
|
+
if (typeof item === "string") {
|
|
699
|
+
if (exact) {
|
|
700
|
+
exactStrings.add(item);
|
|
701
|
+
} else {
|
|
702
|
+
fuzzyStrings.push(item);
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
regexList.push(normaliseRegex(item));
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
if (exact) {
|
|
709
|
+
const exactStringCount = exactStrings?.size ?? 0;
|
|
710
|
+
if (exactStringCount === 1 && regexList.length === 0) {
|
|
711
|
+
const [needle] = exactStrings;
|
|
712
|
+
return (value) => value === needle;
|
|
713
|
+
}
|
|
714
|
+
if (regexList.length === 0) {
|
|
715
|
+
return (value) => exactStrings.has(value);
|
|
716
|
+
}
|
|
717
|
+
if (exactStringCount === 0 && regexList.length === 1) {
|
|
718
|
+
const [regex] = regexList;
|
|
719
|
+
return (value) => regex.test(value);
|
|
720
|
+
}
|
|
721
|
+
return (value) => {
|
|
722
|
+
if (exactStrings?.has(value)) {
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
725
|
+
return regexList.some((regex) => regex.test(value));
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
const fuzzyMatcher = exact ? void 0 : buildFuzzyMatcher(fuzzyStrings);
|
|
729
|
+
const hasRegex = regexList.length > 0;
|
|
730
|
+
if (fuzzyMatcher && !hasRegex) {
|
|
731
|
+
return fuzzyMatcher;
|
|
732
|
+
}
|
|
733
|
+
if (!fuzzyMatcher && regexList.length === 1) {
|
|
734
|
+
const [regex] = regexList;
|
|
735
|
+
return (value) => regex.test(value);
|
|
736
|
+
}
|
|
737
|
+
return (value) => {
|
|
738
|
+
if (fuzzyMatcher?.(value)) {
|
|
739
|
+
return true;
|
|
740
|
+
}
|
|
741
|
+
if (!hasRegex) {
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
return regexList.some((regex) => regex.test(value));
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// src/js/babel/parse.ts
|
|
749
|
+
var import_lru_cache2 = require("lru-cache");
|
|
750
|
+
var parseCache = new import_lru_cache2.LRUCache(
|
|
751
|
+
{
|
|
752
|
+
max: 1024
|
|
753
|
+
}
|
|
754
|
+
);
|
|
755
|
+
function genCacheKey(source, options) {
|
|
756
|
+
if (typeof options === "string") {
|
|
757
|
+
return source + options;
|
|
758
|
+
}
|
|
759
|
+
return source + JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val);
|
|
760
|
+
}
|
|
761
|
+
function babelParse(code, opts = {}) {
|
|
762
|
+
const { cache, cacheKey, ...rest } = opts;
|
|
763
|
+
const cacheKeyString = genCacheKey(code, cacheKey ?? rest);
|
|
764
|
+
let result;
|
|
765
|
+
if (cache) {
|
|
766
|
+
result = parseCache.get(cacheKeyString);
|
|
767
|
+
}
|
|
768
|
+
if (!result) {
|
|
769
|
+
const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
|
|
770
|
+
result = (0, import_parser.parse)(code, parseOptions);
|
|
771
|
+
if (cache) {
|
|
772
|
+
parseCache.set(cacheKeyString, result);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return result;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// src/js/babel/process.ts
|
|
779
|
+
var import_magic_string = __toESM(require("magic-string"));
|
|
780
|
+
|
|
781
|
+
// src/js/handlers.ts
|
|
782
|
+
var import_escape3 = require("@ast-core/escape");
|
|
783
|
+
var import_extractors = require("@weapp-tailwindcss/shared/extractors");
|
|
784
|
+
|
|
785
|
+
// src/wxml/shared.ts
|
|
786
|
+
var import_escape2 = require("@weapp-core/escape");
|
|
787
|
+
var NEWLINE_RE = /[\n\r]+/g;
|
|
788
|
+
function replaceWxml(original, options = {
|
|
789
|
+
keepEOL: false,
|
|
790
|
+
escapeMap: import_escape2.MappingChars2String
|
|
791
|
+
}) {
|
|
792
|
+
const { keepEOL, escapeMap, ignoreHead } = options;
|
|
793
|
+
let res = original;
|
|
794
|
+
if (!keepEOL) {
|
|
795
|
+
res = res.replaceAll(NEWLINE_RE, "");
|
|
796
|
+
}
|
|
797
|
+
res = (0, import_escape2.escape)(res, {
|
|
798
|
+
map: escapeMap,
|
|
799
|
+
ignoreHead
|
|
800
|
+
});
|
|
801
|
+
return res;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// src/shared/classname-transform.ts
|
|
805
|
+
var escapedCandidateCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
|
|
806
|
+
var defaultEscapedCandidateCache = /* @__PURE__ */ new Map();
|
|
807
|
+
var lastEscapedCandidateEscapeMap;
|
|
808
|
+
var lastEscapedCandidateCacheStore;
|
|
809
|
+
function isUrlLikeCandidate(candidate) {
|
|
810
|
+
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
811
|
+
}
|
|
812
|
+
function isArbitraryValueCandidate(candidate) {
|
|
813
|
+
let hasOpenBracket = false;
|
|
814
|
+
let hasCloseBracket = false;
|
|
815
|
+
for (let i = 0; i < candidate.length; i++) {
|
|
816
|
+
const char = candidate[i];
|
|
817
|
+
if (char === "[") {
|
|
818
|
+
hasOpenBracket = true;
|
|
819
|
+
} else if (char === "]") {
|
|
820
|
+
hasCloseBracket = true;
|
|
821
|
+
}
|
|
822
|
+
if (hasOpenBracket && hasCloseBracket) {
|
|
823
|
+
break;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
if (!hasOpenBracket || !hasCloseBracket) {
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
829
|
+
const normalized = candidate.trim();
|
|
830
|
+
if (isUrlLikeCandidate(normalized)) {
|
|
831
|
+
return false;
|
|
832
|
+
}
|
|
833
|
+
return true;
|
|
834
|
+
}
|
|
835
|
+
function shouldEnableArbitraryValueFallbackByInputs(classNameSet, jsArbitraryValueFallback, tailwindcssMajorVersion) {
|
|
836
|
+
if (jsArbitraryValueFallback === true) {
|
|
837
|
+
return true;
|
|
838
|
+
}
|
|
839
|
+
if (jsArbitraryValueFallback === false) {
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
return tailwindcssMajorVersion === 4 && (!classNameSet || classNameSet.size === 0);
|
|
843
|
+
}
|
|
844
|
+
function shouldEnableArbitraryValueFallback({
|
|
845
|
+
classNameSet,
|
|
846
|
+
jsArbitraryValueFallback,
|
|
847
|
+
tailwindcssMajorVersion
|
|
848
|
+
}) {
|
|
849
|
+
return shouldEnableArbitraryValueFallbackByInputs(
|
|
850
|
+
classNameSet,
|
|
851
|
+
jsArbitraryValueFallback,
|
|
852
|
+
tailwindcssMajorVersion
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
var SKIP_RESULT = { decision: "skip" };
|
|
856
|
+
var DIRECT_RESULT = { decision: "direct" };
|
|
857
|
+
var FALLBACK_RESULT = { decision: "fallback" };
|
|
858
|
+
function getEscapedCandidateCacheStore(escapeMap) {
|
|
859
|
+
if (!escapeMap) {
|
|
860
|
+
return defaultEscapedCandidateCache;
|
|
861
|
+
}
|
|
862
|
+
if (escapeMap === lastEscapedCandidateEscapeMap && lastEscapedCandidateCacheStore) {
|
|
863
|
+
return lastEscapedCandidateCacheStore;
|
|
864
|
+
}
|
|
865
|
+
let store = escapedCandidateCacheByEscapeMap.get(escapeMap);
|
|
866
|
+
if (!store) {
|
|
867
|
+
store = /* @__PURE__ */ new Map();
|
|
868
|
+
escapedCandidateCacheByEscapeMap.set(escapeMap, store);
|
|
869
|
+
}
|
|
870
|
+
lastEscapedCandidateEscapeMap = escapeMap;
|
|
871
|
+
lastEscapedCandidateCacheStore = store;
|
|
872
|
+
return store;
|
|
873
|
+
}
|
|
874
|
+
function getEscapedCandidate(candidate, escapeMap, store = getEscapedCandidateCacheStore(escapeMap)) {
|
|
875
|
+
let cached = store.get(candidate);
|
|
876
|
+
if (cached === void 0) {
|
|
877
|
+
cached = replaceWxml(candidate, { escapeMap });
|
|
878
|
+
store.set(candidate, cached);
|
|
879
|
+
}
|
|
880
|
+
return cached;
|
|
881
|
+
}
|
|
882
|
+
function resolveClassNameTransformWithResult(candidate, {
|
|
883
|
+
alwaysEscape,
|
|
884
|
+
classNameSet,
|
|
885
|
+
escapeMap,
|
|
886
|
+
jsArbitraryValueFallback,
|
|
887
|
+
jsPreserveClass,
|
|
888
|
+
tailwindcssMajorVersion,
|
|
889
|
+
classContext
|
|
890
|
+
}) {
|
|
891
|
+
if (alwaysEscape) {
|
|
892
|
+
return DIRECT_RESULT;
|
|
893
|
+
}
|
|
894
|
+
if (jsPreserveClass?.(candidate)) {
|
|
895
|
+
return SKIP_RESULT;
|
|
896
|
+
}
|
|
897
|
+
if (classNameSet?.has(candidate)) {
|
|
898
|
+
return DIRECT_RESULT;
|
|
899
|
+
}
|
|
900
|
+
if (classNameSet && classNameSet.size > 0) {
|
|
901
|
+
const escapedCandidate = getEscapedCandidate(candidate, escapeMap);
|
|
902
|
+
if (escapedCandidate !== candidate && classNameSet.has(escapedCandidate)) {
|
|
903
|
+
return { decision: "escaped", escapedValue: escapedCandidate };
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (classContext && shouldEnableArbitraryValueFallbackByInputs(classNameSet, jsArbitraryValueFallback, tailwindcssMajorVersion) && isArbitraryValueCandidate(candidate)) {
|
|
907
|
+
return FALLBACK_RESULT;
|
|
908
|
+
}
|
|
909
|
+
return SKIP_RESULT;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// src/utils/decode.ts
|
|
913
|
+
var unicodeEscapeRE = /\\u([\dA-Fa-f]{4})/g;
|
|
914
|
+
var unicodeEscapeTestRE = /\\u[\dA-Fa-f]{4}/;
|
|
915
|
+
function decodeUnicode(value) {
|
|
916
|
+
if (!unicodeEscapeTestRE.test(value)) {
|
|
917
|
+
return value;
|
|
918
|
+
}
|
|
919
|
+
return value.replace(unicodeEscapeRE, (_match, hex) => {
|
|
920
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
921
|
+
return Number.isNaN(codePoint) ? _match : String.fromCharCode(codePoint);
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
function decodeUnicode2(input) {
|
|
925
|
+
if (!unicodeEscapeTestRE.test(input)) {
|
|
926
|
+
return input;
|
|
927
|
+
}
|
|
928
|
+
try {
|
|
929
|
+
return JSON.parse(`"${input}"`);
|
|
930
|
+
} catch (_error) {
|
|
931
|
+
return decodeUnicode(input);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// src/js/class-context.ts
|
|
936
|
+
var CLASS_LIKE_KEYWORDS = /* @__PURE__ */ new Set([
|
|
937
|
+
"class",
|
|
938
|
+
"classname",
|
|
939
|
+
"hoverclass",
|
|
940
|
+
"virtualhostclass",
|
|
941
|
+
"rootclass"
|
|
942
|
+
]);
|
|
943
|
+
var CLASS_HELPER_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
944
|
+
"cn",
|
|
945
|
+
"clsx",
|
|
946
|
+
"classnames",
|
|
947
|
+
"twmerge",
|
|
948
|
+
"cva",
|
|
949
|
+
"tv",
|
|
950
|
+
"cx",
|
|
951
|
+
"r"
|
|
952
|
+
]);
|
|
953
|
+
var DASH_CODE = 45;
|
|
954
|
+
var COLON_CODE = 58;
|
|
955
|
+
var UPPERCASE_A_CODE = 65;
|
|
956
|
+
var UPPERCASE_Z_CODE = 90;
|
|
957
|
+
var UNDERSCORE_CODE = 95;
|
|
958
|
+
var ASCII_MAX_CODE = 127;
|
|
959
|
+
var NORMALIZE_KEYWORD_REGEXP = /[-_:]/g;
|
|
960
|
+
function normalizeKeyword(name) {
|
|
961
|
+
const length = name.length;
|
|
962
|
+
let firstNormalizedIndex = -1;
|
|
963
|
+
for (let i = 0; i < length; i++) {
|
|
964
|
+
const code = name.charCodeAt(i);
|
|
965
|
+
if (code === DASH_CODE || code === UNDERSCORE_CODE || code === COLON_CODE || code >= UPPERCASE_A_CODE && code <= UPPERCASE_Z_CODE) {
|
|
966
|
+
firstNormalizedIndex = i;
|
|
967
|
+
break;
|
|
968
|
+
}
|
|
969
|
+
if (code > ASCII_MAX_CODE) {
|
|
970
|
+
return name.replace(NORMALIZE_KEYWORD_REGEXP, "").toLowerCase();
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
if (firstNormalizedIndex === -1) {
|
|
974
|
+
return name;
|
|
975
|
+
}
|
|
976
|
+
let normalized = name.slice(0, firstNormalizedIndex);
|
|
977
|
+
for (let i = firstNormalizedIndex; i < length; i++) {
|
|
978
|
+
const code = name.charCodeAt(i);
|
|
979
|
+
if (code === DASH_CODE || code === UNDERSCORE_CODE || code === COLON_CODE) {
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
982
|
+
if (code >= UPPERCASE_A_CODE && code <= UPPERCASE_Z_CODE) {
|
|
983
|
+
normalized += String.fromCharCode(code + 32);
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
if (code > ASCII_MAX_CODE) {
|
|
987
|
+
return name.replace(NORMALIZE_KEYWORD_REGEXP, "").toLowerCase();
|
|
988
|
+
}
|
|
989
|
+
normalized += name[i];
|
|
990
|
+
}
|
|
991
|
+
return normalized;
|
|
992
|
+
}
|
|
993
|
+
function readObjectKeyName(path22) {
|
|
994
|
+
if (path22.isIdentifier()) {
|
|
995
|
+
return path22.node.name;
|
|
996
|
+
}
|
|
997
|
+
if (path22.isStringLiteral()) {
|
|
998
|
+
return path22.node.value;
|
|
999
|
+
}
|
|
1000
|
+
if (path22.isTemplateLiteral() && path22.node.expressions.length === 0) {
|
|
1001
|
+
return path22.node.quasis[0]?.value.cooked ?? path22.node.quasis[0]?.value.raw;
|
|
1002
|
+
}
|
|
1003
|
+
return void 0;
|
|
1004
|
+
}
|
|
1005
|
+
function isClassLikeObjectProperty(path22, valuePath) {
|
|
1006
|
+
if (!path22.isObjectProperty()) {
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
if (path22.get("value") !== valuePath) {
|
|
1010
|
+
return false;
|
|
1011
|
+
}
|
|
1012
|
+
const keyName = readObjectKeyName(path22.get("key"));
|
|
1013
|
+
if (!keyName) {
|
|
1014
|
+
return false;
|
|
1015
|
+
}
|
|
1016
|
+
return CLASS_LIKE_KEYWORDS.has(normalizeKeyword(keyName));
|
|
1017
|
+
}
|
|
1018
|
+
function isClassLikeJsxAttribute(path22) {
|
|
1019
|
+
if (!path22.isJSXAttribute()) {
|
|
1020
|
+
return false;
|
|
1021
|
+
}
|
|
1022
|
+
const namePath = path22.get("name");
|
|
1023
|
+
if (!namePath.isJSXIdentifier()) {
|
|
1024
|
+
return false;
|
|
1025
|
+
}
|
|
1026
|
+
return CLASS_LIKE_KEYWORDS.has(normalizeKeyword(namePath.node.name));
|
|
1027
|
+
}
|
|
1028
|
+
function readCallHelperName(calleePath) {
|
|
1029
|
+
if (calleePath.isIdentifier()) {
|
|
1030
|
+
return calleePath.node.name;
|
|
1031
|
+
}
|
|
1032
|
+
if (calleePath.isMemberExpression()) {
|
|
1033
|
+
const propertyPath = calleePath.get("property");
|
|
1034
|
+
if (propertyPath.isIdentifier()) {
|
|
1035
|
+
return propertyPath.node.name;
|
|
1036
|
+
}
|
|
1037
|
+
if (propertyPath.isStringLiteral()) {
|
|
1038
|
+
return propertyPath.node.value;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return void 0;
|
|
1042
|
+
}
|
|
1043
|
+
function isClassLikeCallExpression(path22, valuePath) {
|
|
1044
|
+
if (!path22.isCallExpression()) {
|
|
1045
|
+
return false;
|
|
1046
|
+
}
|
|
1047
|
+
const helperName = readCallHelperName(path22.get("callee"));
|
|
1048
|
+
if (!helperName || !CLASS_HELPER_IDENTIFIERS.has(normalizeKeyword(helperName))) {
|
|
1049
|
+
return false;
|
|
1050
|
+
}
|
|
1051
|
+
return path22.get("arguments").some((argumentPath) => argumentPath.node === valuePath.node);
|
|
1052
|
+
}
|
|
1053
|
+
function isClassContextLiteralPath(path22) {
|
|
1054
|
+
let current = path22;
|
|
1055
|
+
while (current.parentPath) {
|
|
1056
|
+
const parent = current.parentPath;
|
|
1057
|
+
if (isClassLikeObjectProperty(parent, current)) {
|
|
1058
|
+
return true;
|
|
1059
|
+
}
|
|
1060
|
+
if (isClassLikeJsxAttribute(parent)) {
|
|
1061
|
+
return true;
|
|
1062
|
+
}
|
|
1063
|
+
if (isClassLikeCallExpression(parent, current)) {
|
|
1064
|
+
return true;
|
|
1065
|
+
}
|
|
1066
|
+
current = parent;
|
|
1067
|
+
}
|
|
1068
|
+
return false;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// src/js/handlers.ts
|
|
1072
|
+
var debug2 = createDebug("[js:handlers] ");
|
|
1073
|
+
var replacementCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
|
|
1074
|
+
var defaultReplacementCache = /* @__PURE__ */ new Map();
|
|
1075
|
+
var WEAPP_TW_IGNORE_MARKER = "weapp-tw";
|
|
1076
|
+
var IGNORE_MARKER = "ignore";
|
|
1077
|
+
function getReplacementCacheStore(escapeMap) {
|
|
1078
|
+
if (!escapeMap) {
|
|
1079
|
+
return defaultReplacementCache;
|
|
1080
|
+
}
|
|
1081
|
+
let store = replacementCacheByEscapeMap.get(escapeMap);
|
|
1082
|
+
if (!store) {
|
|
1083
|
+
store = /* @__PURE__ */ new Map();
|
|
1084
|
+
replacementCacheByEscapeMap.set(escapeMap, store);
|
|
1085
|
+
}
|
|
1086
|
+
return store;
|
|
1087
|
+
}
|
|
1088
|
+
function getReplacement(candidate, escapeMap, store = getReplacementCacheStore(escapeMap)) {
|
|
1089
|
+
let cached = store.get(candidate);
|
|
1090
|
+
if (cached === void 0) {
|
|
1091
|
+
cached = replaceWxml(candidate, { escapeMap });
|
|
1092
|
+
store.set(candidate, cached);
|
|
1093
|
+
}
|
|
1094
|
+
return cached;
|
|
1095
|
+
}
|
|
1096
|
+
function hasIgnoreComment(node) {
|
|
1097
|
+
const { leadingComments } = node;
|
|
1098
|
+
if (!Array.isArray(leadingComments) || leadingComments.length === 0) {
|
|
1099
|
+
return false;
|
|
1100
|
+
}
|
|
1101
|
+
for (const comment of leadingComments) {
|
|
1102
|
+
const { value } = comment;
|
|
1103
|
+
if (value.includes(WEAPP_TW_IGNORE_MARKER) && value.includes(IGNORE_MARKER)) {
|
|
1104
|
+
return true;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return false;
|
|
1108
|
+
}
|
|
1109
|
+
function extractLiteralValue(path22, { unescapeUnicode, arbitraryValues }) {
|
|
1110
|
+
const allowDoubleQuotes = arbitraryValues?.allowDoubleQuotes;
|
|
1111
|
+
const { node } = path22;
|
|
1112
|
+
let offset = 0;
|
|
1113
|
+
let original;
|
|
1114
|
+
if (node.type === "StringLiteral") {
|
|
1115
|
+
offset = 1;
|
|
1116
|
+
original = node.value;
|
|
1117
|
+
} else if (node.type === "TemplateElement") {
|
|
1118
|
+
original = node.value.raw;
|
|
1119
|
+
} else {
|
|
1120
|
+
original = "";
|
|
1121
|
+
}
|
|
1122
|
+
let literal = original;
|
|
1123
|
+
if (unescapeUnicode && original.includes("\\u")) {
|
|
1124
|
+
literal = decodeUnicode2(original);
|
|
1125
|
+
}
|
|
1126
|
+
return {
|
|
1127
|
+
allowDoubleQuotes,
|
|
1128
|
+
literal,
|
|
1129
|
+
offset,
|
|
1130
|
+
original
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
function createCandidatePlanResolver(options, classContext) {
|
|
1134
|
+
const { escapeMap } = options;
|
|
1135
|
+
const replacementCache = getReplacementCacheStore(escapeMap);
|
|
1136
|
+
const transformOptions = classContext ? {
|
|
1137
|
+
...options,
|
|
1138
|
+
classContext
|
|
1139
|
+
} : options;
|
|
1140
|
+
let firstCandidate = "";
|
|
1141
|
+
let firstPlan;
|
|
1142
|
+
let cache;
|
|
1143
|
+
const buildCandidatePlan = (candidate) => {
|
|
1144
|
+
const result = resolveClassNameTransformWithResult(candidate, transformOptions);
|
|
1145
|
+
if (result.decision === "skip") {
|
|
1146
|
+
return { result };
|
|
1147
|
+
}
|
|
1148
|
+
let replacement;
|
|
1149
|
+
if (result.decision === "escaped" && result.escapedValue) {
|
|
1150
|
+
replacement = result.escapedValue;
|
|
1151
|
+
replacementCache.set(candidate, replacement);
|
|
1152
|
+
} else {
|
|
1153
|
+
replacement = getReplacement(candidate, escapeMap, replacementCache);
|
|
1154
|
+
}
|
|
1155
|
+
return {
|
|
1156
|
+
result,
|
|
1157
|
+
replacement
|
|
1158
|
+
};
|
|
1159
|
+
};
|
|
1160
|
+
return (candidate) => {
|
|
1161
|
+
if (cache) {
|
|
1162
|
+
const cached = cache.get(candidate);
|
|
1163
|
+
if (cached) {
|
|
1164
|
+
return cached;
|
|
1165
|
+
}
|
|
1166
|
+
} else if (firstPlan && candidate === firstCandidate) {
|
|
1167
|
+
return firstPlan;
|
|
1168
|
+
}
|
|
1169
|
+
const plan = buildCandidatePlan(candidate);
|
|
1170
|
+
if (!firstPlan) {
|
|
1171
|
+
firstCandidate = candidate;
|
|
1172
|
+
firstPlan = plan;
|
|
1173
|
+
return plan;
|
|
1174
|
+
}
|
|
1175
|
+
if (!cache) {
|
|
1176
|
+
cache = /* @__PURE__ */ new Map();
|
|
1177
|
+
cache.set(firstCandidate, firstPlan);
|
|
1178
|
+
}
|
|
1179
|
+
cache.set(candidate, plan);
|
|
1180
|
+
return plan;
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
function replaceHandleValue(path22, options) {
|
|
1184
|
+
const { needEscaped = false } = options;
|
|
1185
|
+
const { classNameSet, alwaysEscape } = options;
|
|
1186
|
+
const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
|
|
1187
|
+
if (!alwaysEscape && !fallbackEnabled && (!classNameSet || classNameSet.size === 0)) {
|
|
1188
|
+
return void 0;
|
|
1189
|
+
}
|
|
1190
|
+
if (hasIgnoreComment(path22.node)) {
|
|
1191
|
+
return void 0;
|
|
1192
|
+
}
|
|
1193
|
+
const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path22, options);
|
|
1194
|
+
const candidates = (0, import_extractors.splitCode)(literal, allowDoubleQuotes);
|
|
1195
|
+
if (candidates.length === 0) {
|
|
1196
|
+
return void 0;
|
|
1197
|
+
}
|
|
1198
|
+
const debugEnabled = debug2.enabled;
|
|
1199
|
+
const classContext = options.wrapExpression || isClassContextLiteralPath(path22);
|
|
1200
|
+
let transformed = literal;
|
|
1201
|
+
let mutated = false;
|
|
1202
|
+
let matchedCandidateCount = 0;
|
|
1203
|
+
let escapedDecisionCount = 0;
|
|
1204
|
+
let fallbackDecisionCount = 0;
|
|
1205
|
+
let escapedSamples;
|
|
1206
|
+
let skippedSamples;
|
|
1207
|
+
const resolveCandidatePlan = createCandidatePlanResolver(options, classContext);
|
|
1208
|
+
for (const candidate of candidates) {
|
|
1209
|
+
const plan = resolveCandidatePlan(candidate);
|
|
1210
|
+
if (plan.result.decision === "skip") {
|
|
1211
|
+
if (debugEnabled) {
|
|
1212
|
+
if (!skippedSamples) {
|
|
1213
|
+
skippedSamples = [];
|
|
1214
|
+
}
|
|
1215
|
+
if (skippedSamples.length < 6) {
|
|
1216
|
+
skippedSamples.push(candidate);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
if (debugEnabled) {
|
|
1222
|
+
matchedCandidateCount += 1;
|
|
1223
|
+
if (plan.result.decision === "escaped") {
|
|
1224
|
+
escapedDecisionCount += 1;
|
|
1225
|
+
if (!escapedSamples) {
|
|
1226
|
+
escapedSamples = [];
|
|
1227
|
+
}
|
|
1228
|
+
if (escapedSamples.length < 6) {
|
|
1229
|
+
escapedSamples.push(candidate);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
if (plan.result.decision === "fallback") {
|
|
1233
|
+
fallbackDecisionCount += 1;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
const replaced = transformed.replace(candidate, plan.replacement);
|
|
1237
|
+
if (replaced !== transformed) {
|
|
1238
|
+
transformed = replaced;
|
|
1239
|
+
mutated = true;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
const node = path22.node;
|
|
1243
|
+
if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
|
|
1244
|
+
return void 0;
|
|
1245
|
+
}
|
|
1246
|
+
if (debugEnabled) {
|
|
1247
|
+
debug2(
|
|
1248
|
+
"runtimeSet size=%d fallbackTriggered=%s candidates=%d matched=%d escapedHits=%d skipped=%d file=%s escapedSamples=%s skippedSamples=%s",
|
|
1249
|
+
classNameSet?.size ?? 0,
|
|
1250
|
+
fallbackDecisionCount > 0,
|
|
1251
|
+
candidates.length,
|
|
1252
|
+
matchedCandidateCount,
|
|
1253
|
+
escapedDecisionCount,
|
|
1254
|
+
skippedSamples?.length ?? 0,
|
|
1255
|
+
options.filename ?? "unknown",
|
|
1256
|
+
escapedSamples?.join(",") || "-",
|
|
1257
|
+
skippedSamples?.join(",") || "-"
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
const start = node.start + offset;
|
|
1261
|
+
const end = node.end - offset;
|
|
1262
|
+
if (start >= end || transformed === original) {
|
|
1263
|
+
return void 0;
|
|
1264
|
+
}
|
|
1265
|
+
const value = needEscaped ? (0, import_escape3.jsStringEscape)(transformed) : transformed;
|
|
1266
|
+
return {
|
|
1267
|
+
start,
|
|
1268
|
+
end,
|
|
1269
|
+
value,
|
|
1270
|
+
path: path22
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
// src/js/sourceAnalysis.ts
|
|
1275
|
+
function hasReplacementEntries(replacements) {
|
|
1276
|
+
for (const key in replacements) {
|
|
1277
|
+
if (Object.hasOwn(replacements, key)) {
|
|
1278
|
+
return true;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
return false;
|
|
1282
|
+
}
|
|
1283
|
+
function createModuleSpecifierReplacementToken(path22, replacement) {
|
|
1284
|
+
const node = path22.node;
|
|
1285
|
+
if (node.value === replacement) {
|
|
1286
|
+
return void 0;
|
|
1287
|
+
}
|
|
1288
|
+
if (typeof node.start !== "number" || typeof node.end !== "number") {
|
|
1289
|
+
return void 0;
|
|
1290
|
+
}
|
|
1291
|
+
const start = node.start + 1;
|
|
1292
|
+
const end = node.end - 1;
|
|
1293
|
+
if (start >= end) {
|
|
1294
|
+
return void 0;
|
|
1295
|
+
}
|
|
1296
|
+
return {
|
|
1297
|
+
start,
|
|
1298
|
+
end,
|
|
1299
|
+
value: replacement,
|
|
1300
|
+
path: path22
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
function collectModuleSpecifierReplacementTokens(analysis, replacements) {
|
|
1304
|
+
if (!hasReplacementEntries(replacements)) {
|
|
1305
|
+
return [];
|
|
1306
|
+
}
|
|
1307
|
+
if (analysis.importDeclarations.size === 0 && analysis.exportDeclarations.size === 0 && analysis.requireCallPaths.length === 0 && analysis.walker.imports.size === 0) {
|
|
1308
|
+
return [];
|
|
1309
|
+
}
|
|
1310
|
+
const tokens = [];
|
|
1311
|
+
const applyReplacement = (path22) => {
|
|
1312
|
+
const replacement = replacements[path22.node.value];
|
|
1313
|
+
if (!replacement) {
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
const token = createModuleSpecifierReplacementToken(path22, replacement);
|
|
1317
|
+
if (token) {
|
|
1318
|
+
tokens.push(token);
|
|
1319
|
+
}
|
|
1320
|
+
};
|
|
1321
|
+
for (const importPath of analysis.importDeclarations) {
|
|
1322
|
+
const source = importPath.get("source");
|
|
1323
|
+
if (source.isStringLiteral()) {
|
|
1324
|
+
applyReplacement(source);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
for (const exportPath of analysis.exportDeclarations) {
|
|
1328
|
+
if (exportPath.isExportNamedDeclaration() || exportPath.isExportAllDeclaration()) {
|
|
1329
|
+
const source = exportPath.get("source");
|
|
1330
|
+
if (source && !Array.isArray(source) && source.isStringLiteral()) {
|
|
1331
|
+
applyReplacement(source);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
for (const literalPath of analysis.requireCallPaths) {
|
|
1336
|
+
applyReplacement(literalPath);
|
|
1337
|
+
}
|
|
1338
|
+
for (const token of analysis.walker.imports) {
|
|
1339
|
+
const replacement = replacements[token.source];
|
|
1340
|
+
if (replacement) {
|
|
1341
|
+
token.source = replacement;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
return tokens;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
// src/js/babel/process.ts
|
|
1348
|
+
var optionVariantsCache = /* @__PURE__ */ new WeakMap();
|
|
1349
|
+
function getNeedEscapedOptions(options, needEscaped) {
|
|
1350
|
+
if (options.needEscaped === needEscaped) {
|
|
1351
|
+
return options;
|
|
1352
|
+
}
|
|
1353
|
+
let cached = optionVariantsCache.get(options);
|
|
1354
|
+
if (!cached) {
|
|
1355
|
+
cached = {};
|
|
1356
|
+
optionVariantsCache.set(options, cached);
|
|
1357
|
+
}
|
|
1358
|
+
if (needEscaped) {
|
|
1359
|
+
if (!cached.stringLiteralOptions) {
|
|
1360
|
+
cached.stringLiteralOptions = {
|
|
1361
|
+
...options,
|
|
1362
|
+
needEscaped: true
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
return cached.stringLiteralOptions;
|
|
1366
|
+
}
|
|
1367
|
+
if (!cached.templateLiteralOptions) {
|
|
1368
|
+
cached.templateLiteralOptions = {
|
|
1369
|
+
...options,
|
|
1370
|
+
needEscaped: false
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
return cached.templateLiteralOptions;
|
|
1374
|
+
}
|
|
1375
|
+
function processUpdatedSource(rawSource, options, analysis) {
|
|
1376
|
+
const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
|
|
1377
|
+
if (targetPaths.length === 0 && !options.moduleSpecifierReplacements && jsTokenUpdater.length === 0) {
|
|
1378
|
+
return new import_magic_string.default(rawSource);
|
|
1379
|
+
}
|
|
1380
|
+
const replacementTokens = [];
|
|
1381
|
+
for (const path22 of targetPaths) {
|
|
1382
|
+
if (ignoredPaths.has(path22)) {
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
const token = replaceHandleValue(
|
|
1386
|
+
path22,
|
|
1387
|
+
path22.isStringLiteral() ? getNeedEscapedOptions(options, true) : getNeedEscapedOptions(options, false)
|
|
1388
|
+
);
|
|
1389
|
+
if (token) {
|
|
1390
|
+
replacementTokens.push(token);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
if (options.moduleSpecifierReplacements) {
|
|
1394
|
+
replacementTokens.push(
|
|
1395
|
+
...collectModuleSpecifierReplacementTokens(analysis, options.moduleSpecifierReplacements)
|
|
1396
|
+
);
|
|
1397
|
+
}
|
|
1398
|
+
if (jsTokenUpdater.length + replacementTokens.length === 0) {
|
|
1399
|
+
return new import_magic_string.default(rawSource);
|
|
1400
|
+
}
|
|
1401
|
+
const ms = new import_magic_string.default(rawSource);
|
|
1402
|
+
jsTokenUpdater.push(...replacementTokens).filter((token) => !ignoredPaths.has(token.path)).updateMagicString(ms);
|
|
1403
|
+
return ms;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// src/js/evalTransforms.ts
|
|
1407
|
+
var import_escape4 = require("@ast-core/escape");
|
|
1408
|
+
var evalHandlerOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
1409
|
+
var EVAL_SCOPE_ERROR_REGEXP = /pass a scope and parentPath|traversing a Program\/File/i;
|
|
1410
|
+
function isEvalPath(path22) {
|
|
1411
|
+
if (path22.isCallExpression()) {
|
|
1412
|
+
const calleePath = path22.get("callee");
|
|
1413
|
+
return calleePath.isIdentifier({ name: "eval" });
|
|
1414
|
+
}
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
function createEvalReplacementToken(path22, updated) {
|
|
1418
|
+
const node = path22.node;
|
|
1419
|
+
let offset = 0;
|
|
1420
|
+
let original;
|
|
1421
|
+
if (path22.isStringLiteral()) {
|
|
1422
|
+
offset = 1;
|
|
1423
|
+
original = path22.node.value;
|
|
1424
|
+
} else if (path22.isTemplateElement()) {
|
|
1425
|
+
original = path22.node.value.raw;
|
|
1426
|
+
} else {
|
|
1427
|
+
original = "";
|
|
1428
|
+
}
|
|
1429
|
+
if (typeof node.start !== "number" || typeof node.end !== "number") {
|
|
1430
|
+
return void 0;
|
|
1431
|
+
}
|
|
1432
|
+
const start = node.start + offset;
|
|
1433
|
+
const end = node.end - offset;
|
|
1434
|
+
if (start >= end) {
|
|
1435
|
+
return void 0;
|
|
1436
|
+
}
|
|
1437
|
+
if (original === updated) {
|
|
1438
|
+
return void 0;
|
|
1439
|
+
}
|
|
1440
|
+
const value = path22.isStringLiteral() ? (0, import_escape4.jsStringEscape)(updated) : updated;
|
|
1441
|
+
return {
|
|
1442
|
+
start,
|
|
1443
|
+
end,
|
|
1444
|
+
value,
|
|
1445
|
+
path: path22
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
function handleEvalStringLiteral(path22, handlerOptions, updater, handler) {
|
|
1449
|
+
const { code } = handler(path22.node.value, handlerOptions);
|
|
1450
|
+
if (!code) {
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
const token = createEvalReplacementToken(path22, code);
|
|
1454
|
+
if (token) {
|
|
1455
|
+
updater.addToken(token);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
function handleEvalTemplateElement(path22, handlerOptions, updater, handler) {
|
|
1459
|
+
const { code } = handler(path22.node.value.raw, handlerOptions);
|
|
1460
|
+
if (!code) {
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
const token = createEvalReplacementToken(path22, code);
|
|
1464
|
+
if (token) {
|
|
1465
|
+
updater.addToken(token);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
function getEvalStringHandlerOptions(options) {
|
|
1469
|
+
if (options.needEscaped === false && options.generateMap === false) {
|
|
1470
|
+
return options;
|
|
1471
|
+
}
|
|
1472
|
+
let cached = evalHandlerOptionsCache.get(options);
|
|
1473
|
+
if (!cached) {
|
|
1474
|
+
cached = {};
|
|
1475
|
+
evalHandlerOptionsCache.set(options, cached);
|
|
1476
|
+
}
|
|
1477
|
+
if (!cached.stringLiteralOptions) {
|
|
1478
|
+
cached.stringLiteralOptions = {
|
|
1479
|
+
...options,
|
|
1480
|
+
needEscaped: false,
|
|
1481
|
+
generateMap: false
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
return cached.stringLiteralOptions;
|
|
1485
|
+
}
|
|
1486
|
+
function getEvalTemplateHandlerOptions(options) {
|
|
1487
|
+
if (options.generateMap === false) {
|
|
1488
|
+
return options;
|
|
1489
|
+
}
|
|
1490
|
+
let cached = evalHandlerOptionsCache.get(options);
|
|
1491
|
+
if (!cached) {
|
|
1492
|
+
cached = {};
|
|
1493
|
+
evalHandlerOptionsCache.set(options, cached);
|
|
1494
|
+
}
|
|
1495
|
+
if (!cached.templateLiteralOptions) {
|
|
1496
|
+
cached.templateLiteralOptions = {
|
|
1497
|
+
...options,
|
|
1498
|
+
generateMap: false
|
|
1499
|
+
};
|
|
1500
|
+
}
|
|
1501
|
+
return cached.templateLiteralOptions;
|
|
1502
|
+
}
|
|
1503
|
+
function walkEvalExpression(path22, options, updater, handler) {
|
|
1504
|
+
const stringHandlerOptions = getEvalStringHandlerOptions(options);
|
|
1505
|
+
const templateHandlerOptions = getEvalTemplateHandlerOptions(options);
|
|
1506
|
+
const maybeTraverse = path22?.traverse;
|
|
1507
|
+
if (typeof maybeTraverse === "function") {
|
|
1508
|
+
try {
|
|
1509
|
+
return maybeTraverse.call(path22, {
|
|
1510
|
+
StringLiteral(innerPath) {
|
|
1511
|
+
handleEvalStringLiteral(innerPath, stringHandlerOptions, updater, handler);
|
|
1512
|
+
},
|
|
1513
|
+
TemplateElement(innerPath) {
|
|
1514
|
+
handleEvalTemplateElement(innerPath, templateHandlerOptions, updater, handler);
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
} catch (error) {
|
|
1518
|
+
const msg = error?.message ?? "";
|
|
1519
|
+
const scopeError = EVAL_SCOPE_ERROR_REGEXP.test(msg);
|
|
1520
|
+
if (!scopeError) {
|
|
1521
|
+
throw error;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
const getArgs = path22?.get?.("arguments");
|
|
1526
|
+
if (Array.isArray(getArgs)) {
|
|
1527
|
+
for (const arg of getArgs) {
|
|
1528
|
+
if (arg?.isStringLiteral?.()) {
|
|
1529
|
+
handleEvalStringLiteral(arg, stringHandlerOptions, updater, handler);
|
|
1530
|
+
continue;
|
|
1531
|
+
}
|
|
1532
|
+
if (arg?.isTemplateLiteral?.()) {
|
|
1533
|
+
for (const quasi of arg.get("quasis")) {
|
|
1534
|
+
handleEvalTemplateElement(quasi, templateHandlerOptions, updater, handler);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
const nodeArgs = path22?.node?.arguments;
|
|
1541
|
+
if (Array.isArray(nodeArgs)) {
|
|
1542
|
+
for (const n of nodeArgs) {
|
|
1543
|
+
if (n?.type === "StringLiteral") {
|
|
1544
|
+
const stub = {
|
|
1545
|
+
node: n,
|
|
1546
|
+
isStringLiteral: () => true
|
|
1547
|
+
};
|
|
1548
|
+
handleEvalStringLiteral(stub, stringHandlerOptions, updater, handler);
|
|
1549
|
+
} else if (n?.type === "TemplateLiteral" && Array.isArray(n.quasis)) {
|
|
1550
|
+
for (const q of n.quasis) {
|
|
1551
|
+
const stub = {
|
|
1552
|
+
node: q,
|
|
1553
|
+
isStringLiteral: () => false,
|
|
1554
|
+
isTemplateElement: () => true
|
|
1555
|
+
};
|
|
1556
|
+
handleEvalTemplateElement(stub, templateHandlerOptions, updater, handler);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
// src/js/JsTokenUpdater.ts
|
|
1564
|
+
var JsTokenUpdater = class {
|
|
1565
|
+
constructor({ value } = {}) {
|
|
1566
|
+
this.tokens = value ? [...value] : [];
|
|
1567
|
+
}
|
|
1568
|
+
addToken(token) {
|
|
1569
|
+
if (token) {
|
|
1570
|
+
this.tokens.push(token);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
push(...args) {
|
|
1574
|
+
this.tokens.push(...args);
|
|
1575
|
+
return this;
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* 待写入的 token 数量。
|
|
1579
|
+
*/
|
|
1580
|
+
get length() {
|
|
1581
|
+
return this.tokens.length;
|
|
1582
|
+
}
|
|
1583
|
+
map(callbackfn) {
|
|
1584
|
+
this.tokens = this.tokens.map(callbackfn);
|
|
1585
|
+
return this;
|
|
1586
|
+
}
|
|
1587
|
+
filter(callbackfn) {
|
|
1588
|
+
this.tokens = this.tokens.filter(callbackfn);
|
|
1589
|
+
return this;
|
|
1590
|
+
}
|
|
1591
|
+
updateMagicString(ms) {
|
|
1592
|
+
for (const { start, end, value } of this.tokens) {
|
|
1593
|
+
ms.update(start, end, value);
|
|
1594
|
+
}
|
|
1595
|
+
return ms;
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
// src/js/module-graph/ignored-exports.ts
|
|
1600
|
+
var IgnoredExportsTracker = class {
|
|
1601
|
+
constructor(options) {
|
|
1602
|
+
this.options = options;
|
|
1603
|
+
this.ignoredExportNames = /* @__PURE__ */ new Map();
|
|
1604
|
+
}
|
|
1605
|
+
addIgnoredExport(filename, exportName) {
|
|
1606
|
+
if (!exportName) {
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
let pending = this.ignoredExportNames.get(filename);
|
|
1610
|
+
if (!pending) {
|
|
1611
|
+
pending = /* @__PURE__ */ new Set();
|
|
1612
|
+
this.ignoredExportNames.set(filename, pending);
|
|
1613
|
+
}
|
|
1614
|
+
if (pending.has(exportName)) {
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1617
|
+
pending.add(exportName);
|
|
1618
|
+
const existing = this.options.modules.get(filename);
|
|
1619
|
+
if (existing) {
|
|
1620
|
+
this.applyIgnoredExportsToAnalysis(filename, existing.analysis);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
registerIgnoredExportsFromTokens(resolved, tokens) {
|
|
1624
|
+
for (const token of tokens) {
|
|
1625
|
+
if (token.type === "ImportSpecifier") {
|
|
1626
|
+
this.addIgnoredExport(resolved, token.imported);
|
|
1627
|
+
} else if (token.type === "ImportDefaultSpecifier") {
|
|
1628
|
+
this.addIgnoredExport(resolved, "default");
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
applyIgnoredExportsToAnalysis(filename, analysis) {
|
|
1633
|
+
const pending = this.ignoredExportNames.get(filename);
|
|
1634
|
+
if (!pending || pending.size === 0) {
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const names = new Set(pending);
|
|
1638
|
+
pending.clear();
|
|
1639
|
+
const propagate = [];
|
|
1640
|
+
for (const exportPath of analysis.exportDeclarations) {
|
|
1641
|
+
if (names.size === 0) {
|
|
1642
|
+
break;
|
|
1643
|
+
}
|
|
1644
|
+
if (exportPath.isExportDefaultDeclaration()) {
|
|
1645
|
+
if (names.has("default")) {
|
|
1646
|
+
analysis.walker.walkExportDefaultDeclaration(exportPath);
|
|
1647
|
+
names.delete("default");
|
|
1648
|
+
}
|
|
1649
|
+
continue;
|
|
1650
|
+
}
|
|
1651
|
+
if (exportPath.isExportNamedDeclaration()) {
|
|
1652
|
+
const source = exportPath.node.source?.value;
|
|
1653
|
+
if (typeof source === "string") {
|
|
1654
|
+
for (const spec of exportPath.get("specifiers")) {
|
|
1655
|
+
if (!spec.isExportSpecifier()) {
|
|
1656
|
+
continue;
|
|
1657
|
+
}
|
|
1658
|
+
const exported = spec.get("exported");
|
|
1659
|
+
let exportedName;
|
|
1660
|
+
if (exported.isIdentifier()) {
|
|
1661
|
+
exportedName = exported.node.name;
|
|
1662
|
+
} else if (exported.isStringLiteral()) {
|
|
1663
|
+
exportedName = exported.node.value;
|
|
1664
|
+
}
|
|
1665
|
+
if (!exportedName || !names.has(exportedName)) {
|
|
1666
|
+
continue;
|
|
1667
|
+
}
|
|
1668
|
+
const local = spec.get("local");
|
|
1669
|
+
if (local.isIdentifier()) {
|
|
1670
|
+
propagate.push({
|
|
1671
|
+
specifier: source,
|
|
1672
|
+
exportName: local.node.name
|
|
1673
|
+
});
|
|
1674
|
+
names.delete(exportedName);
|
|
1675
|
+
} else if (local.isStringLiteral()) {
|
|
1676
|
+
propagate.push({
|
|
1677
|
+
specifier: source,
|
|
1678
|
+
exportName: local.node.value
|
|
1679
|
+
});
|
|
1680
|
+
names.delete(exportedName);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
continue;
|
|
1684
|
+
}
|
|
1685
|
+
const declaration = exportPath.get("declaration");
|
|
1686
|
+
if (declaration.isVariableDeclaration()) {
|
|
1687
|
+
for (const decl of declaration.get("declarations")) {
|
|
1688
|
+
const id = decl.get("id");
|
|
1689
|
+
if (id.isIdentifier()) {
|
|
1690
|
+
const exportName = id.node.name;
|
|
1691
|
+
if (names.has(exportName)) {
|
|
1692
|
+
analysis.walker.walkVariableDeclarator(decl);
|
|
1693
|
+
names.delete(exportName);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
for (const spec of exportPath.get("specifiers")) {
|
|
1699
|
+
if (!spec.isExportSpecifier()) {
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
const exported = spec.get("exported");
|
|
1703
|
+
let exportedName;
|
|
1704
|
+
if (exported.isIdentifier()) {
|
|
1705
|
+
exportedName = exported.node.name;
|
|
1706
|
+
} else if (exported.isStringLiteral()) {
|
|
1707
|
+
exportedName = exported.node.value;
|
|
1708
|
+
}
|
|
1709
|
+
if (!exportedName || !names.has(exportedName)) {
|
|
1710
|
+
continue;
|
|
1711
|
+
}
|
|
1712
|
+
const local = spec.get("local");
|
|
1713
|
+
analysis.walker.walkNode(local);
|
|
1714
|
+
names.delete(exportedName);
|
|
1715
|
+
}
|
|
1716
|
+
continue;
|
|
1717
|
+
}
|
|
1718
|
+
if (exportPath.isExportAllDeclaration()) {
|
|
1719
|
+
const source = exportPath.node.source?.value;
|
|
1720
|
+
if (typeof source === "string") {
|
|
1721
|
+
for (const exportName of names) {
|
|
1722
|
+
propagate.push({
|
|
1723
|
+
specifier: source,
|
|
1724
|
+
exportName
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
names.clear();
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
for (const { specifier, exportName } of propagate) {
|
|
1732
|
+
let resolved;
|
|
1733
|
+
try {
|
|
1734
|
+
resolved = this.options.resolve(specifier, filename);
|
|
1735
|
+
} catch {
|
|
1736
|
+
resolved = void 0;
|
|
1737
|
+
}
|
|
1738
|
+
if (!resolved) {
|
|
1739
|
+
pending.add(exportName);
|
|
1740
|
+
continue;
|
|
1741
|
+
}
|
|
1742
|
+
if (this.options.filter && !this.options.filter(resolved, specifier, filename)) {
|
|
1743
|
+
pending.add(exportName);
|
|
1744
|
+
continue;
|
|
1745
|
+
}
|
|
1746
|
+
this.addIgnoredExport(resolved, exportName);
|
|
1747
|
+
}
|
|
1748
|
+
for (const name of names) {
|
|
1749
|
+
pending.add(name);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
|
|
1754
|
+
// src/js/ModuleGraph.ts
|
|
1755
|
+
var JsModuleGraph = class {
|
|
1756
|
+
constructor(entry, graphOptions) {
|
|
1757
|
+
this.modules = /* @__PURE__ */ new Map();
|
|
1758
|
+
this.queue = [];
|
|
1759
|
+
this.resolve = graphOptions.resolve;
|
|
1760
|
+
this.load = graphOptions.load;
|
|
1761
|
+
this.filter = graphOptions.filter;
|
|
1762
|
+
this.maxDepth = graphOptions.maxDepth ?? Number.POSITIVE_INFINITY;
|
|
1763
|
+
const { moduleGraph: _moduleGraph, filename: _ignoredFilename, ...rest } = entry.handlerOptions;
|
|
1764
|
+
this.baseOptions = {
|
|
1765
|
+
...rest,
|
|
1766
|
+
filename: entry.filename
|
|
1767
|
+
};
|
|
1768
|
+
this.parserOptions = entry.handlerOptions.babelParserOptions;
|
|
1769
|
+
this.rootFilename = entry.filename;
|
|
1770
|
+
this.ignoredExports = new IgnoredExportsTracker({
|
|
1771
|
+
resolve: this.resolve,
|
|
1772
|
+
filter: this.filter,
|
|
1773
|
+
modules: this.modules
|
|
1774
|
+
});
|
|
1775
|
+
this.modules.set(entry.filename, {
|
|
1776
|
+
filename: entry.filename,
|
|
1777
|
+
source: entry.source,
|
|
1778
|
+
analysis: entry.analysis
|
|
1779
|
+
});
|
|
1780
|
+
this.queue.push({ filename: entry.filename, depth: 0 });
|
|
1781
|
+
}
|
|
1782
|
+
build() {
|
|
1783
|
+
this.collectDependencies();
|
|
1784
|
+
let linked;
|
|
1785
|
+
for (const [filename, state] of this.modules) {
|
|
1786
|
+
if (filename === this.rootFilename) {
|
|
1787
|
+
continue;
|
|
1788
|
+
}
|
|
1789
|
+
const childOptions = {
|
|
1790
|
+
...this.baseOptions,
|
|
1791
|
+
filename
|
|
1792
|
+
};
|
|
1793
|
+
const ms = processUpdatedSource(state.source, childOptions, state.analysis);
|
|
1794
|
+
const code = ms.toString();
|
|
1795
|
+
if (code !== state.source) {
|
|
1796
|
+
if (!linked) {
|
|
1797
|
+
linked = {};
|
|
1798
|
+
}
|
|
1799
|
+
linked[filename] = { code };
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
return linked;
|
|
1803
|
+
}
|
|
1804
|
+
collectDependencies() {
|
|
1805
|
+
while (this.queue.length > 0) {
|
|
1806
|
+
const { filename, depth } = this.queue.shift();
|
|
1807
|
+
if (depth >= this.maxDepth) {
|
|
1808
|
+
continue;
|
|
1809
|
+
}
|
|
1810
|
+
const state = this.modules.get(filename);
|
|
1811
|
+
if (!state) {
|
|
1812
|
+
continue;
|
|
1813
|
+
}
|
|
1814
|
+
const dependencySpecifiers = /* @__PURE__ */ new Map();
|
|
1815
|
+
for (const token of state.analysis.walker.imports) {
|
|
1816
|
+
if (!dependencySpecifiers.has(token.source)) {
|
|
1817
|
+
dependencySpecifiers.set(token.source, []);
|
|
1818
|
+
}
|
|
1819
|
+
dependencySpecifiers.get(token.source).push(token);
|
|
1820
|
+
}
|
|
1821
|
+
for (const exportPath of state.analysis.exportDeclarations) {
|
|
1822
|
+
if (exportPath.isExportAllDeclaration() || exportPath.isExportNamedDeclaration()) {
|
|
1823
|
+
const source = exportPath.node.source?.value;
|
|
1824
|
+
if (typeof source === "string" && !dependencySpecifiers.has(source)) {
|
|
1825
|
+
dependencySpecifiers.set(source, []);
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
for (const [specifier, tokens] of dependencySpecifiers) {
|
|
1830
|
+
let resolved;
|
|
1831
|
+
try {
|
|
1832
|
+
resolved = this.resolve(specifier, filename);
|
|
1833
|
+
} catch {
|
|
1834
|
+
continue;
|
|
1835
|
+
}
|
|
1836
|
+
if (!resolved) {
|
|
1837
|
+
continue;
|
|
1838
|
+
}
|
|
1839
|
+
if (this.filter && !this.filter(resolved, specifier, filename)) {
|
|
1840
|
+
continue;
|
|
1841
|
+
}
|
|
1842
|
+
if (tokens.length > 0) {
|
|
1843
|
+
this.ignoredExports.registerIgnoredExportsFromTokens(resolved, tokens);
|
|
1844
|
+
}
|
|
1845
|
+
if (this.modules.has(resolved)) {
|
|
1846
|
+
continue;
|
|
1847
|
+
}
|
|
1848
|
+
let source;
|
|
1849
|
+
try {
|
|
1850
|
+
source = this.load(resolved);
|
|
1851
|
+
} catch {
|
|
1852
|
+
continue;
|
|
1853
|
+
}
|
|
1854
|
+
if (typeof source !== "string") {
|
|
1855
|
+
continue;
|
|
1856
|
+
}
|
|
1857
|
+
let analysis;
|
|
1858
|
+
try {
|
|
1859
|
+
const ast = babelParse(source, {
|
|
1860
|
+
...this.parserOptions,
|
|
1861
|
+
sourceFilename: resolved
|
|
1862
|
+
});
|
|
1863
|
+
analysis = analyzeSource(ast, {
|
|
1864
|
+
...this.baseOptions,
|
|
1865
|
+
filename: resolved
|
|
1866
|
+
});
|
|
1867
|
+
this.ignoredExports.applyIgnoredExportsToAnalysis(resolved, analysis);
|
|
1868
|
+
} catch {
|
|
1869
|
+
continue;
|
|
1870
|
+
}
|
|
1871
|
+
this.modules.set(resolved, {
|
|
1872
|
+
filename: resolved,
|
|
1873
|
+
source,
|
|
1874
|
+
analysis
|
|
1875
|
+
});
|
|
1876
|
+
this.queue.push({ filename: resolved, depth: depth + 1 });
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
};
|
|
1881
|
+
|
|
1882
|
+
// src/js/node-path-walker/export-handlers.ts
|
|
1883
|
+
function walkExportDeclaration(ctx, path22) {
|
|
1884
|
+
if (path22.isExportDeclaration()) {
|
|
1885
|
+
if (path22.isExportNamedDeclaration()) {
|
|
1886
|
+
walkExportNamedDeclaration(ctx, path22);
|
|
1887
|
+
} else if (path22.isExportDefaultDeclaration()) {
|
|
1888
|
+
walkExportDefaultDeclaration(ctx, path22);
|
|
1889
|
+
} else if (path22.isExportAllDeclaration()) {
|
|
1890
|
+
walkExportAllDeclaration(ctx, path22);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
function walkExportNamedDeclaration(ctx, path22) {
|
|
1895
|
+
const declaration = path22.get("declaration");
|
|
1896
|
+
if (declaration.isVariableDeclaration()) {
|
|
1897
|
+
for (const decl of declaration.get("declarations")) {
|
|
1898
|
+
ctx.walkNode(decl);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
const specifiers = path22.get("specifiers");
|
|
1902
|
+
for (const spec of specifiers) {
|
|
1903
|
+
if (spec.isExportSpecifier()) {
|
|
1904
|
+
const local = spec.get("local");
|
|
1905
|
+
if (local.isIdentifier()) {
|
|
1906
|
+
ctx.walkNode(local);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
function walkExportDefaultDeclaration(ctx, path22) {
|
|
1912
|
+
const decl = path22.get("declaration");
|
|
1913
|
+
if (decl.isIdentifier()) {
|
|
1914
|
+
ctx.walkNode(decl);
|
|
1915
|
+
} else {
|
|
1916
|
+
ctx.walkNode(decl);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
function walkExportAllDeclaration(ctx, path22) {
|
|
1920
|
+
const source = path22.get("source");
|
|
1921
|
+
if (source.isStringLiteral()) {
|
|
1922
|
+
ctx.addImportToken(
|
|
1923
|
+
{
|
|
1924
|
+
declaration: path22,
|
|
1925
|
+
source: source.node.value,
|
|
1926
|
+
type: "ExportAllDeclaration"
|
|
1927
|
+
}
|
|
1928
|
+
);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
// src/js/node-path-walker/import-tokens.ts
|
|
1933
|
+
function maybeAddImportToken(imports, arg) {
|
|
1934
|
+
if (!(arg.isImportSpecifier() && arg.node.importKind !== "type" || arg.isImportDefaultSpecifier())) {
|
|
1935
|
+
return false;
|
|
1936
|
+
}
|
|
1937
|
+
const importDeclaration = arg.parentPath;
|
|
1938
|
+
if (!importDeclaration.isImportDeclaration() || importDeclaration.node.importKind === "type") {
|
|
1939
|
+
return false;
|
|
1940
|
+
}
|
|
1941
|
+
if (arg.isImportSpecifier()) {
|
|
1942
|
+
const imported = arg.get("imported");
|
|
1943
|
+
if (imported.isIdentifier()) {
|
|
1944
|
+
imports.add(
|
|
1945
|
+
{
|
|
1946
|
+
declaration: importDeclaration,
|
|
1947
|
+
specifier: arg,
|
|
1948
|
+
imported: imported.node.name,
|
|
1949
|
+
local: arg.node.local.name,
|
|
1950
|
+
source: importDeclaration.node.source.value,
|
|
1951
|
+
type: "ImportSpecifier"
|
|
1952
|
+
}
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
return true;
|
|
1956
|
+
}
|
|
1957
|
+
imports.add(
|
|
1958
|
+
{
|
|
1959
|
+
declaration: importDeclaration,
|
|
1960
|
+
specifier: arg,
|
|
1961
|
+
local: arg.node.local.name,
|
|
1962
|
+
source: importDeclaration.node.source.value,
|
|
1963
|
+
type: "ImportDefaultSpecifier"
|
|
1964
|
+
}
|
|
1965
|
+
);
|
|
1966
|
+
return true;
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
// src/js/NodePathWalker.ts
|
|
1970
|
+
var EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS = [];
|
|
1971
|
+
var EMPTY_IMPORT_TOKENS = /* @__PURE__ */ new Set();
|
|
1972
|
+
function NOOP_STRING_PATH_CALLBACK() {
|
|
1973
|
+
}
|
|
1974
|
+
var NEVER_MATCH_NAME2 = () => false;
|
|
1975
|
+
var NodePathWalker = class {
|
|
1976
|
+
constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
|
|
1977
|
+
this.hasIgnoredCallIdentifiers = Boolean(ignoreCallExpressionIdentifiers && ignoreCallExpressionIdentifiers.length > 0);
|
|
1978
|
+
this.ignoreCallExpressionIdentifiers = ignoreCallExpressionIdentifiers ?? EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS;
|
|
1979
|
+
this.callback = callback ?? NOOP_STRING_PATH_CALLBACK;
|
|
1980
|
+
this.isIgnoredCallIdentifier = this.hasIgnoredCallIdentifiers ? createNameMatcher(this.ignoreCallExpressionIdentifiers, { exact: true }) : NEVER_MATCH_NAME2;
|
|
1981
|
+
}
|
|
1982
|
+
get imports() {
|
|
1983
|
+
return this.importsStore ?? EMPTY_IMPORT_TOKENS;
|
|
1984
|
+
}
|
|
1985
|
+
getWritableImports() {
|
|
1986
|
+
if (!this.importsStore) {
|
|
1987
|
+
this.importsStore = /* @__PURE__ */ new Set();
|
|
1988
|
+
}
|
|
1989
|
+
return this.importsStore;
|
|
1990
|
+
}
|
|
1991
|
+
addImportToken(token) {
|
|
1992
|
+
this.getWritableImports().add(token);
|
|
1993
|
+
}
|
|
1994
|
+
getVisited() {
|
|
1995
|
+
if (!this.visitedStore) {
|
|
1996
|
+
this.visitedStore = /* @__PURE__ */ new WeakSet();
|
|
1997
|
+
}
|
|
1998
|
+
return this.visitedStore;
|
|
1999
|
+
}
|
|
2000
|
+
walkVariableDeclarator(path22) {
|
|
2001
|
+
const init = path22.get("init");
|
|
2002
|
+
this.walkNode(init);
|
|
2003
|
+
}
|
|
2004
|
+
walkTemplateLiteral(path22) {
|
|
2005
|
+
for (const exp of path22.get("expressions")) {
|
|
2006
|
+
this.walkNode(exp);
|
|
2007
|
+
}
|
|
2008
|
+
for (const quasis of path22.get("quasis")) {
|
|
2009
|
+
this.callback(quasis);
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
walkStringLiteral(path22) {
|
|
2013
|
+
this.callback(path22);
|
|
2014
|
+
}
|
|
2015
|
+
walkBinaryExpression(path22) {
|
|
2016
|
+
const left = path22.get("left");
|
|
2017
|
+
this.walkNode(left);
|
|
2018
|
+
const right = path22.get("right");
|
|
2019
|
+
this.walkNode(right);
|
|
2020
|
+
}
|
|
2021
|
+
walkLogicalExpression(path22) {
|
|
2022
|
+
const left = path22.get("left");
|
|
2023
|
+
this.walkNode(left);
|
|
2024
|
+
const right = path22.get("right");
|
|
2025
|
+
this.walkNode(right);
|
|
2026
|
+
}
|
|
2027
|
+
walkObjectExpression(path22) {
|
|
2028
|
+
const props = path22.get("properties");
|
|
2029
|
+
for (const prop of props) {
|
|
2030
|
+
if (prop.isObjectProperty()) {
|
|
2031
|
+
const key = prop.get("key");
|
|
2032
|
+
this.walkNode(key);
|
|
2033
|
+
const value = prop.get("value");
|
|
2034
|
+
this.walkNode(value);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
walkArrayExpression(path22) {
|
|
2039
|
+
const elements = path22.get("elements");
|
|
2040
|
+
for (const element of elements) {
|
|
2041
|
+
this.walkNode(element);
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
walkNode(arg) {
|
|
2045
|
+
const visited = this.getVisited();
|
|
2046
|
+
if (visited.has(arg)) {
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
2049
|
+
visited.add(arg);
|
|
2050
|
+
if (arg.isIdentifier()) {
|
|
2051
|
+
const binding = arg?.scope?.getBinding?.(arg.node.name);
|
|
2052
|
+
if (binding) {
|
|
2053
|
+
this.walkNode(binding.path);
|
|
2054
|
+
}
|
|
2055
|
+
} else if (arg.isMemberExpression()) {
|
|
2056
|
+
const objectPath = arg.get("object");
|
|
2057
|
+
if (objectPath.isIdentifier()) {
|
|
2058
|
+
const binding = arg?.scope?.getBinding?.(objectPath.node.name);
|
|
2059
|
+
if (binding) {
|
|
2060
|
+
if (binding.path.isVariableDeclarator()) {
|
|
2061
|
+
this.walkVariableDeclarator(binding.path);
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
} else if (arg.isTemplateLiteral()) {
|
|
2066
|
+
this.walkTemplateLiteral(arg);
|
|
2067
|
+
} else if (arg.isStringLiteral()) {
|
|
2068
|
+
this.walkStringLiteral(arg);
|
|
2069
|
+
} else if (arg.isBinaryExpression()) {
|
|
2070
|
+
this.walkBinaryExpression(arg);
|
|
2071
|
+
} else if (arg.isLogicalExpression()) {
|
|
2072
|
+
this.walkLogicalExpression(arg);
|
|
2073
|
+
} else if (arg.isObjectExpression()) {
|
|
2074
|
+
this.walkObjectExpression(arg);
|
|
2075
|
+
} else if (arg.isArrayExpression()) {
|
|
2076
|
+
this.walkArrayExpression(arg);
|
|
2077
|
+
} else if (arg.isVariableDeclarator()) {
|
|
2078
|
+
this.walkVariableDeclarator(arg);
|
|
2079
|
+
} else if (maybeAddImportToken(this.getWritableImports(), arg)) {
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* Walk the arguments of a desired call expression so their bindings can be analysed.
|
|
2084
|
+
*/
|
|
2085
|
+
walkCallExpression(path22) {
|
|
2086
|
+
if (!this.hasIgnoredCallIdentifiers) {
|
|
2087
|
+
return;
|
|
2088
|
+
}
|
|
2089
|
+
const calleePath = path22.get("callee");
|
|
2090
|
+
if (calleePath.isIdentifier() && this.isIgnoredCallIdentifier(calleePath.node.name)) {
|
|
2091
|
+
for (const arg of path22.get("arguments")) {
|
|
2092
|
+
this.walkNode(arg);
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
walkExportDeclaration(path22) {
|
|
2097
|
+
walkExportDeclaration(this, path22);
|
|
2098
|
+
}
|
|
2099
|
+
walkExportNamedDeclaration(path22) {
|
|
2100
|
+
walkExportNamedDeclaration(this, path22);
|
|
2101
|
+
}
|
|
2102
|
+
walkExportDefaultDeclaration(path22) {
|
|
2103
|
+
walkExportDefaultDeclaration(this, path22);
|
|
2104
|
+
}
|
|
2105
|
+
walkExportAllDeclaration(path22) {
|
|
2106
|
+
walkExportAllDeclaration(this, path22);
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
|
|
2110
|
+
// src/js/taggedTemplateIgnore.ts
|
|
2111
|
+
function createTaggedTemplateIgnore({ matcher, names }) {
|
|
2112
|
+
const bindingIgnoreCache = /* @__PURE__ */ new Map();
|
|
2113
|
+
const taggedTemplateIgnoreCache = /* @__PURE__ */ new WeakMap();
|
|
2114
|
+
const seenBindings = /* @__PURE__ */ new Set();
|
|
2115
|
+
let singleCanonicalIgnoreName;
|
|
2116
|
+
let canonicalIgnoreNames;
|
|
2117
|
+
for (const item of names ?? []) {
|
|
2118
|
+
if (typeof item !== "string") {
|
|
2119
|
+
continue;
|
|
2120
|
+
}
|
|
2121
|
+
if (singleCanonicalIgnoreName === void 0) {
|
|
2122
|
+
singleCanonicalIgnoreName = item;
|
|
2123
|
+
continue;
|
|
2124
|
+
}
|
|
2125
|
+
if (item === singleCanonicalIgnoreName) {
|
|
2126
|
+
continue;
|
|
2127
|
+
}
|
|
2128
|
+
if (!canonicalIgnoreNames) {
|
|
2129
|
+
canonicalIgnoreNames = /* @__PURE__ */ new Set([singleCanonicalIgnoreName, item]);
|
|
2130
|
+
continue;
|
|
2131
|
+
}
|
|
2132
|
+
canonicalIgnoreNames.add(item);
|
|
2133
|
+
}
|
|
2134
|
+
const hasCanonicalIgnoreNames = singleCanonicalIgnoreName !== void 0;
|
|
2135
|
+
const matchesIgnoreName = (value) => {
|
|
2136
|
+
if (hasCanonicalIgnoreNames) {
|
|
2137
|
+
if (canonicalIgnoreNames) {
|
|
2138
|
+
if (canonicalIgnoreNames.has(value)) {
|
|
2139
|
+
return true;
|
|
2140
|
+
}
|
|
2141
|
+
} else if (value === singleCanonicalIgnoreName) {
|
|
2142
|
+
return true;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
return matcher(value);
|
|
2146
|
+
};
|
|
2147
|
+
const propertyMatches = (propertyPath) => {
|
|
2148
|
+
if (!propertyPath) {
|
|
2149
|
+
return false;
|
|
2150
|
+
}
|
|
2151
|
+
if (propertyPath.isIdentifier()) {
|
|
2152
|
+
return matchesIgnoreName(propertyPath.node.name);
|
|
2153
|
+
}
|
|
2154
|
+
if (propertyPath.isStringLiteral()) {
|
|
2155
|
+
return matchesIgnoreName(propertyPath.node.value);
|
|
2156
|
+
}
|
|
2157
|
+
return false;
|
|
2158
|
+
};
|
|
2159
|
+
const resolvesMemberExpressionToIgnore = (path22, seen) => {
|
|
2160
|
+
const propertyPath = path22.get("property");
|
|
2161
|
+
if (propertyMatches(propertyPath)) {
|
|
2162
|
+
return true;
|
|
2163
|
+
}
|
|
2164
|
+
const objectPath = path22.get("object");
|
|
2165
|
+
if (objectPath.isIdentifier()) {
|
|
2166
|
+
const scope = objectPath?.scope;
|
|
2167
|
+
const binding = scope?.getBinding?.(objectPath.node.name);
|
|
2168
|
+
if (binding) {
|
|
2169
|
+
return resolvesToWeappTwIgnore(binding, seen);
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
return false;
|
|
2173
|
+
};
|
|
2174
|
+
const resolvesToWeappTwIgnore = (binding, seen) => {
|
|
2175
|
+
const cached = bindingIgnoreCache.get(binding);
|
|
2176
|
+
if (cached !== void 0) {
|
|
2177
|
+
return cached;
|
|
2178
|
+
}
|
|
2179
|
+
if (seen.has(binding)) {
|
|
2180
|
+
return false;
|
|
2181
|
+
}
|
|
2182
|
+
seen.add(binding);
|
|
2183
|
+
let result = false;
|
|
2184
|
+
const bindingPath = binding.path;
|
|
2185
|
+
if (bindingPath.isImportSpecifier()) {
|
|
2186
|
+
const imported = bindingPath.node.imported;
|
|
2187
|
+
if (imported.type === "Identifier" && matchesIgnoreName(imported.name)) {
|
|
2188
|
+
result = true;
|
|
2189
|
+
} else if (imported.type === "StringLiteral" && matchesIgnoreName(imported.value)) {
|
|
2190
|
+
result = true;
|
|
2191
|
+
}
|
|
2192
|
+
} else if (bindingPath.isVariableDeclarator()) {
|
|
2193
|
+
const init = bindingPath.get("init");
|
|
2194
|
+
if (init && init.node) {
|
|
2195
|
+
if (init.isIdentifier()) {
|
|
2196
|
+
const target = binding?.scope?.getBinding?.(init.node.name);
|
|
2197
|
+
if (target) {
|
|
2198
|
+
result = resolvesToWeappTwIgnore(target, seen);
|
|
2199
|
+
}
|
|
2200
|
+
} else if (init.isMemberExpression()) {
|
|
2201
|
+
result = resolvesMemberExpressionToIgnore(init, seen);
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
bindingIgnoreCache.set(binding, result);
|
|
2206
|
+
seen.delete(binding);
|
|
2207
|
+
return result;
|
|
2208
|
+
};
|
|
2209
|
+
const getEffectiveTagPath = (tagPath) => {
|
|
2210
|
+
let current = tagPath;
|
|
2211
|
+
while (true) {
|
|
2212
|
+
if (current.isParenthesizedExpression?.() || current.node.type === "ParenthesizedExpression") {
|
|
2213
|
+
current = current.get("expression");
|
|
2214
|
+
continue;
|
|
2215
|
+
}
|
|
2216
|
+
if (current.isTSAsExpression() || current.isTSTypeAssertion()) {
|
|
2217
|
+
current = current.get("expression");
|
|
2218
|
+
continue;
|
|
2219
|
+
}
|
|
2220
|
+
if (current.isTSNonNullExpression()) {
|
|
2221
|
+
current = current.get("expression");
|
|
2222
|
+
continue;
|
|
2223
|
+
}
|
|
2224
|
+
if (current.isTypeCastExpression?.()) {
|
|
2225
|
+
current = current.get("expression");
|
|
2226
|
+
continue;
|
|
2227
|
+
}
|
|
2228
|
+
if (current.isSequenceExpression()) {
|
|
2229
|
+
const expressions = current.get("expressions");
|
|
2230
|
+
const last = expressions.at(-1);
|
|
2231
|
+
if (last) {
|
|
2232
|
+
current = last;
|
|
2233
|
+
continue;
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
if (current.isCallExpression?.() || current.node.type === "CallExpression") {
|
|
2237
|
+
const callee = current.get("callee");
|
|
2238
|
+
current = callee;
|
|
2239
|
+
continue;
|
|
2240
|
+
}
|
|
2241
|
+
break;
|
|
2242
|
+
}
|
|
2243
|
+
return current;
|
|
2244
|
+
};
|
|
2245
|
+
const evaluateTagPath = (tagPath, seen) => {
|
|
2246
|
+
if (tagPath.isCallExpression?.() || tagPath.node.type === "CallExpression") {
|
|
2247
|
+
const calleePath = tagPath.get("callee");
|
|
2248
|
+
return evaluateTagPath(calleePath, seen);
|
|
2249
|
+
}
|
|
2250
|
+
if (tagPath.isIdentifier()) {
|
|
2251
|
+
if (matchesIgnoreName(tagPath.node.name)) {
|
|
2252
|
+
return true;
|
|
2253
|
+
}
|
|
2254
|
+
const binding = tagPath?.scope?.getBinding?.(tagPath.node.name);
|
|
2255
|
+
if (binding) {
|
|
2256
|
+
return resolvesToWeappTwIgnore(binding, seen);
|
|
2257
|
+
}
|
|
2258
|
+
return false;
|
|
2259
|
+
}
|
|
2260
|
+
if (tagPath.isMemberExpression()) {
|
|
2261
|
+
return resolvesMemberExpressionToIgnore(tagPath, seen);
|
|
2262
|
+
}
|
|
2263
|
+
return false;
|
|
2264
|
+
};
|
|
2265
|
+
const computeIgnore = (tagPath) => {
|
|
2266
|
+
const cached = taggedTemplateIgnoreCache.get(tagPath.node);
|
|
2267
|
+
if (cached !== void 0) {
|
|
2268
|
+
return cached;
|
|
2269
|
+
}
|
|
2270
|
+
const effectiveTagPath = getEffectiveTagPath(tagPath);
|
|
2271
|
+
const effectiveCached = taggedTemplateIgnoreCache.get(effectiveTagPath.node);
|
|
2272
|
+
if (effectiveCached !== void 0) {
|
|
2273
|
+
taggedTemplateIgnoreCache.set(tagPath.node, effectiveCached);
|
|
2274
|
+
return effectiveCached;
|
|
2275
|
+
}
|
|
2276
|
+
seenBindings.clear();
|
|
2277
|
+
const result = evaluateTagPath(effectiveTagPath, seenBindings);
|
|
2278
|
+
taggedTemplateIgnoreCache.set(effectiveTagPath.node, result);
|
|
2279
|
+
taggedTemplateIgnoreCache.set(tagPath.node, result);
|
|
2280
|
+
return result;
|
|
2281
|
+
};
|
|
2282
|
+
return {
|
|
2283
|
+
shouldIgnore(tagPath) {
|
|
2284
|
+
return computeIgnore(tagPath);
|
|
2285
|
+
},
|
|
2286
|
+
getEffectiveTagPath
|
|
594
2287
|
};
|
|
595
2288
|
}
|
|
596
2289
|
|
|
597
|
-
// src/
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
2290
|
+
// src/js/babel.ts
|
|
2291
|
+
var EXPRESSION_WRAPPER_PREFIX = "(\n";
|
|
2292
|
+
var EXPRESSION_WRAPPER_SUFFIX = "\n)";
|
|
2293
|
+
var EMPTY_IGNORED_PATHS = /* @__PURE__ */ new WeakSet();
|
|
2294
|
+
var EMPTY_IMPORT_DECLARATIONS = /* @__PURE__ */ new Set();
|
|
2295
|
+
var EMPTY_EXPORT_DECLARATIONS = /* @__PURE__ */ new Set();
|
|
2296
|
+
var EMPTY_REQUIRE_CALL_PATHS = [];
|
|
2297
|
+
var ignoredTaggedTemplateMatcherCache = /* @__PURE__ */ new WeakMap();
|
|
2298
|
+
var defaultEvalHandler;
|
|
2299
|
+
function getIgnoredTaggedTemplateMatcher(options) {
|
|
2300
|
+
const cached = ignoredTaggedTemplateMatcherCache.get(options);
|
|
2301
|
+
if (cached) {
|
|
2302
|
+
return cached;
|
|
2303
|
+
}
|
|
2304
|
+
const created = createNameMatcher(options.ignoreTaggedTemplateExpressionIdentifiers, { exact: true });
|
|
2305
|
+
ignoredTaggedTemplateMatcherCache.set(options, created);
|
|
2306
|
+
return created;
|
|
2307
|
+
}
|
|
2308
|
+
function getDefaultEvalHandler() {
|
|
2309
|
+
if (!defaultEvalHandler) {
|
|
2310
|
+
throw new Error("Default JS eval handler is not initialized.");
|
|
614
2311
|
}
|
|
615
|
-
|
|
2312
|
+
return defaultEvalHandler;
|
|
616
2313
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
2314
|
+
function analyzeSource(ast, options, handler, collectModuleMetadata = true) {
|
|
2315
|
+
const jsTokenUpdater = new JsTokenUpdater();
|
|
2316
|
+
const needScope = Boolean(options.ignoreCallExpressionIdentifiers && options.ignoreCallExpressionIdentifiers.length > 0);
|
|
2317
|
+
const ignoredPaths = needScope ? /* @__PURE__ */ new WeakSet() : EMPTY_IGNORED_PATHS;
|
|
2318
|
+
const walker = needScope ? new NodePathWalker({
|
|
2319
|
+
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
2320
|
+
callback(path22) {
|
|
2321
|
+
ignoredPaths.add(path22);
|
|
2322
|
+
}
|
|
2323
|
+
}) : new NodePathWalker();
|
|
2324
|
+
let taggedTemplateIgnore;
|
|
2325
|
+
const hasTaggedTemplateIgnoreIdentifiers = Boolean(
|
|
2326
|
+
options.ignoreTaggedTemplateExpressionIdentifiers && options.ignoreTaggedTemplateExpressionIdentifiers.length > 0
|
|
2327
|
+
);
|
|
2328
|
+
function getTaggedTemplateIgnore() {
|
|
2329
|
+
if (!taggedTemplateIgnore) {
|
|
2330
|
+
taggedTemplateIgnore = createTaggedTemplateIgnore({
|
|
2331
|
+
matcher: getIgnoredTaggedTemplateMatcher(options),
|
|
2332
|
+
names: options.ignoreTaggedTemplateExpressionIdentifiers
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
return taggedTemplateIgnore;
|
|
2336
|
+
}
|
|
2337
|
+
const targetPaths = [];
|
|
2338
|
+
const importDeclarations = collectModuleMetadata ? /* @__PURE__ */ new Set() : EMPTY_IMPORT_DECLARATIONS;
|
|
2339
|
+
const exportDeclarations = collectModuleMetadata ? /* @__PURE__ */ new Set() : EMPTY_EXPORT_DECLARATIONS;
|
|
2340
|
+
const requireCallPaths = collectModuleMetadata ? [] : EMPTY_REQUIRE_CALL_PATHS;
|
|
2341
|
+
const evalHandler = handler ?? getDefaultEvalHandler();
|
|
2342
|
+
const templateElementEnter = hasTaggedTemplateIgnoreIdentifiers ? (p) => {
|
|
2343
|
+
const pp = p.parentPath;
|
|
2344
|
+
if (pp.isTemplateLiteral()) {
|
|
2345
|
+
const ppp = pp.parentPath;
|
|
2346
|
+
if (isEvalPath(ppp)) {
|
|
2347
|
+
return;
|
|
2348
|
+
}
|
|
2349
|
+
if (ppp.isTaggedTemplateExpression()) {
|
|
2350
|
+
const tagPath = ppp.get("tag");
|
|
2351
|
+
if (getTaggedTemplateIgnore().shouldIgnore(tagPath)) {
|
|
2352
|
+
return;
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
targetPaths.push(p);
|
|
2357
|
+
} : (p) => {
|
|
2358
|
+
const pp = p.parentPath;
|
|
2359
|
+
if (pp.isTemplateLiteral()) {
|
|
2360
|
+
const ppp = pp.parentPath;
|
|
2361
|
+
if (isEvalPath(ppp)) {
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
targetPaths.push(p);
|
|
2366
|
+
};
|
|
2367
|
+
const callExpressionEnter = !collectModuleMetadata && !needScope ? (p) => {
|
|
2368
|
+
if (isEvalPath(p)) {
|
|
2369
|
+
walkEvalExpression(p, options, jsTokenUpdater, evalHandler);
|
|
2370
|
+
}
|
|
2371
|
+
} : (p) => {
|
|
2372
|
+
if (isEvalPath(p)) {
|
|
2373
|
+
walkEvalExpression(p, options, jsTokenUpdater, evalHandler);
|
|
2374
|
+
return;
|
|
2375
|
+
}
|
|
2376
|
+
const calleePath = p.get("callee");
|
|
2377
|
+
if (collectModuleMetadata && calleePath.isIdentifier({ name: "require" }) && !p?.scope?.hasBinding?.("require")) {
|
|
2378
|
+
const args = p.get("arguments");
|
|
2379
|
+
if (Array.isArray(args) && args.length > 0) {
|
|
2380
|
+
const first = args[0];
|
|
2381
|
+
if (first?.isStringLiteral()) {
|
|
2382
|
+
requireCallPaths.push(first);
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
if (needScope) {
|
|
2387
|
+
walker.walkCallExpression(p);
|
|
2388
|
+
}
|
|
2389
|
+
};
|
|
2390
|
+
const traverseOptions = {
|
|
2391
|
+
StringLiteral: {
|
|
2392
|
+
enter(p) {
|
|
2393
|
+
if (isEvalPath(p.parentPath)) {
|
|
2394
|
+
return;
|
|
2395
|
+
}
|
|
2396
|
+
targetPaths.push(p);
|
|
2397
|
+
}
|
|
2398
|
+
},
|
|
2399
|
+
TemplateElement: {
|
|
2400
|
+
enter: templateElementEnter
|
|
2401
|
+
},
|
|
2402
|
+
CallExpression: {
|
|
2403
|
+
enter: callExpressionEnter
|
|
2404
|
+
},
|
|
2405
|
+
...collectModuleMetadata ? {
|
|
2406
|
+
ImportDeclaration: {
|
|
2407
|
+
enter(p) {
|
|
2408
|
+
importDeclarations.add(p);
|
|
2409
|
+
}
|
|
2410
|
+
},
|
|
2411
|
+
ExportDeclaration: {
|
|
2412
|
+
enter(p) {
|
|
2413
|
+
exportDeclarations.add(p);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
} : {}
|
|
2417
|
+
};
|
|
2418
|
+
traverse(ast, { ...traverseOptions, noScope: !needScope });
|
|
2419
|
+
return {
|
|
2420
|
+
walker,
|
|
2421
|
+
jsTokenUpdater,
|
|
2422
|
+
ast,
|
|
2423
|
+
targetPaths,
|
|
2424
|
+
importDeclarations,
|
|
2425
|
+
exportDeclarations,
|
|
2426
|
+
requireCallPaths,
|
|
2427
|
+
ignoredPaths
|
|
2428
|
+
};
|
|
660
2429
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
2430
|
+
function jsHandler(rawSource, options) {
|
|
2431
|
+
const shouldWrapExpression = Boolean(options.wrapExpression);
|
|
2432
|
+
const source = shouldWrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
|
|
2433
|
+
let ast;
|
|
2434
|
+
try {
|
|
2435
|
+
ast = babelParse(source, options.babelParserOptions);
|
|
2436
|
+
} catch (error) {
|
|
2437
|
+
return {
|
|
2438
|
+
code: rawSource,
|
|
2439
|
+
error
|
|
2440
|
+
};
|
|
671
2441
|
}
|
|
672
|
-
);
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
2442
|
+
const needsModuleMetadata = Boolean(options.moduleSpecifierReplacements || options.moduleGraph && options.filename);
|
|
2443
|
+
const analysis = analyzeSource(ast, options, jsHandler, needsModuleMetadata);
|
|
2444
|
+
const ms = processUpdatedSource(source, options, analysis);
|
|
2445
|
+
if (shouldWrapExpression) {
|
|
2446
|
+
const start = 0;
|
|
2447
|
+
const end = source.length;
|
|
2448
|
+
const prefixLength = EXPRESSION_WRAPPER_PREFIX.length;
|
|
2449
|
+
const suffixLength = EXPRESSION_WRAPPER_SUFFIX.length;
|
|
2450
|
+
ms.remove(start, start + prefixLength);
|
|
2451
|
+
ms.remove(end - suffixLength, end);
|
|
2452
|
+
}
|
|
2453
|
+
const result = {
|
|
2454
|
+
code: ms.toString()
|
|
2455
|
+
};
|
|
2456
|
+
if (options.generateMap) {
|
|
2457
|
+
Object.defineProperty(result, "map", {
|
|
2458
|
+
configurable: true,
|
|
2459
|
+
enumerable: true,
|
|
2460
|
+
get() {
|
|
2461
|
+
return ms.generateMap();
|
|
2462
|
+
}
|
|
2463
|
+
});
|
|
2464
|
+
}
|
|
2465
|
+
if (options.moduleGraph && options.filename) {
|
|
2466
|
+
const graph = new JsModuleGraph(
|
|
2467
|
+
{
|
|
2468
|
+
filename: options.filename,
|
|
2469
|
+
source: rawSource,
|
|
2470
|
+
analysis,
|
|
2471
|
+
handlerOptions: options
|
|
2472
|
+
},
|
|
2473
|
+
options.moduleGraph
|
|
2474
|
+
);
|
|
2475
|
+
const linked = graph.build();
|
|
2476
|
+
if (linked) {
|
|
2477
|
+
result.linked = linked;
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
return result;
|
|
2481
|
+
}
|
|
2482
|
+
defaultEvalHandler = jsHandler;
|
|
689
2483
|
|
|
690
2484
|
// src/wxml/utils/codegen/legacy-rewriter.ts
|
|
691
2485
|
var import_magic_string2 = __toESM(require("magic-string"));
|
|
@@ -929,9 +2723,273 @@ function formatOutputPath(target, baseDir) {
|
|
|
929
2723
|
return relative.startsWith(".") ? relative : `.${import_node_path12.default.sep}${relative}`;
|
|
930
2724
|
}
|
|
931
2725
|
|
|
2726
|
+
// src/cli/doctor.ts
|
|
2727
|
+
var import_node_fs7 = require("fs");
|
|
2728
|
+
var import_node_module3 = require("module");
|
|
2729
|
+
var import_node_path13 = __toESM(require("path"));
|
|
2730
|
+
var import_node_process13 = __toESM(require("process"));
|
|
2731
|
+
var import_semver = __toESM(require("semver"));
|
|
2732
|
+
|
|
2733
|
+
// src/cli/doctor/constants.ts
|
|
2734
|
+
var CONFIG_FILES = {
|
|
2735
|
+
tailwind: [
|
|
2736
|
+
"tailwind.config.js",
|
|
2737
|
+
"tailwind.config.cjs",
|
|
2738
|
+
"tailwind.config.mjs",
|
|
2739
|
+
"tailwind.config.ts"
|
|
2740
|
+
],
|
|
2741
|
+
postcss: [
|
|
2742
|
+
"postcss.config.js",
|
|
2743
|
+
"postcss.config.cjs",
|
|
2744
|
+
"postcss.config.mjs",
|
|
2745
|
+
"postcss.config.ts"
|
|
2746
|
+
],
|
|
2747
|
+
vite: ["vite.config.js", "vite.config.mjs", "vite.config.ts"],
|
|
2748
|
+
webpack: ["webpack.config.js", "webpack.config.cjs", "webpack.config.ts"]
|
|
2749
|
+
};
|
|
2750
|
+
var FRAMEWORK_DEPS = [
|
|
2751
|
+
["@tarojs/taro", "Taro"],
|
|
2752
|
+
["@dcloudio/uni-app", "uni-app"],
|
|
2753
|
+
["@mpxjs/core", "MPX"],
|
|
2754
|
+
["remax", "Remax"],
|
|
2755
|
+
["rax", "Rax"]
|
|
2756
|
+
];
|
|
2757
|
+
|
|
2758
|
+
// src/cli/doctor.ts
|
|
2759
|
+
function tryReadJson(file) {
|
|
2760
|
+
try {
|
|
2761
|
+
return JSON.parse((0, import_node_fs7.readFileSync)(file, "utf8"));
|
|
2762
|
+
} catch {
|
|
2763
|
+
return void 0;
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
function findFirstExisting(cwd, files) {
|
|
2767
|
+
return files.find((file) => (0, import_node_fs7.existsSync)(import_node_path13.default.join(cwd, file)));
|
|
2768
|
+
}
|
|
2769
|
+
function readProjectPackageJson(cwd) {
|
|
2770
|
+
return tryReadJson(import_node_path13.default.join(cwd, "package.json"));
|
|
2771
|
+
}
|
|
2772
|
+
function readDependencyVersion(cwd, packageName) {
|
|
2773
|
+
try {
|
|
2774
|
+
const requireFromCwd = (0, import_node_module3.createRequire)(import_node_path13.default.join(cwd, "package.json"));
|
|
2775
|
+
const packageJsonPath = requireFromCwd.resolve(`${packageName}/package.json`);
|
|
2776
|
+
return tryReadJson(packageJsonPath)?.version;
|
|
2777
|
+
} catch {
|
|
2778
|
+
return void 0;
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
function collectDependencySpecs(pkg) {
|
|
2782
|
+
return {
|
|
2783
|
+
...pkg?.dependencies ?? {},
|
|
2784
|
+
...pkg?.devDependencies ?? {},
|
|
2785
|
+
...pkg?.optionalDependencies ?? {},
|
|
2786
|
+
...pkg?.peerDependencies ?? {}
|
|
2787
|
+
};
|
|
2788
|
+
}
|
|
2789
|
+
function detectPackageManager(cwd, pkg) {
|
|
2790
|
+
if (pkg?.packageManager) {
|
|
2791
|
+
return pkg.packageManager;
|
|
2792
|
+
}
|
|
2793
|
+
if ((0, import_node_fs7.existsSync)(import_node_path13.default.join(cwd, "pnpm-lock.yaml"))) {
|
|
2794
|
+
return "pnpm";
|
|
2795
|
+
}
|
|
2796
|
+
if ((0, import_node_fs7.existsSync)(import_node_path13.default.join(cwd, "package-lock.json"))) {
|
|
2797
|
+
return "npm";
|
|
2798
|
+
}
|
|
2799
|
+
if ((0, import_node_fs7.existsSync)(import_node_path13.default.join(cwd, "yarn.lock"))) {
|
|
2800
|
+
return "yarn";
|
|
2801
|
+
}
|
|
2802
|
+
return void 0;
|
|
2803
|
+
}
|
|
2804
|
+
function detectFrameworks(deps) {
|
|
2805
|
+
return FRAMEWORK_DEPS.filter(([dependency]) => dependency in deps).map(([, label]) => label);
|
|
2806
|
+
}
|
|
2807
|
+
function addCheck(checks, check) {
|
|
2808
|
+
checks.push(check);
|
|
2809
|
+
}
|
|
2810
|
+
function summarizeChecks(checks) {
|
|
2811
|
+
return checks.reduce((summary, check) => {
|
|
2812
|
+
summary[check.status] += 1;
|
|
2813
|
+
return summary;
|
|
2814
|
+
}, { ok: 0, warn: 0, error: 0, info: 0 });
|
|
2815
|
+
}
|
|
2816
|
+
function hasDependency(deps, packageName) {
|
|
2817
|
+
return packageName in deps;
|
|
2818
|
+
}
|
|
2819
|
+
function getMajorVersion(version) {
|
|
2820
|
+
if (!version) {
|
|
2821
|
+
return void 0;
|
|
2822
|
+
}
|
|
2823
|
+
return import_semver.default.parse(version)?.major;
|
|
2824
|
+
}
|
|
2825
|
+
function getDependencyMajor(deps, packageName) {
|
|
2826
|
+
const spec = deps[packageName];
|
|
2827
|
+
return spec ? import_semver.default.minVersion(spec)?.major : void 0;
|
|
2828
|
+
}
|
|
2829
|
+
function createDoctorReport(options = {}) {
|
|
2830
|
+
const cwd = import_node_path13.default.resolve(options.cwd ?? import_node_process13.default.cwd());
|
|
2831
|
+
const nodeVersion = options.nodeVersion ?? import_node_process13.default.versions.node;
|
|
2832
|
+
const pkg = readProjectPackageJson(cwd);
|
|
2833
|
+
const deps = collectDependencySpecs(pkg);
|
|
2834
|
+
const checks = [];
|
|
2835
|
+
const packageManager = detectPackageManager(cwd, pkg);
|
|
2836
|
+
const frameworks = detectFrameworks(deps);
|
|
2837
|
+
const tailwindcssVersion = readDependencyVersion(cwd, "tailwindcss");
|
|
2838
|
+
const weappTailwindcssVersion = readDependencyVersion(cwd, "weapp-tailwindcss");
|
|
2839
|
+
const tailwindMajor = getMajorVersion(tailwindcssVersion) ?? getDependencyMajor(deps, "tailwindcss");
|
|
2840
|
+
const tailwindConfig = findFirstExisting(cwd, CONFIG_FILES.tailwind);
|
|
2841
|
+
const postcssConfig = findFirstExisting(cwd, CONFIG_FILES.postcss);
|
|
2842
|
+
const viteConfig = findFirstExisting(cwd, CONFIG_FILES.vite);
|
|
2843
|
+
const webpackConfig = findFirstExisting(cwd, CONFIG_FILES.webpack);
|
|
2844
|
+
addCheck(checks, pkg ? {
|
|
2845
|
+
id: "package-json",
|
|
2846
|
+
title: "package.json",
|
|
2847
|
+
status: "ok",
|
|
2848
|
+
message: "\u5DF2\u627E\u5230\u9879\u76EE package.json\u3002"
|
|
2849
|
+
} : {
|
|
2850
|
+
id: "package-json",
|
|
2851
|
+
title: "package.json",
|
|
2852
|
+
status: "error",
|
|
2853
|
+
message: "\u5F53\u524D\u76EE\u5F55\u6CA1\u6709 package.json\u3002",
|
|
2854
|
+
suggestion: "\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u8FD0\u884C doctor\uFF0C\u6216\u901A\u8FC7 --cwd \u6307\u5411\u9879\u76EE\u6839\u76EE\u5F55\u3002"
|
|
2855
|
+
});
|
|
2856
|
+
addCheck(checks, import_semver.default.satisfies(nodeVersion, WEAPP_TW_REQUIRED_NODE_VERSION_RANGE) ? {
|
|
2857
|
+
id: "node-version",
|
|
2858
|
+
title: "Node.js",
|
|
2859
|
+
status: "ok",
|
|
2860
|
+
message: `\u5F53\u524D Node.js ${nodeVersion} \u6EE1\u8DB3\u7248\u672C\u8981\u6C42 ${WEAPP_TW_REQUIRED_NODE_VERSION_RANGE}\u3002`
|
|
2861
|
+
} : {
|
|
2862
|
+
id: "node-version",
|
|
2863
|
+
title: "Node.js",
|
|
2864
|
+
status: "error",
|
|
2865
|
+
message: `\u5F53\u524D Node.js ${nodeVersion} \u4E0D\u6EE1\u8DB3\u7248\u672C\u8981\u6C42 ${WEAPP_TW_REQUIRED_NODE_VERSION_RANGE}\u3002`,
|
|
2866
|
+
suggestion: "\u8BF7\u5347\u7EA7 Node.js \u540E\u518D\u5B89\u88C5\u6216\u6784\u5EFA weapp-tailwindcss \u9879\u76EE\u3002"
|
|
2867
|
+
});
|
|
2868
|
+
addCheck(checks, packageManager ? {
|
|
2869
|
+
id: "package-manager",
|
|
2870
|
+
title: "\u5305\u7BA1\u7406\u5668",
|
|
2871
|
+
status: packageManager.startsWith("pnpm") ? "ok" : "info",
|
|
2872
|
+
message: `\u68C0\u6D4B\u5230 ${packageManager}\u3002`
|
|
2873
|
+
} : {
|
|
2874
|
+
id: "package-manager",
|
|
2875
|
+
title: "\u5305\u7BA1\u7406\u5668",
|
|
2876
|
+
status: "info",
|
|
2877
|
+
message: "\u672A\u68C0\u6D4B\u5230 lockfile \u6216 packageManager \u5B57\u6BB5\u3002"
|
|
2878
|
+
});
|
|
2879
|
+
addCheck(checks, hasDependency(deps, "weapp-tailwindcss") || Boolean(weappTailwindcssVersion) ? {
|
|
2880
|
+
id: "weapp-tailwindcss",
|
|
2881
|
+
title: "weapp-tailwindcss",
|
|
2882
|
+
status: "ok",
|
|
2883
|
+
message: `\u68C0\u6D4B\u5230 weapp-tailwindcss${weappTailwindcssVersion ? `@${weappTailwindcssVersion}` : ""}\u3002`
|
|
2884
|
+
} : {
|
|
2885
|
+
id: "weapp-tailwindcss",
|
|
2886
|
+
title: "weapp-tailwindcss",
|
|
2887
|
+
status: "warn",
|
|
2888
|
+
message: "\u672A\u5728\u5F53\u524D\u9879\u76EE\u4F9D\u8D56\u4E2D\u68C0\u6D4B\u5230 weapp-tailwindcss\u3002",
|
|
2889
|
+
suggestion: "\u5982\u679C\u8FD9\u662F\u4E1A\u52A1\u9879\u76EE\uFF0C\u8BF7\u5B89\u88C5 weapp-tailwindcss \u5E76\u786E\u8BA4\u547D\u4EE4\u8FD0\u884C\u5728\u9879\u76EE\u6839\u76EE\u5F55\u3002"
|
|
2890
|
+
});
|
|
2891
|
+
addCheck(checks, hasDependency(deps, "tailwindcss") || Boolean(tailwindcssVersion) ? {
|
|
2892
|
+
id: "tailwindcss",
|
|
2893
|
+
title: "Tailwind CSS",
|
|
2894
|
+
status: "ok",
|
|
2895
|
+
message: `\u68C0\u6D4B\u5230 tailwindcss${tailwindcssVersion ? `@${tailwindcssVersion}` : ""}\u3002`
|
|
2896
|
+
} : {
|
|
2897
|
+
id: "tailwindcss",
|
|
2898
|
+
title: "Tailwind CSS",
|
|
2899
|
+
status: "error",
|
|
2900
|
+
message: "\u672A\u68C0\u6D4B\u5230 tailwindcss\u3002",
|
|
2901
|
+
suggestion: "\u8BF7\u5B89\u88C5 tailwindcss\uFF0C\u5E76\u786E\u8BA4\u4F9D\u8D56\u53EF\u4EE5\u4ECE\u5F53\u524D\u9879\u76EE\u89E3\u6790\u3002"
|
|
2902
|
+
});
|
|
2903
|
+
addCheck(checks, tailwindConfig ? {
|
|
2904
|
+
id: "tailwind-config",
|
|
2905
|
+
title: "Tailwind \u914D\u7F6E",
|
|
2906
|
+
status: "ok",
|
|
2907
|
+
message: `\u68C0\u6D4B\u5230 ${tailwindConfig}\u3002`
|
|
2908
|
+
} : {
|
|
2909
|
+
id: "tailwind-config",
|
|
2910
|
+
title: "Tailwind \u914D\u7F6E",
|
|
2911
|
+
status: tailwindMajor === 4 ? "info" : "warn",
|
|
2912
|
+
message: "\u672A\u68C0\u6D4B\u5230 tailwind.config.*\u3002",
|
|
2913
|
+
suggestion: tailwindMajor === 4 ? "Tailwind CSS v4 \u53EF\u4EE5\u91C7\u7528 CSS-first \u914D\u7F6E\uFF1B\u5982\u679C\u4F7F\u7528 v3 \u6216\u590D\u6742 content/source\uFF0C\u8BF7\u8865\u5145\u914D\u7F6E\u6587\u4EF6\u3002" : "\u8BF7\u786E\u8BA4 Tailwind content/source \u914D\u7F6E\u80FD\u591F\u8986\u76D6\u5C0F\u7A0B\u5E8F\u9875\u9762\u3001\u7EC4\u4EF6\u548C\u811A\u672C\u6587\u4EF6\u3002"
|
|
2914
|
+
});
|
|
2915
|
+
addCheck(checks, postcssConfig ? {
|
|
2916
|
+
id: "postcss-config",
|
|
2917
|
+
title: "PostCSS \u914D\u7F6E",
|
|
2918
|
+
status: "ok",
|
|
2919
|
+
message: `\u68C0\u6D4B\u5230 ${postcssConfig}\u3002`
|
|
2920
|
+
} : {
|
|
2921
|
+
id: "postcss-config",
|
|
2922
|
+
title: "PostCSS \u914D\u7F6E",
|
|
2923
|
+
status: viteConfig ? "info" : "warn",
|
|
2924
|
+
message: "\u672A\u68C0\u6D4B\u5230 postcss.config.*\u3002",
|
|
2925
|
+
suggestion: "\u5982\u679C\u901A\u8FC7 PostCSS \u63A5\u5165\uFF0C\u8BF7\u8865\u5145 postcss.config.*\uFF1B\u5982\u679C\u901A\u8FC7 Vite/Taro \u63D2\u4EF6\u63A5\u5165\uFF0C\u53EF\u5FFD\u7565\u6B64\u9879\u3002"
|
|
2926
|
+
});
|
|
2927
|
+
if (tailwindMajor === 4 && postcssConfig && !hasDependency(deps, "@tailwindcss/postcss")) {
|
|
2928
|
+
addCheck(checks, {
|
|
2929
|
+
id: "tailwindcss-v4-postcss",
|
|
2930
|
+
title: "Tailwind v4 PostCSS",
|
|
2931
|
+
status: "warn",
|
|
2932
|
+
message: "Tailwind CSS v4 \u9879\u76EE\u5B58\u5728 PostCSS \u914D\u7F6E\uFF0C\u4F46\u672A\u68C0\u6D4B\u5230 @tailwindcss/postcss\u3002",
|
|
2933
|
+
suggestion: "\u5982\u679C PostCSS \u914D\u7F6E\u4E2D\u4ECD\u76F4\u63A5\u4F7F\u7528 tailwindcss\uFF0C\u8BF7\u8FC1\u79FB\u5230 @tailwindcss/postcss\u3002"
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
addCheck(checks, frameworks.length > 0 ? {
|
|
2937
|
+
id: "framework",
|
|
2938
|
+
title: "\u6846\u67B6\u8BC6\u522B",
|
|
2939
|
+
status: "ok",
|
|
2940
|
+
message: `\u68C0\u6D4B\u5230 ${frameworks.join(", ")}\u3002`
|
|
2941
|
+
} : {
|
|
2942
|
+
id: "framework",
|
|
2943
|
+
title: "\u6846\u67B6\u8BC6\u522B",
|
|
2944
|
+
status: "info",
|
|
2945
|
+
message: "\u672A\u4ECE\u4F9D\u8D56\u4E2D\u8BC6\u522B\u51FA Taro\u3001uni-app\u3001MPX\u3001Remax \u6216 Rax\u3002"
|
|
2946
|
+
});
|
|
2947
|
+
addCheck(checks, viteConfig || webpackConfig ? {
|
|
2948
|
+
id: "bundler-config",
|
|
2949
|
+
title: "\u6784\u5EFA\u5668\u914D\u7F6E",
|
|
2950
|
+
status: "ok",
|
|
2951
|
+
message: `\u68C0\u6D4B\u5230 ${[viteConfig, webpackConfig].filter(Boolean).join(", ")}\u3002`
|
|
2952
|
+
} : {
|
|
2953
|
+
id: "bundler-config",
|
|
2954
|
+
title: "\u6784\u5EFA\u5668\u914D\u7F6E",
|
|
2955
|
+
status: "info",
|
|
2956
|
+
message: "\u672A\u68C0\u6D4B\u5230 vite.config.* \u6216 webpack.config.*\u3002"
|
|
2957
|
+
});
|
|
2958
|
+
return {
|
|
2959
|
+
cwd,
|
|
2960
|
+
nodeVersion,
|
|
2961
|
+
detected: {
|
|
2962
|
+
packageManager,
|
|
2963
|
+
frameworks,
|
|
2964
|
+
tailwindcssVersion,
|
|
2965
|
+
weappTailwindcssVersion
|
|
2966
|
+
},
|
|
2967
|
+
summary: summarizeChecks(checks),
|
|
2968
|
+
checks
|
|
2969
|
+
};
|
|
2970
|
+
}
|
|
2971
|
+
function hasDoctorFailure(report, strict = false) {
|
|
2972
|
+
return report.summary.error > 0 || strict && report.summary.warn > 0;
|
|
2973
|
+
}
|
|
2974
|
+
function formatDoctorReport(report) {
|
|
2975
|
+
const lines = [
|
|
2976
|
+
`weapp-tailwindcss doctor`,
|
|
2977
|
+
`cwd: ${report.cwd}`,
|
|
2978
|
+
`summary: ${report.summary.error} error, ${report.summary.warn} warn, ${report.summary.ok} ok, ${report.summary.info} info`,
|
|
2979
|
+
""
|
|
2980
|
+
];
|
|
2981
|
+
for (const check of report.checks) {
|
|
2982
|
+
lines.push(`[${check.status}] ${check.title}: ${check.message}`);
|
|
2983
|
+
if (check.suggestion) {
|
|
2984
|
+
lines.push(` -> ${check.suggestion}`);
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
return lines.join("\n");
|
|
2988
|
+
}
|
|
2989
|
+
|
|
932
2990
|
// src/cli/helpers.ts
|
|
933
2991
|
var import_promises3 = require("fs/promises");
|
|
934
|
-
var
|
|
2992
|
+
var import_node_process16 = __toESM(require("process"));
|
|
935
2993
|
|
|
936
2994
|
// src/logger/index.ts
|
|
937
2995
|
var import_logger13 = require("@weapp-tailwindcss/logger");
|
|
@@ -989,19 +3047,19 @@ function toBoolean(value, fallback) {
|
|
|
989
3047
|
}
|
|
990
3048
|
|
|
991
3049
|
// src/cli/helpers/options/resolve.ts
|
|
992
|
-
var
|
|
993
|
-
var
|
|
3050
|
+
var import_node_path14 = __toESM(require("path"));
|
|
3051
|
+
var import_node_process14 = __toESM(require("process"));
|
|
994
3052
|
function resolveCliCwd(value) {
|
|
995
3053
|
const raw = readStringOption("cwd", value);
|
|
996
3054
|
if (!raw) {
|
|
997
3055
|
return void 0;
|
|
998
3056
|
}
|
|
999
|
-
return
|
|
3057
|
+
return import_node_path14.default.isAbsolute(raw) ? import_node_path14.default.normalize(raw) : import_node_path14.default.resolve(import_node_process14.default.cwd(), raw);
|
|
1000
3058
|
}
|
|
1001
3059
|
|
|
1002
3060
|
// src/cli/helpers/patch-cwd.ts
|
|
1003
|
-
var
|
|
1004
|
-
var
|
|
3061
|
+
var import_node_path15 = __toESM(require("path"));
|
|
3062
|
+
var import_node_process15 = __toESM(require("process"));
|
|
1005
3063
|
|
|
1006
3064
|
// src/tailwindcss/index.ts
|
|
1007
3065
|
var import_local_pkg = require("local-pkg");
|
|
@@ -1014,7 +3072,7 @@ function normalizeCandidatePath(baseDir, candidate) {
|
|
|
1014
3072
|
if (!candidate) {
|
|
1015
3073
|
return void 0;
|
|
1016
3074
|
}
|
|
1017
|
-
return
|
|
3075
|
+
return import_node_path15.default.isAbsolute(candidate) ? import_node_path15.default.normalize(candidate) : import_node_path15.default.resolve(baseDir, candidate);
|
|
1018
3076
|
}
|
|
1019
3077
|
function detectTailwindWorkspace(paths) {
|
|
1020
3078
|
for (const candidate of paths) {
|
|
@@ -1028,15 +3086,15 @@ function detectTailwindWorkspace(paths) {
|
|
|
1028
3086
|
}
|
|
1029
3087
|
return void 0;
|
|
1030
3088
|
}
|
|
1031
|
-
function resolvePatchDefaultCwd(currentCwd =
|
|
1032
|
-
const baseDir =
|
|
1033
|
-
const explicitCwd = normalizeCandidatePath(baseDir,
|
|
3089
|
+
function resolvePatchDefaultCwd(currentCwd = import_node_process15.default.cwd()) {
|
|
3090
|
+
const baseDir = import_node_path15.default.normalize(currentCwd);
|
|
3091
|
+
const explicitCwd = normalizeCandidatePath(baseDir, import_node_process15.default.env.WEAPP_TW_PATCH_CWD);
|
|
1034
3092
|
if (explicitCwd) {
|
|
1035
3093
|
return explicitCwd;
|
|
1036
3094
|
}
|
|
1037
3095
|
const workspaceRoot = findWorkspaceRoot(baseDir);
|
|
1038
|
-
const initCwd = normalizeCandidatePath(baseDir,
|
|
1039
|
-
const localPrefix = normalizeCandidatePath(baseDir,
|
|
3096
|
+
const initCwd = normalizeCandidatePath(baseDir, import_node_process15.default.env.INIT_CWD);
|
|
3097
|
+
const localPrefix = normalizeCandidatePath(baseDir, import_node_process15.default.env.npm_config_local_prefix);
|
|
1040
3098
|
const candidates = [
|
|
1041
3099
|
baseDir,
|
|
1042
3100
|
workspaceRoot,
|
|
@@ -1057,7 +3115,7 @@ async function ensureDir(dir) {
|
|
|
1057
3115
|
function handleCliError(error) {
|
|
1058
3116
|
if (error instanceof Error) {
|
|
1059
3117
|
import_logger13.logger.error(error.message);
|
|
1060
|
-
if (error.stack &&
|
|
3118
|
+
if (error.stack && import_node_process16.default.env.WEAPP_TW_DEBUG === "1") {
|
|
1061
3119
|
import_logger13.logger.error(error.stack);
|
|
1062
3120
|
}
|
|
1063
3121
|
} else {
|
|
@@ -1070,13 +3128,13 @@ function commandAction(handler) {
|
|
|
1070
3128
|
await handler(...args);
|
|
1071
3129
|
} catch (error) {
|
|
1072
3130
|
handleCliError(error);
|
|
1073
|
-
|
|
3131
|
+
import_node_process16.default.exitCode = 1;
|
|
1074
3132
|
}
|
|
1075
3133
|
};
|
|
1076
3134
|
}
|
|
1077
3135
|
|
|
1078
3136
|
// src/cli/mount-options.ts
|
|
1079
|
-
var
|
|
3137
|
+
var import_node_process18 = __toESM(require("process"));
|
|
1080
3138
|
|
|
1081
3139
|
// src/cli/mount-options/patch-status.ts
|
|
1082
3140
|
function formatStatusFilesHint(files) {
|
|
@@ -1151,24 +3209,24 @@ function buildExtendLengthUnitsOverride(options) {
|
|
|
1151
3209
|
}
|
|
1152
3210
|
|
|
1153
3211
|
// src/cli/workspace.ts
|
|
1154
|
-
var
|
|
1155
|
-
var
|
|
3212
|
+
var import_node_path20 = __toESM(require("path"));
|
|
3213
|
+
var import_node_process17 = __toESM(require("process"));
|
|
1156
3214
|
|
|
1157
3215
|
// src/cli/workspace/package-dirs.ts
|
|
1158
|
-
var
|
|
1159
|
-
var
|
|
3216
|
+
var import_node_fs11 = require("fs");
|
|
3217
|
+
var import_node_path18 = __toESM(require("path"));
|
|
1160
3218
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
1161
3219
|
|
|
1162
3220
|
// src/cli/workspace/workspace-globs.ts
|
|
1163
|
-
var
|
|
1164
|
-
var
|
|
3221
|
+
var import_node_fs9 = require("fs");
|
|
3222
|
+
var import_node_path16 = __toESM(require("path"));
|
|
1165
3223
|
var import_yaml = require("yaml");
|
|
1166
3224
|
|
|
1167
3225
|
// src/cli/workspace/workspace-io.ts
|
|
1168
|
-
var
|
|
1169
|
-
function
|
|
3226
|
+
var import_node_fs8 = require("fs");
|
|
3227
|
+
function tryReadJson2(file) {
|
|
1170
3228
|
try {
|
|
1171
|
-
const content = (0,
|
|
3229
|
+
const content = (0, import_node_fs8.readFileSync)(file, "utf8");
|
|
1172
3230
|
return JSON.parse(content);
|
|
1173
3231
|
} catch {
|
|
1174
3232
|
return void 0;
|
|
@@ -1177,8 +3235,8 @@ function tryReadJson(file) {
|
|
|
1177
3235
|
|
|
1178
3236
|
// src/cli/workspace/workspace-globs.ts
|
|
1179
3237
|
function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
|
|
1180
|
-
const pkgJsonPath =
|
|
1181
|
-
const pkg =
|
|
3238
|
+
const pkgJsonPath = import_node_path16.default.join(workspaceRoot, "package.json");
|
|
3239
|
+
const pkg = tryReadJson2(pkgJsonPath);
|
|
1182
3240
|
if (!pkg?.workspaces) {
|
|
1183
3241
|
return [];
|
|
1184
3242
|
}
|
|
@@ -1191,12 +3249,12 @@ function parseWorkspaceGlobsFromPackageJson(workspaceRoot) {
|
|
|
1191
3249
|
return [];
|
|
1192
3250
|
}
|
|
1193
3251
|
function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
|
|
1194
|
-
const workspaceFile =
|
|
1195
|
-
if (!(0,
|
|
3252
|
+
const workspaceFile = import_node_path16.default.join(workspaceRoot, "pnpm-workspace.yaml");
|
|
3253
|
+
if (!(0, import_node_fs9.existsSync)(workspaceFile)) {
|
|
1196
3254
|
return [];
|
|
1197
3255
|
}
|
|
1198
3256
|
try {
|
|
1199
|
-
const parsed = (0, import_yaml.parse)((0,
|
|
3257
|
+
const parsed = (0, import_yaml.parse)((0, import_node_fs9.readFileSync)(workspaceFile, "utf8"));
|
|
1200
3258
|
return Array.isArray(parsed?.packages) ? parsed.packages.filter(Boolean) : [];
|
|
1201
3259
|
} catch {
|
|
1202
3260
|
return [];
|
|
@@ -1204,16 +3262,16 @@ function parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot) {
|
|
|
1204
3262
|
}
|
|
1205
3263
|
|
|
1206
3264
|
// src/cli/workspace/workspace-lock.ts
|
|
1207
|
-
var
|
|
1208
|
-
var
|
|
3265
|
+
var import_node_fs10 = require("fs");
|
|
3266
|
+
var import_node_path17 = __toESM(require("path"));
|
|
1209
3267
|
var import_yaml2 = require("yaml");
|
|
1210
3268
|
function parseImportersFromLock(workspaceRoot) {
|
|
1211
|
-
const lockPath =
|
|
1212
|
-
if (!(0,
|
|
3269
|
+
const lockPath = import_node_path17.default.join(workspaceRoot, "pnpm-lock.yaml");
|
|
3270
|
+
if (!(0, import_node_fs10.existsSync)(lockPath)) {
|
|
1213
3271
|
return [];
|
|
1214
3272
|
}
|
|
1215
3273
|
try {
|
|
1216
|
-
const parsed = (0, import_yaml2.parse)((0,
|
|
3274
|
+
const parsed = (0, import_yaml2.parse)((0, import_node_fs10.readFileSync)(lockPath, "utf8"));
|
|
1217
3275
|
const importers = parsed?.importers;
|
|
1218
3276
|
if (!importers) {
|
|
1219
3277
|
return [];
|
|
@@ -1222,7 +3280,7 @@ function parseImportersFromLock(workspaceRoot) {
|
|
|
1222
3280
|
if (!key || key === ".") {
|
|
1223
3281
|
return workspaceRoot;
|
|
1224
3282
|
}
|
|
1225
|
-
return
|
|
3283
|
+
return import_node_path17.default.join(workspaceRoot, key);
|
|
1226
3284
|
});
|
|
1227
3285
|
} catch {
|
|
1228
3286
|
return [];
|
|
@@ -1235,7 +3293,7 @@ var TRAILING_SLASH_RE = /\/+$/;
|
|
|
1235
3293
|
async function resolveWorkspacePackageDirs(workspaceRoot) {
|
|
1236
3294
|
const dirs = /* @__PURE__ */ new Set();
|
|
1237
3295
|
for (const importerDir of parseImportersFromLock(workspaceRoot)) {
|
|
1238
|
-
dirs.add(
|
|
3296
|
+
dirs.add(import_node_path18.default.normalize(importerDir));
|
|
1239
3297
|
}
|
|
1240
3298
|
if (!dirs.size) {
|
|
1241
3299
|
let globs = parseWorkspaceGlobsFromWorkspaceFile(workspaceRoot);
|
|
@@ -1255,13 +3313,13 @@ async function resolveWorkspacePackageDirs(workspaceRoot) {
|
|
|
1255
3313
|
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1256
3314
|
});
|
|
1257
3315
|
for (const file of packageJsonFiles) {
|
|
1258
|
-
dirs.add(
|
|
3316
|
+
dirs.add(import_node_path18.default.normalize(import_node_path18.default.dirname(file)));
|
|
1259
3317
|
}
|
|
1260
3318
|
}
|
|
1261
3319
|
}
|
|
1262
|
-
const rootPkg =
|
|
1263
|
-
if ((0,
|
|
1264
|
-
dirs.add(
|
|
3320
|
+
const rootPkg = import_node_path18.default.join(workspaceRoot, "package.json");
|
|
3321
|
+
if ((0, import_node_fs11.existsSync)(rootPkg)) {
|
|
3322
|
+
dirs.add(import_node_path18.default.normalize(workspaceRoot));
|
|
1265
3323
|
}
|
|
1266
3324
|
return [...dirs];
|
|
1267
3325
|
}
|
|
@@ -1270,9 +3328,9 @@ async function resolveWorkspacePackageDirs(workspaceRoot) {
|
|
|
1270
3328
|
var import_tailwindcss_patch2 = require("tailwindcss-patch");
|
|
1271
3329
|
|
|
1272
3330
|
// src/cli/workspace/patch-utils.ts
|
|
1273
|
-
var
|
|
3331
|
+
var import_node_path19 = __toESM(require("path"));
|
|
1274
3332
|
function formatDisplayName(workspaceRoot, dir, name) {
|
|
1275
|
-
const relative =
|
|
3333
|
+
const relative = import_node_path19.default.relative(workspaceRoot, dir) || ".";
|
|
1276
3334
|
return name ? `${name} (${relative})` : relative;
|
|
1277
3335
|
}
|
|
1278
3336
|
function summarizeWorkspaceResults(results) {
|
|
@@ -1345,7 +3403,7 @@ async function patchWorkspacePackage(workspaceRoot, dir, pkgName, options) {
|
|
|
1345
3403
|
|
|
1346
3404
|
// src/cli/workspace.ts
|
|
1347
3405
|
async function patchWorkspace(options) {
|
|
1348
|
-
const cwd = options.cwd ??
|
|
3406
|
+
const cwd = options.cwd ?? import_node_process17.default.cwd();
|
|
1349
3407
|
const workspaceRoot = findWorkspaceRoot(cwd) ?? cwd;
|
|
1350
3408
|
const packageDirs = await resolveWorkspacePackageDirs(workspaceRoot);
|
|
1351
3409
|
if (packageDirs.length === 0) {
|
|
@@ -1354,8 +3412,8 @@ async function patchWorkspace(options) {
|
|
|
1354
3412
|
}
|
|
1355
3413
|
const results = [];
|
|
1356
3414
|
for (const dir of packageDirs) {
|
|
1357
|
-
const pkgJsonPath =
|
|
1358
|
-
const pkgJson =
|
|
3415
|
+
const pkgJsonPath = import_node_path20.default.join(dir, "package.json");
|
|
3416
|
+
const pkgJson = tryReadJson2(pkgJsonPath);
|
|
1359
3417
|
results.push(await patchWorkspacePackage(workspaceRoot, dir, pkgJson?.name, options));
|
|
1360
3418
|
}
|
|
1361
3419
|
summarizeWorkspaceResults(results);
|
|
@@ -1365,7 +3423,7 @@ async function patchWorkspace(options) {
|
|
|
1365
3423
|
function handleCliError2(error) {
|
|
1366
3424
|
if (error instanceof Error) {
|
|
1367
3425
|
import_logger13.logger.error(error.message);
|
|
1368
|
-
if (error.stack &&
|
|
3426
|
+
if (error.stack && import_node_process18.default.env.WEAPP_TW_DEBUG === "1") {
|
|
1369
3427
|
import_logger13.logger.error(error.stack);
|
|
1370
3428
|
}
|
|
1371
3429
|
} else {
|
|
@@ -1378,7 +3436,7 @@ function withCommandErrorHandling(handler) {
|
|
|
1378
3436
|
return await handler(ctx, next);
|
|
1379
3437
|
} catch (error) {
|
|
1380
3438
|
handleCliError2(error);
|
|
1381
|
-
|
|
3439
|
+
import_node_process18.default.exitCode = 1;
|
|
1382
3440
|
return void 0;
|
|
1383
3441
|
}
|
|
1384
3442
|
});
|
|
@@ -1486,16 +3544,16 @@ var mountOptions = {
|
|
|
1486
3544
|
};
|
|
1487
3545
|
|
|
1488
3546
|
// src/cli/vscode-entry.ts
|
|
1489
|
-
var
|
|
3547
|
+
var import_node_fs12 = require("fs");
|
|
1490
3548
|
var import_promises4 = require("fs/promises");
|
|
1491
|
-
var
|
|
3549
|
+
var import_node_path21 = __toESM(require("path"));
|
|
1492
3550
|
var DEFAULT_VSCODE_ENTRY_OUTPUT = ".vscode/weapp-tailwindcss.intellisense.css";
|
|
1493
3551
|
var DEFAULT_VSCODE_SOURCES = [
|
|
1494
3552
|
'not "./dist"',
|
|
1495
3553
|
'not "./unpackage"',
|
|
1496
3554
|
"./src/**/*.{wxml,axml,swan,qml,ttml,ux,uts}",
|
|
1497
|
-
"./src/**/*.{js,jsx,ts,tsx}",
|
|
1498
|
-
"./src/**/*.{vue,svelte,html,md,mdx}"
|
|
3555
|
+
"./src/**/*.{js,jsx,ts,tsx,mjs,cjs,wxs,sjs}",
|
|
3556
|
+
"./src/**/*.{vue,svelte,mpx,html,md,mdx}"
|
|
1499
3557
|
];
|
|
1500
3558
|
var SINGLE_QUOTE = "'";
|
|
1501
3559
|
var DOUBLE_QUOTE = '"';
|
|
@@ -1505,7 +3563,7 @@ function toPosixPath(filepath) {
|
|
|
1505
3563
|
}
|
|
1506
3564
|
async function assertFileExists(filepath) {
|
|
1507
3565
|
try {
|
|
1508
|
-
await (0, import_promises4.access)(filepath,
|
|
3566
|
+
await (0, import_promises4.access)(filepath, import_node_fs12.constants.F_OK);
|
|
1509
3567
|
} catch (error) {
|
|
1510
3568
|
const err = error;
|
|
1511
3569
|
if (err?.code === "ENOENT") {
|
|
@@ -1516,7 +3574,7 @@ async function assertFileExists(filepath) {
|
|
|
1516
3574
|
}
|
|
1517
3575
|
async function assertCanWrite(filepath, force) {
|
|
1518
3576
|
try {
|
|
1519
|
-
await (0, import_promises4.access)(filepath,
|
|
3577
|
+
await (0, import_promises4.access)(filepath, import_node_fs12.constants.F_OK);
|
|
1520
3578
|
if (!force) {
|
|
1521
3579
|
throw new Error(
|
|
1522
3580
|
`VS Code helper already exists at ${filepath}. Re-run with --force to overwrite it.`
|
|
@@ -1561,16 +3619,16 @@ function formatSource(pattern) {
|
|
|
1561
3619
|
}
|
|
1562
3620
|
function resolveOutputPath(baseDir, output) {
|
|
1563
3621
|
const target = output ?? DEFAULT_VSCODE_ENTRY_OUTPUT;
|
|
1564
|
-
return
|
|
3622
|
+
return import_node_path21.default.isAbsolute(target) ? import_node_path21.default.normalize(target) : import_node_path21.default.resolve(baseDir, target);
|
|
1565
3623
|
}
|
|
1566
3624
|
function resolveCssEntry(baseDir, entry) {
|
|
1567
|
-
return
|
|
3625
|
+
return import_node_path21.default.isAbsolute(entry) ? import_node_path21.default.normalize(entry) : import_node_path21.default.resolve(baseDir, entry);
|
|
1568
3626
|
}
|
|
1569
3627
|
function toRelativeImport(fromFile, targetFile) {
|
|
1570
|
-
const fromDir =
|
|
1571
|
-
let relative =
|
|
3628
|
+
const fromDir = import_node_path21.default.dirname(fromFile);
|
|
3629
|
+
let relative = import_node_path21.default.relative(fromDir, targetFile);
|
|
1572
3630
|
if (!relative) {
|
|
1573
|
-
relative =
|
|
3631
|
+
relative = import_node_path21.default.basename(targetFile);
|
|
1574
3632
|
}
|
|
1575
3633
|
if (!relative.startsWith(".")) {
|
|
1576
3634
|
relative = `./${relative}`;
|
|
@@ -1582,7 +3640,7 @@ async function generateVscodeIntellisenseEntry(options) {
|
|
|
1582
3640
|
const cssEntryPath = resolveCssEntry(baseDir, options.cssEntry);
|
|
1583
3641
|
await assertFileExists(cssEntryPath);
|
|
1584
3642
|
const outputPath = resolveOutputPath(baseDir, options.output);
|
|
1585
|
-
await ensureDir(
|
|
3643
|
+
await ensureDir(import_node_path21.default.dirname(outputPath));
|
|
1586
3644
|
await assertCanWrite(outputPath, options.force);
|
|
1587
3645
|
const sources = options.sources && options.sources.length > 0 ? options.sources : DEFAULT_VSCODE_SOURCES;
|
|
1588
3646
|
const formattedSources = sources.map(formatSource).filter((statement) => Boolean(statement));
|
|
@@ -1607,10 +3665,10 @@ async function generateVscodeIntellisenseEntry(options) {
|
|
|
1607
3665
|
}
|
|
1608
3666
|
|
|
1609
3667
|
// src/cli.ts
|
|
1610
|
-
|
|
1611
|
-
if (
|
|
3668
|
+
import_node_process19.default.title = "node (weapp-tailwindcss)";
|
|
3669
|
+
if (!import_semver2.default.satisfies(import_node_process19.default.versions.node, WEAPP_TW_REQUIRED_NODE_VERSION_RANGE)) {
|
|
1612
3670
|
import_logger13.logger.warn(
|
|
1613
|
-
`You are using Node.js ${
|
|
3671
|
+
`You are using Node.js ${import_node_process19.default.versions.node}. For weapp-tailwindcss, Node.js version ${WEAPP_TW_REQUIRED_NODE_VERSION_RANGE} is required.`
|
|
1614
3672
|
);
|
|
1615
3673
|
}
|
|
1616
3674
|
var cli = (0, import_tailwindcss_patch3.createTailwindcssPatchCli)({
|
|
@@ -1620,7 +3678,7 @@ var cli = (0, import_tailwindcss_patch3.createTailwindcssPatchCli)({
|
|
|
1620
3678
|
cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliSense").option("--cwd <dir>", "Working directory").option("--css <file>", "Path to the CSS file that imports weapp-tailwindcss (required)").option("--output <file>", `Helper output path. Defaults to ${DEFAULT_VSCODE_ENTRY_OUTPUT}`).option("--source <pattern>", "Additional @source glob (can be repeated)").option("--force", "Overwrite the helper file when it already exists").action(
|
|
1621
3679
|
commandAction(async (options) => {
|
|
1622
3680
|
const resolvedCwd = resolveCliCwd(options.cwd);
|
|
1623
|
-
const baseDir = resolvedCwd ??
|
|
3681
|
+
const baseDir = resolvedCwd ?? import_node_process19.default.cwd();
|
|
1624
3682
|
const cssEntry = readStringOption("css", options.css);
|
|
1625
3683
|
if (!cssEntry) {
|
|
1626
3684
|
throw new Error('Option "--css" is required.');
|
|
@@ -1640,6 +3698,20 @@ cli.command("vscode-entry", "Generate a VS Code helper CSS for Tailwind IntelliS
|
|
|
1640
3698
|
);
|
|
1641
3699
|
})
|
|
1642
3700
|
);
|
|
3701
|
+
cli.command("doctor", "Check project setup for weapp-tailwindcss").option("--cwd <dir>", "Working directory").option("--json", "Print a JSON report").option("--strict", "Exit with code 1 when warnings are found").action(
|
|
3702
|
+
commandAction(async (options) => {
|
|
3703
|
+
const resolvedCwd = resolveCliCwd(options.cwd);
|
|
3704
|
+
const report = createDoctorReport({ cwd: resolvedCwd });
|
|
3705
|
+
if (toBoolean(options.json, false)) {
|
|
3706
|
+
import_logger13.logger.log(JSON.stringify(report, null, 2));
|
|
3707
|
+
} else {
|
|
3708
|
+
import_logger13.logger.log(formatDoctorReport(report));
|
|
3709
|
+
}
|
|
3710
|
+
if (hasDoctorFailure(report, toBoolean(options.strict, false))) {
|
|
3711
|
+
import_node_process19.default.exitCode = 1;
|
|
3712
|
+
}
|
|
3713
|
+
})
|
|
3714
|
+
);
|
|
1643
3715
|
cli.help();
|
|
1644
|
-
cli.version(
|
|
3716
|
+
cli.version(import_node_process19.default.env.npm_package_version ?? "0.0.0");
|
|
1645
3717
|
cli.parse();
|