weapp-vite 6.1.11 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-routes.mjs +3 -3
- package/dist/{chunk-5PIOVA35.mjs → chunk-2GIOG6RC.mjs} +117 -56
- package/dist/{chunk-5HAJ3FAL.mjs → chunk-FC2MZYU3.mjs} +66 -2
- package/dist/{chunk-QOUJL7WX.mjs → chunk-M2DQHZBW.mjs} +1 -1
- package/dist/{chunk-KB3SOFHU.mjs → chunk-QVXE3ABR.mjs} +1392 -871
- package/dist/cli.mjs +32 -6
- package/dist/{config-BWWRobaC.d.ts → config-B2MoO2Hh.d.ts} +23 -7
- package/dist/config.d.ts +2 -2
- package/dist/{file-C7ZTAE5G.mjs → file-JVATZEJQ.mjs} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +4 -4
- package/dist/json.d.ts +1 -1
- package/dist/{jsonMacros-HN23LCSO.mjs → jsonMacros-VSJW5D23.mjs} +2 -2
- package/dist/types.d.ts +1 -1
- package/package.json +26 -32
- package/volar.cjs +3 -0
- package/dist/auto-import-components/resolvers.cjs +0 -359
- package/dist/auto-import-components/resolvers.d.cts +0 -10
- package/dist/auto-routes.cjs +0 -53
- package/dist/auto-routes.d.cts +0 -10
- package/dist/chunk-2CHNKORP.cjs +0 -29
- package/dist/chunk-53RK3GBH.cjs +0 -6
- package/dist/chunk-AOXSTOWS.cjs +0 -309
- package/dist/chunk-E2Y62AWE.cjs +0 -1668
- package/dist/chunk-HL25C7YQ.cjs +0 -13
- package/dist/chunk-HRJEZONN.cjs +0 -34
- package/dist/chunk-PFE2IVZ3.cjs +0 -45
- package/dist/chunk-PKMO2BH6.cjs +0 -33
- package/dist/chunk-SP5GJ7QP.cjs +0 -40496
- package/dist/cli.cjs +0 -2012
- package/dist/cli.d.cts +0 -2
- package/dist/config-C7v_wuTW.d.cts +0 -1003
- package/dist/config.cjs +0 -19
- package/dist/config.d.cts +0 -15
- package/dist/file-Q3KQERJD.cjs +0 -29
- package/dist/index.cjs +0 -40
- package/dist/index.d.cts +0 -23
- package/dist/json.cjs +0 -15
- package/dist/json.d.cts +0 -15
- package/dist/jsonMacros-H3SIUXIW.cjs +0 -10
- package/dist/routes-C9hKJjXs.d.cts +0 -11
- package/dist/runtime.cjs +0 -11
- package/dist/runtime.d.cts +0 -29
- package/dist/types-Dxi4LfZo.d.cts +0 -46
- package/dist/types.cjs +0 -25
- package/dist/types.d.cts +0 -26
- package/dist/volar.cjs +0 -13
- package/dist/volar.d.cts +0 -2
package/dist/auto-routes.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getCompilerContext
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-QVXE3ABR.mjs";
|
|
4
|
+
import "./chunk-2GIOG6RC.mjs";
|
|
5
|
+
import "./chunk-FC2MZYU3.mjs";
|
|
6
6
|
import "./chunk-AZBN7A5I.mjs";
|
|
7
7
|
import "./chunk-V5RMQ6TF.mjs";
|
|
8
8
|
import {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
jsExtensions,
|
|
4
4
|
require_src,
|
|
5
5
|
vueExtensions
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FC2MZYU3.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__commonJS,
|
|
9
9
|
__toESM,
|
|
@@ -559,9 +559,9 @@ function declaredNamesInStatement(statement) {
|
|
|
559
559
|
}
|
|
560
560
|
return out;
|
|
561
561
|
}
|
|
562
|
-
function collectTopLevelReferencedNames(
|
|
562
|
+
function collectTopLevelReferencedNames(path12) {
|
|
563
563
|
const names = /* @__PURE__ */ new Set();
|
|
564
|
-
|
|
564
|
+
path12.traverse({
|
|
565
565
|
Identifier(p) {
|
|
566
566
|
if (!p.isReferencedIdentifier()) {
|
|
567
567
|
return;
|
|
@@ -626,7 +626,7 @@ var import_merge = __toESM(require_src(), 1);
|
|
|
626
626
|
import * as t3 from "@babel/types";
|
|
627
627
|
import fs5 from "fs-extra";
|
|
628
628
|
import MagicString2 from "magic-string";
|
|
629
|
-
import
|
|
629
|
+
import path11 from "pathe";
|
|
630
630
|
import { bundleRequire } from "rolldown-require";
|
|
631
631
|
|
|
632
632
|
// src/plugins/vue/transform/tempDirLock.ts
|
|
@@ -655,7 +655,7 @@ async function withTempDirLock(tempDir, fn) {
|
|
|
655
655
|
init_esm_shims();
|
|
656
656
|
import * as t2 from "@babel/types";
|
|
657
657
|
import MagicString from "magic-string";
|
|
658
|
-
import
|
|
658
|
+
import path9 from "pathe";
|
|
659
659
|
|
|
660
660
|
// src/utils/index.ts
|
|
661
661
|
init_esm_shims();
|
|
@@ -736,10 +736,70 @@ function getReadFileCheckMtime(config) {
|
|
|
736
736
|
return Boolean(config?.isDev);
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
+
// src/utils/configErrors.ts
|
|
740
|
+
init_esm_shims();
|
|
741
|
+
import path from "pathe";
|
|
742
|
+
var CJS_ERROR_PATTERNS = [
|
|
743
|
+
"__dirname is not defined",
|
|
744
|
+
"__filename is not defined",
|
|
745
|
+
"require is not defined",
|
|
746
|
+
"module is not defined",
|
|
747
|
+
"exports is not defined",
|
|
748
|
+
"es module scope"
|
|
749
|
+
];
|
|
750
|
+
function collectErrorText(error, texts) {
|
|
751
|
+
if (!error) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
if (typeof error === "string") {
|
|
755
|
+
texts.push(error);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
if (typeof error === "object") {
|
|
759
|
+
const err = error;
|
|
760
|
+
if (err.message) {
|
|
761
|
+
texts.push(String(err.message));
|
|
762
|
+
}
|
|
763
|
+
if (err.stack) {
|
|
764
|
+
texts.push(String(err.stack));
|
|
765
|
+
}
|
|
766
|
+
if ("cause" in err) {
|
|
767
|
+
collectErrorText(err.cause, texts);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function formatConfigPath(configPath, cwd) {
|
|
772
|
+
if (!configPath) {
|
|
773
|
+
return "vite.config.ts";
|
|
774
|
+
}
|
|
775
|
+
const relative = path.relative(cwd, configPath);
|
|
776
|
+
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) {
|
|
777
|
+
return relative;
|
|
778
|
+
}
|
|
779
|
+
return configPath;
|
|
780
|
+
}
|
|
781
|
+
function createCjsConfigLoadError(options) {
|
|
782
|
+
const texts = [];
|
|
783
|
+
collectErrorText(options.error, texts);
|
|
784
|
+
const haystack = texts.join("\n").toLowerCase();
|
|
785
|
+
const isCjsError = CJS_ERROR_PATTERNS.some((pattern) => haystack.includes(pattern));
|
|
786
|
+
if (!isCjsError) {
|
|
787
|
+
return void 0;
|
|
788
|
+
}
|
|
789
|
+
const target = formatConfigPath(options.configPath, options.cwd);
|
|
790
|
+
const message = `${target} \u4E3A CJS \u683C\u5F0F\uFF0C\u9700\u8981\u6539\u4E3A ESM \u5199\u6CD5\uFF08\u53EF\u53C2\u8003 import.meta.dirname \u7B49\u7528\u6CD5\uFF09\u3002`;
|
|
791
|
+
const error = new Error(message);
|
|
792
|
+
if (options.error instanceof Error) {
|
|
793
|
+
;
|
|
794
|
+
error.cause = options.error;
|
|
795
|
+
}
|
|
796
|
+
return error;
|
|
797
|
+
}
|
|
798
|
+
|
|
739
799
|
// src/utils/entryResolve.ts
|
|
740
800
|
init_esm_shims();
|
|
741
801
|
import fs from "fs-extra";
|
|
742
|
-
import
|
|
802
|
+
import path2 from "pathe";
|
|
743
803
|
function buildCandidates(base, extensions) {
|
|
744
804
|
return extensions.map((ext) => changeFileExtension(base, ext));
|
|
745
805
|
}
|
|
@@ -747,7 +807,7 @@ async function resolveEntryPath(input, options) {
|
|
|
747
807
|
if (!input || typeof input !== "string") {
|
|
748
808
|
return void 0;
|
|
749
809
|
}
|
|
750
|
-
if (
|
|
810
|
+
if (path2.extname(input)) {
|
|
751
811
|
return void 0;
|
|
752
812
|
}
|
|
753
813
|
const kind = options?.kind ?? "default";
|
|
@@ -762,7 +822,7 @@ async function resolveEntryPath(input, options) {
|
|
|
762
822
|
isDir = false;
|
|
763
823
|
}
|
|
764
824
|
if (isDir) {
|
|
765
|
-
base =
|
|
825
|
+
base = path2.join(input, indexBaseName);
|
|
766
826
|
}
|
|
767
827
|
const jsFirst = kind === "named" || isDir;
|
|
768
828
|
const extensions = jsFirst ? [...jsExtensions, ...vueExtensions] : [...vueExtensions, ...jsExtensions];
|
|
@@ -778,7 +838,7 @@ async function resolveEntryPath(input, options) {
|
|
|
778
838
|
init_esm_shims();
|
|
779
839
|
import { get, isObject, set } from "@weapp-core/shared";
|
|
780
840
|
import { parse as parseJson, stringify } from "comment-json";
|
|
781
|
-
import
|
|
841
|
+
import path3 from "pathe";
|
|
782
842
|
function parseCommentJson(json) {
|
|
783
843
|
return parseJson(json, void 0, true);
|
|
784
844
|
}
|
|
@@ -826,7 +886,7 @@ function resolveImportee(importee, jsonPath, aliasEntries) {
|
|
|
826
886
|
return importee;
|
|
827
887
|
}
|
|
828
888
|
const updatedId = importee.replace(matchedEntry.find, matchedEntry.replacement);
|
|
829
|
-
return
|
|
889
|
+
return path3.relative(path3.dirname(jsonPath), updatedId);
|
|
830
890
|
}
|
|
831
891
|
return importee;
|
|
832
892
|
}
|
|
@@ -870,7 +930,7 @@ import crypto from "crypto";
|
|
|
870
930
|
// src/utils/path.ts
|
|
871
931
|
init_esm_shims();
|
|
872
932
|
import { sep } from "path";
|
|
873
|
-
import
|
|
933
|
+
import path4 from "pathe";
|
|
874
934
|
var BACKSLASH_RE = /\\/g;
|
|
875
935
|
var LEADING_SLASH_RE = /^[\\/]+/;
|
|
876
936
|
var DUPLICATE_SLASH_RE = /\/{2,}/g;
|
|
@@ -891,17 +951,17 @@ function isPathInside(parent, target) {
|
|
|
891
951
|
if (!parent) {
|
|
892
952
|
return false;
|
|
893
953
|
}
|
|
894
|
-
const relative =
|
|
895
|
-
return relative === "" || !relative.startsWith("..") && !
|
|
954
|
+
const relative = path4.relative(parent, target);
|
|
955
|
+
return relative === "" || !relative.startsWith("..") && !path4.isAbsolute(relative);
|
|
896
956
|
}
|
|
897
957
|
|
|
898
958
|
// src/utils/projectConfig.ts
|
|
899
959
|
init_esm_shims();
|
|
900
960
|
import fs2 from "fs-extra";
|
|
901
|
-
import
|
|
961
|
+
import path5 from "pathe";
|
|
902
962
|
async function getProjectConfig(root, options) {
|
|
903
|
-
const baseJsonPath =
|
|
904
|
-
const privateJsonPath =
|
|
963
|
+
const baseJsonPath = path5.resolve(root, "project.config.json");
|
|
964
|
+
const privateJsonPath = path5.resolve(root, "project.private.config.json");
|
|
905
965
|
let baseJson = {};
|
|
906
966
|
let privateJson = {};
|
|
907
967
|
if (await fs2.pathExists(baseJsonPath)) {
|
|
@@ -1114,33 +1174,33 @@ function normalizeFsResolvedId(id, options) {
|
|
|
1114
1174
|
|
|
1115
1175
|
// src/utils/toAbsoluteId.ts
|
|
1116
1176
|
init_esm_shims();
|
|
1117
|
-
import
|
|
1177
|
+
import path6 from "pathe";
|
|
1118
1178
|
function toAbsoluteId(id, configService, importer, options) {
|
|
1119
1179
|
const cleanId = normalizeFsResolvedId(id);
|
|
1120
1180
|
if (!cleanId || isSkippableResolvedId(cleanId)) {
|
|
1121
1181
|
return cleanId;
|
|
1122
1182
|
}
|
|
1123
|
-
if (
|
|
1183
|
+
if (path6.isAbsolute(cleanId)) {
|
|
1124
1184
|
return cleanId;
|
|
1125
1185
|
}
|
|
1126
1186
|
const cleanImporter = importer ? normalizeFsResolvedId(importer) : void 0;
|
|
1127
|
-
if (cleanImporter && !isSkippableResolvedId(cleanImporter) &&
|
|
1128
|
-
return
|
|
1187
|
+
if (cleanImporter && !isSkippableResolvedId(cleanImporter) && path6.isAbsolute(cleanImporter)) {
|
|
1188
|
+
return path6.resolve(path6.dirname(cleanImporter), cleanId);
|
|
1129
1189
|
}
|
|
1130
1190
|
const baseDir = options?.base === "cwd" ? configService.cwd : configService.absoluteSrcRoot;
|
|
1131
|
-
return
|
|
1191
|
+
return path6.resolve(baseDir, cleanId);
|
|
1132
1192
|
}
|
|
1133
1193
|
|
|
1134
1194
|
// src/utils/usingComponentFrom.ts
|
|
1135
1195
|
init_esm_shims();
|
|
1136
1196
|
import { removeExtensionDeep } from "@weapp-core/shared";
|
|
1137
|
-
import
|
|
1197
|
+
import path7 from "pathe";
|
|
1138
1198
|
function usingComponentFromResolvedFile(resolvedFile, configService) {
|
|
1139
1199
|
if (!resolvedFile) {
|
|
1140
1200
|
return void 0;
|
|
1141
1201
|
}
|
|
1142
1202
|
const normalized = normalizeFsResolvedId(resolvedFile);
|
|
1143
|
-
if (!normalized || isSkippableResolvedId(normalized) || !
|
|
1203
|
+
if (!normalized || isSkippableResolvedId(normalized) || !path7.isAbsolute(normalized)) {
|
|
1144
1204
|
return void 0;
|
|
1145
1205
|
}
|
|
1146
1206
|
const base = removeExtensionDeep(normalized);
|
|
@@ -1199,7 +1259,7 @@ function checkRuntime(minVersions) {
|
|
|
1199
1259
|
// src/utils/weappConfig.ts
|
|
1200
1260
|
init_esm_shims();
|
|
1201
1261
|
import fs3 from "fs-extra";
|
|
1202
|
-
import
|
|
1262
|
+
import path8 from "pathe";
|
|
1203
1263
|
var WEAPP_VITE_CONFIG_CANDIDATES = [
|
|
1204
1264
|
"weapp-vite.config.ts",
|
|
1205
1265
|
"weapp-vite.config.mts",
|
|
@@ -1212,7 +1272,7 @@ var WEAPP_VITE_CONFIG_CANDIDATES = [
|
|
|
1212
1272
|
var WEAPP_VITE_CONFIG_SET = new Set(WEAPP_VITE_CONFIG_CANDIDATES);
|
|
1213
1273
|
async function findWeappConfigInDirectory(directory) {
|
|
1214
1274
|
for (const filename of WEAPP_VITE_CONFIG_CANDIDATES) {
|
|
1215
|
-
const candidatePath =
|
|
1275
|
+
const candidatePath = path8.resolve(directory, filename);
|
|
1216
1276
|
if (await fs3.pathExists(candidatePath)) {
|
|
1217
1277
|
return candidatePath;
|
|
1218
1278
|
}
|
|
@@ -1222,15 +1282,15 @@ async function findWeappConfigInDirectory(directory) {
|
|
|
1222
1282
|
async function resolveWeappConfigFile(options) {
|
|
1223
1283
|
const { root, specified } = options;
|
|
1224
1284
|
if (specified) {
|
|
1225
|
-
const resolvedSpecified =
|
|
1226
|
-
const specifiedBaseName =
|
|
1285
|
+
const resolvedSpecified = path8.isAbsolute(specified) ? specified : path8.resolve(root, specified);
|
|
1286
|
+
const specifiedBaseName = path8.basename(resolvedSpecified);
|
|
1227
1287
|
if (WEAPP_VITE_CONFIG_SET.has(specifiedBaseName)) {
|
|
1228
1288
|
if (await fs3.pathExists(resolvedSpecified)) {
|
|
1229
1289
|
return resolvedSpecified;
|
|
1230
1290
|
}
|
|
1231
1291
|
return void 0;
|
|
1232
1292
|
}
|
|
1233
|
-
const fromSpecifiedDirectory = await findWeappConfigInDirectory(
|
|
1293
|
+
const fromSpecifiedDirectory = await findWeappConfigInDirectory(path8.dirname(resolvedSpecified));
|
|
1234
1294
|
if (fromSpecifiedDirectory) {
|
|
1235
1295
|
return fromSpecifiedDirectory;
|
|
1236
1296
|
}
|
|
@@ -1243,8 +1303,8 @@ function rewriteRelativeImportSource(source, fromDir, tempDir) {
|
|
|
1243
1303
|
if (!source.startsWith(".")) {
|
|
1244
1304
|
return source;
|
|
1245
1305
|
}
|
|
1246
|
-
const abs =
|
|
1247
|
-
let next = toPosixPath(
|
|
1306
|
+
const abs = path9.resolve(fromDir, source);
|
|
1307
|
+
let next = toPosixPath(path9.relative(tempDir, abs));
|
|
1248
1308
|
if (!next.startsWith(".")) {
|
|
1249
1309
|
next = `./${next}`;
|
|
1250
1310
|
}
|
|
@@ -1312,23 +1372,23 @@ import { createHash } from "crypto";
|
|
|
1312
1372
|
import fs4 from "fs";
|
|
1313
1373
|
import os from "os";
|
|
1314
1374
|
import process3 from "process";
|
|
1315
|
-
import
|
|
1375
|
+
import path10 from "pathe";
|
|
1316
1376
|
function getWevuConfigCacheRoot() {
|
|
1317
1377
|
const env = process3.env.WEAPP_VITE_WEVU_CONFIG_DIR?.trim();
|
|
1318
1378
|
if (env) {
|
|
1319
|
-
return
|
|
1379
|
+
return path10.resolve(env);
|
|
1320
1380
|
}
|
|
1321
1381
|
const cwd = process3.cwd();
|
|
1322
|
-
const nodeModulesDir =
|
|
1382
|
+
const nodeModulesDir = path10.join(cwd, "node_modules");
|
|
1323
1383
|
if (fs4.existsSync(nodeModulesDir)) {
|
|
1324
|
-
return
|
|
1384
|
+
return path10.join(nodeModulesDir, ".cache", "weapp-vite", "wevu-config");
|
|
1325
1385
|
}
|
|
1326
|
-
return
|
|
1386
|
+
return path10.join(os.tmpdir(), "weapp-vite", "wevu-config");
|
|
1327
1387
|
}
|
|
1328
1388
|
function resolveWevuConfigTempDir(fromDir) {
|
|
1329
1389
|
const root = getWevuConfigCacheRoot();
|
|
1330
|
-
const key = createHash("sha256").update(
|
|
1331
|
-
return
|
|
1390
|
+
const key = createHash("sha256").update(path10.normalize(fromDir)).digest("hex").slice(0, 8);
|
|
1391
|
+
return path10.join(root, key);
|
|
1332
1392
|
}
|
|
1333
1393
|
|
|
1334
1394
|
// src/plugins/vue/transform/jsonMacros/execute.ts
|
|
@@ -1364,7 +1424,7 @@ async function evaluateScriptSetupJsonMacro(params) {
|
|
|
1364
1424
|
options
|
|
1365
1425
|
} = params;
|
|
1366
1426
|
const ms = new MagicString2(originalContent);
|
|
1367
|
-
const dir =
|
|
1427
|
+
const dir = path11.dirname(filename);
|
|
1368
1428
|
const tempDir = resolveWevuConfigTempDir(dir);
|
|
1369
1429
|
for (const statementPath of keptStatementPaths) {
|
|
1370
1430
|
if (!statementPath.isImportDeclaration()) {
|
|
@@ -1414,12 +1474,12 @@ export default __weapp_json_macro_values
|
|
|
1414
1474
|
const extension = resolveScriptSetupExtension(lang);
|
|
1415
1475
|
return await withTempDirLock(tempDir, async () => {
|
|
1416
1476
|
await fs5.ensureDir(tempDir);
|
|
1417
|
-
const basename =
|
|
1477
|
+
const basename = path11.basename(filename, path11.extname(filename));
|
|
1418
1478
|
const unique = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
1419
|
-
const tempFile =
|
|
1479
|
+
const tempFile = path11.join(tempDir, `${basename}.json-macro.${unique}.${extension}`);
|
|
1420
1480
|
await fs5.writeFile(tempFile, evalSource, "utf8");
|
|
1421
1481
|
try {
|
|
1422
|
-
const { mod } = await bundleRequire({
|
|
1482
|
+
const { mod, dependencies } = await bundleRequire({
|
|
1423
1483
|
filepath: tempFile,
|
|
1424
1484
|
cwd: dir
|
|
1425
1485
|
});
|
|
@@ -1453,9 +1513,9 @@ export default __weapp_json_macro_values
|
|
|
1453
1513
|
}
|
|
1454
1514
|
}
|
|
1455
1515
|
if (!Object.keys(accumulator).length) {
|
|
1456
|
-
return
|
|
1516
|
+
return { dependencies };
|
|
1457
1517
|
}
|
|
1458
|
-
return accumulator;
|
|
1518
|
+
return { config: accumulator, dependencies };
|
|
1459
1519
|
} finally {
|
|
1460
1520
|
try {
|
|
1461
1521
|
await fs5.remove(tempFile);
|
|
@@ -1488,20 +1548,20 @@ function collectMacroCallPaths(ast, filename) {
|
|
|
1488
1548
|
const macroNames = /* @__PURE__ */ new Set();
|
|
1489
1549
|
const macroStatements = [];
|
|
1490
1550
|
traverse(ast, {
|
|
1491
|
-
CallExpression(
|
|
1492
|
-
const callee =
|
|
1551
|
+
CallExpression(path12) {
|
|
1552
|
+
const callee = path12.node.callee;
|
|
1493
1553
|
if (!t4.isIdentifier(callee)) {
|
|
1494
1554
|
return;
|
|
1495
1555
|
}
|
|
1496
1556
|
if (!JSON_MACROS.has(callee.name)) {
|
|
1497
1557
|
return;
|
|
1498
1558
|
}
|
|
1499
|
-
const isTopLevelStatement =
|
|
1559
|
+
const isTopLevelStatement = path12.parentPath?.isExpressionStatement() && path12.parentPath.parentPath?.isProgram();
|
|
1500
1560
|
if (!isTopLevelStatement) {
|
|
1501
1561
|
throw new Error(`${callee.name}() \u5FC5\u987B\u5728 <script setup> \u9876\u5C42\u8BED\u53E5\u4E2D\u4F7F\u7528\uFF08${filename}\uFF09\u3002`);
|
|
1502
1562
|
}
|
|
1503
1563
|
macroNames.add(callee.name);
|
|
1504
|
-
macroStatements.push(
|
|
1564
|
+
macroStatements.push(path12.parentPath);
|
|
1505
1565
|
}
|
|
1506
1566
|
});
|
|
1507
1567
|
return { macroNames, macroStatements };
|
|
@@ -1515,9 +1575,9 @@ function assertSingleMacro(macroNames, filename) {
|
|
|
1515
1575
|
function findProgramPath(ast) {
|
|
1516
1576
|
let programPath;
|
|
1517
1577
|
traverse(ast, {
|
|
1518
|
-
Program(
|
|
1519
|
-
programPath =
|
|
1520
|
-
|
|
1578
|
+
Program(path12) {
|
|
1579
|
+
programPath = path12;
|
|
1580
|
+
path12.stop();
|
|
1521
1581
|
}
|
|
1522
1582
|
});
|
|
1523
1583
|
return programPath;
|
|
@@ -1572,16 +1632,16 @@ function stripJsonMacroCallsFromCode(code, filename) {
|
|
|
1572
1632
|
}
|
|
1573
1633
|
const ms = new MagicString3(code);
|
|
1574
1634
|
traverse(ast, {
|
|
1575
|
-
ExpressionStatement(
|
|
1576
|
-
const expr =
|
|
1635
|
+
ExpressionStatement(path12) {
|
|
1636
|
+
const expr = path12.node.expression;
|
|
1577
1637
|
if (!t5.isCallExpression(expr) || !t5.isIdentifier(expr.callee)) {
|
|
1578
1638
|
return;
|
|
1579
1639
|
}
|
|
1580
1640
|
if (!JSON_MACROS.has(expr.callee.name)) {
|
|
1581
1641
|
return;
|
|
1582
1642
|
}
|
|
1583
|
-
const start =
|
|
1584
|
-
const end =
|
|
1643
|
+
const start = path12.node.start;
|
|
1644
|
+
const end = path12.node.end;
|
|
1585
1645
|
if (typeof start === "number" && typeof end === "number") {
|
|
1586
1646
|
ms.remove(start, end);
|
|
1587
1647
|
}
|
|
@@ -1600,8 +1660,8 @@ async function extractJsonMacroFromScriptSetup(content, filename, lang, options)
|
|
|
1600
1660
|
return { stripped };
|
|
1601
1661
|
}
|
|
1602
1662
|
const macroHash = createHash2("sha256").update(macroStatementSources.join("\n")).digest("hex").slice(0, 12);
|
|
1603
|
-
const
|
|
1604
|
-
return
|
|
1663
|
+
const result = await evaluateJsonMacroConfig(content, filename, lang, options);
|
|
1664
|
+
return result ? { stripped, config: result.config, macroHash, dependencies: result.dependencies } : { stripped, macroHash };
|
|
1605
1665
|
}
|
|
1606
1666
|
async function evaluateJsonMacroConfig(content, filename, lang, options) {
|
|
1607
1667
|
const ast = parseScriptSetupAst(content, filename);
|
|
@@ -1642,6 +1702,7 @@ export {
|
|
|
1642
1702
|
parseJsLike,
|
|
1643
1703
|
getPathExistsTtlMs,
|
|
1644
1704
|
getReadFileCheckMtime,
|
|
1705
|
+
createCjsConfigLoadError,
|
|
1645
1706
|
withTempDirLock,
|
|
1646
1707
|
rewriteJsLikeImportsForTempDir,
|
|
1647
1708
|
resolveWevuConfigTempDir,
|
|
@@ -113,6 +113,9 @@ var templateExtensions = ["wxml", "html"];
|
|
|
113
113
|
|
|
114
114
|
// src/utils/file.ts
|
|
115
115
|
var pathExistsInFlight = /* @__PURE__ */ new Map();
|
|
116
|
+
var vueConfigCache = /* @__PURE__ */ new Map();
|
|
117
|
+
var configMtimeInFlight = /* @__PURE__ */ new Map();
|
|
118
|
+
var NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
|
|
116
119
|
function pathExistsCached(filePath) {
|
|
117
120
|
const pending = pathExistsInFlight.get(filePath);
|
|
118
121
|
if (pending) {
|
|
@@ -124,6 +127,37 @@ function pathExistsCached(filePath) {
|
|
|
124
127
|
pathExistsInFlight.set(filePath, next);
|
|
125
128
|
return next;
|
|
126
129
|
}
|
|
130
|
+
function getMtimeCached(filePath) {
|
|
131
|
+
const pending = configMtimeInFlight.get(filePath);
|
|
132
|
+
if (pending) {
|
|
133
|
+
return pending;
|
|
134
|
+
}
|
|
135
|
+
const next = fs.stat(filePath).then((stat) => stat.mtimeMs).catch(() => void 0).finally(() => {
|
|
136
|
+
configMtimeInFlight.delete(filePath);
|
|
137
|
+
});
|
|
138
|
+
configMtimeInFlight.set(filePath, next);
|
|
139
|
+
return next;
|
|
140
|
+
}
|
|
141
|
+
async function isVueConfigCacheValid(vueFilePath, cache) {
|
|
142
|
+
const nextMtime = await getMtimeCached(vueFilePath);
|
|
143
|
+
if (nextMtime === void 0 || cache.fileMtimeMs === void 0) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (nextMtime !== cache.fileMtimeMs) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
if (cache.dependencies.length === 0) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
for (const dep of cache.dependencies) {
|
|
153
|
+
const nextDepMtime = await getMtimeCached(dep);
|
|
154
|
+
const cachedDepMtime = cache.dependencyMtimeMs.get(dep);
|
|
155
|
+
if (nextDepMtime === void 0 || cachedDepMtime === void 0 || nextDepMtime !== cachedDepMtime) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
127
161
|
function isJsOrTs(name) {
|
|
128
162
|
if (typeof name === "string") {
|
|
129
163
|
return /\.[jt]s$/.test(name);
|
|
@@ -240,12 +274,17 @@ async function touch(filename) {
|
|
|
240
274
|
}
|
|
241
275
|
async function extractConfigFromVue(vueFilePath) {
|
|
242
276
|
try {
|
|
277
|
+
const cached = vueConfigCache.get(vueFilePath);
|
|
278
|
+
if (cached && await isVueConfigCacheValid(vueFilePath, cached)) {
|
|
279
|
+
return cached.config;
|
|
280
|
+
}
|
|
243
281
|
const content = await fs.readFile(vueFilePath, "utf-8");
|
|
244
282
|
const { descriptor, errors } = parse(content, { filename: vueFilePath });
|
|
245
283
|
if (errors.length > 0) {
|
|
246
284
|
return void 0;
|
|
247
285
|
}
|
|
248
286
|
const mergedConfig = {};
|
|
287
|
+
const macroDependencies = [];
|
|
249
288
|
const { parse: parseJson } = await import("comment-json");
|
|
250
289
|
const jsonBlocks = descriptor.customBlocks.filter((block) => block.type === "json");
|
|
251
290
|
for (const block of jsonBlocks) {
|
|
@@ -264,13 +303,16 @@ async function extractConfigFromVue(vueFilePath) {
|
|
|
264
303
|
const setupContent = descriptor.scriptSetup?.content;
|
|
265
304
|
const hasMacroHint = typeof setupContent === "string" && /\bdefine(?:App|Page|Component)Json\s*\(/.test(setupContent);
|
|
266
305
|
if (hasMacroHint) {
|
|
267
|
-
const { extractJsonMacroFromScriptSetup } = await import("./jsonMacros-
|
|
306
|
+
const { extractJsonMacroFromScriptSetup } = await import("./jsonMacros-VSJW5D23.mjs");
|
|
268
307
|
try {
|
|
269
308
|
const extracted = await extractJsonMacroFromScriptSetup(
|
|
270
309
|
setupContent,
|
|
271
310
|
vueFilePath,
|
|
272
311
|
descriptor.scriptSetup?.lang
|
|
273
312
|
);
|
|
313
|
+
if (extracted.dependencies?.length) {
|
|
314
|
+
macroDependencies.push(...extracted.dependencies);
|
|
315
|
+
}
|
|
274
316
|
if (extracted.config && typeof extracted.config === "object" && !Array.isArray(extracted.config)) {
|
|
275
317
|
(0, import_merge.recursive)(mergedConfig, extracted.config);
|
|
276
318
|
}
|
|
@@ -280,7 +322,29 @@ async function extractConfigFromVue(vueFilePath) {
|
|
|
280
322
|
}
|
|
281
323
|
}
|
|
282
324
|
}
|
|
283
|
-
|
|
325
|
+
const normalizedDependencies = Array.from(
|
|
326
|
+
new Set(
|
|
327
|
+
macroDependencies.filter((dep) => dep && !NODE_MODULES_RE.test(dep)).map((dep) => path.normalize(dep))
|
|
328
|
+
)
|
|
329
|
+
);
|
|
330
|
+
const dependencyMtimeMs = /* @__PURE__ */ new Map();
|
|
331
|
+
await Promise.all(
|
|
332
|
+
normalizedDependencies.map(async (dep) => {
|
|
333
|
+
const mtime = await getMtimeCached(dep);
|
|
334
|
+
if (mtime !== void 0) {
|
|
335
|
+
dependencyMtimeMs.set(dep, mtime);
|
|
336
|
+
}
|
|
337
|
+
})
|
|
338
|
+
);
|
|
339
|
+
const fileMtimeMs = await getMtimeCached(vueFilePath);
|
|
340
|
+
const hasConfig = Object.keys(mergedConfig).length > 0;
|
|
341
|
+
vueConfigCache.set(vueFilePath, {
|
|
342
|
+
config: hasConfig ? mergedConfig : void 0,
|
|
343
|
+
fileMtimeMs,
|
|
344
|
+
dependencies: normalizedDependencies,
|
|
345
|
+
dependencyMtimeMs
|
|
346
|
+
});
|
|
347
|
+
return hasConfig ? mergedConfig : void 0;
|
|
284
348
|
} catch {
|
|
285
349
|
return void 0;
|
|
286
350
|
}
|