weapp-vite 6.22.0 → 6.23.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/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +195 -62
- package/dist/{config-6l-p3o-C.d.mts → config-qh0O73A5.d.mts} +36 -1
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-PBWMhrli.mjs → createContext-RnHhe84f.mjs} +313 -75
- package/dist/docs/glass-easel.md +23 -0
- package/dist/docs/index.md +8 -6
- package/dist/{file-D0n-Q1ra.mjs → file-Cr034LIZ.mjs} +1 -1
- package/dist/file-DWR7zIBT.mjs +2 -0
- package/dist/getInstance-BjUP-8qc.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/test.mjs +1 -1
- package/dist/types.d.mts +2 -2
- package/package.json +17 -17
- package/dist/file-DPQbjCzZ.mjs +0 -2
- package/dist/getInstance-DxCSOpxw.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-Cr034LIZ.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";
|
|
@@ -8,9 +8,9 @@ import { APP_PRELUDE_CHUNK_MARKER, APP_PRELUDE_GUARD_KEY, APP_PRELUDE_REQUIRE_MA
|
|
|
8
8
|
import path, { posix } from "pathe";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import path$1, { normalize, relative, win32 } from "node:path";
|
|
11
|
-
import { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, addExtension, defu, escapeStringRegexp, get, getDefaultMiniProgramPlatform, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, isEmptyObject, isObject, normalizeMiniProgramPlatform, removeExtension, removeExtensionDeep, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle } from "@weapp-core/shared";
|
|
11
|
+
import { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, addExtension, defu, escapeStringRegexp, escapeWxmlAttribute, escapeWxmlText, get, getDefaultMiniProgramPlatform, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, isEmptyObject, isObject, normalizeMiniProgramPlatform, removeExtension, removeExtensionDeep, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle } from "@weapp-core/shared";
|
|
12
12
|
import { fs as fs$1 } from "@weapp-core/shared/fs";
|
|
13
|
-
import { BABEL_TS_MODULE_PARSER_OPTIONS, analyzeScript, analyzeScripts, collectComponentPropsFromCode, collectRequireTokens, collectScriptSetupImportsFromCode, generate, mayContainPlatformApiIdentifierByText, mayContainStaticRequireLiteral, parse, parseJsLikeWithEngine, platformApiIdentifiers } from "@weapp-vite/ast";
|
|
13
|
+
import { BABEL_TS_MODULE_PARSER_OPTIONS, analyzeScript as analyzeScript$1, analyzeScripts, collectComponentPropsFromCode, collectRequireTokens, collectScriptSetupImportsFromCode, generate, mayContainPlatformApiIdentifierByText, mayContainStaticRequireLiteral, parse, parseJsLikeWithEngine, platformApiIdentifiers } from "@weapp-vite/ast";
|
|
14
14
|
import { collectOnPageScrollPerformanceWarnings } from "@weapp-vite/ast/operations/onPageScroll";
|
|
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";
|
|
@@ -7965,6 +7965,47 @@ function resolveNpmStrategyMode(ctx) {
|
|
|
7965
7965
|
return resolveNpmStrategy(ctx);
|
|
7966
7966
|
}
|
|
7967
7967
|
//#endregion
|
|
7968
|
+
//#region src/runtime/watch/options.ts
|
|
7969
|
+
/**
|
|
7970
|
+
* 解析主 watcher 与 sidecar watcher 共享的轮询配置。
|
|
7971
|
+
*/
|
|
7972
|
+
function resolvePollingWatchOptions(configService) {
|
|
7973
|
+
const buildWatch = configService.inlineConfig?.build?.watch;
|
|
7974
|
+
const chokidar = buildWatch && typeof buildWatch === "object" && "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
7975
|
+
const serverWatch = configService.inlineConfig?.server?.watch;
|
|
7976
|
+
const envUsePolling = process.env.CHOKIDAR_USEPOLLING;
|
|
7977
|
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
7978
|
+
const envBinaryInterval = process.env.CHOKIDAR_BINARY_INTERVAL;
|
|
7979
|
+
const usePollingCandidate = chokidar?.usePolling ?? serverWatch?.usePolling ?? (envUsePolling === "1" || envUsePolling === "true" ? true : envUsePolling === "0" || envUsePolling === "false" ? false : void 0);
|
|
7980
|
+
const intervalCandidate = chokidar?.interval ?? serverWatch?.interval ?? (envInterval ? Number(envInterval) : void 0);
|
|
7981
|
+
const binaryIntervalCandidate = chokidar?.binaryInterval ?? serverWatch?.binaryInterval ?? (envBinaryInterval ? Number(envBinaryInterval) : void 0);
|
|
7982
|
+
return {
|
|
7983
|
+
usePolling: typeof usePollingCandidate === "boolean" ? usePollingCandidate : void 0,
|
|
7984
|
+
interval: typeof intervalCandidate === "number" && Number.isFinite(intervalCandidate) ? intervalCandidate : void 0,
|
|
7985
|
+
binaryInterval: typeof binaryIntervalCandidate === "number" && Number.isFinite(binaryIntervalCandidate) ? binaryIntervalCandidate : void 0
|
|
7986
|
+
};
|
|
7987
|
+
}
|
|
7988
|
+
function createSidecarWatchOptions(configService, input) {
|
|
7989
|
+
const polling = resolvePollingWatchOptions(configService);
|
|
7990
|
+
return {
|
|
7991
|
+
...input,
|
|
7992
|
+
...polling.usePolling !== void 0 ? { usePolling: polling.usePolling } : {},
|
|
7993
|
+
...typeof polling.interval === "number" ? { interval: polling.interval } : {},
|
|
7994
|
+
...typeof polling.binaryInterval === "number" ? { binaryInterval: polling.binaryInterval } : {}
|
|
7995
|
+
};
|
|
7996
|
+
}
|
|
7997
|
+
/**
|
|
7998
|
+
* 合并用户配置并排除 Vite 开发服务器不应监听的构建输出目录。
|
|
7999
|
+
*/
|
|
8000
|
+
function createViteWatchIgnored(root, outDir, ignored) {
|
|
8001
|
+
const normalizedRoot = normalizeFsResolvedId(root);
|
|
8002
|
+
const normalizedOutDir = normalizeFsResolvedId(path.isAbsolute(outDir) ? outDir : path.resolve(root, outDir));
|
|
8003
|
+
return [...ignored === void 0 ? [] : Array.isArray(ignored) ? ignored : [ignored], (id) => {
|
|
8004
|
+
const normalizedId = normalizeFsResolvedId(path.isAbsolute(id) ? id : path.resolve(normalizedRoot, id));
|
|
8005
|
+
return isPathInside(normalizedOutDir, normalizedId);
|
|
8006
|
+
}];
|
|
8007
|
+
}
|
|
8008
|
+
//#endregion
|
|
7968
8009
|
//#region src/moduleGraph/logicalEntry.ts
|
|
7969
8010
|
function createLogicalEntryModuleCode(entry, dependencies) {
|
|
7970
8011
|
const source = JSON.stringify(entry.sourceId);
|
|
@@ -8075,6 +8116,9 @@ function createProviderPlugin(ctx, config, onChange) {
|
|
|
8075
8116
|
};
|
|
8076
8117
|
}
|
|
8077
8118
|
async function createDevModuleGraphProvider(ctx, buildConfig, onChange) {
|
|
8119
|
+
const configService = ctx.configService;
|
|
8120
|
+
const userWatch = buildConfig.server?.watch;
|
|
8121
|
+
const ignored = configService?.outDir ? createViteWatchIgnored(buildConfig.root ?? configService.cwd, configService.outDir, userWatch?.ignored) : userWatch?.ignored;
|
|
8078
8122
|
const server = await createServer({
|
|
8079
8123
|
...buildConfig,
|
|
8080
8124
|
appType: "custom",
|
|
@@ -8084,7 +8128,11 @@ async function createDevModuleGraphProvider(ctx, buildConfig, onChange) {
|
|
|
8084
8128
|
server: {
|
|
8085
8129
|
...buildConfig.server ?? {},
|
|
8086
8130
|
hmr: true,
|
|
8087
|
-
middlewareMode: true
|
|
8131
|
+
middlewareMode: true,
|
|
8132
|
+
watch: {
|
|
8133
|
+
...userWatch ?? {},
|
|
8134
|
+
...ignored !== void 0 ? { ignored } : {}
|
|
8135
|
+
}
|
|
8088
8136
|
},
|
|
8089
8137
|
build: {
|
|
8090
8138
|
...buildConfig.build ?? {},
|
|
@@ -9222,6 +9270,12 @@ function createRuntimeState() {
|
|
|
9222
9270
|
const emptyAutoRoutesSnapshot = createEmptyAutoRoutesSnapshot();
|
|
9223
9271
|
const emptyAutoRoutesArtifacts = createAutoRoutesArtifacts(emptyAutoRoutesSnapshot);
|
|
9224
9272
|
return {
|
|
9273
|
+
glassEasel: {
|
|
9274
|
+
detected: false,
|
|
9275
|
+
diagnostics: /* @__PURE__ */ new Map(),
|
|
9276
|
+
warnedDiagnostics: /* @__PURE__ */ new Set(),
|
|
9277
|
+
silent: false
|
|
9278
|
+
},
|
|
9225
9279
|
autoRoutes: {
|
|
9226
9280
|
routes: emptyAutoRoutesSnapshot,
|
|
9227
9281
|
serialized: emptyAutoRoutesArtifacts.serialized,
|
|
@@ -9337,6 +9391,10 @@ function createRuntimeState() {
|
|
|
9337
9391
|
//#region src/runtime/resetRuntimeState.ts
|
|
9338
9392
|
function resetRuntimeStateForFreshBuild(runtimeState) {
|
|
9339
9393
|
const fresh = createRuntimeState();
|
|
9394
|
+
runtimeState.glassEasel.detected = false;
|
|
9395
|
+
runtimeState.glassEasel.diagnostics.clear();
|
|
9396
|
+
runtimeState.glassEasel.warnedDiagnostics.clear();
|
|
9397
|
+
runtimeState.glassEasel.silent = false;
|
|
9340
9398
|
const autoRoutes = runtimeState.autoRoutes;
|
|
9341
9399
|
autoRoutes.routes = fresh.autoRoutes.routes;
|
|
9342
9400
|
autoRoutes.serialized = fresh.autoRoutes.serialized;
|
|
@@ -11993,12 +12051,6 @@ const EVENT_NAMES = {
|
|
|
11993
12051
|
};
|
|
11994
12052
|
const EVENT_PROP_RE = /^on[A-Z]/;
|
|
11995
12053
|
const IDENTIFIER_RE$1 = /^[A-Z_$][\w$]*$/i;
|
|
11996
|
-
function escapeAttribute(value) {
|
|
11997
|
-
return value.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<");
|
|
11998
|
-
}
|
|
11999
|
-
function escapeText(value) {
|
|
12000
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
12001
|
-
}
|
|
12002
12054
|
function normalizeJsxText(value) {
|
|
12003
12055
|
return value.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).join(" ");
|
|
12004
12056
|
}
|
|
@@ -12069,13 +12121,13 @@ function compileAttributes(element, slot, bindingFields, tagKind) {
|
|
|
12069
12121
|
if (name === "style" && t.isObjectExpression(expression)) {
|
|
12070
12122
|
const style = compileStaticStyle(expression);
|
|
12071
12123
|
if (style !== void 0) {
|
|
12072
|
-
output.push(`style="${
|
|
12124
|
+
output.push(`style="${escapeWxmlAttribute(style)}"`);
|
|
12073
12125
|
continue;
|
|
12074
12126
|
}
|
|
12075
12127
|
}
|
|
12076
12128
|
const staticValue = readStaticPrimitive(expression);
|
|
12077
12129
|
if (staticValue !== void 0) {
|
|
12078
|
-
output.push(`${outputName}="${
|
|
12130
|
+
output.push(`${outputName}="${escapeWxmlAttribute(String(staticValue))}"`);
|
|
12079
12131
|
continue;
|
|
12080
12132
|
}
|
|
12081
12133
|
bindingFields.add(name);
|
|
@@ -12089,13 +12141,13 @@ function isDynamicTextExpression(node) {
|
|
|
12089
12141
|
}
|
|
12090
12142
|
function compileStaticChildren(children, context) {
|
|
12091
12143
|
return children.map((child) => {
|
|
12092
|
-
if (t.isJSXText(child)) return
|
|
12144
|
+
if (t.isJSXText(child)) return escapeWxmlText(normalizeJsxText(child.value));
|
|
12093
12145
|
if (t.isJSXElement(child)) return compileStaticElement(child, context);
|
|
12094
12146
|
if (t.isJSXFragment(child)) return compileStaticFragment(child, context);
|
|
12095
12147
|
if (t.isJSXExpressionContainer(child)) {
|
|
12096
12148
|
if (t.isJSXEmptyExpression(child.expression)) return "";
|
|
12097
12149
|
const value = readStaticPrimitive(child.expression);
|
|
12098
|
-
if (value !== void 0) return
|
|
12150
|
+
if (value !== void 0) return escapeWxmlText(String(value));
|
|
12099
12151
|
throw new Error("static template 的容器节点暂不支持动态结构表达式");
|
|
12100
12152
|
}
|
|
12101
12153
|
return "";
|
|
@@ -12405,36 +12457,6 @@ function createReactPlugin(ctx) {
|
|
|
12405
12457
|
}];
|
|
12406
12458
|
}
|
|
12407
12459
|
//#endregion
|
|
12408
|
-
//#region src/runtime/watch/options.ts
|
|
12409
|
-
/**
|
|
12410
|
-
* 解析主 watcher 与 sidecar watcher 共享的轮询配置。
|
|
12411
|
-
*/
|
|
12412
|
-
function resolvePollingWatchOptions(configService) {
|
|
12413
|
-
const buildWatch = configService.inlineConfig?.build?.watch;
|
|
12414
|
-
const chokidar = buildWatch && typeof buildWatch === "object" && "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
12415
|
-
const serverWatch = configService.inlineConfig?.server?.watch;
|
|
12416
|
-
const envUsePolling = process.env.CHOKIDAR_USEPOLLING;
|
|
12417
|
-
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
12418
|
-
const envBinaryInterval = process.env.CHOKIDAR_BINARY_INTERVAL;
|
|
12419
|
-
const usePollingCandidate = chokidar?.usePolling ?? serverWatch?.usePolling ?? (envUsePolling === "1" || envUsePolling === "true" ? true : envUsePolling === "0" || envUsePolling === "false" ? false : void 0);
|
|
12420
|
-
const intervalCandidate = chokidar?.interval ?? serverWatch?.interval ?? (envInterval ? Number(envInterval) : void 0);
|
|
12421
|
-
const binaryIntervalCandidate = chokidar?.binaryInterval ?? serverWatch?.binaryInterval ?? (envBinaryInterval ? Number(envBinaryInterval) : void 0);
|
|
12422
|
-
return {
|
|
12423
|
-
usePolling: typeof usePollingCandidate === "boolean" ? usePollingCandidate : void 0,
|
|
12424
|
-
interval: typeof intervalCandidate === "number" && Number.isFinite(intervalCandidate) ? intervalCandidate : void 0,
|
|
12425
|
-
binaryInterval: typeof binaryIntervalCandidate === "number" && Number.isFinite(binaryIntervalCandidate) ? binaryIntervalCandidate : void 0
|
|
12426
|
-
};
|
|
12427
|
-
}
|
|
12428
|
-
function createSidecarWatchOptions(configService, input) {
|
|
12429
|
-
const polling = resolvePollingWatchOptions(configService);
|
|
12430
|
-
return {
|
|
12431
|
-
...input,
|
|
12432
|
-
...polling.usePolling !== void 0 ? { usePolling: polling.usePolling } : {},
|
|
12433
|
-
...typeof polling.interval === "number" ? { interval: polling.interval } : {},
|
|
12434
|
-
...typeof polling.binaryInterval === "number" ? { binaryInterval: polling.binaryInterval } : {}
|
|
12435
|
-
};
|
|
12436
|
-
}
|
|
12437
|
-
//#endregion
|
|
12438
12460
|
//#region src/runtime/statefulHmr/outputWriter.ts
|
|
12439
12461
|
/**
|
|
12440
12462
|
* @description 通过独立的 Vite write 阶段持久化 DevEngine 已生成的文件,不重新解析业务源码。
|
|
@@ -13122,7 +13144,7 @@ async function runStatefulHmrDev(ctx, buildOptions, restart, snapshots) {
|
|
|
13122
13144
|
port: 0,
|
|
13123
13145
|
watch: {
|
|
13124
13146
|
...buildOptions.server?.watch ?? {},
|
|
13125
|
-
ignored:
|
|
13147
|
+
ignored: createViteWatchIgnored(buildOptions.root ?? configService.cwd, configService.outDir, buildOptions.server?.watch?.ignored)
|
|
13126
13148
|
}
|
|
13127
13149
|
},
|
|
13128
13150
|
build: {
|
|
@@ -13142,14 +13164,6 @@ async function runStatefulHmrDev(ctx, buildOptions, restart, snapshots) {
|
|
|
13142
13164
|
throw error;
|
|
13143
13165
|
}
|
|
13144
13166
|
}
|
|
13145
|
-
function createStatefulHmrWatchIgnored(root, outDir, ignored) {
|
|
13146
|
-
const normalizedRoot = normalizeFsResolvedId(root);
|
|
13147
|
-
const normalizedOutDir = normalizeFsResolvedId(path.isAbsolute(outDir) ? outDir : path.resolve(root, outDir));
|
|
13148
|
-
return [...ignored === void 0 ? [] : Array.isArray(ignored) ? ignored : [ignored], (id) => {
|
|
13149
|
-
const normalizedId = normalizeFsResolvedId(path.isAbsolute(id) ? id : path.resolve(normalizedRoot, id));
|
|
13150
|
-
return isPathInside(normalizedOutDir, normalizedId);
|
|
13151
|
-
}];
|
|
13152
|
-
}
|
|
13153
13167
|
var StatefulHmrSession = class {
|
|
13154
13168
|
ctx;
|
|
13155
13169
|
server;
|
|
@@ -14560,6 +14574,8 @@ const SCRIPT_MODULE_IMPORT_RE = /\.(?:wxs|sjs)(?:\.[jt]s)?$/i;
|
|
|
14560
14574
|
const COMMENT_IFDEF_RE = /#ifdef\s+(\w+)/;
|
|
14561
14575
|
const COMMENT_ENDIF_RE = /#endif/;
|
|
14562
14576
|
const MP_DIRECTIVE_NAME_RE = /^([a-z]+):(if|elif|else|for|for-item|for-index|key)$/;
|
|
14577
|
+
const LEGACY_WEAPP_DIRECTIVE_NAME_RE = /^wx-(if|for)$/;
|
|
14578
|
+
const GLASS_EASEL_ESCAPE_RE = /\\["']/;
|
|
14563
14579
|
const SUPPORTED_MP_DIRECTIVE_PREFIXES = new Set(getSupportedMiniProgramDirectivePrefixes());
|
|
14564
14580
|
function toKebabCaseTagName(tagName) {
|
|
14565
14581
|
return tagName.replace(TAG_NAME_LOWER_TO_UPPER_RE, "$1-$2").replace(TAG_NAME_MULTI_UPPER_RE, "$1-$2").toLowerCase();
|
|
@@ -14589,14 +14605,19 @@ function parseWxml(options) {
|
|
|
14589
14605
|
const templateImportNormalizeTokens = [];
|
|
14590
14606
|
const eventTokens = [];
|
|
14591
14607
|
const directiveTokens = [];
|
|
14608
|
+
const glassEaselFindings = [];
|
|
14592
14609
|
const tagNameTokens = [];
|
|
14593
14610
|
const tagStack = [];
|
|
14611
|
+
const loopStack = [];
|
|
14612
|
+
let loopDepth = 0;
|
|
14613
|
+
let currentHasLoopDirective = false;
|
|
14594
14614
|
const parser = new Parser({
|
|
14595
14615
|
onopentagname(name) {
|
|
14596
14616
|
tagStack.push(name);
|
|
14597
14617
|
currentTagName = name;
|
|
14598
14618
|
importAttrs = getScriptModuleImportAttrs(currentTagName) ?? getTemplateImportAttrs(currentTagName);
|
|
14599
14619
|
tagStartIndex = parser.startIndex;
|
|
14620
|
+
currentHasLoopDirective = false;
|
|
14600
14621
|
if (normalizeComponentTagName && shouldNormalizeTagName(name)) {
|
|
14601
14622
|
const normalized = toKebabCaseTagName(name);
|
|
14602
14623
|
if (normalized !== name) tagNameTokens.push({
|
|
@@ -14613,6 +14634,31 @@ function parseWxml(options) {
|
|
|
14613
14634
|
},
|
|
14614
14635
|
onattribute(name, value, quote) {
|
|
14615
14636
|
attrs[name] = value;
|
|
14637
|
+
const legacyDirectiveMatch = LEGACY_WEAPP_DIRECTIVE_NAME_RE.exec(name);
|
|
14638
|
+
if (legacyDirectiveMatch) {
|
|
14639
|
+
const start = parser.startIndex;
|
|
14640
|
+
const end = start + name.length;
|
|
14641
|
+
directiveTokens.push({
|
|
14642
|
+
start,
|
|
14643
|
+
end,
|
|
14644
|
+
value: `${directivePrefix}:${legacyDirectiveMatch[1]}`
|
|
14645
|
+
});
|
|
14646
|
+
glassEaselFindings.push({
|
|
14647
|
+
code: "GE002",
|
|
14648
|
+
severity: "warning",
|
|
14649
|
+
message: `${name} 不受 glass-easel 支持,已安全归一化为 ${directivePrefix}:${legacyDirectiveMatch[1]}。`,
|
|
14650
|
+
start,
|
|
14651
|
+
normalized: true
|
|
14652
|
+
});
|
|
14653
|
+
}
|
|
14654
|
+
if (name === "wx:for" || name === "wx-for" || name === "let:for") currentHasLoopDirective = true;
|
|
14655
|
+
const rawAttribute = source.slice(parser.startIndex, parser.endIndex + 1);
|
|
14656
|
+
if (GLASS_EASEL_ESCAPE_RE.test(rawAttribute)) glassEaselFindings.push({
|
|
14657
|
+
code: "GE004",
|
|
14658
|
+
severity: "error",
|
|
14659
|
+
message: "属性仍使用反斜杠转义引号,请改用 "、' 或调整属性外层引号。",
|
|
14660
|
+
start: parser.startIndex
|
|
14661
|
+
});
|
|
14616
14662
|
if (!currentTagName || !isScriptModuleTagName(currentTagName)) templateTokens.push({
|
|
14617
14663
|
start: parser.startIndex,
|
|
14618
14664
|
end: parser.endIndex + 1,
|
|
@@ -14678,12 +14724,21 @@ function parseWxml(options) {
|
|
|
14678
14724
|
});
|
|
14679
14725
|
},
|
|
14680
14726
|
onopentag(name, attributes) {
|
|
14727
|
+
if (name === "include" && loopDepth > 0) glassEaselFindings.push({
|
|
14728
|
+
code: "GE003",
|
|
14729
|
+
severity: "error",
|
|
14730
|
+
message: "wx:for 作用域内的 <include> 无法向 glass-easel 传递循环变量,请改用 <template>。",
|
|
14731
|
+
start: tagStartIndex
|
|
14732
|
+
});
|
|
14733
|
+
loopStack.push(currentHasLoopDirective);
|
|
14734
|
+
if (currentHasLoopDirective) loopDepth += 1;
|
|
14681
14735
|
if (isScriptModuleTagName(name)) scriptModules.push({
|
|
14682
14736
|
attrs: attributes,
|
|
14683
14737
|
tagName: name
|
|
14684
14738
|
});
|
|
14685
14739
|
},
|
|
14686
14740
|
onclosetag(name) {
|
|
14741
|
+
if (loopStack.pop()) loopDepth -= 1;
|
|
14687
14742
|
currentTagName = tagStack.pop();
|
|
14688
14743
|
if (currentTagName) {
|
|
14689
14744
|
const componentName = normalizeComponentTagName && shouldNormalizeTagName(currentTagName) ? toKebabCaseTagName(currentTagName) : currentTagName;
|
|
@@ -14778,6 +14833,7 @@ function parseWxml(options) {
|
|
|
14778
14833
|
eventTokens,
|
|
14779
14834
|
directiveTokens,
|
|
14780
14835
|
tagNameTokens,
|
|
14836
|
+
glassEaselFindings,
|
|
14781
14837
|
code: source
|
|
14782
14838
|
} };
|
|
14783
14839
|
}
|
|
@@ -18687,6 +18743,28 @@ async function copyEsModuleDirectoryForAlipay(sourceRoot, targetRoot) {
|
|
|
18687
18743
|
return true;
|
|
18688
18744
|
}
|
|
18689
18745
|
//#endregion
|
|
18746
|
+
//#region src/runtime/npmPlugin/builder/packageFiles.ts
|
|
18747
|
+
function normalizePattern$1(pattern) {
|
|
18748
|
+
return pattern.replaceAll("\\", "/");
|
|
18749
|
+
}
|
|
18750
|
+
function createNpmPackageFileMatcher(config) {
|
|
18751
|
+
const include = config?.include?.length ? picomatch(config.include.map(normalizePattern$1), { dot: true }) : () => true;
|
|
18752
|
+
const exclude = config?.exclude?.length ? picomatch(config.exclude.map(normalizePattern$1), { dot: true }) : () => false;
|
|
18753
|
+
return (relativePath) => {
|
|
18754
|
+
const normalizedPath = normalizePattern$1(relativePath);
|
|
18755
|
+
return include(normalizedPath) && !exclude(normalizedPath);
|
|
18756
|
+
};
|
|
18757
|
+
}
|
|
18758
|
+
function createNpmPackageCopyFilter(sourceRoot, config) {
|
|
18759
|
+
if (!config?.include?.length && !config?.exclude?.length) return;
|
|
18760
|
+
const matches = createNpmPackageFileMatcher(config);
|
|
18761
|
+
return async (sourcePath) => {
|
|
18762
|
+
const relativePath = path.relative(sourceRoot, sourcePath);
|
|
18763
|
+
if (!relativePath) return true;
|
|
18764
|
+
return (await fs$1.stat(sourcePath)).isDirectory() || matches(relativePath);
|
|
18765
|
+
};
|
|
18766
|
+
}
|
|
18767
|
+
//#endregion
|
|
18690
18768
|
//#region src/runtime/npmPlugin/builder/packageBuilder.ts
|
|
18691
18769
|
function toPluginArray(plugins) {
|
|
18692
18770
|
const queue = [];
|
|
@@ -18788,9 +18866,12 @@ function createPackageBuilder(ctx, oxcVitePlugin) {
|
|
|
18788
18866
|
outDir
|
|
18789
18867
|
}).options);
|
|
18790
18868
|
}
|
|
18791
|
-
async function copyBuild({ from, to }) {
|
|
18869
|
+
async function copyBuild({ from, to, name }) {
|
|
18792
18870
|
await fs$1.remove(to);
|
|
18793
|
-
await fs$1.copy(from, to, {
|
|
18871
|
+
await fs$1.copy(from, to, {
|
|
18872
|
+
filter: createNpmPackageCopyFilter(from, ctx.configService?.weappViteConfig?.npm?.packageFiles?.[name]),
|
|
18873
|
+
overwrite: true
|
|
18874
|
+
});
|
|
18794
18875
|
}
|
|
18795
18876
|
let buildPackage;
|
|
18796
18877
|
async function runBuildPackage({ dep, outDir, options, isDependenciesCacheOutdate }) {
|
|
@@ -18933,6 +19014,7 @@ function createDependenciesCache(ctx) {
|
|
|
18933
19014
|
const configService = requireConfigService(ctx, "读取依赖缓存哈希前必须初始化 configService。");
|
|
18934
19015
|
return objectHash({
|
|
18935
19016
|
dependencies: configService.packageJson.dependencies ?? {},
|
|
19017
|
+
packageFiles: configService.weappViteConfig?.npm?.packageFiles ?? {},
|
|
18936
19018
|
scope: serializeDependencyScope(resolveDependencyScope(root))
|
|
18937
19019
|
});
|
|
18938
19020
|
}
|
|
@@ -25430,18 +25512,6 @@ function createRequestGlobalsPassiveBindingsCode(targets, explicitBindingTargets
|
|
|
25430
25512
|
if (target === "performance") return `var performance = ${REQUEST_GLOBAL_EXPOSE_HELPER}("performance",${actualRef}&&typeof ${actualRef}.now==="function"&&${actualRef}?.[${JSON.stringify(REQUEST_GLOBAL_PLACEHOLDER_KEY)}]!==true?${actualRef}:globalThis.performance&&typeof globalThis.performance.now==="function"&&globalThis.performance?.[${JSON.stringify(REQUEST_GLOBAL_PLACEHOLDER_KEY)}]!==true?globalThis.performance:__weappViteRequestGlobalsLazyObject("performance",["now"]))`;
|
|
25431
25513
|
if (target === "crypto") return `var crypto = ${REQUEST_GLOBAL_EXPOSE_HELPER}("crypto",${actualRef}&&typeof ${actualRef}.getRandomValues==="function"&&${actualRef}?.[${JSON.stringify(REQUEST_GLOBAL_PLACEHOLDER_KEY)}]!==true?${actualRef}:globalThis.crypto&&typeof globalThis.crypto.getRandomValues==="function"&&globalThis.crypto?.[${JSON.stringify(REQUEST_GLOBAL_PLACEHOLDER_KEY)}]!==true?globalThis.crypto:__weappViteRequestGlobalsLazyObject("crypto",["getRandomValues"]))`;
|
|
25432
25514
|
if (target === "URL") return `var URL = ${REQUEST_GLOBAL_EXPOSE_HELPER}("URL",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},["123","fake://abc"],"fake://abc/123")?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.URL,["123","fake://abc"],"fake://abc/123")?globalThis.URL:${placeholderFactory})`;
|
|
25433
|
-
if (target === "URLSearchParams") return `var URLSearchParams = ${REQUEST_GLOBAL_EXPOSE_HELPER}("URLSearchParams",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},["client=graphql-request"])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.URLSearchParams,["client=graphql-request"])?globalThis.URLSearchParams:${placeholderFactory})`;
|
|
25434
|
-
if (target === "Blob") return `var Blob = ${REQUEST_GLOBAL_EXPOSE_HELPER}("Blob",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},[])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.Blob,[])?globalThis.Blob:${placeholderFactory})`;
|
|
25435
|
-
if (target === "File") return `var File = ${REQUEST_GLOBAL_EXPOSE_HELPER}("File",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},[[],"request-globals.bin"])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.File,[[],"request-globals.bin"])?globalThis.File:${placeholderFactory})`;
|
|
25436
|
-
if (target === "FormData") return `var FormData = ${REQUEST_GLOBAL_EXPOSE_HELPER}("FormData",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},[])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.FormData,[])?globalThis.FormData:${placeholderFactory})`;
|
|
25437
|
-
if (target === "Headers") return `var Headers = ${REQUEST_GLOBAL_EXPOSE_HELPER}("Headers",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},[])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.Headers,[])?globalThis.Headers:${placeholderFactory})`;
|
|
25438
|
-
if (target === "Request") return `var Request = ${REQUEST_GLOBAL_EXPOSE_HELPER}("Request",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},["https://request-globals.invalid"])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.Request,["https://request-globals.invalid"])?globalThis.Request:${placeholderFactory})`;
|
|
25439
|
-
if (target === "Response") return `var Response = ${REQUEST_GLOBAL_EXPOSE_HELPER}("Response",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},[null])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.Response,[null])?globalThis.Response:${placeholderFactory})`;
|
|
25440
|
-
if (target === "TextEncoder") return `var TextEncoder = ${REQUEST_GLOBAL_EXPOSE_HELPER}("TextEncoder",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},[])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.TextEncoder,[])?globalThis.TextEncoder:${placeholderFactory})`;
|
|
25441
|
-
if (target === "TextDecoder") return `var TextDecoder = ${REQUEST_GLOBAL_EXPOSE_HELPER}("TextDecoder",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},[])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.TextDecoder,[])?globalThis.TextDecoder:${placeholderFactory})`;
|
|
25442
|
-
if (target === "XMLHttpRequest") return `var XMLHttpRequest = ${REQUEST_GLOBAL_EXPOSE_HELPER}("XMLHttpRequest",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},[])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.XMLHttpRequest,[])?globalThis.XMLHttpRequest:${placeholderFactory})`;
|
|
25443
|
-
if (target === "WebSocket") return `var WebSocket = ${REQUEST_GLOBAL_EXPOSE_HELPER}("WebSocket",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},["wss://request-globals.invalid"])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.WebSocket,["wss://request-globals.invalid"])?globalThis.WebSocket:${placeholderFactory})`;
|
|
25444
|
-
if (target === "AbortController") return `var AbortController = ${REQUEST_GLOBAL_EXPOSE_HELPER}("AbortController",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},[])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.AbortController,[])?globalThis.AbortController:${placeholderFactory})`;
|
|
25445
25515
|
return `var ${target} = ${REQUEST_GLOBAL_EXPOSE_HELPER}(${JSON.stringify(target)},typeof ${actualRef}==="function"&&${actualRef}?.[${JSON.stringify(REQUEST_GLOBAL_PLACEHOLDER_KEY)}]!==true?${actualRef}:typeof globalThis.${target}==="function"&&globalThis.${target}?.[${JSON.stringify(REQUEST_GLOBAL_PLACEHOLDER_KEY)}]!==true?globalThis.${target}:${placeholderFactory})`;
|
|
25446
25516
|
}).join(";")};`;
|
|
25447
25517
|
}
|
|
@@ -26441,6 +26511,167 @@ function css(ctx) {
|
|
|
26441
26511
|
}];
|
|
26442
26512
|
}
|
|
26443
26513
|
//#endregion
|
|
26514
|
+
//#region src/analyze/glassEasel/index.ts
|
|
26515
|
+
const MIGRATION_GUIDE = "https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/glass-easel/migration.html";
|
|
26516
|
+
const TEMPLATE_FILE_RE = /\.(?:wxml|axml|swan|ttml|jxml|qml|ksml|xhsml)$/i;
|
|
26517
|
+
function isRecord(value) {
|
|
26518
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26519
|
+
}
|
|
26520
|
+
function getOutputSource(output) {
|
|
26521
|
+
if (output.type === "chunk") return output.code;
|
|
26522
|
+
if (typeof output.source === "string") return output.source;
|
|
26523
|
+
return Buffer.from(output.source).toString("utf8");
|
|
26524
|
+
}
|
|
26525
|
+
function offsetToLocation(source, offset) {
|
|
26526
|
+
const lines = source.slice(0, offset).split(/\r?\n/);
|
|
26527
|
+
return {
|
|
26528
|
+
line: lines.length,
|
|
26529
|
+
column: (lines[lines.length - 1]?.length ?? 0) + 1
|
|
26530
|
+
};
|
|
26531
|
+
}
|
|
26532
|
+
function diagnosticKey(diagnostic) {
|
|
26533
|
+
return [
|
|
26534
|
+
diagnostic.code,
|
|
26535
|
+
diagnostic.file,
|
|
26536
|
+
diagnostic.line ?? 0,
|
|
26537
|
+
diagnostic.column ?? 0,
|
|
26538
|
+
diagnostic.message
|
|
26539
|
+
].join(":");
|
|
26540
|
+
}
|
|
26541
|
+
function registerDiagnostic(ctx, diagnostic) {
|
|
26542
|
+
const key = diagnosticKey(diagnostic);
|
|
26543
|
+
ctx.runtimeState.glassEasel.diagnostics.set(key, diagnostic);
|
|
26544
|
+
if (ctx.runtimeState.glassEasel.silent || ctx.runtimeState.glassEasel.warnedDiagnostics.has(key)) return;
|
|
26545
|
+
ctx.runtimeState.glassEasel.warnedDiagnostics.add(key);
|
|
26546
|
+
logger_default.warn(`[${diagnostic.code}] ${diagnostic.file}${diagnostic.line ? `:${diagnostic.line}:${diagnostic.column}` : ""} ${diagnostic.message}`);
|
|
26547
|
+
}
|
|
26548
|
+
function analyzeJsonConfig(file, source) {
|
|
26549
|
+
let config;
|
|
26550
|
+
try {
|
|
26551
|
+
config = JSON.parse(source);
|
|
26552
|
+
} catch {
|
|
26553
|
+
return {
|
|
26554
|
+
detected: false,
|
|
26555
|
+
diagnostics: []
|
|
26556
|
+
};
|
|
26557
|
+
}
|
|
26558
|
+
if (!isRecord(config)) return {
|
|
26559
|
+
detected: false,
|
|
26560
|
+
diagnostics: []
|
|
26561
|
+
};
|
|
26562
|
+
if (!(file === "app.json" || file.endsWith("/app.json") || file === "plugin.json" || file.endsWith("/plugin.json") || config.component !== true) || config.glassEaselWebview !== true) return {
|
|
26563
|
+
detected: false,
|
|
26564
|
+
diagnostics: []
|
|
26565
|
+
};
|
|
26566
|
+
if (config.componentFramework === "glass-easel") return {
|
|
26567
|
+
detected: true,
|
|
26568
|
+
diagnostics: []
|
|
26569
|
+
};
|
|
26570
|
+
return {
|
|
26571
|
+
detected: true,
|
|
26572
|
+
diagnostics: [{
|
|
26573
|
+
code: "GE001",
|
|
26574
|
+
severity: "error",
|
|
26575
|
+
file,
|
|
26576
|
+
message: "WebView glass-easel 需成对配置 componentFramework: \"glass-easel\" 与 glassEaselWebview: true。"
|
|
26577
|
+
}]
|
|
26578
|
+
};
|
|
26579
|
+
}
|
|
26580
|
+
function getMemberPropertyName(node) {
|
|
26581
|
+
if (!node || node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") return;
|
|
26582
|
+
if (!node.computed && node.property?.type === "Identifier") return node.property.name;
|
|
26583
|
+
if (node.property?.type === "StringLiteral") return node.property.value;
|
|
26584
|
+
}
|
|
26585
|
+
function isWxCreateSelectorQueryCall(node) {
|
|
26586
|
+
if (!node || node.type !== "CallExpression") return false;
|
|
26587
|
+
const callee = node.callee;
|
|
26588
|
+
return getMemberPropertyName(callee) === "createSelectorQuery" && callee.object?.type === "Identifier" && callee.object.name === "wx";
|
|
26589
|
+
}
|
|
26590
|
+
function analyzeScript(file, source) {
|
|
26591
|
+
const diagnostics = [];
|
|
26592
|
+
try {
|
|
26593
|
+
const ast = parseJsLike(source);
|
|
26594
|
+
traverse(ast, { CallExpression(callPath) {
|
|
26595
|
+
const node = callPath.node;
|
|
26596
|
+
const method = getMemberPropertyName(node.callee);
|
|
26597
|
+
if (method === "select" || method === "selectAll") {
|
|
26598
|
+
const selector = node.arguments?.[0];
|
|
26599
|
+
if (selector?.type === "StringLiteral" && /(?:^|[\s>+~,])[.#]\d/.test(selector.value)) diagnostics.push({
|
|
26600
|
+
code: "GE005",
|
|
26601
|
+
severity: "error",
|
|
26602
|
+
file,
|
|
26603
|
+
line: selector.loc?.start.line,
|
|
26604
|
+
column: selector.loc ? selector.loc.start.column + 1 : void 0,
|
|
26605
|
+
message: `SelectorQuery 选择器 ${JSON.stringify(selector.value)} 含数字开头的 id 或 class。`
|
|
26606
|
+
});
|
|
26607
|
+
}
|
|
26608
|
+
if (method === "in" && isWxCreateSelectorQueryCall(node.callee.object) && node.arguments?.[0]?.type === "ThisExpression") diagnostics.push({
|
|
26609
|
+
code: "GE006",
|
|
26610
|
+
severity: "warning",
|
|
26611
|
+
file,
|
|
26612
|
+
line: node.loc?.start.line,
|
|
26613
|
+
column: node.loc ? node.loc.start.column + 1 : void 0,
|
|
26614
|
+
message: "可将 wx.createSelectorQuery().in(this) 改为 this.createSelectorQuery(),减少兼容层开销。"
|
|
26615
|
+
});
|
|
26616
|
+
} });
|
|
26617
|
+
} catch {}
|
|
26618
|
+
return diagnostics;
|
|
26619
|
+
}
|
|
26620
|
+
function analyzeGlassEaselBundle(ctx, bundle) {
|
|
26621
|
+
const entries = Object.entries(bundle);
|
|
26622
|
+
const localDiagnostics = [];
|
|
26623
|
+
let detected = ctx.runtimeState.glassEasel.detected;
|
|
26624
|
+
for (const [bundleFileName, output] of entries) {
|
|
26625
|
+
const file = output.fileName || bundleFileName;
|
|
26626
|
+
if (!file.endsWith(".json")) continue;
|
|
26627
|
+
const result = analyzeJsonConfig(file, getOutputSource(output));
|
|
26628
|
+
detected ||= result.detected;
|
|
26629
|
+
localDiagnostics.push(...result.diagnostics);
|
|
26630
|
+
}
|
|
26631
|
+
ctx.runtimeState.glassEasel.detected = detected;
|
|
26632
|
+
if (!detected) return;
|
|
26633
|
+
for (const [sourceFile, token] of ctx.runtimeState.wxml.tokenMap) for (const finding of token.glassEaselFindings ?? []) {
|
|
26634
|
+
if (finding.code !== "GE002") continue;
|
|
26635
|
+
localDiagnostics.push({
|
|
26636
|
+
code: finding.code,
|
|
26637
|
+
severity: finding.severity,
|
|
26638
|
+
message: finding.message,
|
|
26639
|
+
file: ctx.configService.relativeAbsoluteSrcRoot(sourceFile),
|
|
26640
|
+
...offsetToLocation(token.code, finding.start),
|
|
26641
|
+
normalized: finding.normalized
|
|
26642
|
+
});
|
|
26643
|
+
}
|
|
26644
|
+
for (const [bundleFileName, output] of entries) {
|
|
26645
|
+
const file = output.fileName || bundleFileName;
|
|
26646
|
+
const source = getOutputSource(output);
|
|
26647
|
+
if (TEMPLATE_FILE_RE.test(file)) {
|
|
26648
|
+
const token = scanWxml(source, { platform: ctx.configService.platform });
|
|
26649
|
+
for (const finding of token.glassEaselFindings ?? []) localDiagnostics.push({
|
|
26650
|
+
code: finding.code,
|
|
26651
|
+
severity: finding.severity,
|
|
26652
|
+
message: finding.message,
|
|
26653
|
+
file,
|
|
26654
|
+
...offsetToLocation(source, finding.start),
|
|
26655
|
+
normalized: finding.normalized
|
|
26656
|
+
});
|
|
26657
|
+
} else if (output.type === "chunk") localDiagnostics.push(...analyzeScript(file, source));
|
|
26658
|
+
}
|
|
26659
|
+
for (const diagnostic of localDiagnostics) registerDiagnostic(ctx, diagnostic);
|
|
26660
|
+
}
|
|
26661
|
+
function createGlassEaselAnalyzeResult(ctx) {
|
|
26662
|
+
const diagnostics = Array.from(ctx.runtimeState.glassEasel.diagnostics.values()).sort((left, right) => left.file.localeCompare(right.file) || (left.line ?? 0) - (right.line ?? 0) || left.code.localeCompare(right.code));
|
|
26663
|
+
return {
|
|
26664
|
+
detected: ctx.runtimeState.glassEasel.detected,
|
|
26665
|
+
minimumBaseLibrary: "3.8.12",
|
|
26666
|
+
migrationGuide: MIGRATION_GUIDE,
|
|
26667
|
+
diagnostics,
|
|
26668
|
+
summary: {
|
|
26669
|
+
errors: diagnostics.filter((item) => item.severity === "error").length,
|
|
26670
|
+
warnings: diagnostics.filter((item) => item.severity === "warning").length
|
|
26671
|
+
}
|
|
26672
|
+
};
|
|
26673
|
+
}
|
|
26674
|
+
//#endregion
|
|
26444
26675
|
//#region src/i18n/config.ts
|
|
26445
26676
|
const IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
26446
26677
|
function normalizeName(value, fallback, field) {
|
|
@@ -26752,7 +26983,9 @@ const TEMPLATE_STATIC_REWRITE_MARKERS = [
|
|
|
26752
26983
|
".qml",
|
|
26753
26984
|
".ksml",
|
|
26754
26985
|
".xhsml",
|
|
26755
|
-
"import.meta."
|
|
26986
|
+
"import.meta.",
|
|
26987
|
+
"wx-if",
|
|
26988
|
+
"wx-for"
|
|
26756
26989
|
];
|
|
26757
26990
|
const TEMPLATE_DIRECTIVE_PREFIXES = getSupportedMiniProgramDirectivePrefixes();
|
|
26758
26991
|
const GRAPH_ONLY_OUTPUT_MARKERS = [WEAPP_VITE_LOGICAL_ENTRY_RESOLVED_PREFIX, WEAPP_VITE_SIDECAR_RESOLVED_PREFIX];
|
|
@@ -26941,6 +27174,7 @@ function createOutputFinalizerPlugin(ctx, subPackageMeta) {
|
|
|
26941
27174
|
restoreNativePageLayoutOutputs(ctx, outputBundle);
|
|
26942
27175
|
normalizeGraphOnlyAssets(ctx, outputBundle, (asset) => this.emitFile(asset));
|
|
26943
27176
|
const assetEntries = collectOutputFinalizerAssetEntries(outputBundle);
|
|
27177
|
+
if (ctx.configService.platform === "weapp") analyzeGlassEaselBundle(ctx, outputBundle);
|
|
26944
27178
|
normalizePreprocessorStyleAssetEntries(outputBundle, assetEntries.preprocessorStyleAssets, ctx.configService.outputExtensions?.wxss, (asset) => this.emitFile(asset));
|
|
26945
27179
|
normalizeTemplateAssetEntries(ctx, assetEntries.templateAssets, subPackageMeta);
|
|
26946
27180
|
pruneUnchangedDevHmrOutputs(ctx, outputBundle, wevuRuntimeRewriteOptions, { runtimeRewriteDone: true });
|
|
@@ -27226,7 +27460,7 @@ function rememberChunkScriptAnalysis(chunk, analysis, options) {
|
|
|
27226
27460
|
function getChunkScriptAnalysis(chunk, options) {
|
|
27227
27461
|
const cached = options?.cache?.get(chunk);
|
|
27228
27462
|
if (cached?.code === chunk.code) return cached.analysis;
|
|
27229
|
-
const analysis = mayNeedChunkScriptAnalysis(chunk.code) ? analyzeScript(chunk.code, { engine: options?.astEngine }) : {
|
|
27463
|
+
const analysis = mayNeedChunkScriptAnalysis(chunk.code) ? analyzeScript$1(chunk.code, { engine: options?.astEngine }) : {
|
|
27230
27464
|
hasPlatformApiAccess: false,
|
|
27231
27465
|
hasStaticRequireLiteral: false
|
|
27232
27466
|
};
|
|
@@ -28182,10 +28416,14 @@ function emitAppPreludeRequireAssets(bundle, appPreludeCode, state, requestGloba
|
|
|
28182
28416
|
return output?.type === "chunk" && resolveAppPreludeRequireFileName(output.fileName, state) === fileName;
|
|
28183
28417
|
});
|
|
28184
28418
|
const sortedScopeChunks = [...scopeChunks.filter((chunk) => !requestGlobalsPreludeOptions.installerChunks.has(toPosixPath(chunk.fileName))), ...scopeChunks.filter((chunk) => requestGlobalsPreludeOptions.installerChunks.has(toPosixPath(chunk.fileName)))];
|
|
28185
|
-
|
|
28186
|
-
if (
|
|
28187
|
-
const
|
|
28188
|
-
if (
|
|
28419
|
+
let requestGlobalsPreludeCode;
|
|
28420
|
+
if (requestGlobalsPreludeOptions.enabled) for (const chunk of sortedScopeChunks) {
|
|
28421
|
+
const code = createRequestGlobalsPreludeAssetCode(fileName, chunk, requestGlobalsPreludeOptions.installerChunks, requestGlobalsPreludeOptions.targets, requestGlobalsPreludeOptions.mode, requestGlobalsPreludeOptions.networkDefaults);
|
|
28422
|
+
if (!code) continue;
|
|
28423
|
+
requestGlobalsPreludeCode = code;
|
|
28424
|
+
const installerChunkFileName = resolveRequestGlobalsInstallerImport(chunk, requestGlobalsPreludeOptions.installerChunks)?.installerChunkFileName ?? (requestGlobalsPreludeOptions.installerChunks.has(toPosixPath(chunk.fileName)) ? toPosixPath(chunk.fileName) : void 0);
|
|
28425
|
+
if (installerChunkFileName) preservedRequestGlobalsInstallerChunks.add(installerChunkFileName);
|
|
28426
|
+
break;
|
|
28189
28427
|
}
|
|
28190
28428
|
const source = [requestGlobalsPreludeCode, appPreludeCode].filter(Boolean).join("\n");
|
|
28191
28429
|
emitFile?.({
|
|
@@ -34500,7 +34738,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
34500
34738
|
const { path: appEntryPath } = appEntry;
|
|
34501
34739
|
let configFromVue;
|
|
34502
34740
|
if (!appConfigFile && vueAppPath) {
|
|
34503
|
-
const { extractConfigFromVue } = await import("./file-
|
|
34741
|
+
const { extractConfigFromVue } = await import("./file-DWR7zIBT.mjs");
|
|
34504
34742
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
34505
34743
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
34506
34744
|
}
|
|
@@ -35516,4 +35754,4 @@ async function createCompilerContext(options) {
|
|
|
35516
35754
|
return ctx;
|
|
35517
35755
|
}
|
|
35518
35756
|
//#endregion
|
|
35519
|
-
export {
|
|
35757
|
+
export { getDefaultIdeProjectRoot as A, collectPreloadPages as C, loadViteConfigFile as D, suggestPreloadRules as E, isPathInside as M, parseCommentJson as O, getProjectConfigFileName as S, resolvePreloadPackageIdentifier as T, SHARED_CHUNK_VIRTUAL_PREFIX as _, createGlassEaselAnalyzeResult as a, resolveWeappConfigFile as b, getSupportedWeappVitePlatforms as c, resolveWeappViteTarget as d, getBackendForCapability as f, createSharedBuildConfig as g, syncManagedTsconfigBootstrapFiles as h, setActiveCompilerContextKey as i, shouldPassPlatformArgToIdeOpen as j, createCjsConfigLoadError as k, getSupportedWeappViteTargetDescriptors as l, syncProjectSupportFiles as m, getCompilerContext as n, formatBytes as o, resolveBackendExecution as p, resetCompilerContext as r, WEB_PLATFORM_ALIASES as s, createCompilerContext as t, isWebPlatform as u, resolveHmrProfileJsonPath as v, findPreloadRuleKey as w, checkRuntime as x, getRouteRuntimeGlobalKeys as y };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# glass-easel 兼容检查
|
|
2
|
+
|
|
3
|
+
WebView glass-easel 需要微信基础库 `3.8.12` 或更高,weapp-vite 模板默认不启用。开发者工具只提供低于该门槛的基础库时应保持回退;`componentFramework: "glass-easel"` 单独存在不会开启 WebView glass-easel。
|
|
4
|
+
|
|
5
|
+
确认开发者工具与真机基础库均满足要求后,由用户在 App、Page 或 Plugin JSON 中显式成对配置:
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"componentFramework": "glass-easel",
|
|
10
|
+
"glassEaselWebview": true
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
宿主 JSON 是唯一配置源,不要在 `vite.config.ts` 中创建重复配置。插件必须在 `plugin.json` 中声明;组件框架会沿 `usingComponents` 与 `componentGenerics.*.default` 传播。删除或关闭 `glassEaselWebview` 即可回退。
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
wv analyze --glass-easel-check
|
|
18
|
+
wv analyze --glass-easel-check --json
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`glassEasel` 报告使用 `GE001` 到 `GE006` 稳定诊断码。工具会安全归一化 `wx-if` / `wx-for`;循环内 `<include>`、旧式反斜杠引号转义和数字开头选择器只诊断,不自动改写。
|
|
22
|
+
|
|
23
|
+
官方参考:https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/glass-easel/migration.html
|