weapp-vite 6.22.0 → 6.24.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 +6 -6
- 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-DddiW1j3.mjs} +330 -80
- package/dist/docs/README.md +6 -6
- package/dist/docs/glass-easel.md +23 -0
- package/dist/docs/i18n.md +1 -1
- package/dist/docs/index.md +8 -6
- package/dist/docs/mcp.md +6 -0
- package/dist/docs/volar.md +8 -8
- package/dist/{file-D0n-Q1ra.mjs → file-CaKJV6Km.mjs} +1 -1
- package/dist/file-QyWJOwaH.mjs +2 -0
- package/dist/getInstance-BXs7VCNS.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 +22 -22
- 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-CaKJV6Km.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";
|
|
@@ -1911,7 +1911,7 @@ function createHtmlCustomDataDefinition(componentNames, getMetadata, baseTags =
|
|
|
1911
1911
|
if (attributes.length) tag.attributes = attributes;
|
|
1912
1912
|
tag.references = [{
|
|
1913
1913
|
name: "weapp-vite 自动导入组件",
|
|
1914
|
-
url: "https://vite.
|
|
1914
|
+
url: "https://vite.weapp.dev/guide/auto-import-components.html"
|
|
1915
1915
|
}];
|
|
1916
1916
|
return tag;
|
|
1917
1917
|
}))
|
|
@@ -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
|
}
|
|
@@ -18394,6 +18450,17 @@ function transformTemplateForAlipay(source) {
|
|
|
18394
18450
|
return rewriteAlipayReferenceExtensions(normalizeImportSjsAttributes(rewriteTemplateImportExtensionsForAlipay(rewriteAlipayTemplateSyntax(source))));
|
|
18395
18451
|
}
|
|
18396
18452
|
//#endregion
|
|
18453
|
+
//#region src/runtime/npmPlugin/builder/jsModule/helpers.ts
|
|
18454
|
+
const ESM_SYNTAX_RE$1 = /\bimport(?=[\s{'"*])|\bexport(?=[\s{*])/;
|
|
18455
|
+
function hasEsmSyntax(source) {
|
|
18456
|
+
return ESM_SYNTAX_RE$1.test(source);
|
|
18457
|
+
}
|
|
18458
|
+
function createExportAllStatements(source, scope) {
|
|
18459
|
+
const requireId = scope.generateUidIdentifier("reExported");
|
|
18460
|
+
const exportKeyId = scope.generateUidIdentifier("exportKey");
|
|
18461
|
+
return [t.variableDeclaration("const", [t.variableDeclarator(requireId, t.callExpression(t.identifier("require"), [source]))]), t.expressionStatement(t.callExpression(t.memberExpression(t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("keys")), [requireId]), t.identifier("forEach")), [t.arrowFunctionExpression([exportKeyId], t.blockStatement([t.ifStatement(t.logicalExpression("||", t.binaryExpression("===", exportKeyId, t.stringLiteral("default")), t.binaryExpression("===", exportKeyId, t.stringLiteral("__esModule"))), t.returnStatement()), t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier("exports"), exportKeyId, true), t.memberExpression(requireId, exportKeyId, true)))]))]))];
|
|
18462
|
+
}
|
|
18463
|
+
//#endregion
|
|
18397
18464
|
//#region src/runtime/npmPlugin/builder/shared.ts
|
|
18398
18465
|
async function collectFiles(root) {
|
|
18399
18466
|
const files = [];
|
|
@@ -18442,10 +18509,6 @@ async function resolvePreferredPackageEntry(rootPath, pkg) {
|
|
|
18442
18509
|
}
|
|
18443
18510
|
//#endregion
|
|
18444
18511
|
//#region src/runtime/npmPlugin/builder/jsModule.ts
|
|
18445
|
-
const ESM_SYNTAX_RE$1 = /\bimport\s|\bexport\s/;
|
|
18446
|
-
function hasEsmSyntax(source) {
|
|
18447
|
-
return ESM_SYNTAX_RE$1.test(source);
|
|
18448
|
-
}
|
|
18449
18512
|
function createExportsMember(name) {
|
|
18450
18513
|
return t.memberExpression(t.identifier("exports"), t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name), !t.isValidIdentifier(name));
|
|
18451
18514
|
}
|
|
@@ -18559,6 +18622,11 @@ async function transformJsModuleToCjs(source, options) {
|
|
|
18559
18622
|
}
|
|
18560
18623
|
path.replaceWithMultiple(statements);
|
|
18561
18624
|
transformed = true;
|
|
18625
|
+
},
|
|
18626
|
+
ExportAllDeclaration(path) {
|
|
18627
|
+
hasConvertedExport = true;
|
|
18628
|
+
path.replaceWithMultiple(createExportAllStatements(t.stringLiteral(path.node.source.value), path.scope));
|
|
18629
|
+
transformed = true;
|
|
18562
18630
|
}
|
|
18563
18631
|
});
|
|
18564
18632
|
if (exportAssignments.length > 0) {
|
|
@@ -18687,6 +18755,28 @@ async function copyEsModuleDirectoryForAlipay(sourceRoot, targetRoot) {
|
|
|
18687
18755
|
return true;
|
|
18688
18756
|
}
|
|
18689
18757
|
//#endregion
|
|
18758
|
+
//#region src/runtime/npmPlugin/builder/packageFiles.ts
|
|
18759
|
+
function normalizePattern$1(pattern) {
|
|
18760
|
+
return pattern.replaceAll("\\", "/");
|
|
18761
|
+
}
|
|
18762
|
+
function createNpmPackageFileMatcher(config) {
|
|
18763
|
+
const include = config?.include?.length ? picomatch(config.include.map(normalizePattern$1), { dot: true }) : () => true;
|
|
18764
|
+
const exclude = config?.exclude?.length ? picomatch(config.exclude.map(normalizePattern$1), { dot: true }) : () => false;
|
|
18765
|
+
return (relativePath) => {
|
|
18766
|
+
const normalizedPath = normalizePattern$1(relativePath);
|
|
18767
|
+
return include(normalizedPath) && !exclude(normalizedPath);
|
|
18768
|
+
};
|
|
18769
|
+
}
|
|
18770
|
+
function createNpmPackageCopyFilter(sourceRoot, config) {
|
|
18771
|
+
if (!config?.include?.length && !config?.exclude?.length) return;
|
|
18772
|
+
const matches = createNpmPackageFileMatcher(config);
|
|
18773
|
+
return async (sourcePath) => {
|
|
18774
|
+
const relativePath = path.relative(sourceRoot, sourcePath);
|
|
18775
|
+
if (!relativePath) return true;
|
|
18776
|
+
return (await fs$1.stat(sourcePath)).isDirectory() || matches(relativePath);
|
|
18777
|
+
};
|
|
18778
|
+
}
|
|
18779
|
+
//#endregion
|
|
18690
18780
|
//#region src/runtime/npmPlugin/builder/packageBuilder.ts
|
|
18691
18781
|
function toPluginArray(plugins) {
|
|
18692
18782
|
const queue = [];
|
|
@@ -18788,9 +18878,12 @@ function createPackageBuilder(ctx, oxcVitePlugin) {
|
|
|
18788
18878
|
outDir
|
|
18789
18879
|
}).options);
|
|
18790
18880
|
}
|
|
18791
|
-
async function copyBuild({ from, to }) {
|
|
18881
|
+
async function copyBuild({ from, to, name }) {
|
|
18792
18882
|
await fs$1.remove(to);
|
|
18793
|
-
await fs$1.copy(from, to, {
|
|
18883
|
+
await fs$1.copy(from, to, {
|
|
18884
|
+
filter: createNpmPackageCopyFilter(from, ctx.configService?.weappViteConfig?.npm?.packageFiles?.[name]),
|
|
18885
|
+
overwrite: true
|
|
18886
|
+
});
|
|
18794
18887
|
}
|
|
18795
18888
|
let buildPackage;
|
|
18796
18889
|
async function runBuildPackage({ dep, outDir, options, isDependenciesCacheOutdate }) {
|
|
@@ -18933,6 +19026,7 @@ function createDependenciesCache(ctx) {
|
|
|
18933
19026
|
const configService = requireConfigService(ctx, "读取依赖缓存哈希前必须初始化 configService。");
|
|
18934
19027
|
return objectHash({
|
|
18935
19028
|
dependencies: configService.packageJson.dependencies ?? {},
|
|
19029
|
+
packageFiles: configService.weappViteConfig?.npm?.packageFiles ?? {},
|
|
18936
19030
|
scope: serializeDependencyScope(resolveDependencyScope(root))
|
|
18937
19031
|
});
|
|
18938
19032
|
}
|
|
@@ -25430,18 +25524,6 @@ function createRequestGlobalsPassiveBindingsCode(targets, explicitBindingTargets
|
|
|
25430
25524
|
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
25525
|
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
25526
|
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
25527
|
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
25528
|
}).join(";")};`;
|
|
25447
25529
|
}
|
|
@@ -26441,6 +26523,167 @@ function css(ctx) {
|
|
|
26441
26523
|
}];
|
|
26442
26524
|
}
|
|
26443
26525
|
//#endregion
|
|
26526
|
+
//#region src/analyze/glassEasel/index.ts
|
|
26527
|
+
const MIGRATION_GUIDE = "https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/glass-easel/migration.html";
|
|
26528
|
+
const TEMPLATE_FILE_RE = /\.(?:wxml|axml|swan|ttml|jxml|qml|ksml|xhsml)$/i;
|
|
26529
|
+
function isRecord(value) {
|
|
26530
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26531
|
+
}
|
|
26532
|
+
function getOutputSource(output) {
|
|
26533
|
+
if (output.type === "chunk") return output.code;
|
|
26534
|
+
if (typeof output.source === "string") return output.source;
|
|
26535
|
+
return Buffer.from(output.source).toString("utf8");
|
|
26536
|
+
}
|
|
26537
|
+
function offsetToLocation(source, offset) {
|
|
26538
|
+
const lines = source.slice(0, offset).split(/\r?\n/);
|
|
26539
|
+
return {
|
|
26540
|
+
line: lines.length,
|
|
26541
|
+
column: (lines[lines.length - 1]?.length ?? 0) + 1
|
|
26542
|
+
};
|
|
26543
|
+
}
|
|
26544
|
+
function diagnosticKey(diagnostic) {
|
|
26545
|
+
return [
|
|
26546
|
+
diagnostic.code,
|
|
26547
|
+
diagnostic.file,
|
|
26548
|
+
diagnostic.line ?? 0,
|
|
26549
|
+
diagnostic.column ?? 0,
|
|
26550
|
+
diagnostic.message
|
|
26551
|
+
].join(":");
|
|
26552
|
+
}
|
|
26553
|
+
function registerDiagnostic(ctx, diagnostic) {
|
|
26554
|
+
const key = diagnosticKey(diagnostic);
|
|
26555
|
+
ctx.runtimeState.glassEasel.diagnostics.set(key, diagnostic);
|
|
26556
|
+
if (ctx.runtimeState.glassEasel.silent || ctx.runtimeState.glassEasel.warnedDiagnostics.has(key)) return;
|
|
26557
|
+
ctx.runtimeState.glassEasel.warnedDiagnostics.add(key);
|
|
26558
|
+
logger_default.warn(`[${diagnostic.code}] ${diagnostic.file}${diagnostic.line ? `:${diagnostic.line}:${diagnostic.column}` : ""} ${diagnostic.message}`);
|
|
26559
|
+
}
|
|
26560
|
+
function analyzeJsonConfig(file, source) {
|
|
26561
|
+
let config;
|
|
26562
|
+
try {
|
|
26563
|
+
config = JSON.parse(source);
|
|
26564
|
+
} catch {
|
|
26565
|
+
return {
|
|
26566
|
+
detected: false,
|
|
26567
|
+
diagnostics: []
|
|
26568
|
+
};
|
|
26569
|
+
}
|
|
26570
|
+
if (!isRecord(config)) return {
|
|
26571
|
+
detected: false,
|
|
26572
|
+
diagnostics: []
|
|
26573
|
+
};
|
|
26574
|
+
if (!(file === "app.json" || file.endsWith("/app.json") || file === "plugin.json" || file.endsWith("/plugin.json") || config.component !== true) || config.glassEaselWebview !== true) return {
|
|
26575
|
+
detected: false,
|
|
26576
|
+
diagnostics: []
|
|
26577
|
+
};
|
|
26578
|
+
if (config.componentFramework === "glass-easel") return {
|
|
26579
|
+
detected: true,
|
|
26580
|
+
diagnostics: []
|
|
26581
|
+
};
|
|
26582
|
+
return {
|
|
26583
|
+
detected: true,
|
|
26584
|
+
diagnostics: [{
|
|
26585
|
+
code: "GE001",
|
|
26586
|
+
severity: "error",
|
|
26587
|
+
file,
|
|
26588
|
+
message: "WebView glass-easel 需成对配置 componentFramework: \"glass-easel\" 与 glassEaselWebview: true。"
|
|
26589
|
+
}]
|
|
26590
|
+
};
|
|
26591
|
+
}
|
|
26592
|
+
function getMemberPropertyName(node) {
|
|
26593
|
+
if (!node || node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") return;
|
|
26594
|
+
if (!node.computed && node.property?.type === "Identifier") return node.property.name;
|
|
26595
|
+
if (node.property?.type === "StringLiteral") return node.property.value;
|
|
26596
|
+
}
|
|
26597
|
+
function isWxCreateSelectorQueryCall(node) {
|
|
26598
|
+
if (!node || node.type !== "CallExpression") return false;
|
|
26599
|
+
const callee = node.callee;
|
|
26600
|
+
return getMemberPropertyName(callee) === "createSelectorQuery" && callee.object?.type === "Identifier" && callee.object.name === "wx";
|
|
26601
|
+
}
|
|
26602
|
+
function analyzeScript(file, source) {
|
|
26603
|
+
const diagnostics = [];
|
|
26604
|
+
try {
|
|
26605
|
+
const ast = parseJsLike(source);
|
|
26606
|
+
traverse(ast, { CallExpression(callPath) {
|
|
26607
|
+
const node = callPath.node;
|
|
26608
|
+
const method = getMemberPropertyName(node.callee);
|
|
26609
|
+
if (method === "select" || method === "selectAll") {
|
|
26610
|
+
const selector = node.arguments?.[0];
|
|
26611
|
+
if (selector?.type === "StringLiteral" && /(?:^|[\s>+~,])[.#]\d/.test(selector.value)) diagnostics.push({
|
|
26612
|
+
code: "GE005",
|
|
26613
|
+
severity: "error",
|
|
26614
|
+
file,
|
|
26615
|
+
line: selector.loc?.start.line,
|
|
26616
|
+
column: selector.loc ? selector.loc.start.column + 1 : void 0,
|
|
26617
|
+
message: `SelectorQuery 选择器 ${JSON.stringify(selector.value)} 含数字开头的 id 或 class。`
|
|
26618
|
+
});
|
|
26619
|
+
}
|
|
26620
|
+
if (method === "in" && isWxCreateSelectorQueryCall(node.callee.object) && node.arguments?.[0]?.type === "ThisExpression") diagnostics.push({
|
|
26621
|
+
code: "GE006",
|
|
26622
|
+
severity: "warning",
|
|
26623
|
+
file,
|
|
26624
|
+
line: node.loc?.start.line,
|
|
26625
|
+
column: node.loc ? node.loc.start.column + 1 : void 0,
|
|
26626
|
+
message: "可将 wx.createSelectorQuery().in(this) 改为 this.createSelectorQuery(),减少兼容层开销。"
|
|
26627
|
+
});
|
|
26628
|
+
} });
|
|
26629
|
+
} catch {}
|
|
26630
|
+
return diagnostics;
|
|
26631
|
+
}
|
|
26632
|
+
function analyzeGlassEaselBundle(ctx, bundle) {
|
|
26633
|
+
const entries = Object.entries(bundle);
|
|
26634
|
+
const localDiagnostics = [];
|
|
26635
|
+
let detected = ctx.runtimeState.glassEasel.detected;
|
|
26636
|
+
for (const [bundleFileName, output] of entries) {
|
|
26637
|
+
const file = output.fileName || bundleFileName;
|
|
26638
|
+
if (!file.endsWith(".json")) continue;
|
|
26639
|
+
const result = analyzeJsonConfig(file, getOutputSource(output));
|
|
26640
|
+
detected ||= result.detected;
|
|
26641
|
+
localDiagnostics.push(...result.diagnostics);
|
|
26642
|
+
}
|
|
26643
|
+
ctx.runtimeState.glassEasel.detected = detected;
|
|
26644
|
+
if (!detected) return;
|
|
26645
|
+
for (const [sourceFile, token] of ctx.runtimeState.wxml.tokenMap) for (const finding of token.glassEaselFindings ?? []) {
|
|
26646
|
+
if (finding.code !== "GE002") continue;
|
|
26647
|
+
localDiagnostics.push({
|
|
26648
|
+
code: finding.code,
|
|
26649
|
+
severity: finding.severity,
|
|
26650
|
+
message: finding.message,
|
|
26651
|
+
file: ctx.configService.relativeAbsoluteSrcRoot(sourceFile),
|
|
26652
|
+
...offsetToLocation(token.code, finding.start),
|
|
26653
|
+
normalized: finding.normalized
|
|
26654
|
+
});
|
|
26655
|
+
}
|
|
26656
|
+
for (const [bundleFileName, output] of entries) {
|
|
26657
|
+
const file = output.fileName || bundleFileName;
|
|
26658
|
+
const source = getOutputSource(output);
|
|
26659
|
+
if (TEMPLATE_FILE_RE.test(file)) {
|
|
26660
|
+
const token = scanWxml(source, { platform: ctx.configService.platform });
|
|
26661
|
+
for (const finding of token.glassEaselFindings ?? []) localDiagnostics.push({
|
|
26662
|
+
code: finding.code,
|
|
26663
|
+
severity: finding.severity,
|
|
26664
|
+
message: finding.message,
|
|
26665
|
+
file,
|
|
26666
|
+
...offsetToLocation(source, finding.start),
|
|
26667
|
+
normalized: finding.normalized
|
|
26668
|
+
});
|
|
26669
|
+
} else if (output.type === "chunk") localDiagnostics.push(...analyzeScript(file, source));
|
|
26670
|
+
}
|
|
26671
|
+
for (const diagnostic of localDiagnostics) registerDiagnostic(ctx, diagnostic);
|
|
26672
|
+
}
|
|
26673
|
+
function createGlassEaselAnalyzeResult(ctx) {
|
|
26674
|
+
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));
|
|
26675
|
+
return {
|
|
26676
|
+
detected: ctx.runtimeState.glassEasel.detected,
|
|
26677
|
+
minimumBaseLibrary: "3.8.12",
|
|
26678
|
+
migrationGuide: MIGRATION_GUIDE,
|
|
26679
|
+
diagnostics,
|
|
26680
|
+
summary: {
|
|
26681
|
+
errors: diagnostics.filter((item) => item.severity === "error").length,
|
|
26682
|
+
warnings: diagnostics.filter((item) => item.severity === "warning").length
|
|
26683
|
+
}
|
|
26684
|
+
};
|
|
26685
|
+
}
|
|
26686
|
+
//#endregion
|
|
26444
26687
|
//#region src/i18n/config.ts
|
|
26445
26688
|
const IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
26446
26689
|
function normalizeName(value, fallback, field) {
|
|
@@ -26752,7 +26995,9 @@ const TEMPLATE_STATIC_REWRITE_MARKERS = [
|
|
|
26752
26995
|
".qml",
|
|
26753
26996
|
".ksml",
|
|
26754
26997
|
".xhsml",
|
|
26755
|
-
"import.meta."
|
|
26998
|
+
"import.meta.",
|
|
26999
|
+
"wx-if",
|
|
27000
|
+
"wx-for"
|
|
26756
27001
|
];
|
|
26757
27002
|
const TEMPLATE_DIRECTIVE_PREFIXES = getSupportedMiniProgramDirectivePrefixes();
|
|
26758
27003
|
const GRAPH_ONLY_OUTPUT_MARKERS = [WEAPP_VITE_LOGICAL_ENTRY_RESOLVED_PREFIX, WEAPP_VITE_SIDECAR_RESOLVED_PREFIX];
|
|
@@ -26941,6 +27186,7 @@ function createOutputFinalizerPlugin(ctx, subPackageMeta) {
|
|
|
26941
27186
|
restoreNativePageLayoutOutputs(ctx, outputBundle);
|
|
26942
27187
|
normalizeGraphOnlyAssets(ctx, outputBundle, (asset) => this.emitFile(asset));
|
|
26943
27188
|
const assetEntries = collectOutputFinalizerAssetEntries(outputBundle);
|
|
27189
|
+
if (ctx.configService.platform === "weapp") analyzeGlassEaselBundle(ctx, outputBundle);
|
|
26944
27190
|
normalizePreprocessorStyleAssetEntries(outputBundle, assetEntries.preprocessorStyleAssets, ctx.configService.outputExtensions?.wxss, (asset) => this.emitFile(asset));
|
|
26945
27191
|
normalizeTemplateAssetEntries(ctx, assetEntries.templateAssets, subPackageMeta);
|
|
26946
27192
|
pruneUnchangedDevHmrOutputs(ctx, outputBundle, wevuRuntimeRewriteOptions, { runtimeRewriteDone: true });
|
|
@@ -27226,7 +27472,7 @@ function rememberChunkScriptAnalysis(chunk, analysis, options) {
|
|
|
27226
27472
|
function getChunkScriptAnalysis(chunk, options) {
|
|
27227
27473
|
const cached = options?.cache?.get(chunk);
|
|
27228
27474
|
if (cached?.code === chunk.code) return cached.analysis;
|
|
27229
|
-
const analysis = mayNeedChunkScriptAnalysis(chunk.code) ? analyzeScript(chunk.code, { engine: options?.astEngine }) : {
|
|
27475
|
+
const analysis = mayNeedChunkScriptAnalysis(chunk.code) ? analyzeScript$1(chunk.code, { engine: options?.astEngine }) : {
|
|
27230
27476
|
hasPlatformApiAccess: false,
|
|
27231
27477
|
hasStaticRequireLiteral: false
|
|
27232
27478
|
};
|
|
@@ -28182,10 +28428,14 @@ function emitAppPreludeRequireAssets(bundle, appPreludeCode, state, requestGloba
|
|
|
28182
28428
|
return output?.type === "chunk" && resolveAppPreludeRequireFileName(output.fileName, state) === fileName;
|
|
28183
28429
|
});
|
|
28184
28430
|
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 (
|
|
28431
|
+
let requestGlobalsPreludeCode;
|
|
28432
|
+
if (requestGlobalsPreludeOptions.enabled) for (const chunk of sortedScopeChunks) {
|
|
28433
|
+
const code = createRequestGlobalsPreludeAssetCode(fileName, chunk, requestGlobalsPreludeOptions.installerChunks, requestGlobalsPreludeOptions.targets, requestGlobalsPreludeOptions.mode, requestGlobalsPreludeOptions.networkDefaults);
|
|
28434
|
+
if (!code) continue;
|
|
28435
|
+
requestGlobalsPreludeCode = code;
|
|
28436
|
+
const installerChunkFileName = resolveRequestGlobalsInstallerImport(chunk, requestGlobalsPreludeOptions.installerChunks)?.installerChunkFileName ?? (requestGlobalsPreludeOptions.installerChunks.has(toPosixPath(chunk.fileName)) ? toPosixPath(chunk.fileName) : void 0);
|
|
28437
|
+
if (installerChunkFileName) preservedRequestGlobalsInstallerChunks.add(installerChunkFileName);
|
|
28438
|
+
break;
|
|
28189
28439
|
}
|
|
28190
28440
|
const source = [requestGlobalsPreludeCode, appPreludeCode].filter(Boolean).join("\n");
|
|
28191
28441
|
emitFile?.({
|
|
@@ -34500,7 +34750,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
34500
34750
|
const { path: appEntryPath } = appEntry;
|
|
34501
34751
|
let configFromVue;
|
|
34502
34752
|
if (!appConfigFile && vueAppPath) {
|
|
34503
|
-
const { extractConfigFromVue } = await import("./file-
|
|
34753
|
+
const { extractConfigFromVue } = await import("./file-QyWJOwaH.mjs");
|
|
34504
34754
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
34505
34755
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
34506
34756
|
}
|
|
@@ -35516,4 +35766,4 @@ async function createCompilerContext(options) {
|
|
|
35516
35766
|
return ctx;
|
|
35517
35767
|
}
|
|
35518
35768
|
//#endregion
|
|
35519
|
-
export {
|
|
35769
|
+
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 };
|