weapp-vite 7.5.0 → 7.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -6
- package/THIRD_PARTY_NOTICES.md +60 -0
- package/bin/bootstrap.js +9 -4
- package/bin/bootstrap.test.ts +82 -1
- package/bin/nodeVersionWarning.js +17 -0
- package/bin/nodeVersionWarning.test.ts +30 -0
- package/dist/action-BD56SQh4.mjs +254 -0
- package/dist/action-CPtgEl6p.mjs +94 -0
- package/dist/action-le0bNff_.mjs +1102 -0
- package/dist/action-ytG5oFAw.mjs +138 -0
- package/dist/action-zmJrU8PC.mjs +245 -0
- package/dist/{analyze-ZJUvEdaY.mjs → analyze-DCZo-sJd.mjs} +4 -71
- package/dist/artifacts-TrTX9_jj.mjs +104 -0
- package/dist/assets-XyhpYtGl.mjs +630 -0
- package/dist/auto-import-components/resolvers.d.mts +1 -1
- package/dist/auto-import-components/resolvers.mjs +1 -1
- package/dist/auto-import-presets/wevu-router.d.mts +1 -1
- package/dist/auto-import-presets/wevu-router.mjs +1 -1
- package/dist/auto-import-presets/wevu.d.mts +1 -1
- package/dist/auto-import-presets/wevu.mjs +1 -1
- package/dist/auto-import-presets.d.mts +2 -2
- package/dist/auto-import-presets.mjs +2 -2
- package/dist/auto-routes.d.mts +1 -3
- package/dist/auto-routes.mjs +3 -4
- package/dist/{budget-BD7VqLCl.d.mts → budget-DTPngJU0.d.mts} +1 -10
- package/dist/budget-_Mu-4GKn.mjs +63 -0
- package/dist/builtProject-B145uOt5.mjs +534 -0
- package/dist/{package-7swhyLmf.mjs → classifier-CNTJOYQL.mjs} +5 -9
- package/dist/cli-acceptance.mjs +3 -4
- package/dist/cli.mjs +142 -4569
- package/dist/{config-DRGcCi3h.mjs → config-59ZWhCIf.mjs} +1 -2
- package/dist/{config-V0L-IAJf.d.mts → config-BNx2BODw.d.mts} +145 -150
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +3 -3
- package/dist/{constants-DEZdcsMn.mjs → constants-BOe8mgqL.mjs} +2 -4
- package/dist/{createCompilerContextInstance-DJH_P_nZ.mjs → createCompilerContextInstance-BXSdH2E8.mjs} +19930 -14019
- package/dist/{createContext-BqYzHhY9.mjs → createContext-W0TeXxbo.mjs} +7 -5
- package/dist/dashboard/analyze.d.mts +1 -7
- package/dist/dashboard/analyze.mjs +3 -1
- package/dist/dashboard/vite.d.mts +2 -4
- package/dist/dashboard/vite.mjs +1 -2
- package/dist/dashboard.d.mts +2 -2
- package/dist/dashboard.mjs +1733 -1
- package/dist/dashboardTransport-C9290QgS.mjs +15 -0
- package/dist/{dashboardViteBridge-Dy3nAD4m.mjs → dashboardViteBridge-B7QgQo94.mjs} +11 -11
- package/dist/{dev-fR5GiJRO.mjs → dev-D1QSExwk.mjs} +6 -3
- package/dist/devProvider-Bcvz5nu4.mjs +4966 -0
- package/dist/docs/README.md +14 -6
- package/dist/docs/ai-workflows.md +2 -0
- package/dist/docs/mcp.md +11 -1
- package/dist/docs/troubleshooting.md +16 -0
- package/dist/docs/vue-sfc.md +25 -2
- package/dist/docs/weapp-config.md +29 -0
- package/dist/docs/wevu-authoring.md +2 -0
- package/dist/doctor-worker.mjs +5 -5
- package/dist/doctor.d.mts +2 -8
- package/dist/doctor.mjs +24 -31
- package/dist/engine-Mnnm_ALP.mjs +53 -0
- package/dist/file-5eEfbK60.mjs +1 -0
- package/dist/{file-sC3jD7Fh.mjs → file-D8mp5GmB.mjs} +50 -26
- package/dist/{files-BqxFIPRp.mjs → files-Cy9jURJu.mjs} +1 -2
- package/dist/forwardConsole-D2Q0RIqc.mjs +509 -0
- package/dist/getInstance-BXNVH7sU.mjs +1 -0
- package/dist/{getInstance-DiGSzBNI.mjs → getInstance-DfNlbr-X.mjs} +2 -3
- package/dist/history-dKxzoHmN.mjs +774 -0
- package/dist/i18n.d.mts +1 -3
- package/dist/i18n.mjs +1 -2
- package/dist/{index-C9HjUX5c.d.mts → index-DIZJRrvK.d.mts} +1 -24
- package/dist/{index-CaXAtb9e.d.mts → index-SnaW3cvA.d.mts} +0 -12
- package/dist/index.d.mts +3 -7
- package/dist/index.mjs +6 -6
- package/dist/{json-BL8Dhhk6.mjs → json-Cvon2mw5.mjs} +1 -2
- package/dist/json.d.mts +1 -1
- package/dist/json.mjs +1 -1
- package/dist/lib-CJyMBzoe.mjs +140 -0
- package/dist/{lifecycle-BROTlwSL.mjs → lifecycle-CUo8PMQc.mjs} +123 -33
- package/dist/{loadConfig-C3BQhz7F.mjs → loadConfig-CKIdfW4o.mjs} +2 -3
- package/dist/loadConfig-D4WGJcYp.mjs +1 -0
- package/dist/logBuildAppFinish-DOBoof6S.mjs +54 -0
- package/dist/mcp-D88QvQgG.mjs +84 -0
- package/dist/{mcp-Cj8Maqo6.mjs → mcp-ovJgl1N9.mjs} +2 -4
- package/dist/mcp.d.mts +1 -3
- package/dist/mcp.mjs +1 -1
- package/dist/mcpClient-C8JzVZ46.mjs +283 -0
- package/dist/{processCleanup-B6KA30Zc.mjs → metadata-HlDKtlsu.mjs} +2 -21
- package/dist/nodeEnv-zq1EymWj.mjs +6 -0
- package/dist/openIde-QoYKhuuM.mjs +643 -0
- package/dist/options-Cz8vZ-0w.mjs +33 -0
- package/dist/{chunkStrategy-DRA5WpB-.mjs → package-DR62fAzP.mjs} +32 -31
- package/dist/path-E1OjBJAl.mjs +43 -0
- package/dist/{platform-CnkySBKz.mjs → platform-BiMpsZIb.mjs} +1 -2
- package/dist/{pluginHost--CaeyWpA.mjs → pluginHost-vn8Vty1J.mjs} +1 -2
- package/dist/processCleanup-DzB64WI8.mjs +18 -0
- package/dist/{protocol-vg8HGJ4n.mjs → protocol-HiSJRrSO.mjs} +43 -41
- package/dist/reader-wzPH_W8A.mjs +92 -0
- package/dist/realpathScope-DwlLaCk3.mjs +22 -0
- package/dist/report-PJVyo-UZ.mjs +105 -0
- package/dist/{path-doV773b7.mjs → resolvedId-DaxPh_yV.mjs} +5 -50
- package/dist/{resolvers-Dod-euqX.mjs → resolvers-CKYqmRD_.mjs} +10 -20
- package/dist/resolvers.d.mts +1 -1
- package/dist/resolvers.mjs +1 -1
- package/dist/{routes-C7fCmf92.d.mts → routes-DvAFX29h.d.mts} +0 -2
- package/dist/{runtime-Ee2HY6gR.d.mts → runtime-BL4RjBRa.d.mts} +1 -9
- package/dist/runtime-CKtMVERT.mjs +42 -0
- package/dist/{runtime-D6VCNhNY.mjs → runtime-DDUCb7pP.mjs} +4 -8
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/schematics-DikfOjMD.mjs +90 -0
- package/dist/{session-PskhD-nZ.mjs → session-COrQJYif.mjs} +81 -21
- package/dist/test.d.mts +1 -3
- package/dist/test.mjs +54 -30
- package/dist/types-BK2EQ3Jm.d.mts +37 -0
- package/dist/{types-CgZn5X6j.d.mts → types-e2BMP9NU.d.mts} +1 -4
- package/dist/types.d.mts +4 -4
- package/dist/{upload-D4msblBf.mjs → upload-Chal5b3w.mjs} +118 -24
- package/dist/upload-worker.mjs +3 -5
- package/dist/{utils-CJSCgEj6.mjs → utils-CTGSZp4j.mjs} +72 -146
- package/dist/vite.d.mts +2 -4
- package/dist/vite.mjs +55 -21
- package/dist/volar.mjs +1 -2
- package/dist/{wevu-BQWUU7br.mjs → wevu-BaihCXO9.mjs} +1 -2
- package/dist/wevu-DTtSOyxB.d.mts +3 -0
- package/dist/{wevu-router-Dg1LnBlg.mjs → wevu-router-BIoxDbnu.mjs} +1 -2
- package/dist/wevu-router-CdWurGQ4.d.mts +3 -0
- package/dist/wxs-7V7MPzeW.mjs +1 -0
- package/dist/wxs-BdHHXltv.mjs +110 -0
- package/package.json +62 -53
- package/dist/dashboard-DvqF3Key.mjs +0 -1842
- package/dist/devProvider-BGBkw28J.mjs +0 -1050
- package/dist/file-DRb4eWqw.mjs +0 -1
- package/dist/getInstance-SiE6WZRh.mjs +0 -1
- package/dist/loadConfig-VGtBF4qm.mjs +0 -1
- package/dist/mcp-D3Yh24Cj.mjs +0 -529
- package/dist/wevu-C4KEC5kO.d.mts +0 -5
- package/dist/wevu-router-Cg2sIkIE.d.mts +0 -5
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { s as getProjectConfigFileName } from "./utils-CTGSZp4j.mjs";
|
|
2
|
+
import { r as logger_default, t as colors } from "./logger-DGn5iEVN.mjs";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { resolveCommand } from "package-manager-detector/commands";
|
|
5
|
+
// src/cli/commands/build/completion.ts
|
|
6
|
+
function shouldScheduleCompletedProductionBuildExit(options, analyzeHandle) {
|
|
7
|
+
return process.env.VITEST !== "true" && process.env.NODE_ENV !== "test" && process.env.WEAPP_VITE_DISABLE_COMPLETED_BUILD_EXIT !== "1" && options.watch !== true && options.open !== true && analyzeHandle === void 0;
|
|
8
|
+
}
|
|
9
|
+
function scheduleCompletedProductionBuildExit(options, analyzeHandle) {
|
|
10
|
+
if (!shouldScheduleCompletedProductionBuildExit(options, analyzeHandle)) return;
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
if (process.exitCode === void 0 || process.exitCode === 0) process.exit(0);
|
|
13
|
+
}, 0).unref?.();
|
|
14
|
+
}
|
|
15
|
+
// src/cli/formatDuration.ts
|
|
16
|
+
/**
|
|
17
|
+
* 将毫秒耗时格式化为适合 CLI 展示的文本。
|
|
18
|
+
*/
|
|
19
|
+
function formatDuration(durationMs) {
|
|
20
|
+
return `${durationMs}ms`;
|
|
21
|
+
}
|
|
22
|
+
// src/cli/logBuildAppFinish.ts
|
|
23
|
+
let logBuildAppFinishOnlyShowOnce = false;
|
|
24
|
+
function collectServerUrls(webServer) {
|
|
25
|
+
const urls = webServer?.resolvedUrls;
|
|
26
|
+
if (!urls) return [];
|
|
27
|
+
return [...urls.local ?? [], ...urls.network ?? []];
|
|
28
|
+
}
|
|
29
|
+
function logBuildAppFinish(configService, webServer, options = {}) {
|
|
30
|
+
if (logBuildAppFinishOnlyShowOnce) return;
|
|
31
|
+
const { skipMini = false, skipWeb = false, uiUrls = [] } = options;
|
|
32
|
+
const webUrls = skipWeb ? [] : collectServerUrls(webServer);
|
|
33
|
+
if (skipMini) {
|
|
34
|
+
logger_default.success("开发服务已就绪:");
|
|
35
|
+
if (webUrls.length > 0) logger_default.info(`Web:${colors.cyan(webUrls[0])}`);
|
|
36
|
+
else logger_default.info("Web:已启动");
|
|
37
|
+
logBuildAppFinishOnlyShowOnce = true;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const { command, args } = resolveCommand(configService.packageManager.agent, "run", ["open"]) ?? {
|
|
41
|
+
command: "npm",
|
|
42
|
+
args: ["run", "open"]
|
|
43
|
+
};
|
|
44
|
+
const devCommand = `${command} ${args.join(" ")}`;
|
|
45
|
+
logger_default.success("开发服务已就绪:");
|
|
46
|
+
logger_default.info(`小程序:执行 ${colors.bold(colors.green(devCommand))},或手动导入 ${colors.green(getProjectConfigFileName(configService.platform))}`);
|
|
47
|
+
if (uiUrls.length > 0) logger_default.info(`UI:${colors.cyan(uiUrls[0])}`);
|
|
48
|
+
else if (!skipMini) logger_default.info("UI:未启用");
|
|
49
|
+
if (webUrls.length > 0) logger_default.info(`Web:${colors.cyan(webUrls[0])}`);
|
|
50
|
+
const projectConfigFileName = getProjectConfigFileName(configService.platform);
|
|
51
|
+
if (!uiUrls.length && !webUrls.length) logger_default.info(`提示:手动打开对应平台开发者工具,导入根目录(${colors.green(projectConfigFileName)} 文件所在目录)`);
|
|
52
|
+
logBuildAppFinishOnlyShowOnce = true;
|
|
53
|
+
}
|
|
54
|
+
export { formatDuration as n, scheduleCompletedProductionBuildExit as r, logBuildAppFinish as t };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { writeFile } from "node:fs/promises";
|
|
4
|
+
// src/cli/commands/accept.ts
|
|
5
|
+
function registerAcceptCommand(cli) {
|
|
6
|
+
cli.command("accept [root]", "run deterministic mini-program acceptance without a model").option("--init", "create acceptance configuration without overwriting").option("--inspect", "inspect acceptance prerequisites without executing project code").option("--report <jobId>", "read a saved report and check source freshness").option("--acceptance-config <file>", "select an acceptance JSON configuration").option("--trust", "authorize the reviewed configuration for this invocation").option("--json", "write protocol data only to stdout").action(async (root = ".", options) => {
|
|
7
|
+
try {
|
|
8
|
+
const directory = path.resolve(root);
|
|
9
|
+
const { defaultVerification, detectProject, safePath } = await import("@weapp-vite/acceptance");
|
|
10
|
+
if (options.init) {
|
|
11
|
+
const target = await safePath(directory, options.acceptanceConfig ?? "weapp-acceptance.config.json");
|
|
12
|
+
const config = {
|
|
13
|
+
version: 1,
|
|
14
|
+
verification: defaultVerification(await detectProject(directory)),
|
|
15
|
+
acceptance: {
|
|
16
|
+
requiredChecks: ["build", "devtools"],
|
|
17
|
+
scenarios: [],
|
|
18
|
+
timeoutMs: 6e5
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
await writeFile(target, `${JSON.stringify(config, null, 2)}\n`, { flag: "wx" });
|
|
22
|
+
process.stdout.write(`${JSON.stringify({
|
|
23
|
+
created: target,
|
|
24
|
+
modelRequired: false
|
|
25
|
+
})}\n`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const { createRuntimeAcceptanceService } = await import("@weapp-vite/mcp");
|
|
29
|
+
const { connectMiniProgram, prepareAcceptanceProject, resolveAutomatorSessionOptions } = await import("weapp-ide-cli");
|
|
30
|
+
const service = await createRuntimeAcceptanceService(directory, {
|
|
31
|
+
trust: Boolean(options.trust && !options.inspect && !options.report),
|
|
32
|
+
configFile: options.acceptanceConfig
|
|
33
|
+
}, {
|
|
34
|
+
connectMiniProgram,
|
|
35
|
+
resolveSessionOptions: resolveAutomatorSessionOptions,
|
|
36
|
+
prepareProject: prepareAcceptanceProject
|
|
37
|
+
});
|
|
38
|
+
let jobId;
|
|
39
|
+
let cancelRequested = false;
|
|
40
|
+
const cancel = () => {
|
|
41
|
+
cancelRequested = true;
|
|
42
|
+
if (jobId) service.cancel(jobId);
|
|
43
|
+
};
|
|
44
|
+
process.once("SIGINT", cancel);
|
|
45
|
+
try {
|
|
46
|
+
let result;
|
|
47
|
+
if (options.inspect) result = await service.inspect();
|
|
48
|
+
else if (options.report) result = await service.report(options.report);
|
|
49
|
+
else {
|
|
50
|
+
let report = await service.start();
|
|
51
|
+
jobId = report.jobId;
|
|
52
|
+
if (cancelRequested) await service.cancel(jobId);
|
|
53
|
+
while (report.status === "running") {
|
|
54
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
55
|
+
report = await service.report(jobId);
|
|
56
|
+
}
|
|
57
|
+
result = report;
|
|
58
|
+
}
|
|
59
|
+
process.stdout.write(`${JSON.stringify(result, null, options.json ? void 0 : 2)}\n`);
|
|
60
|
+
if ("passed" in result && (!result.passed || result.snapshot.stale)) process.exitCode = 1;
|
|
61
|
+
} finally {
|
|
62
|
+
process.off("SIGINT", cancel);
|
|
63
|
+
await service.close();
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
if (options.json) process.stdout.write(`${JSON.stringify({
|
|
68
|
+
status: "failed",
|
|
69
|
+
passed: false,
|
|
70
|
+
reason: message
|
|
71
|
+
})}\n`);
|
|
72
|
+
else process.stderr.write(`${message}\n`);
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// src/cli/commands/mcp/index.ts
|
|
78
|
+
function registerMcpCommand(cli) {
|
|
79
|
+
cli.command("mcp [...args]", "start weapp-vite MCP server or manage MCP client onboarding").option("--transport <type>", "[string] stdio | streamable-http | command | http", { default: "stdio" }).option("--host <host>", "[string] streamable-http host").option("--port <port>", "[number] streamable-http port").option("--endpoint <path>", "[string] streamable-http endpoint path").option("--rest-endpoint <path>", "[string] streamable-http REST runtime endpoint path").option("--no-rest", "[boolean] disable streamable-http REST runtime endpoints").option("--unref", "[boolean] unref HTTP server to not block process exit").option("--url <url>", "[string] explicit HTTP MCP url").option("--workspace-root <path>", "[string] workspace root path, defaults to cwd").option("-y, --yes", "[boolean] write config without prompt").action(async (args, options) => {
|
|
80
|
+
const { runMcpCommand } = await import("./action-ytG5oFAw.mjs");
|
|
81
|
+
return runMcpCommand(args, options);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
export { registerAcceptCommand as n, registerMcpCommand as t };
|
|
@@ -2,7 +2,7 @@ import { r as logger_default } from "./logger-DGn5iEVN.mjs";
|
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT } from "@weapp-core/constants";
|
|
4
4
|
import { determineAgent } from "@vercel/detect-agent";
|
|
5
|
-
|
|
5
|
+
// src/aiEnvironment.ts
|
|
6
6
|
const AI_ENV_KEYS = [
|
|
7
7
|
"CODEX_HOME",
|
|
8
8
|
"CODEX_SANDBOX",
|
|
@@ -71,8 +71,7 @@ function resolveBooleanLikeEnv(value) {
|
|
|
71
71
|
"off"
|
|
72
72
|
].includes(normalized)) return false;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
//#region src/mcp.ts
|
|
74
|
+
// src/mcp.ts
|
|
76
75
|
/** 创建服务时才加载 MCP 运行时;配置解析与公开常量保持同步。 */
|
|
77
76
|
async function createWeappViteMcpServer(options) {
|
|
78
77
|
const { createWeappViteMcpServer } = await import("@weapp-vite/mcp");
|
|
@@ -133,5 +132,4 @@ async function startWeappViteMcpServer(options) {
|
|
|
133
132
|
})
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
|
-
//#endregion
|
|
137
135
|
export { createWeappViteMcpServer as a, startWeappViteMcpServer 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,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ut as WeappMcpConfig } from "./config-BNx2BODw.mjs";
|
|
2
2
|
import { DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT } from "@weapp-core/constants";
|
|
3
3
|
import { CreateServerOptions, McpServerHandle, StartMcpServerOptions, createWeappViteMcpServer as createWeappViteMcpServer$1 } from "@weapp-vite/mcp";
|
|
4
|
-
//#region src/mcp.d.ts
|
|
5
4
|
/** 创建服务时才加载 MCP 运行时;配置解析与公开常量保持同步。 */
|
|
6
5
|
export declare function createWeappViteMcpServer(options?: CreateServerOptions): ReturnType<typeof createWeappViteMcpServer$1>;
|
|
7
6
|
export interface ResolvedWeappMcpConfig {
|
|
@@ -24,5 +23,4 @@ export interface ResolveWeappMcpConfigOptions {
|
|
|
24
23
|
export declare function resolveProjectMcpPort(projectRoot?: string): number;
|
|
25
24
|
export declare function resolveWeappMcpConfig(config?: boolean | WeappMcpConfig, options?: ResolveWeappMcpConfigOptions): ResolvedWeappMcpConfig;
|
|
26
25
|
export declare function startWeappViteMcpServer(options?: WeappViteMcpServerOptions): Promise<WeappViteMcpServerHandle>;
|
|
27
|
-
//#endregion
|
|
28
26
|
export { type CreateServerOptions, DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT };
|
package/dist/mcp.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as DEFAULT_MCP_ENDPOINT, n as DEFAULT_MCP_HOST, r as DEFAULT_MCP_PORT, i as DEFAULT_RUNTIME_REST_ENDPOINT, a as createWeappViteMcpServer, o as resolveProjectMcpPort, s as resolveWeappMcpConfig, c as startWeappViteMcpServer } from "./mcp-
|
|
1
|
+
export { t as DEFAULT_MCP_ENDPOINT, n as DEFAULT_MCP_HOST, r as DEFAULT_MCP_PORT, i as DEFAULT_RUNTIME_REST_ENDPOINT, a as createWeappViteMcpServer, o as resolveProjectMcpPort, s as resolveWeappMcpConfig, c as startWeappViteMcpServer } from "./mcp-ovJgl1N9.mjs";
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import { fs } from "@weapp-core/shared/fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import { clearTimeout, setTimeout } from "node:timers";
|
|
6
|
+
// src/cli/mcpClient/shared.ts
|
|
7
|
+
const CODEX_BLOCK_PREFIX = "# >>> weapp-vite mcp ";
|
|
8
|
+
const CODEX_BLOCK_SUFFIX = " >>>";
|
|
9
|
+
const CODEX_BLOCK_END_PREFIX = "# <<< weapp-vite mcp ";
|
|
10
|
+
const CODEX_BLOCK_END_SUFFIX = " <<<";
|
|
11
|
+
const DEFAULT_HTTP_TIMEOUT_MS = 1500;
|
|
12
|
+
const WORKSPACE_FOLDER_TOKEN = "${workspaceFolder}";
|
|
13
|
+
const REG_CodexUrl = /^\s*url\s*=\s*"([^"]+)"/m;
|
|
14
|
+
const REG_CodexCommand = /^\s*command\s*=\s*"([^"]+)"/m;
|
|
15
|
+
const REG_CodexArgs = /^\s*args\s*=\s*\[([^\]]*)\]/m;
|
|
16
|
+
const REG_FirstTomlString = /"([^"]+)"/;
|
|
17
|
+
function resolveTargetWorkspaceRoot(target) {
|
|
18
|
+
if (target.client === "cursor") return path.dirname(path.dirname(target.configPath));
|
|
19
|
+
if (target.client === "claude-code") return path.dirname(target.configPath);
|
|
20
|
+
return process.cwd();
|
|
21
|
+
}
|
|
22
|
+
function escapeRegExp(value) {
|
|
23
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24
|
+
}
|
|
25
|
+
function renderTomlString(value) {
|
|
26
|
+
return JSON.stringify(value);
|
|
27
|
+
}
|
|
28
|
+
function sanitizeServerNameSegment(value) {
|
|
29
|
+
return value.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/-{2,}/g, "-").replace(/^-|-$/g, "");
|
|
30
|
+
}
|
|
31
|
+
function resolveServerName(workspaceRoot) {
|
|
32
|
+
return `weapp-vite-${sanitizeServerNameSegment(path.basename(workspaceRoot)) || "project"}`;
|
|
33
|
+
}
|
|
34
|
+
function resolveNodeBinCommand() {
|
|
35
|
+
return process.execPath || "node";
|
|
36
|
+
}
|
|
37
|
+
function resolveProjectCliBin(workspaceRoot) {
|
|
38
|
+
return path.join(workspaceRoot, "node_modules", "weapp-vite", "bin", "weapp-vite.js");
|
|
39
|
+
}
|
|
40
|
+
function renderCommandArgs(args) {
|
|
41
|
+
return args.map(renderTomlString).join(", ");
|
|
42
|
+
}
|
|
43
|
+
function renderCodexBlock(serverName, entry) {
|
|
44
|
+
const startMarker = `${CODEX_BLOCK_PREFIX}${serverName}${CODEX_BLOCK_SUFFIX}`;
|
|
45
|
+
const endMarker = `${CODEX_BLOCK_END_PREFIX}${serverName}${CODEX_BLOCK_END_SUFFIX}`;
|
|
46
|
+
if (entry.url) return `${startMarker}
|
|
47
|
+
[mcp_servers.${serverName}]
|
|
48
|
+
url = ${renderTomlString(entry.url)}
|
|
49
|
+
${endMarker}
|
|
50
|
+
`;
|
|
51
|
+
return `${startMarker}
|
|
52
|
+
[mcp_servers.${serverName}]
|
|
53
|
+
command = ${renderTomlString(entry.command ?? resolveNodeBinCommand())}
|
|
54
|
+
args = [${renderCommandArgs(entry.args ?? [])}]
|
|
55
|
+
${endMarker}
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
function renderJsonPreview(serverName, entry) {
|
|
59
|
+
return `${JSON.stringify({ mcpServers: { [serverName]: entry } }, null, 2)}
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
function resolveCommandEntry(client, workspaceRoot) {
|
|
63
|
+
const binPath = resolveProjectCliBin(workspaceRoot);
|
|
64
|
+
if (client === "cursor") return {
|
|
65
|
+
command: "node",
|
|
66
|
+
args: [
|
|
67
|
+
`${WORKSPACE_FOLDER_TOKEN}/node_modules/weapp-vite/bin/weapp-vite.js`,
|
|
68
|
+
"mcp",
|
|
69
|
+
"--workspace-root",
|
|
70
|
+
WORKSPACE_FOLDER_TOKEN
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
command: resolveNodeBinCommand(),
|
|
75
|
+
args: [
|
|
76
|
+
binPath,
|
|
77
|
+
"mcp",
|
|
78
|
+
"--workspace-root",
|
|
79
|
+
workspaceRoot
|
|
80
|
+
]
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function resolveHttpEntry(client, url) {
|
|
84
|
+
if (client === "claude-code") return {
|
|
85
|
+
type: "http",
|
|
86
|
+
url
|
|
87
|
+
};
|
|
88
|
+
return { url };
|
|
89
|
+
}
|
|
90
|
+
function resolveConfigEntry(client, transport, workspaceRoot, url) {
|
|
91
|
+
return transport === "http" ? resolveHttpEntry(client, url ?? "") : resolveCommandEntry(client, workspaceRoot);
|
|
92
|
+
}
|
|
93
|
+
function resolveCodexBlockPattern(serverName) {
|
|
94
|
+
const startMarker = `${CODEX_BLOCK_PREFIX}${serverName}${CODEX_BLOCK_SUFFIX}`;
|
|
95
|
+
const endMarker = `${CODEX_BLOCK_END_PREFIX}${serverName}${CODEX_BLOCK_END_SUFFIX}`;
|
|
96
|
+
return new RegExp(`${escapeRegExp(startMarker)}[\\s\\S]*?${escapeRegExp(endMarker)}\\n?`, "g");
|
|
97
|
+
}
|
|
98
|
+
function upsertCodexManagedBlock(content, serverName, block) {
|
|
99
|
+
const withoutExisting = content.trimEnd().replace(resolveCodexBlockPattern(serverName), "").trimEnd();
|
|
100
|
+
if (!withoutExisting) return block;
|
|
101
|
+
return `${withoutExisting}\n\n${block}`;
|
|
102
|
+
}
|
|
103
|
+
function parseJsonConfig(content, configPath) {
|
|
104
|
+
if (!content.trim()) return {};
|
|
105
|
+
try {
|
|
106
|
+
return JSON.parse(content);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
109
|
+
throw new Error(`无法解析 MCP 配置文件 ${configPath}:${message}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function resolveTarget(client, workspaceRoot) {
|
|
113
|
+
const serverName = resolveServerName(workspaceRoot);
|
|
114
|
+
if (client === "codex") return {
|
|
115
|
+
client,
|
|
116
|
+
configPath: path.join(os.homedir(), ".codex", "config.toml"),
|
|
117
|
+
displayName: "Codex",
|
|
118
|
+
serverName
|
|
119
|
+
};
|
|
120
|
+
if (client === "claude-code") return {
|
|
121
|
+
client,
|
|
122
|
+
configPath: path.join(workspaceRoot, ".mcp.json"),
|
|
123
|
+
displayName: "Claude Code",
|
|
124
|
+
serverName
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
client,
|
|
128
|
+
configPath: path.join(workspaceRoot, ".cursor", "mcp.json"),
|
|
129
|
+
displayName: "Cursor",
|
|
130
|
+
serverName
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// src/cli/mcpClient/inspect.ts
|
|
134
|
+
async function probeHttpEndpoint(url) {
|
|
135
|
+
const controller = new AbortController();
|
|
136
|
+
const timer = setTimeout(() => {
|
|
137
|
+
controller.abort();
|
|
138
|
+
}, DEFAULT_HTTP_TIMEOUT_MS);
|
|
139
|
+
try {
|
|
140
|
+
return (await fetch(url, {
|
|
141
|
+
method: "GET",
|
|
142
|
+
signal: controller.signal
|
|
143
|
+
})).status > 0;
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
} finally {
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
controller.abort();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function inspectJsonConfig(target) {
|
|
152
|
+
if (!await fs.pathExists(target.configPath)) return {
|
|
153
|
+
configExists: false,
|
|
154
|
+
configPath: target.configPath,
|
|
155
|
+
displayName: target.displayName,
|
|
156
|
+
issues: [`未找到配置文件:${target.configPath}`],
|
|
157
|
+
serverName: target.serverName
|
|
158
|
+
};
|
|
159
|
+
const entry = parseJsonConfig(await fs.readFile(target.configPath, "utf8"), target.configPath).mcpServers?.[target.serverName];
|
|
160
|
+
if (!entry) return {
|
|
161
|
+
configExists: true,
|
|
162
|
+
configPath: target.configPath,
|
|
163
|
+
displayName: target.displayName,
|
|
164
|
+
issues: [`配置文件中未找到服务器 ${target.serverName}`],
|
|
165
|
+
serverName: target.serverName
|
|
166
|
+
};
|
|
167
|
+
const transport = entry.url ? "http" : "command";
|
|
168
|
+
const issues = [];
|
|
169
|
+
let httpReachable;
|
|
170
|
+
if (transport === "command") {
|
|
171
|
+
const normalizedBin = (entry.args?.[0])?.replaceAll(WORKSPACE_FOLDER_TOKEN, resolveTargetWorkspaceRoot(target));
|
|
172
|
+
if (!normalizedBin || !await fs.pathExists(normalizedBin)) issues.push(`未找到本地 CLI 入口:${normalizedBin ?? "缺少 args[0]"}`);
|
|
173
|
+
} else if (entry.url) {
|
|
174
|
+
httpReachable = await probeHttpEndpoint(entry.url);
|
|
175
|
+
if (!httpReachable) issues.push(`HTTP MCP 地址不可达:${entry.url}`);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
configExists: true,
|
|
179
|
+
configPath: target.configPath,
|
|
180
|
+
displayName: target.displayName,
|
|
181
|
+
httpReachable,
|
|
182
|
+
issues,
|
|
183
|
+
serverName: target.serverName,
|
|
184
|
+
transport
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async function inspectCodexConfig(target) {
|
|
188
|
+
if (!await fs.pathExists(target.configPath)) return {
|
|
189
|
+
configExists: false,
|
|
190
|
+
configPath: target.configPath,
|
|
191
|
+
displayName: target.displayName,
|
|
192
|
+
issues: [`未找到配置文件:${target.configPath}`],
|
|
193
|
+
serverName: target.serverName
|
|
194
|
+
};
|
|
195
|
+
const blockMatch = (await fs.readFile(target.configPath, "utf8")).match(resolveCodexBlockPattern(target.serverName));
|
|
196
|
+
if (!blockMatch?.[0]) return {
|
|
197
|
+
configExists: true,
|
|
198
|
+
configPath: target.configPath,
|
|
199
|
+
displayName: target.displayName,
|
|
200
|
+
issues: [`未找到 weapp-vite 生成的 Codex 配置区块:${target.serverName}`],
|
|
201
|
+
serverName: target.serverName
|
|
202
|
+
};
|
|
203
|
+
const block = blockMatch[0];
|
|
204
|
+
const issues = [];
|
|
205
|
+
const urlMatch = block.match(REG_CodexUrl);
|
|
206
|
+
const commandMatch = block.match(REG_CodexCommand);
|
|
207
|
+
const argsMatch = block.match(REG_CodexArgs);
|
|
208
|
+
if (urlMatch?.[1]) {
|
|
209
|
+
const reachable = await probeHttpEndpoint(urlMatch[1]);
|
|
210
|
+
if (!reachable) issues.push(`HTTP MCP 地址不可达:${urlMatch[1]}`);
|
|
211
|
+
return {
|
|
212
|
+
configExists: true,
|
|
213
|
+
configPath: target.configPath,
|
|
214
|
+
displayName: target.displayName,
|
|
215
|
+
httpReachable: reachable,
|
|
216
|
+
issues,
|
|
217
|
+
serverName: target.serverName,
|
|
218
|
+
transport: "http"
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const binPath = (argsMatch?.[1]?.match(REG_FirstTomlString))?.[1];
|
|
222
|
+
if (!commandMatch?.[1]) issues.push("Codex 配置区块缺少 command 字段");
|
|
223
|
+
if (!binPath || !await fs.pathExists(binPath)) issues.push(`未找到本地 CLI 入口:${binPath ?? "缺少 args[0]"}`);
|
|
224
|
+
return {
|
|
225
|
+
configExists: true,
|
|
226
|
+
configPath: target.configPath,
|
|
227
|
+
displayName: target.displayName,
|
|
228
|
+
issues,
|
|
229
|
+
serverName: target.serverName,
|
|
230
|
+
transport: "command"
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
async function inspectMcpClientConfig(options) {
|
|
234
|
+
const target = resolveTarget(options.client, path.resolve(options.workspaceRoot));
|
|
235
|
+
if (target.client === "codex") return await inspectCodexConfig(target);
|
|
236
|
+
return await inspectJsonConfig(target);
|
|
237
|
+
}
|
|
238
|
+
// src/cli/mcpClient/plan.ts
|
|
239
|
+
function resolveSupportedMcpClient(input) {
|
|
240
|
+
if (input === "codex" || input === "claude-code" || input === "cursor") return input;
|
|
241
|
+
throw new Error(`不支持的 MCP 客户端:${input}。当前仅支持 codex、claude-code、cursor。`);
|
|
242
|
+
}
|
|
243
|
+
function buildMcpClientConfigPlan(options) {
|
|
244
|
+
const workspaceRoot = path.resolve(options.workspaceRoot);
|
|
245
|
+
const target = resolveTarget(options.client, workspaceRoot);
|
|
246
|
+
const entry = resolveConfigEntry(options.client, options.transport, workspaceRoot, options.url);
|
|
247
|
+
if (options.transport === "http" && !entry.url) throw new Error("HTTP 模式缺少 MCP 服务地址,请使用 --url 指定或在当前项目中检测到可用地址。");
|
|
248
|
+
return {
|
|
249
|
+
entry,
|
|
250
|
+
preview: target.client === "codex" ? renderCodexBlock(target.serverName, entry) : renderJsonPreview(target.serverName, entry),
|
|
251
|
+
target,
|
|
252
|
+
transport: options.transport
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function formatMcpQuickStart(options) {
|
|
256
|
+
const suffix = options.transport === "http" && options.httpUrl ? ` --transport http --url ${options.httpUrl}` : "";
|
|
257
|
+
return [
|
|
258
|
+
"在 AI 工具中接入 weapp-vite MCP:",
|
|
259
|
+
` - Codex: wv mcp init codex${suffix}`,
|
|
260
|
+
` - Claude Code: wv mcp init claude-code${suffix}`,
|
|
261
|
+
` - Cursor: wv mcp init cursor${suffix}`
|
|
262
|
+
];
|
|
263
|
+
}
|
|
264
|
+
// src/cli/mcpClient/index.ts
|
|
265
|
+
async function writeMcpClientConfig(plan) {
|
|
266
|
+
await fs.ensureDir(path.dirname(plan.target.configPath));
|
|
267
|
+
const existing = await fs.readFile(plan.target.configPath, "utf8").catch(() => "");
|
|
268
|
+
if (plan.target.client === "codex") {
|
|
269
|
+
const nextContent = upsertCodexManagedBlock(existing, plan.target.serverName, plan.preview);
|
|
270
|
+
await fs.writeFile(plan.target.configPath, nextContent, "utf8");
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const parsed = parseJsonConfig(existing, plan.target.configPath);
|
|
274
|
+
const nextConfig = {
|
|
275
|
+
...parsed,
|
|
276
|
+
mcpServers: {
|
|
277
|
+
...parsed.mcpServers ?? {},
|
|
278
|
+
[plan.target.serverName]: plan.entry
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
await fs.writeFile(plan.target.configPath, `${JSON.stringify(nextConfig, null, 2)}\n`, "utf8");
|
|
282
|
+
}
|
|
283
|
+
export { inspectMcpClientConfig as a, resolveSupportedMcpClient as i, buildMcpClientConfigPlan as n, formatMcpQuickStart as r, writeMcpClientConfig as t };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
1
|
import path from "pathe";
|
|
3
|
-
|
|
2
|
+
// src/analyze/subpackages/metadata.ts
|
|
4
3
|
const defaultTotalBudgetBytes = 20971520;
|
|
5
4
|
const defaultPackageBudgetBytes = 2097152;
|
|
6
5
|
const defaultWarningRatio = .85;
|
|
@@ -56,22 +55,4 @@ function createAnalyzeMetadata(configService, now = /* @__PURE__ */ new Date())
|
|
|
56
55
|
}
|
|
57
56
|
};
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
//#region src/cli/processCleanup.ts
|
|
61
|
-
function isSassEmbeddedChild(handle) {
|
|
62
|
-
if (!handle || typeof handle !== "object") return false;
|
|
63
|
-
const child = handle;
|
|
64
|
-
const spawnfile = typeof child.spawnfile === "string" ? child.spawnfile : "";
|
|
65
|
-
const spawnargs = Array.isArray(child.spawnargs) ? child.spawnargs : [];
|
|
66
|
-
return Boolean("kill" in handle && "spawnfile" in handle && (spawnfile.includes("sass-embedded") || spawnfile.includes("dart-sass") && spawnargs.includes("--embedded")));
|
|
67
|
-
}
|
|
68
|
-
function terminateStaleSassEmbeddedProcess() {
|
|
69
|
-
const getHandles = process._getActiveHandles;
|
|
70
|
-
const handles = typeof getHandles === "function" ? getHandles() : void 0;
|
|
71
|
-
if (!Array.isArray(handles)) return;
|
|
72
|
-
for (const handle of handles) if (isSassEmbeddedChild(handle)) try {
|
|
73
|
-
handle.kill();
|
|
74
|
-
} catch {}
|
|
75
|
-
}
|
|
76
|
-
//#endregion
|
|
77
|
-
export { resolveAnalyzeHistoryMetadata as i, createAnalyzeMetadata as n, resolveAnalyzeBudgets as r, terminateStaleSassEmbeddedProcess as t };
|
|
58
|
+
export { resolveAnalyzeBudgets as n, resolveAnalyzeHistoryMetadata as r, createAnalyzeMetadata as t };
|