weapp-vite 6.20.3 → 6.20.5
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/README.md +1 -1
- package/dist/auto-import-components/resolvers.mjs +1 -1
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +135 -17
- package/dist/{config-C810aRQQ.d.mts → config-B1H1OqnR.d.mts} +10 -1
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-DavT7XIA.mjs → createContext-Ryo4nfbU.mjs} +627 -151
- package/dist/docs/README.md +1 -1
- package/dist/docs/ai-workflows.md +2 -0
- package/dist/docs/getting-started.md +13 -2
- package/dist/docs/testing.md +13 -0
- package/dist/docs/uni-app-component-libraries.md +4 -4
- package/dist/docs/weapp-config.md +21 -4
- package/dist/file-BjrPjC70.mjs +2 -0
- package/dist/{file-AiMZtyLe.mjs → file-CWbsTVPm.mjs} +1 -1
- package/dist/getInstance-CJAXp9db.mjs +2 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/json.d.mts +1 -1
- package/dist/mcp.d.mts +1 -1
- package/dist/{resolvers-w4g7O94W.mjs → resolvers-icNxkpcy.mjs} +2 -0
- package/dist/resolvers.mjs +1 -1
- package/dist/test.mjs +1 -1
- package/dist/types.d.mts +2 -2
- package/package.json +18 -18
- package/dist/file-D0RifY1q.mjs +0 -2
- package/dist/getInstance-Czvi9cUi.mjs +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as applyWeappViteHostMeta } from "./pluginHost--CaeyWpA.mjs";
|
|
2
2
|
import { n as configureLogger, r as logger_default } from "./logger-mt4mSTqV.mjs";
|
|
3
|
-
import { C as isNativeTemplateSource, S as ALL_NATIVE_STYLE_RESOLVER_EXTENSIONS, T as MINI_PROGRAM_PLATFORM_ADAPTERS, _ as jsExtensions, a as findJsonEntry, b as templateExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as scriptExtensions, w as isSourceStyleExtension, x as vueExtensions, y as supportedCssLangs } from "./file-
|
|
3
|
+
import { C as isNativeTemplateSource, S as ALL_NATIVE_STYLE_RESOLVER_EXTENSIONS, T as MINI_PROGRAM_PLATFORM_ADAPTERS, _ as jsExtensions, a as findJsonEntry, b as templateExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as scriptExtensions, w as isSourceStyleExtension, x as vueExtensions, y as supportedCssLangs } from "./file-CWbsTVPm.mjs";
|
|
4
4
|
import { createRequire, isBuiltin } from "node:module";
|
|
5
5
|
import { createDebug } from "obug";
|
|
6
6
|
import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
@@ -15,7 +15,7 @@ import { collectOnPageScrollPerformanceWarnings } from "@weapp-vite/ast/operatio
|
|
|
15
15
|
import { collectSetDataPickKeysFromTemplateCode } from "@weapp-vite/ast/operations/setDataPick";
|
|
16
16
|
import { BABEL_TS_MODULE_PARSER_OPTIONS as BABEL_TS_MODULE_PARSER_OPTIONS$1, generate as generate$1, getVisitorKeys, parse as parse$3, parseJsLike, traverse } from "@weapp-vite/ast/babel";
|
|
17
17
|
import { compileScript, parse as parse$1 } from "vue/compiler-sfc";
|
|
18
|
-
import
|
|
18
|
+
import picomatch from "picomatch";
|
|
19
19
|
import { VUE_COMPONENT_TAG_RE, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, WE_VU_RUNTIME_APIS, buildClassStyleComputedCode, collectVueTemplateTags, compileJsxFile, compileVueFile, compileVueStyleToWxss, createJsonMerger, createPageEntryMatcher, createPageEntryMatcher as createPageEntryMatcher$1, generateScopedId, getClassStyleWxsSource, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isUniAppCompatibilityFile, pathExists, readAndParseSfc, readFile as readFile$1, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, stripJsonMacroCallsFromCode, transformNestedWxssVars, transformUniAppSource, transformVueDeepSelectors } from "wevu/compiler";
|
|
20
20
|
import process from "node:process";
|
|
21
21
|
import { parse as parse$2, stringify } from "comment-json";
|
|
@@ -38,6 +38,7 @@ import { Buffer } from "node:buffer";
|
|
|
38
38
|
import MagicString from "magic-string";
|
|
39
39
|
import remapping from "@jridgewell/remapping";
|
|
40
40
|
import * as t from "@weapp-vite/ast/babelTypes";
|
|
41
|
+
import { dev } from "rolldown/experimental";
|
|
41
42
|
import babelPresetEnv from "@babel/preset-env";
|
|
42
43
|
import babelPresetTypescript from "@babel/preset-typescript";
|
|
43
44
|
import * as babel from "@weapp-vite/ast/babelCore";
|
|
@@ -263,6 +264,11 @@ function createModuleGraphService() {
|
|
|
263
264
|
let topologyRescan;
|
|
264
265
|
const entryDependencies = /* @__PURE__ */ new Map();
|
|
265
266
|
const pendingChanges = /* @__PURE__ */ new Map();
|
|
267
|
+
const hasRegisteredEntryDependency = (file) => {
|
|
268
|
+
if (entryDependencies.has(file)) return true;
|
|
269
|
+
for (const dependenciesByKind of entryDependencies.values()) for (const sourceIds of dependenciesByKind.values()) if (sourceIds.has(file)) return true;
|
|
270
|
+
return false;
|
|
271
|
+
};
|
|
266
272
|
const collectFromBuildGraph = (file, affected) => {
|
|
267
273
|
for (const buildContext of buildContexts.values()) {
|
|
268
274
|
if (typeof buildContext.getModuleInfo !== "function") continue;
|
|
@@ -368,6 +374,7 @@ function createModuleGraphService() {
|
|
|
368
374
|
},
|
|
369
375
|
hasModule(rawFile) {
|
|
370
376
|
const file = normalizeSourceId(rawFile);
|
|
377
|
+
if (hasRegisteredEntryDependency(file)) return true;
|
|
371
378
|
if (devServer) return collectDevStartNodes(devServer, file).size > 0;
|
|
372
379
|
return Array.from(buildContexts.values()).some((context) => collectBuildStartIds(context, file).size > 0);
|
|
373
380
|
},
|
|
@@ -1228,7 +1235,7 @@ function getNodeText(node) {
|
|
|
1228
1235
|
concise: true
|
|
1229
1236
|
}).code.trim();
|
|
1230
1237
|
}
|
|
1231
|
-
function getPropertyName(name) {
|
|
1238
|
+
function getPropertyName$1(name) {
|
|
1232
1239
|
if (name.type === "Identifier") return name.name;
|
|
1233
1240
|
if (name.type === "StringLiteral") return name.value;
|
|
1234
1241
|
if (name.type === "NumericLiteral") return String(name.value);
|
|
@@ -1285,7 +1292,7 @@ function resolveTypeFromConfigLiteral(configType) {
|
|
|
1285
1292
|
let constructorType;
|
|
1286
1293
|
for (const member of configType.members) {
|
|
1287
1294
|
if (member.type !== "TSPropertySignature") continue;
|
|
1288
|
-
const key = getPropertyName(member.key);
|
|
1295
|
+
const key = getPropertyName$1(member.key);
|
|
1289
1296
|
const type = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1290
1297
|
if (key === "value" && type && !containsImportType(type)) valueType = getNodeText(type);
|
|
1291
1298
|
else if (key === "type") constructorType = mapConstructorType(type);
|
|
@@ -1295,7 +1302,7 @@ function resolveTypeFromConfigLiteral(configType) {
|
|
|
1295
1302
|
function isPropsConfigLiteral(configType) {
|
|
1296
1303
|
for (const member of configType.members) {
|
|
1297
1304
|
if (member.type !== "TSPropertySignature") continue;
|
|
1298
|
-
const key = getPropertyName(member.key);
|
|
1305
|
+
const key = getPropertyName$1(member.key);
|
|
1299
1306
|
if (key === "type" || key === "value") return true;
|
|
1300
1307
|
}
|
|
1301
1308
|
return false;
|
|
@@ -1304,7 +1311,7 @@ function extractFromPropertiesTypeLiteral(node) {
|
|
|
1304
1311
|
const map = /* @__PURE__ */ new Map();
|
|
1305
1312
|
for (const member of node.members) {
|
|
1306
1313
|
if (member.type !== "TSPropertySignature") continue;
|
|
1307
|
-
const propName = getPropertyName(member.key);
|
|
1314
|
+
const propName = getPropertyName$1(member.key);
|
|
1308
1315
|
if (!propName) continue;
|
|
1309
1316
|
const type = resolveTypeFromConfigLiteral(unwrapTypeAnnotation(member.typeAnnotation)) ?? "any";
|
|
1310
1317
|
map.set(propName, type);
|
|
@@ -1315,7 +1322,7 @@ function extractFromPropsInterfaceMembers(node) {
|
|
|
1315
1322
|
const map = /* @__PURE__ */ new Map();
|
|
1316
1323
|
for (const member of node.body.body) {
|
|
1317
1324
|
if (member.type !== "TSPropertySignature") continue;
|
|
1318
|
-
const propName = getPropertyName(member.key);
|
|
1325
|
+
const propName = getPropertyName$1(member.key);
|
|
1319
1326
|
if (!propName) continue;
|
|
1320
1327
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1321
1328
|
if (!typeNode || typeNode.type !== "TSTypeLiteral") continue;
|
|
@@ -1339,7 +1346,7 @@ function extractComponentPropsFromDts(code) {
|
|
|
1339
1346
|
}
|
|
1340
1347
|
for (const member of path.node.body.body) {
|
|
1341
1348
|
if (member.type !== "TSPropertySignature") continue;
|
|
1342
|
-
if (getPropertyName(member.key) !== "properties") continue;
|
|
1349
|
+
if (getPropertyName$1(member.key) !== "properties") continue;
|
|
1343
1350
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1344
1351
|
if (typeNode?.type === "TSTypeLiteral") {
|
|
1345
1352
|
props = extractFromPropertiesTypeLiteral(typeNode);
|
|
@@ -1360,7 +1367,7 @@ function extractComponentPropsFromDts(code) {
|
|
|
1360
1367
|
}
|
|
1361
1368
|
for (const member of path.node.body.body) {
|
|
1362
1369
|
if (member.type !== "ClassProperty" && member.type !== "ClassAccessorProperty") continue;
|
|
1363
|
-
if (getPropertyName(member.key) !== "properties") continue;
|
|
1370
|
+
if (getPropertyName$1(member.key) !== "properties") continue;
|
|
1364
1371
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1365
1372
|
if (typeNode?.type === "TSTypeLiteral") {
|
|
1366
1373
|
props = extractFromPropertiesTypeLiteral(typeNode);
|
|
@@ -1391,7 +1398,7 @@ function extractInlinePropsTypeFromCode(code) {
|
|
|
1391
1398
|
const pushTypeLiteralMembers = (node) => {
|
|
1392
1399
|
for (const member of node.members) {
|
|
1393
1400
|
if (member.type !== "TSPropertySignature") continue;
|
|
1394
|
-
const propName = getPropertyName(member.key);
|
|
1401
|
+
const propName = getPropertyName$1(member.key);
|
|
1395
1402
|
if (!propName) continue;
|
|
1396
1403
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1397
1404
|
props.set(propName, typeNode ? getNodeText(typeNode) : "any");
|
|
@@ -1400,7 +1407,7 @@ function extractInlinePropsTypeFromCode(code) {
|
|
|
1400
1407
|
const pushInterfaceMembers = (node) => {
|
|
1401
1408
|
for (const member of node.body.body) {
|
|
1402
1409
|
if (member.type !== "TSPropertySignature") continue;
|
|
1403
|
-
const propName = getPropertyName(member.key);
|
|
1410
|
+
const propName = getPropertyName$1(member.key);
|
|
1404
1411
|
if (!propName) continue;
|
|
1405
1412
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1406
1413
|
props.set(propName, typeNode ? getNodeText(typeNode) : "any");
|
|
@@ -5303,6 +5310,216 @@ async function loadViteConfigFile(configEnv, configFile, configRoot, configFileD
|
|
|
5303
5310
|
return withSuppressedWarningCodes(suppressedWarningCodes, () => loadConfigFromFile(configEnv, resolvedConfigFile, configRoot, logLevel, void 0, resolvedConfigLoader));
|
|
5304
5311
|
}
|
|
5305
5312
|
//#endregion
|
|
5313
|
+
//#region src/utils/preloadScan.ts
|
|
5314
|
+
const ROUTER_METHODS = /* @__PURE__ */ new Set([
|
|
5315
|
+
"navigateTo",
|
|
5316
|
+
"redirectTo",
|
|
5317
|
+
"reLaunch",
|
|
5318
|
+
"switchTab",
|
|
5319
|
+
"push",
|
|
5320
|
+
"replace"
|
|
5321
|
+
]);
|
|
5322
|
+
const TEMPLATE_NAVIGATOR_RE = /<navigator(?=\s|>)[^>]*?\surl\s*=\s*(["'])([^"'{}\s]+)\1/gi;
|
|
5323
|
+
function normalizePagePath$1(value) {
|
|
5324
|
+
return path.posix.normalize(value).replace(/^\/+/, "").replace(/^\.\//, "");
|
|
5325
|
+
}
|
|
5326
|
+
function normalizeStaticTarget(target, sourcePage) {
|
|
5327
|
+
const route = toPosixPath(target).split(/[?#]/, 1)[0];
|
|
5328
|
+
return normalizePagePath$1(route.startsWith("/") ? route : route.startsWith("./") || route.startsWith("../") ? path.posix.join(path.posix.dirname(sourcePage), route) : route);
|
|
5329
|
+
}
|
|
5330
|
+
function getStaticString(node) {
|
|
5331
|
+
if (node?.type === "StringLiteral" || node?.type === "Literal" && typeof node.value === "string") return node.value;
|
|
5332
|
+
if (node?.type === "TemplateLiteral" && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? node.quasis[0]?.value.raw;
|
|
5333
|
+
}
|
|
5334
|
+
function getPropertyName(node) {
|
|
5335
|
+
if (!node) return;
|
|
5336
|
+
if (node.type === "Identifier" && !node.computed) return node.name;
|
|
5337
|
+
return getStaticString(node);
|
|
5338
|
+
}
|
|
5339
|
+
function getRouteFromObject(argument) {
|
|
5340
|
+
if (argument?.type !== "ObjectExpression") return;
|
|
5341
|
+
for (const property of argument.properties ?? []) {
|
|
5342
|
+
if (property.type !== "ObjectProperty" && property.type !== "Property") continue;
|
|
5343
|
+
const name = getPropertyName(property.key);
|
|
5344
|
+
if (name !== "url" && name !== "path") continue;
|
|
5345
|
+
const value = getStaticString(property.value);
|
|
5346
|
+
if (value) return value;
|
|
5347
|
+
}
|
|
5348
|
+
}
|
|
5349
|
+
function collectScriptTargets(source, sourcePage) {
|
|
5350
|
+
const targets = [];
|
|
5351
|
+
try {
|
|
5352
|
+
const ast = parseJsLike(source);
|
|
5353
|
+
traverse(ast, { CallExpression(callPath) {
|
|
5354
|
+
const callee = callPath.node.callee;
|
|
5355
|
+
const method = callee?.type === "Identifier" ? callee.name : callee?.type === "MemberExpression" ? getPropertyName(callee.property) : void 0;
|
|
5356
|
+
if (!ROUTER_METHODS.has(method)) return;
|
|
5357
|
+
const argument = callPath.node.arguments?.[0];
|
|
5358
|
+
const target = getStaticString(argument) ?? getRouteFromObject(argument);
|
|
5359
|
+
if (target) targets.push(normalizeStaticTarget(target, sourcePage));
|
|
5360
|
+
} });
|
|
5361
|
+
} catch {}
|
|
5362
|
+
return [...new Set(targets)];
|
|
5363
|
+
}
|
|
5364
|
+
function collectTemplateTargets(source, sourcePage) {
|
|
5365
|
+
const targets = [];
|
|
5366
|
+
const withoutComments = source.replace(/<!--[\s\S]*?-->/g, "");
|
|
5367
|
+
TEMPLATE_NAVIGATOR_RE.lastIndex = 0;
|
|
5368
|
+
for (const match of withoutComments.matchAll(TEMPLATE_NAVIGATOR_RE)) {
|
|
5369
|
+
const target = match[2];
|
|
5370
|
+
if (target) targets.push(normalizeStaticTarget(target, sourcePage));
|
|
5371
|
+
}
|
|
5372
|
+
return [...new Set(targets)];
|
|
5373
|
+
}
|
|
5374
|
+
function collectStaticRouteTargets(source, kind, sourcePage) {
|
|
5375
|
+
return kind === "template" ? collectTemplateTargets(source, sourcePage) : collectScriptTargets(source, sourcePage);
|
|
5376
|
+
}
|
|
5377
|
+
//#endregion
|
|
5378
|
+
//#region src/utils/preloadRule.ts
|
|
5379
|
+
const PRELOAD_RULE_GLOB_RE = /[*?[\]{}()!+@]/g;
|
|
5380
|
+
function normalizePagePath(value) {
|
|
5381
|
+
return normalizeRoot(value).replace(/^\/+/, "");
|
|
5382
|
+
}
|
|
5383
|
+
function normalizePackageRoot(value) {
|
|
5384
|
+
return normalizeRoot(value).replace(/^\/+|\/+$/g, "");
|
|
5385
|
+
}
|
|
5386
|
+
function normalizeRule(value, pattern) {
|
|
5387
|
+
if (!isObject(value)) throw new TypeError(`routeRules.${pattern}.preload 必须是对象。`);
|
|
5388
|
+
const packages = value.packages;
|
|
5389
|
+
if (!Array.isArray(packages) || packages.length === 0 || packages.some((item) => typeof item !== "string" || !item.trim())) throw new TypeError(`routeRules.${pattern}.preload.packages 必须是非空字符串数组。`);
|
|
5390
|
+
const network = value.network;
|
|
5391
|
+
if (network !== void 0 && network !== "all" && network !== "wifi") throw new TypeError(`routeRules.${pattern}.preload.network 只能是 "all" 或 "wifi"。`);
|
|
5392
|
+
const normalizedPackages = [...new Set(packages.map((item) => normalizePackageRoot(item)).filter(Boolean))];
|
|
5393
|
+
if (normalizedPackages.length === 0) throw new TypeError(`routeRules.${pattern}.preload.packages 必须包含有效的分包 root。`);
|
|
5394
|
+
return {
|
|
5395
|
+
packages: normalizedPackages,
|
|
5396
|
+
...network === void 0 ? {} : { network }
|
|
5397
|
+
};
|
|
5398
|
+
}
|
|
5399
|
+
function getRuleScore(pattern) {
|
|
5400
|
+
const segments = pattern.split("/").filter(Boolean);
|
|
5401
|
+
const wildcards = pattern.match(PRELOAD_RULE_GLOB_RE) ?? [];
|
|
5402
|
+
PRELOAD_RULE_GLOB_RE.lastIndex = 0;
|
|
5403
|
+
return [
|
|
5404
|
+
segments.filter((segment) => {
|
|
5405
|
+
PRELOAD_RULE_GLOB_RE.lastIndex = 0;
|
|
5406
|
+
return !PRELOAD_RULE_GLOB_RE.test(segment);
|
|
5407
|
+
}).length,
|
|
5408
|
+
pattern.replace(PRELOAD_RULE_GLOB_RE, "").length,
|
|
5409
|
+
-wildcards.length,
|
|
5410
|
+
segments.length,
|
|
5411
|
+
pattern.length
|
|
5412
|
+
];
|
|
5413
|
+
}
|
|
5414
|
+
function compareScores(left, right) {
|
|
5415
|
+
for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
|
|
5416
|
+
const leftValue = left[index] ?? 0;
|
|
5417
|
+
const rightValue = right[index] ?? 0;
|
|
5418
|
+
if (leftValue !== rightValue) return leftValue > rightValue ? 1 : -1;
|
|
5419
|
+
}
|
|
5420
|
+
return 0;
|
|
5421
|
+
}
|
|
5422
|
+
function pageCandidates(page) {
|
|
5423
|
+
const normalized = normalizePagePath(page);
|
|
5424
|
+
const withoutPagesPrefix = normalized.startsWith("pages/") ? normalized.slice(6) : normalized;
|
|
5425
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
5426
|
+
for (const route of [normalized, withoutPagesPrefix]) {
|
|
5427
|
+
const withoutIndex = route.replace(/\/index$/, "") || route;
|
|
5428
|
+
for (const value of [route, withoutIndex]) {
|
|
5429
|
+
candidates.add(value);
|
|
5430
|
+
candidates.add(`/${value}`);
|
|
5431
|
+
}
|
|
5432
|
+
}
|
|
5433
|
+
return [...candidates];
|
|
5434
|
+
}
|
|
5435
|
+
function findRouteRuleMatch(page, routeRules) {
|
|
5436
|
+
if (!routeRules) return;
|
|
5437
|
+
const candidates = pageCandidates(page);
|
|
5438
|
+
let matched;
|
|
5439
|
+
for (const [pattern, value] of Object.entries(routeRules)) {
|
|
5440
|
+
if (!value || value.preload === void 0) continue;
|
|
5441
|
+
if (!candidates.some((candidate) => picomatch(pattern)(candidate))) continue;
|
|
5442
|
+
const rule = normalizeRule(value.preload, pattern);
|
|
5443
|
+
const score = getRuleScore(pattern);
|
|
5444
|
+
if (!matched || compareScores(score, matched.score) > 0) matched = {
|
|
5445
|
+
page,
|
|
5446
|
+
rule,
|
|
5447
|
+
pattern,
|
|
5448
|
+
score
|
|
5449
|
+
};
|
|
5450
|
+
}
|
|
5451
|
+
if (!matched) return;
|
|
5452
|
+
const { score: _score, ...result } = matched;
|
|
5453
|
+
return result;
|
|
5454
|
+
}
|
|
5455
|
+
function collectSubPackages(appJson) {
|
|
5456
|
+
return (Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : []).flatMap((item) => {
|
|
5457
|
+
if (!isObject(item) || typeof item.root !== "string") return [];
|
|
5458
|
+
const root = normalizePackageRoot(item.root);
|
|
5459
|
+
return (Array.isArray(item.pages) ? item.pages.filter((page) => typeof page === "string" && page.trim().length > 0) : []).map((page) => ({
|
|
5460
|
+
route: normalizePagePath(path.posix.join(root, page)),
|
|
5461
|
+
packageRoot: root
|
|
5462
|
+
}));
|
|
5463
|
+
});
|
|
5464
|
+
}
|
|
5465
|
+
function collectPreloadPages(appJson) {
|
|
5466
|
+
return [...Array.isArray(appJson.pages) ? appJson.pages.filter((page) => typeof page === "string" && page.trim().length > 0).map((page) => ({ route: normalizePagePath(page) })) : [], ...collectSubPackages(appJson)];
|
|
5467
|
+
}
|
|
5468
|
+
function findPreloadRuleKey(page, preloadRule) {
|
|
5469
|
+
const candidates = pageCandidates(page);
|
|
5470
|
+
return Object.keys(preloadRule).find((candidate) => candidates.includes(normalizePagePath(candidate)));
|
|
5471
|
+
}
|
|
5472
|
+
function cloneRule(rule) {
|
|
5473
|
+
if (!isObject(rule)) return rule;
|
|
5474
|
+
const packages = Array.isArray(rule.packages) ? rule.packages.filter((item) => typeof item === "string") : [];
|
|
5475
|
+
return {
|
|
5476
|
+
...rule,
|
|
5477
|
+
packages: [...packages]
|
|
5478
|
+
};
|
|
5479
|
+
}
|
|
5480
|
+
/**
|
|
5481
|
+
* @description 将 routeRules 中的 preload 声明合成为 app.json.preloadRule。
|
|
5482
|
+
* 手写的 preloadRule 保持优先,其他平台不生成微信专属字段。
|
|
5483
|
+
*/
|
|
5484
|
+
function applyPreloadRulesToAppJson(appJson, routeRules, platform) {
|
|
5485
|
+
if (platform !== "weapp" || !routeRules) return appJson;
|
|
5486
|
+
const existing = isObject(appJson.preloadRule) ? appJson.preloadRule : {};
|
|
5487
|
+
const next = { ...existing };
|
|
5488
|
+
for (const page of collectPreloadPages(appJson)) {
|
|
5489
|
+
const match = findRouteRuleMatch(page.route, routeRules);
|
|
5490
|
+
if (!match || findPreloadRuleKey(page.route, existing) !== void 0) continue;
|
|
5491
|
+
next[page.route] = cloneRule(match.rule);
|
|
5492
|
+
}
|
|
5493
|
+
if (Object.keys(next).length > 0) appJson.preloadRule = next;
|
|
5494
|
+
return appJson;
|
|
5495
|
+
}
|
|
5496
|
+
function suggestPreloadRules(appJson, pageSources) {
|
|
5497
|
+
const pages = collectPreloadPages(appJson);
|
|
5498
|
+
const packageByRoute = new Map(pages.map((page) => [page.route, page.packageRoot]));
|
|
5499
|
+
const suggestions = [];
|
|
5500
|
+
const uncovered = /* @__PURE__ */ new Set();
|
|
5501
|
+
for (const page of pages) {
|
|
5502
|
+
const source = pageSources.get(page.route);
|
|
5503
|
+
for (const kind of ["template", "script"]) for (const target of collectStaticRouteTargets(source?.[kind] ?? "", kind, page.route)) {
|
|
5504
|
+
const packageRoot = packageByRoute.get(target);
|
|
5505
|
+
if (!packageRoot || packageRoot === page.packageRoot) continue;
|
|
5506
|
+
const suggestion = {
|
|
5507
|
+
page: page.route,
|
|
5508
|
+
packageRoot,
|
|
5509
|
+
target,
|
|
5510
|
+
source: kind
|
|
5511
|
+
};
|
|
5512
|
+
suggestions.push(suggestion);
|
|
5513
|
+
}
|
|
5514
|
+
if (source && !source.template && !source.script) uncovered.add(page.route);
|
|
5515
|
+
}
|
|
5516
|
+
return {
|
|
5517
|
+
pages,
|
|
5518
|
+
suggestions,
|
|
5519
|
+
uncovered: [...uncovered]
|
|
5520
|
+
};
|
|
5521
|
+
}
|
|
5522
|
+
//#endregion
|
|
5306
5523
|
//#region src/utils/projectConfig.ts
|
|
5307
5524
|
async function readProjectConfigFile(filePath, required) {
|
|
5308
5525
|
if (!await fs$1.pathExists(filePath)) {
|
|
@@ -5342,6 +5559,17 @@ async function getProjectConfig(root, options) {
|
|
|
5342
5559
|
async function getProjectPrivateConfig(root, options) {
|
|
5343
5560
|
return await readProjectConfigFile(path.resolve(root, options?.privatePath ?? "project.private.config.json"), false);
|
|
5344
5561
|
}
|
|
5562
|
+
async function disableProjectPrivateConfigHotReload(filePath) {
|
|
5563
|
+
const config = await readProjectConfigFile(filePath, true);
|
|
5564
|
+
const setting = config.setting && typeof config.setting === "object" && !Array.isArray(config.setting) ? config.setting : {};
|
|
5565
|
+
if (setting.compileHotReLoad === false) return false;
|
|
5566
|
+
config.setting = {
|
|
5567
|
+
...setting,
|
|
5568
|
+
compileHotReLoad: false
|
|
5569
|
+
};
|
|
5570
|
+
await fs$1.writeFile(filePath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
5571
|
+
return true;
|
|
5572
|
+
}
|
|
5345
5573
|
function resolveProjectConfigSyncDirs(options) {
|
|
5346
5574
|
const outputRoot = path.dirname(options.outDir);
|
|
5347
5575
|
const sourceBasePath = path.resolve(options.projectConfigPath);
|
|
@@ -5723,7 +5951,7 @@ function createRegistryHelpers(state) {
|
|
|
5723
5951
|
}
|
|
5724
5952
|
const nextKey = globs.join("\0");
|
|
5725
5953
|
if (!state.autoImportState.matcher || state.autoImportState.matcherKey !== nextKey) {
|
|
5726
|
-
state.autoImportState.matcher =
|
|
5954
|
+
state.autoImportState.matcher = picomatch(globs, { windows: true });
|
|
5727
5955
|
state.autoImportState.matcherKey = nextKey;
|
|
5728
5956
|
}
|
|
5729
5957
|
return state.autoImportState.matcher;
|
|
@@ -6206,7 +6434,7 @@ function createRule(pattern) {
|
|
|
6206
6434
|
};
|
|
6207
6435
|
return {
|
|
6208
6436
|
pattern,
|
|
6209
|
-
match:
|
|
6437
|
+
match: picomatch(pattern, { dot: true })
|
|
6210
6438
|
};
|
|
6211
6439
|
}
|
|
6212
6440
|
function isDefaultAutoRouteInclude(include) {
|
|
@@ -6744,14 +6972,12 @@ function normalizeScopedSubPackage(subPackage) {
|
|
|
6744
6972
|
pages: Array.isArray(subPackage.pages) ? subPackage.pages : []
|
|
6745
6973
|
};
|
|
6746
6974
|
}
|
|
6747
|
-
function filterPreloadRule(preloadRule,
|
|
6975
|
+
function filterPreloadRule(preloadRule, scopedPages, scopedPackageIdentifiers, includeMainPackage) {
|
|
6748
6976
|
if (!preloadRule || typeof preloadRule !== "object") return preloadRule;
|
|
6749
|
-
const scopedRoots = new Set(scope.subPackageRoots);
|
|
6750
6977
|
const scopedPreloadRule = {};
|
|
6751
6978
|
for (const [pagePath, rule] of Object.entries(preloadRule)) {
|
|
6752
6979
|
const normalizedPagePath = normalizeRoot(pagePath);
|
|
6753
|
-
|
|
6754
|
-
if (!(pageSubPackageRoot ? scopedRoots.has(pageSubPackageRoot) : scope.includeMainPackage)) continue;
|
|
6980
|
+
if (!scopedPages.has(normalizedPagePath)) continue;
|
|
6755
6981
|
if (!rule || typeof rule !== "object" || !("packages" in rule)) {
|
|
6756
6982
|
scopedPreloadRule[pagePath] = rule;
|
|
6757
6983
|
continue;
|
|
@@ -6762,7 +6988,9 @@ function filterPreloadRule(preloadRule, scope, allSubPackageRoots) {
|
|
|
6762
6988
|
continue;
|
|
6763
6989
|
}
|
|
6764
6990
|
const filteredPackages = packages.filter((packageRoot) => {
|
|
6765
|
-
|
|
6991
|
+
if (typeof packageRoot !== "string") return false;
|
|
6992
|
+
const normalizedPackageRoot = normalizeRoot(packageRoot);
|
|
6993
|
+
return normalizedPackageRoot === "__APP__" ? includeMainPackage : scopedPackageIdentifiers.has(normalizedPackageRoot);
|
|
6766
6994
|
});
|
|
6767
6995
|
if (filteredPackages.length > 0) scopedPreloadRule[pagePath] = {
|
|
6768
6996
|
...rule,
|
|
@@ -6771,18 +6999,49 @@ function filterPreloadRule(preloadRule, scope, allSubPackageRoots) {
|
|
|
6771
6999
|
}
|
|
6772
7000
|
return Object.keys(scopedPreloadRule).length > 0 ? scopedPreloadRule : void 0;
|
|
6773
7001
|
}
|
|
7002
|
+
function collectScopedAppGraph(pages, subPackages) {
|
|
7003
|
+
const mainPages = new Set(pages.map((page) => normalizeRoot(page)));
|
|
7004
|
+
const allPages = new Set(mainPages);
|
|
7005
|
+
const packageIdentifiers = /* @__PURE__ */ new Set();
|
|
7006
|
+
for (const subPackage of subPackages) {
|
|
7007
|
+
const root = normalizeRoot(subPackage.root ?? "");
|
|
7008
|
+
if (!root) continue;
|
|
7009
|
+
packageIdentifiers.add(root);
|
|
7010
|
+
if (typeof subPackage.name === "string" && subPackage.name.trim()) packageIdentifiers.add(normalizeRoot(subPackage.name));
|
|
7011
|
+
for (const page of subPackage.pages ?? []) allPages.add(normalizeRoot(`${root}/${page}`));
|
|
7012
|
+
}
|
|
7013
|
+
return {
|
|
7014
|
+
allPages,
|
|
7015
|
+
mainPages,
|
|
7016
|
+
packageIdentifiers
|
|
7017
|
+
};
|
|
7018
|
+
}
|
|
7019
|
+
function filterTabBar(tabBar, mainPages) {
|
|
7020
|
+
if (!tabBar || !Array.isArray(tabBar.list)) return tabBar;
|
|
7021
|
+
const list = tabBar.list.filter((item) => {
|
|
7022
|
+
return typeof item.pagePath === "string" && mainPages.has(normalizeRoot(item.pagePath));
|
|
7023
|
+
});
|
|
7024
|
+
if (list.length < 2) return;
|
|
7025
|
+
return {
|
|
7026
|
+
...tabBar,
|
|
7027
|
+
list
|
|
7028
|
+
};
|
|
7029
|
+
}
|
|
6774
7030
|
function applyBuildScopeToAppConfig(config, scope) {
|
|
6775
7031
|
if (!scope?.enabled) return config;
|
|
6776
7032
|
const scopedRoots = new Set(scope.subPackageRoots);
|
|
6777
|
-
const
|
|
6778
|
-
const allSubPackageRoots = new Set(sourceSubPackages.map((subPackage) => subPackage.root ? normalizeRoot(subPackage.root) : void 0).filter((root) => Boolean(root)));
|
|
6779
|
-
const scopedSubPackages = sourceSubPackages.filter((subPackage) => isSubPackageInScope(subPackage, scopedRoots)).map(normalizeScopedSubPackage);
|
|
7033
|
+
const scopedSubPackages = (Array.isArray(config.subPackages) ? config.subPackages : Array.isArray(config.subpackages) ? config.subpackages : []).filter((subPackage) => isSubPackageInScope(subPackage, scopedRoots)).map(normalizeScopedSubPackage);
|
|
6780
7034
|
config.pages = scope.includeMainPackage && Array.isArray(config.pages) ? config.pages : [];
|
|
6781
7035
|
config.subPackages = scopedSubPackages;
|
|
6782
7036
|
delete config.subpackages;
|
|
6783
|
-
const
|
|
7037
|
+
const scopedGraph = collectScopedAppGraph(config.pages, scopedSubPackages);
|
|
7038
|
+
const preloadRule = filterPreloadRule(config.preloadRule, scopedGraph.allPages, scopedGraph.packageIdentifiers, scope.includeMainPackage);
|
|
6784
7039
|
if (preloadRule) config.preloadRule = preloadRule;
|
|
6785
7040
|
else delete config.preloadRule;
|
|
7041
|
+
const tabBar = filterTabBar(config.tabBar, scopedGraph.mainPages);
|
|
7042
|
+
if (tabBar) config.tabBar = tabBar;
|
|
7043
|
+
else delete config.tabBar;
|
|
7044
|
+
if (typeof config.entryPagePath === "string" && !scopedGraph.mainPages.has(normalizeRoot(config.entryPagePath))) delete config.entryPagePath;
|
|
6786
7045
|
return config;
|
|
6787
7046
|
}
|
|
6788
7047
|
function applyBuildScopeToAutoRoutes(routes, scope) {
|
|
@@ -7874,18 +8133,65 @@ function resolveCompilerOutputExtensions(outputExtensions) {
|
|
|
7874
8133
|
}
|
|
7875
8134
|
//#endregion
|
|
7876
8135
|
//#region src/runtime/hmrRuntime.ts
|
|
7877
|
-
function
|
|
7878
|
-
|
|
7879
|
-
if (options.platform === "weapp" && options.
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
8136
|
+
function resolveHmrRuntimeDecision(options) {
|
|
8137
|
+
const configured = options.configured ?? "auto";
|
|
8138
|
+
if (options.platform === "weapp" && options.skyline === true) return {
|
|
8139
|
+
configured,
|
|
8140
|
+
reason: "skyline-fallback",
|
|
8141
|
+
runtime: "classic"
|
|
8142
|
+
};
|
|
8143
|
+
if (configured === "classic" || configured === "stateful-experimental") return {
|
|
8144
|
+
configured,
|
|
8145
|
+
reason: "explicit",
|
|
8146
|
+
runtime: configured
|
|
8147
|
+
};
|
|
8148
|
+
if (options.platform === "weapp" && options.compileHotReLoad === true) return {
|
|
8149
|
+
configured,
|
|
8150
|
+
reason: "auto-stateful",
|
|
8151
|
+
runtime: "stateful-experimental"
|
|
8152
|
+
};
|
|
8153
|
+
return {
|
|
8154
|
+
configured,
|
|
8155
|
+
reason: options.platform === "weapp" ? "auto-classic" : "auto-non-wechat",
|
|
8156
|
+
runtime: "classic"
|
|
8157
|
+
};
|
|
8158
|
+
}
|
|
8159
|
+
function findSkylineRendererFiles(output) {
|
|
8160
|
+
const jsonConfigs = /* @__PURE__ */ new Map();
|
|
8161
|
+
for (const item of output) {
|
|
8162
|
+
if (item.type !== "asset" || !item.fileName.endsWith(".json")) continue;
|
|
8163
|
+
const source = typeof item.source === "string" ? item.source : item.source instanceof Uint8Array ? new TextDecoder().decode(item.source) : void 0;
|
|
8164
|
+
if (!source) continue;
|
|
8165
|
+
try {
|
|
8166
|
+
const config = JSON.parse(source);
|
|
8167
|
+
if (config && typeof config === "object" && !Array.isArray(config)) jsonConfigs.set(item.fileName.replaceAll("\\", "/"), config);
|
|
8168
|
+
} catch {}
|
|
8169
|
+
}
|
|
8170
|
+
const appConfig = jsonConfigs.get("app.json");
|
|
8171
|
+
if (!appConfig) return [];
|
|
8172
|
+
const configFiles = /* @__PURE__ */ new Set(["app.json"]);
|
|
8173
|
+
if (Array.isArray(appConfig.pages)) {
|
|
8174
|
+
for (const page of appConfig.pages) if (typeof page === "string") configFiles.add(`${page}.json`);
|
|
8175
|
+
}
|
|
8176
|
+
const subPackages = Array.isArray(appConfig.subPackages) ? appConfig.subPackages : Array.isArray(appConfig.subpackages) ? appConfig.subpackages : [];
|
|
8177
|
+
for (const subPackage of subPackages) {
|
|
8178
|
+
if (!subPackage || typeof subPackage !== "object" || Array.isArray(subPackage)) continue;
|
|
8179
|
+
const { pages, root } = subPackage;
|
|
8180
|
+
if (typeof root !== "string" || !Array.isArray(pages)) continue;
|
|
8181
|
+
const normalizedRoot = root.replaceAll("\\", "/").replace(/^\/+|\/+$/g, "");
|
|
8182
|
+
for (const page of pages) if (typeof page === "string") configFiles.add(`${normalizedRoot}/${page}.json`);
|
|
8183
|
+
}
|
|
8184
|
+
return [...configFiles].filter((fileName) => jsonConfigs.get(fileName)?.renderer === "skyline");
|
|
8185
|
+
}
|
|
8186
|
+
function formatHmrRuntimeStartupMessages(decision) {
|
|
8187
|
+
if (decision.reason === "skyline-fallback") return ["HMR 模式:classic(自动降级:Skyline 暂不支持微信开发者工具热重载)", "HMR 切换:切回 WebView 后可手动重新开启微信开发者工具“热重载”。"];
|
|
8188
|
+
if (decision.reason === "runtime-compatibility-fallback") return ["HMR 模式:classic(自动降级:stateful HMR 运行时兼容性检查失败)", "HMR 切换:修复兼容性问题后重启 wv dev,或通过 weapp.hmr.runtime 显式配置 classic。"];
|
|
8189
|
+
if (decision.reason === "explicit") {
|
|
8190
|
+
const alternative = decision.runtime === "classic" ? "stateful-experimental" : "classic";
|
|
8191
|
+
return [`HMR 模式:${decision.runtime}(显式配置)`, `HMR 切换:修改 weapp.hmr.runtime 为 auto 或 ${alternative} 后重启 wv dev。`];
|
|
8192
|
+
}
|
|
8193
|
+
if (decision.reason === "auto-non-wechat") return ["HMR 模式:classic(自动检测:仅微信小程序支持 stateful-experimental)", "HMR 切换:可通过 weapp.hmr.runtime 显式配置 classic。"];
|
|
8194
|
+
if (decision.reason === "auto-stateful") return ["HMR 模式:stateful-experimental(自动检测:微信开发者工具热重载已开启)", "HMR 切换:关闭微信开发者工具“热重载”后重启 wv dev,或通过 weapp.hmr.runtime 显式配置。"];
|
|
7889
8195
|
return ["HMR 模式:classic(自动检测:微信开发者工具热重载未开启或无法确认)", "HMR 切换:开启微信开发者工具“热重载”后重启 wv dev,或通过 weapp.hmr.runtime 显式配置。"];
|
|
7890
8196
|
}
|
|
7891
8197
|
//#endregion
|
|
@@ -10602,7 +10908,7 @@ function resolveNodeModulesSharedPath(cleanedAbsoluteId) {
|
|
|
10602
10908
|
}
|
|
10603
10909
|
function createStringOrRegExpMatcher(pattern) {
|
|
10604
10910
|
if (typeof pattern === "string") {
|
|
10605
|
-
const matcher =
|
|
10911
|
+
const matcher = picomatch(pattern, { dot: true });
|
|
10606
10912
|
return (value) => matcher(value);
|
|
10607
10913
|
}
|
|
10608
10914
|
if (isRegexp(pattern)) return (value) => {
|
|
@@ -11207,6 +11513,8 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11207
11513
|
let pendingBatch;
|
|
11208
11514
|
let requestGeneration = 0;
|
|
11209
11515
|
let activeRequest;
|
|
11516
|
+
let lastRequestError;
|
|
11517
|
+
let lastResponse;
|
|
11210
11518
|
let timer;
|
|
11211
11519
|
const sessionId = Date.now().toString(36) + '-' + Math.random().toString(36).slice(2);
|
|
11212
11520
|
const schedule = (delay) => {
|
|
@@ -11230,7 +11538,9 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11230
11538
|
success(result) {
|
|
11231
11539
|
if (generation !== requestGeneration) return;
|
|
11232
11540
|
activeRequest = undefined;
|
|
11541
|
+
lastRequestError = undefined;
|
|
11233
11542
|
const type = result?.data?.type;
|
|
11543
|
+
lastResponse = { action, statusCode: result?.statusCode, type };
|
|
11234
11544
|
if (action === 'register' && type === 'registered') {
|
|
11235
11545
|
phase = 'polling';
|
|
11236
11546
|
if (pendingBatch) globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CLIENT_KEY)}].receiveBatch(pendingBatch.meta, pendingBatch.apply);
|
|
@@ -11240,9 +11550,14 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11240
11550
|
else if (type === 'rebuilding') schedule(1000);
|
|
11241
11551
|
else schedule(500);
|
|
11242
11552
|
},
|
|
11243
|
-
fail() {
|
|
11553
|
+
fail(error) {
|
|
11244
11554
|
if (generation !== requestGeneration) return;
|
|
11245
11555
|
activeRequest = undefined;
|
|
11556
|
+
lastRequestError = {
|
|
11557
|
+
action,
|
|
11558
|
+
errMsg: String(error?.errMsg || ''),
|
|
11559
|
+
errno: error?.errno,
|
|
11560
|
+
};
|
|
11246
11561
|
schedule(500);
|
|
11247
11562
|
}
|
|
11248
11563
|
});
|
|
@@ -11262,6 +11577,7 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11262
11577
|
lastApply: undefined,
|
|
11263
11578
|
getVersion() { return version; },
|
|
11264
11579
|
getLastApply() { return this.lastApply; },
|
|
11580
|
+
getTransportState() { return { phase, version, lastRequestError, lastResponse }; },
|
|
11265
11581
|
stop() {
|
|
11266
11582
|
phase = 'stopped';
|
|
11267
11583
|
if (timer) {
|
|
@@ -11911,6 +12227,36 @@ function createReactPlugin(ctx) {
|
|
|
11911
12227
|
}];
|
|
11912
12228
|
}
|
|
11913
12229
|
//#endregion
|
|
12230
|
+
//#region src/runtime/watch/options.ts
|
|
12231
|
+
/**
|
|
12232
|
+
* 解析主 watcher 与 sidecar watcher 共享的轮询配置。
|
|
12233
|
+
*/
|
|
12234
|
+
function resolvePollingWatchOptions(configService) {
|
|
12235
|
+
const buildWatch = configService.inlineConfig?.build?.watch;
|
|
12236
|
+
const chokidar = buildWatch && typeof buildWatch === "object" && "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
12237
|
+
const serverWatch = configService.inlineConfig?.server?.watch;
|
|
12238
|
+
const envUsePolling = process.env.CHOKIDAR_USEPOLLING;
|
|
12239
|
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
12240
|
+
const envBinaryInterval = process.env.CHOKIDAR_BINARY_INTERVAL;
|
|
12241
|
+
const usePollingCandidate = chokidar?.usePolling ?? serverWatch?.usePolling ?? (envUsePolling === "1" || envUsePolling === "true" ? true : envUsePolling === "0" || envUsePolling === "false" ? false : void 0);
|
|
12242
|
+
const intervalCandidate = chokidar?.interval ?? serverWatch?.interval ?? (envInterval ? Number(envInterval) : void 0);
|
|
12243
|
+
const binaryIntervalCandidate = chokidar?.binaryInterval ?? serverWatch?.binaryInterval ?? (envBinaryInterval ? Number(envBinaryInterval) : void 0);
|
|
12244
|
+
return {
|
|
12245
|
+
usePolling: typeof usePollingCandidate === "boolean" ? usePollingCandidate : void 0,
|
|
12246
|
+
interval: typeof intervalCandidate === "number" && Number.isFinite(intervalCandidate) ? intervalCandidate : void 0,
|
|
12247
|
+
binaryInterval: typeof binaryIntervalCandidate === "number" && Number.isFinite(binaryIntervalCandidate) ? binaryIntervalCandidate : void 0
|
|
12248
|
+
};
|
|
12249
|
+
}
|
|
12250
|
+
function createSidecarWatchOptions(configService, input) {
|
|
12251
|
+
const polling = resolvePollingWatchOptions(configService);
|
|
12252
|
+
return {
|
|
12253
|
+
...input,
|
|
12254
|
+
...polling.usePolling !== void 0 ? { usePolling: polling.usePolling } : {},
|
|
12255
|
+
...typeof polling.interval === "number" ? { interval: polling.interval } : {},
|
|
12256
|
+
...typeof polling.binaryInterval === "number" ? { binaryInterval: polling.binaryInterval } : {}
|
|
12257
|
+
};
|
|
12258
|
+
}
|
|
12259
|
+
//#endregion
|
|
11914
12260
|
//#region src/runtime/statefulHmr/outputWriter.ts
|
|
11915
12261
|
/**
|
|
11916
12262
|
* @description 通过独立的 Vite write 阶段持久化 DevEngine 已生成的文件,不重新解析业务源码。
|
|
@@ -12232,7 +12578,7 @@ var StatefulHmrTransport = class {
|
|
|
12232
12578
|
return {
|
|
12233
12579
|
buildId: this.state.buildId,
|
|
12234
12580
|
token: this.token,
|
|
12235
|
-
url: `http://
|
|
12581
|
+
url: `http://localhost:${port}${endpointPath}`
|
|
12236
12582
|
};
|
|
12237
12583
|
}
|
|
12238
12584
|
handleRequest = async (request, response) => {
|
|
@@ -12374,12 +12720,16 @@ var StatefulHmrViteAdapter = class {
|
|
|
12374
12720
|
config;
|
|
12375
12721
|
server;
|
|
12376
12722
|
callbacks;
|
|
12723
|
+
watchOptions;
|
|
12724
|
+
createDevEngine;
|
|
12377
12725
|
bundledDev;
|
|
12378
12726
|
initialOutputError;
|
|
12379
|
-
constructor(config, server, callbacks) {
|
|
12727
|
+
constructor(config, server, callbacks, watchOptions = {}, createDevEngine = dev) {
|
|
12380
12728
|
this.config = config;
|
|
12381
12729
|
this.server = server;
|
|
12382
12730
|
this.callbacks = callbacks;
|
|
12731
|
+
this.watchOptions = watchOptions;
|
|
12732
|
+
this.createDevEngine = createDevEngine;
|
|
12383
12733
|
}
|
|
12384
12734
|
install() {
|
|
12385
12735
|
const bundledDev = this.server.environments.client.bundledDev;
|
|
@@ -12388,7 +12738,6 @@ var StatefulHmrViteAdapter = class {
|
|
|
12388
12738
|
this.bundledDev = bundledDev;
|
|
12389
12739
|
this.installOptions(bundledDev);
|
|
12390
12740
|
this.installOutput(bundledDev);
|
|
12391
|
-
this.installPatches(bundledDev);
|
|
12392
12741
|
this.installListener(bundledDev);
|
|
12393
12742
|
}
|
|
12394
12743
|
async rebuild(prepare) {
|
|
@@ -12476,34 +12825,46 @@ var StatefulHmrViteAdapter = class {
|
|
|
12476
12825
|
}
|
|
12477
12826
|
};
|
|
12478
12827
|
}
|
|
12479
|
-
installPatches(bundledDev) {
|
|
12480
|
-
const original = bundledDev.handleHmrOutput.bind(bundledDev);
|
|
12481
|
-
bundledDev.handleHmrOutput = (client, files, output, info) => {
|
|
12482
|
-
if (output.type === "Noop") {
|
|
12483
|
-
this.callbacks.onPatch(files, output);
|
|
12484
|
-
return;
|
|
12485
|
-
}
|
|
12486
|
-
if (this.callbacks.onPatch(files, output)) original(client, files, output, info);
|
|
12487
|
-
};
|
|
12488
|
-
}
|
|
12489
12828
|
installListener(bundledDev) {
|
|
12490
|
-
const original = bundledDev.listen.bind(bundledDev);
|
|
12491
12829
|
bundledDev.listen = async () => {
|
|
12492
|
-
await
|
|
12493
|
-
|
|
12494
|
-
const
|
|
12495
|
-
|
|
12496
|
-
|
|
12830
|
+
const rolldownOptions = await bundledDev.getRolldownOptions();
|
|
12831
|
+
if (Array.isArray(rolldownOptions.output) && rolldownOptions.output.length > 1) throw new Error("stateful-experimental HMR 不支持多组 Rolldown output 配置。");
|
|
12832
|
+
const outputOptions = Array.isArray(rolldownOptions.output) ? rolldownOptions.output[0] : rolldownOptions.output;
|
|
12833
|
+
const engine = await this.createDevEngine(rolldownOptions, outputOptions, {
|
|
12834
|
+
onAdditionalAssets: (result) => bundledDev.storeOutputFiles(result.output),
|
|
12835
|
+
onHmrUpdates: (result) => this.handleHmrUpdates(result),
|
|
12836
|
+
onOutput: (result) => {
|
|
12837
|
+
if (result instanceof Error) {
|
|
12838
|
+
this.initialOutputError = result;
|
|
12839
|
+
this.callbacks.onError(result.message);
|
|
12840
|
+
return;
|
|
12841
|
+
}
|
|
12842
|
+
bundledDev.storeOutputFiles(result.output);
|
|
12843
|
+
},
|
|
12844
|
+
watch: {
|
|
12845
|
+
skipWrite: true,
|
|
12846
|
+
...this.watchOptions
|
|
12847
|
+
}
|
|
12848
|
+
});
|
|
12849
|
+
bundledDev._devEngine = engine;
|
|
12850
|
+
engine.run().catch((error) => {
|
|
12851
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
12852
|
+
this.callbacks.onError(message);
|
|
12853
|
+
});
|
|
12854
|
+
await engine.registerClient(clientId);
|
|
12497
12855
|
await engine.ensureCurrentBuildFinish();
|
|
12498
12856
|
if (this.initialOutputError) throw this.initialOutputError;
|
|
12499
12857
|
if ((await engine.getBundleState()).lastBuildErrored) throw new Error("微信状态保持 HMR 初次构建失败。");
|
|
12500
12858
|
await this.callbacks.waitForInitialBundle();
|
|
12501
12859
|
};
|
|
12502
12860
|
}
|
|
12503
|
-
|
|
12504
|
-
if (
|
|
12505
|
-
|
|
12506
|
-
|
|
12861
|
+
handleHmrUpdates(result) {
|
|
12862
|
+
if (result instanceof Error) {
|
|
12863
|
+
this.callbacks.onError(result.message);
|
|
12864
|
+
return;
|
|
12865
|
+
}
|
|
12866
|
+
if (result.changedFiles.length === 0) return;
|
|
12867
|
+
for (const { clientId: updateClientId, update } of result.updates) if (updateClientId === clientId) this.callbacks.onPatch(result.changedFiles, update);
|
|
12507
12868
|
}
|
|
12508
12869
|
};
|
|
12509
12870
|
function createStatefulHmrBanner(chunk) {
|
|
@@ -12540,16 +12901,22 @@ async function runStatefulHmrDev(ctx, buildOptions, restart, snapshots) {
|
|
|
12540
12901
|
const configService = ctx.configService;
|
|
12541
12902
|
if (configService.platform !== "weapp") throw new Error("weapp.hmr.runtime=\"stateful-experimental\" 目前仅支持微信小程序平台。");
|
|
12542
12903
|
let session;
|
|
12904
|
+
const entryIds = new Set(Array.from(snapshots.entryIds, (id) => normalizeFsResolvedId(id)));
|
|
12905
|
+
const pollingWatchOptions = resolvePollingWatchOptions(configService);
|
|
12543
12906
|
const installPlugin = {
|
|
12544
12907
|
name: "weapp-vite:stateful-hmr-session",
|
|
12545
12908
|
enforce: "post",
|
|
12546
12909
|
configureServer(server) {
|
|
12547
|
-
const currentSession = new StatefulHmrSession(ctx, server, restart, snapshots
|
|
12910
|
+
const currentSession = new StatefulHmrSession(ctx, server, restart, entryIds, snapshots, {
|
|
12911
|
+
compareContentsForPolling: pollingWatchOptions.usePolling === true ? true : void 0,
|
|
12912
|
+
pollInterval: pollingWatchOptions.interval,
|
|
12913
|
+
usePolling: pollingWatchOptions.usePolling
|
|
12914
|
+
});
|
|
12548
12915
|
session = currentSession;
|
|
12549
12916
|
currentSession.install();
|
|
12550
12917
|
},
|
|
12551
12918
|
transform(code, id) {
|
|
12552
|
-
if (!isStatefulHmrBoundary(id, configService.absoluteSrcRoot,
|
|
12919
|
+
if (!isStatefulHmrBoundary(id, configService.absoluteSrcRoot, entryIds) || code.includes("import.meta.hot.accept")) return;
|
|
12553
12920
|
return `${id.endsWith(".vue") ? code : redirectNativeComponentRegistration(code)}\nif (import.meta.hot) import.meta.hot.accept();\n`;
|
|
12554
12921
|
}
|
|
12555
12922
|
};
|
|
@@ -12609,6 +12976,7 @@ var StatefulHmrSession = class {
|
|
|
12609
12976
|
ctx;
|
|
12610
12977
|
server;
|
|
12611
12978
|
restart;
|
|
12979
|
+
entryIds;
|
|
12612
12980
|
snapshots;
|
|
12613
12981
|
activeSnapshotBatch;
|
|
12614
12982
|
adapter;
|
|
@@ -12621,10 +12989,11 @@ var StatefulHmrSession = class {
|
|
|
12621
12989
|
sourceChangeListener = (file, dirtyReasonSummary) => {
|
|
12622
12990
|
this.handleSourceUpdate(file, dirtyReasonSummary);
|
|
12623
12991
|
};
|
|
12624
|
-
constructor(ctx, server, restart, snapshots) {
|
|
12992
|
+
constructor(ctx, server, restart, entryIds, snapshots, devWatchOptions) {
|
|
12625
12993
|
this.ctx = ctx;
|
|
12626
12994
|
this.server = server;
|
|
12627
12995
|
this.restart = restart;
|
|
12996
|
+
this.entryIds = entryIds;
|
|
12628
12997
|
this.snapshots = snapshots;
|
|
12629
12998
|
this.replaceSnapshotAssets(snapshots.initial);
|
|
12630
12999
|
this.transport = new StatefulHmrTransport(server, async (buildId, source) => {
|
|
@@ -12642,7 +13011,7 @@ var StatefulHmrSession = class {
|
|
|
12642
13011
|
onOutput: (output) => this.handleOutput(output),
|
|
12643
13012
|
onPatch: (files, output) => this.handlePatch(files, output),
|
|
12644
13013
|
waitForInitialBundle: () => this.waitForInitialBundle()
|
|
12645
|
-
});
|
|
13014
|
+
}, devWatchOptions);
|
|
12646
13015
|
this.snapshotScheduler = new StatefulHmrSnapshotScheduler({
|
|
12647
13016
|
execute: (batch) => this.executeSnapshotBatch(batch),
|
|
12648
13017
|
onError: (error) => this.server.config.logger.error("[weapp-vite] stateful HMR snapshot refresh failed", { error: error instanceof Error ? error : new Error(String(error)) })
|
|
@@ -12710,7 +13079,7 @@ var StatefulHmrSession = class {
|
|
|
12710
13079
|
}
|
|
12711
13080
|
handlePatch(files, output) {
|
|
12712
13081
|
if (output.type === "Noop") return false;
|
|
12713
|
-
if (!isSafeJavaScriptPatch(files, output, this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary, this.
|
|
13082
|
+
if (!isSafeJavaScriptPatch(files, output, this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary, this.entryIds, this.server.config.root)) {
|
|
12714
13083
|
if (shouldRestartStatefulHmrServer(files, this.ctx.configService?.configFileDependencies)) this.requestServerRestart();
|
|
12715
13084
|
else if (this.snapshotScheduler.isPending() || files.length > 0 && files.every(isStatefulHmrAssetFile) || shouldUseStatefulHmrSnapshotOnly(this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary ?? [])) {
|
|
12716
13085
|
if (!this.snapshotScheduler.isPending()) this.requestSnapshotRefresh(files);
|
|
@@ -12902,33 +13271,6 @@ function formatStatefulHmrError(error) {
|
|
|
12902
13271
|
return String(error);
|
|
12903
13272
|
}
|
|
12904
13273
|
//#endregion
|
|
12905
|
-
//#region src/runtime/watch/options.ts
|
|
12906
|
-
function resolvePollingWatchConfig(configService) {
|
|
12907
|
-
const buildWatch = configService.inlineConfig?.build?.watch;
|
|
12908
|
-
const chokidar = buildWatch && typeof buildWatch === "object" && "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
12909
|
-
const serverWatch = configService.inlineConfig?.server?.watch;
|
|
12910
|
-
const envUsePolling = process.env.CHOKIDAR_USEPOLLING;
|
|
12911
|
-
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
12912
|
-
const envBinaryInterval = process.env.CHOKIDAR_BINARY_INTERVAL;
|
|
12913
|
-
const usePollingCandidate = chokidar?.usePolling ?? serverWatch?.usePolling ?? (envUsePolling === "1" || envUsePolling === "true" ? true : envUsePolling === "0" || envUsePolling === "false" ? false : void 0);
|
|
12914
|
-
const intervalCandidate = chokidar?.interval ?? serverWatch?.interval ?? (envInterval ? Number(envInterval) : void 0);
|
|
12915
|
-
const binaryIntervalCandidate = chokidar?.binaryInterval ?? serverWatch?.binaryInterval ?? (envBinaryInterval ? Number(envBinaryInterval) : void 0);
|
|
12916
|
-
return {
|
|
12917
|
-
usePolling: typeof usePollingCandidate === "boolean" ? usePollingCandidate : void 0,
|
|
12918
|
-
interval: typeof intervalCandidate === "number" && Number.isFinite(intervalCandidate) ? intervalCandidate : void 0,
|
|
12919
|
-
binaryInterval: typeof binaryIntervalCandidate === "number" && Number.isFinite(binaryIntervalCandidate) ? binaryIntervalCandidate : void 0
|
|
12920
|
-
};
|
|
12921
|
-
}
|
|
12922
|
-
function createSidecarWatchOptions(configService, input) {
|
|
12923
|
-
const polling = resolvePollingWatchConfig(configService);
|
|
12924
|
-
return {
|
|
12925
|
-
...input,
|
|
12926
|
-
...polling.usePolling !== void 0 ? { usePolling: polling.usePolling } : {},
|
|
12927
|
-
...typeof polling.interval === "number" ? { interval: polling.interval } : {},
|
|
12928
|
-
...typeof polling.binaryInterval === "number" ? { binaryInterval: polling.binaryInterval } : {}
|
|
12929
|
-
};
|
|
12930
|
-
}
|
|
12931
|
-
//#endregion
|
|
12932
13274
|
//#region src/plugins/autoImport.ts
|
|
12933
13275
|
const LEADING_DOT_SLASH_RE$2 = /^\.\//;
|
|
12934
13276
|
const LEADING_SLASHES_RE$2 = /^\/+/;
|
|
@@ -13676,6 +14018,12 @@ function transformWxsCode(code, options) {
|
|
|
13676
14018
|
const expression = p.node.expression;
|
|
13677
14019
|
if (expression.type === "CallExpression" && expression.callee.type === "MemberExpression" && t.isIdentifier(expression.callee.object) && expression.callee.object.name === "Object" && t.isIdentifier(expression.callee.property) && expression.callee.property.name === "defineProperty" && expression.arguments.length >= 2 && t.isIdentifier(expression.arguments[0]) && expression.arguments[0].name === "exports" && t.isStringLiteral(expression.arguments[1]) && expression.arguments[1].value === "__esModule") p.remove();
|
|
13678
14020
|
},
|
|
14021
|
+
AssignmentExpression: { enter(p) {
|
|
14022
|
+
if (!preserveEsmExports || p.node.operator !== "=") return;
|
|
14023
|
+
const left = p.node.left;
|
|
14024
|
+
if (!t.isMemberExpression(left) || left.computed || !t.isIdentifier(left.object, { name: "module" }) || !t.isIdentifier(left.property, { name: "exports" }) || !p.parentPath.isExpressionStatement()) return;
|
|
14025
|
+
p.parentPath.replaceWith(t.exportDefaultDeclaration(p.node.right));
|
|
14026
|
+
} },
|
|
13679
14027
|
NewExpression: { enter(p) {
|
|
13680
14028
|
const node = p.node;
|
|
13681
14029
|
if (t.isIdentifier(node.callee, { name: "RegExp" })) p.replaceWith(t.callExpression(t.identifier("getRegExp"), node.arguments));
|
|
@@ -15289,8 +15637,50 @@ function createSnapshotSidecarIgnoredMatcher(ctx) {
|
|
|
15289
15637
|
}
|
|
15290
15638
|
function createBuildService(ctx) {
|
|
15291
15639
|
let lastHmrSlowTipProfileCount = 0;
|
|
15292
|
-
let
|
|
15640
|
+
let devHmrDecision;
|
|
15293
15641
|
let devHmrRuntimeNoticeLogged = false;
|
|
15642
|
+
let skylineHmrFallbackApplied = false;
|
|
15643
|
+
const SKYLINE_HMR_COMPATIBILITY_URL = "https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/skyline/migration/compatibility.html#%E5%B8%B8%E8%A7%81%E7%9A%84%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98";
|
|
15644
|
+
function logHmrRuntimeDecision(decision) {
|
|
15645
|
+
if (devHmrRuntimeNoticeLogged) return;
|
|
15646
|
+
devHmrRuntimeNoticeLogged = true;
|
|
15647
|
+
for (const message of formatHmrRuntimeStartupMessages(decision)) logger_default.info(message);
|
|
15648
|
+
}
|
|
15649
|
+
async function applySkylineHmrFallback(options) {
|
|
15650
|
+
const configService = ctx.configService;
|
|
15651
|
+
if (!configService) return false;
|
|
15652
|
+
const currentDecision = devHmrDecision ?? resolveHmrRuntimeDecision({
|
|
15653
|
+
platform: configService.platform,
|
|
15654
|
+
configured: options.configured,
|
|
15655
|
+
compileHotReLoad: options.compileHotReLoad
|
|
15656
|
+
});
|
|
15657
|
+
if (skylineHmrFallbackApplied || currentDecision.runtime === "classic" && options.compileHotReLoad !== true) return false;
|
|
15658
|
+
skylineHmrFallbackApplied = true;
|
|
15659
|
+
devHmrDecision = resolveHmrRuntimeDecision({
|
|
15660
|
+
platform: configService.platform,
|
|
15661
|
+
configured: currentDecision.configured,
|
|
15662
|
+
compileHotReLoad: options.compileHotReLoad,
|
|
15663
|
+
skyline: true
|
|
15664
|
+
});
|
|
15665
|
+
const detectedFiles = options.files.slice(0, 3).join("、");
|
|
15666
|
+
const detectedSuffix = detectedFiles ? `(${detectedFiles})` : "";
|
|
15667
|
+
const privateConfigPath = configService.projectPrivateConfigPath;
|
|
15668
|
+
const privateConfigDisplay = privateConfigPath ? configService.relativeCwd(privateConfigPath) : "project.private.config.json";
|
|
15669
|
+
if (options.compileHotReLoad === true) try {
|
|
15670
|
+
if (!privateConfigPath) throw new Error("无法解析项目私有配置路径");
|
|
15671
|
+
await disableProjectPrivateConfigHotReload(privateConfigPath);
|
|
15672
|
+
const privateConfig = configService.projectPrivateConfig;
|
|
15673
|
+
privateConfig.setting = {
|
|
15674
|
+
...privateConfig.setting && typeof privateConfig.setting === "object" && !Array.isArray(privateConfig.setting) ? privateConfig.setting : {},
|
|
15675
|
+
compileHotReLoad: false
|
|
15676
|
+
};
|
|
15677
|
+
logger_default.warn(`检测到 Skyline 渲染配置${detectedSuffix}。微信开发者工具暂不支持 Skyline 热重载,已将 ${privateConfigDisplay} 中的 setting.compileHotReLoad 设为 false,并降级为 classic。详情:${SKYLINE_HMR_COMPATIBILITY_URL}`);
|
|
15678
|
+
} catch (error) {
|
|
15679
|
+
logger_default.warn(`检测到 Skyline 渲染配置${detectedSuffix}。已降级为 classic,但无法自动关闭 ${privateConfigDisplay} 中的 setting.compileHotReLoad:${error instanceof Error ? error.message : String(error)}。请手动关闭微信开发者工具“热重载”。详情:${SKYLINE_HMR_COMPATIBILITY_URL}`);
|
|
15680
|
+
}
|
|
15681
|
+
else logger_default.warn(`检测到 Skyline 渲染配置${detectedSuffix}。微信开发者工具暂不支持 Skyline 热重载,weapp.hmr.runtime="stateful-experimental" 已自动降级为 classic。详情:${SKYLINE_HMR_COMPATIBILITY_URL}`);
|
|
15682
|
+
return true;
|
|
15683
|
+
}
|
|
15294
15684
|
function createHmrProfileJsonSample(totalMs) {
|
|
15295
15685
|
const profile = ctx.runtimeState.build.hmr.profile;
|
|
15296
15686
|
const relativeFile = profile.file && ctx.configService ? ctx.configService.relativeCwd(profile.file) : void 0;
|
|
@@ -15851,31 +16241,47 @@ function createBuildService(ctx) {
|
|
|
15851
16241
|
if (process.env.NODE_ENV === void 0) process.env.NODE_ENV = "development";
|
|
15852
16242
|
debug$2?.(`[${target}] dev build watcher start`);
|
|
15853
16243
|
const { hasWorkersDir, workersDir } = checkWorkersOptions(target, configService, scanService);
|
|
15854
|
-
const createDevBuildOptions = () => appendHmrMetricsPlugin(applyTargetBuildOverride(configService.merge(void 0, createSharedBuildConfig(configService, scanService), resolveTargetBuildOverride(target)), target));
|
|
15855
|
-
let buildOptions = createDevBuildOptions();
|
|
15856
|
-
buildOptions.build = {
|
|
15857
|
-
...buildOptions.build ?? {},
|
|
15858
|
-
write: true
|
|
15859
|
-
};
|
|
15860
16244
|
const configuredHmrRuntime = configService.weappViteConfig.hmr?.runtime;
|
|
15861
16245
|
const compileHotReLoad = configService.projectPrivateConfig.setting?.compileHotReLoad;
|
|
15862
|
-
|
|
16246
|
+
devHmrDecision ??= resolveHmrRuntimeDecision({
|
|
15863
16247
|
platform: configService.platform,
|
|
15864
16248
|
configured: configuredHmrRuntime,
|
|
15865
16249
|
compileHotReLoad
|
|
15866
16250
|
});
|
|
15867
|
-
const
|
|
15868
|
-
|
|
15869
|
-
|
|
15870
|
-
|
|
15871
|
-
|
|
15872
|
-
|
|
15873
|
-
|
|
15874
|
-
|
|
15875
|
-
|
|
15876
|
-
|
|
15877
|
-
|
|
15878
|
-
|
|
16251
|
+
const createDevBuildOptions = () => {
|
|
16252
|
+
const options = applyTargetBuildOverride(configService.merge(void 0, createSharedBuildConfig(configService, scanService), resolveTargetBuildOverride(target)), target);
|
|
16253
|
+
if (target === "app" && devHmrDecision?.runtime === "classic") {
|
|
16254
|
+
let skylineFiles = [];
|
|
16255
|
+
options.plugins = [...options.plugins ?? [], {
|
|
16256
|
+
name: "weapp-vite:skyline-hmr-compatibility",
|
|
16257
|
+
enforce: "post",
|
|
16258
|
+
generateBundle(_options, bundle) {
|
|
16259
|
+
skylineFiles = findSkylineRendererFiles(Object.values(bundle));
|
|
16260
|
+
},
|
|
16261
|
+
writeBundle() {
|
|
16262
|
+
if (skylineFiles.length === 0) return;
|
|
16263
|
+
const detectedFiles = skylineFiles;
|
|
16264
|
+
skylineFiles = [];
|
|
16265
|
+
setTimeout(() => {
|
|
16266
|
+
applySkylineHmrFallback({
|
|
16267
|
+
compileHotReLoad,
|
|
16268
|
+
configured: devHmrDecision?.configured,
|
|
16269
|
+
files: detectedFiles
|
|
16270
|
+
});
|
|
16271
|
+
}, 0);
|
|
16272
|
+
}
|
|
16273
|
+
}];
|
|
16274
|
+
}
|
|
16275
|
+
return appendHmrMetricsPlugin(options);
|
|
16276
|
+
};
|
|
16277
|
+
let buildOptions = createDevBuildOptions();
|
|
16278
|
+
buildOptions.build = {
|
|
16279
|
+
...buildOptions.build ?? {},
|
|
16280
|
+
write: true
|
|
16281
|
+
};
|
|
16282
|
+
const hmrDecision = devHmrDecision;
|
|
16283
|
+
if (target === "app" && hmrDecision.runtime !== "stateful-experimental") logHmrRuntimeDecision(hmrDecision);
|
|
16284
|
+
if (target === "app" && hmrDecision.runtime === "stateful-experimental") try {
|
|
15879
16285
|
const snapshotBuildOptions = {
|
|
15880
16286
|
...buildOptions,
|
|
15881
16287
|
build: {
|
|
@@ -15885,6 +16291,21 @@ function createBuildService(ctx) {
|
|
|
15885
16291
|
}
|
|
15886
16292
|
};
|
|
15887
16293
|
const initialSnapshot = toStatefulHmrOutput(await build(snapshotBuildOptions));
|
|
16294
|
+
const initialEntryIds = new Set(ctx.runtimeState.build.hmr.resolvedEntryMap.keys());
|
|
16295
|
+
const skylineFiles = findSkylineRendererFiles(initialSnapshot);
|
|
16296
|
+
if (skylineFiles.length > 0) await applySkylineHmrFallback({
|
|
16297
|
+
compileHotReLoad,
|
|
16298
|
+
configured: hmrDecision.configured,
|
|
16299
|
+
files: skylineFiles
|
|
16300
|
+
});
|
|
16301
|
+
if (devHmrDecision?.runtime === "classic") {
|
|
16302
|
+
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
16303
|
+
await configService.load(configService.loadOptions);
|
|
16304
|
+
await scanService.loadAppEntry();
|
|
16305
|
+
scanService.loadSubPackages();
|
|
16306
|
+
return await runDev(target);
|
|
16307
|
+
}
|
|
16308
|
+
logHmrRuntimeDecision(hmrDecision);
|
|
15888
16309
|
await configService.load(configService.loadOptions);
|
|
15889
16310
|
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
15890
16311
|
await scanService.loadAppEntry();
|
|
@@ -15906,6 +16327,7 @@ function createBuildService(ctx) {
|
|
|
15906
16327
|
await runDev(target);
|
|
15907
16328
|
logger_default.success("微信状态保持 HMR 构建已完成完整重载。");
|
|
15908
16329
|
}, {
|
|
16330
|
+
entryIds: initialEntryIds,
|
|
15909
16331
|
initial: initialSnapshot,
|
|
15910
16332
|
rebuild: async (files) => {
|
|
15911
16333
|
for (const file of files) invalidateFileCache(file);
|
|
@@ -15934,10 +16356,14 @@ function createBuildService(ctx) {
|
|
|
15934
16356
|
watcherService.setRollupWatcher(watcher, "/");
|
|
15935
16357
|
return watcher;
|
|
15936
16358
|
} catch (error) {
|
|
15937
|
-
if (
|
|
15938
|
-
|
|
16359
|
+
if (hmrDecision.configured !== "auto" || !isStatefulHmrRuntimeCompatibilityError(error)) throw error;
|
|
16360
|
+
devHmrDecision = {
|
|
16361
|
+
configured: hmrDecision.configured,
|
|
16362
|
+
reason: "runtime-compatibility-fallback",
|
|
16363
|
+
runtime: "classic"
|
|
16364
|
+
};
|
|
15939
16365
|
logger_default.warn(`微信状态保持 HMR 运行时不可用,已自动降级为 classic:${error instanceof Error ? error.message : String(error)}`);
|
|
15940
|
-
logger_default.info(
|
|
16366
|
+
logger_default.info(formatHmrRuntimeStartupMessages(devHmrDecision)[0]);
|
|
15941
16367
|
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
15942
16368
|
await configService.load(configService.loadOptions);
|
|
15943
16369
|
await scanService.loadAppEntry();
|
|
@@ -18888,6 +19314,7 @@ function emitSfcJsonAsset(ctx, bundle, relativeBase, result, options) {
|
|
|
18888
19314
|
if (!nextConfig) return;
|
|
18889
19315
|
if (options.emitIfMissingOnly) {
|
|
18890
19316
|
if (!bundle[jsonFileName]) {
|
|
19317
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18891
19318
|
const nextSource = JSON.stringify(nextConfig, null, 2);
|
|
18892
19319
|
if (emittedAssetSourceCache.get(cacheKey) !== nextSource) {
|
|
18893
19320
|
ctx.emitFile({
|
|
@@ -18902,19 +19329,23 @@ function emitSfcJsonAsset(ctx, bundle, relativeBase, result, options) {
|
|
|
18902
19329
|
}
|
|
18903
19330
|
if (options.mergeExistingAsset && existing && existing.type === "asset") {
|
|
18904
19331
|
try {
|
|
18905
|
-
const
|
|
19332
|
+
const mergedConfig = mergeJson(JSON.parse(existing.source.toString()), nextConfig, "merge-existing");
|
|
19333
|
+
const merged = options.finalizeConfig?.(mergedConfig) ?? mergedConfig;
|
|
18906
19334
|
existing.source = JSON.stringify(merged, null, 2);
|
|
18907
19335
|
} catch {
|
|
19336
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18908
19337
|
existing.source = JSON.stringify(nextConfig, null, 2);
|
|
18909
19338
|
}
|
|
18910
19339
|
return;
|
|
18911
19340
|
}
|
|
18912
19341
|
if (existing && existing.type === "asset") {
|
|
19342
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18913
19343
|
const nextSource = JSON.stringify(nextConfig, null, 2);
|
|
18914
19344
|
if ((existing.source?.toString?.() ?? "") !== nextSource) existing.source = nextSource;
|
|
18915
19345
|
emittedAssetSourceCache.set(cacheKey, nextSource);
|
|
18916
19346
|
return;
|
|
18917
19347
|
}
|
|
19348
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18918
19349
|
const nextSource = JSON.stringify(nextConfig, null, 2);
|
|
18919
19350
|
if (emittedAssetSourceCache.get(cacheKey) === nextSource) return;
|
|
18920
19351
|
ctx.emitFile({
|
|
@@ -19712,7 +20143,7 @@ function stripQueryAndHash(value) {
|
|
|
19712
20143
|
}
|
|
19713
20144
|
function createPathMatcher(patterns, options) {
|
|
19714
20145
|
if (!patterns.length) return () => false;
|
|
19715
|
-
return
|
|
20146
|
+
return picomatch(patterns.map((pattern) => normalizePath$1(pattern)), options);
|
|
19716
20147
|
}
|
|
19717
20148
|
function createAssetPathVariants(file, roots) {
|
|
19718
20149
|
const variants = [file];
|
|
@@ -19806,14 +20237,15 @@ function withScopedSlotHostAsset(ctx, fileName, buffer) {
|
|
|
19806
20237
|
}
|
|
19807
20238
|
function patchScopedSlotHostAssetForBundle(ctx, fileName, output) {
|
|
19808
20239
|
if (output.type === "chunk") {
|
|
19809
|
-
const
|
|
20240
|
+
const chunk = output;
|
|
20241
|
+
const current = chunk.code;
|
|
19810
20242
|
if (typeof current !== "string") return false;
|
|
19811
20243
|
if (!getScopedSlotGenericKeys(ctx, fileName)?.size || ctx.configService.platform !== "weapp" || current.includes(WEVU_SLOT_OWNER_ID_PROP)) return false;
|
|
19812
|
-
const transformCode = resolveOutputChunkTransformCode(
|
|
19813
|
-
const injected = injectScopedSlotHostPropertiesInJs(transformCode, { sourceMap: Boolean(normalizeEncodedSourceMapLike(
|
|
19814
|
-
if (injected.transformed) return applyOutputChunkTransform(
|
|
20244
|
+
const transformCode = resolveOutputChunkTransformCode(chunk);
|
|
20245
|
+
const injected = injectScopedSlotHostPropertiesInJs(transformCode, { sourceMap: Boolean(normalizeEncodedSourceMapLike(chunk.map)) || transformCode !== current });
|
|
20246
|
+
if (injected.transformed) return applyOutputChunkTransform(chunk, injected.code, injected.map);
|
|
19815
20247
|
const propertySource = createScopedSlotHostPropertiesSource();
|
|
19816
|
-
return replaceOutputChunkCode(
|
|
20248
|
+
return replaceOutputChunkCode(chunk, /Component\(\s*\{/, (match) => `${match[0]} properties: { ${propertySource} },`);
|
|
19817
20249
|
}
|
|
19818
20250
|
const current = output.source;
|
|
19819
20251
|
if (typeof current !== "string" && !Buffer.isBuffer(current) && !(current instanceof Uint8Array)) return false;
|
|
@@ -20450,15 +20882,26 @@ function createExtendedLibManager() {
|
|
|
20450
20882
|
};
|
|
20451
20883
|
}
|
|
20452
20884
|
//#endregion
|
|
20885
|
+
//#region src/runtime/appConfig.ts
|
|
20886
|
+
function finalizeAppConfigForBuild(config, options) {
|
|
20887
|
+
return applyBuildScopeToAppConfig(applyPreloadRulesToAppJson(normalizeAppJson(config), options.routeRules, options.platform), resolveBuildScope(options.buildScope));
|
|
20888
|
+
}
|
|
20889
|
+
//#endregion
|
|
20453
20890
|
//#region src/plugins/hooks/useLoadEntry/jsonEmit.ts
|
|
20454
20891
|
function createJsonEmitManager(configService) {
|
|
20455
20892
|
const map = /* @__PURE__ */ new Map();
|
|
20456
20893
|
function register(entry) {
|
|
20457
20894
|
if (!entry.jsonPath && !entry.fileName) return;
|
|
20458
20895
|
const fileName = entry.fileName ?? resolveRelativeJsonOutputFileName(configService, entry.jsonPath);
|
|
20459
|
-
const
|
|
20896
|
+
const shouldNormalizeAppJson = entry.type === "app" && fileName === "app.json";
|
|
20897
|
+
const weappViteConfig = configService.weappViteConfig ?? {};
|
|
20898
|
+
const normalizedEntry = shouldNormalizeAppJson ? {
|
|
20460
20899
|
...entry,
|
|
20461
|
-
json:
|
|
20900
|
+
json: finalizeAppConfigForBuild(entry.json, {
|
|
20901
|
+
buildScope: weappViteConfig.buildScope,
|
|
20902
|
+
platform: configService.platform,
|
|
20903
|
+
routeRules: weappViteConfig.routeRules
|
|
20904
|
+
})
|
|
20462
20905
|
} : entry;
|
|
20463
20906
|
map.set(fileName, {
|
|
20464
20907
|
fileName,
|
|
@@ -21272,7 +21715,7 @@ function resolveRouteRuleLayoutMeta(filename, configService) {
|
|
|
21272
21715
|
const routeCandidates = normalizePageRouteCandidates(filename, configService);
|
|
21273
21716
|
let matched;
|
|
21274
21717
|
for (const [pattern, rule] of Object.entries(routeRules)) {
|
|
21275
|
-
if (!routeCandidates.some((candidate) =>
|
|
21718
|
+
if (!routeCandidates.some((candidate) => picomatch(pattern)(candidate))) continue;
|
|
21276
21719
|
const normalizedMeta = normalizeRouteRuleLayoutMeta(rule?.appLayout);
|
|
21277
21720
|
const patternSegments = pattern.split("/").filter(Boolean);
|
|
21278
21721
|
const wildcardMatches = pattern.match(ROUTE_RULE_GLOB_TOKEN_RE) ?? [];
|
|
@@ -21527,6 +21970,7 @@ async function collectAppEntries(options) {
|
|
|
21527
21970
|
let pluginJsonPathForRegistration;
|
|
21528
21971
|
let pluginJsonForRegistration;
|
|
21529
21972
|
let pluginSignature;
|
|
21973
|
+
let appJson;
|
|
21530
21974
|
if (!isPluginBuild) {
|
|
21531
21975
|
extendedLibManager.syncFromAppJson(json);
|
|
21532
21976
|
await Promise.all([collectAppSideFiles(pluginCtx, id, json, jsonService, registerJsonAsset, existsCache, pathExistsTtlMs), collectMiniappConfigFile(pluginCtx, id, configService, jsonService, registerJsonAsset, existsCache, pathExistsTtlMs)]);
|
|
@@ -21548,6 +21992,7 @@ async function collectAppEntries(options) {
|
|
|
21548
21992
|
const pluginSignatureMatches = cached.pluginSignature === pluginSignature;
|
|
21549
21993
|
if (cached.appSignature === appSignature && pluginPathMatches && pluginSignatureMatches) return {
|
|
21550
21994
|
entries: cached.entries,
|
|
21995
|
+
appJson: cached.appJson,
|
|
21551
21996
|
pluginResolvedRecords: cached.pluginResolvedRecords,
|
|
21552
21997
|
pluginEntryTypes: cached.pluginEntryTypes,
|
|
21553
21998
|
pluginJsonPathForRegistration: cached.pluginJsonPathForRegistration,
|
|
@@ -21559,11 +22004,10 @@ async function collectAppEntries(options) {
|
|
|
21559
22004
|
};
|
|
21560
22005
|
}
|
|
21561
22006
|
if (!isPluginBuild) {
|
|
21562
|
-
|
|
21563
|
-
|
|
21564
|
-
|
|
21565
|
-
|
|
21566
|
-
type: "app"
|
|
22007
|
+
appJson = finalizeAppConfigForBuild(json, {
|
|
22008
|
+
buildScope: configService.weappViteConfig.buildScope,
|
|
22009
|
+
platform: configService.platform,
|
|
22010
|
+
routeRules: configService.weappViteConfig.routeRules
|
|
21567
22011
|
});
|
|
21568
22012
|
entries.push(...analyzeAppJson(appJson));
|
|
21569
22013
|
}
|
|
@@ -21593,6 +22037,7 @@ async function collectAppEntries(options) {
|
|
|
21593
22037
|
}
|
|
21594
22038
|
if (useCache && cache) cache.current = {
|
|
21595
22039
|
appSignature,
|
|
22040
|
+
appJson,
|
|
21596
22041
|
pluginSignature,
|
|
21597
22042
|
pluginJsonPath,
|
|
21598
22043
|
entries: [...entries],
|
|
@@ -21603,6 +22048,7 @@ async function collectAppEntries(options) {
|
|
|
21603
22048
|
};
|
|
21604
22049
|
return {
|
|
21605
22050
|
entries,
|
|
22051
|
+
appJson,
|
|
21606
22052
|
pluginResolvedRecords,
|
|
21607
22053
|
pluginEntryTypes,
|
|
21608
22054
|
pluginJsonPathForRegistration,
|
|
@@ -22416,7 +22862,7 @@ async function emitEntryOutput(options) {
|
|
|
22416
22862
|
}
|
|
22417
22863
|
}
|
|
22418
22864
|
if (!isPluginBuild || type !== "app") registerJsonAsset({
|
|
22419
|
-
jsonPath,
|
|
22865
|
+
jsonPath: type === "app" ? id : jsonPath,
|
|
22420
22866
|
json,
|
|
22421
22867
|
type
|
|
22422
22868
|
});
|
|
@@ -22767,6 +23213,7 @@ function createEntryLoader(options) {
|
|
|
22767
23213
|
extendedLibManager,
|
|
22768
23214
|
cache: appEntriesCache
|
|
22769
23215
|
});
|
|
23216
|
+
if (appResult.appJson) json = appResult.appJson;
|
|
22770
23217
|
autoRoutesSignature = configService.isDev ? ctx.autoRoutesService?.getSignature?.() : void 0;
|
|
22771
23218
|
entries.push(...appResult.entries);
|
|
22772
23219
|
const registerAppComponentEntry = (entry) => {
|
|
@@ -25326,8 +25773,8 @@ function getStyleMatcher(entry) {
|
|
|
25326
25773
|
if (cached) return cached;
|
|
25327
25774
|
const includePatterns = entry.include?.length ? entry.include : ["**/*"];
|
|
25328
25775
|
const excludePatterns = entry.exclude?.length ? entry.exclude : void 0;
|
|
25329
|
-
const matcher = { include:
|
|
25330
|
-
if (excludePatterns?.length) matcher.exclude =
|
|
25776
|
+
const matcher = { include: picomatch(includePatterns, { dot: true }) };
|
|
25777
|
+
if (excludePatterns?.length) matcher.exclude = picomatch(excludePatterns, { dot: true });
|
|
25331
25778
|
styleMatcherCache.set(entry, matcher);
|
|
25332
25779
|
return matcher;
|
|
25333
25780
|
}
|
|
@@ -28410,16 +28857,16 @@ function resolveEntryRecord(state, sourceId) {
|
|
|
28410
28857
|
const relativeBase = removeExtensionDeep(state.ctx.configService.relativeAbsoluteSrcRoot(sourceId));
|
|
28411
28858
|
return state.entriesMap.get(relativeBase) ?? state.entriesMap.get(removeExtensionDeep(sourceId));
|
|
28412
28859
|
}
|
|
28413
|
-
async function resolveLocalModule(
|
|
28860
|
+
async function resolveLocalModule(pluginContext, source, importer) {
|
|
28414
28861
|
const localBase = path.isAbsolute(source) ? source : source.startsWith("/") ? source : path.resolve(path.dirname(importer), source);
|
|
28415
|
-
const resolved = await
|
|
28862
|
+
const resolved = await pluginContext.resolve(localBase, importer);
|
|
28416
28863
|
if (resolved?.id) return normalizeFsResolvedId(resolved.id);
|
|
28417
28864
|
if (path.isAbsolute(localBase) && !path.extname(localBase)) {
|
|
28418
28865
|
const localEntry = (await findJsEntry(localBase)).path ?? await findVueEntry(localBase);
|
|
28419
|
-
if (localEntry) return normalizeFsResolvedId((await
|
|
28866
|
+
if (localEntry) return normalizeFsResolvedId((await pluginContext.resolve(localEntry, importer))?.id ?? localEntry);
|
|
28420
28867
|
}
|
|
28421
28868
|
}
|
|
28422
|
-
async function collectUsingComponentDependencies(state, ownerId, json) {
|
|
28869
|
+
async function collectUsingComponentDependencies(state, pluginContext, ownerId, json) {
|
|
28423
28870
|
if (!json || typeof json !== "object" || !("usingComponents" in json)) return [];
|
|
28424
28871
|
const usingComponents = json.usingComponents;
|
|
28425
28872
|
if (!usingComponents || typeof usingComponents !== "object" || Array.isArray(usingComponents)) return [];
|
|
@@ -28427,7 +28874,7 @@ async function collectUsingComponentDependencies(state, ownerId, json) {
|
|
|
28427
28874
|
for (const value of Object.values(usingComponents)) {
|
|
28428
28875
|
if (typeof value !== "string" || !value || value.includes("://")) continue;
|
|
28429
28876
|
const outputKey = removeExtensionDeep(value).replace(/^\/+/, "");
|
|
28430
|
-
const resolved = await resolveLocalModule(
|
|
28877
|
+
const resolved = await resolveLocalModule(pluginContext, state.ctx.runtimeState.build.hmr.externalComponentEntryMap.get(outputKey) ?? (value.startsWith("/") ? path.resolve(state.ctx.configService.absoluteSrcRoot, value.slice(1)) : value), ownerId);
|
|
28431
28878
|
if (resolved) dependencies.push({
|
|
28432
28879
|
kind: "using-component",
|
|
28433
28880
|
sourceId: resolved
|
|
@@ -28444,7 +28891,7 @@ function collectTemplateDependencies(state, templatePath) {
|
|
|
28444
28891
|
});
|
|
28445
28892
|
return dependencies;
|
|
28446
28893
|
}
|
|
28447
|
-
async function collectLogicalEntryDependencies(state, ownerId) {
|
|
28894
|
+
async function collectLogicalEntryDependencies(state, pluginContext, ownerId) {
|
|
28448
28895
|
const pendingDependencies = state.ctx.moduleGraphService.getEntryDependencies(ownerId);
|
|
28449
28896
|
const dependencies = [];
|
|
28450
28897
|
const addExistingDependency = async (kind, sourceId) => {
|
|
@@ -28469,7 +28916,7 @@ async function collectLogicalEntryDependencies(state, ownerId) {
|
|
|
28469
28916
|
await addExistingDependency("style", styleEntry.path);
|
|
28470
28917
|
if (templatePath) await state.ctx.wxmlService?.scan(templatePath);
|
|
28471
28918
|
dependencies.push(...collectTemplateDependencies(state, templatePath));
|
|
28472
|
-
dependencies.push(...await collectUsingComponentDependencies(state, ownerId, entry?.json));
|
|
28919
|
+
dependencies.push(...await collectUsingComponentDependencies(state, pluginContext, ownerId, entry?.json));
|
|
28473
28920
|
for (const kind of [
|
|
28474
28921
|
"json",
|
|
28475
28922
|
"jsx",
|
|
@@ -28493,7 +28940,7 @@ function createLogicalEntryResolveHook(state) {
|
|
|
28493
28940
|
if (!sidecarSource) return null;
|
|
28494
28941
|
state.ctx.moduleGraphService.bindPluginContext(this);
|
|
28495
28942
|
return {
|
|
28496
|
-
id: (await
|
|
28943
|
+
id: (await this.resolve(id, importer, { skipSelf: true }))?.id ?? createSidecarSourceSpecifier(sidecarSource.ownerId, sidecarSource.sourceId, sidecarSource.kind),
|
|
28497
28944
|
moduleSideEffects: "no-treeshake"
|
|
28498
28945
|
};
|
|
28499
28946
|
};
|
|
@@ -28505,7 +28952,7 @@ function createLogicalEntryLoadHook(state) {
|
|
|
28505
28952
|
state.ctx.moduleGraphService.bindPluginContext(this);
|
|
28506
28953
|
if (state.ctx.configService.isDev) await state.loadEntry.call(this, logicalEntry.sourceId, logicalEntry.type === "app" ? "app" : logicalEntry.type === "page" ? "page" : "component");
|
|
28507
28954
|
return {
|
|
28508
|
-
code: createLogicalEntryModuleCode(logicalEntry, await collectLogicalEntryDependencies(state, logicalEntry.sourceId)),
|
|
28955
|
+
code: createLogicalEntryModuleCode(logicalEntry, await collectLogicalEntryDependencies(state, this, logicalEntry.sourceId)),
|
|
28509
28956
|
moduleSideEffects: "no-treeshake"
|
|
28510
28957
|
};
|
|
28511
28958
|
}
|
|
@@ -30114,6 +30561,11 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
30114
30561
|
const style = await processVueResultStyle(sfcStyle, options.configService);
|
|
30115
30562
|
emitSfcStyleIfMissing(options.pluginCtx, options.bundle, options.relativeBase, style, options.outputExtensions.wxss, isAppVue ? { updateExisting: false } : void 0);
|
|
30116
30563
|
}
|
|
30564
|
+
const finalizeJsonConfig = isAppVue ? (config) => finalizeAppConfigForBuild(config, {
|
|
30565
|
+
buildScope: options.configService.weappViteConfig?.buildScope,
|
|
30566
|
+
platform: options.configService.platform,
|
|
30567
|
+
routeRules: options.configService.weappViteConfig?.routeRules
|
|
30568
|
+
}) : void 0;
|
|
30117
30569
|
if (options.result.config || shouldEmitComponentJson) emitSharedVueEntryJsonAsset({
|
|
30118
30570
|
bundle: options.bundle,
|
|
30119
30571
|
pluginCtx: options.pluginCtx,
|
|
@@ -30126,6 +30578,7 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
30126
30578
|
mergeExistingAsset: shouldMergeJsonAsset,
|
|
30127
30579
|
mergeStrategy: jsonConfig?.mergeStrategy,
|
|
30128
30580
|
defaults: jsonConfig?.defaults?.[jsonKind],
|
|
30581
|
+
...finalizeJsonConfig ? { finalizeConfig: finalizeJsonConfig } : {},
|
|
30129
30582
|
kind: jsonKind,
|
|
30130
30583
|
extension: options.jsonExtension
|
|
30131
30584
|
}
|
|
@@ -30140,8 +30593,8 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
30140
30593
|
function hasVueExtension(id) {
|
|
30141
30594
|
return Boolean(id?.endsWith(".vue"));
|
|
30142
30595
|
}
|
|
30143
|
-
function getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration = false) {
|
|
30144
|
-
return `${vuePath}::${isPage ? "page" : "component"}::${isApp ? "app" : "entry"}::${delegatesComponentRegistration ? "logical-registration" : "module-registration"}`;
|
|
30596
|
+
function getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration = false, emitResolvedComponentEntries = true) {
|
|
30597
|
+
return `${vuePath}::${isPage ? "page" : "component"}::${isApp ? "app" : "entry"}::${delegatesComponentRegistration ? "logical-registration" : "module-registration"}::${emitResolvedComponentEntries ? "emit-entries" : "resolve-only"}`;
|
|
30145
30598
|
}
|
|
30146
30599
|
function shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, configService) {
|
|
30147
30600
|
return !isPage && !isApp && !configService.weappLibConfig?.enabled && !ctx.moduleGraphService?.isLogicalLayoutEntry?.(vuePath);
|
|
@@ -30171,6 +30624,24 @@ function resolveVueTemplatePlatformOptions(options) {
|
|
|
30171
30624
|
function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state, delegatesComponentRegistration) {
|
|
30172
30625
|
const importerBaseName = removeExtensionDeep(vuePath);
|
|
30173
30626
|
const autoImportResolveCache = /* @__PURE__ */ new Map();
|
|
30627
|
+
const resolveUsingComponentPath = createUsingComponentPathResolver(pluginCtx, configService, state.reExportResolutionCache);
|
|
30628
|
+
const externalComponentEntryMap = ctx.runtimeState?.build?.hmr?.externalComponentEntryMap;
|
|
30629
|
+
const registerResolvedComponentEntry = externalComponentEntryMap ? async (...args) => {
|
|
30630
|
+
const [importSource, importerFilename, info] = args;
|
|
30631
|
+
const resolved = await resolveUsingComponentPath(importSource, importerFilename, info);
|
|
30632
|
+
if (typeof resolved !== "string" && resolved?.from && resolved.resolvedId) {
|
|
30633
|
+
const outputKey = removeExtensionDeep(resolved.from).replace(/^\/+/, "");
|
|
30634
|
+
const isNewEntry = externalComponentEntryMap.get(outputKey) !== resolved.resolvedId;
|
|
30635
|
+
externalComponentEntryMap.set(outputKey, resolved.resolvedId);
|
|
30636
|
+
if (isNewEntry && state.emitResolvedComponentEntries !== false && typeof pluginCtx.emitFile === "function") pluginCtx.emitFile({
|
|
30637
|
+
type: "chunk",
|
|
30638
|
+
id: createLogicalEntryId(resolved.resolvedId, "component"),
|
|
30639
|
+
fileName: resolveRelativeOutputFileNameWithExtension(configService, resolved.resolvedId, ".js"),
|
|
30640
|
+
preserveSignature: "exports-only"
|
|
30641
|
+
});
|
|
30642
|
+
}
|
|
30643
|
+
return resolved;
|
|
30644
|
+
} : resolveUsingComponentPath;
|
|
30174
30645
|
const scopedSlotsCompiler = configService.weappViteConfig?.vue?.template?.scopedSlotsCompiler ?? "auto";
|
|
30175
30646
|
const scopedSlotsRequireProps = configService.weappViteConfig?.vue?.template?.scopedSlotsRequireProps ?? false;
|
|
30176
30647
|
const slotSingleRootNoWrapper = configService.weappViteConfig?.vue?.template?.slotSingleRootNoWrapper ?? false;
|
|
@@ -30266,7 +30737,7 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
30266
30737
|
autoUsingComponents: {
|
|
30267
30738
|
enabled: true,
|
|
30268
30739
|
warn: (message) => logger_default.warn(message),
|
|
30269
|
-
resolveUsingComponentPath:
|
|
30740
|
+
resolveUsingComponentPath: registerResolvedComponentEntry
|
|
30270
30741
|
},
|
|
30271
30742
|
autoImportTags: {
|
|
30272
30743
|
enabled: true,
|
|
@@ -30324,7 +30795,7 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
30324
30795
|
}
|
|
30325
30796
|
function createCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state) {
|
|
30326
30797
|
const delegatesComponentRegistration = shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, configService);
|
|
30327
|
-
const cacheKey = getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration);
|
|
30798
|
+
const cacheKey = getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration, state.emitResolvedComponentEntries !== false);
|
|
30328
30799
|
const cached = state.compileOptionsCache?.get(cacheKey);
|
|
30329
30800
|
if (cached) return cached;
|
|
30330
30801
|
const created = buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state, delegatesComponentRegistration);
|
|
@@ -31409,7 +31880,8 @@ async function emitCompiledVueEntryAssets(bundle, state, filename, cached) {
|
|
|
31409
31880
|
reExportResolutionCache,
|
|
31410
31881
|
classStyleRuntimeWarned,
|
|
31411
31882
|
compileOptionsCache,
|
|
31412
|
-
componentMetaCache
|
|
31883
|
+
componentMetaCache,
|
|
31884
|
+
emitResolvedComponentEntries: false
|
|
31413
31885
|
};
|
|
31414
31886
|
const { outputExtensions, templateExtension, jsonExtension, scriptExtension, scriptModuleExtension, platformAssetOptions } = resolveVueBundleAssetContext(configService);
|
|
31415
31887
|
const emitState = await resolveCompiledEntryEmitState({
|
|
@@ -31530,7 +32002,8 @@ async function emitFallbackPageAssets(bundle, state, options) {
|
|
|
31530
32002
|
reExportResolutionCache,
|
|
31531
32003
|
classStyleRuntimeWarned,
|
|
31532
32004
|
compileOptionsCache,
|
|
31533
|
-
componentMetaCache
|
|
32005
|
+
componentMetaCache,
|
|
32006
|
+
emitResolvedComponentEntries: false
|
|
31534
32007
|
};
|
|
31535
32008
|
const { outputExtensions, templateExtension, styleExtension, jsonExtension, scriptModuleExtension, platformAssetOptions } = resolveVueBundleAssetContext(configService);
|
|
31536
32009
|
const collectedEntries = await collectFallbackPageEntryIds(configService, scanService);
|
|
@@ -33524,7 +33997,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
33524
33997
|
const { path: appEntryPath } = appEntry;
|
|
33525
33998
|
let configFromVue;
|
|
33526
33999
|
if (!appConfigFile && vueAppPath) {
|
|
33527
|
-
const { extractConfigFromVue } = await import("./file-
|
|
34000
|
+
const { extractConfigFromVue } = await import("./file-BjrPjC70.mjs");
|
|
33528
34001
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
33529
34002
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
33530
34003
|
}
|
|
@@ -33546,9 +34019,12 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
33546
34019
|
if (configFromVue) config = configFromVue;
|
|
33547
34020
|
else config = await ctx.jsonService.read(appConfigFile);
|
|
33548
34021
|
await applyAutoRoutesToAppConfigIfNeeded(ctx, config);
|
|
33549
|
-
|
|
34022
|
+
config = finalizeAppConfigForBuild(config, {
|
|
34023
|
+
buildScope: ctx.configService.weappViteConfig.buildScope,
|
|
34024
|
+
platform: ctx.configService.platform,
|
|
34025
|
+
routeRules: ctx.configService.weappViteConfig.routeRules
|
|
34026
|
+
});
|
|
33550
34027
|
if (isObject(config)) {
|
|
33551
|
-
normalizeAppConfigSubPackages(config);
|
|
33552
34028
|
const resolvedAppEntry = {
|
|
33553
34029
|
path: appEntryPath || vueAppPath,
|
|
33554
34030
|
preludePath: appPreludePath,
|
|
@@ -34502,4 +34978,4 @@ async function createCompilerContext(options) {
|
|
|
34502
34978
|
return ctx;
|
|
34503
34979
|
}
|
|
34504
34980
|
//#endregion
|
|
34505
|
-
export {
|
|
34981
|
+
export { isPathInside as A, findPreloadRuleKey as C, createCjsConfigLoadError as D, parseCommentJson as E, getDefaultIdeProjectRoot as O, collectPreloadPages as S, loadViteConfigFile as T, resolveHmrProfileJsonPath as _, formatBytes as a, checkRuntime as b, getSupportedWeappViteTargetDescriptors as c, getBackendForCapability as d, resolveBackendExecution as f, SHARED_CHUNK_VIRTUAL_PREFIX as g, createSharedBuildConfig as h, setActiveCompilerContextKey as i, shouldPassPlatformArgToIdeOpen as k, isWebPlatform as l, syncManagedTsconfigBootstrapFiles as m, getCompilerContext as n, WEB_PLATFORM_ALIASES as o, syncProjectSupportFiles as p, resetCompilerContext as r, getSupportedWeappVitePlatforms as s, createCompilerContext as t, resolveWeappViteTarget as u, getRouteRuntimeGlobalKeys as v, suggestPreloadRules as w, getProjectConfigFileName as x, resolveWeappConfigFile as y };
|