weapp-vite 6.16.42 → 6.16.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +301 -61
- package/dist/{config-CobCpW-a.d.mts → config-Ds7MBgQm.d.mts} +2 -2
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-BjCo8Rn4.mjs → createContext-D2uF0JED.mjs} +116 -37
- package/dist/file-CTUeDbPw.mjs +2 -0
- package/dist/{file-Cm-gX3xL.mjs → file-DBbvHZyc.mjs} +1 -1
- package/dist/getInstance-DwrlgiHQ.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-YXCIQr-Z.mjs +124 -0
- package/dist/mcp.d.mts +11 -3
- package/dist/mcp.mjs +2 -2
- package/dist/types.d.mts +1 -1
- package/package.json +20 -20
- package/dist/file-C00jTD86.mjs +0 -2
- package/dist/getInstance-BuRfAoqK.mjs +0 -2
- package/dist/mcp-qmDOTH07.mjs +0 -43
|
@@ -420,9 +420,9 @@ interface MultiPlatformConfig {
|
|
|
420
420
|
*/
|
|
421
421
|
interface WeappMcpConfig {
|
|
422
422
|
enabled?: boolean;
|
|
423
|
-
autoStart?: boolean;
|
|
423
|
+
autoStart?: boolean | 'ai';
|
|
424
424
|
host?: string;
|
|
425
|
-
port?: number;
|
|
425
|
+
port?: number | 'auto';
|
|
426
426
|
endpoint?: string;
|
|
427
427
|
/**
|
|
428
428
|
* @description streamable-http 模式下的 DevTools runtime REST 入口;设为 false 可关闭。
|
package/dist/config.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Bn as WeappViteHostMeta, Hn as createWeappViteHostMeta, Un as isWeappViteHost, Vn as applyWeappViteHostMeta, Wn as resolveWeappViteHostMeta, Yn as WeappViteRuntime, _ as definePageJson, a as UserConfigFnNoEnvPlain, at as WeappViteConfig, c as UserConfigFnPromise, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, l as defineConfig, m as Theme, n as UserConfigExport, o as UserConfigFnObject, p as Sitemap, r as UserConfigFn, s as UserConfigFnObjectPlain, t as UserConfig, u as App, v as defineSitemapJson, y as defineThemeJson, zn as WEAPP_VITE_HOST_NAME } from "./config-
|
|
1
|
+
import { Bn as WeappViteHostMeta, Hn as createWeappViteHostMeta, Un as isWeappViteHost, Vn as applyWeappViteHostMeta, Wn as resolveWeappViteHostMeta, Yn as WeappViteRuntime, _ as definePageJson, a as UserConfigFnNoEnvPlain, at as WeappViteConfig, c as UserConfigFnPromise, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, l as defineConfig, m as Theme, n as UserConfigExport, o as UserConfigFnObject, p as Sitemap, r as UserConfigFn, s as UserConfigFnObjectPlain, t as UserConfig, u as App, v as defineSitemapJson, y as defineThemeJson, zn as WEAPP_VITE_HOST_NAME } from "./config-Ds7MBgQm.mjs";
|
|
2
2
|
export { type App, type Component, type Page, type Sitemap, type Theme, UserConfig, UserConfigExport, UserConfigFn, UserConfigFnNoEnv, UserConfigFnNoEnvPlain, UserConfigFnObject, UserConfigFnObjectPlain, UserConfigFnPromise, WEAPP_VITE_HOST_NAME, type WeappViteConfig, WeappViteHostMeta, type WeappViteRuntime, applyWeappViteHostMeta, createWeappViteHostMeta, defineAppJson, defineComponentJson, defineConfig, definePageJson, defineSitemapJson, defineThemeJson, isWeappViteHost, resolveWeappViteHostMeta };
|
|
@@ -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 { _ as jsExtensions, a as findJsonEntry, b as vueExtensions, 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 supportedCssLangs, y as templateExtensions } from "./file-
|
|
3
|
+
import { _ as jsExtensions, a as findJsonEntry, b as vueExtensions, 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 supportedCssLangs, y as templateExtensions } from "./file-DBbvHZyc.mjs";
|
|
4
4
|
import { createRequire, isBuiltin } from "node:module";
|
|
5
5
|
import path, { posix } from "pathe";
|
|
6
6
|
import path$1, { normalize, relative, win32 } from "node:path";
|
|
@@ -9146,9 +9146,9 @@ function getWeappViteConfig() {
|
|
|
9146
9146
|
},
|
|
9147
9147
|
mcp: {
|
|
9148
9148
|
enabled: true,
|
|
9149
|
-
autoStart:
|
|
9149
|
+
autoStart: "ai",
|
|
9150
9150
|
host: "127.0.0.1",
|
|
9151
|
-
port:
|
|
9151
|
+
port: "auto",
|
|
9152
9152
|
endpoint: "/mcp",
|
|
9153
9153
|
restEndpoint: "/api/weapp/devtools"
|
|
9154
9154
|
},
|
|
@@ -11037,6 +11037,27 @@ async function collectAppSideFiles(pluginCtx, id, json, jsonService, registerJso
|
|
|
11037
11037
|
await processSideJson(sitemapLocation);
|
|
11038
11038
|
await processSideJson(themeLocation);
|
|
11039
11039
|
}
|
|
11040
|
+
async function collectMiniappConfigFile(pluginCtx, id, configService, jsonService, registerJsonAsset, existsCache, ttlMs) {
|
|
11041
|
+
if (configService.platform !== "weapp") return;
|
|
11042
|
+
const runtimeMiniappConfigPath = path.resolve(path.dirname(id), "app.miniapp.json");
|
|
11043
|
+
if (await addWatchTarget(pluginCtx, runtimeMiniappConfigPath, existsCache, ttlMs)) {
|
|
11044
|
+
registerJsonAsset({
|
|
11045
|
+
fileName: "app.miniapp.json",
|
|
11046
|
+
json: await jsonService.read(runtimeMiniappConfigPath),
|
|
11047
|
+
jsonPath: runtimeMiniappConfigPath,
|
|
11048
|
+
type: "page"
|
|
11049
|
+
});
|
|
11050
|
+
return;
|
|
11051
|
+
}
|
|
11052
|
+
const miniappConfigPath = path.resolve(configService.cwd, "project.miniapp.json");
|
|
11053
|
+
if (!await addWatchTarget(pluginCtx, miniappConfigPath, existsCache, ttlMs)) return;
|
|
11054
|
+
registerJsonAsset({
|
|
11055
|
+
fileName: "app.miniapp.json",
|
|
11056
|
+
json: await jsonService.read(miniappConfigPath),
|
|
11057
|
+
jsonPath: miniappConfigPath,
|
|
11058
|
+
type: "page"
|
|
11059
|
+
});
|
|
11060
|
+
}
|
|
11040
11061
|
async function ensureTemplateScanned(pluginCtx, id, scanTemplateEntry, existsCache, ttlMs) {
|
|
11041
11062
|
const { path: templateEntry, predictions } = await findTemplateEntry(id);
|
|
11042
11063
|
for (const prediction of predictions) await addWatchTarget(pluginCtx, prediction, existsCache, ttlMs);
|
|
@@ -14317,32 +14338,33 @@ function mergeInlineConfig(config, injectBuiltinAliases, ...configs) {
|
|
|
14317
14338
|
//#endregion
|
|
14318
14339
|
//#region src/plugins/utils/scriptlessComponent.ts
|
|
14319
14340
|
const SCRIPTLESS_COMPONENT_STUB = "Component({})";
|
|
14341
|
+
const SLOT_HOST_SCRIPTLESS_COMPONENT_STUB = "Component({properties:{vueSlots:{type:null,value:null},__wvSlotOwnerId:{type:String,value:\"\"},__wvSlotScope:{type:null,value:null}}})";
|
|
14320
14342
|
/**
|
|
14321
14343
|
* 统一生成无脚本组件的脚本产物文件名。
|
|
14322
14344
|
*/
|
|
14323
14345
|
function resolveScriptlessComponentFileName(relativeBase, scriptExtension) {
|
|
14324
14346
|
return `${relativeBase}.${scriptExtension}`;
|
|
14325
14347
|
}
|
|
14326
|
-
function emitScriptlessComponentAsset(pluginCtx, fileName) {
|
|
14348
|
+
function emitScriptlessComponentAsset(pluginCtx, fileName, source = SCRIPTLESS_COMPONENT_STUB) {
|
|
14327
14349
|
pluginCtx.emitFile({
|
|
14328
14350
|
type: "asset",
|
|
14329
14351
|
fileName,
|
|
14330
|
-
source
|
|
14352
|
+
source
|
|
14331
14353
|
});
|
|
14332
14354
|
}
|
|
14333
14355
|
/**
|
|
14334
14356
|
* 在 bundle 中补齐或覆盖无脚本组件占位脚本。
|
|
14335
14357
|
*/
|
|
14336
|
-
function ensureScriptlessComponentAsset(pluginCtx, bundle, relativeBase, scriptExtension) {
|
|
14358
|
+
function ensureScriptlessComponentAsset(pluginCtx, bundle, relativeBase, scriptExtension, source = SCRIPTLESS_COMPONENT_STUB) {
|
|
14337
14359
|
const fileName = resolveScriptlessComponentFileName(relativeBase, scriptExtension);
|
|
14338
14360
|
const existing = bundle[fileName];
|
|
14339
14361
|
if (existing) {
|
|
14340
14362
|
if (existing.type === "asset") {
|
|
14341
|
-
if ((existing.source?.toString?.() ?? "") !==
|
|
14363
|
+
if ((existing.source?.toString?.() ?? "") !== source) existing.source = source;
|
|
14342
14364
|
}
|
|
14343
14365
|
return fileName;
|
|
14344
14366
|
}
|
|
14345
|
-
emitScriptlessComponentAsset(pluginCtx, fileName);
|
|
14367
|
+
emitScriptlessComponentAsset(pluginCtx, fileName, source);
|
|
14346
14368
|
return fileName;
|
|
14347
14369
|
}
|
|
14348
14370
|
//#endregion
|
|
@@ -14864,6 +14886,25 @@ function isKnownWevuComponentCallee(callee) {
|
|
|
14864
14886
|
function mayNeedInjectSetDataPickInJs(source) {
|
|
14865
14887
|
return source.includes("createWevuComponent") || source.includes("defineComponent") || source.includes("__wevu_isPage") || source.includes(".so(");
|
|
14866
14888
|
}
|
|
14889
|
+
/**
|
|
14890
|
+
* 判断脚本 setup 阶段是否会读取编译期 slot 名元数据。
|
|
14891
|
+
*/
|
|
14892
|
+
function mayNeedScopedSlotHostPropertiesForSetupSlotsInJs(source) {
|
|
14893
|
+
if (!source.includes("useSlots")) return false;
|
|
14894
|
+
const ast = parseJsLike(source);
|
|
14895
|
+
const useSlotsLocals = /* @__PURE__ */ new Set();
|
|
14896
|
+
traverse(ast, { ImportDeclaration(path) {
|
|
14897
|
+
const sourceValue = path.node.source.value;
|
|
14898
|
+
if (sourceValue !== "wevu" && sourceValue !== "vue" && sourceValue !== "wevu/internal-runtime") return;
|
|
14899
|
+
for (const specifier of path.node.specifiers) if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "useSlots" && specifier.local.type === "Identifier") useSlotsLocals.add(specifier.local.name);
|
|
14900
|
+
} });
|
|
14901
|
+
if (!useSlotsLocals.size) return false;
|
|
14902
|
+
let hasSetupSlotsCall = false;
|
|
14903
|
+
traverse(ast, { CallExpression(path) {
|
|
14904
|
+
if (path.node.callee.type === "Identifier" && useSlotsLocals.has(path.node.callee.name)) hasSetupSlotsCall = true;
|
|
14905
|
+
} });
|
|
14906
|
+
return hasSetupSlotsCall;
|
|
14907
|
+
}
|
|
14867
14908
|
function getObjectPropertyByKey$1(objectExpression, key) {
|
|
14868
14909
|
for (const member of objectExpression.properties) {
|
|
14869
14910
|
if (member.type !== "ObjectProperty") continue;
|
|
@@ -15791,8 +15832,8 @@ function createExtendedLibManager() {
|
|
|
15791
15832
|
function createJsonEmitManager(configService) {
|
|
15792
15833
|
const map = /* @__PURE__ */ new Map();
|
|
15793
15834
|
function register(entry) {
|
|
15794
|
-
if (!entry.jsonPath) return;
|
|
15795
|
-
const fileName = resolveRelativeJsonOutputFileName(configService, entry.jsonPath);
|
|
15835
|
+
if (!entry.jsonPath && !entry.fileName) return;
|
|
15836
|
+
const fileName = entry.fileName ?? resolveRelativeJsonOutputFileName(configService, entry.jsonPath);
|
|
15796
15837
|
const normalizedEntry = entry.type === "app" && fileName === "app.json" ? {
|
|
15797
15838
|
...entry,
|
|
15798
15839
|
json: normalizeAppJson(entry.json)
|
|
@@ -15968,19 +16009,21 @@ function getPlatformLayoutElseDirective(platform) {
|
|
|
15968
16009
|
function toKebabAttrName(key) {
|
|
15969
16010
|
return toKebabCase(key);
|
|
15970
16011
|
}
|
|
16012
|
+
const LAYOUT_SLOT_OWNER_ATTR = `${WEVU_SLOT_OWNER_ID_ATTR}="{{${WEVU_SLOT_OWNER_ID_PROP} || ${WEVU_SLOT_OWNER_ID_KEY} || ''}}"`;
|
|
15971
16013
|
function hasDynamicExpressionLayoutProps(props) {
|
|
15972
16014
|
if (!props) return false;
|
|
15973
16015
|
return Object.values(props).some((value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "expression");
|
|
15974
16016
|
}
|
|
15975
16017
|
function serializeLayoutProps(props) {
|
|
15976
|
-
|
|
15977
|
-
|
|
16018
|
+
const attrs = [LAYOUT_SLOT_OWNER_ATTR];
|
|
16019
|
+
if (!props || Object.keys(props).length === 0) return ` ${attrs.join(" ")}`;
|
|
16020
|
+
attrs.push(...Object.entries(props).map(([key, value]) => {
|
|
15978
16021
|
const attrName = toKebabAttrName(key);
|
|
15979
16022
|
if (typeof value === "string") return `${attrName}="${escapeDoubleQuotedAttr(value)}"`;
|
|
15980
16023
|
if (typeof value === "object" && value && "kind" in value && value.kind === "expression") return `${attrName}="{{${WEVU_LAYOUT_BIND_PREFIX}${key}}}"`;
|
|
15981
16024
|
if (typeof value === "number" || typeof value === "boolean" || value === null) return `${attrName}="{{${String(value)}}}"`;
|
|
15982
16025
|
return "";
|
|
15983
|
-
}).filter(Boolean);
|
|
16026
|
+
}).filter(Boolean));
|
|
15984
16027
|
return attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
|
|
15985
16028
|
}
|
|
15986
16029
|
function collapseNestedLayoutWrapper(template, tagName) {
|
|
@@ -16001,10 +16044,12 @@ function serializeFallbackLayoutValue(value, keyName) {
|
|
|
16001
16044
|
return `(${WEVU_PAGE_LAYOUT_PROPS_KEY}&&${WEVU_PAGE_LAYOUT_PROPS_KEY}.${keyName})!==undefined?${WEVU_PAGE_LAYOUT_PROPS_KEY}.${keyName}:${JSON.stringify(value)}`;
|
|
16002
16045
|
}
|
|
16003
16046
|
function buildDynamicLayoutAttrs(propKeys, currentLayout) {
|
|
16004
|
-
|
|
16005
|
-
return ` ${
|
|
16047
|
+
const attrs = [LAYOUT_SLOT_OWNER_ATTR];
|
|
16048
|
+
if (propKeys.length === 0) return ` ${attrs.join(" ")}`;
|
|
16049
|
+
attrs.push(...propKeys.map((key) => {
|
|
16006
16050
|
return `${toKebabAttrName(key)}="{{${serializeFallbackLayoutValue(currentLayout?.props?.[key], key)}}}"`;
|
|
16007
|
-
})
|
|
16051
|
+
}));
|
|
16052
|
+
return ` ${attrs.join(" ")}`;
|
|
16008
16053
|
}
|
|
16009
16054
|
function buildDynamicLayoutTemplate(innerTemplate, currentLayout, layouts, propKeys, platform) {
|
|
16010
16055
|
return `${layouts.map((layout, index) => {
|
|
@@ -16723,6 +16768,7 @@ async function collectAppEntries(options) {
|
|
|
16723
16768
|
if (!isPluginBuild) {
|
|
16724
16769
|
extendedLibManager.syncFromAppJson(json);
|
|
16725
16770
|
await collectAppSideFiles(pluginCtx, id, json, jsonService, registerJsonAsset, existsCache, pathExistsTtlMs);
|
|
16771
|
+
await collectMiniappConfigFile(pluginCtx, id, configService, jsonService, registerJsonAsset, existsCache, pathExistsTtlMs);
|
|
16726
16772
|
}
|
|
16727
16773
|
const pluginJsonPath = scanService?.pluginJsonPath;
|
|
16728
16774
|
if (isPluginBuild && configService.absolutePluginRoot && pluginJsonPath) {
|
|
@@ -17269,7 +17315,7 @@ function createEntryLoader(options) {
|
|
|
17269
17315
|
if (!relativeLayoutBase || emittedScriptlessVueLayoutJs.has(relativeLayoutBase)) continue;
|
|
17270
17316
|
emittedScriptlessVueLayoutJs.add(relativeLayoutBase);
|
|
17271
17317
|
const { scriptExtension } = resolveCompilerOutputExtensions(configService.outputExtensions);
|
|
17272
|
-
emitScriptlessComponentAsset(this, resolveScriptlessComponentFileName(relativeLayoutBase, scriptExtension));
|
|
17318
|
+
emitScriptlessComponentAsset(this, resolveScriptlessComponentFileName(relativeLayoutBase, scriptExtension), SLOT_HOST_SCRIPTLESS_COMPONENT_STUB);
|
|
17273
17319
|
}
|
|
17274
17320
|
};
|
|
17275
17321
|
if (type === "app") {
|
|
@@ -18798,6 +18844,7 @@ const REQUEST_GLOBAL_FREE_BINDING_TARGETS = new Set([
|
|
|
18798
18844
|
"URL",
|
|
18799
18845
|
"URLSearchParams",
|
|
18800
18846
|
"Blob",
|
|
18847
|
+
"File",
|
|
18801
18848
|
"FormData"
|
|
18802
18849
|
]);
|
|
18803
18850
|
const CODE_USAGE_AUTO_RULES = [
|
|
@@ -18932,7 +18979,7 @@ function resolveRequestGlobalsBindingTargets(targets) {
|
|
|
18932
18979
|
const bindingTargets = [...targets];
|
|
18933
18980
|
if (targets.some((target) => target === "fetch" || target === "Request" || target === "Response" || target === "XMLHttpRequest" || target === "WebSocket")) {
|
|
18934
18981
|
bindingTargets.push("TextEncoder", "TextDecoder");
|
|
18935
|
-
bindingTargets.push("URL", "URLSearchParams", "Blob", "FormData");
|
|
18982
|
+
bindingTargets.push("URL", "URLSearchParams", "Blob", "File", "FormData");
|
|
18936
18983
|
}
|
|
18937
18984
|
if (targets.includes("CustomEvent")) bindingTargets.push("Event");
|
|
18938
18985
|
return [...new Set(bindingTargets)].filter((target) => REQUEST_GLOBAL_FREE_BINDING_TARGETS.has(target));
|
|
@@ -18977,6 +19024,7 @@ function createRequestGlobalsPassiveBindingsCode(targets, explicitBindingTargets
|
|
|
18977
19024
|
if (target === "URL") return `var URL = ${REQUEST_GLOBAL_EXPOSE_HELPER}("URL",${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(${actualRef},["https://request-globals.invalid"])?${actualRef}:${REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER}(globalThis.URL,["https://request-globals.invalid"])?globalThis.URL:${placeholderFactory})`;
|
|
18978
19025
|
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})`;
|
|
18979
19026
|
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})`;
|
|
19027
|
+
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})`;
|
|
18980
19028
|
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})`;
|
|
18981
19029
|
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})`;
|
|
18982
19030
|
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})`;
|
|
@@ -22959,16 +23007,19 @@ async function loadTransformPageEntries(scanService) {
|
|
|
22959
23007
|
pluginPages
|
|
22960
23008
|
};
|
|
22961
23009
|
}
|
|
22962
|
-
function invalidatePageLayoutCaches(configService, compilationCache, styleBlocksCache) {
|
|
23010
|
+
function invalidatePageLayoutCaches(configService, compilationCache, styleBlocksCache, styleRefreshTokens) {
|
|
22963
23011
|
if (!configService) return;
|
|
22964
23012
|
for (const [cachedId, cached] of compilationCache.entries()) {
|
|
22965
23013
|
if (cached.isPage) cached.source = void 0;
|
|
22966
23014
|
styleBlocksCache.delete(cachedId);
|
|
23015
|
+
styleRefreshTokens?.delete(cachedId);
|
|
22967
23016
|
}
|
|
22968
23017
|
}
|
|
22969
|
-
function invalidateVueFileCaches(file, compilationCache, styleBlocksCache, options) {
|
|
22970
|
-
if (!options.existsSync(file))
|
|
22971
|
-
|
|
23018
|
+
function invalidateVueFileCaches(file, compilationCache, styleBlocksCache, options, styleRefreshTokens) {
|
|
23019
|
+
if (!options.existsSync(file)) {
|
|
23020
|
+
compilationCache.delete(file);
|
|
23021
|
+
styleRefreshTokens?.delete(file);
|
|
23022
|
+
} else {
|
|
22972
23023
|
const cached = compilationCache.get(file);
|
|
22973
23024
|
if (cached) {
|
|
22974
23025
|
cached.source = void 0;
|
|
@@ -22978,15 +23029,15 @@ function invalidateVueFileCaches(file, compilationCache, styleBlocksCache, optio
|
|
|
22978
23029
|
styleBlocksCache.delete(file);
|
|
22979
23030
|
}
|
|
22980
23031
|
function handleTransformLayoutInvalidation(file, options) {
|
|
22981
|
-
const { configService, compilationCache, styleBlocksCache, isLayoutFile, invalidateResolvedPageLayoutsCache } = options;
|
|
23032
|
+
const { configService, compilationCache, styleBlocksCache, styleRefreshTokens, isLayoutFile, invalidateResolvedPageLayoutsCache } = options;
|
|
22982
23033
|
if (!configService || !isLayoutFile(file, configService)) return false;
|
|
22983
23034
|
invalidateResolvedPageLayoutsCache(configService.absoluteSrcRoot);
|
|
22984
|
-
invalidatePageLayoutCaches(configService, compilationCache, styleBlocksCache);
|
|
23035
|
+
invalidatePageLayoutCaches(configService, compilationCache, styleBlocksCache, styleRefreshTokens);
|
|
22985
23036
|
return true;
|
|
22986
23037
|
}
|
|
22987
23038
|
function handleTransformVueFileInvalidation(file, options) {
|
|
22988
23039
|
if (!isVueLikeId(file)) return false;
|
|
22989
|
-
invalidateVueFileCaches(file, options.compilationCache, options.styleBlocksCache, { existsSync: options.existsSync });
|
|
23040
|
+
invalidateVueFileCaches(file, options.compilationCache, options.styleBlocksCache, { existsSync: options.existsSync }, options.styleRefreshTokens);
|
|
22990
23041
|
return true;
|
|
22991
23042
|
}
|
|
22992
23043
|
async function ensureSfcStyleBlocks(filename, styleBlocksCache, options) {
|
|
@@ -23140,7 +23191,8 @@ async function finalizeTransformEntryScript(options) {
|
|
|
23140
23191
|
}
|
|
23141
23192
|
}
|
|
23142
23193
|
const hasScopedSlotHostGenerics = Boolean(result.componentGenerics && Object.keys(result.componentGenerics).length > 0);
|
|
23143
|
-
|
|
23194
|
+
const needsSetupSlotHostProperties = result.script && mayNeedScopedSlotHostPropertiesForSetupSlotsInJs(result.script);
|
|
23195
|
+
if (!isPage && !isApp && result.script && (hasScopedSlotHostGenerics || result.template?.includes(WEVU_SLOT_OWNER_ID_PROP) || result.template?.includes("<slot") || result.template?.includes("vueSlots") || needsSetupSlotHostProperties)) {
|
|
23144
23196
|
const injectedProps = injectScopedSlotHostPropertiesInJs(result.script);
|
|
23145
23197
|
if (injectedProps.transformed) {
|
|
23146
23198
|
result.script = injectedProps.code;
|
|
@@ -23330,7 +23382,8 @@ async function finalizeCompiledVueLikeResult(options) {
|
|
|
23330
23382
|
if (injectedPick.transformed) result.script = injectedPick.code;
|
|
23331
23383
|
}
|
|
23332
23384
|
const hasScopedSlotHostGenerics = Boolean(result.componentGenerics && Object.keys(result.componentGenerics).length > 0);
|
|
23333
|
-
|
|
23385
|
+
const needsSetupSlotHostProperties = result.script && mayNeedScopedSlotHostPropertiesForSetupSlotsInJs(result.script);
|
|
23386
|
+
if (!isPage && !isApp && result.script && (hasScopedSlotHostGenerics || result.template?.includes(WEVU_SLOT_OWNER_ID_PROP) || result.template?.includes("<slot") || result.template?.includes("vueSlots") || needsSetupSlotHostProperties)) {
|
|
23334
23387
|
const injectedProps = injectScopedSlotHostPropertiesInJs(result.script);
|
|
23335
23388
|
if (injectedProps.transformed) result.script = injectedProps.code;
|
|
23336
23389
|
}
|
|
@@ -23506,8 +23559,8 @@ async function emitNativeLayoutAssetsIfNeeded(options) {
|
|
|
23506
23559
|
});
|
|
23507
23560
|
}
|
|
23508
23561
|
function emitScriptlessComponentJsFallbackIfMissing(options) {
|
|
23509
|
-
const { pluginCtx, bundle, relativeBase, scriptExtension } = options;
|
|
23510
|
-
ensureScriptlessComponentAsset(pluginCtx, bundle, relativeBase, scriptExtension);
|
|
23562
|
+
const { pluginCtx, bundle, relativeBase, scriptExtension, source } = options;
|
|
23563
|
+
ensureScriptlessComponentAsset(pluginCtx, bundle, relativeBase, scriptExtension, source);
|
|
23511
23564
|
}
|
|
23512
23565
|
function resolveVueLayoutScriptFallbackState(options) {
|
|
23513
23566
|
const resolvedOptions = resolveVueLayoutAssetOptions({
|
|
@@ -23553,7 +23606,8 @@ async function emitVueLayoutScriptFallbackIfNeeded(options) {
|
|
|
23553
23606
|
pluginCtx,
|
|
23554
23607
|
bundle,
|
|
23555
23608
|
relativeBase: resolvedOptions.relativeBase,
|
|
23556
|
-
scriptExtension: resolvedOptions.scriptExtension
|
|
23609
|
+
scriptExtension: resolvedOptions.scriptExtension,
|
|
23610
|
+
source: SLOT_HOST_SCRIPTLESS_COMPONENT_STUB
|
|
23557
23611
|
});
|
|
23558
23612
|
}
|
|
23559
23613
|
function createBundleLayoutEmitters(options) {
|
|
@@ -23642,7 +23696,8 @@ function emitAppShellAssetsIfNeeded(options) {
|
|
|
23642
23696
|
pluginCtx: options.pluginCtx,
|
|
23643
23697
|
bundle: options.bundle,
|
|
23644
23698
|
relativeBase,
|
|
23645
|
-
scriptExtension: options.scriptExtension
|
|
23699
|
+
scriptExtension: options.scriptExtension,
|
|
23700
|
+
source: SLOT_HOST_SCRIPTLESS_COMPONENT_STUB
|
|
23646
23701
|
});
|
|
23647
23702
|
}
|
|
23648
23703
|
//#endregion
|
|
@@ -23987,8 +24042,18 @@ function parseUsingComponents(config) {
|
|
|
23987
24042
|
return {};
|
|
23988
24043
|
}
|
|
23989
24044
|
}
|
|
24045
|
+
function createSfcStyleBlocksSignature(styleBlocks) {
|
|
24046
|
+
if (!styleBlocks?.length) return "";
|
|
24047
|
+
return JSON.stringify(styleBlocks.map((styleBlock) => ({
|
|
24048
|
+
attrs: styleBlock.attrs,
|
|
24049
|
+
content: styleBlock.content,
|
|
24050
|
+
lang: styleBlock.lang,
|
|
24051
|
+
module: styleBlock.module,
|
|
24052
|
+
scoped: styleBlock.scoped
|
|
24053
|
+
})));
|
|
24054
|
+
}
|
|
23990
24055
|
async function transformVueLikeFile(options) {
|
|
23991
|
-
const { ctx, pluginCtx, code, id, compilationCache, setAppShell, pageMatcher, setPageMatcher, scanDirtySynced, setScanDirtySynced, reExportResolutionCache, compileOptionsCache, styleBlocksCache, scopedSlotModules, emittedScopedSlotChunks, classStyleRuntimeWarned, readAndParseSfc, createReadAndParseSfcOptions } = options;
|
|
24056
|
+
const { ctx, pluginCtx, code, id, compilationCache, setAppShell, pageMatcher, setPageMatcher, scanDirtySynced, setScanDirtySynced, reExportResolutionCache, compileOptionsCache, styleBlocksCache, styleRefreshTokens, scopedSlotModules, emittedScopedSlotChunks, classStyleRuntimeWarned, readAndParseSfc, createReadAndParseSfcOptions } = options;
|
|
23992
24057
|
const vueTransformTiming = ctx.configService?.weappViteConfig?.debug?.vueTransformTiming;
|
|
23993
24058
|
const { measureStage, reportTiming } = createTransformStageMeasurer(vueTransformTiming);
|
|
23994
24059
|
const configService = ctx.configService;
|
|
@@ -24002,6 +24067,7 @@ async function transformVueLikeFile(options) {
|
|
|
24002
24067
|
});
|
|
24003
24068
|
if (!filename) return null;
|
|
24004
24069
|
try {
|
|
24070
|
+
const previousStyleSignature = createSfcStyleBlocksSignature(compilationCache.get(filename)?.result.meta?.styleBlocks ?? styleBlocksCache.get(filename));
|
|
24005
24071
|
const source = await measureStage("readSource", async () => await loadTransformSource({
|
|
24006
24072
|
code,
|
|
24007
24073
|
filename,
|
|
@@ -24054,8 +24120,15 @@ async function transformVueLikeFile(options) {
|
|
|
24054
24120
|
compileVueFile,
|
|
24055
24121
|
compileJsxFile
|
|
24056
24122
|
})));
|
|
24057
|
-
|
|
24058
|
-
|
|
24123
|
+
const currentStyleBlocks = Array.isArray(result.meta?.styleBlocks) ? result.meta.styleBlocks : styleBlocksCache.get(filename);
|
|
24124
|
+
if (currentStyleBlocks) styleBlocksCache.set(filename, currentStyleBlocks);
|
|
24125
|
+
if (configService.isDev && ctx.runtimeState?.build?.hmr?.dirtyVueEntryIds?.has(filename)) {
|
|
24126
|
+
const currentStyleSignature = createSfcStyleBlocksSignature(currentStyleBlocks);
|
|
24127
|
+
const hmrEventId = ctx.runtimeState.build.hmr.profile.eventId;
|
|
24128
|
+
if (hmrEventId != null && currentStyleSignature && currentStyleSignature !== previousStyleSignature) styleRefreshTokens.set(filename, hmrEventId);
|
|
24129
|
+
else styleRefreshTokens.delete(filename);
|
|
24130
|
+
}
|
|
24131
|
+
const sfcStyleDependencies = syncVueSfcStyleDependencies(ctx, filename, currentStyleBlocks);
|
|
24059
24132
|
for (const dependency of sfcStyleDependencies) addNormalizedWatchFile(pluginCtx, dependency);
|
|
24060
24133
|
registerScopedSlotHostGenerics(ctx, result.scopedSlotComponents, parseUsingComponents(result.config));
|
|
24061
24134
|
await measureStage("finalizeCompiledResult", async () => {
|
|
@@ -24084,7 +24157,7 @@ async function transformVueLikeFile(options) {
|
|
|
24084
24157
|
isPage,
|
|
24085
24158
|
isApp,
|
|
24086
24159
|
isDev: configService.isDev,
|
|
24087
|
-
hmrStyleToken: configService.isDev
|
|
24160
|
+
hmrStyleToken: configService.isDev ? styleRefreshTokens.get(filename) : void 0
|
|
24088
24161
|
}));
|
|
24089
24162
|
reportTiming(filename, isPage);
|
|
24090
24163
|
return {
|
|
@@ -24106,6 +24179,7 @@ function createVueTransformPlugin(ctx) {
|
|
|
24106
24179
|
const reExportResolutionCache = /* @__PURE__ */ new Map();
|
|
24107
24180
|
const compileOptionsCache = /* @__PURE__ */ new Map();
|
|
24108
24181
|
const styleBlocksCache = /* @__PURE__ */ new Map();
|
|
24182
|
+
const styleRefreshTokens = /* @__PURE__ */ new Map();
|
|
24109
24183
|
const scopedSlotModules = /* @__PURE__ */ new Map();
|
|
24110
24184
|
const emittedScopedSlotChunks = /* @__PURE__ */ new Set();
|
|
24111
24185
|
const classStyleRuntimeWarned = { value: false };
|
|
@@ -24165,6 +24239,7 @@ function createVueTransformPlugin(ctx) {
|
|
|
24165
24239
|
reExportResolutionCache,
|
|
24166
24240
|
compileOptionsCache,
|
|
24167
24241
|
styleBlocksCache,
|
|
24242
|
+
styleRefreshTokens,
|
|
24168
24243
|
scopedSlotModules,
|
|
24169
24244
|
emittedScopedSlotChunks,
|
|
24170
24245
|
classStyleRuntimeWarned,
|
|
@@ -24193,12 +24268,14 @@ function createVueTransformPlugin(ctx) {
|
|
|
24193
24268
|
configService: ctx.configService,
|
|
24194
24269
|
compilationCache,
|
|
24195
24270
|
styleBlocksCache,
|
|
24271
|
+
styleRefreshTokens,
|
|
24196
24272
|
isLayoutFile,
|
|
24197
24273
|
invalidateResolvedPageLayoutsCache
|
|
24198
24274
|
});
|
|
24199
24275
|
handleTransformVueFileInvalidation(normalizedId, {
|
|
24200
24276
|
compilationCache,
|
|
24201
24277
|
styleBlocksCache,
|
|
24278
|
+
styleRefreshTokens,
|
|
24202
24279
|
existsSync: fs.existsSync
|
|
24203
24280
|
});
|
|
24204
24281
|
const profile = ctx.runtimeState?.build?.hmr?.profile;
|
|
@@ -24214,12 +24291,14 @@ function createVueTransformPlugin(ctx) {
|
|
|
24214
24291
|
configService: ctx.configService,
|
|
24215
24292
|
compilationCache,
|
|
24216
24293
|
styleBlocksCache,
|
|
24294
|
+
styleRefreshTokens,
|
|
24217
24295
|
isLayoutFile,
|
|
24218
24296
|
invalidateResolvedPageLayoutsCache
|
|
24219
24297
|
})) return [];
|
|
24220
24298
|
if (!handleTransformVueFileInvalidation(file, {
|
|
24221
24299
|
compilationCache,
|
|
24222
24300
|
styleBlocksCache,
|
|
24301
|
+
styleRefreshTokens,
|
|
24223
24302
|
existsSync: fs.existsSync
|
|
24224
24303
|
})) return;
|
|
24225
24304
|
return [];
|
|
@@ -25199,7 +25278,7 @@ function createConfigServicePlugin(ctx) {
|
|
|
25199
25278
|
}
|
|
25200
25279
|
//#endregion
|
|
25201
25280
|
//#region src/runtime/jsonPlugin.ts
|
|
25202
|
-
const APP_CONFIG_RE = /app\.json(?:\.[jt]s)?$/;
|
|
25281
|
+
const APP_CONFIG_RE = /(?:^|[/\\])app\.json(?:\.[jt]s)?$/;
|
|
25203
25282
|
const SCRIPT_JSON_CONFIG_RE = /\.json\.[jt]s$/;
|
|
25204
25283
|
function createJsonService(ctx) {
|
|
25205
25284
|
const cache = ctx.runtimeState.json.cache;
|
|
@@ -25398,7 +25477,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
25398
25477
|
const vueAppPath = await findVueEntry(appBasename);
|
|
25399
25478
|
let configFromVue;
|
|
25400
25479
|
if (!appConfigFile && vueAppPath) {
|
|
25401
|
-
const { extractConfigFromVue } = await import("./file-
|
|
25480
|
+
const { extractConfigFromVue } = await import("./file-CTUeDbPw.mjs");
|
|
25402
25481
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
25403
25482
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
25404
25483
|
}
|
|
@@ -84,7 +84,7 @@ function resolveAutoRoutesMacroImportPath() {
|
|
|
84
84
|
}
|
|
85
85
|
async function resolveAutoRoutesInlineSnapshot() {
|
|
86
86
|
try {
|
|
87
|
-
const { getCompilerContext } = await import("./getInstance-
|
|
87
|
+
const { getCompilerContext } = await import("./getInstance-DwrlgiHQ.mjs");
|
|
88
88
|
const compilerContext = getCompilerContext();
|
|
89
89
|
const service = compilerContext.autoRoutesService;
|
|
90
90
|
const reference = service?.getReference?.();
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $n as WebPlatform, A as Ref, Bn as WeappViteHostMeta, C as LoadConfigOptions, D as MethodDefinitions, E as InlineConfig, F as RolldownPlugin, Gn as ResolveWeappViteTargetOptions, Hn as createWeappViteHostMeta, I as RolldownPluginOption, Jn as WeappVitePlatform, Kn as ResolvedWeappViteTarget, L as RolldownWatchOptions, M as RolldownBuild, N as RolldownOptions, O as Plugin, P as RolldownOutput, Qn as WeappViteTargetKind, R as RolldownWatcher, S as CompilerContext, T as ConfigEnv, Un as isWeappViteHost, Vn as applyWeappViteHostMeta, Wn as resolveWeappViteHostMeta, Xn as WeappViteTargetDescriptor, Yn as WeappViteRuntime, Zn as WeappViteTargetInput, _ as definePageJson, a as UserConfigFnNoEnvPlain, at as WeappViteConfig, c as UserConfigFnPromise, d as Component, er as getSupportedWeappVitePlatforms, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, j as ResolvedConfig, k as PluginOption, l as defineConfig, m as Theme, n as UserConfigExport, nr as isWebPlatform, o as UserConfigFnObject, p as Sitemap, qn as WEB_PLATFORM_ALIASES, r as UserConfigFn, rr as resolveWeappViteTarget, s as UserConfigFnObjectPlain, t as UserConfig, tr as getSupportedWeappViteTargetDescriptors, u as App, v as defineSitemapJson, w as ComputedDefinitions, y as defineThemeJson, z as ViteDevServer, zn as WEAPP_VITE_HOST_NAME } from "./config-
|
|
1
|
+
import { $n as WebPlatform, A as Ref, Bn as WeappViteHostMeta, C as LoadConfigOptions, D as MethodDefinitions, E as InlineConfig, F as RolldownPlugin, Gn as ResolveWeappViteTargetOptions, Hn as createWeappViteHostMeta, I as RolldownPluginOption, Jn as WeappVitePlatform, Kn as ResolvedWeappViteTarget, L as RolldownWatchOptions, M as RolldownBuild, N as RolldownOptions, O as Plugin, P as RolldownOutput, Qn as WeappViteTargetKind, R as RolldownWatcher, S as CompilerContext, T as ConfigEnv, Un as isWeappViteHost, Vn as applyWeappViteHostMeta, Wn as resolveWeappViteHostMeta, Xn as WeappViteTargetDescriptor, Yn as WeappViteRuntime, Zn as WeappViteTargetInput, _ as definePageJson, a as UserConfigFnNoEnvPlain, at as WeappViteConfig, c as UserConfigFnPromise, d as Component, er as getSupportedWeappVitePlatforms, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, j as ResolvedConfig, k as PluginOption, l as defineConfig, m as Theme, n as UserConfigExport, nr as isWebPlatform, o as UserConfigFnObject, p as Sitemap, qn as WEB_PLATFORM_ALIASES, r as UserConfigFn, rr as resolveWeappViteTarget, s as UserConfigFnObjectPlain, t as UserConfig, tr as getSupportedWeappViteTargetDescriptors, u as App, v as defineSitemapJson, w as ComputedDefinitions, y as defineThemeJson, z as ViteDevServer, zn as WEAPP_VITE_HOST_NAME } from "./config-Ds7MBgQm.mjs";
|
|
2
2
|
import { a as createWevuComponent, i as WevuComponentOptions, n as defineProps, r as setPageLayout, t as defineEmits } from "./runtime-CDNs17Qq.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/createContext.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as defineThemeJson, i as defineSitemapJson, n as defineComponentJson, r as definePageJson, t as defineAppJson } from "./json-BL8Dhhk6.mjs";
|
|
2
2
|
import { a as resolveWeappViteHostMeta, i as isWeappViteHost, n as applyWeappViteHostMeta, r as createWeappViteHostMeta, t as WEAPP_VITE_HOST_NAME } from "./pluginHost--CaeyWpA.mjs";
|
|
3
3
|
import { t as defineConfig } from "./config-DRGcCi3h.mjs";
|
|
4
|
-
import { c as getSupportedWeappViteTargetDescriptors, l as isWebPlatform, o as WEB_PLATFORM_ALIASES, s as getSupportedWeappVitePlatforms, t as createCompilerContext, u as resolveWeappViteTarget } from "./createContext-
|
|
4
|
+
import { c as getSupportedWeappViteTargetDescriptors, l as isWebPlatform, o as WEB_PLATFORM_ALIASES, s as getSupportedWeappVitePlatforms, t as createCompilerContext, u as resolveWeappViteTarget } from "./createContext-D2uF0JED.mjs";
|
|
5
5
|
import { i as createWevuComponent, n as defineProps, r as setPageLayout, t as defineEmits } from "./runtime-C3z9pDQB.mjs";
|
|
6
6
|
export { WEAPP_VITE_HOST_NAME, WEB_PLATFORM_ALIASES, applyWeappViteHostMeta, createCompilerContext, createWeappViteHostMeta, createWevuComponent, defineAppJson, defineComponentJson, defineConfig, defineEmits, definePageJson, defineProps, defineSitemapJson, defineThemeJson, getSupportedWeappVitePlatforms, getSupportedWeappViteTargetDescriptors, isWeappViteHost, isWebPlatform, resolveWeappViteHostMeta, resolveWeappViteTarget, 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-Ds7MBgQm.mjs";
|
|
2
2
|
export { type App, type Component, type Page, type Sitemap, type Theme, defineAppJson, defineComponentJson, definePageJson, defineSitemapJson, defineThemeJson };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { r as logger_default } from "./logger-mt4mSTqV.mjs";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { connectMiniProgram } from "weapp-ide-cli";
|
|
4
|
+
import { determineAgent } from "@vercel/detect-agent";
|
|
5
|
+
import { DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, createWeappViteMcpServer, startWeappViteMcpServer } from "@weapp-vite/mcp";
|
|
6
|
+
//#region src/aiEnvironment.ts
|
|
7
|
+
const AI_ENV_KEYS = [
|
|
8
|
+
"CODEX_HOME",
|
|
9
|
+
"CODEX_SANDBOX",
|
|
10
|
+
"CODEX_USER_AGENT",
|
|
11
|
+
"CLAUDECODE",
|
|
12
|
+
"CLAUDE_CODE",
|
|
13
|
+
"CURSOR_AGENT",
|
|
14
|
+
"GITHUB_COPILOT_AGENT",
|
|
15
|
+
"OPENAI_AGENT"
|
|
16
|
+
];
|
|
17
|
+
function isTruthyEnvValue(value) {
|
|
18
|
+
if (value === void 0) return false;
|
|
19
|
+
const normalized = value.trim().toLowerCase();
|
|
20
|
+
return normalized !== "" && normalized !== "0" && normalized !== "false" && normalized !== "no";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @description 判断当前命令是否由 AI 开发代理触发。
|
|
24
|
+
*/
|
|
25
|
+
function isAiDevelopmentEnvironment(env = process.env) {
|
|
26
|
+
if (isTruthyEnvValue(env.WEAPP_VITE_AI)) return true;
|
|
27
|
+
return AI_ENV_KEYS.some((key) => isTruthyEnvValue(env[key]));
|
|
28
|
+
}
|
|
29
|
+
function resolveAiDevelopmentEnvironmentFromEnv(env = process.env) {
|
|
30
|
+
if (isTruthyEnvValue(env.WEAPP_VITE_AI)) return {
|
|
31
|
+
agentName: env.WEAPP_VITE_AI.trim(),
|
|
32
|
+
isAgent: true
|
|
33
|
+
};
|
|
34
|
+
if (isAiDevelopmentEnvironment(env)) return { isAgent: true };
|
|
35
|
+
return { isAgent: false };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @description 使用标准 agent 检测库识别 AI 终端,并保留 weapp-vite 显式环境变量兜底。
|
|
39
|
+
*/
|
|
40
|
+
async function detectAiDevelopmentEnvironment(env = process.env) {
|
|
41
|
+
const envResult = resolveAiDevelopmentEnvironmentFromEnv(env);
|
|
42
|
+
if (envResult.isAgent) return envResult;
|
|
43
|
+
try {
|
|
44
|
+
const result = await determineAgent();
|
|
45
|
+
return {
|
|
46
|
+
agentName: result.isAgent ? result.agent.name : void 0,
|
|
47
|
+
isAgent: result.isAgent
|
|
48
|
+
};
|
|
49
|
+
} catch {
|
|
50
|
+
return envResult;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function resolveBooleanLikeEnv(value) {
|
|
54
|
+
if (value === void 0) return;
|
|
55
|
+
const normalized = value.trim().toLowerCase();
|
|
56
|
+
if (!normalized) return;
|
|
57
|
+
if (normalized === "ai") return "ai";
|
|
58
|
+
if ([
|
|
59
|
+
"1",
|
|
60
|
+
"true",
|
|
61
|
+
"yes",
|
|
62
|
+
"on"
|
|
63
|
+
].includes(normalized)) return true;
|
|
64
|
+
if ([
|
|
65
|
+
"0",
|
|
66
|
+
"false",
|
|
67
|
+
"no",
|
|
68
|
+
"off"
|
|
69
|
+
].includes(normalized)) return false;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/mcp.ts
|
|
73
|
+
function normalizeEndpoint(input) {
|
|
74
|
+
const value = typeof input === "string" ? input.trim() : "";
|
|
75
|
+
if (!value) return DEFAULT_MCP_ENDPOINT;
|
|
76
|
+
return value.startsWith("/") ? value : `/${value}`;
|
|
77
|
+
}
|
|
78
|
+
function resolveProjectMcpPort(projectRoot = process.cwd()) {
|
|
79
|
+
let hash = 0;
|
|
80
|
+
for (const char of projectRoot) hash = hash * 31 + char.charCodeAt(0) >>> 0;
|
|
81
|
+
return DEFAULT_MCP_PORT + hash % 2e4;
|
|
82
|
+
}
|
|
83
|
+
function normalizePort(input, cwd) {
|
|
84
|
+
if (input === void 0 || input === "auto") return resolveProjectMcpPort(cwd);
|
|
85
|
+
if (typeof input === "number" && Number.isInteger(input) && input > 0 && input <= 65535) return input;
|
|
86
|
+
return DEFAULT_MCP_PORT;
|
|
87
|
+
}
|
|
88
|
+
function resolveAutoStart(input, options) {
|
|
89
|
+
const env = options.env ?? process.env;
|
|
90
|
+
const value = resolveBooleanLikeEnv(env.WEAPP_VITE_MCP) ?? input ?? "ai";
|
|
91
|
+
if (value === "ai") return options.isAgent ?? resolveAiDevelopmentEnvironmentFromEnv(env).isAgent;
|
|
92
|
+
return value === true;
|
|
93
|
+
}
|
|
94
|
+
function resolveWeappMcpConfig(config, options = {}) {
|
|
95
|
+
if (config === false) return {
|
|
96
|
+
enabled: false,
|
|
97
|
+
autoStart: false,
|
|
98
|
+
host: DEFAULT_MCP_HOST,
|
|
99
|
+
port: DEFAULT_MCP_PORT,
|
|
100
|
+
endpoint: DEFAULT_MCP_ENDPOINT,
|
|
101
|
+
restEndpoint: DEFAULT_RUNTIME_REST_ENDPOINT
|
|
102
|
+
};
|
|
103
|
+
const record = typeof config === "object" && config ? config : {};
|
|
104
|
+
return {
|
|
105
|
+
agentName: options.agentName,
|
|
106
|
+
enabled: record.enabled !== false,
|
|
107
|
+
autoStart: resolveAutoStart(record.autoStart, options),
|
|
108
|
+
host: typeof record.host === "string" && record.host.trim().length > 0 ? record.host.trim() : DEFAULT_MCP_HOST,
|
|
109
|
+
port: normalizePort(record.port, options.cwd),
|
|
110
|
+
endpoint: normalizeEndpoint(record.endpoint),
|
|
111
|
+
restEndpoint: record.restEndpoint === false ? false : normalizeEndpoint(record.restEndpoint ?? DEFAULT_RUNTIME_REST_ENDPOINT)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
async function startWeappViteMcpServer$1(options) {
|
|
115
|
+
return startWeappViteMcpServer({
|
|
116
|
+
runtimeHooks: { connectMiniProgram },
|
|
117
|
+
...options,
|
|
118
|
+
onReady: options?.onReady ?? ((message) => {
|
|
119
|
+
logger_default.info(message);
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { createWeappViteMcpServer as a, startWeappViteMcpServer$1 as c, DEFAULT_RUNTIME_REST_ENDPOINT as i, detectAiDevelopmentEnvironment as l, DEFAULT_MCP_HOST as n, resolveProjectMcpPort as o, DEFAULT_MCP_PORT as r, resolveWeappMcpConfig as s, DEFAULT_MCP_ENDPOINT as t };
|
package/dist/mcp.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Et as WeappMcpConfig } from "./config-
|
|
1
|
+
import { Et as WeappMcpConfig } from "./config-Ds7MBgQm.mjs";
|
|
2
2
|
import { CreateServerOptions, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, McpServerHandle, StartMcpServerOptions, createWeappViteMcpServer } from "@weapp-vite/mcp";
|
|
3
3
|
|
|
4
4
|
//#region src/mcp.d.ts
|
|
5
5
|
interface ResolvedWeappMcpConfig {
|
|
6
|
+
agentName?: string;
|
|
6
7
|
enabled: boolean;
|
|
7
8
|
autoStart: boolean;
|
|
8
9
|
host: string;
|
|
@@ -12,7 +13,14 @@ interface ResolvedWeappMcpConfig {
|
|
|
12
13
|
}
|
|
13
14
|
interface WeappViteMcpServerOptions extends StartMcpServerOptions {}
|
|
14
15
|
interface WeappViteMcpServerHandle extends McpServerHandle {}
|
|
15
|
-
|
|
16
|
+
interface ResolveWeappMcpConfigOptions {
|
|
17
|
+
agentName?: string;
|
|
18
|
+
cwd?: string;
|
|
19
|
+
env?: NodeJS.ProcessEnv;
|
|
20
|
+
isAgent?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare function resolveProjectMcpPort(projectRoot?: string): number;
|
|
23
|
+
declare function resolveWeappMcpConfig(config?: boolean | WeappMcpConfig, options?: ResolveWeappMcpConfigOptions): ResolvedWeappMcpConfig;
|
|
16
24
|
declare function startWeappViteMcpServer(options?: WeappViteMcpServerOptions): Promise<WeappViteMcpServerHandle>;
|
|
17
25
|
//#endregion
|
|
18
|
-
export { type CreateServerOptions, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, ResolvedWeappMcpConfig, WeappViteMcpServerHandle, WeappViteMcpServerOptions, createWeappViteMcpServer, resolveWeappMcpConfig, startWeappViteMcpServer };
|
|
26
|
+
export { type CreateServerOptions, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, ResolveWeappMcpConfigOptions, ResolvedWeappMcpConfig, WeappViteMcpServerHandle, WeappViteMcpServerOptions, createWeappViteMcpServer, resolveProjectMcpPort, resolveWeappMcpConfig, startWeappViteMcpServer };
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as createWeappViteMcpServer, i as DEFAULT_RUNTIME_REST_ENDPOINT, n as DEFAULT_MCP_HOST, o as
|
|
2
|
-
export { DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, createWeappViteMcpServer, resolveWeappMcpConfig, startWeappViteMcpServer };
|
|
1
|
+
import { a as createWeappViteMcpServer, c as startWeappViteMcpServer, i as DEFAULT_RUNTIME_REST_ENDPOINT, n as DEFAULT_MCP_HOST, o as resolveProjectMcpPort, r as DEFAULT_MCP_PORT, s as resolveWeappMcpConfig, t as DEFAULT_MCP_ENDPOINT } from "./mcp-YXCIQr-Z.mjs";
|
|
2
|
+
export { DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT, createWeappViteMcpServer, resolveProjectMcpPort, resolveWeappMcpConfig, startWeappViteMcpServer };
|