weapp-vite 6.20.4 → 6.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/auto-import-components/resolvers.mjs +1 -1
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +232 -18
- package/dist/{config-C810aRQQ.d.mts → config-Pi3hdn_g.d.mts} +37 -11
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-DoH-W4mj.mjs → createContext-BE57_Xi7.mjs} +863 -180
- package/dist/docs/README.md +1 -1
- package/dist/docs/ai-workflows.md +4 -0
- package/dist/docs/getting-started.md +13 -2
- package/dist/docs/testing.md +15 -0
- package/dist/docs/uni-app-component-libraries.md +4 -4
- package/dist/docs/weapp-config.md +60 -4
- package/dist/{file-DnVj_L9_.mjs → file-Byldwig4.mjs} +1 -1
- package/dist/file-C-jjrMsb.mjs +2 -0
- package/dist/getInstance-yJ2CpeL9.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 +17 -17
- package/dist/file-BPMjkByK.mjs +0 -2
- package/dist/getInstance-BPs9XIGi.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-Byldwig4.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";
|
|
@@ -191,7 +192,11 @@ function normalizeViteId(id, options) {
|
|
|
191
192
|
if (stripQuery) clean = clean.split("?", 1)[0];
|
|
192
193
|
if (fileProtocolToPathEnabled && clean.startsWith("file://")) try {
|
|
193
194
|
clean = fileURLToPath(clean);
|
|
194
|
-
} catch {
|
|
195
|
+
} catch {
|
|
196
|
+
try {
|
|
197
|
+
clean = decodeURIComponent(new URL(clean).pathname);
|
|
198
|
+
} catch {}
|
|
199
|
+
}
|
|
195
200
|
if (stripAtFsPrefix) clean = stripViteAtFsPrefix(clean);
|
|
196
201
|
if (stripLeadingNullByte && clean.startsWith("\0")) clean = clean.slice(1);
|
|
197
202
|
if (clean.includes("\\")) clean = clean.replace(BACKSLASH_RE$1, "/");
|
|
@@ -1234,7 +1239,7 @@ function getNodeText(node) {
|
|
|
1234
1239
|
concise: true
|
|
1235
1240
|
}).code.trim();
|
|
1236
1241
|
}
|
|
1237
|
-
function getPropertyName(name) {
|
|
1242
|
+
function getPropertyName$1(name) {
|
|
1238
1243
|
if (name.type === "Identifier") return name.name;
|
|
1239
1244
|
if (name.type === "StringLiteral") return name.value;
|
|
1240
1245
|
if (name.type === "NumericLiteral") return String(name.value);
|
|
@@ -1291,7 +1296,7 @@ function resolveTypeFromConfigLiteral(configType) {
|
|
|
1291
1296
|
let constructorType;
|
|
1292
1297
|
for (const member of configType.members) {
|
|
1293
1298
|
if (member.type !== "TSPropertySignature") continue;
|
|
1294
|
-
const key = getPropertyName(member.key);
|
|
1299
|
+
const key = getPropertyName$1(member.key);
|
|
1295
1300
|
const type = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1296
1301
|
if (key === "value" && type && !containsImportType(type)) valueType = getNodeText(type);
|
|
1297
1302
|
else if (key === "type") constructorType = mapConstructorType(type);
|
|
@@ -1301,7 +1306,7 @@ function resolveTypeFromConfigLiteral(configType) {
|
|
|
1301
1306
|
function isPropsConfigLiteral(configType) {
|
|
1302
1307
|
for (const member of configType.members) {
|
|
1303
1308
|
if (member.type !== "TSPropertySignature") continue;
|
|
1304
|
-
const key = getPropertyName(member.key);
|
|
1309
|
+
const key = getPropertyName$1(member.key);
|
|
1305
1310
|
if (key === "type" || key === "value") return true;
|
|
1306
1311
|
}
|
|
1307
1312
|
return false;
|
|
@@ -1310,7 +1315,7 @@ function extractFromPropertiesTypeLiteral(node) {
|
|
|
1310
1315
|
const map = /* @__PURE__ */ new Map();
|
|
1311
1316
|
for (const member of node.members) {
|
|
1312
1317
|
if (member.type !== "TSPropertySignature") continue;
|
|
1313
|
-
const propName = getPropertyName(member.key);
|
|
1318
|
+
const propName = getPropertyName$1(member.key);
|
|
1314
1319
|
if (!propName) continue;
|
|
1315
1320
|
const type = resolveTypeFromConfigLiteral(unwrapTypeAnnotation(member.typeAnnotation)) ?? "any";
|
|
1316
1321
|
map.set(propName, type);
|
|
@@ -1321,7 +1326,7 @@ function extractFromPropsInterfaceMembers(node) {
|
|
|
1321
1326
|
const map = /* @__PURE__ */ new Map();
|
|
1322
1327
|
for (const member of node.body.body) {
|
|
1323
1328
|
if (member.type !== "TSPropertySignature") continue;
|
|
1324
|
-
const propName = getPropertyName(member.key);
|
|
1329
|
+
const propName = getPropertyName$1(member.key);
|
|
1325
1330
|
if (!propName) continue;
|
|
1326
1331
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1327
1332
|
if (!typeNode || typeNode.type !== "TSTypeLiteral") continue;
|
|
@@ -1345,7 +1350,7 @@ function extractComponentPropsFromDts(code) {
|
|
|
1345
1350
|
}
|
|
1346
1351
|
for (const member of path.node.body.body) {
|
|
1347
1352
|
if (member.type !== "TSPropertySignature") continue;
|
|
1348
|
-
if (getPropertyName(member.key) !== "properties") continue;
|
|
1353
|
+
if (getPropertyName$1(member.key) !== "properties") continue;
|
|
1349
1354
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1350
1355
|
if (typeNode?.type === "TSTypeLiteral") {
|
|
1351
1356
|
props = extractFromPropertiesTypeLiteral(typeNode);
|
|
@@ -1366,7 +1371,7 @@ function extractComponentPropsFromDts(code) {
|
|
|
1366
1371
|
}
|
|
1367
1372
|
for (const member of path.node.body.body) {
|
|
1368
1373
|
if (member.type !== "ClassProperty" && member.type !== "ClassAccessorProperty") continue;
|
|
1369
|
-
if (getPropertyName(member.key) !== "properties") continue;
|
|
1374
|
+
if (getPropertyName$1(member.key) !== "properties") continue;
|
|
1370
1375
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1371
1376
|
if (typeNode?.type === "TSTypeLiteral") {
|
|
1372
1377
|
props = extractFromPropertiesTypeLiteral(typeNode);
|
|
@@ -1397,7 +1402,7 @@ function extractInlinePropsTypeFromCode(code) {
|
|
|
1397
1402
|
const pushTypeLiteralMembers = (node) => {
|
|
1398
1403
|
for (const member of node.members) {
|
|
1399
1404
|
if (member.type !== "TSPropertySignature") continue;
|
|
1400
|
-
const propName = getPropertyName(member.key);
|
|
1405
|
+
const propName = getPropertyName$1(member.key);
|
|
1401
1406
|
if (!propName) continue;
|
|
1402
1407
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1403
1408
|
props.set(propName, typeNode ? getNodeText(typeNode) : "any");
|
|
@@ -1406,7 +1411,7 @@ function extractInlinePropsTypeFromCode(code) {
|
|
|
1406
1411
|
const pushInterfaceMembers = (node) => {
|
|
1407
1412
|
for (const member of node.body.body) {
|
|
1408
1413
|
if (member.type !== "TSPropertySignature") continue;
|
|
1409
|
-
const propName = getPropertyName(member.key);
|
|
1414
|
+
const propName = getPropertyName$1(member.key);
|
|
1410
1415
|
if (!propName) continue;
|
|
1411
1416
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1412
1417
|
props.set(propName, typeNode ? getNodeText(typeNode) : "any");
|
|
@@ -5309,6 +5314,297 @@ async function loadViteConfigFile(configEnv, configFile, configRoot, configFileD
|
|
|
5309
5314
|
return withSuppressedWarningCodes(suppressedWarningCodes, () => loadConfigFromFile(configEnv, resolvedConfigFile, configRoot, logLevel, void 0, resolvedConfigLoader));
|
|
5310
5315
|
}
|
|
5311
5316
|
//#endregion
|
|
5317
|
+
//#region src/utils/preloadScan.ts
|
|
5318
|
+
const HOST_ROUTER_METHODS = /* @__PURE__ */ new Set([
|
|
5319
|
+
"navigateTo",
|
|
5320
|
+
"redirectTo",
|
|
5321
|
+
"reLaunch",
|
|
5322
|
+
"switchTab"
|
|
5323
|
+
]);
|
|
5324
|
+
const ROUTER_METHODS = /* @__PURE__ */ new Set(["push", "replace"]);
|
|
5325
|
+
const ROUTER_MODULES = /* @__PURE__ */ new Set([
|
|
5326
|
+
"vue-router",
|
|
5327
|
+
"wevu",
|
|
5328
|
+
"wevu/router"
|
|
5329
|
+
]);
|
|
5330
|
+
const ROUTER_FACTORY_METHODS = /* @__PURE__ */ new Map([
|
|
5331
|
+
["createRouter", ROUTER_METHODS],
|
|
5332
|
+
["useNativeRouter", HOST_ROUTER_METHODS],
|
|
5333
|
+
["useRouter", ROUTER_METHODS]
|
|
5334
|
+
]);
|
|
5335
|
+
const TEMPLATE_NAVIGATOR_RE = /<navigator(?=\s|>)[^>]*?\surl\s*=\s*(["'])([^"'{}\s]+)\1/gi;
|
|
5336
|
+
function normalizePagePath$1(value) {
|
|
5337
|
+
return path.posix.normalize(value).replace(/^\/+/, "").replace(/^\.\//, "");
|
|
5338
|
+
}
|
|
5339
|
+
function normalizeStaticTarget(target, sourcePage) {
|
|
5340
|
+
const route = toPosixPath(target).split(/[?#]/, 1)[0];
|
|
5341
|
+
return normalizePagePath$1(route.startsWith("/") ? route : route.startsWith("./") || route.startsWith("../") ? path.posix.join(path.posix.dirname(sourcePage), route) : route);
|
|
5342
|
+
}
|
|
5343
|
+
function getStaticString(node) {
|
|
5344
|
+
if (node?.type === "StringLiteral" || node?.type === "Literal" && typeof node.value === "string") return node.value;
|
|
5345
|
+
if (node?.type === "TemplateLiteral" && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? node.quasis[0]?.value.raw;
|
|
5346
|
+
}
|
|
5347
|
+
function getPropertyName(node) {
|
|
5348
|
+
if (!node) return;
|
|
5349
|
+
if (node.type === "Identifier" && !node.computed) return node.name;
|
|
5350
|
+
return getStaticString(node);
|
|
5351
|
+
}
|
|
5352
|
+
function getRouteFromObject(argument) {
|
|
5353
|
+
if (argument?.type !== "ObjectExpression") return;
|
|
5354
|
+
for (const property of argument.properties ?? []) {
|
|
5355
|
+
if (property.type !== "ObjectProperty" && property.type !== "Property") continue;
|
|
5356
|
+
const name = getPropertyName(property.key);
|
|
5357
|
+
if (name !== "url" && name !== "path") continue;
|
|
5358
|
+
const value = getStaticString(property.value);
|
|
5359
|
+
if (value) return value;
|
|
5360
|
+
}
|
|
5361
|
+
}
|
|
5362
|
+
function getIdentifierName(node) {
|
|
5363
|
+
return node?.type === "Identifier" ? node.name : void 0;
|
|
5364
|
+
}
|
|
5365
|
+
function collectRouterBindings(ast) {
|
|
5366
|
+
const importedFactories = /* @__PURE__ */ new Map();
|
|
5367
|
+
const routerObjects = /* @__PURE__ */ new Map();
|
|
5368
|
+
const routerFunctions = /* @__PURE__ */ new Map();
|
|
5369
|
+
traverse(ast, { ImportDeclaration(importPath) {
|
|
5370
|
+
if (!ROUTER_MODULES.has(importPath.node.source?.value)) return;
|
|
5371
|
+
for (const specifier of importPath.node.specifiers ?? []) {
|
|
5372
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
5373
|
+
const imported = getIdentifierName(specifier.imported) ?? getStaticString(specifier.imported);
|
|
5374
|
+
const local = getIdentifierName(specifier.local);
|
|
5375
|
+
const methods = imported ? ROUTER_FACTORY_METHODS.get(imported) : void 0;
|
|
5376
|
+
const binding = local ? importPath.scope.getBinding(local) : void 0;
|
|
5377
|
+
if (methods && binding) importedFactories.set(binding, methods);
|
|
5378
|
+
}
|
|
5379
|
+
} });
|
|
5380
|
+
traverse(ast, { VariableDeclarator(declaratorPath) {
|
|
5381
|
+
const init = declaratorPath.node.init;
|
|
5382
|
+
const factory = init?.type === "CallExpression" ? getIdentifierName(init.callee) : void 0;
|
|
5383
|
+
if (!factory) return;
|
|
5384
|
+
const factoryBinding = declaratorPath.scope.getBinding(factory);
|
|
5385
|
+
const methods = factoryBinding ? importedFactories.get(factoryBinding) : ROUTER_FACTORY_METHODS.get(factory);
|
|
5386
|
+
if (!methods) return;
|
|
5387
|
+
const id = declaratorPath.node.id;
|
|
5388
|
+
const objectName = getIdentifierName(id);
|
|
5389
|
+
if (objectName) {
|
|
5390
|
+
const binding = declaratorPath.scope.getBinding(objectName);
|
|
5391
|
+
if (binding?.constant) routerObjects.set(binding, methods);
|
|
5392
|
+
return;
|
|
5393
|
+
}
|
|
5394
|
+
if (id?.type !== "ObjectPattern") return;
|
|
5395
|
+
for (const property of id.properties ?? []) {
|
|
5396
|
+
if (property.type !== "ObjectProperty" && property.type !== "Property") continue;
|
|
5397
|
+
const importedMethod = getPropertyName(property.key);
|
|
5398
|
+
const local = getIdentifierName(property.value);
|
|
5399
|
+
const binding = local ? declaratorPath.scope.getBinding(local) : void 0;
|
|
5400
|
+
if (importedMethod && methods.has(importedMethod) && binding?.constant) routerFunctions.set(binding, importedMethod);
|
|
5401
|
+
}
|
|
5402
|
+
} });
|
|
5403
|
+
return {
|
|
5404
|
+
routerFunctions,
|
|
5405
|
+
routerObjects
|
|
5406
|
+
};
|
|
5407
|
+
}
|
|
5408
|
+
function getNavigationMethod(callPath, bindings) {
|
|
5409
|
+
const callee = callPath.node.callee;
|
|
5410
|
+
const directName = getIdentifierName(callee);
|
|
5411
|
+
const directMethod = directName ? bindings.routerFunctions.get(callPath.scope.getBinding(directName)) : void 0;
|
|
5412
|
+
if (directMethod) return directMethod;
|
|
5413
|
+
if (callee?.type !== "MemberExpression" && callee?.type !== "OptionalMemberExpression") return;
|
|
5414
|
+
const objectName = getIdentifierName(callee.object);
|
|
5415
|
+
const method = getPropertyName(callee.property);
|
|
5416
|
+
if (objectName === "wx" && !callPath.scope.getBinding("wx") && method && HOST_ROUTER_METHODS.has(method)) return method;
|
|
5417
|
+
if (objectName && method) {
|
|
5418
|
+
if (bindings.routerObjects.get(callPath.scope.getBinding(objectName))?.has(method)) return method;
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
function collectScriptTargets(source, sourcePage) {
|
|
5422
|
+
const targets = [];
|
|
5423
|
+
try {
|
|
5424
|
+
const ast = parseJsLike(source);
|
|
5425
|
+
const bindings = collectRouterBindings(ast);
|
|
5426
|
+
traverse(ast, { CallExpression(callPath) {
|
|
5427
|
+
if (!getNavigationMethod(callPath, bindings)) return;
|
|
5428
|
+
const argument = callPath.node.arguments?.[0];
|
|
5429
|
+
const target = getStaticString(argument) ?? getRouteFromObject(argument);
|
|
5430
|
+
if (target) targets.push(normalizeStaticTarget(target, sourcePage));
|
|
5431
|
+
} });
|
|
5432
|
+
} catch {}
|
|
5433
|
+
return [...new Set(targets)];
|
|
5434
|
+
}
|
|
5435
|
+
function collectTemplateTargets(source, sourcePage) {
|
|
5436
|
+
const targets = [];
|
|
5437
|
+
const withoutComments = source.replace(/<!--[\s\S]*?-->/g, "");
|
|
5438
|
+
TEMPLATE_NAVIGATOR_RE.lastIndex = 0;
|
|
5439
|
+
for (const match of withoutComments.matchAll(TEMPLATE_NAVIGATOR_RE)) {
|
|
5440
|
+
const target = match[2];
|
|
5441
|
+
if (target) targets.push(normalizeStaticTarget(target, sourcePage));
|
|
5442
|
+
}
|
|
5443
|
+
return [...new Set(targets)];
|
|
5444
|
+
}
|
|
5445
|
+
function collectStaticRouteTargets(source, kind, sourcePage) {
|
|
5446
|
+
return kind === "template" ? collectTemplateTargets(source, sourcePage) : collectScriptTargets(source, sourcePage);
|
|
5447
|
+
}
|
|
5448
|
+
//#endregion
|
|
5449
|
+
//#region src/utils/preloadRule.ts
|
|
5450
|
+
const PRELOAD_RULE_GLOB_RE = /[*?[\]{}()!+@]/g;
|
|
5451
|
+
function normalizePagePath(value) {
|
|
5452
|
+
return normalizeRoot(value).replace(/^\/+/, "");
|
|
5453
|
+
}
|
|
5454
|
+
function normalizePackageRoot(value) {
|
|
5455
|
+
return normalizeRoot(value).replace(/^\/+|\/+$/g, "");
|
|
5456
|
+
}
|
|
5457
|
+
function normalizeRule(value, pattern) {
|
|
5458
|
+
if (!isObject(value)) throw new TypeError(`routeRules.${pattern}.preload 必须是对象。`);
|
|
5459
|
+
const packages = value.packages;
|
|
5460
|
+
if (!Array.isArray(packages) || packages.length === 0 || packages.some((item) => typeof item !== "string" || !item.trim())) throw new TypeError(`routeRules.${pattern}.preload.packages 必须是非空字符串数组。`);
|
|
5461
|
+
const network = value.network;
|
|
5462
|
+
if (network !== void 0 && network !== "all" && network !== "wifi") throw new TypeError(`routeRules.${pattern}.preload.network 只能是 "all" 或 "wifi"。`);
|
|
5463
|
+
const normalizedPackages = [...new Set(packages.map((item) => normalizePackageRoot(item)).filter(Boolean))];
|
|
5464
|
+
if (normalizedPackages.length === 0) throw new TypeError(`routeRules.${pattern}.preload.packages 必须包含有效的分包 root。`);
|
|
5465
|
+
return {
|
|
5466
|
+
packages: normalizedPackages,
|
|
5467
|
+
...network === void 0 ? {} : { network }
|
|
5468
|
+
};
|
|
5469
|
+
}
|
|
5470
|
+
function getRuleScore(pattern) {
|
|
5471
|
+
const segments = pattern.split("/").filter(Boolean);
|
|
5472
|
+
const wildcards = pattern.match(PRELOAD_RULE_GLOB_RE) ?? [];
|
|
5473
|
+
PRELOAD_RULE_GLOB_RE.lastIndex = 0;
|
|
5474
|
+
return [
|
|
5475
|
+
segments.filter((segment) => {
|
|
5476
|
+
PRELOAD_RULE_GLOB_RE.lastIndex = 0;
|
|
5477
|
+
return !PRELOAD_RULE_GLOB_RE.test(segment);
|
|
5478
|
+
}).length,
|
|
5479
|
+
pattern.replace(PRELOAD_RULE_GLOB_RE, "").length,
|
|
5480
|
+
-wildcards.length,
|
|
5481
|
+
segments.length,
|
|
5482
|
+
pattern.length
|
|
5483
|
+
];
|
|
5484
|
+
}
|
|
5485
|
+
function compareScores(left, right) {
|
|
5486
|
+
for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
|
|
5487
|
+
const leftValue = left[index] ?? 0;
|
|
5488
|
+
const rightValue = right[index] ?? 0;
|
|
5489
|
+
if (leftValue !== rightValue) return leftValue > rightValue ? 1 : -1;
|
|
5490
|
+
}
|
|
5491
|
+
return 0;
|
|
5492
|
+
}
|
|
5493
|
+
function pageCandidates(page) {
|
|
5494
|
+
const normalized = normalizePagePath(page);
|
|
5495
|
+
const withoutPagesPrefix = normalized.startsWith("pages/") ? normalized.slice(6) : normalized;
|
|
5496
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
5497
|
+
for (const route of [normalized, withoutPagesPrefix]) {
|
|
5498
|
+
const withoutIndex = route.replace(/\/index$/, "") || route;
|
|
5499
|
+
for (const value of [route, withoutIndex]) {
|
|
5500
|
+
candidates.add(value);
|
|
5501
|
+
candidates.add(`/${value}`);
|
|
5502
|
+
}
|
|
5503
|
+
}
|
|
5504
|
+
return [...candidates];
|
|
5505
|
+
}
|
|
5506
|
+
function findRouteRuleMatch(page, routeRules) {
|
|
5507
|
+
if (!routeRules) return;
|
|
5508
|
+
const candidates = pageCandidates(page);
|
|
5509
|
+
let matched;
|
|
5510
|
+
for (const [pattern, value] of Object.entries(routeRules)) {
|
|
5511
|
+
if (!value || value.preload === void 0) continue;
|
|
5512
|
+
if (!candidates.some((candidate) => picomatch(pattern)(candidate))) continue;
|
|
5513
|
+
const rule = normalizeRule(value.preload, pattern);
|
|
5514
|
+
const score = getRuleScore(pattern);
|
|
5515
|
+
if (!matched || compareScores(score, matched.score) > 0) matched = {
|
|
5516
|
+
page,
|
|
5517
|
+
rule,
|
|
5518
|
+
pattern,
|
|
5519
|
+
score
|
|
5520
|
+
};
|
|
5521
|
+
}
|
|
5522
|
+
if (!matched) return;
|
|
5523
|
+
const { score: _score, ...result } = matched;
|
|
5524
|
+
return result;
|
|
5525
|
+
}
|
|
5526
|
+
function collectSubPackages(appJson) {
|
|
5527
|
+
return (Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : []).flatMap((item) => {
|
|
5528
|
+
if (!isObject(item) || typeof item.root !== "string") return [];
|
|
5529
|
+
const root = normalizePackageRoot(item.root);
|
|
5530
|
+
return (Array.isArray(item.pages) ? item.pages.filter((page) => typeof page === "string" && page.trim().length > 0) : []).map((page) => ({
|
|
5531
|
+
route: normalizePagePath(path.posix.join(root, page)),
|
|
5532
|
+
packageRoot: root,
|
|
5533
|
+
...item.independent === true ? { independent: true } : {}
|
|
5534
|
+
}));
|
|
5535
|
+
});
|
|
5536
|
+
}
|
|
5537
|
+
function collectPreloadPages(appJson) {
|
|
5538
|
+
return [...Array.isArray(appJson.pages) ? appJson.pages.filter((page) => typeof page === "string" && page.trim().length > 0).map((page) => ({ route: normalizePagePath(page) })) : [], ...collectSubPackages(appJson)];
|
|
5539
|
+
}
|
|
5540
|
+
function findPreloadRuleKey(page, preloadRule) {
|
|
5541
|
+
const candidates = pageCandidates(page);
|
|
5542
|
+
return Object.keys(preloadRule).find((candidate) => candidates.includes(normalizePagePath(candidate)));
|
|
5543
|
+
}
|
|
5544
|
+
function resolvePreloadPackageIdentifier(value, appJson) {
|
|
5545
|
+
const normalized = value === "__APP__" ? value : normalizePackageRoot(value);
|
|
5546
|
+
if (!normalized || normalized === "__APP__") return normalized || void 0;
|
|
5547
|
+
const source = Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : [];
|
|
5548
|
+
for (const item of source) {
|
|
5549
|
+
if (!isObject(item) || typeof item.root !== "string") continue;
|
|
5550
|
+
const root = normalizePackageRoot(item.root);
|
|
5551
|
+
if (root === normalized || typeof item.name === "string" && item.name === value) return root;
|
|
5552
|
+
}
|
|
5553
|
+
return normalized;
|
|
5554
|
+
}
|
|
5555
|
+
function cloneRule(rule) {
|
|
5556
|
+
if (!isObject(rule)) return rule;
|
|
5557
|
+
const packages = Array.isArray(rule.packages) ? rule.packages.filter((item) => typeof item === "string") : [];
|
|
5558
|
+
return {
|
|
5559
|
+
...rule,
|
|
5560
|
+
packages: [...packages]
|
|
5561
|
+
};
|
|
5562
|
+
}
|
|
5563
|
+
/**
|
|
5564
|
+
* @description 将 routeRules 中的 preload 声明合成为 app.json.preloadRule。
|
|
5565
|
+
* 手写的 preloadRule 保持优先,其他平台不生成微信专属字段。
|
|
5566
|
+
*/
|
|
5567
|
+
function applyPreloadRulesToAppJson(appJson, routeRules, platform) {
|
|
5568
|
+
if (platform !== "weapp" || !routeRules) return appJson;
|
|
5569
|
+
const existing = isObject(appJson.preloadRule) ? appJson.preloadRule : {};
|
|
5570
|
+
const next = { ...existing };
|
|
5571
|
+
for (const page of collectPreloadPages(appJson)) {
|
|
5572
|
+
const match = findRouteRuleMatch(page.route, routeRules);
|
|
5573
|
+
if (!match || findPreloadRuleKey(page.route, existing) !== void 0) continue;
|
|
5574
|
+
next[page.route] = cloneRule(match.rule);
|
|
5575
|
+
}
|
|
5576
|
+
if (Object.keys(next).length > 0) appJson.preloadRule = next;
|
|
5577
|
+
return appJson;
|
|
5578
|
+
}
|
|
5579
|
+
function suggestPreloadRules(appJson, pageSources) {
|
|
5580
|
+
const pages = collectPreloadPages(appJson);
|
|
5581
|
+
const pageByRoute = new Map(pages.map((page) => [page.route, page]));
|
|
5582
|
+
const suggestions = [];
|
|
5583
|
+
const uncovered = /* @__PURE__ */ new Set();
|
|
5584
|
+
for (const page of pages) {
|
|
5585
|
+
const source = pageSources.get(page.route);
|
|
5586
|
+
for (const kind of ["template", "script"]) for (const target of collectStaticRouteTargets(source?.[kind] ?? "", kind, page.route)) {
|
|
5587
|
+
const targetPage = pageByRoute.get(target);
|
|
5588
|
+
if (!targetPage) continue;
|
|
5589
|
+
const packageRoot = targetPage.packageRoot ?? (page.independent ? "__APP__" : void 0);
|
|
5590
|
+
if (!packageRoot || packageRoot === page.packageRoot) continue;
|
|
5591
|
+
const suggestion = {
|
|
5592
|
+
page: page.route,
|
|
5593
|
+
packageRoot,
|
|
5594
|
+
target,
|
|
5595
|
+
source: kind
|
|
5596
|
+
};
|
|
5597
|
+
suggestions.push(suggestion);
|
|
5598
|
+
}
|
|
5599
|
+
if (source && !source.template && !source.script) uncovered.add(page.route);
|
|
5600
|
+
}
|
|
5601
|
+
return {
|
|
5602
|
+
pages,
|
|
5603
|
+
suggestions,
|
|
5604
|
+
uncovered: [...uncovered]
|
|
5605
|
+
};
|
|
5606
|
+
}
|
|
5607
|
+
//#endregion
|
|
5312
5608
|
//#region src/utils/projectConfig.ts
|
|
5313
5609
|
async function readProjectConfigFile(filePath, required) {
|
|
5314
5610
|
if (!await fs$1.pathExists(filePath)) {
|
|
@@ -5348,6 +5644,17 @@ async function getProjectConfig(root, options) {
|
|
|
5348
5644
|
async function getProjectPrivateConfig(root, options) {
|
|
5349
5645
|
return await readProjectConfigFile(path.resolve(root, options?.privatePath ?? "project.private.config.json"), false);
|
|
5350
5646
|
}
|
|
5647
|
+
async function disableProjectPrivateConfigHotReload(filePath) {
|
|
5648
|
+
const config = await readProjectConfigFile(filePath, true);
|
|
5649
|
+
const setting = config.setting && typeof config.setting === "object" && !Array.isArray(config.setting) ? config.setting : {};
|
|
5650
|
+
if (setting.compileHotReLoad === false) return false;
|
|
5651
|
+
config.setting = {
|
|
5652
|
+
...setting,
|
|
5653
|
+
compileHotReLoad: false
|
|
5654
|
+
};
|
|
5655
|
+
await fs$1.writeFile(filePath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
5656
|
+
return true;
|
|
5657
|
+
}
|
|
5351
5658
|
function resolveProjectConfigSyncDirs(options) {
|
|
5352
5659
|
const outputRoot = path.dirname(options.outDir);
|
|
5353
5660
|
const sourceBasePath = path.resolve(options.projectConfigPath);
|
|
@@ -5729,7 +6036,7 @@ function createRegistryHelpers(state) {
|
|
|
5729
6036
|
}
|
|
5730
6037
|
const nextKey = globs.join("\0");
|
|
5731
6038
|
if (!state.autoImportState.matcher || state.autoImportState.matcherKey !== nextKey) {
|
|
5732
|
-
state.autoImportState.matcher =
|
|
6039
|
+
state.autoImportState.matcher = picomatch(globs, { windows: true });
|
|
5733
6040
|
state.autoImportState.matcherKey = nextKey;
|
|
5734
6041
|
}
|
|
5735
6042
|
return state.autoImportState.matcher;
|
|
@@ -6212,7 +6519,7 @@ function createRule(pattern) {
|
|
|
6212
6519
|
};
|
|
6213
6520
|
return {
|
|
6214
6521
|
pattern,
|
|
6215
|
-
match:
|
|
6522
|
+
match: picomatch(pattern, { dot: true })
|
|
6216
6523
|
};
|
|
6217
6524
|
}
|
|
6218
6525
|
function isDefaultAutoRouteInclude(include) {
|
|
@@ -6750,14 +7057,12 @@ function normalizeScopedSubPackage(subPackage) {
|
|
|
6750
7057
|
pages: Array.isArray(subPackage.pages) ? subPackage.pages : []
|
|
6751
7058
|
};
|
|
6752
7059
|
}
|
|
6753
|
-
function filterPreloadRule(preloadRule,
|
|
7060
|
+
function filterPreloadRule(preloadRule, scopedPages, scopedPackageIdentifiers, includeMainPackage) {
|
|
6754
7061
|
if (!preloadRule || typeof preloadRule !== "object") return preloadRule;
|
|
6755
|
-
const scopedRoots = new Set(scope.subPackageRoots);
|
|
6756
7062
|
const scopedPreloadRule = {};
|
|
6757
7063
|
for (const [pagePath, rule] of Object.entries(preloadRule)) {
|
|
6758
7064
|
const normalizedPagePath = normalizeRoot(pagePath);
|
|
6759
|
-
|
|
6760
|
-
if (!(pageSubPackageRoot ? scopedRoots.has(pageSubPackageRoot) : scope.includeMainPackage)) continue;
|
|
7065
|
+
if (!scopedPages.has(normalizedPagePath)) continue;
|
|
6761
7066
|
if (!rule || typeof rule !== "object" || !("packages" in rule)) {
|
|
6762
7067
|
scopedPreloadRule[pagePath] = rule;
|
|
6763
7068
|
continue;
|
|
@@ -6768,7 +7073,9 @@ function filterPreloadRule(preloadRule, scope, allSubPackageRoots) {
|
|
|
6768
7073
|
continue;
|
|
6769
7074
|
}
|
|
6770
7075
|
const filteredPackages = packages.filter((packageRoot) => {
|
|
6771
|
-
|
|
7076
|
+
if (typeof packageRoot !== "string") return false;
|
|
7077
|
+
const normalizedPackageRoot = normalizeRoot(packageRoot);
|
|
7078
|
+
return normalizedPackageRoot === "__APP__" ? includeMainPackage : scopedPackageIdentifiers.has(normalizedPackageRoot);
|
|
6772
7079
|
});
|
|
6773
7080
|
if (filteredPackages.length > 0) scopedPreloadRule[pagePath] = {
|
|
6774
7081
|
...rule,
|
|
@@ -6777,18 +7084,49 @@ function filterPreloadRule(preloadRule, scope, allSubPackageRoots) {
|
|
|
6777
7084
|
}
|
|
6778
7085
|
return Object.keys(scopedPreloadRule).length > 0 ? scopedPreloadRule : void 0;
|
|
6779
7086
|
}
|
|
7087
|
+
function collectScopedAppGraph(pages, subPackages) {
|
|
7088
|
+
const mainPages = new Set(pages.map((page) => normalizeRoot(page)));
|
|
7089
|
+
const allPages = new Set(mainPages);
|
|
7090
|
+
const packageIdentifiers = /* @__PURE__ */ new Set();
|
|
7091
|
+
for (const subPackage of subPackages) {
|
|
7092
|
+
const root = normalizeRoot(subPackage.root ?? "");
|
|
7093
|
+
if (!root) continue;
|
|
7094
|
+
packageIdentifiers.add(root);
|
|
7095
|
+
if (typeof subPackage.name === "string" && subPackage.name.trim()) packageIdentifiers.add(normalizeRoot(subPackage.name));
|
|
7096
|
+
for (const page of subPackage.pages ?? []) allPages.add(normalizeRoot(`${root}/${page}`));
|
|
7097
|
+
}
|
|
7098
|
+
return {
|
|
7099
|
+
allPages,
|
|
7100
|
+
mainPages,
|
|
7101
|
+
packageIdentifiers
|
|
7102
|
+
};
|
|
7103
|
+
}
|
|
7104
|
+
function filterTabBar(tabBar, mainPages) {
|
|
7105
|
+
if (!tabBar || !Array.isArray(tabBar.list)) return tabBar;
|
|
7106
|
+
const list = tabBar.list.filter((item) => {
|
|
7107
|
+
return typeof item.pagePath === "string" && mainPages.has(normalizeRoot(item.pagePath));
|
|
7108
|
+
});
|
|
7109
|
+
if (list.length < 2) return;
|
|
7110
|
+
return {
|
|
7111
|
+
...tabBar,
|
|
7112
|
+
list
|
|
7113
|
+
};
|
|
7114
|
+
}
|
|
6780
7115
|
function applyBuildScopeToAppConfig(config, scope) {
|
|
6781
7116
|
if (!scope?.enabled) return config;
|
|
6782
7117
|
const scopedRoots = new Set(scope.subPackageRoots);
|
|
6783
|
-
const
|
|
6784
|
-
const allSubPackageRoots = new Set(sourceSubPackages.map((subPackage) => subPackage.root ? normalizeRoot(subPackage.root) : void 0).filter((root) => Boolean(root)));
|
|
6785
|
-
const scopedSubPackages = sourceSubPackages.filter((subPackage) => isSubPackageInScope(subPackage, scopedRoots)).map(normalizeScopedSubPackage);
|
|
7118
|
+
const scopedSubPackages = (Array.isArray(config.subPackages) ? config.subPackages : Array.isArray(config.subpackages) ? config.subpackages : []).filter((subPackage) => isSubPackageInScope(subPackage, scopedRoots)).map(normalizeScopedSubPackage);
|
|
6786
7119
|
config.pages = scope.includeMainPackage && Array.isArray(config.pages) ? config.pages : [];
|
|
6787
7120
|
config.subPackages = scopedSubPackages;
|
|
6788
7121
|
delete config.subpackages;
|
|
6789
|
-
const
|
|
7122
|
+
const scopedGraph = collectScopedAppGraph(config.pages, scopedSubPackages);
|
|
7123
|
+
const preloadRule = filterPreloadRule(config.preloadRule, scopedGraph.allPages, scopedGraph.packageIdentifiers, scope.includeMainPackage);
|
|
6790
7124
|
if (preloadRule) config.preloadRule = preloadRule;
|
|
6791
7125
|
else delete config.preloadRule;
|
|
7126
|
+
const tabBar = filterTabBar(config.tabBar, scopedGraph.mainPages);
|
|
7127
|
+
if (tabBar) config.tabBar = tabBar;
|
|
7128
|
+
else delete config.tabBar;
|
|
7129
|
+
if (typeof config.entryPagePath === "string" && !scopedGraph.mainPages.has(normalizeRoot(config.entryPagePath))) delete config.entryPagePath;
|
|
6792
7130
|
return config;
|
|
6793
7131
|
}
|
|
6794
7132
|
function applyBuildScopeToAutoRoutes(routes, scope) {
|
|
@@ -7880,18 +8218,65 @@ function resolveCompilerOutputExtensions(outputExtensions) {
|
|
|
7880
8218
|
}
|
|
7881
8219
|
//#endregion
|
|
7882
8220
|
//#region src/runtime/hmrRuntime.ts
|
|
7883
|
-
function
|
|
7884
|
-
|
|
7885
|
-
if (options.platform === "weapp" && options.
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
8221
|
+
function resolveHmrRuntimeDecision(options) {
|
|
8222
|
+
const configured = options.configured ?? "auto";
|
|
8223
|
+
if (options.platform === "weapp" && options.skyline === true) return {
|
|
8224
|
+
configured,
|
|
8225
|
+
reason: "skyline-fallback",
|
|
8226
|
+
runtime: "classic"
|
|
8227
|
+
};
|
|
8228
|
+
if (configured === "classic" || configured === "stateful-experimental") return {
|
|
8229
|
+
configured,
|
|
8230
|
+
reason: "explicit",
|
|
8231
|
+
runtime: configured
|
|
8232
|
+
};
|
|
8233
|
+
if (options.platform === "weapp" && options.compileHotReLoad === true) return {
|
|
8234
|
+
configured,
|
|
8235
|
+
reason: "auto-stateful",
|
|
8236
|
+
runtime: "stateful-experimental"
|
|
8237
|
+
};
|
|
8238
|
+
return {
|
|
8239
|
+
configured,
|
|
8240
|
+
reason: options.platform === "weapp" ? "auto-classic" : "auto-non-wechat",
|
|
8241
|
+
runtime: "classic"
|
|
8242
|
+
};
|
|
8243
|
+
}
|
|
8244
|
+
function findSkylineRendererFiles(output) {
|
|
8245
|
+
const jsonConfigs = /* @__PURE__ */ new Map();
|
|
8246
|
+
for (const item of output) {
|
|
8247
|
+
if (item.type !== "asset" || !item.fileName.endsWith(".json")) continue;
|
|
8248
|
+
const source = typeof item.source === "string" ? item.source : item.source instanceof Uint8Array ? new TextDecoder().decode(item.source) : void 0;
|
|
8249
|
+
if (!source) continue;
|
|
8250
|
+
try {
|
|
8251
|
+
const config = JSON.parse(source);
|
|
8252
|
+
if (config && typeof config === "object" && !Array.isArray(config)) jsonConfigs.set(item.fileName.replaceAll("\\", "/"), config);
|
|
8253
|
+
} catch {}
|
|
8254
|
+
}
|
|
8255
|
+
const appConfig = jsonConfigs.get("app.json");
|
|
8256
|
+
if (!appConfig) return [];
|
|
8257
|
+
const configFiles = /* @__PURE__ */ new Set(["app.json"]);
|
|
8258
|
+
if (Array.isArray(appConfig.pages)) {
|
|
8259
|
+
for (const page of appConfig.pages) if (typeof page === "string") configFiles.add(`${page}.json`);
|
|
8260
|
+
}
|
|
8261
|
+
const subPackages = Array.isArray(appConfig.subPackages) ? appConfig.subPackages : Array.isArray(appConfig.subpackages) ? appConfig.subpackages : [];
|
|
8262
|
+
for (const subPackage of subPackages) {
|
|
8263
|
+
if (!subPackage || typeof subPackage !== "object" || Array.isArray(subPackage)) continue;
|
|
8264
|
+
const { pages, root } = subPackage;
|
|
8265
|
+
if (typeof root !== "string" || !Array.isArray(pages)) continue;
|
|
8266
|
+
const normalizedRoot = root.replaceAll("\\", "/").replace(/^\/+|\/+$/g, "");
|
|
8267
|
+
for (const page of pages) if (typeof page === "string") configFiles.add(`${normalizedRoot}/${page}.json`);
|
|
8268
|
+
}
|
|
8269
|
+
return [...configFiles].filter((fileName) => jsonConfigs.get(fileName)?.renderer === "skyline");
|
|
8270
|
+
}
|
|
8271
|
+
function formatHmrRuntimeStartupMessages(decision) {
|
|
8272
|
+
if (decision.reason === "skyline-fallback") return ["HMR 模式:classic(自动降级:Skyline 暂不支持微信开发者工具热重载)", "HMR 切换:切回 WebView 后可手动重新开启微信开发者工具“热重载”。"];
|
|
8273
|
+
if (decision.reason === "runtime-compatibility-fallback") return ["HMR 模式:classic(自动降级:stateful HMR 运行时兼容性检查失败)", "HMR 切换:修复兼容性问题后重启 wv dev,或通过 weapp.hmr.runtime 显式配置 classic。"];
|
|
8274
|
+
if (decision.reason === "explicit") {
|
|
8275
|
+
const alternative = decision.runtime === "classic" ? "stateful-experimental" : "classic";
|
|
8276
|
+
return [`HMR 模式:${decision.runtime}(显式配置)`, `HMR 切换:修改 weapp.hmr.runtime 为 auto 或 ${alternative} 后重启 wv dev。`];
|
|
8277
|
+
}
|
|
8278
|
+
if (decision.reason === "auto-non-wechat") return ["HMR 模式:classic(自动检测:仅微信小程序支持 stateful-experimental)", "HMR 切换:可通过 weapp.hmr.runtime 显式配置 classic。"];
|
|
8279
|
+
if (decision.reason === "auto-stateful") return ["HMR 模式:stateful-experimental(自动检测:微信开发者工具热重载已开启)", "HMR 切换:关闭微信开发者工具“热重载”后重启 wv dev,或通过 weapp.hmr.runtime 显式配置。"];
|
|
7895
8280
|
return ["HMR 模式:classic(自动检测:微信开发者工具热重载未开启或无法确认)", "HMR 切换:开启微信开发者工具“热重载”后重启 wv dev,或通过 weapp.hmr.runtime 显式配置。"];
|
|
7896
8281
|
}
|
|
7897
8282
|
//#endregion
|
|
@@ -8923,6 +9308,7 @@ function createRuntimeState() {
|
|
|
8923
9308
|
emittedCode: /* @__PURE__ */ new Map()
|
|
8924
9309
|
},
|
|
8925
9310
|
scan: {
|
|
9311
|
+
mainPackageStyleEntries: void 0,
|
|
8926
9312
|
subPackageMap: /* @__PURE__ */ new Map(),
|
|
8927
9313
|
independentSubPackageMap: /* @__PURE__ */ new Map(),
|
|
8928
9314
|
warnedMessages: /* @__PURE__ */ new Set(),
|
|
@@ -8992,6 +9378,7 @@ function resetRuntimeStateForFreshBuild(runtimeState) {
|
|
|
8992
9378
|
wxml.cache.signatureMap.clear();
|
|
8993
9379
|
wxml.emittedCode.clear();
|
|
8994
9380
|
const scan = runtimeState.scan;
|
|
9381
|
+
scan.mainPackageStyleEntries = void 0;
|
|
8995
9382
|
scan.subPackageMap.clear();
|
|
8996
9383
|
scan.independentSubPackageMap.clear();
|
|
8997
9384
|
scan.warnedMessages.clear();
|
|
@@ -10466,6 +10853,83 @@ function createAdvancedChunkNameResolver(options) {
|
|
|
10466
10853
|
};
|
|
10467
10854
|
}
|
|
10468
10855
|
//#endregion
|
|
10856
|
+
//#region src/runtime/preserveModules.ts
|
|
10857
|
+
const PRESERVED_MODULE_GROUP_PRIORITY = 100;
|
|
10858
|
+
function createPatternMatcher(pattern) {
|
|
10859
|
+
if (typeof pattern === "string") {
|
|
10860
|
+
const matcher = picomatch(pattern, { dot: true });
|
|
10861
|
+
return (value) => matcher(value);
|
|
10862
|
+
}
|
|
10863
|
+
if (isRegexp(pattern)) return (value) => {
|
|
10864
|
+
pattern.lastIndex = 0;
|
|
10865
|
+
return pattern.test(value);
|
|
10866
|
+
};
|
|
10867
|
+
}
|
|
10868
|
+
function createPreserveModuleMatcher(patterns) {
|
|
10869
|
+
const matchers = patterns?.map((pattern) => createPatternMatcher(pattern)).filter((matcher) => typeof matcher === "function");
|
|
10870
|
+
if (!matchers?.length) return;
|
|
10871
|
+
return (relativeId, absoluteId) => {
|
|
10872
|
+
return matchers.some((matcher) => matcher(relativeId) || matcher(absoluteId));
|
|
10873
|
+
};
|
|
10874
|
+
}
|
|
10875
|
+
function normalizePreservedSourceId(id) {
|
|
10876
|
+
return normalizeViteId(id, {
|
|
10877
|
+
stripQuery: true,
|
|
10878
|
+
fileProtocolToPath: true,
|
|
10879
|
+
stripAtFsPrefix: true,
|
|
10880
|
+
stripLeadingNullByte: true
|
|
10881
|
+
});
|
|
10882
|
+
}
|
|
10883
|
+
function normalizePreserveModulesRolldownOptions(configService, rolldownOptions) {
|
|
10884
|
+
if (configService.weappViteConfig?.chunks?.preserveModules?.length && (rolldownOptions.preserveEntrySignatures === void 0 || rolldownOptions.preserveEntrySignatures === "exports-only")) rolldownOptions.preserveEntrySignatures = "allow-extension";
|
|
10885
|
+
return rolldownOptions;
|
|
10886
|
+
}
|
|
10887
|
+
function resolvePreservedModuleName(options) {
|
|
10888
|
+
const { configService, ctx, getSubPackageRoots, id } = options;
|
|
10889
|
+
if (parseSidecarSourceRequest(id)) return;
|
|
10890
|
+
const absoluteId = normalizePreservedSourceId(id);
|
|
10891
|
+
if (!path.isAbsolute(absoluteId) || !isPathInside(configService.absoluteSrcRoot, absoluteId)) return;
|
|
10892
|
+
const moduleInfo = ctx.getModuleInfo(id);
|
|
10893
|
+
if (moduleInfo?.importers?.some((importer) => {
|
|
10894
|
+
return parseLogicalEntryId(importer)?.sourceId === absoluteId;
|
|
10895
|
+
})) return;
|
|
10896
|
+
const relativeId = normalizeRelativePath$1(path.relative(configService.absoluteSrcRoot, absoluteId));
|
|
10897
|
+
if (!relativeId || relativeId.startsWith("..")) return;
|
|
10898
|
+
const subPackageRoots = Array.from(getSubPackageRoots());
|
|
10899
|
+
const moduleRoot = resolveSubPackagePrefix(relativeId, subPackageRoots);
|
|
10900
|
+
if (moduleRoot) assertModuleScopedToRoot({
|
|
10901
|
+
moduleInfo,
|
|
10902
|
+
moduleRoot,
|
|
10903
|
+
relativeAbsoluteSrcRoot: configService.relativeAbsoluteSrcRoot,
|
|
10904
|
+
subPackageRoots,
|
|
10905
|
+
moduleId: id
|
|
10906
|
+
});
|
|
10907
|
+
const name = removeExtensionDeep(relativeId);
|
|
10908
|
+
return name && name !== "." ? name : void 0;
|
|
10909
|
+
}
|
|
10910
|
+
function createPreserveModulesGroup(configService, getSubPackageRoots) {
|
|
10911
|
+
const matches = createPreserveModuleMatcher(configService.weappViteConfig?.chunks?.preserveModules);
|
|
10912
|
+
if (!matches) return;
|
|
10913
|
+
return {
|
|
10914
|
+
name: (id, ctx) => resolvePreservedModuleName({
|
|
10915
|
+
configService,
|
|
10916
|
+
ctx,
|
|
10917
|
+
getSubPackageRoots,
|
|
10918
|
+
id
|
|
10919
|
+
}),
|
|
10920
|
+
test: (id) => {
|
|
10921
|
+
const absoluteId = normalizePreservedSourceId(id);
|
|
10922
|
+
const relativeId = configService.relativeAbsoluteSrcRoot(absoluteId);
|
|
10923
|
+
return matches(relativeId, absoluteId);
|
|
10924
|
+
},
|
|
10925
|
+
priority: PRESERVED_MODULE_GROUP_PRIORITY,
|
|
10926
|
+
minShareCount: 1,
|
|
10927
|
+
minSize: 0,
|
|
10928
|
+
minModuleSize: 0,
|
|
10929
|
+
includeDependenciesRecursively: false
|
|
10930
|
+
};
|
|
10931
|
+
}
|
|
10932
|
+
//#endregion
|
|
10469
10933
|
//#region src/runtime/wevuModules.ts
|
|
10470
10934
|
const WEVU_RUNTIME_MODULE_IDS = [
|
|
10471
10935
|
"wevu",
|
|
@@ -10608,7 +11072,7 @@ function resolveNodeModulesSharedPath(cleanedAbsoluteId) {
|
|
|
10608
11072
|
}
|
|
10609
11073
|
function createStringOrRegExpMatcher(pattern) {
|
|
10610
11074
|
if (typeof pattern === "string") {
|
|
10611
|
-
const matcher =
|
|
11075
|
+
const matcher = picomatch(pattern, { dot: true });
|
|
10612
11076
|
return (value) => matcher(value);
|
|
10613
11077
|
}
|
|
10614
11078
|
if (isRegexp(pattern)) return (value) => {
|
|
@@ -10777,15 +11241,20 @@ function createSharedBuildResolver(configService, getSubPackageRoots) {
|
|
|
10777
11241
|
return { resolveAdvancedChunkName: resolveSharedBuildChunkName };
|
|
10778
11242
|
}
|
|
10779
11243
|
function createSharedBuildOutput(configService, getSubPackageRoots, options = {}) {
|
|
11244
|
+
const preserveModulesGroup = createPreserveModulesGroup(configService, getSubPackageRoots);
|
|
10780
11245
|
const { resolveAdvancedChunkName } = createSharedBuildResolver(configService, getSubPackageRoots);
|
|
10781
11246
|
return {
|
|
10782
|
-
codeSplitting: { groups: [
|
|
10783
|
-
|
|
10784
|
-
|
|
10785
|
-
|
|
10786
|
-
|
|
10787
|
-
|
|
10788
|
-
|
|
11247
|
+
codeSplitting: { groups: [
|
|
11248
|
+
...preserveModulesGroup ? [preserveModulesGroup] : [],
|
|
11249
|
+
...configService.isDev ? [{
|
|
11250
|
+
test: isStableHashedDistChunkModule,
|
|
11251
|
+
minShareCount: 1,
|
|
11252
|
+
minSize: 0,
|
|
11253
|
+
minModuleSize: 0,
|
|
11254
|
+
name: (id) => resolveStableHashedDistChunkName({ facadeModuleId: id })
|
|
11255
|
+
}] : [],
|
|
11256
|
+
{ name: (id, ctx) => resolveAdvancedChunkName(id, ctx) }
|
|
11257
|
+
] },
|
|
10789
11258
|
minifyInternalExports: false,
|
|
10790
11259
|
chunkFileNames: (chunk) => {
|
|
10791
11260
|
if (isRequestGlobalsRuntimeChunk(chunk)) return REQUEST_GLOBAL_RUNTIME_CHUNK_FILE_BASENAME;
|
|
@@ -10800,7 +11269,12 @@ function createSharedBuildOutput(configService, getSubPackageRoots, options = {}
|
|
|
10800
11269
|
};
|
|
10801
11270
|
}
|
|
10802
11271
|
function createSharedBuildConfig(configService, scanService) {
|
|
10803
|
-
|
|
11272
|
+
const output = createSharedBuildOutput(configService, () => scanService.subPackageMap.keys());
|
|
11273
|
+
const preserveEntrySignatures = configService.weappViteConfig?.chunks?.preserveModules?.length ? "allow-extension" : void 0;
|
|
11274
|
+
return { build: { rolldownOptions: {
|
|
11275
|
+
...preserveEntrySignatures ? { preserveEntrySignatures } : {},
|
|
11276
|
+
output
|
|
11277
|
+
} } };
|
|
10804
11278
|
}
|
|
10805
11279
|
//#endregion
|
|
10806
11280
|
//#region src/runtime/statefulHmr/runtimeSource.ts
|
|
@@ -11213,6 +11687,8 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11213
11687
|
let pendingBatch;
|
|
11214
11688
|
let requestGeneration = 0;
|
|
11215
11689
|
let activeRequest;
|
|
11690
|
+
let lastRequestError;
|
|
11691
|
+
let lastResponse;
|
|
11216
11692
|
let timer;
|
|
11217
11693
|
const sessionId = Date.now().toString(36) + '-' + Math.random().toString(36).slice(2);
|
|
11218
11694
|
const schedule = (delay) => {
|
|
@@ -11236,7 +11712,9 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11236
11712
|
success(result) {
|
|
11237
11713
|
if (generation !== requestGeneration) return;
|
|
11238
11714
|
activeRequest = undefined;
|
|
11715
|
+
lastRequestError = undefined;
|
|
11239
11716
|
const type = result?.data?.type;
|
|
11717
|
+
lastResponse = { action, statusCode: result?.statusCode, type };
|
|
11240
11718
|
if (action === 'register' && type === 'registered') {
|
|
11241
11719
|
phase = 'polling';
|
|
11242
11720
|
if (pendingBatch) globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CLIENT_KEY)}].receiveBatch(pendingBatch.meta, pendingBatch.apply);
|
|
@@ -11246,9 +11724,14 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11246
11724
|
else if (type === 'rebuilding') schedule(1000);
|
|
11247
11725
|
else schedule(500);
|
|
11248
11726
|
},
|
|
11249
|
-
fail() {
|
|
11727
|
+
fail(error) {
|
|
11250
11728
|
if (generation !== requestGeneration) return;
|
|
11251
11729
|
activeRequest = undefined;
|
|
11730
|
+
lastRequestError = {
|
|
11731
|
+
action,
|
|
11732
|
+
errMsg: String(error?.errMsg || ''),
|
|
11733
|
+
errno: error?.errno,
|
|
11734
|
+
};
|
|
11252
11735
|
schedule(500);
|
|
11253
11736
|
}
|
|
11254
11737
|
});
|
|
@@ -11268,6 +11751,7 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11268
11751
|
lastApply: undefined,
|
|
11269
11752
|
getVersion() { return version; },
|
|
11270
11753
|
getLastApply() { return this.lastApply; },
|
|
11754
|
+
getTransportState() { return { phase, version, lastRequestError, lastResponse }; },
|
|
11271
11755
|
stop() {
|
|
11272
11756
|
phase = 'stopped';
|
|
11273
11757
|
if (timer) {
|
|
@@ -11917,6 +12401,36 @@ function createReactPlugin(ctx) {
|
|
|
11917
12401
|
}];
|
|
11918
12402
|
}
|
|
11919
12403
|
//#endregion
|
|
12404
|
+
//#region src/runtime/watch/options.ts
|
|
12405
|
+
/**
|
|
12406
|
+
* 解析主 watcher 与 sidecar watcher 共享的轮询配置。
|
|
12407
|
+
*/
|
|
12408
|
+
function resolvePollingWatchOptions(configService) {
|
|
12409
|
+
const buildWatch = configService.inlineConfig?.build?.watch;
|
|
12410
|
+
const chokidar = buildWatch && typeof buildWatch === "object" && "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
12411
|
+
const serverWatch = configService.inlineConfig?.server?.watch;
|
|
12412
|
+
const envUsePolling = process.env.CHOKIDAR_USEPOLLING;
|
|
12413
|
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
12414
|
+
const envBinaryInterval = process.env.CHOKIDAR_BINARY_INTERVAL;
|
|
12415
|
+
const usePollingCandidate = chokidar?.usePolling ?? serverWatch?.usePolling ?? (envUsePolling === "1" || envUsePolling === "true" ? true : envUsePolling === "0" || envUsePolling === "false" ? false : void 0);
|
|
12416
|
+
const intervalCandidate = chokidar?.interval ?? serverWatch?.interval ?? (envInterval ? Number(envInterval) : void 0);
|
|
12417
|
+
const binaryIntervalCandidate = chokidar?.binaryInterval ?? serverWatch?.binaryInterval ?? (envBinaryInterval ? Number(envBinaryInterval) : void 0);
|
|
12418
|
+
return {
|
|
12419
|
+
usePolling: typeof usePollingCandidate === "boolean" ? usePollingCandidate : void 0,
|
|
12420
|
+
interval: typeof intervalCandidate === "number" && Number.isFinite(intervalCandidate) ? intervalCandidate : void 0,
|
|
12421
|
+
binaryInterval: typeof binaryIntervalCandidate === "number" && Number.isFinite(binaryIntervalCandidate) ? binaryIntervalCandidate : void 0
|
|
12422
|
+
};
|
|
12423
|
+
}
|
|
12424
|
+
function createSidecarWatchOptions(configService, input) {
|
|
12425
|
+
const polling = resolvePollingWatchOptions(configService);
|
|
12426
|
+
return {
|
|
12427
|
+
...input,
|
|
12428
|
+
...polling.usePolling !== void 0 ? { usePolling: polling.usePolling } : {},
|
|
12429
|
+
...typeof polling.interval === "number" ? { interval: polling.interval } : {},
|
|
12430
|
+
...typeof polling.binaryInterval === "number" ? { binaryInterval: polling.binaryInterval } : {}
|
|
12431
|
+
};
|
|
12432
|
+
}
|
|
12433
|
+
//#endregion
|
|
11920
12434
|
//#region src/runtime/statefulHmr/outputWriter.ts
|
|
11921
12435
|
/**
|
|
11922
12436
|
* @description 通过独立的 Vite write 阶段持久化 DevEngine 已生成的文件,不重新解析业务源码。
|
|
@@ -12238,7 +12752,7 @@ var StatefulHmrTransport = class {
|
|
|
12238
12752
|
return {
|
|
12239
12753
|
buildId: this.state.buildId,
|
|
12240
12754
|
token: this.token,
|
|
12241
|
-
url: `http://
|
|
12755
|
+
url: `http://localhost:${port}${endpointPath}`
|
|
12242
12756
|
};
|
|
12243
12757
|
}
|
|
12244
12758
|
handleRequest = async (request, response) => {
|
|
@@ -12380,12 +12894,16 @@ var StatefulHmrViteAdapter = class {
|
|
|
12380
12894
|
config;
|
|
12381
12895
|
server;
|
|
12382
12896
|
callbacks;
|
|
12897
|
+
watchOptions;
|
|
12898
|
+
createDevEngine;
|
|
12383
12899
|
bundledDev;
|
|
12384
12900
|
initialOutputError;
|
|
12385
|
-
constructor(config, server, callbacks) {
|
|
12901
|
+
constructor(config, server, callbacks, watchOptions = {}, createDevEngine = dev) {
|
|
12386
12902
|
this.config = config;
|
|
12387
12903
|
this.server = server;
|
|
12388
12904
|
this.callbacks = callbacks;
|
|
12905
|
+
this.watchOptions = watchOptions;
|
|
12906
|
+
this.createDevEngine = createDevEngine;
|
|
12389
12907
|
}
|
|
12390
12908
|
install() {
|
|
12391
12909
|
const bundledDev = this.server.environments.client.bundledDev;
|
|
@@ -12394,7 +12912,6 @@ var StatefulHmrViteAdapter = class {
|
|
|
12394
12912
|
this.bundledDev = bundledDev;
|
|
12395
12913
|
this.installOptions(bundledDev);
|
|
12396
12914
|
this.installOutput(bundledDev);
|
|
12397
|
-
this.installPatches(bundledDev);
|
|
12398
12915
|
this.installListener(bundledDev);
|
|
12399
12916
|
}
|
|
12400
12917
|
async rebuild(prepare) {
|
|
@@ -12482,34 +12999,46 @@ var StatefulHmrViteAdapter = class {
|
|
|
12482
12999
|
}
|
|
12483
13000
|
};
|
|
12484
13001
|
}
|
|
12485
|
-
installPatches(bundledDev) {
|
|
12486
|
-
const original = bundledDev.handleHmrOutput.bind(bundledDev);
|
|
12487
|
-
bundledDev.handleHmrOutput = (client, files, output, info) => {
|
|
12488
|
-
if (output.type === "Noop") {
|
|
12489
|
-
this.callbacks.onPatch(files, output);
|
|
12490
|
-
return;
|
|
12491
|
-
}
|
|
12492
|
-
if (this.callbacks.onPatch(files, output)) original(client, files, output, info);
|
|
12493
|
-
};
|
|
12494
|
-
}
|
|
12495
13002
|
installListener(bundledDev) {
|
|
12496
|
-
const original = bundledDev.listen.bind(bundledDev);
|
|
12497
13003
|
bundledDev.listen = async () => {
|
|
12498
|
-
await
|
|
12499
|
-
|
|
12500
|
-
const
|
|
12501
|
-
|
|
12502
|
-
|
|
13004
|
+
const rolldownOptions = await bundledDev.getRolldownOptions();
|
|
13005
|
+
if (Array.isArray(rolldownOptions.output) && rolldownOptions.output.length > 1) throw new Error("stateful-experimental HMR 不支持多组 Rolldown output 配置。");
|
|
13006
|
+
const outputOptions = Array.isArray(rolldownOptions.output) ? rolldownOptions.output[0] : rolldownOptions.output;
|
|
13007
|
+
const engine = await this.createDevEngine(rolldownOptions, outputOptions, {
|
|
13008
|
+
onAdditionalAssets: (result) => bundledDev.storeOutputFiles(result.output),
|
|
13009
|
+
onHmrUpdates: (result) => this.handleHmrUpdates(result),
|
|
13010
|
+
onOutput: (result) => {
|
|
13011
|
+
if (result instanceof Error) {
|
|
13012
|
+
this.initialOutputError = result;
|
|
13013
|
+
this.callbacks.onError(result.message);
|
|
13014
|
+
return;
|
|
13015
|
+
}
|
|
13016
|
+
bundledDev.storeOutputFiles(result.output);
|
|
13017
|
+
},
|
|
13018
|
+
watch: {
|
|
13019
|
+
skipWrite: true,
|
|
13020
|
+
...this.watchOptions
|
|
13021
|
+
}
|
|
13022
|
+
});
|
|
13023
|
+
bundledDev._devEngine = engine;
|
|
13024
|
+
engine.run().catch((error) => {
|
|
13025
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
13026
|
+
this.callbacks.onError(message);
|
|
13027
|
+
});
|
|
13028
|
+
await engine.registerClient(clientId);
|
|
12503
13029
|
await engine.ensureCurrentBuildFinish();
|
|
12504
13030
|
if (this.initialOutputError) throw this.initialOutputError;
|
|
12505
13031
|
if ((await engine.getBundleState()).lastBuildErrored) throw new Error("微信状态保持 HMR 初次构建失败。");
|
|
12506
13032
|
await this.callbacks.waitForInitialBundle();
|
|
12507
13033
|
};
|
|
12508
13034
|
}
|
|
12509
|
-
|
|
12510
|
-
if (
|
|
12511
|
-
|
|
12512
|
-
|
|
13035
|
+
handleHmrUpdates(result) {
|
|
13036
|
+
if (result instanceof Error) {
|
|
13037
|
+
this.callbacks.onError(result.message);
|
|
13038
|
+
return;
|
|
13039
|
+
}
|
|
13040
|
+
if (result.changedFiles.length === 0) return;
|
|
13041
|
+
for (const { clientId: updateClientId, update } of result.updates) if (updateClientId === clientId) this.callbacks.onPatch(result.changedFiles, update);
|
|
12513
13042
|
}
|
|
12514
13043
|
};
|
|
12515
13044
|
function createStatefulHmrBanner(chunk) {
|
|
@@ -12546,16 +13075,22 @@ async function runStatefulHmrDev(ctx, buildOptions, restart, snapshots) {
|
|
|
12546
13075
|
const configService = ctx.configService;
|
|
12547
13076
|
if (configService.platform !== "weapp") throw new Error("weapp.hmr.runtime=\"stateful-experimental\" 目前仅支持微信小程序平台。");
|
|
12548
13077
|
let session;
|
|
13078
|
+
const entryIds = new Set(Array.from(snapshots.entryIds, (id) => normalizeFsResolvedId(id)));
|
|
13079
|
+
const pollingWatchOptions = resolvePollingWatchOptions(configService);
|
|
12549
13080
|
const installPlugin = {
|
|
12550
13081
|
name: "weapp-vite:stateful-hmr-session",
|
|
12551
13082
|
enforce: "post",
|
|
12552
13083
|
configureServer(server) {
|
|
12553
|
-
const currentSession = new StatefulHmrSession(ctx, server, restart, snapshots
|
|
13084
|
+
const currentSession = new StatefulHmrSession(ctx, server, restart, entryIds, snapshots, {
|
|
13085
|
+
compareContentsForPolling: pollingWatchOptions.usePolling === true ? true : void 0,
|
|
13086
|
+
pollInterval: pollingWatchOptions.interval,
|
|
13087
|
+
usePolling: pollingWatchOptions.usePolling
|
|
13088
|
+
});
|
|
12554
13089
|
session = currentSession;
|
|
12555
13090
|
currentSession.install();
|
|
12556
13091
|
},
|
|
12557
13092
|
transform(code, id) {
|
|
12558
|
-
if (!isStatefulHmrBoundary(id, configService.absoluteSrcRoot,
|
|
13093
|
+
if (!isStatefulHmrBoundary(id, configService.absoluteSrcRoot, entryIds) || code.includes("import.meta.hot.accept")) return;
|
|
12559
13094
|
return `${id.endsWith(".vue") ? code : redirectNativeComponentRegistration(code)}\nif (import.meta.hot) import.meta.hot.accept();\n`;
|
|
12560
13095
|
}
|
|
12561
13096
|
};
|
|
@@ -12615,6 +13150,7 @@ var StatefulHmrSession = class {
|
|
|
12615
13150
|
ctx;
|
|
12616
13151
|
server;
|
|
12617
13152
|
restart;
|
|
13153
|
+
entryIds;
|
|
12618
13154
|
snapshots;
|
|
12619
13155
|
activeSnapshotBatch;
|
|
12620
13156
|
adapter;
|
|
@@ -12627,10 +13163,11 @@ var StatefulHmrSession = class {
|
|
|
12627
13163
|
sourceChangeListener = (file, dirtyReasonSummary) => {
|
|
12628
13164
|
this.handleSourceUpdate(file, dirtyReasonSummary);
|
|
12629
13165
|
};
|
|
12630
|
-
constructor(ctx, server, restart, snapshots) {
|
|
13166
|
+
constructor(ctx, server, restart, entryIds, snapshots, devWatchOptions) {
|
|
12631
13167
|
this.ctx = ctx;
|
|
12632
13168
|
this.server = server;
|
|
12633
13169
|
this.restart = restart;
|
|
13170
|
+
this.entryIds = entryIds;
|
|
12634
13171
|
this.snapshots = snapshots;
|
|
12635
13172
|
this.replaceSnapshotAssets(snapshots.initial);
|
|
12636
13173
|
this.transport = new StatefulHmrTransport(server, async (buildId, source) => {
|
|
@@ -12648,7 +13185,7 @@ var StatefulHmrSession = class {
|
|
|
12648
13185
|
onOutput: (output) => this.handleOutput(output),
|
|
12649
13186
|
onPatch: (files, output) => this.handlePatch(files, output),
|
|
12650
13187
|
waitForInitialBundle: () => this.waitForInitialBundle()
|
|
12651
|
-
});
|
|
13188
|
+
}, devWatchOptions);
|
|
12652
13189
|
this.snapshotScheduler = new StatefulHmrSnapshotScheduler({
|
|
12653
13190
|
execute: (batch) => this.executeSnapshotBatch(batch),
|
|
12654
13191
|
onError: (error) => this.server.config.logger.error("[weapp-vite] stateful HMR snapshot refresh failed", { error: error instanceof Error ? error : new Error(String(error)) })
|
|
@@ -12716,7 +13253,7 @@ var StatefulHmrSession = class {
|
|
|
12716
13253
|
}
|
|
12717
13254
|
handlePatch(files, output) {
|
|
12718
13255
|
if (output.type === "Noop") return false;
|
|
12719
|
-
if (!isSafeJavaScriptPatch(files, output, this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary, this.
|
|
13256
|
+
if (!isSafeJavaScriptPatch(files, output, this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary, this.entryIds, this.server.config.root)) {
|
|
12720
13257
|
if (shouldRestartStatefulHmrServer(files, this.ctx.configService?.configFileDependencies)) this.requestServerRestart();
|
|
12721
13258
|
else if (this.snapshotScheduler.isPending() || files.length > 0 && files.every(isStatefulHmrAssetFile) || shouldUseStatefulHmrSnapshotOnly(this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary ?? [])) {
|
|
12722
13259
|
if (!this.snapshotScheduler.isPending()) this.requestSnapshotRefresh(files);
|
|
@@ -12908,33 +13445,6 @@ function formatStatefulHmrError(error) {
|
|
|
12908
13445
|
return String(error);
|
|
12909
13446
|
}
|
|
12910
13447
|
//#endregion
|
|
12911
|
-
//#region src/runtime/watch/options.ts
|
|
12912
|
-
function resolvePollingWatchConfig(configService) {
|
|
12913
|
-
const buildWatch = configService.inlineConfig?.build?.watch;
|
|
12914
|
-
const chokidar = buildWatch && typeof buildWatch === "object" && "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
12915
|
-
const serverWatch = configService.inlineConfig?.server?.watch;
|
|
12916
|
-
const envUsePolling = process.env.CHOKIDAR_USEPOLLING;
|
|
12917
|
-
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
12918
|
-
const envBinaryInterval = process.env.CHOKIDAR_BINARY_INTERVAL;
|
|
12919
|
-
const usePollingCandidate = chokidar?.usePolling ?? serverWatch?.usePolling ?? (envUsePolling === "1" || envUsePolling === "true" ? true : envUsePolling === "0" || envUsePolling === "false" ? false : void 0);
|
|
12920
|
-
const intervalCandidate = chokidar?.interval ?? serverWatch?.interval ?? (envInterval ? Number(envInterval) : void 0);
|
|
12921
|
-
const binaryIntervalCandidate = chokidar?.binaryInterval ?? serverWatch?.binaryInterval ?? (envBinaryInterval ? Number(envBinaryInterval) : void 0);
|
|
12922
|
-
return {
|
|
12923
|
-
usePolling: typeof usePollingCandidate === "boolean" ? usePollingCandidate : void 0,
|
|
12924
|
-
interval: typeof intervalCandidate === "number" && Number.isFinite(intervalCandidate) ? intervalCandidate : void 0,
|
|
12925
|
-
binaryInterval: typeof binaryIntervalCandidate === "number" && Number.isFinite(binaryIntervalCandidate) ? binaryIntervalCandidate : void 0
|
|
12926
|
-
};
|
|
12927
|
-
}
|
|
12928
|
-
function createSidecarWatchOptions(configService, input) {
|
|
12929
|
-
const polling = resolvePollingWatchConfig(configService);
|
|
12930
|
-
return {
|
|
12931
|
-
...input,
|
|
12932
|
-
...polling.usePolling !== void 0 ? { usePolling: polling.usePolling } : {},
|
|
12933
|
-
...typeof polling.interval === "number" ? { interval: polling.interval } : {},
|
|
12934
|
-
...typeof polling.binaryInterval === "number" ? { binaryInterval: polling.binaryInterval } : {}
|
|
12935
|
-
};
|
|
12936
|
-
}
|
|
12937
|
-
//#endregion
|
|
12938
13448
|
//#region src/plugins/autoImport.ts
|
|
12939
13449
|
const LEADING_DOT_SLASH_RE$2 = /^\.\//;
|
|
12940
13450
|
const LEADING_SLASHES_RE$2 = /^\/+/;
|
|
@@ -13682,6 +14192,12 @@ function transformWxsCode(code, options) {
|
|
|
13682
14192
|
const expression = p.node.expression;
|
|
13683
14193
|
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();
|
|
13684
14194
|
},
|
|
14195
|
+
AssignmentExpression: { enter(p) {
|
|
14196
|
+
if (!preserveEsmExports || p.node.operator !== "=") return;
|
|
14197
|
+
const left = p.node.left;
|
|
14198
|
+
if (!t.isMemberExpression(left) || left.computed || !t.isIdentifier(left.object, { name: "module" }) || !t.isIdentifier(left.property, { name: "exports" }) || !p.parentPath.isExpressionStatement()) return;
|
|
14199
|
+
p.parentPath.replaceWith(t.exportDefaultDeclaration(p.node.right));
|
|
14200
|
+
} },
|
|
13685
14201
|
NewExpression: { enter(p) {
|
|
13686
14202
|
const node = p.node;
|
|
13687
14203
|
if (t.isIdentifier(node.callee, { name: "RegExp" })) p.replaceWith(t.callExpression(t.identifier("getRegExp"), node.arguments));
|
|
@@ -15295,8 +15811,50 @@ function createSnapshotSidecarIgnoredMatcher(ctx) {
|
|
|
15295
15811
|
}
|
|
15296
15812
|
function createBuildService(ctx) {
|
|
15297
15813
|
let lastHmrSlowTipProfileCount = 0;
|
|
15298
|
-
let
|
|
15814
|
+
let devHmrDecision;
|
|
15299
15815
|
let devHmrRuntimeNoticeLogged = false;
|
|
15816
|
+
let skylineHmrFallbackApplied = false;
|
|
15817
|
+
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";
|
|
15818
|
+
function logHmrRuntimeDecision(decision) {
|
|
15819
|
+
if (devHmrRuntimeNoticeLogged) return;
|
|
15820
|
+
devHmrRuntimeNoticeLogged = true;
|
|
15821
|
+
for (const message of formatHmrRuntimeStartupMessages(decision)) logger_default.info(message);
|
|
15822
|
+
}
|
|
15823
|
+
async function applySkylineHmrFallback(options) {
|
|
15824
|
+
const configService = ctx.configService;
|
|
15825
|
+
if (!configService) return false;
|
|
15826
|
+
const currentDecision = devHmrDecision ?? resolveHmrRuntimeDecision({
|
|
15827
|
+
platform: configService.platform,
|
|
15828
|
+
configured: options.configured,
|
|
15829
|
+
compileHotReLoad: options.compileHotReLoad
|
|
15830
|
+
});
|
|
15831
|
+
if (skylineHmrFallbackApplied || currentDecision.runtime === "classic" && options.compileHotReLoad !== true) return false;
|
|
15832
|
+
skylineHmrFallbackApplied = true;
|
|
15833
|
+
devHmrDecision = resolveHmrRuntimeDecision({
|
|
15834
|
+
platform: configService.platform,
|
|
15835
|
+
configured: currentDecision.configured,
|
|
15836
|
+
compileHotReLoad: options.compileHotReLoad,
|
|
15837
|
+
skyline: true
|
|
15838
|
+
});
|
|
15839
|
+
const detectedFiles = options.files.slice(0, 3).join("、");
|
|
15840
|
+
const detectedSuffix = detectedFiles ? `(${detectedFiles})` : "";
|
|
15841
|
+
const privateConfigPath = configService.projectPrivateConfigPath;
|
|
15842
|
+
const privateConfigDisplay = privateConfigPath ? configService.relativeCwd(privateConfigPath) : "project.private.config.json";
|
|
15843
|
+
if (options.compileHotReLoad === true) try {
|
|
15844
|
+
if (!privateConfigPath) throw new Error("无法解析项目私有配置路径");
|
|
15845
|
+
await disableProjectPrivateConfigHotReload(privateConfigPath);
|
|
15846
|
+
const privateConfig = configService.projectPrivateConfig;
|
|
15847
|
+
privateConfig.setting = {
|
|
15848
|
+
...privateConfig.setting && typeof privateConfig.setting === "object" && !Array.isArray(privateConfig.setting) ? privateConfig.setting : {},
|
|
15849
|
+
compileHotReLoad: false
|
|
15850
|
+
};
|
|
15851
|
+
logger_default.warn(`检测到 Skyline 渲染配置${detectedSuffix}。微信开发者工具暂不支持 Skyline 热重载,已将 ${privateConfigDisplay} 中的 setting.compileHotReLoad 设为 false,并降级为 classic。详情:${SKYLINE_HMR_COMPATIBILITY_URL}`);
|
|
15852
|
+
} catch (error) {
|
|
15853
|
+
logger_default.warn(`检测到 Skyline 渲染配置${detectedSuffix}。已降级为 classic,但无法自动关闭 ${privateConfigDisplay} 中的 setting.compileHotReLoad:${error instanceof Error ? error.message : String(error)}。请手动关闭微信开发者工具“热重载”。详情:${SKYLINE_HMR_COMPATIBILITY_URL}`);
|
|
15854
|
+
}
|
|
15855
|
+
else logger_default.warn(`检测到 Skyline 渲染配置${detectedSuffix}。微信开发者工具暂不支持 Skyline 热重载,weapp.hmr.runtime="stateful-experimental" 已自动降级为 classic。详情:${SKYLINE_HMR_COMPATIBILITY_URL}`);
|
|
15856
|
+
return true;
|
|
15857
|
+
}
|
|
15300
15858
|
function createHmrProfileJsonSample(totalMs) {
|
|
15301
15859
|
const profile = ctx.runtimeState.build.hmr.profile;
|
|
15302
15860
|
const relativeFile = profile.file && ctx.configService ? ctx.configService.relativeCwd(profile.file) : void 0;
|
|
@@ -15857,31 +16415,47 @@ function createBuildService(ctx) {
|
|
|
15857
16415
|
if (process.env.NODE_ENV === void 0) process.env.NODE_ENV = "development";
|
|
15858
16416
|
debug$2?.(`[${target}] dev build watcher start`);
|
|
15859
16417
|
const { hasWorkersDir, workersDir } = checkWorkersOptions(target, configService, scanService);
|
|
15860
|
-
const createDevBuildOptions = () => appendHmrMetricsPlugin(applyTargetBuildOverride(configService.merge(void 0, createSharedBuildConfig(configService, scanService), resolveTargetBuildOverride(target)), target));
|
|
15861
|
-
let buildOptions = createDevBuildOptions();
|
|
15862
|
-
buildOptions.build = {
|
|
15863
|
-
...buildOptions.build ?? {},
|
|
15864
|
-
write: true
|
|
15865
|
-
};
|
|
15866
16418
|
const configuredHmrRuntime = configService.weappViteConfig.hmr?.runtime;
|
|
15867
16419
|
const compileHotReLoad = configService.projectPrivateConfig.setting?.compileHotReLoad;
|
|
15868
|
-
|
|
16420
|
+
devHmrDecision ??= resolveHmrRuntimeDecision({
|
|
15869
16421
|
platform: configService.platform,
|
|
15870
16422
|
configured: configuredHmrRuntime,
|
|
15871
16423
|
compileHotReLoad
|
|
15872
16424
|
});
|
|
15873
|
-
const
|
|
15874
|
-
|
|
15875
|
-
|
|
15876
|
-
|
|
15877
|
-
|
|
15878
|
-
|
|
15879
|
-
|
|
15880
|
-
|
|
15881
|
-
|
|
15882
|
-
|
|
15883
|
-
|
|
15884
|
-
|
|
16425
|
+
const createDevBuildOptions = () => {
|
|
16426
|
+
const options = applyTargetBuildOverride(configService.merge(void 0, createSharedBuildConfig(configService, scanService), resolveTargetBuildOverride(target)), target);
|
|
16427
|
+
if (target === "app" && devHmrDecision?.runtime === "classic") {
|
|
16428
|
+
let skylineFiles = [];
|
|
16429
|
+
options.plugins = [...options.plugins ?? [], {
|
|
16430
|
+
name: "weapp-vite:skyline-hmr-compatibility",
|
|
16431
|
+
enforce: "post",
|
|
16432
|
+
generateBundle(_options, bundle) {
|
|
16433
|
+
skylineFiles = findSkylineRendererFiles(Object.values(bundle));
|
|
16434
|
+
},
|
|
16435
|
+
writeBundle() {
|
|
16436
|
+
if (skylineFiles.length === 0) return;
|
|
16437
|
+
const detectedFiles = skylineFiles;
|
|
16438
|
+
skylineFiles = [];
|
|
16439
|
+
setTimeout(() => {
|
|
16440
|
+
applySkylineHmrFallback({
|
|
16441
|
+
compileHotReLoad,
|
|
16442
|
+
configured: devHmrDecision?.configured,
|
|
16443
|
+
files: detectedFiles
|
|
16444
|
+
});
|
|
16445
|
+
}, 0);
|
|
16446
|
+
}
|
|
16447
|
+
}];
|
|
16448
|
+
}
|
|
16449
|
+
return appendHmrMetricsPlugin(options);
|
|
16450
|
+
};
|
|
16451
|
+
let buildOptions = createDevBuildOptions();
|
|
16452
|
+
buildOptions.build = {
|
|
16453
|
+
...buildOptions.build ?? {},
|
|
16454
|
+
write: true
|
|
16455
|
+
};
|
|
16456
|
+
const hmrDecision = devHmrDecision;
|
|
16457
|
+
if (target === "app" && hmrDecision.runtime !== "stateful-experimental") logHmrRuntimeDecision(hmrDecision);
|
|
16458
|
+
if (target === "app" && hmrDecision.runtime === "stateful-experimental") try {
|
|
15885
16459
|
const snapshotBuildOptions = {
|
|
15886
16460
|
...buildOptions,
|
|
15887
16461
|
build: {
|
|
@@ -15891,6 +16465,21 @@ function createBuildService(ctx) {
|
|
|
15891
16465
|
}
|
|
15892
16466
|
};
|
|
15893
16467
|
const initialSnapshot = toStatefulHmrOutput(await build(snapshotBuildOptions));
|
|
16468
|
+
const initialEntryIds = new Set(ctx.runtimeState.build.hmr.resolvedEntryMap.keys());
|
|
16469
|
+
const skylineFiles = findSkylineRendererFiles(initialSnapshot);
|
|
16470
|
+
if (skylineFiles.length > 0) await applySkylineHmrFallback({
|
|
16471
|
+
compileHotReLoad,
|
|
16472
|
+
configured: hmrDecision.configured,
|
|
16473
|
+
files: skylineFiles
|
|
16474
|
+
});
|
|
16475
|
+
if (devHmrDecision?.runtime === "classic") {
|
|
16476
|
+
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
16477
|
+
await configService.load(configService.loadOptions);
|
|
16478
|
+
await scanService.loadAppEntry();
|
|
16479
|
+
scanService.loadSubPackages();
|
|
16480
|
+
return await runDev(target);
|
|
16481
|
+
}
|
|
16482
|
+
logHmrRuntimeDecision(hmrDecision);
|
|
15894
16483
|
await configService.load(configService.loadOptions);
|
|
15895
16484
|
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
15896
16485
|
await scanService.loadAppEntry();
|
|
@@ -15912,6 +16501,7 @@ function createBuildService(ctx) {
|
|
|
15912
16501
|
await runDev(target);
|
|
15913
16502
|
logger_default.success("微信状态保持 HMR 构建已完成完整重载。");
|
|
15914
16503
|
}, {
|
|
16504
|
+
entryIds: initialEntryIds,
|
|
15915
16505
|
initial: initialSnapshot,
|
|
15916
16506
|
rebuild: async (files) => {
|
|
15917
16507
|
for (const file of files) invalidateFileCache(file);
|
|
@@ -15940,10 +16530,14 @@ function createBuildService(ctx) {
|
|
|
15940
16530
|
watcherService.setRollupWatcher(watcher, "/");
|
|
15941
16531
|
return watcher;
|
|
15942
16532
|
} catch (error) {
|
|
15943
|
-
if (
|
|
15944
|
-
|
|
16533
|
+
if (hmrDecision.configured !== "auto" || !isStatefulHmrRuntimeCompatibilityError(error)) throw error;
|
|
16534
|
+
devHmrDecision = {
|
|
16535
|
+
configured: hmrDecision.configured,
|
|
16536
|
+
reason: "runtime-compatibility-fallback",
|
|
16537
|
+
runtime: "classic"
|
|
16538
|
+
};
|
|
15945
16539
|
logger_default.warn(`微信状态保持 HMR 运行时不可用,已自动降级为 classic:${error instanceof Error ? error.message : String(error)}`);
|
|
15946
|
-
logger_default.info(
|
|
16540
|
+
logger_default.info(formatHmrRuntimeStartupMessages(devHmrDecision)[0]);
|
|
15947
16541
|
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
15948
16542
|
await configService.load(configService.loadOptions);
|
|
15949
16543
|
await scanService.loadAppEntry();
|
|
@@ -17194,7 +17788,8 @@ function configureBuildAndPlugins(options) {
|
|
|
17194
17788
|
const rdTransform = rdOptions.transform ?? {};
|
|
17195
17789
|
if (!Object.prototype.hasOwnProperty.call(rdTransform, "tsconfig")) rdTransform.tsconfig = false;
|
|
17196
17790
|
rdOptions.transform = rdTransform;
|
|
17197
|
-
rdOptions.preserveEntrySignatures
|
|
17791
|
+
if (config.weapp?.chunks?.preserveModules?.length && (rdOptions.preserveEntrySignatures === void 0 || rdOptions.preserveEntrySignatures === "exports-only")) rdOptions.preserveEntrySignatures = "allow-extension";
|
|
17792
|
+
else rdOptions.preserveEntrySignatures ??= "exports-only";
|
|
17198
17793
|
if (Array.isArray(rdOptions.output)) rdOptions.output = rdOptions.output.map((output) => ({
|
|
17199
17794
|
...output,
|
|
17200
17795
|
format: jsFormat
|
|
@@ -18894,6 +19489,7 @@ function emitSfcJsonAsset(ctx, bundle, relativeBase, result, options) {
|
|
|
18894
19489
|
if (!nextConfig) return;
|
|
18895
19490
|
if (options.emitIfMissingOnly) {
|
|
18896
19491
|
if (!bundle[jsonFileName]) {
|
|
19492
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18897
19493
|
const nextSource = JSON.stringify(nextConfig, null, 2);
|
|
18898
19494
|
if (emittedAssetSourceCache.get(cacheKey) !== nextSource) {
|
|
18899
19495
|
ctx.emitFile({
|
|
@@ -18908,19 +19504,23 @@ function emitSfcJsonAsset(ctx, bundle, relativeBase, result, options) {
|
|
|
18908
19504
|
}
|
|
18909
19505
|
if (options.mergeExistingAsset && existing && existing.type === "asset") {
|
|
18910
19506
|
try {
|
|
18911
|
-
const
|
|
19507
|
+
const mergedConfig = mergeJson(JSON.parse(existing.source.toString()), nextConfig, "merge-existing");
|
|
19508
|
+
const merged = options.finalizeConfig?.(mergedConfig) ?? mergedConfig;
|
|
18912
19509
|
existing.source = JSON.stringify(merged, null, 2);
|
|
18913
19510
|
} catch {
|
|
19511
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18914
19512
|
existing.source = JSON.stringify(nextConfig, null, 2);
|
|
18915
19513
|
}
|
|
18916
19514
|
return;
|
|
18917
19515
|
}
|
|
18918
19516
|
if (existing && existing.type === "asset") {
|
|
19517
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18919
19518
|
const nextSource = JSON.stringify(nextConfig, null, 2);
|
|
18920
19519
|
if ((existing.source?.toString?.() ?? "") !== nextSource) existing.source = nextSource;
|
|
18921
19520
|
emittedAssetSourceCache.set(cacheKey, nextSource);
|
|
18922
19521
|
return;
|
|
18923
19522
|
}
|
|
19523
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18924
19524
|
const nextSource = JSON.stringify(nextConfig, null, 2);
|
|
18925
19525
|
if (emittedAssetSourceCache.get(cacheKey) === nextSource) return;
|
|
18926
19526
|
ctx.emitFile({
|
|
@@ -19718,7 +20318,7 @@ function stripQueryAndHash(value) {
|
|
|
19718
20318
|
}
|
|
19719
20319
|
function createPathMatcher(patterns, options) {
|
|
19720
20320
|
if (!patterns.length) return () => false;
|
|
19721
|
-
return
|
|
20321
|
+
return picomatch(patterns.map((pattern) => normalizePath$1(pattern)), options);
|
|
19722
20322
|
}
|
|
19723
20323
|
function createAssetPathVariants(file, roots) {
|
|
19724
20324
|
const variants = [file];
|
|
@@ -20457,15 +21057,26 @@ function createExtendedLibManager() {
|
|
|
20457
21057
|
};
|
|
20458
21058
|
}
|
|
20459
21059
|
//#endregion
|
|
21060
|
+
//#region src/runtime/appConfig.ts
|
|
21061
|
+
function finalizeAppConfigForBuild(config, options) {
|
|
21062
|
+
return applyBuildScopeToAppConfig(applyPreloadRulesToAppJson(normalizeAppJson(config), options.routeRules, options.platform), resolveBuildScope(options.buildScope));
|
|
21063
|
+
}
|
|
21064
|
+
//#endregion
|
|
20460
21065
|
//#region src/plugins/hooks/useLoadEntry/jsonEmit.ts
|
|
20461
21066
|
function createJsonEmitManager(configService) {
|
|
20462
21067
|
const map = /* @__PURE__ */ new Map();
|
|
20463
21068
|
function register(entry) {
|
|
20464
21069
|
if (!entry.jsonPath && !entry.fileName) return;
|
|
20465
21070
|
const fileName = entry.fileName ?? resolveRelativeJsonOutputFileName(configService, entry.jsonPath);
|
|
20466
|
-
const
|
|
21071
|
+
const shouldNormalizeAppJson = entry.type === "app" && fileName === "app.json";
|
|
21072
|
+
const weappViteConfig = configService.weappViteConfig ?? {};
|
|
21073
|
+
const normalizedEntry = shouldNormalizeAppJson ? {
|
|
20467
21074
|
...entry,
|
|
20468
|
-
json:
|
|
21075
|
+
json: finalizeAppConfigForBuild(entry.json, {
|
|
21076
|
+
buildScope: weappViteConfig.buildScope,
|
|
21077
|
+
platform: configService.platform,
|
|
21078
|
+
routeRules: weappViteConfig.routeRules
|
|
21079
|
+
})
|
|
20469
21080
|
} : entry;
|
|
20470
21081
|
map.set(fileName, {
|
|
20471
21082
|
fileName,
|
|
@@ -21279,7 +21890,7 @@ function resolveRouteRuleLayoutMeta(filename, configService) {
|
|
|
21279
21890
|
const routeCandidates = normalizePageRouteCandidates(filename, configService);
|
|
21280
21891
|
let matched;
|
|
21281
21892
|
for (const [pattern, rule] of Object.entries(routeRules)) {
|
|
21282
|
-
if (!routeCandidates.some((candidate) =>
|
|
21893
|
+
if (!routeCandidates.some((candidate) => picomatch(pattern)(candidate))) continue;
|
|
21283
21894
|
const normalizedMeta = normalizeRouteRuleLayoutMeta(rule?.appLayout);
|
|
21284
21895
|
const patternSegments = pattern.split("/").filter(Boolean);
|
|
21285
21896
|
const wildcardMatches = pattern.match(ROUTE_RULE_GLOB_TOKEN_RE) ?? [];
|
|
@@ -21534,6 +22145,7 @@ async function collectAppEntries(options) {
|
|
|
21534
22145
|
let pluginJsonPathForRegistration;
|
|
21535
22146
|
let pluginJsonForRegistration;
|
|
21536
22147
|
let pluginSignature;
|
|
22148
|
+
let appJson;
|
|
21537
22149
|
if (!isPluginBuild) {
|
|
21538
22150
|
extendedLibManager.syncFromAppJson(json);
|
|
21539
22151
|
await Promise.all([collectAppSideFiles(pluginCtx, id, json, jsonService, registerJsonAsset, existsCache, pathExistsTtlMs), collectMiniappConfigFile(pluginCtx, id, configService, jsonService, registerJsonAsset, existsCache, pathExistsTtlMs)]);
|
|
@@ -21555,6 +22167,7 @@ async function collectAppEntries(options) {
|
|
|
21555
22167
|
const pluginSignatureMatches = cached.pluginSignature === pluginSignature;
|
|
21556
22168
|
if (cached.appSignature === appSignature && pluginPathMatches && pluginSignatureMatches) return {
|
|
21557
22169
|
entries: cached.entries,
|
|
22170
|
+
appJson: cached.appJson,
|
|
21558
22171
|
pluginResolvedRecords: cached.pluginResolvedRecords,
|
|
21559
22172
|
pluginEntryTypes: cached.pluginEntryTypes,
|
|
21560
22173
|
pluginJsonPathForRegistration: cached.pluginJsonPathForRegistration,
|
|
@@ -21566,11 +22179,10 @@ async function collectAppEntries(options) {
|
|
|
21566
22179
|
};
|
|
21567
22180
|
}
|
|
21568
22181
|
if (!isPluginBuild) {
|
|
21569
|
-
|
|
21570
|
-
|
|
21571
|
-
|
|
21572
|
-
|
|
21573
|
-
type: "app"
|
|
22182
|
+
appJson = finalizeAppConfigForBuild(json, {
|
|
22183
|
+
buildScope: configService.weappViteConfig.buildScope,
|
|
22184
|
+
platform: configService.platform,
|
|
22185
|
+
routeRules: configService.weappViteConfig.routeRules
|
|
21574
22186
|
});
|
|
21575
22187
|
entries.push(...analyzeAppJson(appJson));
|
|
21576
22188
|
}
|
|
@@ -21600,6 +22212,7 @@ async function collectAppEntries(options) {
|
|
|
21600
22212
|
}
|
|
21601
22213
|
if (useCache && cache) cache.current = {
|
|
21602
22214
|
appSignature,
|
|
22215
|
+
appJson,
|
|
21603
22216
|
pluginSignature,
|
|
21604
22217
|
pluginJsonPath,
|
|
21605
22218
|
entries: [...entries],
|
|
@@ -21610,6 +22223,7 @@ async function collectAppEntries(options) {
|
|
|
21610
22223
|
};
|
|
21611
22224
|
return {
|
|
21612
22225
|
entries,
|
|
22226
|
+
appJson,
|
|
21613
22227
|
pluginResolvedRecords,
|
|
21614
22228
|
pluginEntryTypes,
|
|
21615
22229
|
pluginJsonPathForRegistration,
|
|
@@ -22423,7 +23037,7 @@ async function emitEntryOutput(options) {
|
|
|
22423
23037
|
}
|
|
22424
23038
|
}
|
|
22425
23039
|
if (!isPluginBuild || type !== "app") registerJsonAsset({
|
|
22426
|
-
jsonPath,
|
|
23040
|
+
jsonPath: type === "app" ? id : jsonPath,
|
|
22427
23041
|
json,
|
|
22428
23042
|
type
|
|
22429
23043
|
});
|
|
@@ -22774,6 +23388,7 @@ function createEntryLoader(options) {
|
|
|
22774
23388
|
extendedLibManager,
|
|
22775
23389
|
cache: appEntriesCache
|
|
22776
23390
|
});
|
|
23391
|
+
if (appResult.appJson) json = appResult.appJson;
|
|
22777
23392
|
autoRoutesSignature = configService.isDev ? ctx.autoRoutesService?.getSignature?.() : void 0;
|
|
22778
23393
|
entries.push(...appResult.entries);
|
|
22779
23394
|
const registerAppComponentEntry = (entry) => {
|
|
@@ -25303,9 +25918,11 @@ function invalidateSharedStyleCache() {
|
|
|
25303
25918
|
const styleMatcherCache = /* @__PURE__ */ new WeakMap();
|
|
25304
25919
|
function collectSharedStyleEntries(ctx, configService) {
|
|
25305
25920
|
const map = /* @__PURE__ */ new Map();
|
|
25921
|
+
const mainPackageEntries = ctx.scanService?.mainPackageStyleEntries;
|
|
25922
|
+
const currentRoot = configService.currentSubPackageRoot;
|
|
25923
|
+
if (!currentRoot && mainPackageEntries?.length) map.set("", mainPackageEntries);
|
|
25306
25924
|
const registry = ctx.scanService?.subPackageMap;
|
|
25307
25925
|
if (!registry?.size) return map;
|
|
25308
|
-
const currentRoot = configService.currentSubPackageRoot;
|
|
25309
25926
|
for (const [root, meta] of registry.entries()) {
|
|
25310
25927
|
if (!meta.styleEntries?.length) continue;
|
|
25311
25928
|
if (currentRoot && root !== currentRoot) continue;
|
|
@@ -25328,13 +25945,16 @@ function relativeToRoot(pathname, root) {
|
|
|
25328
25945
|
if (pathname === root) return "";
|
|
25329
25946
|
if (pathname.startsWith(`${root}/`)) return pathname.slice(root.length + 1);
|
|
25330
25947
|
}
|
|
25948
|
+
function isMainAppStyleFile(fileName) {
|
|
25949
|
+
return !fileName.includes("/") && path.posix.basename(fileName, path.posix.extname(fileName)) === "app";
|
|
25950
|
+
}
|
|
25331
25951
|
function getStyleMatcher(entry) {
|
|
25332
25952
|
const cached = styleMatcherCache.get(entry);
|
|
25333
25953
|
if (cached) return cached;
|
|
25334
25954
|
const includePatterns = entry.include?.length ? entry.include : ["**/*"];
|
|
25335
25955
|
const excludePatterns = entry.exclude?.length ? entry.exclude : void 0;
|
|
25336
|
-
const matcher = { include:
|
|
25337
|
-
if (excludePatterns?.length) matcher.exclude =
|
|
25956
|
+
const matcher = { include: picomatch(includePatterns, { dot: true }) };
|
|
25957
|
+
if (excludePatterns?.length) matcher.exclude = picomatch(excludePatterns, { dot: true });
|
|
25338
25958
|
styleMatcherCache.set(entry, matcher);
|
|
25339
25959
|
return matcher;
|
|
25340
25960
|
}
|
|
@@ -25354,11 +25974,15 @@ function findSharedStylesForModule(modulePath, fileName, sharedStyles) {
|
|
|
25354
25974
|
const matched = [];
|
|
25355
25975
|
for (const [root, entries] of sharedStyles.entries()) {
|
|
25356
25976
|
const normalizedRoot = normalizeRoot(root);
|
|
25357
|
-
if (!normalizedRoot) continue;
|
|
25977
|
+
if (root && !normalizedRoot) continue;
|
|
25978
|
+
if (!normalizedRoot && isMainAppStyleFile(sanitizedFile)) continue;
|
|
25358
25979
|
if (!isWithinRoot(sanitizedFile, normalizedRoot)) continue;
|
|
25359
25980
|
const relativeModule = relativeToRoot(sanitizedModule, normalizedRoot);
|
|
25360
25981
|
const relativeFile = relativeToRoot(sanitizedFile, normalizedRoot);
|
|
25361
|
-
for (const entry of entries)
|
|
25982
|
+
for (const entry of entries) {
|
|
25983
|
+
if (entry.inject === false) continue;
|
|
25984
|
+
if (matchesStyleEntry(entry, relativeModule, relativeFile)) matched.push(entry);
|
|
25985
|
+
}
|
|
25362
25986
|
}
|
|
25363
25987
|
return matched;
|
|
25364
25988
|
}
|
|
@@ -25634,9 +26258,10 @@ async function handleBundleEntry(ctx, bundle, bundleKey, asset, configService, s
|
|
|
25634
26258
|
const cssWithImports = injectSharedStyleImportsCached(processedCss, owner, fileName, sharedStyles, configService, sharedStyleImportCache);
|
|
25635
26259
|
emitCssAssetIfChanged(ctx, this, bundle, fileName, cssWithImports);
|
|
25636
26260
|
emitted.add(normalizedFileName);
|
|
26261
|
+
return normalizedFileName;
|
|
25637
26262
|
};
|
|
25638
|
-
const isFinalStyleAsset = bundleKey.endsWith(`.${configService.outputExtensions.wxss}`);
|
|
25639
26263
|
const isCssAsset = bundleKey.endsWith(".css");
|
|
26264
|
+
const isFinalStyleAsset = bundleKey.endsWith(`.${configService.outputExtensions.wxss}`) && (!isCssAsset || path.posix.basename(bundleKey, ".css") === "app");
|
|
25640
26265
|
const isSourceStyleAssetKey = isSourceStyleAsset(bundleKey);
|
|
25641
26266
|
if (isFinalStyleAsset) {
|
|
25642
26267
|
const absOriginal = resolveOriginalStylePath();
|
|
@@ -25676,10 +26301,11 @@ async function handleBundleEntry(ctx, bundle, bundleKey, asset, configService, s
|
|
|
25676
26301
|
delete bundle[bundleKey];
|
|
25677
26302
|
return;
|
|
25678
26303
|
}
|
|
25679
|
-
await Promise.all(Array.from(owners).map(async (owner) => {
|
|
25680
|
-
await emitStyleAssetForOwner(owner, resolveOriginalStylePath(), !isCssAsset);
|
|
26304
|
+
const emittedOwners = await Promise.all(Array.from(owners).map(async (owner) => {
|
|
26305
|
+
return await emitStyleAssetForOwner(owner, resolveOriginalStylePath(), !isCssAsset);
|
|
25681
26306
|
}));
|
|
25682
|
-
|
|
26307
|
+
const normalizedBundleKey = toPosixPath(bundleKey);
|
|
26308
|
+
if (!isCssAsset || !emittedOwners.includes(normalizedBundleKey)) delete bundle[bundleKey];
|
|
25683
26309
|
}
|
|
25684
26310
|
async function emitSharedStyleEntries(ctx, sharedStyles, emitted, configService, bundle, resolvedConfig) {
|
|
25685
26311
|
if (!sharedStyles.size) return;
|
|
@@ -28417,16 +29043,16 @@ function resolveEntryRecord(state, sourceId) {
|
|
|
28417
29043
|
const relativeBase = removeExtensionDeep(state.ctx.configService.relativeAbsoluteSrcRoot(sourceId));
|
|
28418
29044
|
return state.entriesMap.get(relativeBase) ?? state.entriesMap.get(removeExtensionDeep(sourceId));
|
|
28419
29045
|
}
|
|
28420
|
-
async function resolveLocalModule(
|
|
29046
|
+
async function resolveLocalModule(pluginContext, source, importer) {
|
|
28421
29047
|
const localBase = path.isAbsolute(source) ? source : source.startsWith("/") ? source : path.resolve(path.dirname(importer), source);
|
|
28422
|
-
const resolved = await
|
|
29048
|
+
const resolved = await pluginContext.resolve(localBase, importer);
|
|
28423
29049
|
if (resolved?.id) return normalizeFsResolvedId(resolved.id);
|
|
28424
29050
|
if (path.isAbsolute(localBase) && !path.extname(localBase)) {
|
|
28425
29051
|
const localEntry = (await findJsEntry(localBase)).path ?? await findVueEntry(localBase);
|
|
28426
|
-
if (localEntry) return normalizeFsResolvedId((await
|
|
29052
|
+
if (localEntry) return normalizeFsResolvedId((await pluginContext.resolve(localEntry, importer))?.id ?? localEntry);
|
|
28427
29053
|
}
|
|
28428
29054
|
}
|
|
28429
|
-
async function collectUsingComponentDependencies(state, ownerId, json) {
|
|
29055
|
+
async function collectUsingComponentDependencies(state, pluginContext, ownerId, json) {
|
|
28430
29056
|
if (!json || typeof json !== "object" || !("usingComponents" in json)) return [];
|
|
28431
29057
|
const usingComponents = json.usingComponents;
|
|
28432
29058
|
if (!usingComponents || typeof usingComponents !== "object" || Array.isArray(usingComponents)) return [];
|
|
@@ -28434,7 +29060,7 @@ async function collectUsingComponentDependencies(state, ownerId, json) {
|
|
|
28434
29060
|
for (const value of Object.values(usingComponents)) {
|
|
28435
29061
|
if (typeof value !== "string" || !value || value.includes("://")) continue;
|
|
28436
29062
|
const outputKey = removeExtensionDeep(value).replace(/^\/+/, "");
|
|
28437
|
-
const resolved = await resolveLocalModule(
|
|
29063
|
+
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);
|
|
28438
29064
|
if (resolved) dependencies.push({
|
|
28439
29065
|
kind: "using-component",
|
|
28440
29066
|
sourceId: resolved
|
|
@@ -28451,7 +29077,7 @@ function collectTemplateDependencies(state, templatePath) {
|
|
|
28451
29077
|
});
|
|
28452
29078
|
return dependencies;
|
|
28453
29079
|
}
|
|
28454
|
-
async function collectLogicalEntryDependencies(state, ownerId) {
|
|
29080
|
+
async function collectLogicalEntryDependencies(state, pluginContext, ownerId) {
|
|
28455
29081
|
const pendingDependencies = state.ctx.moduleGraphService.getEntryDependencies(ownerId);
|
|
28456
29082
|
const dependencies = [];
|
|
28457
29083
|
const addExistingDependency = async (kind, sourceId) => {
|
|
@@ -28476,7 +29102,7 @@ async function collectLogicalEntryDependencies(state, ownerId) {
|
|
|
28476
29102
|
await addExistingDependency("style", styleEntry.path);
|
|
28477
29103
|
if (templatePath) await state.ctx.wxmlService?.scan(templatePath);
|
|
28478
29104
|
dependencies.push(...collectTemplateDependencies(state, templatePath));
|
|
28479
|
-
dependencies.push(...await collectUsingComponentDependencies(state, ownerId, entry?.json));
|
|
29105
|
+
dependencies.push(...await collectUsingComponentDependencies(state, pluginContext, ownerId, entry?.json));
|
|
28480
29106
|
for (const kind of [
|
|
28481
29107
|
"json",
|
|
28482
29108
|
"jsx",
|
|
@@ -28500,7 +29126,7 @@ function createLogicalEntryResolveHook(state) {
|
|
|
28500
29126
|
if (!sidecarSource) return null;
|
|
28501
29127
|
state.ctx.moduleGraphService.bindPluginContext(this);
|
|
28502
29128
|
return {
|
|
28503
|
-
id: (await
|
|
29129
|
+
id: (await this.resolve(id, importer, { skipSelf: true }))?.id ?? createSidecarSourceSpecifier(sidecarSource.ownerId, sidecarSource.sourceId, sidecarSource.kind),
|
|
28504
29130
|
moduleSideEffects: "no-treeshake"
|
|
28505
29131
|
};
|
|
28506
29132
|
};
|
|
@@ -28512,7 +29138,7 @@ function createLogicalEntryLoadHook(state) {
|
|
|
28512
29138
|
state.ctx.moduleGraphService.bindPluginContext(this);
|
|
28513
29139
|
if (state.ctx.configService.isDev) await state.loadEntry.call(this, logicalEntry.sourceId, logicalEntry.type === "app" ? "app" : logicalEntry.type === "page" ? "page" : "component");
|
|
28514
29140
|
return {
|
|
28515
|
-
code: createLogicalEntryModuleCode(logicalEntry, await collectLogicalEntryDependencies(state, logicalEntry.sourceId)),
|
|
29141
|
+
code: createLogicalEntryModuleCode(logicalEntry, await collectLogicalEntryDependencies(state, this, logicalEntry.sourceId)),
|
|
28516
29142
|
moduleSideEffects: "no-treeshake"
|
|
28517
29143
|
};
|
|
28518
29144
|
}
|
|
@@ -30121,6 +30747,11 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
30121
30747
|
const style = await processVueResultStyle(sfcStyle, options.configService);
|
|
30122
30748
|
emitSfcStyleIfMissing(options.pluginCtx, options.bundle, options.relativeBase, style, options.outputExtensions.wxss, isAppVue ? { updateExisting: false } : void 0);
|
|
30123
30749
|
}
|
|
30750
|
+
const finalizeJsonConfig = isAppVue ? (config) => finalizeAppConfigForBuild(config, {
|
|
30751
|
+
buildScope: options.configService.weappViteConfig?.buildScope,
|
|
30752
|
+
platform: options.configService.platform,
|
|
30753
|
+
routeRules: options.configService.weappViteConfig?.routeRules
|
|
30754
|
+
}) : void 0;
|
|
30124
30755
|
if (options.result.config || shouldEmitComponentJson) emitSharedVueEntryJsonAsset({
|
|
30125
30756
|
bundle: options.bundle,
|
|
30126
30757
|
pluginCtx: options.pluginCtx,
|
|
@@ -30133,6 +30764,7 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
30133
30764
|
mergeExistingAsset: shouldMergeJsonAsset,
|
|
30134
30765
|
mergeStrategy: jsonConfig?.mergeStrategy,
|
|
30135
30766
|
defaults: jsonConfig?.defaults?.[jsonKind],
|
|
30767
|
+
...finalizeJsonConfig ? { finalizeConfig: finalizeJsonConfig } : {},
|
|
30136
30768
|
kind: jsonKind,
|
|
30137
30769
|
extension: options.jsonExtension
|
|
30138
30770
|
}
|
|
@@ -30147,8 +30779,8 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
30147
30779
|
function hasVueExtension(id) {
|
|
30148
30780
|
return Boolean(id?.endsWith(".vue"));
|
|
30149
30781
|
}
|
|
30150
|
-
function getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration = false) {
|
|
30151
|
-
return `${vuePath}::${isPage ? "page" : "component"}::${isApp ? "app" : "entry"}::${delegatesComponentRegistration ? "logical-registration" : "module-registration"}`;
|
|
30782
|
+
function getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration = false, emitResolvedComponentEntries = true) {
|
|
30783
|
+
return `${vuePath}::${isPage ? "page" : "component"}::${isApp ? "app" : "entry"}::${delegatesComponentRegistration ? "logical-registration" : "module-registration"}::${emitResolvedComponentEntries ? "emit-entries" : "resolve-only"}`;
|
|
30152
30784
|
}
|
|
30153
30785
|
function shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, configService) {
|
|
30154
30786
|
return !isPage && !isApp && !configService.weappLibConfig?.enabled && !ctx.moduleGraphService?.isLogicalLayoutEntry?.(vuePath);
|
|
@@ -30178,6 +30810,24 @@ function resolveVueTemplatePlatformOptions(options) {
|
|
|
30178
30810
|
function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state, delegatesComponentRegistration) {
|
|
30179
30811
|
const importerBaseName = removeExtensionDeep(vuePath);
|
|
30180
30812
|
const autoImportResolveCache = /* @__PURE__ */ new Map();
|
|
30813
|
+
const resolveUsingComponentPath = createUsingComponentPathResolver(pluginCtx, configService, state.reExportResolutionCache);
|
|
30814
|
+
const externalComponentEntryMap = ctx.runtimeState?.build?.hmr?.externalComponentEntryMap;
|
|
30815
|
+
const registerResolvedComponentEntry = externalComponentEntryMap ? async (...args) => {
|
|
30816
|
+
const [importSource, importerFilename, info] = args;
|
|
30817
|
+
const resolved = await resolveUsingComponentPath(importSource, importerFilename, info);
|
|
30818
|
+
if (typeof resolved !== "string" && resolved?.from && resolved.resolvedId) {
|
|
30819
|
+
const outputKey = removeExtensionDeep(resolved.from).replace(/^\/+/, "");
|
|
30820
|
+
const isNewEntry = externalComponentEntryMap.get(outputKey) !== resolved.resolvedId;
|
|
30821
|
+
externalComponentEntryMap.set(outputKey, resolved.resolvedId);
|
|
30822
|
+
if (isNewEntry && state.emitResolvedComponentEntries !== false && typeof pluginCtx.emitFile === "function") pluginCtx.emitFile({
|
|
30823
|
+
type: "chunk",
|
|
30824
|
+
id: createLogicalEntryId(resolved.resolvedId, "component"),
|
|
30825
|
+
fileName: resolveRelativeOutputFileNameWithExtension(configService, resolved.resolvedId, ".js"),
|
|
30826
|
+
preserveSignature: "exports-only"
|
|
30827
|
+
});
|
|
30828
|
+
}
|
|
30829
|
+
return resolved;
|
|
30830
|
+
} : resolveUsingComponentPath;
|
|
30181
30831
|
const scopedSlotsCompiler = configService.weappViteConfig?.vue?.template?.scopedSlotsCompiler ?? "auto";
|
|
30182
30832
|
const scopedSlotsRequireProps = configService.weappViteConfig?.vue?.template?.scopedSlotsRequireProps ?? false;
|
|
30183
30833
|
const slotSingleRootNoWrapper = configService.weappViteConfig?.vue?.template?.slotSingleRootNoWrapper ?? false;
|
|
@@ -30273,7 +30923,7 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
30273
30923
|
autoUsingComponents: {
|
|
30274
30924
|
enabled: true,
|
|
30275
30925
|
warn: (message) => logger_default.warn(message),
|
|
30276
|
-
resolveUsingComponentPath:
|
|
30926
|
+
resolveUsingComponentPath: registerResolvedComponentEntry
|
|
30277
30927
|
},
|
|
30278
30928
|
autoImportTags: {
|
|
30279
30929
|
enabled: true,
|
|
@@ -30331,7 +30981,7 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
30331
30981
|
}
|
|
30332
30982
|
function createCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state) {
|
|
30333
30983
|
const delegatesComponentRegistration = shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, configService);
|
|
30334
|
-
const cacheKey = getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration);
|
|
30984
|
+
const cacheKey = getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration, state.emitResolvedComponentEntries !== false);
|
|
30335
30985
|
const cached = state.compileOptionsCache?.get(cacheKey);
|
|
30336
30986
|
if (cached) return cached;
|
|
30337
30987
|
const created = buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state, delegatesComponentRegistration);
|
|
@@ -31416,7 +32066,8 @@ async function emitCompiledVueEntryAssets(bundle, state, filename, cached) {
|
|
|
31416
32066
|
reExportResolutionCache,
|
|
31417
32067
|
classStyleRuntimeWarned,
|
|
31418
32068
|
compileOptionsCache,
|
|
31419
|
-
componentMetaCache
|
|
32069
|
+
componentMetaCache,
|
|
32070
|
+
emitResolvedComponentEntries: false
|
|
31420
32071
|
};
|
|
31421
32072
|
const { outputExtensions, templateExtension, jsonExtension, scriptExtension, scriptModuleExtension, platformAssetOptions } = resolveVueBundleAssetContext(configService);
|
|
31422
32073
|
const emitState = await resolveCompiledEntryEmitState({
|
|
@@ -31537,7 +32188,8 @@ async function emitFallbackPageAssets(bundle, state, options) {
|
|
|
31537
32188
|
reExportResolutionCache,
|
|
31538
32189
|
classStyleRuntimeWarned,
|
|
31539
32190
|
compileOptionsCache,
|
|
31540
|
-
componentMetaCache
|
|
32191
|
+
componentMetaCache,
|
|
32192
|
+
emitResolvedComponentEntries: false
|
|
31541
32193
|
};
|
|
31542
32194
|
const { outputExtensions, templateExtension, styleExtension, jsonExtension, scriptModuleExtension, platformAssetOptions } = resolveVueBundleAssetContext(configService);
|
|
31543
32195
|
const collectedEntries = await collectFallbackPageEntryIds(configService, scanService);
|
|
@@ -32615,6 +33267,7 @@ function normalizeInlineConfigAfterDefu(inline, options) {
|
|
|
32615
33267
|
...userRolldownOptions?.output ?? {}
|
|
32616
33268
|
}
|
|
32617
33269
|
};
|
|
33270
|
+
if (ctx.configService) normalizePreserveModulesRolldownOptions(ctx.configService, mergedRolldownOptions);
|
|
32618
33271
|
const defaultTsconfig = resolveDefaultRolldownTsconfig(cwd, configFilePath);
|
|
32619
33272
|
const resolveOptions = mergedRolldownOptions.resolve;
|
|
32620
33273
|
if (defaultTsconfig) {
|
|
@@ -32791,6 +33444,7 @@ function mergeWeb(options, ...configs) {
|
|
|
32791
33444
|
}
|
|
32792
33445
|
});
|
|
32793
33446
|
stripRollupOptions(inline);
|
|
33447
|
+
if (options.configService) normalizePreserveModulesRolldownOptions(options.configService, inline.build?.rolldownOptions ?? (inline.build.rolldownOptions = {}));
|
|
32794
33448
|
inline.root = web.root;
|
|
32795
33449
|
inline.configFile = false;
|
|
32796
33450
|
const runtimeProvider = resolveRuntimeProvider("web", "web");
|
|
@@ -32848,6 +33502,7 @@ function mergeWorkers(options, ...configs) {
|
|
|
32848
33502
|
});
|
|
32849
33503
|
applyWeappViteHostMeta(inline, "miniprogram", platform);
|
|
32850
33504
|
stripRollupOptions(inline);
|
|
33505
|
+
normalizePreserveModulesRolldownOptions(ctx.configService, inline.build?.rolldownOptions ?? (inline.build.rolldownOptions = {}));
|
|
32851
33506
|
injectBuiltinAliases(inline);
|
|
32852
33507
|
return inline;
|
|
32853
33508
|
}
|
|
@@ -32861,6 +33516,7 @@ function mergeWorkers(options, ...configs) {
|
|
|
32861
33516
|
applyWeappViteHostMeta(inlineConfig, "miniprogram", platform);
|
|
32862
33517
|
stripRollupOptions(inlineConfig);
|
|
32863
33518
|
inlineConfig.logLevel = "info";
|
|
33519
|
+
normalizePreserveModulesRolldownOptions(ctx.configService, inlineConfig.build?.rolldownOptions ?? (inlineConfig.build.rolldownOptions = {}));
|
|
32864
33520
|
injectBuiltinAliases(inlineConfig);
|
|
32865
33521
|
return inlineConfig;
|
|
32866
33522
|
}
|
|
@@ -32919,6 +33575,7 @@ function createMergeFactories(options) {
|
|
|
32919
33575
|
const subPackageRoots = Object.keys(configService.weappViteConfig?.subPackages ?? {});
|
|
32920
33576
|
const sharedOutput = configService.options.chunksConfigured ? createSharedBuildOutput(configService, () => subPackageRoots, { runtime: "web" }) : void 0;
|
|
32921
33577
|
return backend.driver.mergeConfig({ merge: (...backendConfigs) => mergeWeb({
|
|
33578
|
+
configService,
|
|
32922
33579
|
config: currentOptions.config,
|
|
32923
33580
|
web: currentOptions.weappWeb,
|
|
32924
33581
|
mode: currentOptions.mode,
|
|
@@ -33531,7 +34188,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
33531
34188
|
const { path: appEntryPath } = appEntry;
|
|
33532
34189
|
let configFromVue;
|
|
33533
34190
|
if (!appConfigFile && vueAppPath) {
|
|
33534
|
-
const { extractConfigFromVue } = await import("./file-
|
|
34191
|
+
const { extractConfigFromVue } = await import("./file-C-jjrMsb.mjs");
|
|
33535
34192
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
33536
34193
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
33537
34194
|
}
|
|
@@ -33553,9 +34210,12 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
33553
34210
|
if (configFromVue) config = configFromVue;
|
|
33554
34211
|
else config = await ctx.jsonService.read(appConfigFile);
|
|
33555
34212
|
await applyAutoRoutesToAppConfigIfNeeded(ctx, config);
|
|
33556
|
-
|
|
34213
|
+
config = finalizeAppConfigForBuild(config, {
|
|
34214
|
+
buildScope: ctx.configService.weappViteConfig.buildScope,
|
|
34215
|
+
platform: ctx.configService.platform,
|
|
34216
|
+
routeRules: ctx.configService.weappViteConfig.routeRules
|
|
34217
|
+
});
|
|
33557
34218
|
if (isObject(config)) {
|
|
33558
|
-
normalizeAppConfigSubPackages(config);
|
|
33559
34219
|
const resolvedAppEntry = {
|
|
33560
34220
|
path: appEntryPath || vueAppPath,
|
|
33561
34221
|
preludePath: appPreludePath,
|
|
@@ -33630,6 +34290,7 @@ function coerceStyleConfig(entry) {
|
|
|
33630
34290
|
return {
|
|
33631
34291
|
source,
|
|
33632
34292
|
scope: "all",
|
|
34293
|
+
inject: true,
|
|
33633
34294
|
explicitScope: false
|
|
33634
34295
|
};
|
|
33635
34296
|
}
|
|
@@ -33642,6 +34303,7 @@ function coerceStyleConfig(entry) {
|
|
|
33642
34303
|
scope: hasExplicitScope ? coerceScope(entry.scope) : "all",
|
|
33643
34304
|
include: entry.include,
|
|
33644
34305
|
exclude: entry.exclude,
|
|
34306
|
+
inject: entry.inject !== false,
|
|
33645
34307
|
explicitScope: hasExplicitScope
|
|
33646
34308
|
};
|
|
33647
34309
|
}
|
|
@@ -33688,11 +34350,12 @@ function resolveExcludePatterns(descriptor, normalizedRoot) {
|
|
|
33688
34350
|
}
|
|
33689
34351
|
//#endregion
|
|
33690
34352
|
//#region src/runtime/scanPlugin/styleEntries/entries.ts
|
|
33691
|
-
function createStyleEntryDedupeKey(posixOutput, include, exclude) {
|
|
34353
|
+
function createStyleEntryDedupeKey(posixOutput, include, exclude, inject) {
|
|
33692
34354
|
return JSON.stringify({
|
|
33693
34355
|
file: posixOutput,
|
|
33694
34356
|
include,
|
|
33695
|
-
exclude
|
|
34357
|
+
exclude,
|
|
34358
|
+
inject
|
|
33696
34359
|
});
|
|
33697
34360
|
}
|
|
33698
34361
|
function resolveDefaultScopedStyleEntryCandidates(absoluteSrcRoot, root) {
|
|
@@ -33704,7 +34367,7 @@ function resolveDefaultScopedStyleEntryCandidates(absoluteSrcRoot, root) {
|
|
|
33704
34367
|
absolutePath: path.resolve(absoluteSubRoot, `${base}${ext}`)
|
|
33705
34368
|
})));
|
|
33706
34369
|
}
|
|
33707
|
-
function addStyleEntry(descriptor, absolutePath, posixOutput,
|
|
34370
|
+
function addStyleEntry(descriptor, absolutePath, posixOutput, normalizedRoot, warningPrefix, dedupe, normalized) {
|
|
33708
34371
|
const include = resolveIncludePatterns({
|
|
33709
34372
|
scope: descriptor.scope,
|
|
33710
34373
|
include: descriptor.include
|
|
@@ -33713,10 +34376,10 @@ function addStyleEntry(descriptor, absolutePath, posixOutput, root, normalizedRo
|
|
|
33713
34376
|
include.sort();
|
|
33714
34377
|
exclude.sort();
|
|
33715
34378
|
if (!include.length) {
|
|
33716
|
-
logger_default.warn(
|
|
34379
|
+
logger_default.warn(`${warningPrefix}样式入口 \`${descriptor.source}\` 缺少有效作用范围,已按 \`**/*\` 处理。`);
|
|
33717
34380
|
include.push("**/*");
|
|
33718
34381
|
}
|
|
33719
|
-
const key = createStyleEntryDedupeKey(posixOutput, include, exclude);
|
|
34382
|
+
const key = createStyleEntryDedupeKey(posixOutput, include, exclude, descriptor.inject);
|
|
33720
34383
|
if (dedupe.has(key)) return;
|
|
33721
34384
|
dedupe.add(key);
|
|
33722
34385
|
normalized.push({
|
|
@@ -33726,7 +34389,8 @@ function addStyleEntry(descriptor, absolutePath, posixOutput, root, normalizedRo
|
|
|
33726
34389
|
inputExtension: path.extname(absolutePath).toLowerCase(),
|
|
33727
34390
|
scope: descriptor.scope,
|
|
33728
34391
|
include,
|
|
33729
|
-
exclude
|
|
34392
|
+
exclude,
|
|
34393
|
+
inject: descriptor.inject
|
|
33730
34394
|
});
|
|
33731
34395
|
}
|
|
33732
34396
|
function appendDefaultScopedStyleEntries(root, normalizedRoot, service, dedupe, normalized) {
|
|
@@ -33743,13 +34407,14 @@ function appendDefaultScopedStyleEntries(root, normalizedRoot, service, dedupe,
|
|
|
33743
34407
|
scope: candidate.scope,
|
|
33744
34408
|
include: void 0,
|
|
33745
34409
|
exclude: void 0,
|
|
34410
|
+
inject: true,
|
|
33746
34411
|
explicitScope: true
|
|
33747
34412
|
};
|
|
33748
34413
|
const outputAbsolutePath = changeFileExtension(candidate.absolutePath, service.outputExtensions.wxss);
|
|
33749
34414
|
const outputRelativePath = service.relativeOutputPath(outputAbsolutePath);
|
|
33750
34415
|
if (!outputRelativePath) continue;
|
|
33751
34416
|
const posixOutput = toPosixPath(outputRelativePath);
|
|
33752
|
-
addStyleEntry(descriptor, candidate.absolutePath, posixOutput,
|
|
34417
|
+
addStyleEntry(descriptor, candidate.absolutePath, posixOutput, normalizedRoot, `[分包] 分包 ${root} `, dedupe, normalized);
|
|
33753
34418
|
matchedCurrentBase = true;
|
|
33754
34419
|
}
|
|
33755
34420
|
}
|
|
@@ -33802,11 +34467,9 @@ function resolveStyleEntryScope(descriptor, posixOutput, normalizedRoot) {
|
|
|
33802
34467
|
if (descriptor.explicitScope) return descriptor.scope;
|
|
33803
34468
|
return inferScopeFromRelativePath(getRelativePathWithinSubPackage(posixOutput, normalizedRoot)) ?? descriptor.scope;
|
|
33804
34469
|
}
|
|
33805
|
-
function
|
|
34470
|
+
function normalizeStyleEntries(styles, root, configService, options) {
|
|
33806
34471
|
const service = configService;
|
|
33807
34472
|
if (!service) return;
|
|
33808
|
-
const root = subPackage.root?.trim();
|
|
33809
|
-
if (!root) return;
|
|
33810
34473
|
const list = styles === void 0 ? [] : Array.isArray(styles) ? styles : [styles];
|
|
33811
34474
|
const normalizedRoot = normalizeRoot(root);
|
|
33812
34475
|
const normalized = [];
|
|
@@ -33814,37 +34477,52 @@ function normalizeSubPackageStyleEntries(styles, subPackage, configService) {
|
|
|
33814
34477
|
for (const entry of list) {
|
|
33815
34478
|
const descriptor = coerceStyleConfig(entry);
|
|
33816
34479
|
if (!descriptor) {
|
|
33817
|
-
logger_default.warn(
|
|
34480
|
+
logger_default.warn(`${options.warningPrefix}样式入口配置无效,已忽略。`);
|
|
33818
34481
|
continue;
|
|
33819
34482
|
}
|
|
33820
34483
|
const absolutePath = resolveStyleEntryAbsolutePath(descriptor.source, root, service);
|
|
33821
34484
|
if (!absolutePath) {
|
|
33822
|
-
logger_default.warn(
|
|
34485
|
+
logger_default.warn(`${options.warningPrefix}样式入口 \`${descriptor.source}\` 解析失败,已忽略。`);
|
|
33823
34486
|
continue;
|
|
33824
34487
|
}
|
|
33825
34488
|
if (!fs.existsSync(absolutePath)) {
|
|
33826
|
-
logger_default.warn(
|
|
34489
|
+
logger_default.warn(`${options.warningPrefix}样式入口 \`${descriptor.source}\` 对应文件不存在,已忽略。`);
|
|
33827
34490
|
continue;
|
|
33828
34491
|
}
|
|
33829
34492
|
if (!isSupportedSharedStyleExtension(absolutePath)) {
|
|
33830
|
-
logger_default.warn(
|
|
34493
|
+
logger_default.warn(`${options.warningPrefix}样式入口 \`${descriptor.source}\` 当前仅支持以下格式:${SUPPORTED_SHARED_STYLE_EXTENSIONS.join(", ")},已忽略。`);
|
|
33831
34494
|
continue;
|
|
33832
34495
|
}
|
|
33833
34496
|
const outputAbsolutePath = changeFileExtension(absolutePath, service.outputExtensions.wxss);
|
|
33834
34497
|
const outputRelativePath = service.relativeOutputPath(outputAbsolutePath);
|
|
33835
34498
|
if (!outputRelativePath) {
|
|
33836
|
-
logger_default.warn(
|
|
34499
|
+
logger_default.warn(`${options.warningPrefix}样式入口 \`${descriptor.source}\` 不在项目源码目录内,已忽略。`);
|
|
33837
34500
|
continue;
|
|
33838
34501
|
}
|
|
33839
34502
|
const posixOutput = toPosixPath(outputRelativePath);
|
|
33840
34503
|
addStyleEntry({
|
|
33841
34504
|
...descriptor,
|
|
33842
34505
|
scope: resolveStyleEntryScope(descriptor, posixOutput, normalizedRoot)
|
|
33843
|
-
}, absolutePath, posixOutput,
|
|
34506
|
+
}, absolutePath, posixOutput, normalizedRoot, options.warningPrefix, dedupe, normalized);
|
|
33844
34507
|
}
|
|
33845
|
-
appendDefaultScopedStyleEntries(root, normalizedRoot, service, dedupe, normalized);
|
|
34508
|
+
if (options.appendDefaultEntries) appendDefaultScopedStyleEntries(root, normalizedRoot, service, dedupe, normalized);
|
|
33846
34509
|
return normalized.length ? normalized : void 0;
|
|
33847
34510
|
}
|
|
34511
|
+
function normalizeSubPackageStyleEntries(styles, subPackage, configService) {
|
|
34512
|
+
const root = subPackage.root?.trim();
|
|
34513
|
+
if (!root) return;
|
|
34514
|
+
return normalizeStyleEntries(styles, root, configService, {
|
|
34515
|
+
warningPrefix: `[分包] 分包 ${root} `,
|
|
34516
|
+
appendDefaultEntries: true
|
|
34517
|
+
});
|
|
34518
|
+
}
|
|
34519
|
+
function normalizeMainPackageStyleEntries(styles, configService) {
|
|
34520
|
+
if (styles === void 0) return;
|
|
34521
|
+
return normalizeStyleEntries(styles, "", configService, {
|
|
34522
|
+
warningPrefix: "[样式] 主包 ",
|
|
34523
|
+
appendDefaultEntries: false
|
|
34524
|
+
});
|
|
34525
|
+
}
|
|
33848
34526
|
//#endregion
|
|
33849
34527
|
//#region src/runtime/scanPlugin/subpackages.ts
|
|
33850
34528
|
function resolveSubPackageEntries(subPackage) {
|
|
@@ -33865,6 +34543,7 @@ function loadSubPackages(ctx) {
|
|
|
33865
34543
|
if (scanState.isDirty || subPackageMap.size === 0) {
|
|
33866
34544
|
subPackageMap.clear();
|
|
33867
34545
|
independentSubPackageMap.clear();
|
|
34546
|
+
scanState.mainPackageStyleEntries = normalizeMainPackageStyleEntries(configService.weappViteConfig?.styles, configService);
|
|
33868
34547
|
if (scanState.isDirty) independentDirtyRoots.clear();
|
|
33869
34548
|
if (json) {
|
|
33870
34549
|
const independentSubPackages = [...json.subPackages ?? [], ...json.subpackages ?? []];
|
|
@@ -33923,6 +34602,9 @@ function createScanService(ctx) {
|
|
|
33923
34602
|
set pluginJsonPath(value) {
|
|
33924
34603
|
scanState.pluginJsonPath = value;
|
|
33925
34604
|
},
|
|
34605
|
+
get mainPackageStyleEntries() {
|
|
34606
|
+
return scanState.mainPackageStyleEntries;
|
|
34607
|
+
},
|
|
33926
34608
|
subPackageMap,
|
|
33927
34609
|
independentSubPackageMap,
|
|
33928
34610
|
async loadAppEntry() {
|
|
@@ -33944,6 +34626,7 @@ function createScanService(ctx) {
|
|
|
33944
34626
|
markDirty() {
|
|
33945
34627
|
scanState.isDirty = true;
|
|
33946
34628
|
scanState.appEntry = void 0;
|
|
34629
|
+
scanState.mainPackageStyleEntries = void 0;
|
|
33947
34630
|
scanState.pluginJson = void 0;
|
|
33948
34631
|
scanState.pluginJsonPath = void 0;
|
|
33949
34632
|
},
|
|
@@ -34509,4 +35192,4 @@ async function createCompilerContext(options) {
|
|
|
34509
35192
|
return ctx;
|
|
34510
35193
|
}
|
|
34511
35194
|
//#endregion
|
|
34512
|
-
export {
|
|
35195
|
+
export { shouldPassPlatformArgToIdeOpen as A, findPreloadRuleKey as C, parseCommentJson as D, loadViteConfigFile as E, createCjsConfigLoadError as O, collectPreloadPages as S, suggestPreloadRules 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, isPathInside as j, getDefaultIdeProjectRoot 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, resolvePreloadPackageIdentifier as w, getProjectConfigFileName as x, resolveWeappConfigFile as y };
|