@weapp-vite/web 1.2.0 → 1.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/index.mjs +88 -19
- package/dist/plugin.mjs +88 -19
- package/package.json +7 -6
package/dist/index.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import * as t from "@babel/types";
|
|
|
28
28
|
import fs from "fs-extra";
|
|
29
29
|
import MagicString from "magic-string";
|
|
30
30
|
import { dirname as dirname2, extname, join, normalize, posix, relative as relative2, resolve } from "pathe";
|
|
31
|
+
import { bundleRequire } from "rolldown-require";
|
|
31
32
|
|
|
32
33
|
// src/compiler/wxml.ts
|
|
33
34
|
import { readFileSync } from "fs";
|
|
@@ -756,7 +757,8 @@ function toRelativeImport(from, target) {
|
|
|
756
757
|
const fromDir = dirname(from);
|
|
757
758
|
const rel = relative(fromDir, target);
|
|
758
759
|
if (!rel || rel.startsWith(".")) {
|
|
759
|
-
|
|
760
|
+
const fallback = normalizeTemplatePath(target).split("/").pop() ?? "";
|
|
761
|
+
return rel || `./${fallback}`;
|
|
760
762
|
}
|
|
761
763
|
return `./${rel}`;
|
|
762
764
|
}
|
|
@@ -952,7 +954,8 @@ function appendWxsQuery(pathname) {
|
|
|
952
954
|
return `${pathname}${pathname.includes("?") ? "&" : "?"}wxs`;
|
|
953
955
|
}
|
|
954
956
|
function isSupportedRequirePath(request) {
|
|
955
|
-
|
|
957
|
+
const normalized = request.replace(/\\/g, "/");
|
|
958
|
+
return normalized.startsWith(".") || normalized.startsWith("/");
|
|
956
959
|
}
|
|
957
960
|
function transformWxsToEsm(code, id, options) {
|
|
958
961
|
const dependencies = [];
|
|
@@ -974,7 +977,8 @@ function transformWxsToEsm(code, id, options) {
|
|
|
974
977
|
warnings.push(`[@weapp-vite/web] WXS require \u4EC5\u652F\u6301\u76F8\u5BF9\u6216\u7EDD\u5BF9\u8DEF\u5F84: ${request} (from ${id})`);
|
|
975
978
|
continue;
|
|
976
979
|
}
|
|
977
|
-
const
|
|
980
|
+
const normalizedRequest = request.replace(/\\/g, "/");
|
|
981
|
+
const resolved = options.resolvePath(normalizedRequest, id);
|
|
978
982
|
if (!resolved) {
|
|
979
983
|
warnings.push(`[@weapp-vite/web] \u65E0\u6CD5\u89E3\u6790 WXS require: ${request} (from ${id})`);
|
|
980
984
|
continue;
|
|
@@ -1071,6 +1075,7 @@ function weappWebPlugin(options = {}) {
|
|
|
1071
1075
|
const moduleMeta = /* @__PURE__ */ new Map();
|
|
1072
1076
|
const pageNavigationMap = /* @__PURE__ */ new Map();
|
|
1073
1077
|
const templateComponentMap = /* @__PURE__ */ new Map();
|
|
1078
|
+
const templatePathSet = /* @__PURE__ */ new Set();
|
|
1074
1079
|
const componentTagMap = /* @__PURE__ */ new Map();
|
|
1075
1080
|
const componentIdMap = /* @__PURE__ */ new Map();
|
|
1076
1081
|
let appNavigationDefaults = {};
|
|
@@ -1116,7 +1121,18 @@ function weappWebPlugin(options = {}) {
|
|
|
1116
1121
|
transform(code, id) {
|
|
1117
1122
|
const clean = cleanUrl(id);
|
|
1118
1123
|
if (isTemplateFile(clean)) {
|
|
1124
|
+
if (isHtmlEntry(clean, root)) {
|
|
1125
|
+
return null;
|
|
1126
|
+
}
|
|
1119
1127
|
const normalizedId = normalizePath2(clean);
|
|
1128
|
+
if (templatePathSet.size > 0) {
|
|
1129
|
+
if (!isInsideDir(clean, srcRoot)) {
|
|
1130
|
+
return null;
|
|
1131
|
+
}
|
|
1132
|
+
if (!templatePathSet.has(normalizedId)) {
|
|
1133
|
+
return null;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1120
1136
|
const navigationConfig = pageNavigationMap.get(normalizedId);
|
|
1121
1137
|
const componentTags = templateComponentMap.get(normalizedId);
|
|
1122
1138
|
const { code: compiled, dependencies, warnings } = compileWxml({
|
|
@@ -1288,6 +1304,7 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1288
1304
|
moduleMeta.clear();
|
|
1289
1305
|
pageNavigationMap.clear();
|
|
1290
1306
|
templateComponentMap.clear();
|
|
1307
|
+
templatePathSet.clear();
|
|
1291
1308
|
componentTagMap.clear();
|
|
1292
1309
|
componentIdMap.clear();
|
|
1293
1310
|
appNavigationDefaults = {};
|
|
@@ -1315,8 +1332,9 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1315
1332
|
}
|
|
1316
1333
|
);
|
|
1317
1334
|
}
|
|
1318
|
-
const
|
|
1319
|
-
|
|
1335
|
+
const appJsonBasePath = join(srcRoot, "app.json");
|
|
1336
|
+
const appJsonPath = await resolveJsonPath(appJsonBasePath);
|
|
1337
|
+
if (appJsonPath) {
|
|
1320
1338
|
const appJson = await readJsonFile(appJsonPath);
|
|
1321
1339
|
if (appJson) {
|
|
1322
1340
|
appComponentTags = await collectComponentTagsFromConfig(appJson, srcRoot, appJsonPath, reportWarning, (tags) => {
|
|
@@ -1363,9 +1381,13 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1363
1381
|
return;
|
|
1364
1382
|
}
|
|
1365
1383
|
const template = await resolveTemplateFile(base);
|
|
1384
|
+
if (template) {
|
|
1385
|
+
templatePathSet.add(normalizePath2(template));
|
|
1386
|
+
}
|
|
1366
1387
|
const style = await resolveStyleFile(base);
|
|
1367
|
-
const
|
|
1368
|
-
const
|
|
1388
|
+
const pageJsonBasePath = join(srcRoot, `${pageId}.json`);
|
|
1389
|
+
const pageJsonPath = await resolveJsonPath(pageJsonBasePath);
|
|
1390
|
+
const pageJson = pageJsonPath ? await readJsonFile(pageJsonPath) : void 0;
|
|
1369
1391
|
moduleMeta.set(
|
|
1370
1392
|
normalizePath2(script),
|
|
1371
1393
|
{
|
|
@@ -1380,7 +1402,7 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1380
1402
|
script,
|
|
1381
1403
|
id: toPosixId(pageId)
|
|
1382
1404
|
});
|
|
1383
|
-
const pageComponentTags = pageJson ? await collectComponentTagsFromConfig(pageJson, dirname2(script), pageJsonPath, reportWarning) : await collectComponentTagsFromJson(
|
|
1405
|
+
const pageComponentTags = pageJson && pageJsonPath ? await collectComponentTagsFromConfig(pageJson, dirname2(script), pageJsonPath, reportWarning) : await collectComponentTagsFromJson(pageJsonBasePath, dirname2(script), reportWarning);
|
|
1384
1406
|
if (template) {
|
|
1385
1407
|
const mergedTags = mergeComponentTags(appComponentTags, pageComponentTags);
|
|
1386
1408
|
if (Object.keys(mergedTags).length > 0) {
|
|
@@ -1410,6 +1432,9 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1410
1432
|
const idRelative = relative2(srcRoot, script).replace(new RegExp(`${extname(script)}$`), "");
|
|
1411
1433
|
const componentIdPosix = toPosixId(idRelative);
|
|
1412
1434
|
const template = await resolveTemplateFile(script);
|
|
1435
|
+
if (template) {
|
|
1436
|
+
templatePathSet.add(normalizePath2(template));
|
|
1437
|
+
}
|
|
1413
1438
|
const style = await resolveStyleFile(script);
|
|
1414
1439
|
moduleMeta.set(
|
|
1415
1440
|
normalizePath2(script),
|
|
@@ -1425,8 +1450,8 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1425
1450
|
script,
|
|
1426
1451
|
id: componentIdPosix
|
|
1427
1452
|
});
|
|
1428
|
-
const
|
|
1429
|
-
const componentTags = await collectComponentTagsFromJson(
|
|
1453
|
+
const componentJsonBasePath = `${script.replace(new RegExp(`${extname(script)}$`), "")}.json`;
|
|
1454
|
+
const componentTags = await collectComponentTagsFromJson(componentJsonBasePath, dirname2(script), reportWarning);
|
|
1430
1455
|
if (template) {
|
|
1431
1456
|
const mergedTags = mergeComponentTags(appComponentTags, componentTags);
|
|
1432
1457
|
if (Object.keys(mergedTags).length > 0) {
|
|
@@ -1468,12 +1493,16 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1468
1493
|
}
|
|
1469
1494
|
return tags;
|
|
1470
1495
|
}
|
|
1471
|
-
async function collectComponentTagsFromJson(
|
|
1472
|
-
const
|
|
1496
|
+
async function collectComponentTagsFromJson(jsonBasePath, importerDir, warn2) {
|
|
1497
|
+
const resolvedPath = await resolveJsonPath(jsonBasePath);
|
|
1498
|
+
if (!resolvedPath) {
|
|
1499
|
+
return {};
|
|
1500
|
+
}
|
|
1501
|
+
const json = await readJsonFile(resolvedPath);
|
|
1473
1502
|
if (!json) {
|
|
1474
1503
|
return {};
|
|
1475
1504
|
}
|
|
1476
|
-
return collectComponentTagsFromConfig(json, importerDir,
|
|
1505
|
+
return collectComponentTagsFromConfig(json, importerDir, resolvedPath, warn2);
|
|
1477
1506
|
}
|
|
1478
1507
|
function mergeComponentTags(base, overrides) {
|
|
1479
1508
|
if (!Object.keys(base).length && !Object.keys(overrides).length) {
|
|
@@ -1539,14 +1568,44 @@ function isRecord(value) {
|
|
|
1539
1568
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1540
1569
|
}
|
|
1541
1570
|
async function readJsonFile(pathname) {
|
|
1542
|
-
|
|
1543
|
-
|
|
1571
|
+
const candidates = [pathname];
|
|
1572
|
+
if (pathname.endsWith(".json")) {
|
|
1573
|
+
candidates.push(`${pathname}.ts`, `${pathname}.js`);
|
|
1544
1574
|
}
|
|
1545
|
-
const
|
|
1546
|
-
|
|
1547
|
-
|
|
1575
|
+
for (const candidate of candidates) {
|
|
1576
|
+
if (!await fs.pathExists(candidate)) {
|
|
1577
|
+
continue;
|
|
1578
|
+
}
|
|
1579
|
+
if (candidate.endsWith(".json")) {
|
|
1580
|
+
const json = await fs.readJson(candidate).catch(() => void 0);
|
|
1581
|
+
if (!isRecord(json)) {
|
|
1582
|
+
return void 0;
|
|
1583
|
+
}
|
|
1584
|
+
return json;
|
|
1585
|
+
}
|
|
1586
|
+
const { mod } = await bundleRequire({
|
|
1587
|
+
filepath: candidate,
|
|
1588
|
+
preserveTemporaryFile: true
|
|
1589
|
+
});
|
|
1590
|
+
const resolved = typeof mod.default === "function" ? await mod.default() : mod.default;
|
|
1591
|
+
if (!isRecord(resolved)) {
|
|
1592
|
+
return void 0;
|
|
1593
|
+
}
|
|
1594
|
+
return resolved;
|
|
1595
|
+
}
|
|
1596
|
+
return void 0;
|
|
1597
|
+
}
|
|
1598
|
+
async function resolveJsonPath(basePath) {
|
|
1599
|
+
const candidates = [basePath];
|
|
1600
|
+
if (basePath.endsWith(".json")) {
|
|
1601
|
+
candidates.push(`${basePath}.ts`, `${basePath}.js`);
|
|
1602
|
+
}
|
|
1603
|
+
for (const candidate of candidates) {
|
|
1604
|
+
if (await fs.pathExists(candidate)) {
|
|
1605
|
+
return candidate;
|
|
1606
|
+
}
|
|
1548
1607
|
}
|
|
1549
|
-
return
|
|
1608
|
+
return void 0;
|
|
1550
1609
|
}
|
|
1551
1610
|
function pickNavigationConfig(source) {
|
|
1552
1611
|
const config = {};
|
|
@@ -1576,6 +1635,16 @@ function mergeNavigationConfig(base, overrides) {
|
|
|
1576
1635
|
function normalizePath2(p) {
|
|
1577
1636
|
return posix.normalize(p.split("\\").join("/"));
|
|
1578
1637
|
}
|
|
1638
|
+
function isInsideDir(filePath, dir) {
|
|
1639
|
+
const rel = relative2(dir, filePath);
|
|
1640
|
+
return rel === "" || !rel.startsWith("..") && !posix.isAbsolute(rel);
|
|
1641
|
+
}
|
|
1642
|
+
function isHtmlEntry(filePath, root) {
|
|
1643
|
+
if (!filePath.toLowerCase().endsWith(".html")) {
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
return normalizePath2(filePath) === normalizePath2(resolve(root, "index.html"));
|
|
1647
|
+
}
|
|
1579
1648
|
function resolveImportBase(raw, importer, srcRoot) {
|
|
1580
1649
|
if (!raw) {
|
|
1581
1650
|
return void 0;
|
package/dist/plugin.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import * as t from "@babel/types";
|
|
|
6
6
|
import fs from "fs-extra";
|
|
7
7
|
import MagicString from "magic-string";
|
|
8
8
|
import { dirname as dirname2, extname, join, normalize, posix, relative as relative2, resolve } from "pathe";
|
|
9
|
+
import { bundleRequire } from "rolldown-require";
|
|
9
10
|
|
|
10
11
|
// src/compiler/wxml.ts
|
|
11
12
|
import { readFileSync } from "fs";
|
|
@@ -734,7 +735,8 @@ function toRelativeImport(from, target) {
|
|
|
734
735
|
const fromDir = dirname(from);
|
|
735
736
|
const rel = relative(fromDir, target);
|
|
736
737
|
if (!rel || rel.startsWith(".")) {
|
|
737
|
-
|
|
738
|
+
const fallback = normalizeTemplatePath(target).split("/").pop() ?? "";
|
|
739
|
+
return rel || `./${fallback}`;
|
|
738
740
|
}
|
|
739
741
|
return `./${rel}`;
|
|
740
742
|
}
|
|
@@ -930,7 +932,8 @@ function appendWxsQuery(pathname) {
|
|
|
930
932
|
return `${pathname}${pathname.includes("?") ? "&" : "?"}wxs`;
|
|
931
933
|
}
|
|
932
934
|
function isSupportedRequirePath(request) {
|
|
933
|
-
|
|
935
|
+
const normalized = request.replace(/\\/g, "/");
|
|
936
|
+
return normalized.startsWith(".") || normalized.startsWith("/");
|
|
934
937
|
}
|
|
935
938
|
function transformWxsToEsm(code, id, options) {
|
|
936
939
|
const dependencies = [];
|
|
@@ -952,7 +955,8 @@ function transformWxsToEsm(code, id, options) {
|
|
|
952
955
|
warnings.push(`[@weapp-vite/web] WXS require \u4EC5\u652F\u6301\u76F8\u5BF9\u6216\u7EDD\u5BF9\u8DEF\u5F84: ${request} (from ${id})`);
|
|
953
956
|
continue;
|
|
954
957
|
}
|
|
955
|
-
const
|
|
958
|
+
const normalizedRequest = request.replace(/\\/g, "/");
|
|
959
|
+
const resolved = options.resolvePath(normalizedRequest, id);
|
|
956
960
|
if (!resolved) {
|
|
957
961
|
warnings.push(`[@weapp-vite/web] \u65E0\u6CD5\u89E3\u6790 WXS require: ${request} (from ${id})`);
|
|
958
962
|
continue;
|
|
@@ -1071,6 +1075,7 @@ function weappWebPlugin(options = {}) {
|
|
|
1071
1075
|
const moduleMeta = /* @__PURE__ */ new Map();
|
|
1072
1076
|
const pageNavigationMap = /* @__PURE__ */ new Map();
|
|
1073
1077
|
const templateComponentMap = /* @__PURE__ */ new Map();
|
|
1078
|
+
const templatePathSet = /* @__PURE__ */ new Set();
|
|
1074
1079
|
const componentTagMap = /* @__PURE__ */ new Map();
|
|
1075
1080
|
const componentIdMap = /* @__PURE__ */ new Map();
|
|
1076
1081
|
let appNavigationDefaults = {};
|
|
@@ -1116,7 +1121,18 @@ function weappWebPlugin(options = {}) {
|
|
|
1116
1121
|
transform(code, id) {
|
|
1117
1122
|
const clean = cleanUrl(id);
|
|
1118
1123
|
if (isTemplateFile(clean)) {
|
|
1124
|
+
if (isHtmlEntry(clean, root)) {
|
|
1125
|
+
return null;
|
|
1126
|
+
}
|
|
1119
1127
|
const normalizedId = normalizePath2(clean);
|
|
1128
|
+
if (templatePathSet.size > 0) {
|
|
1129
|
+
if (!isInsideDir(clean, srcRoot)) {
|
|
1130
|
+
return null;
|
|
1131
|
+
}
|
|
1132
|
+
if (!templatePathSet.has(normalizedId)) {
|
|
1133
|
+
return null;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1120
1136
|
const navigationConfig = pageNavigationMap.get(normalizedId);
|
|
1121
1137
|
const componentTags = templateComponentMap.get(normalizedId);
|
|
1122
1138
|
const { code: compiled, dependencies, warnings } = compileWxml({
|
|
@@ -1288,6 +1304,7 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1288
1304
|
moduleMeta.clear();
|
|
1289
1305
|
pageNavigationMap.clear();
|
|
1290
1306
|
templateComponentMap.clear();
|
|
1307
|
+
templatePathSet.clear();
|
|
1291
1308
|
componentTagMap.clear();
|
|
1292
1309
|
componentIdMap.clear();
|
|
1293
1310
|
appNavigationDefaults = {};
|
|
@@ -1315,8 +1332,9 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1315
1332
|
}
|
|
1316
1333
|
);
|
|
1317
1334
|
}
|
|
1318
|
-
const
|
|
1319
|
-
|
|
1335
|
+
const appJsonBasePath = join(srcRoot, "app.json");
|
|
1336
|
+
const appJsonPath = await resolveJsonPath(appJsonBasePath);
|
|
1337
|
+
if (appJsonPath) {
|
|
1320
1338
|
const appJson = await readJsonFile(appJsonPath);
|
|
1321
1339
|
if (appJson) {
|
|
1322
1340
|
appComponentTags = await collectComponentTagsFromConfig(appJson, srcRoot, appJsonPath, reportWarning, (tags) => {
|
|
@@ -1363,9 +1381,13 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1363
1381
|
return;
|
|
1364
1382
|
}
|
|
1365
1383
|
const template = await resolveTemplateFile(base);
|
|
1384
|
+
if (template) {
|
|
1385
|
+
templatePathSet.add(normalizePath2(template));
|
|
1386
|
+
}
|
|
1366
1387
|
const style = await resolveStyleFile(base);
|
|
1367
|
-
const
|
|
1368
|
-
const
|
|
1388
|
+
const pageJsonBasePath = join(srcRoot, `${pageId}.json`);
|
|
1389
|
+
const pageJsonPath = await resolveJsonPath(pageJsonBasePath);
|
|
1390
|
+
const pageJson = pageJsonPath ? await readJsonFile(pageJsonPath) : void 0;
|
|
1369
1391
|
moduleMeta.set(
|
|
1370
1392
|
normalizePath2(script),
|
|
1371
1393
|
{
|
|
@@ -1380,7 +1402,7 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1380
1402
|
script,
|
|
1381
1403
|
id: toPosixId(pageId)
|
|
1382
1404
|
});
|
|
1383
|
-
const pageComponentTags = pageJson ? await collectComponentTagsFromConfig(pageJson, dirname2(script), pageJsonPath, reportWarning) : await collectComponentTagsFromJson(
|
|
1405
|
+
const pageComponentTags = pageJson && pageJsonPath ? await collectComponentTagsFromConfig(pageJson, dirname2(script), pageJsonPath, reportWarning) : await collectComponentTagsFromJson(pageJsonBasePath, dirname2(script), reportWarning);
|
|
1384
1406
|
if (template) {
|
|
1385
1407
|
const mergedTags = mergeComponentTags(appComponentTags, pageComponentTags);
|
|
1386
1408
|
if (Object.keys(mergedTags).length > 0) {
|
|
@@ -1410,6 +1432,9 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1410
1432
|
const idRelative = relative2(srcRoot, script).replace(new RegExp(`${extname(script)}$`), "");
|
|
1411
1433
|
const componentIdPosix = toPosixId(idRelative);
|
|
1412
1434
|
const template = await resolveTemplateFile(script);
|
|
1435
|
+
if (template) {
|
|
1436
|
+
templatePathSet.add(normalizePath2(template));
|
|
1437
|
+
}
|
|
1413
1438
|
const style = await resolveStyleFile(script);
|
|
1414
1439
|
moduleMeta.set(
|
|
1415
1440
|
normalizePath2(script),
|
|
@@ -1425,8 +1450,8 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1425
1450
|
script,
|
|
1426
1451
|
id: componentIdPosix
|
|
1427
1452
|
});
|
|
1428
|
-
const
|
|
1429
|
-
const componentTags = await collectComponentTagsFromJson(
|
|
1453
|
+
const componentJsonBasePath = `${script.replace(new RegExp(`${extname(script)}$`), "")}.json`;
|
|
1454
|
+
const componentTags = await collectComponentTagsFromJson(componentJsonBasePath, dirname2(script), reportWarning);
|
|
1430
1455
|
if (template) {
|
|
1431
1456
|
const mergedTags = mergeComponentTags(appComponentTags, componentTags);
|
|
1432
1457
|
if (Object.keys(mergedTags).length > 0) {
|
|
@@ -1468,12 +1493,16 @@ if (import.meta.hot) { import.meta.hot.accept() }
|
|
|
1468
1493
|
}
|
|
1469
1494
|
return tags;
|
|
1470
1495
|
}
|
|
1471
|
-
async function collectComponentTagsFromJson(
|
|
1472
|
-
const
|
|
1496
|
+
async function collectComponentTagsFromJson(jsonBasePath, importerDir, warn2) {
|
|
1497
|
+
const resolvedPath = await resolveJsonPath(jsonBasePath);
|
|
1498
|
+
if (!resolvedPath) {
|
|
1499
|
+
return {};
|
|
1500
|
+
}
|
|
1501
|
+
const json = await readJsonFile(resolvedPath);
|
|
1473
1502
|
if (!json) {
|
|
1474
1503
|
return {};
|
|
1475
1504
|
}
|
|
1476
|
-
return collectComponentTagsFromConfig(json, importerDir,
|
|
1505
|
+
return collectComponentTagsFromConfig(json, importerDir, resolvedPath, warn2);
|
|
1477
1506
|
}
|
|
1478
1507
|
function mergeComponentTags(base, overrides) {
|
|
1479
1508
|
if (!Object.keys(base).length && !Object.keys(overrides).length) {
|
|
@@ -1539,14 +1568,44 @@ function isRecord(value) {
|
|
|
1539
1568
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1540
1569
|
}
|
|
1541
1570
|
async function readJsonFile(pathname) {
|
|
1542
|
-
|
|
1543
|
-
|
|
1571
|
+
const candidates = [pathname];
|
|
1572
|
+
if (pathname.endsWith(".json")) {
|
|
1573
|
+
candidates.push(`${pathname}.ts`, `${pathname}.js`);
|
|
1544
1574
|
}
|
|
1545
|
-
const
|
|
1546
|
-
|
|
1547
|
-
|
|
1575
|
+
for (const candidate of candidates) {
|
|
1576
|
+
if (!await fs.pathExists(candidate)) {
|
|
1577
|
+
continue;
|
|
1578
|
+
}
|
|
1579
|
+
if (candidate.endsWith(".json")) {
|
|
1580
|
+
const json = await fs.readJson(candidate).catch(() => void 0);
|
|
1581
|
+
if (!isRecord(json)) {
|
|
1582
|
+
return void 0;
|
|
1583
|
+
}
|
|
1584
|
+
return json;
|
|
1585
|
+
}
|
|
1586
|
+
const { mod } = await bundleRequire({
|
|
1587
|
+
filepath: candidate,
|
|
1588
|
+
preserveTemporaryFile: true
|
|
1589
|
+
});
|
|
1590
|
+
const resolved = typeof mod.default === "function" ? await mod.default() : mod.default;
|
|
1591
|
+
if (!isRecord(resolved)) {
|
|
1592
|
+
return void 0;
|
|
1593
|
+
}
|
|
1594
|
+
return resolved;
|
|
1548
1595
|
}
|
|
1549
|
-
return
|
|
1596
|
+
return void 0;
|
|
1597
|
+
}
|
|
1598
|
+
async function resolveJsonPath(basePath) {
|
|
1599
|
+
const candidates = [basePath];
|
|
1600
|
+
if (basePath.endsWith(".json")) {
|
|
1601
|
+
candidates.push(`${basePath}.ts`, `${basePath}.js`);
|
|
1602
|
+
}
|
|
1603
|
+
for (const candidate of candidates) {
|
|
1604
|
+
if (await fs.pathExists(candidate)) {
|
|
1605
|
+
return candidate;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
return void 0;
|
|
1550
1609
|
}
|
|
1551
1610
|
function pickNavigationConfig(source) {
|
|
1552
1611
|
const config = {};
|
|
@@ -1576,6 +1635,16 @@ function mergeNavigationConfig(base, overrides) {
|
|
|
1576
1635
|
function normalizePath2(p) {
|
|
1577
1636
|
return posix.normalize(p.split("\\").join("/"));
|
|
1578
1637
|
}
|
|
1638
|
+
function isInsideDir(filePath, dir) {
|
|
1639
|
+
const rel = relative2(dir, filePath);
|
|
1640
|
+
return rel === "" || !rel.startsWith("..") && !posix.isAbsolute(rel);
|
|
1641
|
+
}
|
|
1642
|
+
function isHtmlEntry(filePath, root) {
|
|
1643
|
+
if (!filePath.toLowerCase().endsWith(".html")) {
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
return normalizePath2(filePath) === normalizePath2(resolve(root, "index.html"));
|
|
1647
|
+
}
|
|
1579
1648
|
function resolveImportBase(raw, importer, srcRoot) {
|
|
1580
1649
|
if (!raw) {
|
|
1581
1650
|
return void 0;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/web",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"description": "Experimental web runtime for weapp-vite templates",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,15 +44,16 @@
|
|
|
44
44
|
"node": "^20.19.0 || >=22.12.0"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@babel/parser": "^7.
|
|
48
|
-
"@babel/traverse": "^7.
|
|
49
|
-
"@babel/types": "^7.
|
|
47
|
+
"@babel/parser": "^7.29.0",
|
|
48
|
+
"@babel/traverse": "^7.29.0",
|
|
49
|
+
"@babel/types": "^7.29.0",
|
|
50
50
|
"domhandler": "^5.0.3",
|
|
51
51
|
"fs-extra": "^11.3.3",
|
|
52
|
-
"htmlparser2": "^10.
|
|
52
|
+
"htmlparser2": "^10.1.0",
|
|
53
53
|
"lit": "^3.3.1",
|
|
54
54
|
"magic-string": "^0.30.21",
|
|
55
|
-
"pathe": "^2.0.3"
|
|
55
|
+
"pathe": "^2.0.3",
|
|
56
|
+
"rolldown-require": "2.0.3"
|
|
56
57
|
},
|
|
57
58
|
"scripts": {
|
|
58
59
|
"dev": "tsup --watch --sourcemap",
|