weapp-vite 6.16.43 → 6.16.45
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 +210 -103
- package/dist/{config-CobCpW-a.d.mts → config-Ds7MBgQm.d.mts} +2 -2
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-CRpsNCP2.mjs → createContext-Bqsm_duR.mjs} +99 -45
- package/dist/{file-Wkzc9gMS.mjs → file-CsF2X7eL.mjs} +1 -1
- package/dist/file-CsjD5DM3.mjs +2 -0
- package/dist/getInstance-BNM8-aPJ.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 +16 -16
- package/dist/file-iVST36Dh.mjs +0 -2
- package/dist/getInstance-QuyA4zlX.mjs +0 -2
- package/dist/mcp-qmDOTH07.mjs +0 -43
package/dist/auto-routes.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getRouteRuntimeGlobalKeys, n as getCompilerContext } from "./createContext-
|
|
1
|
+
import { g as getRouteRuntimeGlobalKeys, n as getCompilerContext } from "./createContext-Bqsm_duR.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,7 +1,7 @@
|
|
|
1
|
-
import { C as createCjsConfigLoadError, E as isPathInside, S as parseCommentJson, T as shouldPassPlatformArgToIdeOpen, _ as createBuildScopeConfigFromCli, a as formatBytes, b as getProjectConfigFileName, d as syncProjectSupportFiles, f as syncManagedTsconfigBootstrapFiles, h as resolveHmrProfileJsonPath, m as SHARED_CHUNK_VIRTUAL_PREFIX, p as createSharedBuildConfig, t as createCompilerContext, u as resolveWeappViteTarget, v as resolveWeappConfigFile, w as getDefaultIdeProjectRoot, x as loadViteConfigFile, y as checkRuntime } from "./createContext-
|
|
1
|
+
import { C as createCjsConfigLoadError, E as isPathInside, S as parseCommentJson, T as shouldPassPlatformArgToIdeOpen, _ as createBuildScopeConfigFromCli, a as formatBytes, b as getProjectConfigFileName, d as syncProjectSupportFiles, f as syncManagedTsconfigBootstrapFiles, h as resolveHmrProfileJsonPath, m as SHARED_CHUNK_VIRTUAL_PREFIX, p as createSharedBuildConfig, t as createCompilerContext, u as resolveWeappViteTarget, v as resolveWeappConfigFile, w as getDefaultIdeProjectRoot, x as loadViteConfigFile, y as checkRuntime } from "./createContext-Bqsm_duR.mjs";
|
|
2
2
|
import { r as logger_default, t as colors } from "./logger-mt4mSTqV.mjs";
|
|
3
|
-
import { h as VERSION } from "./file-
|
|
4
|
-
import {
|
|
3
|
+
import { h as VERSION } from "./file-CsF2X7eL.mjs";
|
|
4
|
+
import { c as startWeappViteMcpServer, l as detectAiDevelopmentEnvironment, s as resolveWeappMcpConfig } from "./mcp-YXCIQr-Z.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import path, { posix } from "pathe";
|
|
7
7
|
import path$1 from "node:path";
|
|
@@ -9,7 +9,7 @@ import { defu } from "@weapp-core/shared";
|
|
|
9
9
|
import { fs } from "@weapp-core/shared/fs";
|
|
10
10
|
import fs$1 from "node:fs";
|
|
11
11
|
import process from "node:process";
|
|
12
|
-
import fs$2 from "node:fs/promises";
|
|
12
|
+
import fs$2, { mkdir, writeFile } from "node:fs/promises";
|
|
13
13
|
import { build, createServer } from "vite";
|
|
14
14
|
import os from "node:os";
|
|
15
15
|
import { execFile, spawn } from "node:child_process";
|
|
@@ -24,6 +24,7 @@ import { determineAgent } from "@vercel/detect-agent";
|
|
|
24
24
|
import { initConfig } from "@weapp-core/init";
|
|
25
25
|
import { createInterface } from "node:readline/promises";
|
|
26
26
|
import { clearTimeout, setTimeout as setTimeout$1 } from "node:timers";
|
|
27
|
+
import net from "node:net";
|
|
27
28
|
//#region src/cli/runtime.ts
|
|
28
29
|
function logRuntimeTarget(targets, options = {}) {
|
|
29
30
|
if (options.silent) return;
|
|
@@ -412,6 +413,7 @@ async function stabilizeOpenedWechatIdeProject(projectPath, servicePortEnabled,
|
|
|
412
413
|
projectPath
|
|
413
414
|
], options), {
|
|
414
415
|
automatorMode: options.useAutomatorOpen === false ? "skip" : "prefer",
|
|
416
|
+
engineBuildFallbackToCli: true,
|
|
415
417
|
httpMode: "prefer",
|
|
416
418
|
onNonLoginError: (error) => logger_default.error(error),
|
|
417
419
|
preserveProjectRoot: options.useAutomatorOpen === false,
|
|
@@ -3506,9 +3508,117 @@ function registerNpmCommand(cli) {
|
|
|
3506
3508
|
});
|
|
3507
3509
|
}
|
|
3508
3510
|
//#endregion
|
|
3511
|
+
//#region src/cli/mcpDetached.ts
|
|
3512
|
+
function resolveCliEntrypoint() {
|
|
3513
|
+
return process.argv[1];
|
|
3514
|
+
}
|
|
3515
|
+
function resolveManifestPath(cwd) {
|
|
3516
|
+
return path$1.join(cwd, ".weapp-vite", "mcp-runtime.json");
|
|
3517
|
+
}
|
|
3518
|
+
async function isTcpPortOpen(host, port) {
|
|
3519
|
+
return await new Promise((resolve) => {
|
|
3520
|
+
const socket = net.createConnection({
|
|
3521
|
+
host,
|
|
3522
|
+
port
|
|
3523
|
+
});
|
|
3524
|
+
const cleanup = () => {
|
|
3525
|
+
socket.removeAllListeners();
|
|
3526
|
+
socket.destroy();
|
|
3527
|
+
};
|
|
3528
|
+
socket.once("connect", () => {
|
|
3529
|
+
cleanup();
|
|
3530
|
+
resolve(true);
|
|
3531
|
+
});
|
|
3532
|
+
socket.once("error", () => {
|
|
3533
|
+
cleanup();
|
|
3534
|
+
resolve(false);
|
|
3535
|
+
});
|
|
3536
|
+
socket.setTimeout(500, () => {
|
|
3537
|
+
cleanup();
|
|
3538
|
+
resolve(false);
|
|
3539
|
+
});
|
|
3540
|
+
});
|
|
3541
|
+
}
|
|
3542
|
+
async function writeRuntimeManifest(cwd, manifest) {
|
|
3543
|
+
const manifestPath = resolveManifestPath(cwd);
|
|
3544
|
+
await mkdir(path$1.dirname(manifestPath), { recursive: true });
|
|
3545
|
+
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
3546
|
+
}
|
|
3547
|
+
async function maybeStartDetachedMcpServer(options) {
|
|
3548
|
+
const resolvedMcp = resolveWeappMcpConfig(options.mcpConfig, {
|
|
3549
|
+
agentName: options.agentName,
|
|
3550
|
+
cwd: options.cwd,
|
|
3551
|
+
isAgent: options.isAgent
|
|
3552
|
+
});
|
|
3553
|
+
if (!resolvedMcp.enabled || !resolvedMcp.autoStart) return;
|
|
3554
|
+
const entrypoint = resolveCliEntrypoint();
|
|
3555
|
+
if (!entrypoint) {
|
|
3556
|
+
logger_default.warn("[mcp] 找不到当前 CLI 入口,跳过 MCP 后台自动启动。");
|
|
3557
|
+
return;
|
|
3558
|
+
}
|
|
3559
|
+
const url = `http://${resolvedMcp.host}:${resolvedMcp.port}${resolvedMcp.endpoint}`;
|
|
3560
|
+
const restUrl = resolvedMcp.restEndpoint === false ? void 0 : `http://${resolvedMcp.host}:${resolvedMcp.port}${resolvedMcp.restEndpoint}`;
|
|
3561
|
+
if (await isTcpPortOpen(resolvedMcp.host, resolvedMcp.port)) {
|
|
3562
|
+
logger_default.info(`[mcp] MCP 服务已存在,继续复用:${colors.cyan(url)}`);
|
|
3563
|
+
return;
|
|
3564
|
+
}
|
|
3565
|
+
const args = [
|
|
3566
|
+
entrypoint,
|
|
3567
|
+
"mcp",
|
|
3568
|
+
"--transport",
|
|
3569
|
+
"streamable-http",
|
|
3570
|
+
"--host",
|
|
3571
|
+
resolvedMcp.host,
|
|
3572
|
+
"--port",
|
|
3573
|
+
String(resolvedMcp.port),
|
|
3574
|
+
"--endpoint",
|
|
3575
|
+
resolvedMcp.endpoint,
|
|
3576
|
+
"--workspace-root",
|
|
3577
|
+
options.cwd
|
|
3578
|
+
];
|
|
3579
|
+
if (resolvedMcp.restEndpoint === false) args.push("--no-rest");
|
|
3580
|
+
else args.push("--rest-endpoint", resolvedMcp.restEndpoint);
|
|
3581
|
+
const child = spawn(process.execPath, args, {
|
|
3582
|
+
cwd: options.cwd,
|
|
3583
|
+
detached: true,
|
|
3584
|
+
stdio: "ignore"
|
|
3585
|
+
});
|
|
3586
|
+
child.unref();
|
|
3587
|
+
if (child.pid) await writeRuntimeManifest(options.cwd, {
|
|
3588
|
+
agentName: resolvedMcp.agentName,
|
|
3589
|
+
endpoint: resolvedMcp.endpoint,
|
|
3590
|
+
pid: child.pid,
|
|
3591
|
+
projectRoot: options.cwd,
|
|
3592
|
+
restUrl,
|
|
3593
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3594
|
+
startedBy: "weapp-vite open",
|
|
3595
|
+
transport: "streamable-http",
|
|
3596
|
+
url
|
|
3597
|
+
});
|
|
3598
|
+
const suffix = resolvedMcp.agentName ? `(AI 终端:${resolvedMcp.agentName})` : "";
|
|
3599
|
+
logger_default.success(`MCP 服务已在后台自动启动:${suffix}`);
|
|
3600
|
+
logger_default.info(` ➜ ${colors.cyan(url)}`);
|
|
3601
|
+
if (restUrl) logger_default.info(` REST ➜ ${colors.cyan(restUrl)}`);
|
|
3602
|
+
for (const line of formatMcpQuickStart({
|
|
3603
|
+
httpUrl: url,
|
|
3604
|
+
transport: "http"
|
|
3605
|
+
})) logger_default.info(line);
|
|
3606
|
+
}
|
|
3607
|
+
//#endregion
|
|
3608
|
+
//#region src/cli/mcpOptions.ts
|
|
3609
|
+
function applyMcpCliOptions(config, options) {
|
|
3610
|
+
if (options.mcp === false) return false;
|
|
3611
|
+
if (options.mcp === true) return {
|
|
3612
|
+
...typeof config === "object" && config ? config : {},
|
|
3613
|
+
enabled: true,
|
|
3614
|
+
autoStart: true
|
|
3615
|
+
};
|
|
3616
|
+
return config;
|
|
3617
|
+
}
|
|
3618
|
+
//#endregion
|
|
3509
3619
|
//#region src/cli/commands/open.ts
|
|
3510
3620
|
function registerOpenCommand(cli) {
|
|
3511
|
-
cli.command("open [root]").option("-p, --platform <platform>", `[string] target platform (weapp | web)`).option("--trust-project", "[boolean] auto trust Wechat DevTools project on open", { default: true }).option("--login-retry <mode>", "[string] login retry mode for Wechat DevTools (never | once | always)").option("--login-retry-timeout <ms>", "[number] login retry prompt timeout in milliseconds").option("--non-interactive", "[boolean] fail immediately when Wechat DevTools login has expired").action(async (root, options) => {
|
|
3621
|
+
cli.command("open [root]").option("-p, --platform <platform>", `[string] target platform (weapp | web)`).option("--trust-project", "[boolean] auto trust Wechat DevTools project on open", { default: true }).option("--login-retry <mode>", "[string] login retry mode for Wechat DevTools (never | once | always)").option("--login-retry-timeout <ms>", "[number] login retry prompt timeout in milliseconds").option("--non-interactive", "[boolean] fail immediately when Wechat DevTools login has expired").option("--mcp", "[boolean] auto start MCP service before opening IDE").option("--no-mcp", "[boolean] disable MCP service before opening IDE").action(async (root, options) => {
|
|
3512
3622
|
filterDuplicateOptions(options);
|
|
3513
3623
|
const configFile = resolveConfigFile(options);
|
|
3514
3624
|
const targets = resolveRuntimeTargets(options);
|
|
@@ -3525,6 +3635,14 @@ function registerOpenCommand(cli) {
|
|
|
3525
3635
|
weappViteConfig
|
|
3526
3636
|
});
|
|
3527
3637
|
if (latestHmrSummary) logger_default.info(latestHmrSummary.line);
|
|
3638
|
+
const cwdForMcp = cwd ?? process.cwd();
|
|
3639
|
+
const aiEnvironment = await detectAiDevelopmentEnvironment();
|
|
3640
|
+
await maybeStartDetachedMcpServer({
|
|
3641
|
+
agentName: aiEnvironment.agentName,
|
|
3642
|
+
cwd: cwdForMcp,
|
|
3643
|
+
isAgent: aiEnvironment.isAgent,
|
|
3644
|
+
mcpConfig: applyMcpCliOptions(weappViteConfig?.mcp, options)
|
|
3645
|
+
});
|
|
3528
3646
|
await openIde(platform, projectPath ?? resolveIdeProjectRoot(mpDistRoot, process.cwd()), {
|
|
3529
3647
|
loginRetry: options.loginRetry,
|
|
3530
3648
|
loginRetryTimeout: options.loginRetryTimeout,
|
|
@@ -3781,7 +3899,7 @@ function resolveRunnableHotkeyDefinition(input) {
|
|
|
3781
3899
|
}
|
|
3782
3900
|
//#endregion
|
|
3783
3901
|
//#region package.json
|
|
3784
|
-
var version = "6.16.
|
|
3902
|
+
var version = "6.16.45";
|
|
3785
3903
|
//#endregion
|
|
3786
3904
|
//#region src/cli/devHotkeys/format.ts
|
|
3787
3905
|
const FULLWIDTH_ASCII_START = 65281;
|
|
@@ -3795,6 +3913,19 @@ function formatMcpStatus(state) {
|
|
|
3795
3913
|
if (!state.mcpEnabled) return "已禁用";
|
|
3796
3914
|
return state.mcpRunning ? "运行中" : "未启动";
|
|
3797
3915
|
}
|
|
3916
|
+
function formatMcpHelpRows(state) {
|
|
3917
|
+
if (!state.mcpEnabled || !state.mcpHttpUrl) return [];
|
|
3918
|
+
return [
|
|
3919
|
+
"",
|
|
3920
|
+
"MCP 接入",
|
|
3921
|
+
`HTTP:${colors.cyan(state.mcpHttpUrl)}`,
|
|
3922
|
+
...state.mcpRestUrl ? [`REST:${colors.cyan(state.mcpRestUrl)}`] : [],
|
|
3923
|
+
...formatMcpQuickStart({
|
|
3924
|
+
httpUrl: state.mcpHttpUrl,
|
|
3925
|
+
transport: "http"
|
|
3926
|
+
})
|
|
3927
|
+
];
|
|
3928
|
+
}
|
|
3798
3929
|
function formatFooterLine(state) {
|
|
3799
3930
|
if (state.currentAction) return `执行中 ${state.currentAction}`;
|
|
3800
3931
|
return "就绪 等待操作...";
|
|
@@ -3837,7 +3968,8 @@ function formatDevHotkeyHelpWithState(state) {
|
|
|
3837
3968
|
...retrySections,
|
|
3838
3969
|
"",
|
|
3839
3970
|
`当前状态:${state.currentAction ?? "等待操作"} / MCP ${formatMcpStatus(state)}`,
|
|
3840
|
-
...state.lastAction ? [`最近操作:${state.lastAction}`] : []
|
|
3971
|
+
...state.lastAction ? [`最近操作:${state.lastAction}`] : [],
|
|
3972
|
+
...formatMcpHelpRows(state)
|
|
3841
3973
|
].join("\n");
|
|
3842
3974
|
}
|
|
3843
3975
|
/**
|
|
@@ -3861,41 +3993,52 @@ function resolveProjectLabel(cwd) {
|
|
|
3861
3993
|
}
|
|
3862
3994
|
//#endregion
|
|
3863
3995
|
//#region src/cli/devHotkeys/mcp.ts
|
|
3864
|
-
|
|
3996
|
+
const REG_EADDRINUSE$1 = /EADDRINUSE/;
|
|
3997
|
+
function formatMcpUrl$1(host, port, endpoint) {
|
|
3865
3998
|
return `http://${host}:${port}${endpoint}`;
|
|
3866
3999
|
}
|
|
3867
4000
|
function createToggleMcpAction(options) {
|
|
3868
4001
|
const { cwd, getHandle, resolvedMcp, setHandle } = options;
|
|
3869
|
-
return async function toggleMcp() {
|
|
4002
|
+
return async function toggleMcp(actionOptions = {}) {
|
|
4003
|
+
const silent = actionOptions.silent === true;
|
|
3870
4004
|
if (!resolvedMcp.enabled) {
|
|
3871
4005
|
logger_default.warn("[dev action] MCP 已在配置中禁用,跳过切换。");
|
|
3872
4006
|
return "MCP 已禁用";
|
|
3873
4007
|
}
|
|
3874
4008
|
const existingHandle = getHandle();
|
|
3875
4009
|
if (existingHandle?.close) {
|
|
3876
|
-
const url = formatMcpUrl(resolvedMcp.host, resolvedMcp.port, resolvedMcp.endpoint);
|
|
4010
|
+
const url = formatMcpUrl$1(resolvedMcp.host, resolvedMcp.port, resolvedMcp.endpoint);
|
|
3877
4011
|
logger_default.info(`[dev action] 正在关闭 MCP 服务:${colors.cyan(url)}`);
|
|
3878
4012
|
await existingHandle.close();
|
|
3879
4013
|
setHandle(void 0);
|
|
3880
4014
|
logger_default.success(`[dev action] MCP 服务已关闭:${colors.cyan(url)}`);
|
|
3881
4015
|
return `MCP 已关闭 (${url})`;
|
|
3882
4016
|
}
|
|
3883
|
-
const url = formatMcpUrl(resolvedMcp.host, resolvedMcp.port, resolvedMcp.endpoint);
|
|
3884
|
-
logger_default.info(`[dev action] 正在启动 MCP 服务:${colors.cyan(url)}`);
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
4017
|
+
const url = formatMcpUrl$1(resolvedMcp.host, resolvedMcp.port, resolvedMcp.endpoint);
|
|
4018
|
+
if (!silent) logger_default.info(`[dev action] 正在启动 MCP 服务:${colors.cyan(url)}`);
|
|
4019
|
+
let handle;
|
|
4020
|
+
try {
|
|
4021
|
+
handle = await startWeappViteMcpServer({
|
|
4022
|
+
endpoint: resolvedMcp.endpoint,
|
|
4023
|
+
host: resolvedMcp.host,
|
|
4024
|
+
port: resolvedMcp.port,
|
|
4025
|
+
restEndpoint: resolvedMcp.restEndpoint,
|
|
4026
|
+
transport: "streamable-http",
|
|
4027
|
+
unref: false,
|
|
4028
|
+
onReady: () => {},
|
|
4029
|
+
workspaceRoot: cwd
|
|
4030
|
+
});
|
|
4031
|
+
} catch (error) {
|
|
4032
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4033
|
+
if (REG_EADDRINUSE$1.test(message)) {
|
|
4034
|
+
if (!silent) logger_default.info(`[dev action] MCP 服务已存在,继续复用:${colors.cyan(url)}`);
|
|
4035
|
+
return `MCP 已复用 (${url})`;
|
|
4036
|
+
}
|
|
4037
|
+
throw error;
|
|
4038
|
+
}
|
|
4039
|
+
setHandle(handle);
|
|
4040
|
+
const suffix = resolvedMcp.agentName ? `(AI 终端:${resolvedMcp.agentName})` : "";
|
|
4041
|
+
if (!silent) logger_default.success(`[dev action] MCP 服务已启动:${colors.cyan(url)}${suffix}`);
|
|
3899
4042
|
return `MCP 已启动 (${url})`;
|
|
3900
4043
|
};
|
|
3901
4044
|
}
|
|
@@ -3907,6 +4050,9 @@ function forwardSigint() {
|
|
|
3907
4050
|
function forwardSigtstp() {
|
|
3908
4051
|
process.kill(process.pid, "SIGTSTP");
|
|
3909
4052
|
}
|
|
4053
|
+
function formatMcpUrl(host, port, endpoint) {
|
|
4054
|
+
return `http://${host}:${port}${endpoint}`;
|
|
4055
|
+
}
|
|
3910
4056
|
/**
|
|
3911
4057
|
* @description 在开发态启动终端快捷键,并将动作输出到本地日志。
|
|
3912
4058
|
*/
|
|
@@ -3922,12 +4068,20 @@ function startDevHotkeys(options) {
|
|
|
3922
4068
|
let lastAction;
|
|
3923
4069
|
let lastRenderedPanel = "";
|
|
3924
4070
|
const recentInputs = /* @__PURE__ */ new Map();
|
|
3925
|
-
const resolvedMcp = resolveWeappMcpConfig(options.mcpConfig
|
|
4071
|
+
const resolvedMcp = resolveWeappMcpConfig(options.mcpConfig, {
|
|
4072
|
+
agentName: options.agentName,
|
|
4073
|
+
cwd: options.cwd,
|
|
4074
|
+
isAgent: options.isAgent
|
|
4075
|
+
});
|
|
4076
|
+
const mcpHttpUrl = formatMcpUrl(resolvedMcp.host, resolvedMcp.port, resolvedMcp.endpoint);
|
|
4077
|
+
const mcpRestUrl = resolvedMcp.restEndpoint === false ? void 0 : formatMcpUrl(resolvedMcp.host, resolvedMcp.port, resolvedMcp.restEndpoint);
|
|
3926
4078
|
const getState = () => ({
|
|
3927
4079
|
currentAction,
|
|
3928
4080
|
lastAction,
|
|
3929
4081
|
mcpEnabled: resolvedMcp.enabled,
|
|
4082
|
+
mcpHttpUrl,
|
|
3930
4083
|
mcpRunning: Boolean(mcpHandle?.close),
|
|
4084
|
+
mcpRestUrl,
|
|
3931
4085
|
projectLabel: resolveProjectLabel(options.cwd)
|
|
3932
4086
|
});
|
|
3933
4087
|
let inputSession = createSharedInputSession({
|
|
@@ -4006,6 +4160,19 @@ function startDevHotkeys(options) {
|
|
|
4006
4160
|
if (!closed) printHint();
|
|
4007
4161
|
});
|
|
4008
4162
|
};
|
|
4163
|
+
const runBackgroundAction = (label, pendingLabel, action) => {
|
|
4164
|
+
if (running) return;
|
|
4165
|
+
running = true;
|
|
4166
|
+
currentAction = pendingLabel;
|
|
4167
|
+
action().then((summary) => {
|
|
4168
|
+
if (summary) lastAction = summary;
|
|
4169
|
+
}).catch((error) => {
|
|
4170
|
+
logger_default.error(`[dev action] ${label}失败:${error instanceof Error ? error.message : String(error)}`);
|
|
4171
|
+
}).finally(() => {
|
|
4172
|
+
running = false;
|
|
4173
|
+
currentAction = void 0;
|
|
4174
|
+
});
|
|
4175
|
+
};
|
|
4009
4176
|
const handleInput = (input) => {
|
|
4010
4177
|
if (closed) return;
|
|
4011
4178
|
const normalizedInput = normalizeInputChar(input);
|
|
@@ -4070,8 +4237,8 @@ function startDevHotkeys(options) {
|
|
|
4070
4237
|
};
|
|
4071
4238
|
process.on("SIGCONT", onSigcont);
|
|
4072
4239
|
if (!options.silentStartupHint) printHint();
|
|
4073
|
-
if (resolvedMcp.enabled && resolvedMcp.autoStart)
|
|
4074
|
-
await toggleMcp();
|
|
4240
|
+
if (resolvedMcp.enabled && resolvedMcp.autoStart) runBackgroundAction("MCP 自动启动", "正在启动 MCP 服务", async () => {
|
|
4241
|
+
await toggleMcp({ silent: true });
|
|
4075
4242
|
});
|
|
4076
4243
|
return {
|
|
4077
4244
|
close,
|
|
@@ -4080,72 +4247,6 @@ function startDevHotkeys(options) {
|
|
|
4080
4247
|
};
|
|
4081
4248
|
}
|
|
4082
4249
|
//#endregion
|
|
4083
|
-
//#region src/cli/commands/serve/activeIdeProjects.ts
|
|
4084
|
-
const ACTIVE_IDE_PROJECTS_DIR = path$1.join(os.tmpdir(), "weapp-vite-active-dev-open-projects");
|
|
4085
|
-
function normalizeProjectPath(projectPath) {
|
|
4086
|
-
return path$1.resolve(projectPath);
|
|
4087
|
-
}
|
|
4088
|
-
function resolveRecordPath(projectPath) {
|
|
4089
|
-
return path$1.join(ACTIVE_IDE_PROJECTS_DIR, `${Buffer.from(normalizeProjectPath(projectPath)).toString("base64url")}.json`);
|
|
4090
|
-
}
|
|
4091
|
-
function isProcessAlive(pid) {
|
|
4092
|
-
try {
|
|
4093
|
-
process.kill(pid, 0);
|
|
4094
|
-
return true;
|
|
4095
|
-
} catch (error) {
|
|
4096
|
-
if (error && typeof error === "object" && "code" in error && error.code === "ESRCH") return false;
|
|
4097
|
-
return true;
|
|
4098
|
-
}
|
|
4099
|
-
}
|
|
4100
|
-
async function readRecord(filePath) {
|
|
4101
|
-
try {
|
|
4102
|
-
const raw = await fs$2.readFile(filePath, "utf8");
|
|
4103
|
-
const record = JSON.parse(raw);
|
|
4104
|
-
if (typeof record.pid !== "number" || typeof record.projectPath !== "string") return null;
|
|
4105
|
-
return record;
|
|
4106
|
-
} catch {
|
|
4107
|
-
return null;
|
|
4108
|
-
}
|
|
4109
|
-
}
|
|
4110
|
-
/**
|
|
4111
|
-
* @description 登记当前 dev:open 项目,供后续启动判断是否需要保留其它正在运行的 IDE 窗口。
|
|
4112
|
-
*/
|
|
4113
|
-
async function registerActiveServeIdeProject(projectPath) {
|
|
4114
|
-
const filePath = resolveRecordPath(projectPath);
|
|
4115
|
-
await fs$2.mkdir(path$1.dirname(filePath), { recursive: true });
|
|
4116
|
-
await fs$2.writeFile(filePath, `${JSON.stringify({
|
|
4117
|
-
pid: process.pid,
|
|
4118
|
-
projectPath: normalizeProjectPath(projectPath),
|
|
4119
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4120
|
-
}, null, 2)}\n`, "utf8");
|
|
4121
|
-
return async () => {
|
|
4122
|
-
await fs$2.rm(filePath, { force: true }).catch(() => {});
|
|
4123
|
-
};
|
|
4124
|
-
}
|
|
4125
|
-
/**
|
|
4126
|
-
* @description 检查是否存在其它仍在运行的 dev:open 项目。
|
|
4127
|
-
*/
|
|
4128
|
-
async function hasOtherActiveServeIdeProject(projectPath) {
|
|
4129
|
-
const currentProjectPath = normalizeProjectPath(projectPath);
|
|
4130
|
-
let entries;
|
|
4131
|
-
try {
|
|
4132
|
-
entries = await fs$2.readdir(ACTIVE_IDE_PROJECTS_DIR);
|
|
4133
|
-
} catch {
|
|
4134
|
-
return false;
|
|
4135
|
-
}
|
|
4136
|
-
for (const entry of entries) {
|
|
4137
|
-
if (!entry.endsWith(".json")) continue;
|
|
4138
|
-
const filePath = path$1.join(ACTIVE_IDE_PROJECTS_DIR, entry);
|
|
4139
|
-
const record = await readRecord(filePath);
|
|
4140
|
-
if (!record || !isProcessAlive(record.pid)) {
|
|
4141
|
-
await fs$2.rm(filePath, { force: true }).catch(() => {});
|
|
4142
|
-
continue;
|
|
4143
|
-
}
|
|
4144
|
-
if (normalizeProjectPath(record.projectPath) !== currentProjectPath) return true;
|
|
4145
|
-
}
|
|
4146
|
-
return false;
|
|
4147
|
-
}
|
|
4148
|
-
//#endregion
|
|
4149
4250
|
//#region src/cli/commands/serve/analyze.ts
|
|
4150
4251
|
const REG_DIST_PAGE_ENTRY = /pages\/.+\/index\.js$/;
|
|
4151
4252
|
const REG_DIST_POSIX_SEP = /\\/g;
|
|
@@ -4452,7 +4553,7 @@ function waitForServeShutdownSignal() {
|
|
|
4452
4553
|
//#endregion
|
|
4453
4554
|
//#region src/cli/commands/serve/index.ts
|
|
4454
4555
|
function registerServeCommand(cli) {
|
|
4455
|
-
cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | web | all)`).option("--project-config <path>", `[string] project config path (miniprogram only)`).option("--trust-project", "[boolean] auto trust Wechat DevTools project on open", { default: true }).option("--login-retry <mode>", "[string] login retry mode for Wechat DevTools (never | once | always)").option("--login-retry-timeout <ms>", "[number] login retry prompt timeout in milliseconds").option("--non-interactive", "[boolean] fail immediately when Wechat DevTools login has expired").option("--host [host]", `[string] web dev server host`).option("--ui", `[boolean] 启动调试 UI(当前提供分析视图)`, { default: false }).option("--analyze", `[boolean] 启动分包分析仪表盘 (实验特性)`, { default: false }).option("--scope <scope>", `[string] 局部构建范围,例如 main,packages/order`).action(async (root, options) => {
|
|
4556
|
+
cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | web | all)`).option("--project-config <path>", `[string] project config path (miniprogram only)`).option("--trust-project", "[boolean] auto trust Wechat DevTools project on open", { default: true }).option("--login-retry <mode>", "[string] login retry mode for Wechat DevTools (never | once | always)").option("--login-retry-timeout <ms>", "[number] login retry prompt timeout in milliseconds").option("--non-interactive", "[boolean] fail immediately when Wechat DevTools login has expired").option("--mcp", "[boolean] auto start MCP service during dev").option("--no-mcp", "[boolean] disable MCP service during dev").option("--host [host]", `[string] web dev server host`).option("--ui", `[boolean] 启动调试 UI(当前提供分析视图)`, { default: false }).option("--analyze", `[boolean] 启动分包分析仪表盘 (实验特性)`, { default: false }).option("--scope <scope>", `[string] 局部构建范围,例如 main,packages/order`).action(async (root, options) => {
|
|
4456
4557
|
filterDuplicateOptions(options);
|
|
4457
4558
|
const cwd = root ?? process.cwd();
|
|
4458
4559
|
const configFile = resolveConfigFile(options);
|
|
@@ -4497,6 +4598,8 @@ function registerServeCommand(cli) {
|
|
|
4497
4598
|
projectConfigPath: options.projectConfig
|
|
4498
4599
|
});
|
|
4499
4600
|
const { buildService, configService, webService } = ctx;
|
|
4601
|
+
const aiEnvironment = await detectAiDevelopmentEnvironment();
|
|
4602
|
+
const mcpConfig = applyMcpCliOptions(configService.weappViteConfig?.mcp, options);
|
|
4500
4603
|
logRuntimeTarget(targets, { resolvedConfigPlatform: configService.platform });
|
|
4501
4604
|
const enableAnalyze = Boolean(isUiEnabled(options) && targets.runMini);
|
|
4502
4605
|
let analyzeHandle;
|
|
@@ -4527,7 +4630,9 @@ function registerServeCommand(cli) {
|
|
|
4527
4630
|
});
|
|
4528
4631
|
const devHotkeysSession = targets.runMini ? startDevHotkeys({
|
|
4529
4632
|
cwd: configService.cwd,
|
|
4530
|
-
|
|
4633
|
+
agentName: aiEnvironment.agentName,
|
|
4634
|
+
isAgent: aiEnvironment.isAgent,
|
|
4635
|
+
mcpConfig,
|
|
4531
4636
|
openIde: async () => await miniProgramDevActions.openIde({
|
|
4532
4637
|
forceOpen: true,
|
|
4533
4638
|
forceReopen: true
|
|
@@ -4538,7 +4643,6 @@ function registerServeCommand(cli) {
|
|
|
4538
4643
|
silentStartupHint: true,
|
|
4539
4644
|
weappViteConfig: configService.weappViteConfig
|
|
4540
4645
|
}) : void 0;
|
|
4541
|
-
let unregisterActiveIdeProject;
|
|
4542
4646
|
try {
|
|
4543
4647
|
const analyzeController = createAnalyzeController({
|
|
4544
4648
|
configFile,
|
|
@@ -4613,11 +4717,9 @@ function registerServeCommand(cli) {
|
|
|
4613
4717
|
}]);
|
|
4614
4718
|
devHotkeysSession?.suspend();
|
|
4615
4719
|
try {
|
|
4616
|
-
unregisterActiveIdeProject = miniProgramDevActions.projectPath ? await registerActiveServeIdeProject(miniProgramDevActions.projectPath) : void 0;
|
|
4617
|
-
const shouldForceReopen = miniProgramDevActions.projectPath ? !await hasOtherActiveServeIdeProject(miniProgramDevActions.projectPath) : true;
|
|
4618
4720
|
await miniProgramDevActions.openIde({
|
|
4619
4721
|
forceOpen: true,
|
|
4620
|
-
forceReopen:
|
|
4722
|
+
forceReopen: false
|
|
4621
4723
|
});
|
|
4622
4724
|
} finally {
|
|
4623
4725
|
devHotkeysSession?.restore();
|
|
@@ -4626,7 +4728,6 @@ function registerServeCommand(cli) {
|
|
|
4626
4728
|
if (analyzeHandle) await analyzeController.waitForExit();
|
|
4627
4729
|
else if (targets.runMini || targets.runWeb) await waitForServeShutdownSignal();
|
|
4628
4730
|
} finally {
|
|
4629
|
-
await unregisterActiveIdeProject?.();
|
|
4630
4731
|
devHotkeysSession?.close();
|
|
4631
4732
|
ctx.watcherService?.closeAll();
|
|
4632
4733
|
}
|
|
@@ -4736,7 +4837,13 @@ async function maybeAutoStartMcpServer(argv, cliOptions) {
|
|
|
4736
4837
|
} catch (error) {
|
|
4737
4838
|
logger_default.warn(`[mcp] 读取配置失败,使用默认 MCP 配置自动启动:${error instanceof Error ? error.message : String(error)}`);
|
|
4738
4839
|
}
|
|
4739
|
-
const
|
|
4840
|
+
const maybeMcpConfig = rawMcpConfig;
|
|
4841
|
+
const aiEnvironment = await detectAiDevelopmentEnvironment();
|
|
4842
|
+
const resolvedMcp = resolveWeappMcpConfig(maybeMcpConfig, {
|
|
4843
|
+
agentName: aiEnvironment.agentName,
|
|
4844
|
+
cwd: process.cwd(),
|
|
4845
|
+
isAgent: aiEnvironment.isAgent
|
|
4846
|
+
});
|
|
4740
4847
|
if (!resolvedMcp.enabled || !resolvedMcp.autoStart) return;
|
|
4741
4848
|
try {
|
|
4742
4849
|
await startWeappViteMcpServer({
|
|
@@ -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 };
|