weapp-vite 6.12.4 → 6.13.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/client.d.ts +2 -0
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/{config-DKt372Bv.d.mts → config-B3HNOAZo.d.mts} +11 -1
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-D0UJheyD.mjs → createContext-CZ7Kunvn.mjs} +425 -22
- package/dist/{file-Bf2vfymR.mjs → file-DwwblEq4.mjs} +35 -6
- 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/types.d.mts +2 -2
- package/dist/web-apis.d.mts +1 -0
- package/dist/web-apis.mjs +2 -0
- package/package.json +11 -6
package/client.d.ts
CHANGED
|
@@ -43,10 +43,12 @@ declare global {
|
|
|
43
43
|
type __WEAPP_PAGE_JSON__ = import('@weapp-core/schematics').Page
|
|
44
44
|
type __WEAPP_COMPONENT_JSON__ = import('@weapp-core/schematics').Component
|
|
45
45
|
type __WEAPP_PAGE_META__ = import('wevu').PageMeta
|
|
46
|
+
type __WEVU_RUNTIME_APP__ = import('wevu').RuntimeApp<any, any, any>
|
|
46
47
|
|
|
47
48
|
function defineAppJson(config: () => __WEAPP_APP_JSON__): () => __WEAPP_APP_JSON__
|
|
48
49
|
function defineAppJson(config: () => Promise<__WEAPP_APP_JSON__>): () => Promise<__WEAPP_APP_JSON__>
|
|
49
50
|
function defineAppJson(config: __WEAPP_APP_JSON__): __WEAPP_APP_JSON__
|
|
51
|
+
function defineAppSetup<T>(setup: (app: __WEVU_RUNTIME_APP__) => T): T
|
|
50
52
|
|
|
51
53
|
function definePageJson(config: () => __WEAPP_PAGE_JSON__): () => __WEAPP_PAGE_JSON__
|
|
52
54
|
function definePageJson(config: () => Promise<__WEAPP_PAGE_JSON__>): () => Promise<__WEAPP_PAGE_JSON__>
|
package/dist/auto-routes.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as getCompilerContext, l as getRouteRuntimeGlobalKeys } from "./createContext-
|
|
1
|
+
import { i as getCompilerContext, l as getRouteRuntimeGlobalKeys } from "./createContext-CZ7Kunvn.mjs";
|
|
2
2
|
//#region src/auto-routes.ts
|
|
3
3
|
const ROUTE_RUNTIME_OVERRIDE_KEY = Symbol.for("weapp-vite.route-runtime");
|
|
4
4
|
function createGetter(resolver) {
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as getDefaultIdeProjectRoot, b as shouldPassPlatformArgToIdeOpen, c as SHARED_CHUNK_VIRTUAL_PREFIX, d as checkRuntime, f as getProjectConfigFileName, g as DEFAULT_MP_PLATFORM, h as createCjsConfigLoadError, m as parseCommentJson, n as syncProjectSupportFiles, o as formatBytes, p as loadViteConfigFile, r as syncManagedTsconfigBootstrapFiles, s as createSharedBuildConfig, t as createCompilerContext, u as resolveWeappConfigFile, v as normalizeMiniPlatform, x as isPathInside, y as resolveMiniPlatform } from "./createContext-
|
|
1
|
+
import { _ as getDefaultIdeProjectRoot, b as shouldPassPlatformArgToIdeOpen, c as SHARED_CHUNK_VIRTUAL_PREFIX, d as checkRuntime, f as getProjectConfigFileName, g as DEFAULT_MP_PLATFORM, h as createCjsConfigLoadError, m as parseCommentJson, n as syncProjectSupportFiles, o as formatBytes, p as loadViteConfigFile, r as syncManagedTsconfigBootstrapFiles, s as createSharedBuildConfig, t as createCompilerContext, u as resolveWeappConfigFile, v as normalizeMiniPlatform, x as isPathInside, y as resolveMiniPlatform } from "./createContext-CZ7Kunvn.mjs";
|
|
2
2
|
import { r as logger_default, t as colors } from "./logger-gutcwWKE.mjs";
|
|
3
|
-
import { p as VERSION } from "./file-
|
|
3
|
+
import { p as VERSION } from "./file-DwwblEq4.mjs";
|
|
4
4
|
import { resolveWeappMcpConfig, startWeappViteMcpServer } from "./mcp.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import { defu } from "@weapp-core/shared";
|
|
@@ -413,6 +413,15 @@ interface WeappInjectWeapiConfig {
|
|
|
413
413
|
replaceWx?: boolean;
|
|
414
414
|
globalName?: string;
|
|
415
415
|
}
|
|
416
|
+
type WeappInjectRequestGlobalsTarget = 'fetch' | 'Headers' | 'Request' | 'Response' | 'AbortController' | 'AbortSignal' | 'XMLHttpRequest';
|
|
417
|
+
/**
|
|
418
|
+
* @description 请求相关全局对象注入配置
|
|
419
|
+
*/
|
|
420
|
+
interface WeappInjectRequestGlobalsConfig {
|
|
421
|
+
enabled?: boolean;
|
|
422
|
+
targets?: WeappInjectRequestGlobalsTarget[];
|
|
423
|
+
dependencies?: (string | RegExp)[];
|
|
424
|
+
}
|
|
416
425
|
/**
|
|
417
426
|
* @description 本地 npm 构建配置
|
|
418
427
|
*/
|
|
@@ -596,6 +605,7 @@ interface WeappViteConfig {
|
|
|
596
605
|
wevu?: WeappWevuConfig;
|
|
597
606
|
routeRules?: WeappRouteRules;
|
|
598
607
|
injectWeapi?: boolean | WeappInjectWeapiConfig;
|
|
608
|
+
injectRequestGlobals?: boolean | WeappInjectRequestGlobalsConfig;
|
|
599
609
|
mcp?: boolean | WeappMcpConfig;
|
|
600
610
|
forwardConsole?: boolean | WeappForwardConsoleConfig;
|
|
601
611
|
chunks?: ChunksConfig;
|
|
@@ -1469,4 +1479,4 @@ declare function defineConfig(config: UserConfigFnObjectPlain): UserConfigFnObje
|
|
|
1469
1479
|
declare function defineConfig(config: UserConfigFn): UserConfigFn;
|
|
1470
1480
|
declare function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise;
|
|
1471
1481
|
//#endregion
|
|
1472
|
-
export { WeappDebugConfig as $,
|
|
1482
|
+
export { WeappDebugConfig as $, NpmBuildOptions as $t, Ref as A, createWeappViteHostMeta as An, ChunksConfig as At, BindingErrorLike as B, GenerateTemplateEntry as Bt, LoadConfigOptions as C, WeappManagedSharedTsconfigConfig as Cn, WeappVueTemplateConfig as Ct, MethodDefinitions$1 as D, WeappViteHostMeta as Dn, AliasOptions as Dt, InlineConfig$1 as E, WEAPP_VITE_HOST_NAME as En, Alias as Et, RolldownPlugin as F, GenerateFileType as Ft, EntryJsonFragment as G, GenerateTemplatesConfig as Gt, BaseEntry as H, GenerateTemplateFileSource as Ht, RolldownPluginOption as I, GenerateFilenamesOptions as It, ScanComponentItem as J, JsonMergeContext as Jt, PageEntry as K, JsFormat as Kt, RolldownWatchOptions as L, GenerateOptions as Lt, RolldownBuild as M, resolveWeappViteHostMeta as Mn, CopyOptions as Mt, RolldownOptions as N, GenerateDirsOptions as Nt, Plugin$1 as O, WeappViteRuntime as On, AlipayNpmMode as Ot, RolldownOutput$1 as P, GenerateExtensionsOptions as Pt, UserConfig$2 as Q, MpPlatform as Qt, RolldownWatcher$1 as R, GenerateTemplate as Rt, CompilerContext as S, WeappManagedServerTsconfigConfig as Sn, WeappVueConfig as St, ConfigEnv$1 as T, WeappWebConfig as Tn, WeappWorkerConfig as Tt, ComponentEntry as U, GenerateTemplateInlineSource as Ut, AppEntry as V, GenerateTemplateFactory as Vt, Entry as W, GenerateTemplateScope as Wt, ProjectConfig as X, JsonMergeStage as Xt, WxmlDep as Y, JsonMergeFunction as Yt, SubPackageMetaValue as Z, JsonMergeStrategy as Zt, definePageJson as _, WeappLibFileName as _n, WeappMcpConfig as _t, UserConfigFnNoEnvPlain as a, SharedChunkMode as an, EnhanceOptions as at, ChangeEvent as b, WeappManagedAppTsconfigConfig as bn, WeappRouteRules as bt, UserConfigFnPromise as c, SubPackage as cn, MultiPlatformConfig as ct, Component$1 as d, SubPackageStyleEntry as dn, WeappAutoRoutesInclude as dt, NpmMainPackageConfig as en, WeappForwardConsoleConfig as et, Page$1 as f, SubPackageStyleScope as fn, WeappAutoRoutesIncludePattern as ft, defineComponentJson as g, WeappLibEntryContext as gn, WeappInjectWeapiConfig as gt, defineAppJson as h, WeappLibDtsOptions as hn, WeappInjectRequestGlobalsTarget as ht, UserConfigFnNoEnv as i, SharedChunkDynamicImports as in, AutoImportComponentsOption as it, ResolvedConfig as j, isWeappViteHost as jn, CopyGlobs as jt, PluginOption as k, applyWeappViteHostMeta as kn, BuildNpmPackageMeta as kt, defineConfig as l, SubPackageStyleConfigEntry as ln, ScanWxmlOptions as lt, Theme$1 as m, WeappLibConfig as mn, WeappInjectRequestGlobalsConfig as mt, UserConfigExport as n, NpmSubPackageConfig as nn, WeappViteConfig as nt, UserConfigFnObject as o, SharedChunkOverride as on, EnhanceWxmlOptions as ot, Sitemap$1 as p, WeappLibComponentJson as pn, WeappHmrConfig as pt, ComponentsMap as q, JsonConfig as qt, UserConfigFn as r, ResolvedAlias as rn, AutoImportComponents as rt, UserConfigFnObjectPlain as s, SharedChunkStrategy as sn, HandleWxmlOptions as st, UserConfig$1 as t, NpmPluginPackageConfig as tn, WeappForwardConsoleLogLevel as tt, App$1 as u, SubPackageStyleConfigObject as un, WeappAutoRoutesConfig as ut, defineSitemapJson as v, WeappLibInternalDtsOptions as vn, WeappNpmConfig as vt, ComputedDefinitions$1 as w, WeappManagedTypeScriptConfig as wn, WeappWevuConfig as wt, WeappVitePluginApi as x, WeappManagedNodeTsconfigConfig as xn, WeappSubPackageConfig as xt, defineThemeJson as y, WeappLibVueTscOptions as yn, WeappRouteRule as yt, ViteDevServer$1 as z, GenerateTemplateContext as zt };
|
package/dist/config.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { An as
|
|
1
|
+
import { An as createWeappViteHostMeta, Dn as WeappViteHostMeta, En as WEAPP_VITE_HOST_NAME, Mn as resolveWeappViteHostMeta, On as WeappViteRuntime, _ as definePageJson, a as UserConfigFnNoEnvPlain, c as UserConfigFnPromise, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, jn as isWeappViteHost, kn as applyWeappViteHostMeta, l as defineConfig, m as Theme, n as UserConfigExport, nt as WeappViteConfig, o as UserConfigFnObject, p as Sitemap, r as UserConfigFn, s as UserConfigFnObjectPlain, t as UserConfig, u as App, v as defineSitemapJson, y as defineThemeJson } from "./config-B3HNOAZo.mjs";
|
|
2
2
|
export { App, Component, Page, Sitemap, Theme, UserConfig, UserConfigExport, UserConfigFn, UserConfigFnNoEnv, UserConfigFnNoEnvPlain, UserConfigFnObject, UserConfigFnObjectPlain, UserConfigFnPromise, WEAPP_VITE_HOST_NAME, WeappViteConfig, WeappViteHostMeta, WeappViteRuntime, applyWeappViteHostMeta, createWeappViteHostMeta, defineAppJson, defineComponentJson, defineConfig, definePageJson, defineSitemapJson, defineThemeJson, isWeappViteHost, resolveWeappViteHostMeta };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-twds-ZHy.mjs";
|
|
2
2
|
import { n as applyWeappViteHostMeta } from "./pluginHost-SJdl15d3.mjs";
|
|
3
3
|
import { n as configureLogger, r as logger_default } from "./logger-gutcwWKE.mjs";
|
|
4
|
-
import { _ as templateExtensions, a as findJsEntry, c as findVueEntry, d as isTemplate, f as touch, g as supportedCssLangs, h as jsExtensions, i as findCssEntry, l as inlineAutoRoutesImports, m as configExtensions, n as extractConfigFromVue, o as findJsonEntry, s as findTemplateEntry, t as changeFileExtension, u as isJsOrTs, v as vueExtensions } from "./file-
|
|
4
|
+
import { _ as templateExtensions, a as findJsEntry, c as findVueEntry, d as isTemplate, f as touch, g as supportedCssLangs, h as jsExtensions, i as findCssEntry, l as inlineAutoRoutesImports, m as configExtensions, n as extractConfigFromVue, o as findJsonEntry, s as findTemplateEntry, t as changeFileExtension, u as isJsOrTs, v as vueExtensions } from "./file-DwwblEq4.mjs";
|
|
5
5
|
import { createRequire, isBuiltin } from "node:module";
|
|
6
6
|
import { addExtension, defu, get, isEmptyObject, isObject, objectHash, removeExtension, removeExtensionDeep, set } from "@weapp-core/shared";
|
|
7
7
|
import { LRUCache } from "lru-cache";
|
|
@@ -334,7 +334,7 @@ function getVueComponentsSettings(ctx) {
|
|
|
334
334
|
return { enabled: false };
|
|
335
335
|
}
|
|
336
336
|
//#endregion
|
|
337
|
-
//#region src/ast/
|
|
337
|
+
//#region src/ast/index.ts
|
|
338
338
|
/**
|
|
339
339
|
* 解析 AST 引擎配置。
|
|
340
340
|
*/
|
|
@@ -8824,6 +8824,10 @@ const SPECIAL_PACKAGE_ALIASES = [{
|
|
|
8824
8824
|
packageName: "class-variance-authority",
|
|
8825
8825
|
distEntry: "dist/index.js"
|
|
8826
8826
|
}];
|
|
8827
|
+
const SPECIFIER_ALIASES = [{
|
|
8828
|
+
find: "vue-demi",
|
|
8829
|
+
replacement: "wevu/vue-demi"
|
|
8830
|
+
}];
|
|
8827
8831
|
function resolveBuiltinPackageAliases() {
|
|
8828
8832
|
const aliases = [];
|
|
8829
8833
|
for (const { packageName, distEntry } of SPECIAL_PACKAGE_ALIASES) {
|
|
@@ -8836,6 +8840,7 @@ function resolveBuiltinPackageAliases() {
|
|
|
8836
8840
|
replacement: resolvedEntry
|
|
8837
8841
|
});
|
|
8838
8842
|
}
|
|
8843
|
+
aliases.push(...SPECIFIER_ALIASES);
|
|
8839
8844
|
return aliases;
|
|
8840
8845
|
}
|
|
8841
8846
|
//#endregion
|
|
@@ -8942,6 +8947,7 @@ function getWeappViteConfig() {
|
|
|
8942
8947
|
],
|
|
8943
8948
|
unhandledErrors: true
|
|
8944
8949
|
},
|
|
8950
|
+
injectRequestGlobals: {},
|
|
8945
8951
|
chunks: {
|
|
8946
8952
|
sharedStrategy: "duplicate",
|
|
8947
8953
|
sharedMode: "common",
|
|
@@ -10508,9 +10514,52 @@ function injectNativePageLayoutSetter(pageOptions) {
|
|
|
10508
10514
|
pageOptions.properties.push(t.objectMethod("method", createStaticObjectKey("__wevuSetPageLayout"), [t.identifier("layout"), t.identifier("props")], t.blockStatement([
|
|
10509
10515
|
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("__wv_next_layout_name"), t.conditionalExpression(t.binaryExpression("===", t.identifier("layout"), t.booleanLiteral(false)), t.stringLiteral("__wv_no_layout"), t.identifier("layout")))]),
|
|
10510
10516
|
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("__wv_next_layout_props"), t.conditionalExpression(t.binaryExpression("===", t.identifier("layout"), t.booleanLiteral(false)), t.objectExpression([]), t.logicalExpression("||", t.identifier("props"), t.objectExpression([]))))]),
|
|
10517
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("__wv_current_layout_name"), t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier("data")), t.identifier("__wv_page_layout_name")))]),
|
|
10518
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("__wv_current_layout_props"), t.logicalExpression("||", t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier("data")), t.identifier("__wv_page_layout_props")), t.objectExpression([])))]),
|
|
10519
|
+
t.ifStatement(t.logicalExpression("&&", t.binaryExpression("===", t.identifier("__wv_current_layout_name"), t.identifier("__wv_next_layout_name")), t.callExpression(t.memberExpression(t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("keys")), [t.identifier("__wv_current_layout_props")]), t.identifier("every")), [t.arrowFunctionExpression([t.identifier("__wv_key")], t.logicalExpression("&&", t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Object"), t.identifier("prototype")), t.identifier("hasOwnProperty")), t.identifier("call")), [t.identifier("__wv_next_layout_props"), t.identifier("__wv_key")]), t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("is")), [t.memberExpression(t.identifier("__wv_current_layout_props"), t.identifier("__wv_key"), true), t.memberExpression(t.identifier("__wv_next_layout_props"), t.identifier("__wv_key"), true)])))])), t.blockStatement([t.ifStatement(t.binaryExpression("===", t.memberExpression(t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("keys")), [t.identifier("__wv_current_layout_props")]), t.identifier("length")), t.memberExpression(t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("keys")), [t.identifier("__wv_next_layout_props")]), t.identifier("length"))), t.blockStatement([t.returnStatement()]))])),
|
|
10511
10520
|
t.expressionStatement(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier("setData")), [t.objectExpression([t.objectProperty(t.identifier("__wv_page_layout_name"), t.identifier("__wv_next_layout_name")), t.objectProperty(t.identifier("__wv_page_layout_props"), t.identifier("__wv_next_layout_props"))])]))
|
|
10512
10521
|
])));
|
|
10513
10522
|
}
|
|
10523
|
+
function toStaticLayoutValueExpression(value) {
|
|
10524
|
+
if (typeof value === "string") return t.stringLiteral(value);
|
|
10525
|
+
if (typeof value === "number") return t.numericLiteral(value);
|
|
10526
|
+
if (typeof value === "boolean") return t.booleanLiteral(value);
|
|
10527
|
+
if (value === null) return t.nullLiteral();
|
|
10528
|
+
return t.identifier("undefined");
|
|
10529
|
+
}
|
|
10530
|
+
function buildInitialNativePageLayoutState(currentLayout) {
|
|
10531
|
+
const layoutName = currentLayout?.layoutName;
|
|
10532
|
+
const layoutProps = currentLayout?.props ?? {};
|
|
10533
|
+
return t.objectExpression([t.objectProperty(t.identifier("__wv_page_layout_name"), layoutName ? t.stringLiteral(layoutName) : t.identifier("undefined")), t.objectProperty(t.identifier("__wv_page_layout_props"), t.objectExpression(Object.entries(layoutProps).filter(([, value]) => !(typeof value === "object" && value && "kind" in value && value.kind === "expression")).map(([key, value]) => t.objectProperty(createStaticObjectKey(key), toStaticLayoutValueExpression(value)))))]);
|
|
10534
|
+
}
|
|
10535
|
+
function buildInitialNativePageLayoutNameExpression(currentLayout) {
|
|
10536
|
+
return currentLayout?.layoutName ? t.stringLiteral(currentLayout.layoutName) : t.identifier("undefined");
|
|
10537
|
+
}
|
|
10538
|
+
function buildInitialNativePageLayoutPropsExpression(currentLayout) {
|
|
10539
|
+
const layoutProps = currentLayout?.props ?? {};
|
|
10540
|
+
return t.objectExpression(Object.entries(layoutProps).filter(([, value]) => !(typeof value === "object" && value && "kind" in value && value.kind === "expression")).map(([key, value]) => t.objectProperty(createStaticObjectKey(key), toStaticLayoutValueExpression(value))));
|
|
10541
|
+
}
|
|
10542
|
+
function injectNativePageLayoutState(pageOptions, currentLayout) {
|
|
10543
|
+
const initialState = buildInitialNativePageLayoutState(currentLayout);
|
|
10544
|
+
const existingData = getObjectPropertyByKey$1(pageOptions, "data");
|
|
10545
|
+
if (!existingData) {
|
|
10546
|
+
pageOptions.properties.unshift(t.objectProperty(createStaticObjectKey("data"), initialState));
|
|
10547
|
+
return;
|
|
10548
|
+
}
|
|
10549
|
+
if (t.isObjectExpression(existingData.value)) {
|
|
10550
|
+
const dataObject = existingData.value;
|
|
10551
|
+
const layoutNameProp = getObjectPropertyByKey$1(dataObject, "__wv_page_layout_name");
|
|
10552
|
+
const layoutPropsProp = getObjectPropertyByKey$1(dataObject, "__wv_page_layout_props");
|
|
10553
|
+
if (!layoutNameProp) dataObject.properties.unshift(t.objectProperty(t.identifier("__wv_page_layout_name"), buildInitialNativePageLayoutNameExpression(currentLayout)));
|
|
10554
|
+
if (!layoutPropsProp) dataObject.properties.push(t.objectProperty(t.identifier("__wv_page_layout_props"), buildInitialNativePageLayoutPropsExpression(currentLayout)));
|
|
10555
|
+
return;
|
|
10556
|
+
}
|
|
10557
|
+
existingData.value = t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("assign")), [
|
|
10558
|
+
t.objectExpression([]),
|
|
10559
|
+
existingData.value,
|
|
10560
|
+
initialState
|
|
10561
|
+
]);
|
|
10562
|
+
}
|
|
10514
10563
|
function injectLayoutBindingComputed(script, props) {
|
|
10515
10564
|
if (!script || !props) return script;
|
|
10516
10565
|
const runtimeEntries = Object.entries(props).filter((entry) => typeof entry[1] === "object" && entry[1] !== null && "kind" in entry[1] && entry[1].kind === "expression");
|
|
@@ -10585,6 +10634,7 @@ function injectNativePageLayoutRuntime(script, filename, plan) {
|
|
|
10585
10634
|
if (!shouldInjectSetter) return generate(ast, { retainLines: true }).code;
|
|
10586
10635
|
const pageOptions = findNativePageOptionsObject(ast);
|
|
10587
10636
|
if (!pageOptions) throw new Error(`${filename} 中未找到可注入 layout 运行时的 Page({}) 定义。`);
|
|
10637
|
+
injectNativePageLayoutState(pageOptions, plan?.currentLayout);
|
|
10588
10638
|
injectNativePageLayoutSetter(pageOptions);
|
|
10589
10639
|
return generate(ast, { retainLines: true }).code;
|
|
10590
10640
|
}
|
|
@@ -12479,6 +12529,140 @@ async function flushIndependentBuilds(state) {
|
|
|
12479
12529
|
state.pendingIndependentBuilds = [];
|
|
12480
12530
|
}
|
|
12481
12531
|
//#endregion
|
|
12532
|
+
//#region src/runtime/config/internal/injectRequestGlobals.ts
|
|
12533
|
+
const FULL_REQUEST_GLOBAL_TARGETS = [
|
|
12534
|
+
"fetch",
|
|
12535
|
+
"Headers",
|
|
12536
|
+
"Request",
|
|
12537
|
+
"Response",
|
|
12538
|
+
"AbortController",
|
|
12539
|
+
"AbortSignal",
|
|
12540
|
+
"XMLHttpRequest"
|
|
12541
|
+
];
|
|
12542
|
+
const ABORT_REQUEST_GLOBAL_TARGETS = ["AbortController", "AbortSignal"];
|
|
12543
|
+
const DEFAULT_REQUEST_GLOBAL_DEPENDENCIES = ["axios", "graphql-request"];
|
|
12544
|
+
const DEFAULT_ABORT_GLOBAL_DEPENDENCIES = ["@tanstack/query-core", "@tanstack/vue-query"];
|
|
12545
|
+
const REQUEST_GLOBAL_FREE_BINDING_TARGETS$1 = new Set([
|
|
12546
|
+
...FULL_REQUEST_GLOBAL_TARGETS,
|
|
12547
|
+
"URL",
|
|
12548
|
+
"URLSearchParams",
|
|
12549
|
+
"Blob",
|
|
12550
|
+
"FormData"
|
|
12551
|
+
]);
|
|
12552
|
+
function hasMatchedDependency(packageJson, patterns) {
|
|
12553
|
+
return [...new Set([
|
|
12554
|
+
...Object.keys(packageJson?.dependencies ?? {}),
|
|
12555
|
+
...Object.keys(packageJson?.devDependencies ?? {}),
|
|
12556
|
+
...Object.keys(packageJson?.peerDependencies ?? {})
|
|
12557
|
+
])].some((dependency) => {
|
|
12558
|
+
return patterns.some((pattern) => {
|
|
12559
|
+
if (typeof pattern === "string") return pattern === dependency;
|
|
12560
|
+
pattern.lastIndex = 0;
|
|
12561
|
+
return pattern.test(dependency);
|
|
12562
|
+
});
|
|
12563
|
+
});
|
|
12564
|
+
}
|
|
12565
|
+
function resolveTargets(config) {
|
|
12566
|
+
if (config && typeof config === "object" && Array.isArray(config.targets) && config.targets.length > 0) return [...new Set(config.targets)];
|
|
12567
|
+
return [...FULL_REQUEST_GLOBAL_TARGETS];
|
|
12568
|
+
}
|
|
12569
|
+
function resolveDependencyPatterns(config) {
|
|
12570
|
+
if (config && typeof config === "object" && Array.isArray(config.dependencies) && config.dependencies.length > 0) return config.dependencies;
|
|
12571
|
+
return DEFAULT_REQUEST_GLOBAL_DEPENDENCIES;
|
|
12572
|
+
}
|
|
12573
|
+
function hasCustomAutoRuleConfig(config) {
|
|
12574
|
+
if (!config || typeof config !== "object") return false;
|
|
12575
|
+
return Boolean(Array.isArray(config.dependencies) && config.dependencies.length > 0 || Array.isArray(config.targets) && config.targets.length > 0);
|
|
12576
|
+
}
|
|
12577
|
+
function resolveAutoRules(config) {
|
|
12578
|
+
if (hasCustomAutoRuleConfig(config)) return [{
|
|
12579
|
+
dependencyPatterns: resolveDependencyPatterns(config),
|
|
12580
|
+
targets: resolveTargets(config)
|
|
12581
|
+
}];
|
|
12582
|
+
return [{
|
|
12583
|
+
dependencyPatterns: DEFAULT_REQUEST_GLOBAL_DEPENDENCIES,
|
|
12584
|
+
targets: [...FULL_REQUEST_GLOBAL_TARGETS]
|
|
12585
|
+
}, {
|
|
12586
|
+
dependencyPatterns: DEFAULT_ABORT_GLOBAL_DEPENDENCIES,
|
|
12587
|
+
targets: [...ABORT_REQUEST_GLOBAL_TARGETS]
|
|
12588
|
+
}];
|
|
12589
|
+
}
|
|
12590
|
+
/**
|
|
12591
|
+
* @description 解析按需注入请求相关全局对象的最终配置。
|
|
12592
|
+
*/
|
|
12593
|
+
function resolveInjectRequestGlobalsOptions(config, packageJson) {
|
|
12594
|
+
if (config === false) return null;
|
|
12595
|
+
if (config && typeof config === "object" && config.enabled === false) return null;
|
|
12596
|
+
if ((config && typeof config === "object" ? config.enabled : config) === true) return {
|
|
12597
|
+
mode: "explicit",
|
|
12598
|
+
targets: resolveTargets(config),
|
|
12599
|
+
dependencyPatterns: resolveDependencyPatterns(config)
|
|
12600
|
+
};
|
|
12601
|
+
const autoRules = resolveAutoRules(config);
|
|
12602
|
+
const matchedTargets = /* @__PURE__ */ new Set();
|
|
12603
|
+
for (const rule of autoRules) {
|
|
12604
|
+
if (!hasMatchedDependency(packageJson, rule.dependencyPatterns)) continue;
|
|
12605
|
+
for (const target of rule.targets) matchedTargets.add(target);
|
|
12606
|
+
}
|
|
12607
|
+
if (matchedTargets.size === 0) return null;
|
|
12608
|
+
return {
|
|
12609
|
+
mode: "auto",
|
|
12610
|
+
targets: [...matchedTargets]
|
|
12611
|
+
};
|
|
12612
|
+
}
|
|
12613
|
+
function resolveRequestGlobalsRuntimeModuleId() {
|
|
12614
|
+
return "weapp-vite/web-apis";
|
|
12615
|
+
}
|
|
12616
|
+
function resolveRequestGlobalsBindingTargets$1(targets) {
|
|
12617
|
+
const bindingTargets = [...targets];
|
|
12618
|
+
if (targets.some((target) => target === "fetch" || target === "Request" || target === "Response" || target === "XMLHttpRequest")) bindingTargets.push("URL", "URLSearchParams", "Blob", "FormData");
|
|
12619
|
+
return [...new Set(bindingTargets)].filter((target) => REQUEST_GLOBAL_FREE_BINDING_TARGETS$1.has(target));
|
|
12620
|
+
}
|
|
12621
|
+
/**
|
|
12622
|
+
* @description 生成入口文件用的请求全局对象注入代码。
|
|
12623
|
+
*/
|
|
12624
|
+
function createInjectRequestGlobalsCode(targets, options) {
|
|
12625
|
+
const runtimeModuleId = resolveRequestGlobalsRuntimeModuleId();
|
|
12626
|
+
const lines = [`import { installRequestGlobals as __weappViteInstallRequestGlobals } from ${JSON.stringify(runtimeModuleId)}`];
|
|
12627
|
+
if (options?.localBindings) {
|
|
12628
|
+
const bindingTargets = resolveRequestGlobalsBindingTargets$1(targets);
|
|
12629
|
+
lines.push(`const __weappViteRequestGlobalsHost__ = __weappViteInstallRequestGlobals({ targets: ${JSON.stringify(targets)} }) || globalThis`, ...bindingTargets.map((target) => `var ${target} = __weappViteRequestGlobalsHost__.${target}`));
|
|
12630
|
+
} else lines.push(`__weappViteInstallRequestGlobals({ targets: ${JSON.stringify(targets)} })`);
|
|
12631
|
+
lines.push("");
|
|
12632
|
+
return lines.join("\n");
|
|
12633
|
+
}
|
|
12634
|
+
/**
|
|
12635
|
+
* @description 为 Vue SFC 入口生成合法的请求全局注入脚本块。
|
|
12636
|
+
*/
|
|
12637
|
+
function createInjectRequestGlobalsSfcCode(targets, options) {
|
|
12638
|
+
return `<script${options?.setup ? " setup lang=\"ts\"" : " lang=\"ts\""}>\n${createInjectRequestGlobalsCode(targets, options)}<\/script>\n`;
|
|
12639
|
+
}
|
|
12640
|
+
function injectCodeIntoSfcBlock(source, startOffset, injection) {
|
|
12641
|
+
return `${source.slice(0, startOffset)}${injection}${source.slice(startOffset)}`;
|
|
12642
|
+
}
|
|
12643
|
+
/**
|
|
12644
|
+
* @description 将请求全局对象注入到现有 SFC 脚本块,避免生成额外的重复 `<script>`。
|
|
12645
|
+
*/
|
|
12646
|
+
function injectRequestGlobalsIntoSfc(source, targets, options) {
|
|
12647
|
+
if (targets.length === 0) return source;
|
|
12648
|
+
const injection = createInjectRequestGlobalsCode(targets, options);
|
|
12649
|
+
const { descriptor, errors } = parse(source, {
|
|
12650
|
+
filename: "request-globals.vue",
|
|
12651
|
+
ignoreEmpty: false
|
|
12652
|
+
});
|
|
12653
|
+
if (errors.length > 0) return `${createInjectRequestGlobalsSfcCode(targets, options)}${source}`;
|
|
12654
|
+
const inlineScript = descriptor.script && !descriptor.script.src ? descriptor.script : void 0;
|
|
12655
|
+
if (inlineScript) return injectCodeIntoSfcBlock(source, inlineScript.loc.start.offset, injection);
|
|
12656
|
+
const inlineScriptSetup = descriptor.scriptSetup && !descriptor.scriptSetup.src ? descriptor.scriptSetup : void 0;
|
|
12657
|
+
if (inlineScriptSetup) return injectCodeIntoSfcBlock(source, inlineScriptSetup.loc.start.offset, injection);
|
|
12658
|
+
if (!descriptor.script) return `${createInjectRequestGlobalsSfcCode(targets, options)}${source}`;
|
|
12659
|
+
if (!descriptor.scriptSetup) return `${createInjectRequestGlobalsSfcCode(targets, {
|
|
12660
|
+
...options,
|
|
12661
|
+
setup: true
|
|
12662
|
+
})}${source}`;
|
|
12663
|
+
return source;
|
|
12664
|
+
}
|
|
12665
|
+
//#endregion
|
|
12482
12666
|
//#region src/utils/weapi.ts
|
|
12483
12667
|
function getWeapiGlobalHostCandidates() {
|
|
12484
12668
|
return [
|
|
@@ -12526,6 +12710,26 @@ const platformApiIdentifiers = new Set([
|
|
|
12526
12710
|
const NPM_PROTOCOL_RE = /^npm:/;
|
|
12527
12711
|
const ABSOLUTE_NPM_PREFIX_RE = /^\/(?:miniprogram_npm|node_modules)\//;
|
|
12528
12712
|
const PRETTY_NODE_MODULES_RE = /node_modules\/(?:\.pnpm\/[^/]+\/node_modules\/)?(.+)/;
|
|
12713
|
+
const REQUEST_GLOBAL_EXPORT_RE = /Object\.defineProperty\(exports,\s*(?:`([^`]+)`|'([^']+)'|"([^"]+)"),\s*\{[\s\S]*?get:function\(\)\{return ([A-Za-z_$][\w$]*)\}\}\)/g;
|
|
12714
|
+
const REQUEST_GLOBAL_INSTALLER_RE = /function\s+([A-Za-z_$][\w$]*)\([^)]*=\{\}\)\{[\s\S]{0,200}?targets\?\?\[[\s\S]{0,80}?fetch[\s\S]{0,80}?Headers[\s\S]{0,80}?Request[\s\S]{0,80}?Response[\s\S]{0,80}?AbortController[\s\S]{0,80}?AbortSignal[\s\S]{0,80}?XMLHttpRequest[\s\S]{0,240}?return [^}]+\}/;
|
|
12715
|
+
const REQUEST_GLOBAL_ENTRY_NAME_RE = /\.[^/.]+$/;
|
|
12716
|
+
const REQUEST_GLOBAL_REQUIRE_RE = /^(const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*require\((`([^`]+)`|'([^']+)'|"([^"]+)")\);?/;
|
|
12717
|
+
const REQUEST_GLOBAL_TARGET_SIGNATURES = [
|
|
12718
|
+
"fetch",
|
|
12719
|
+
"Headers",
|
|
12720
|
+
"Request",
|
|
12721
|
+
"Response",
|
|
12722
|
+
"AbortController",
|
|
12723
|
+
"AbortSignal",
|
|
12724
|
+
"XMLHttpRequest"
|
|
12725
|
+
];
|
|
12726
|
+
const REQUEST_GLOBAL_FREE_BINDING_TARGETS = new Set([
|
|
12727
|
+
...REQUEST_GLOBAL_TARGET_SIGNATURES,
|
|
12728
|
+
"URL",
|
|
12729
|
+
"URLSearchParams",
|
|
12730
|
+
"Blob",
|
|
12731
|
+
"FormData"
|
|
12732
|
+
]);
|
|
12529
12733
|
function resolveInjectWeapiGlobalName(state) {
|
|
12530
12734
|
const injectWeapi = state.ctx.configService.weappViteConfig?.injectWeapi;
|
|
12531
12735
|
if (!injectWeapi) return null;
|
|
@@ -12645,6 +12849,9 @@ function getRequireImportLiteral(node) {
|
|
|
12645
12849
|
if (node.type === "TemplateLiteral" && node.expressions?.length === 0 && node.quasis?.length === 1) return node.quasis[0]?.value?.cooked ?? null;
|
|
12646
12850
|
return null;
|
|
12647
12851
|
}
|
|
12852
|
+
function getStaticStringLiteral(node) {
|
|
12853
|
+
return getRequireImportLiteral(node);
|
|
12854
|
+
}
|
|
12648
12855
|
function setRequireImportLiteral(node, nextValue) {
|
|
12649
12856
|
if (!node) return;
|
|
12650
12857
|
if (node.type === "StringLiteral" || node.type === "Literal") {
|
|
@@ -12656,6 +12863,119 @@ function setRequireImportLiteral(node, nextValue) {
|
|
|
12656
12863
|
node.quasis[0].value.cooked = nextValue;
|
|
12657
12864
|
}
|
|
12658
12865
|
}
|
|
12866
|
+
function resolveRequestGlobalsInstallerName(code) {
|
|
12867
|
+
const installerMatch = code.match(REQUEST_GLOBAL_INSTALLER_RE);
|
|
12868
|
+
if (installerMatch?.[1]) return installerMatch[1];
|
|
12869
|
+
try {
|
|
12870
|
+
const ast = parseJsLike(code);
|
|
12871
|
+
let installerName = null;
|
|
12872
|
+
const isInstallerFunctionNode = (node) => {
|
|
12873
|
+
if (!node) return false;
|
|
12874
|
+
const functionCode = generate(node).code;
|
|
12875
|
+
return REQUEST_GLOBAL_TARGET_SIGNATURES.every((target) => functionCode.includes(target));
|
|
12876
|
+
};
|
|
12877
|
+
traverse(ast, {
|
|
12878
|
+
FunctionDeclaration(path) {
|
|
12879
|
+
if (installerName || !path.node?.id?.name) return;
|
|
12880
|
+
if (isInstallerFunctionNode(path.node.body)) installerName = path.node.id.name;
|
|
12881
|
+
},
|
|
12882
|
+
VariableDeclarator(path) {
|
|
12883
|
+
if (installerName || path.node?.id?.type !== "Identifier") return;
|
|
12884
|
+
const init = path.node.init;
|
|
12885
|
+
if (!init || init.type !== "FunctionExpression" && init.type !== "ArrowFunctionExpression") return;
|
|
12886
|
+
if (isInstallerFunctionNode(init.body)) installerName = path.node.id.name;
|
|
12887
|
+
}
|
|
12888
|
+
});
|
|
12889
|
+
return installerName;
|
|
12890
|
+
} catch {
|
|
12891
|
+
return null;
|
|
12892
|
+
}
|
|
12893
|
+
}
|
|
12894
|
+
function resolveRequestGlobalsExportName(code) {
|
|
12895
|
+
const installerName = resolveRequestGlobalsInstallerName(code);
|
|
12896
|
+
if (!installerName) return null;
|
|
12897
|
+
for (const match of code.matchAll(REQUEST_GLOBAL_EXPORT_RE)) {
|
|
12898
|
+
const candidateExportName = match[1] ?? match[2] ?? match[3];
|
|
12899
|
+
const returnedIdentifier = match[4];
|
|
12900
|
+
if (candidateExportName && returnedIdentifier === installerName) return candidateExportName;
|
|
12901
|
+
}
|
|
12902
|
+
try {
|
|
12903
|
+
const ast = parseJsLike(code);
|
|
12904
|
+
let exportName = null;
|
|
12905
|
+
traverse(ast, { CallExpression(path) {
|
|
12906
|
+
if (exportName) return;
|
|
12907
|
+
const callee = path.node?.callee;
|
|
12908
|
+
if (!callee || callee.type !== "MemberExpression" || callee.object?.type !== "Identifier" || callee.object.name !== "Object" || callee.property?.type !== "Identifier" || callee.property.name !== "defineProperty") return;
|
|
12909
|
+
const args = path.node.arguments;
|
|
12910
|
+
if (!Array.isArray(args) || args.length < 3) return;
|
|
12911
|
+
if (args[0]?.type !== "Identifier" || args[0].name !== "exports") return;
|
|
12912
|
+
const candidateExportName = getStaticStringLiteral(args[1]);
|
|
12913
|
+
if (!candidateExportName || args[2]?.type !== "ObjectExpression") return;
|
|
12914
|
+
const getterProperty = args[2].properties.find((property) => {
|
|
12915
|
+
return property?.type === "ObjectProperty" && property.key?.type === "Identifier" && property.key.name === "get" || property?.type === "ObjectMethod" && property.key?.type === "Identifier" && property.key.name === "get";
|
|
12916
|
+
});
|
|
12917
|
+
const getterValue = getterProperty?.type === "ObjectMethod" ? getterProperty : getterProperty?.value;
|
|
12918
|
+
if (!getterValue) return;
|
|
12919
|
+
const getterBody = getterValue.body;
|
|
12920
|
+
const returnIdentifier = getterBody?.type === "BlockStatement" ? getterBody.body.find((statement) => statement?.type === "ReturnStatement")?.argument : getterBody;
|
|
12921
|
+
if (returnIdentifier?.type === "Identifier" && returnIdentifier.name === installerName) exportName = candidateExportName;
|
|
12922
|
+
} });
|
|
12923
|
+
return exportName;
|
|
12924
|
+
} catch {
|
|
12925
|
+
return null;
|
|
12926
|
+
}
|
|
12927
|
+
}
|
|
12928
|
+
function normalizeRelativeChunkImport(fileName, importee) {
|
|
12929
|
+
return toPosixPath(path.normalize(path.join(path.dirname(fileName), importee)));
|
|
12930
|
+
}
|
|
12931
|
+
function resolveRequestGlobalsBindingTargets(targets) {
|
|
12932
|
+
const bindingTargets = [...targets];
|
|
12933
|
+
if (targets.some((target) => target === "fetch" || target === "Request" || target === "Response" || target === "XMLHttpRequest")) bindingTargets.push("URL", "URLSearchParams", "Blob", "FormData");
|
|
12934
|
+
return [...new Set(bindingTargets)].filter((target) => REQUEST_GLOBAL_FREE_BINDING_TARGETS.has(target));
|
|
12935
|
+
}
|
|
12936
|
+
function injectRequestGlobalsBundleRuntime(bundle, targets) {
|
|
12937
|
+
const installerChunks = /* @__PURE__ */ new Map();
|
|
12938
|
+
if (targets.length === 0) return installerChunks;
|
|
12939
|
+
const bindingTargets = resolveRequestGlobalsBindingTargets(targets);
|
|
12940
|
+
for (const output of Object.values(bundle)) {
|
|
12941
|
+
if (output?.type !== "chunk") continue;
|
|
12942
|
+
const chunk = output;
|
|
12943
|
+
if (chunk.code.includes("__weappViteRequestGlobalsBundleInstalled__")) continue;
|
|
12944
|
+
const installerName = resolveRequestGlobalsInstallerName(chunk.code);
|
|
12945
|
+
const exportName = resolveRequestGlobalsExportName(chunk.code);
|
|
12946
|
+
if (!installerName || !exportName) continue;
|
|
12947
|
+
installerChunks.set(toPosixPath(chunk.fileName), exportName);
|
|
12948
|
+
const placeholderCode = bindingTargets.map((target) => {
|
|
12949
|
+
return `var ${target} = typeof globalThis.${target} !== "undefined" ? globalThis.${target} : ${target === "fetch" ? "function __weappViteFetchPlaceholder__(){throw new Error(\"fetch is not initialized\")}" : `function ${target}(){}`}`;
|
|
12950
|
+
}).join(";");
|
|
12951
|
+
const runtimeBindingCode = [`const __weappViteRequestGlobalsBundleHost__ = ${installerName}({ targets: ${JSON.stringify(targets)} }) || globalThis`, ...bindingTargets.map((target) => `${target} = __weappViteRequestGlobalsBundleHost__.${target}`)].join(";");
|
|
12952
|
+
chunk.code = `/* __weappViteRequestGlobalsBundleInstalled__ */ ${placeholderCode};\n${chunk.code}\n;${runtimeBindingCode};\n`;
|
|
12953
|
+
}
|
|
12954
|
+
return installerChunks;
|
|
12955
|
+
}
|
|
12956
|
+
function injectRequestGlobalsLocalBindings(bundle, installerChunks, targets, entriesMap) {
|
|
12957
|
+
if (installerChunks.size === 0 || targets.length === 0) return;
|
|
12958
|
+
const bindingTargets = resolveRequestGlobalsBindingTargets(targets);
|
|
12959
|
+
if (bindingTargets.length === 0) return;
|
|
12960
|
+
for (const output of Object.values(bundle)) {
|
|
12961
|
+
if (output?.type !== "chunk") continue;
|
|
12962
|
+
const chunk = output;
|
|
12963
|
+
const entryName = chunk.fileName.replace(REQUEST_GLOBAL_ENTRY_NAME_RE, "");
|
|
12964
|
+
const entryType = entriesMap?.get(entryName)?.type;
|
|
12965
|
+
if (entryType !== "page" && entryType !== "component") continue;
|
|
12966
|
+
if (chunk.code.includes("__weappViteRequestGlobalsLocalBindings__")) continue;
|
|
12967
|
+
if (chunk.code.includes("__weappViteRequestGlobalsHost__") || chunk.code.includes("__weappViteInstallRequestGlobals")) continue;
|
|
12968
|
+
const requireMatch = chunk.code.match(REQUEST_GLOBAL_REQUIRE_RE);
|
|
12969
|
+
const requireAlias = requireMatch?.[2];
|
|
12970
|
+
const importee = requireMatch?.[4] ?? requireMatch?.[5] ?? requireMatch?.[6];
|
|
12971
|
+
if (!requireAlias || !importee) continue;
|
|
12972
|
+
const installerChunkFileName = normalizeRelativeChunkImport(chunk.fileName, importee);
|
|
12973
|
+
const exportName = installerChunks.get(installerChunkFileName);
|
|
12974
|
+
if (!exportName) continue;
|
|
12975
|
+
const injectionCode = [`const __weappViteRequestGlobalsHost__ = ${requireAlias}[${JSON.stringify(exportName)}]({ targets: ${JSON.stringify(targets)} }) || globalThis`, ...bindingTargets.map((target) => `var ${target} = __weappViteRequestGlobalsHost__.${target}`)].join(";");
|
|
12976
|
+
chunk.code = chunk.code.replace(REQUEST_GLOBAL_REQUIRE_RE, (match) => `${match};/* __weappViteRequestGlobalsLocalBindings__ */ ${injectionCode};`);
|
|
12977
|
+
}
|
|
12978
|
+
}
|
|
12659
12979
|
function toRelativeRuntimeNpmImport(fileName, root, importee) {
|
|
12660
12980
|
const normalized = normalizeWeappLocalNpmImport(importee);
|
|
12661
12981
|
const target = root ? `${root}/miniprogram_npm/${normalized}` : `miniprogram_npm/${normalized}`;
|
|
@@ -12727,6 +13047,7 @@ function createGenerateBundleHook(state, isPluginBuild) {
|
|
|
12727
13047
|
const { ctx, subPackageMeta } = state;
|
|
12728
13048
|
const { scanService, configService } = ctx;
|
|
12729
13049
|
const astEngine = resolveAstEngine(configService.weappViteConfig);
|
|
13050
|
+
const injectRequestGlobalsOptions = resolveInjectRequestGlobalsOptions(configService.weappViteConfig?.injectRequestGlobals, configService.packageJson);
|
|
12730
13051
|
return async function generateBundle(_options, bundle) {
|
|
12731
13052
|
const rolldownBundle = bundle;
|
|
12732
13053
|
await flushIndependentBuilds.call(this, state);
|
|
@@ -12857,6 +13178,7 @@ function createGenerateBundleHook(state, isPluginBuild) {
|
|
|
12857
13178
|
}
|
|
12858
13179
|
const injectWeapiGlobalName = resolveInjectWeapiGlobalName(state);
|
|
12859
13180
|
if (injectWeapiGlobalName) rewriteBundlePlatformApi(rolldownBundle, injectWeapiGlobalName, { astEngine });
|
|
13181
|
+
if (injectRequestGlobalsOptions?.targets?.length) injectRequestGlobalsLocalBindings(rolldownBundle, injectRequestGlobalsBundleRuntime(rolldownBundle, injectRequestGlobalsOptions.targets), injectRequestGlobalsOptions.targets, state.entriesMap);
|
|
12860
13182
|
refreshModuleGraph(this, state);
|
|
12861
13183
|
if (configService.weappViteConfig?.debug?.watchFiles) {
|
|
12862
13184
|
const watcherService = ctx.watcherService;
|
|
@@ -13002,6 +13324,7 @@ function createLoadHook(state) {
|
|
|
13002
13324
|
checked: false,
|
|
13003
13325
|
available: false
|
|
13004
13326
|
};
|
|
13327
|
+
const injectRequestGlobalsOptions = resolveInjectRequestGlobalsOptions(configService.weappViteConfig?.injectRequestGlobals, configService.packageJson);
|
|
13005
13328
|
function resolveInjectWeapiOptions() {
|
|
13006
13329
|
const injectWeapi = configService.weappViteConfig?.injectWeapi;
|
|
13007
13330
|
if (!injectWeapi) return null;
|
|
@@ -13088,6 +13411,25 @@ function createLoadHook(state) {
|
|
|
13088
13411
|
code: replacedCode
|
|
13089
13412
|
};
|
|
13090
13413
|
}
|
|
13414
|
+
function prependCodeToLoadResult(result, code) {
|
|
13415
|
+
if (!result || typeof result !== "object" || !("code" in result) || typeof result.code !== "string") return result;
|
|
13416
|
+
return {
|
|
13417
|
+
...result,
|
|
13418
|
+
code: `${code}${result.code}`
|
|
13419
|
+
};
|
|
13420
|
+
}
|
|
13421
|
+
function resolveRequestGlobalsTargets() {
|
|
13422
|
+
if (!injectRequestGlobalsOptions) return [];
|
|
13423
|
+
return injectRequestGlobalsOptions.targets;
|
|
13424
|
+
}
|
|
13425
|
+
function injectRequestGlobalsIntoLoadResult(result, sourceId, targets, options) {
|
|
13426
|
+
if (!result || typeof result !== "object" || !("code" in result) || typeof result.code !== "string" || targets.length === 0) return result;
|
|
13427
|
+
if (sourceId.endsWith(".vue")) return {
|
|
13428
|
+
...result,
|
|
13429
|
+
code: injectRequestGlobalsIntoSfc(result.code, targets, options)
|
|
13430
|
+
};
|
|
13431
|
+
return prependCodeToLoadResult(result, createInjectRequestGlobalsCode(targets, options));
|
|
13432
|
+
}
|
|
13091
13433
|
async function ensureWeapiAvailable(pluginCtx, importer) {
|
|
13092
13434
|
if (weapiResolution.checked) return weapiResolution.available;
|
|
13093
13435
|
weapiResolution.checked = true;
|
|
@@ -13123,32 +13465,42 @@ function createLoadHook(state) {
|
|
|
13123
13465
|
}
|
|
13124
13466
|
const sourceId = normalizeFsResolvedId(id);
|
|
13125
13467
|
const injectOptions = resolveInjectWeapiOptions();
|
|
13126
|
-
if (configService.weappLibConfig?.enabled ? ctx.runtimeState.lib.entries.get(sourceId) : void 0)
|
|
13468
|
+
if (configService.weappLibConfig?.enabled ? ctx.runtimeState.lib.entries.get(sourceId) : void 0) {
|
|
13469
|
+
const result = await loadEntry.call(this, sourceId, "component");
|
|
13470
|
+
const requestGlobalsTargets = resolveRequestGlobalsTargets();
|
|
13471
|
+
if (requestGlobalsTargets.length === 0) return result;
|
|
13472
|
+
return injectRequestGlobalsIntoLoadResult(result, sourceId, requestGlobalsTargets, { localBindings: true });
|
|
13473
|
+
}
|
|
13127
13474
|
const relativeBasename = removeExtensionDeep(configService.relativeAbsoluteSrcRoot(sourceId));
|
|
13128
13475
|
if (relativeBasename === resolveRootEntryBasename()) {
|
|
13129
13476
|
const result = await loadEntry.call(this, sourceId, "app");
|
|
13130
|
-
|
|
13131
|
-
if (!
|
|
13477
|
+
const requestGlobalsTargets = resolveRequestGlobalsTargets();
|
|
13478
|
+
if (!injectOptions || configService.weappLibConfig?.enabled) return injectRequestGlobalsIntoLoadResult(result, sourceId, requestGlobalsTargets);
|
|
13479
|
+
if (!await ensureWeapiAvailable(this, sourceId)) return injectRequestGlobalsIntoLoadResult(result, sourceId, requestGlobalsTargets);
|
|
13132
13480
|
if (result && typeof result === "object" && "code" in result) {
|
|
13133
|
-
const
|
|
13481
|
+
const requestGlobalsInjectedResult = injectRequestGlobalsIntoLoadResult(result, sourceId, requestGlobalsTargets);
|
|
13482
|
+
const platform = getMiniProgramPlatformGlobalKey(configService.platform) ?? "";
|
|
13134
13483
|
const injectedCode = createWeapiInjectionCode({
|
|
13135
13484
|
globalName: injectOptions.globalName,
|
|
13136
13485
|
replaceWx: injectOptions.replaceWx,
|
|
13137
13486
|
platform
|
|
13138
13487
|
});
|
|
13139
13488
|
return replacePlatformApiInLoadResult({
|
|
13140
|
-
...
|
|
13141
|
-
code: `${injectedCode}${
|
|
13489
|
+
...requestGlobalsInjectedResult,
|
|
13490
|
+
code: `${injectedCode}${requestGlobalsInjectedResult.code}`
|
|
13142
13491
|
}, injectOptions, this);
|
|
13143
13492
|
}
|
|
13144
13493
|
return result;
|
|
13145
13494
|
}
|
|
13146
|
-
|
|
13147
|
-
|
|
13495
|
+
const declaredEntryType = state.entriesMap?.get(relativeBasename)?.type;
|
|
13496
|
+
const isDeclaredEntry = Boolean(declaredEntryType);
|
|
13497
|
+
if (loadedEntrySet.has(sourceId) || isDeclaredEntry || subPackageMeta?.entries.includes(relativeBasename)) {
|
|
13498
|
+
const loadType = declaredEntryType === "page" ? "page" : "component";
|
|
13148
13499
|
const result = await loadEntry.call(this, sourceId, loadType);
|
|
13149
|
-
|
|
13150
|
-
if (!
|
|
13151
|
-
return
|
|
13500
|
+
const requestGlobalsTargets = resolveRequestGlobalsTargets();
|
|
13501
|
+
if (!injectOptions || !injectOptions.replaceWx || configService.weappLibConfig?.enabled) return injectRequestGlobalsIntoLoadResult(result, sourceId, requestGlobalsTargets, { localBindings: true });
|
|
13502
|
+
if (!await ensureWeapiAvailable(this, sourceId)) return injectRequestGlobalsIntoLoadResult(result, sourceId, requestGlobalsTargets, { localBindings: true });
|
|
13503
|
+
return injectRequestGlobalsIntoLoadResult(replacePlatformApiInLoadResult(result, injectOptions, this), sourceId, requestGlobalsTargets, { localBindings: true });
|
|
13152
13504
|
}
|
|
13153
13505
|
};
|
|
13154
13506
|
}
|
|
@@ -13162,6 +13514,8 @@ function resolveInjectWeapiOptions(configService) {
|
|
|
13162
13514
|
return { globalName: injectWeapi.globalName?.trim() || "wpi" };
|
|
13163
13515
|
}
|
|
13164
13516
|
function shouldTransformId(id, absoluteSrcRoot) {
|
|
13517
|
+
if (isCSSRequest(id)) return false;
|
|
13518
|
+
if (parseRequest(id).query.type === "style") return false;
|
|
13165
13519
|
const sourceId = normalizeFsResolvedId(id);
|
|
13166
13520
|
if (!sourceId || sourceId.includes("/node_modules/")) return false;
|
|
13167
13521
|
if (sourceId === absoluteSrcRoot) return true;
|
|
@@ -13198,11 +13552,30 @@ function replacePlatformApiAccess(code, globalName, options) {
|
|
|
13198
13552
|
function createTransformHook(state) {
|
|
13199
13553
|
const { configService } = state.ctx;
|
|
13200
13554
|
const astEngine = resolveAstEngine(configService.weappViteConfig);
|
|
13555
|
+
const injectRequestGlobalsOptions = resolveInjectRequestGlobalsOptions(configService.weappViteConfig?.injectRequestGlobals, configService.packageJson);
|
|
13556
|
+
function resolveRequestGlobalsTransformCode(id, code) {
|
|
13557
|
+
if (!injectRequestGlobalsOptions?.targets?.length) return null;
|
|
13558
|
+
if (code.includes("__weappViteInstallRequestGlobals")) return null;
|
|
13559
|
+
const sourceId = normalizeFsResolvedId(id);
|
|
13560
|
+
if (!sourceId) return null;
|
|
13561
|
+
const relativeBasename = removeExtensionDeep(configService.relativeAbsoluteSrcRoot(sourceId));
|
|
13562
|
+
const declaredEntryType = state.entriesMap?.get(relativeBasename)?.type;
|
|
13563
|
+
const isLoadedEntry = state.loadedEntrySet?.has(sourceId) === true;
|
|
13564
|
+
const isRootEntry = relativeBasename === "app";
|
|
13565
|
+
if (!isLoadedEntry && declaredEntryType !== "page" && declaredEntryType !== "component") return null;
|
|
13566
|
+
if (isLoadedEntry && isRootEntry) return null;
|
|
13567
|
+
if (sourceId.endsWith(".vue") && code.includes("<")) return injectRequestGlobalsIntoSfc(code, injectRequestGlobalsOptions.targets, { localBindings: true });
|
|
13568
|
+
return `${createInjectRequestGlobalsCode(injectRequestGlobalsOptions.targets, { localBindings: true })}${code}`;
|
|
13569
|
+
}
|
|
13201
13570
|
return async function transform(code, id) {
|
|
13202
13571
|
const injectOptions = resolveInjectWeapiOptions(configService);
|
|
13203
|
-
if (!injectOptions) return null;
|
|
13204
13572
|
if (!shouldTransformId(id, configService.absoluteSrcRoot)) return null;
|
|
13205
|
-
const
|
|
13573
|
+
const nextCode = resolveRequestGlobalsTransformCode(id, code) ?? code;
|
|
13574
|
+
if (!injectOptions) return nextCode === code ? null : {
|
|
13575
|
+
code: nextCode,
|
|
13576
|
+
map: null
|
|
13577
|
+
};
|
|
13578
|
+
const replaced = replacePlatformApiAccess(nextCode, injectOptions.globalName, {
|
|
13206
13579
|
engine: astEngine,
|
|
13207
13580
|
parserLike: this
|
|
13208
13581
|
});
|
|
@@ -16256,8 +16629,11 @@ async function emitVueBundleAssets(bundle, state) {
|
|
|
16256
16629
|
//#endregion
|
|
16257
16630
|
//#region src/plugins/vue/transform/plugin/shared.ts
|
|
16258
16631
|
const APP_ENTRY_RE = /[\\/]app\.(?:vue|jsx|tsx)$/;
|
|
16259
|
-
const AUTO_ROUTES_DEFAULT_IMPORT_RE = /import\s+([A-Za-z_$][\w$]*)\s+from\s+['"](?:weapp-vite\/auto-routes|virtual:weapp-vite-auto-routes)['"];?/g;
|
|
16260
16632
|
const AUTO_ROUTES_DYNAMIC_IMPORT_RE = /import\(\s*['"](?:weapp-vite\/auto-routes|virtual:weapp-vite-auto-routes)['"]\s*\)/g;
|
|
16633
|
+
const AUTO_ROUTES_ID = "weapp-vite/auto-routes";
|
|
16634
|
+
const AUTO_ROUTES_VIRTUAL_ID = "virtual:weapp-vite-auto-routes";
|
|
16635
|
+
const AUTO_ROUTES_NAMED_IMPORT_ALIAS_RE = /\s+as\s+/g;
|
|
16636
|
+
const AUTO_ROUTES_DEFAULT_AND_NAMED_IMPORT_RE = /^([A-Z_$][\w$]*)\s*,\s*(\{[^}]+\})$/i;
|
|
16261
16637
|
const TEMPLATE_DYNAMIC_HINT_RE = /\{\{|wx:|bind[A-Za-z:_-]+=|catch[A-Za-z:_-]+=/;
|
|
16262
16638
|
const PAGE_FEATURE_HOOK_HINTS = [
|
|
16263
16639
|
"onPageScroll",
|
|
@@ -16291,7 +16667,25 @@ function mayNeedTransformPageScrollDiagnostics(script) {
|
|
|
16291
16667
|
return script.includes(PAGE_SCROLL_HOOK_HINT);
|
|
16292
16668
|
}
|
|
16293
16669
|
function mayNeedInlineAutoRoutes(source) {
|
|
16294
|
-
return
|
|
16670
|
+
return source.includes(AUTO_ROUTES_ID) || source.includes(AUTO_ROUTES_VIRTUAL_ID);
|
|
16671
|
+
}
|
|
16672
|
+
function toObjectDestructureClause(namedImportClause) {
|
|
16673
|
+
return namedImportClause.replace(AUTO_ROUTES_NAMED_IMPORT_ALIAS_RE, ": ");
|
|
16674
|
+
}
|
|
16675
|
+
function resolveInlineAutoRoutesImport(line, inlineRoutes, replacementIndex) {
|
|
16676
|
+
const trimmedLine = line.trim();
|
|
16677
|
+
if (!trimmedLine.startsWith("import ") || !trimmedLine.includes(" from ") || !trimmedLine.includes(`'${AUTO_ROUTES_ID}'`) && !trimmedLine.includes(`"${AUTO_ROUTES_ID}"`) && !trimmedLine.includes(`'${AUTO_ROUTES_VIRTUAL_ID}'`) && !trimmedLine.includes(`"${AUTO_ROUTES_VIRTUAL_ID}"`)) return;
|
|
16678
|
+
const clause = trimmedLine.slice(7, trimmedLine.lastIndexOf(" from ")).trim();
|
|
16679
|
+
const inlineLiteral = JSON.stringify(inlineRoutes);
|
|
16680
|
+
if (clause.startsWith("{")) return `const ${toObjectDestructureClause(clause)} = ${inlineLiteral};`;
|
|
16681
|
+
if (clause.startsWith("* as ")) return `const ${clause.slice(5).trim()} = ${inlineLiteral};`;
|
|
16682
|
+
const defaultAndNamedMatch = clause.match(AUTO_ROUTES_DEFAULT_AND_NAMED_IMPORT_RE);
|
|
16683
|
+
if (defaultAndNamedMatch) {
|
|
16684
|
+
const [, defaultName, namedClause] = defaultAndNamedMatch;
|
|
16685
|
+
const localRef = `__weappViteAutoRoutesInline${replacementIndex}`;
|
|
16686
|
+
return `const ${localRef} = ${inlineLiteral};\nconst ${defaultName} = ${localRef};\nconst ${toObjectDestructureClause(namedClause)} = ${localRef};`;
|
|
16687
|
+
}
|
|
16688
|
+
return `const ${clause} = ${inlineLiteral};`;
|
|
16295
16689
|
}
|
|
16296
16690
|
function createTransformStageMeasurer(vueTransformTiming) {
|
|
16297
16691
|
const stageTimings = {};
|
|
@@ -16444,7 +16838,6 @@ function finalizeTransformEntryCode(options) {
|
|
|
16444
16838
|
async function inlineTransformAutoRoutes(options) {
|
|
16445
16839
|
const { source, autoRoutesService } = options;
|
|
16446
16840
|
if (!mayNeedInlineAutoRoutes(source)) return source;
|
|
16447
|
-
AUTO_ROUTES_DEFAULT_IMPORT_RE.lastIndex = 0;
|
|
16448
16841
|
AUTO_ROUTES_DYNAMIC_IMPORT_RE.lastIndex = 0;
|
|
16449
16842
|
await autoRoutesService?.ensureFresh?.();
|
|
16450
16843
|
const routesRef = autoRoutesService?.getReference?.();
|
|
@@ -16453,7 +16846,15 @@ async function inlineTransformAutoRoutes(options) {
|
|
|
16453
16846
|
entries: routesRef?.entries ?? [],
|
|
16454
16847
|
subPackages: routesRef?.subPackages ?? []
|
|
16455
16848
|
};
|
|
16456
|
-
|
|
16849
|
+
let importReplacementIndex = 0;
|
|
16850
|
+
return source.split("\n").map((line) => {
|
|
16851
|
+
const replaced = resolveInlineAutoRoutesImport(line, inlineRoutes, importReplacementIndex);
|
|
16852
|
+
if (replaced) {
|
|
16853
|
+
importReplacementIndex += 1;
|
|
16854
|
+
return replaced;
|
|
16855
|
+
}
|
|
16856
|
+
return line;
|
|
16857
|
+
}).join("\n").replace(AUTO_ROUTES_DYNAMIC_IMPORT_RE, `Promise.resolve(${JSON.stringify(inlineRoutes)})`);
|
|
16457
16858
|
}
|
|
16458
16859
|
async function resolveTransformEntryFlags(options) {
|
|
16459
16860
|
const { pageMatcher, setPageMatcher, createPageMatcher, configService, scanService, scanDirty, filename } = options;
|
|
@@ -18974,15 +19375,17 @@ function createScanService(ctx) {
|
|
|
18974
19375
|
const appDirname = ctx.configService.absoluteSrcRoot;
|
|
18975
19376
|
const appBasename = resolveScanAppBasename(appDirname);
|
|
18976
19377
|
let { path: appConfigFile } = await findJsonEntry(appBasename);
|
|
19378
|
+
const discoveredAppConfigFile = appConfigFile;
|
|
18977
19379
|
const { path: appEntryPath } = await findJsEntry(appBasename);
|
|
19380
|
+
const vueAppPath = await findVueEntry(appBasename);
|
|
18978
19381
|
let configFromVue;
|
|
18979
|
-
let vueAppPath;
|
|
18980
|
-
if (!appEntryPath) vueAppPath = await findVueEntry(appBasename);
|
|
18981
19382
|
if (!appConfigFile && vueAppPath) {
|
|
18982
|
-
const { extractConfigFromVue } = await import("./file-
|
|
19383
|
+
const { extractConfigFromVue } = await import("./file-DwwblEq4.mjs").then((n) => n.r);
|
|
18983
19384
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
18984
19385
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
18985
19386
|
}
|
|
19387
|
+
if (appEntryPath && vueAppPath) logger_default.warn(`[app] 检测到 ${path.basename(appEntryPath)} 与 ${path.basename(vueAppPath)} 同时存在,当前将优先使用 ${path.basename(appEntryPath)} 作为应用入口,${path.basename(vueAppPath)} 将被忽略。`);
|
|
19388
|
+
if (discoveredAppConfigFile && vueAppPath) logger_default.warn(`[app] 检测到 ${path.basename(discoveredAppConfigFile)} 与 ${path.basename(vueAppPath)} 同时存在,当前将优先使用 ${path.basename(discoveredAppConfigFile)} 作为应用配置来源,${path.basename(vueAppPath)} 中的 app 配置不会生效。`);
|
|
18986
19389
|
if (ctx.configService.absolutePluginRoot) {
|
|
18987
19390
|
const { path: pluginConfigFile } = await findJsonEntry(resolveScanPluginBasename(ctx.configService.absolutePluginRoot));
|
|
18988
19391
|
if (pluginConfigFile) {
|
|
@@ -61,10 +61,31 @@ const configMtimeInFlight = /* @__PURE__ */ new Map();
|
|
|
61
61
|
const NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
|
|
62
62
|
const JS_OR_TS_RE = /\.[jt]s$/;
|
|
63
63
|
const nodeRequire = createRequire(import.meta.url);
|
|
64
|
+
const AUTO_ROUTES_ID = "weapp-vite/auto-routes";
|
|
65
|
+
const AUTO_ROUTES_VIRTUAL_ID = "virtual:weapp-vite-auto-routes";
|
|
64
66
|
const AUTO_ROUTES_SPECIFIER_RE = /(['"])(?:weapp-vite\/auto-routes|virtual:weapp-vite-auto-routes)\1/g;
|
|
65
|
-
const AUTO_ROUTES_DEFAULT_IMPORT_RE = /import\s+([A-Za-z_$][\w$]*)\s+from\s+['"](?:weapp-vite\/auto-routes|virtual:weapp-vite-auto-routes)['"];?/g;
|
|
66
67
|
const AUTO_ROUTES_DYNAMIC_IMPORT_RE = /import\(\s*['"](?:weapp-vite\/auto-routes|virtual:weapp-vite-auto-routes)['"]\s*\)/g;
|
|
68
|
+
const AUTO_ROUTES_NAMED_IMPORT_ALIAS_RE = /\bas\b/g;
|
|
69
|
+
const AUTO_ROUTES_DEFAULT_AND_NAMED_IMPORT_RE = /^([A-Z_$][\w$]*)\s*,\s*(\{[^}]+\})$/i;
|
|
67
70
|
const JSON_MACRO_HINT_RE = /\bdefine(?:App|Page|Component|Sitemap|Theme)Json\s*\(/;
|
|
71
|
+
function toObjectDestructureClause(namedImportClause) {
|
|
72
|
+
return namedImportClause.replace(AUTO_ROUTES_NAMED_IMPORT_ALIAS_RE, ":");
|
|
73
|
+
}
|
|
74
|
+
function resolveInlineAutoRoutesImport(line, inlineRoutes, replacementIndex) {
|
|
75
|
+
const trimmedLine = line.trim();
|
|
76
|
+
if (!trimmedLine.startsWith("import ") || !trimmedLine.includes(" from ") || !trimmedLine.includes(`'${AUTO_ROUTES_ID}'`) && !trimmedLine.includes(`"${AUTO_ROUTES_ID}"`) && !trimmedLine.includes(`'${AUTO_ROUTES_VIRTUAL_ID}'`) && !trimmedLine.includes(`"${AUTO_ROUTES_VIRTUAL_ID}"`)) return;
|
|
77
|
+
const clause = trimmedLine.slice(7, trimmedLine.lastIndexOf(" from ")).trim();
|
|
78
|
+
const inlineLiteral = JSON.stringify(inlineRoutes);
|
|
79
|
+
if (clause.startsWith("{")) return `const ${toObjectDestructureClause(clause)} = ${inlineLiteral};`;
|
|
80
|
+
if (clause.startsWith("* as ")) return `const ${clause.slice(5).trim()} = ${inlineLiteral};`;
|
|
81
|
+
const defaultAndNamedMatch = clause.match(AUTO_ROUTES_DEFAULT_AND_NAMED_IMPORT_RE);
|
|
82
|
+
if (defaultAndNamedMatch) {
|
|
83
|
+
const [, defaultName, namedClause] = defaultAndNamedMatch;
|
|
84
|
+
const localRef = `__weappViteAutoRoutesInline${replacementIndex}`;
|
|
85
|
+
return `const ${localRef} = ${inlineLiteral};\nconst ${defaultName} = ${localRef};\nconst ${toObjectDestructureClause(namedClause)} = ${localRef};`;
|
|
86
|
+
}
|
|
87
|
+
return `const ${clause} = ${inlineLiteral};`;
|
|
88
|
+
}
|
|
68
89
|
function resolveAutoRoutesMacroImportPath() {
|
|
69
90
|
const fallbackCandidates = [
|
|
70
91
|
path.resolve(import.meta.dirname, "auto-routes.mjs"),
|
|
@@ -81,7 +102,7 @@ function resolveAutoRoutesMacroImportPath() {
|
|
|
81
102
|
}
|
|
82
103
|
async function resolveAutoRoutesInlineSnapshot() {
|
|
83
104
|
try {
|
|
84
|
-
const { getCompilerContext } = await import("./createContext-
|
|
105
|
+
const { getCompilerContext } = await import("./createContext-CZ7Kunvn.mjs").then((n) => n.a);
|
|
85
106
|
const compilerContext = getCompilerContext();
|
|
86
107
|
const service = compilerContext.autoRoutesService;
|
|
87
108
|
const reference = service?.getReference?.();
|
|
@@ -101,9 +122,15 @@ async function resolveAutoRoutesInlineSnapshot() {
|
|
|
101
122
|
}
|
|
102
123
|
}
|
|
103
124
|
function inlineAutoRoutesImports(source, inlineRoutes) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
125
|
+
let importReplacementIndex = 0;
|
|
126
|
+
return source.split("\n").map((line) => {
|
|
127
|
+
const replaced = resolveInlineAutoRoutesImport(line, inlineRoutes, importReplacementIndex);
|
|
128
|
+
if (replaced) {
|
|
129
|
+
importReplacementIndex += 1;
|
|
130
|
+
return replaced;
|
|
131
|
+
}
|
|
132
|
+
return line;
|
|
133
|
+
}).join("\n").replace(AUTO_ROUTES_DYNAMIC_IMPORT_RE, `Promise.resolve(${JSON.stringify(inlineRoutes)})`).replace(AUTO_ROUTES_SPECIFIER_RE, JSON.stringify(resolveAutoRoutesMacroImportPath()));
|
|
107
134
|
}
|
|
108
135
|
function pathExistsCached(filePath) {
|
|
109
136
|
const pending = pathExistsInFlight.get(filePath);
|
|
@@ -234,7 +261,9 @@ async function extractConfigFromVue(vueFilePath) {
|
|
|
234
261
|
if (typeof setupContent === "string" && JSON_MACRO_HINT_RE.test(setupContent)) {
|
|
235
262
|
const { extractJsonMacroFromScriptSetup } = await import("wevu/compiler");
|
|
236
263
|
try {
|
|
237
|
-
const
|
|
264
|
+
const autoRoutesInline = await resolveAutoRoutesInlineSnapshot();
|
|
265
|
+
const macroEvalPreamble = descriptor.script?.content ? inlineAutoRoutesImports(descriptor.script.content, autoRoutesInline) : void 0;
|
|
266
|
+
const extracted = await extractJsonMacroFromScriptSetup(inlineAutoRoutesImports(setupContent, autoRoutesInline), vueFilePath, descriptor.scriptSetup?.lang, { preambleContent: macroEvalPreamble });
|
|
238
267
|
if (extracted.dependencies?.length) macroDependencies.push(...extracted.dependencies);
|
|
239
268
|
if (extracted.config && typeof extracted.config === "object" && !Array.isArray(extracted.config)) recursive(mergedConfig, extracted.config);
|
|
240
269
|
} catch (error) {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Ref, An as
|
|
1
|
+
import { A as Ref, An as createWeappViteHostMeta, C as LoadConfigOptions, D as MethodDefinitions, Dn as WeappViteHostMeta, E as InlineConfig, En as WEAPP_VITE_HOST_NAME, F as RolldownPlugin, I as RolldownPluginOption, L as RolldownWatchOptions, M as RolldownBuild, Mn as resolveWeappViteHostMeta, N as RolldownOptions, O as Plugin, On as WeappViteRuntime, P as RolldownOutput, R as RolldownWatcher, S as CompilerContext, T as ConfigEnv, _ as definePageJson, a as UserConfigFnNoEnvPlain, c as UserConfigFnPromise, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, j as ResolvedConfig, jn as isWeappViteHost, k as PluginOption, kn as applyWeappViteHostMeta, l as defineConfig, m as Theme, n as UserConfigExport, nt as WeappViteConfig, o as UserConfigFnObject, p as Sitemap, r as UserConfigFn, s as UserConfigFnObjectPlain, t as UserConfig, u as App, v as defineSitemapJson, w as ComputedDefinitions, y as defineThemeJson, z as ViteDevServer } from "./config-B3HNOAZo.mjs";
|
|
2
2
|
import { WevuComponentOptions, defineEmits, defineProps } from "./runtime.mjs";
|
|
3
3
|
import { createWevuComponent, setPageLayout } from "wevu";
|
|
4
4
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineAppJson, defineComponentJson, definePageJson, defineSitemapJson, defineThemeJson } from "./json.mjs";
|
|
2
2
|
import { a as resolveWeappViteHostMeta, i as isWeappViteHost, n as applyWeappViteHostMeta, r as createWeappViteHostMeta, t as WEAPP_VITE_HOST_NAME } from "./pluginHost-SJdl15d3.mjs";
|
|
3
3
|
import { defineConfig } from "./config.mjs";
|
|
4
|
-
import { t as createCompilerContext } from "./createContext-
|
|
4
|
+
import { t as createCompilerContext } from "./createContext-CZ7Kunvn.mjs";
|
|
5
5
|
import { defineEmits, defineProps } from "./runtime.mjs";
|
|
6
6
|
import { createWevuComponent, setPageLayout } from "wevu";
|
|
7
7
|
export { WEAPP_VITE_HOST_NAME, applyWeappViteHostMeta, createCompilerContext, createWeappViteHostMeta, createWevuComponent, defineAppJson, defineComponentJson, defineConfig, defineEmits, definePageJson, defineProps, defineSitemapJson, defineThemeJson, isWeappViteHost, resolveWeappViteHostMeta, setPageLayout };
|
package/dist/json.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as definePageJson, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, m as Theme, p as Sitemap, u as App, v as defineSitemapJson, y as defineThemeJson } from "./config-
|
|
1
|
+
import { _ as definePageJson, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, m as Theme, p as Sitemap, u as App, v as defineSitemapJson, y as defineThemeJson } from "./config-B3HNOAZo.mjs";
|
|
2
2
|
export { App, Component, Page, Sitemap, Theme, defineAppJson, defineComponentJson, definePageJson, defineSitemapJson, defineThemeJson };
|
package/dist/mcp.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _t as WeappMcpConfig } from "./config-B3HNOAZo.mjs";
|
|
2
2
|
import { CreateServerOptions, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, McpServerHandle, StartMcpServerOptions, createWeappViteMcpServer } from "@weapp-vite/mcp";
|
|
3
3
|
|
|
4
4
|
//#region src/mcp.d.ts
|
package/dist/types.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { c as Resolver } from "./index-BQqQ_BLM.mjs";
|
|
2
2
|
import { n as AutoRoutesSubPackage, t as AutoRoutes } from "./routes-DUBjYF43.mjs";
|
|
3
|
-
import { $ as WeappDebugConfig, $t as
|
|
4
|
-
export { Alias, AliasOptions, AlipayNpmMode, AppEntry, AutoImportComponents, AutoImportComponentsOption, AutoRoutes, AutoRoutesSubPackage, BaseEntry, BindingErrorLike, BuildNpmPackageMeta, ChangeEvent, ChunksConfig, ComponentEntry, ComponentsMap, ComputedDefinitions, ConfigEnv, CopyGlobs, CopyOptions, EnhanceOptions, EnhanceWxmlOptions, Entry, EntryJsonFragment, GenerateDirsOptions, GenerateExtensionsOptions, GenerateFileType, GenerateFilenamesOptions, GenerateOptions, GenerateTemplate, GenerateTemplateContext, GenerateTemplateEntry, GenerateTemplateFactory, GenerateTemplateFileSource, GenerateTemplateInlineSource, GenerateTemplateScope, GenerateTemplatesConfig, HandleWxmlOptions, InlineConfig, JsFormat, JsonConfig, JsonMergeContext, JsonMergeFunction, JsonMergeStage, JsonMergeStrategy, MethodDefinitions, MpPlatform, MultiPlatformConfig, NpmBuildOptions, NpmMainPackageConfig, NpmPluginPackageConfig, NpmSubPackageConfig, PageEntry, Plugin, PluginOption, ProjectConfig, Ref, ResolvedAlias, ResolvedConfig, Resolver, RolldownBuild, RolldownOptions, RolldownOutput, RolldownPlugin, RolldownPluginOption, RolldownWatchOptions, RolldownWatcher, ScanComponentItem, ScanWxmlOptions, SharedChunkDynamicImports, SharedChunkMode, SharedChunkOverride, SharedChunkStrategy, SubPackage, SubPackageMetaValue, SubPackageStyleConfigEntry, SubPackageStyleConfigObject, SubPackageStyleEntry, SubPackageStyleScope, UserConfig, ViteDevServer, WeappAutoRoutesConfig, WeappAutoRoutesInclude, WeappAutoRoutesIncludePattern, WeappDebugConfig, WeappForwardConsoleConfig, WeappForwardConsoleLogLevel, WeappHmrConfig, WeappInjectWeapiConfig, WeappLibComponentJson, WeappLibConfig, WeappLibDtsOptions, WeappLibEntryContext, WeappLibFileName, WeappLibInternalDtsOptions, WeappLibVueTscOptions, WeappManagedAppTsconfigConfig, WeappManagedNodeTsconfigConfig, WeappManagedServerTsconfigConfig, WeappManagedSharedTsconfigConfig, WeappManagedTypeScriptConfig, WeappMcpConfig, WeappNpmConfig, WeappRouteRule, WeappRouteRules, WeappSubPackageConfig, WeappViteConfig, WeappViteHostMeta, WeappVitePluginApi, WeappViteRuntime, WeappVueConfig, WeappVueTemplateConfig, WeappWebConfig, WeappWevuConfig, WeappWorkerConfig, WxmlDep };
|
|
3
|
+
import { $ as WeappDebugConfig, $t as NpmBuildOptions, A as Ref, At as ChunksConfig, B as BindingErrorLike, Bt as GenerateTemplateEntry, Cn as WeappManagedSharedTsconfigConfig, Ct as WeappVueTemplateConfig, D as MethodDefinitions, Dn as WeappViteHostMeta, Dt as AliasOptions, E as InlineConfig, Et as Alias, F as RolldownPlugin, Ft as GenerateFileType, G as EntryJsonFragment, Gt as GenerateTemplatesConfig, H as BaseEntry, Ht as GenerateTemplateFileSource, I as RolldownPluginOption, It as GenerateFilenamesOptions, J as ScanComponentItem, Jt as JsonMergeContext, K as PageEntry, Kt as JsFormat, L as RolldownWatchOptions, Lt as GenerateOptions, M as RolldownBuild, Mt as CopyOptions, N as RolldownOptions, Nt as GenerateDirsOptions, O as Plugin, On as WeappViteRuntime, Ot as AlipayNpmMode, P as RolldownOutput, Pt as GenerateExtensionsOptions, Q as UserConfig, Qt as MpPlatform, R as RolldownWatcher, Rt as GenerateTemplate, Sn as WeappManagedServerTsconfigConfig, St as WeappVueConfig, T as ConfigEnv, Tn as WeappWebConfig, Tt as WeappWorkerConfig, U as ComponentEntry, Ut as GenerateTemplateInlineSource, V as AppEntry, Vt as GenerateTemplateFactory, W as Entry, Wt as GenerateTemplateScope, X as ProjectConfig, Xt as JsonMergeStage, Y as WxmlDep, Yt as JsonMergeFunction, Z as SubPackageMetaValue, Zt as JsonMergeStrategy, _n as WeappLibFileName, _t as WeappMcpConfig, an as SharedChunkMode, at as EnhanceOptions, b as ChangeEvent, bn as WeappManagedAppTsconfigConfig, bt as WeappRouteRules, cn as SubPackage, ct as MultiPlatformConfig, dn as SubPackageStyleEntry, dt as WeappAutoRoutesInclude, en as NpmMainPackageConfig, et as WeappForwardConsoleConfig, fn as SubPackageStyleScope, ft as WeappAutoRoutesIncludePattern, gn as WeappLibEntryContext, gt as WeappInjectWeapiConfig, hn as WeappLibDtsOptions, ht as WeappInjectRequestGlobalsTarget, in as SharedChunkDynamicImports, it as AutoImportComponentsOption, j as ResolvedConfig, jt as CopyGlobs, k as PluginOption, kt as BuildNpmPackageMeta, ln as SubPackageStyleConfigEntry, lt as ScanWxmlOptions, mn as WeappLibConfig, mt as WeappInjectRequestGlobalsConfig, nn as NpmSubPackageConfig, nt as WeappViteConfig, on as SharedChunkOverride, ot as EnhanceWxmlOptions, pn as WeappLibComponentJson, pt as WeappHmrConfig, q as ComponentsMap, qt as JsonConfig, rn as ResolvedAlias, rt as AutoImportComponents, sn as SharedChunkStrategy, st as HandleWxmlOptions, tn as NpmPluginPackageConfig, tt as WeappForwardConsoleLogLevel, un as SubPackageStyleConfigObject, ut as WeappAutoRoutesConfig, vn as WeappLibInternalDtsOptions, vt as WeappNpmConfig, w as ComputedDefinitions, wn as WeappManagedTypeScriptConfig, wt as WeappWevuConfig, x as WeappVitePluginApi, xn as WeappManagedNodeTsconfigConfig, xt as WeappSubPackageConfig, yn as WeappLibVueTscOptions, yt as WeappRouteRule, z as ViteDevServer, zt as GenerateTemplateContext } from "./config-B3HNOAZo.mjs";
|
|
4
|
+
export { Alias, AliasOptions, AlipayNpmMode, AppEntry, AutoImportComponents, AutoImportComponentsOption, AutoRoutes, AutoRoutesSubPackage, BaseEntry, BindingErrorLike, BuildNpmPackageMeta, ChangeEvent, ChunksConfig, ComponentEntry, ComponentsMap, ComputedDefinitions, ConfigEnv, CopyGlobs, CopyOptions, EnhanceOptions, EnhanceWxmlOptions, Entry, EntryJsonFragment, GenerateDirsOptions, GenerateExtensionsOptions, GenerateFileType, GenerateFilenamesOptions, GenerateOptions, GenerateTemplate, GenerateTemplateContext, GenerateTemplateEntry, GenerateTemplateFactory, GenerateTemplateFileSource, GenerateTemplateInlineSource, GenerateTemplateScope, GenerateTemplatesConfig, HandleWxmlOptions, InlineConfig, JsFormat, JsonConfig, JsonMergeContext, JsonMergeFunction, JsonMergeStage, JsonMergeStrategy, MethodDefinitions, MpPlatform, MultiPlatformConfig, NpmBuildOptions, NpmMainPackageConfig, NpmPluginPackageConfig, NpmSubPackageConfig, PageEntry, Plugin, PluginOption, ProjectConfig, Ref, ResolvedAlias, ResolvedConfig, Resolver, RolldownBuild, RolldownOptions, RolldownOutput, RolldownPlugin, RolldownPluginOption, RolldownWatchOptions, RolldownWatcher, ScanComponentItem, ScanWxmlOptions, SharedChunkDynamicImports, SharedChunkMode, SharedChunkOverride, SharedChunkStrategy, SubPackage, SubPackageMetaValue, SubPackageStyleConfigEntry, SubPackageStyleConfigObject, SubPackageStyleEntry, SubPackageStyleScope, UserConfig, ViteDevServer, WeappAutoRoutesConfig, WeappAutoRoutesInclude, WeappAutoRoutesIncludePattern, WeappDebugConfig, WeappForwardConsoleConfig, WeappForwardConsoleLogLevel, WeappHmrConfig, WeappInjectRequestGlobalsConfig, WeappInjectRequestGlobalsTarget, WeappInjectWeapiConfig, WeappLibComponentJson, WeappLibConfig, WeappLibDtsOptions, WeappLibEntryContext, WeappLibFileName, WeappLibInternalDtsOptions, WeappLibVueTscOptions, WeappManagedAppTsconfigConfig, WeappManagedNodeTsconfigConfig, WeappManagedServerTsconfigConfig, WeappManagedSharedTsconfigConfig, WeappManagedTypeScriptConfig, WeappMcpConfig, WeappNpmConfig, WeappRouteRule, WeappRouteRules, WeappSubPackageConfig, WeappViteConfig, WeappViteHostMeta, WeappVitePluginApi, WeappViteRuntime, WeappVueConfig, WeappVueTemplateConfig, WeappWebConfig, WeappWevuConfig, WeappWorkerConfig, WxmlDep };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@wevu/web-apis";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.13.0",
|
|
5
5
|
"description": "weapp-vite 一个现代化的小程序打包工具",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -46,6 +46,10 @@
|
|
|
46
46
|
"types": "./dist/runtime.d.mts",
|
|
47
47
|
"import": "./dist/runtime.mjs"
|
|
48
48
|
},
|
|
49
|
+
"./web-apis": {
|
|
50
|
+
"types": "./dist/web-apis.d.mts",
|
|
51
|
+
"import": "./dist/web-apis.mjs"
|
|
52
|
+
},
|
|
49
53
|
"./mcp": {
|
|
50
54
|
"types": "./dist/mcp.d.mts",
|
|
51
55
|
"import": "./dist/mcp.mjs"
|
|
@@ -100,7 +104,7 @@
|
|
|
100
104
|
"lru-cache": "^11.2.7",
|
|
101
105
|
"magic-string": "^0.30.21",
|
|
102
106
|
"merge": "^2.1.1",
|
|
103
|
-
"p-queue": "^9.1.
|
|
107
|
+
"p-queue": "^9.1.1",
|
|
104
108
|
"package-manager-detector": "^1.6.0",
|
|
105
109
|
"pathe": "^2.0.3",
|
|
106
110
|
"picomatch": "^4.0.4",
|
|
@@ -117,22 +121,23 @@
|
|
|
117
121
|
"@weapp-core/logger": "3.1.1",
|
|
118
122
|
"@weapp-core/schematics": "6.0.4",
|
|
119
123
|
"@weapp-core/shared": "3.0.2",
|
|
120
|
-
"@weapp-vite/ast": "6.
|
|
121
|
-
"@weapp-vite/mcp": "1.1.
|
|
124
|
+
"@weapp-vite/ast": "6.13.0",
|
|
125
|
+
"@weapp-vite/mcp": "1.1.2",
|
|
122
126
|
"@weapp-vite/volar": "2.0.8",
|
|
123
127
|
"@weapp-vite/web": "1.3.10",
|
|
124
128
|
"@wevu/api": "0.2.2",
|
|
129
|
+
"@wevu/web-apis": "1.1.0",
|
|
125
130
|
"rolldown-require": "2.0.12",
|
|
126
131
|
"vite-plugin-performance": "2.0.1",
|
|
127
132
|
"weapp-ide-cli": "5.1.4",
|
|
128
|
-
"wevu": "6.
|
|
133
|
+
"wevu": "6.13.0"
|
|
129
134
|
},
|
|
130
135
|
"publishConfig": {
|
|
131
136
|
"access": "public",
|
|
132
137
|
"registry": "https://registry.npmjs.org"
|
|
133
138
|
},
|
|
134
139
|
"devDependencies": {
|
|
135
|
-
"oxc-parser": "^0.
|
|
140
|
+
"oxc-parser": "^0.123.0",
|
|
136
141
|
"oxc-walker": "^0.7.0",
|
|
137
142
|
"tailwindcss": "^4.2.2",
|
|
138
143
|
"ts-morph": "^27.0.2"
|