weapp-ide-cli 6.1.9 → 6.3.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 +74 -0
- package/dist/automator-BOe32upt.js +822 -0
- package/dist/automator-VSjgHujY.js +1 -0
- package/dist/automator-session-VOB03glx.js +186 -0
- package/dist/automatorProject-DjYLqMj6.js +881 -0
- package/dist/{cli-2sY1sAVq.js → cli-CFlqFpIw.js} +1552 -74
- package/dist/cli.js +3 -3
- package/dist/commands-DmirGBy4.js +1 -0
- package/dist/commands-mslf7-sP.js +529 -0
- package/dist/devtoolsProjectOwnership-BMfSAg4n.js +2022 -0
- package/dist/index.d.ts +420 -76
- package/dist/index.js +8 -5
- package/dist/managed-B04Xo9U_.js +264 -0
- package/dist/run-mcp-83-VKZVA.js +1 -0
- package/dist/{run-mcp-LqaWlQJ_.js → run-mcp-Ni139Z5C.js} +28 -9
- package/package.json +13 -12
- package/dist/automator-session-fbanL2eW.js +0 -1362
- package/dist/commands-DpMG1w04.js +0 -2
- package/dist/commands-__RJ552L.js +0 -1359
- package/dist/run-mcp-C2SQ_hRJ.js +0 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { C as
|
|
4
|
-
import { a as
|
|
5
|
-
|
|
1
|
+
import { A as operatingSystemName, B as removeCustomConfigKey, C as registerWechatDevtoolsInstallation, D as SupportedPlatformsMap, F as createAutoTrustProjectConfig, H as defaultCustomConfigFilePath, I as createCustomConfig, L as createLocaleConfig, O as getDefaultCliPath, P as createAutoBootstrapDevtoolsConfig, R as overwriteCustomConfig, U as resolvePath, V as defaultCustomConfigDirPath, _ as WECHAT_DEVTOOLS_OFFICIAL_CHANNELS_URL, b as compareWechatDevtoolsVersions, c as getActiveWechatDevtoolsTarget, d as validateWechatDevtoolsSelection, f as withWechatDevtoolsSelection, k as isOperatingSystemSupported, l as readWechatDevtoolsSelectionEnvironment, m as assertWechatDevtoolsPort, o as MANAGED_PROJECT_JOURNAL_ENV, p as assertWechatDevtoolsHost, s as MANAGED_PROJECT_MAX_WINDOWS_ENV, u as resolveWechatDevtoolsTarget, v as assertOfficialWechatDevtoolsVersion, w as unregisterWechatDevtoolsInstallation, x as listWechatDevtoolsInstallations, y as readOfficialWechatDevtoolsVersion, z as readCustomConfig } from "./automatorProject-DjYLqMj6.js";
|
|
2
|
+
import { a as isManagedWechatProjectFullyReleased, i as recoverManagedWechatProjectsAfterInstallationExit, m as startWechatIdeAgent, n as cleanupManagedWechatProjects, r as closeManagedWechatProject, s as readManagedWechatProjectRecords, t as beginManagedWechatProject } from "./devtoolsProjectOwnership-BMfSAg4n.js";
|
|
3
|
+
import { A as waitForExclusiveKeypress, C as isWechatIdeLoginRequiredError, D as waitForRetryKeypress, E as promptWechatIdeLoginRetry, O as createSharedInputSession, P as resolveAutomatorSessionOptions, S as formatWechatIdeLoginRequiredError, T as promptRetryKeypress, _ as RETRY_CONFIRM_KEYS, a as bootstrapWechatDevtoolsSettings, b as extractExecutionErrorText, c as getAutomatorProtocolTimeoutMethod, d as isAutomatorProtocolTimeoutError, f as isAutomatorWsConnectError, g as RETRY_CANCEL_KEYS, h as isRetryableAutomatorLaunchError, i as resolveProjectAutomatorPort, k as runWithSuspendedSharedInput, l as isAutomatorLoginError, m as isDevtoolsHttpPortError, n as launchAutomator, o as detectWechatDevtoolsServicePort, p as isDevtoolsExtensionContextInvalidatedError, r as persistOpenedAutomatorSession, s as formatAutomatorLoginError, t as connectOpenedAutomator, u as isAutomatorPortInUseError, v as RETRY_PROMPT_INITIAL_IGNORE_MS, w as isWechatIdeLoginRequiredExitError, x as formatRetryHotkeyPrompt, y as createWechatIdeLoginRequiredExitError } from "./automator-BOe32upt.js";
|
|
4
|
+
import { $ as getConfig, A as queryWechatIdeLogin, B as WECHAT_DEVTOOLS_ENGINE_BUILD_STATUSES, C as refreshWechatIdeTicket, D as validateWechatCliCommandArgs, E as uploadWechatIde, F as startForwardConsole, G as startWechatIdeEngineBuildByHttp, H as pollWechatIdeEngineBuildResultByHttp, I as isWechatIdeEngineBuildEndpointMissingError, J as splitWechatDevtoolsSelectionArgs, K as getRuntimeWechatDevtoolsServicePort, L as prepareAcceptanceProject, M as createAlias, N as createPathCompat, O as runWechatCliWithRetry, P as transformArgv, Q as promptForCliPath, R as runWechatIdeEngineBuild, S as quitWechatIde, T as setWechatIdeTicket, U as requestWechatDevtoolsHttp, V as openWechatIdeProjectByHttp, W as resetWechatIdeFileUtilsByHttp, X as handleConfigCommand, Y as withWechatDevtoolsSelectionArgs, Z as resolveCliPath, _ as isWechatIdeLoggedIn, _t as readBooleanOption, a as autoReplayWechatIde, at as WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, b as openWechatIdeOtherProject, c as buildWechatIdeIpa, ct as AUTOMATOR_COMMAND_NAMES, d as clearWechatIdeCacheByAutomator, dt as runAutomatorCommand, et as getConfiguredLocale, f as closeWechatIdeProject, ft as parseScreenshotArgs, g as getWechatIdeToolInfo, gt as parseAutomatorArgs, h as getWechatIdeTicket, ht as printCompareHelp, i as autoPreviewWechatIde, it as MINIDEV_NAMESPACE_COMMAND_NAMES, j as execute, k as runMinidev, l as buildWechatIdeNpm, lt as getAutomatorCommandHelp, m as getWechatIdeTestAccounts, mt as parseCompareArgs, n as parse, nt as CONFIG_COMMAND_NAME, o as autoWechatIde, ot as WECHAT_CLI_COMMAND_NAMES, p as compileWechatIdeByAutomator, pt as printScreenshotHelp, q as setRuntimeWechatDevtoolsServicePort, r as dispatchWechatCliCommand, rt as MCP_COMMAND_NAME, s as buildWechatIdeApk, st as isWeappIdeTopLevelCommand, t as createCli, tt as resolveDevtoolsAutomationDefaults, u as clearWechatIdeCache, ut as isAutomatorCommand, v as loginWechatIde, vt as readOptionValue, w as resetWechatIdeFileUtils, x as previewWechatIde, y as openWechatIde, yt as removeOption, z as runWechatIdeEngineBuildByHttp } from "./cli-CFlqFpIw.js";
|
|
5
|
+
import { c as releaseSharedMiniProgram, i as closeSharedMiniProgram, l as withMiniProgram, n as acquireSharedMiniProgram, o as connectMiniProgram, s as getSharedMiniProgramSessionCount, u as runRetryableCommand } from "./automator-session-VOB03glx.js";
|
|
6
|
+
import { a as navigateBack, c as pageStack, d as remote, f as scrollTo, g as tap, h as takeScreenshot, i as input, l as reLaunch, m as systemInfo, n as captureScreenshotBuffer, o as navigateTo, p as switchTab, r as currentPage, s as pageData, t as audit, u as redirectTo } from "./commands-mslf7-sP.js";
|
|
7
|
+
import { a as readElementSnapshot, i as registerWeappIdeMcpTools, n as startWeappIdeMcpServer, o as resolveProjectPath, r as createWeappIdeMcpServer, s as toSerializableValue, t as runMcpCommand } from "./run-mcp-Ni139Z5C.js";
|
|
8
|
+
export { AUTOMATOR_COMMAND_NAMES, CONFIG_COMMAND_NAME, MANAGED_PROJECT_JOURNAL_ENV, MANAGED_PROJECT_MAX_WINDOWS_ENV, MCP_COMMAND_NAME, MINIDEV_NAMESPACE_COMMAND_NAMES, RETRY_CANCEL_KEYS, RETRY_CONFIRM_KEYS, RETRY_PROMPT_INITIAL_IGNORE_MS, SupportedPlatformsMap, WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, WECHAT_CLI_COMMAND_NAMES, WECHAT_DEVTOOLS_ENGINE_BUILD_STATUSES, WECHAT_DEVTOOLS_OFFICIAL_CHANNELS_URL, acquireSharedMiniProgram, assertOfficialWechatDevtoolsVersion, assertWechatDevtoolsHost, assertWechatDevtoolsPort, audit, autoPreviewWechatIde, autoReplayWechatIde, autoWechatIde, beginManagedWechatProject, bootstrapWechatDevtoolsSettings, buildWechatIdeApk, buildWechatIdeIpa, buildWechatIdeNpm, captureScreenshotBuffer, cleanupManagedWechatProjects, clearWechatIdeCache, clearWechatIdeCacheByAutomator, closeManagedWechatProject, closeSharedMiniProgram, closeWechatIdeProject, compareWechatDevtoolsVersions, compileWechatIdeByAutomator, connectMiniProgram, connectOpenedAutomator, createAlias, createAutoBootstrapDevtoolsConfig, createAutoTrustProjectConfig, createCli, createCustomConfig, createLocaleConfig, createPathCompat, createSharedInputSession, createWeappIdeMcpServer, createWechatIdeLoginRequiredExitError, currentPage, defaultCustomConfigDirPath, defaultCustomConfigFilePath, detectWechatDevtoolsServicePort, dispatchWechatCliCommand, execute, extractExecutionErrorText, formatAutomatorLoginError, formatRetryHotkeyPrompt, formatWechatIdeLoginRequiredError, getActiveWechatDevtoolsTarget, getAutomatorCommandHelp, getAutomatorProtocolTimeoutMethod, getConfig, getConfiguredLocale, getDefaultCliPath, getRuntimeWechatDevtoolsServicePort, getSharedMiniProgramSessionCount, getWechatIdeTestAccounts, getWechatIdeTicket, getWechatIdeToolInfo, handleConfigCommand, input, isAutomatorCommand, isAutomatorLoginError, isAutomatorPortInUseError, isAutomatorProtocolTimeoutError, isAutomatorWsConnectError, isDevtoolsExtensionContextInvalidatedError, isDevtoolsHttpPortError, isManagedWechatProjectFullyReleased, isOperatingSystemSupported, isRetryableAutomatorLaunchError, isWeappIdeTopLevelCommand, isWechatIdeEngineBuildEndpointMissingError, isWechatIdeLoggedIn, isWechatIdeLoginRequiredError, isWechatIdeLoginRequiredExitError, launchAutomator, listWechatDevtoolsInstallations, loginWechatIde, navigateBack, navigateTo, openWechatIde, openWechatIdeOtherProject, openWechatIdeProjectByHttp, operatingSystemName, overwriteCustomConfig, pageData, pageStack, parse, parseAutomatorArgs, parseCompareArgs, parseScreenshotArgs, persistOpenedAutomatorSession, pollWechatIdeEngineBuildResultByHttp, prepareAcceptanceProject, previewWechatIde, printCompareHelp, printScreenshotHelp, promptForCliPath, promptRetryKeypress, promptWechatIdeLoginRetry, queryWechatIdeLogin, quitWechatIde, reLaunch, readBooleanOption, readCustomConfig, readElementSnapshot, readManagedWechatProjectRecords, readOfficialWechatDevtoolsVersion, readOptionValue, readWechatDevtoolsSelectionEnvironment, recoverManagedWechatProjectsAfterInstallationExit, redirectTo, refreshWechatIdeTicket, registerWeappIdeMcpTools, registerWechatDevtoolsInstallation, releaseSharedMiniProgram, remote, removeCustomConfigKey, removeOption, requestWechatDevtoolsHttp, resetWechatIdeFileUtils, resetWechatIdeFileUtilsByHttp, resolveAutomatorSessionOptions, resolveCliPath, resolveDevtoolsAutomationDefaults, resolvePath, resolveProjectAutomatorPort, resolveProjectPath, resolveWechatDevtoolsTarget, runAutomatorCommand, runMcpCommand, runMinidev, runRetryableCommand, runWechatCliWithRetry, runWechatIdeEngineBuild, runWechatIdeEngineBuildByHttp, runWithSuspendedSharedInput, scrollTo, setRuntimeWechatDevtoolsServicePort, setWechatIdeTicket, splitWechatDevtoolsSelectionArgs, startForwardConsole, startWeappIdeMcpServer, startWechatIdeAgent, startWechatIdeEngineBuildByHttp, switchTab, systemInfo, takeScreenshot, tap, toSerializableValue, transformArgv, unregisterWechatDevtoolsInstallation, uploadWechatIde, validateWechatCliCommandArgs, validateWechatDevtoolsSelection, waitForExclusiveKeypress, waitForRetryKeypress, withMiniProgram, withWechatDevtoolsSelection, withWechatDevtoolsSelectionArgs };
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { i as persistAutomatorSession, m as assertWechatDevtoolsPort, n as readAutomatorProjectPlan, t as populateAutomatorProjectSnapshot } from "./automatorProject-DjYLqMj6.js";
|
|
2
|
+
import { m as startWechatIdeAgent, t as beginManagedWechatProject } from "./devtoolsProjectOwnership-BMfSAg4n.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { withMachineE2ELease } from "@weapp-vite/devtools-runtime";
|
|
5
|
+
import { execa } from "execa";
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import { acquireAutomatorPortLease } from "@weapp-vite/miniprogram-automator";
|
|
9
|
+
//#region src/cli/projectImport.ts
|
|
10
|
+
function isRecord(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
/** 使用同一安装的 skill 入口;Windows 由 execa 处理官方 cmd 包装器。 */
|
|
14
|
+
function resolveProjectImportCli(cliPath, platform = process.platform) {
|
|
15
|
+
const paths = platform === "win32" ? path.win32 : path.posix;
|
|
16
|
+
return paths.join(paths.dirname(cliPath), platform === "win32" ? "wechatide.cmd" : "wechatide");
|
|
17
|
+
}
|
|
18
|
+
/** 官方导入会重写项目根、条件页和基础库选择;窗口启动前恢复原始输入。 */
|
|
19
|
+
async function preserveProjectConfig(projectPath, fileName, run) {
|
|
20
|
+
const file = path.join(projectPath, fileName);
|
|
21
|
+
const original = await fs.readFile(file).catch((error) => {
|
|
22
|
+
if (error.code !== "ENOENT") throw error;
|
|
23
|
+
});
|
|
24
|
+
let failure;
|
|
25
|
+
let failed = false;
|
|
26
|
+
try {
|
|
27
|
+
await run();
|
|
28
|
+
} catch (error) {
|
|
29
|
+
failure = error;
|
|
30
|
+
failed = true;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
if (original) {
|
|
34
|
+
if (!(await fs.readFile(file).catch((error) => {
|
|
35
|
+
if (error.code !== "ENOENT") throw error;
|
|
36
|
+
}))?.equals(original)) await fs.writeFile(file, original);
|
|
37
|
+
} else await fs.rm(file, { force: true });
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (failed) throw new AggregateError([failure, error], "Official import failed and fixture config restoration did not complete");
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
if (failed) throw failure;
|
|
43
|
+
}
|
|
44
|
+
/** 先完成官方项目导入,再启动受管窗口;导入不编译、不导航,也不修改私有能力记录。 */
|
|
45
|
+
async function importManagedDevtoolsProject(options) {
|
|
46
|
+
if (!options.trusted || !process.env["WEAPP_IDE_MANAGED_PROJECT_JOURNAL"]) return;
|
|
47
|
+
options.signal.throwIfAborted();
|
|
48
|
+
const projectPath = path.resolve(options.projectPath);
|
|
49
|
+
await withMachineE2ELease(() => preserveProjectConfig(projectPath, "project.config.json", () => preserveProjectConfig(projectPath, "project.private.config.json", async () => {
|
|
50
|
+
options.signal.throwIfAborted();
|
|
51
|
+
const { stdout } = await execa(resolveProjectImportCli(options.cliPath), [
|
|
52
|
+
"-c",
|
|
53
|
+
"weapp-vite-e2e",
|
|
54
|
+
"project_import",
|
|
55
|
+
"--project",
|
|
56
|
+
projectPath
|
|
57
|
+
], {
|
|
58
|
+
timeout: options.timeout,
|
|
59
|
+
cancelSignal: options.signal,
|
|
60
|
+
killDescendants: false
|
|
61
|
+
});
|
|
62
|
+
const payload = JSON.parse(stdout);
|
|
63
|
+
const result = isRecord(payload) && isRecord(payload.result) ? payload.result : void 0;
|
|
64
|
+
if (!isRecord(payload) || payload.ok !== true || payload.tool !== "project_import" || payload.clientName !== "weapp-vite-e2e" || result?.success !== true || result.projectPath !== projectPath || typeof result.alreadyImported !== "boolean" || result.taskId !== void 0 || result.status !== void 0 || result.error !== void 0) throw new Error("DEVTOOLS_PROJECT_IMPORT_INCOMPLETE: 官方项目导入未完成;请检查本地 weapp-vite-e2e 客户端授权与导入结果,未启动项目窗口。");
|
|
65
|
+
options.signal.throwIfAborted();
|
|
66
|
+
})));
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/cli/automator/managed.ts
|
|
70
|
+
/** 受管启动持有完整窗口回执,快照始终由持久 journal 持有。 */
|
|
71
|
+
async function launchManagedAutomator(options) {
|
|
72
|
+
const { launcher, scope, target, sourceProjectPath, port } = options;
|
|
73
|
+
let projectPath = options.projectPath;
|
|
74
|
+
let portLease;
|
|
75
|
+
let intent;
|
|
76
|
+
let program;
|
|
77
|
+
let allowCleanup;
|
|
78
|
+
const acquisitionSettled = new Promise((resolve) => {
|
|
79
|
+
allowCleanup = resolve;
|
|
80
|
+
});
|
|
81
|
+
let cleaning;
|
|
82
|
+
const cleanupLaunch = () => cleaning ??= (async () => {
|
|
83
|
+
await acquisitionSettled;
|
|
84
|
+
const errors = [];
|
|
85
|
+
let disconnected = !program;
|
|
86
|
+
try {
|
|
87
|
+
await program?.disconnect();
|
|
88
|
+
disconnected = true;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
errors.push(error);
|
|
91
|
+
}
|
|
92
|
+
let projectClosed = !intent;
|
|
93
|
+
try {
|
|
94
|
+
await intent?.close();
|
|
95
|
+
projectClosed = true;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
errors.push(error);
|
|
98
|
+
}
|
|
99
|
+
if (disconnected && projectClosed) await portLease?.release().catch((error) => errors.push(error));
|
|
100
|
+
if (errors.length) throw new AggregateError(errors, "Managed DevTools session cleanup failed");
|
|
101
|
+
})().catch((error) => {
|
|
102
|
+
cleaning = void 0;
|
|
103
|
+
throw error;
|
|
104
|
+
});
|
|
105
|
+
let disownResources = () => {};
|
|
106
|
+
try {
|
|
107
|
+
disownResources = scope.own(cleanupLaunch, "managed-automator-session");
|
|
108
|
+
const snapshotPlan = options.preserveProjectRoot ? void 0 : await readAutomatorProjectPlan(projectPath);
|
|
109
|
+
scope.throwIfAborted();
|
|
110
|
+
if (snapshotPlan) {
|
|
111
|
+
intent = await beginManagedWechatProject({
|
|
112
|
+
target,
|
|
113
|
+
projectPath,
|
|
114
|
+
port,
|
|
115
|
+
snapshotProject: true
|
|
116
|
+
});
|
|
117
|
+
if (!intent) throw new Error("DEVTOOLS_MANAGED_PROJECT_JOURNAL_REQUIRED: managed launch requires a project ownership journal.");
|
|
118
|
+
projectPath = intent.projectPath;
|
|
119
|
+
await intent.prepareSnapshot(async (destination) => await populateAutomatorProjectSnapshot(snapshotPlan, destination));
|
|
120
|
+
scope.throwIfAborted();
|
|
121
|
+
}
|
|
122
|
+
await scope.step(() => importManagedDevtoolsProject({
|
|
123
|
+
cliPath: target.cliPath,
|
|
124
|
+
projectPath,
|
|
125
|
+
trusted: options.trustProject,
|
|
126
|
+
timeout: scope.remainingMs(),
|
|
127
|
+
signal: scope.signal
|
|
128
|
+
}), { stage: "project-import" });
|
|
129
|
+
scope.throwIfAborted();
|
|
130
|
+
portLease = await scope.step(() => acquireAutomatorPortLease(port), {
|
|
131
|
+
stage: "port-lease",
|
|
132
|
+
disposeLate: (lease) => lease.release()
|
|
133
|
+
});
|
|
134
|
+
const rawReleasePortLease = portLease.release.bind(portLease);
|
|
135
|
+
let releasedPortLease;
|
|
136
|
+
portLease.release = () => releasedPortLease ??= rawReleasePortLease().catch((error) => {
|
|
137
|
+
releasedPortLease = void 0;
|
|
138
|
+
throw error;
|
|
139
|
+
});
|
|
140
|
+
intent ??= await beginManagedWechatProject({
|
|
141
|
+
target,
|
|
142
|
+
projectPath,
|
|
143
|
+
port
|
|
144
|
+
});
|
|
145
|
+
if (!intent) throw new Error("DEVTOOLS_MANAGED_PROJECT_JOURNAL_REQUIRED: managed launch requires a project ownership journal.");
|
|
146
|
+
scope.throwIfAborted();
|
|
147
|
+
await startWechatIdeAgent({
|
|
148
|
+
target,
|
|
149
|
+
projectPath,
|
|
150
|
+
port,
|
|
151
|
+
trustProject: options.trustProject,
|
|
152
|
+
signal: scope.signal,
|
|
153
|
+
timeout: scope.remainingMs(),
|
|
154
|
+
...snapshotPlan ? { onBeforeDispatch: async () => await intent.markLaunchDispatched() } : {},
|
|
155
|
+
onStarted: async (result) => await intent.confirm({
|
|
156
|
+
openedProjectWindow: result.openedProjectWindow,
|
|
157
|
+
port: result.autoPort
|
|
158
|
+
})
|
|
159
|
+
});
|
|
160
|
+
scope.throwIfAborted();
|
|
161
|
+
await assertWechatDevtoolsPort(target, port, {
|
|
162
|
+
signal: scope.signal,
|
|
163
|
+
timeout: scope.remainingMs()
|
|
164
|
+
});
|
|
165
|
+
scope.throwIfAborted();
|
|
166
|
+
const wsEndpoint = `ws://127.0.0.1:${port}`;
|
|
167
|
+
program = await launcher.connect({
|
|
168
|
+
wsEndpoint,
|
|
169
|
+
signal: scope.signal,
|
|
170
|
+
timeout: scope.remainingMs()
|
|
171
|
+
});
|
|
172
|
+
scope.throwIfAborted();
|
|
173
|
+
await program.waitForAppReady(scope.remainingMs());
|
|
174
|
+
scope.throwIfAborted();
|
|
175
|
+
Reflect.set(program, "__WEAPP_VITE_SESSION_METADATA", {
|
|
176
|
+
port,
|
|
177
|
+
projectPath,
|
|
178
|
+
wsEndpoint,
|
|
179
|
+
managedProject: {
|
|
180
|
+
id: intent.id,
|
|
181
|
+
journalPath: intent.journalPath
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
await persistAutomatorSession({
|
|
185
|
+
installationId: target.installationId,
|
|
186
|
+
signal: scope.signal,
|
|
187
|
+
port,
|
|
188
|
+
projectPath: sourceProjectPath,
|
|
189
|
+
sessionId: options.sessionId,
|
|
190
|
+
wsEndpoint
|
|
191
|
+
});
|
|
192
|
+
scope.throwIfAborted();
|
|
193
|
+
if (options.persistAsDefaultSession) {
|
|
194
|
+
await persistAutomatorSession({
|
|
195
|
+
installationId: target.installationId,
|
|
196
|
+
signal: scope.signal,
|
|
197
|
+
projectPath: sourceProjectPath,
|
|
198
|
+
wsEndpoint
|
|
199
|
+
});
|
|
200
|
+
scope.throwIfAborted();
|
|
201
|
+
}
|
|
202
|
+
const connectedProgram = program;
|
|
203
|
+
const ownedIntent = intent;
|
|
204
|
+
const ownedPortLease = portLease;
|
|
205
|
+
const rawDisconnect = connectedProgram.disconnect.bind(connectedProgram);
|
|
206
|
+
let disconnecting;
|
|
207
|
+
connectedProgram.disconnect = (...args) => {
|
|
208
|
+
disconnecting ??= (async () => {
|
|
209
|
+
await rawDisconnect(...args);
|
|
210
|
+
await ownedPortLease.release();
|
|
211
|
+
})().catch((error) => {
|
|
212
|
+
disconnecting = void 0;
|
|
213
|
+
throw error;
|
|
214
|
+
});
|
|
215
|
+
return disconnecting;
|
|
216
|
+
};
|
|
217
|
+
let closing;
|
|
218
|
+
connectedProgram.close = async () => {
|
|
219
|
+
closing ??= (async () => {
|
|
220
|
+
const errors = [];
|
|
221
|
+
let disconnected = false;
|
|
222
|
+
try {
|
|
223
|
+
await connectedProgram.disconnect();
|
|
224
|
+
disconnected = true;
|
|
225
|
+
} catch (error) {
|
|
226
|
+
errors.push(error);
|
|
227
|
+
}
|
|
228
|
+
let projectClosed = false;
|
|
229
|
+
try {
|
|
230
|
+
await ownedIntent.close();
|
|
231
|
+
projectClosed = true;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
errors.push(error);
|
|
234
|
+
}
|
|
235
|
+
if (disconnected && projectClosed) await ownedPortLease.release().catch((error) => errors.push(error));
|
|
236
|
+
if (errors.length) throw new AggregateError(errors, "Managed DevTools session cleanup failed");
|
|
237
|
+
})().finally(() => {
|
|
238
|
+
closing = void 0;
|
|
239
|
+
});
|
|
240
|
+
return await closing;
|
|
241
|
+
};
|
|
242
|
+
disownResources();
|
|
243
|
+
allowCleanup();
|
|
244
|
+
return connectedProgram;
|
|
245
|
+
} catch (error) {
|
|
246
|
+
const errors = [error];
|
|
247
|
+
if (intent) try {
|
|
248
|
+
await intent.fail(error);
|
|
249
|
+
} catch (recordError) {
|
|
250
|
+
errors.push(recordError);
|
|
251
|
+
}
|
|
252
|
+
allowCleanup();
|
|
253
|
+
try {
|
|
254
|
+
await cleanupLaunch();
|
|
255
|
+
disownResources();
|
|
256
|
+
} catch (cleanupError) {
|
|
257
|
+
errors.push(...cleanupError instanceof AggregateError ? cleanupError.errors : [cleanupError]);
|
|
258
|
+
}
|
|
259
|
+
if (errors.length > 1) throw new AggregateError(errors, "Managed DevTools launch failed and project cleanup did not complete.", { cause: error });
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
//#endregion
|
|
264
|
+
export { launchManagedAutomator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as runMcpCommand } from "./run-mcp-Ni139Z5C.js";
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Buffer } from "node:buffer";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
1
|
+
import { l as withMiniProgram$1 } from "./automator-session-VOB03glx.js";
|
|
4
2
|
import path from "node:path";
|
|
5
|
-
import process from "node:process";
|
|
6
3
|
import { readDevtoolsElementSnapshot as readElementSnapshot, resolveDevtoolsProjectPath as resolveProjectPath, toDevtoolsSerializableValue as toSerializableValue } from "@weapp-vite/devtools-runtime";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { Buffer } from "node:buffer";
|
|
9
7
|
import { z } from "zod";
|
|
10
8
|
//#region src/mcp/server.ts
|
|
11
9
|
function createResolvedProjectPath(workspaceRoot, projectPath) {
|
|
@@ -16,6 +14,10 @@ function createResolvedOutputPath(workspaceRoot, outputPath) {
|
|
|
16
14
|
}
|
|
17
15
|
async function withConnectedMiniProgram(runtimeHooks, workspaceRoot, input, runner) {
|
|
18
16
|
return await runtimeHooks.withMiniProgram({
|
|
17
|
+
cliPath: input.cliPath,
|
|
18
|
+
devtoolsChannel: input.devtoolsChannel,
|
|
19
|
+
devtoolsVersion: input.devtoolsVersion,
|
|
20
|
+
requireOfficialLatest: input.requireOfficialLatest,
|
|
19
21
|
preferOpenedSession: input.preferOpenedSession,
|
|
20
22
|
port: input.port,
|
|
21
23
|
projectPath: createResolvedProjectPath(workspaceRoot, input.projectPath),
|
|
@@ -31,9 +33,17 @@ async function withConnectedPage(runtimeHooks, workspaceRoot, input, runner) {
|
|
|
31
33
|
}
|
|
32
34
|
function defineConnectionSchema() {
|
|
33
35
|
return {
|
|
36
|
+
cliPath: z.string().trim().min(1).optional().describe("指定微信开发者工具 CLI 安装路径"),
|
|
37
|
+
devtoolsChannel: z.enum([
|
|
38
|
+
"stable",
|
|
39
|
+
"rc",
|
|
40
|
+
"nightly"
|
|
41
|
+
]).optional(),
|
|
42
|
+
devtoolsVersion: z.string().regex(/^\d+(?:\.\d+){2,}$/).optional(),
|
|
43
|
+
requireOfficialLatest: z.boolean().optional(),
|
|
34
44
|
projectPath: z.string().trim().min(1).describe("小程序项目路径,支持 workspaceRoot 相对路径"),
|
|
35
45
|
timeout: z.number().int().positive().optional(),
|
|
36
|
-
port: z.number().int().positive().optional(),
|
|
46
|
+
port: z.number().int().positive().max(65535).optional(),
|
|
37
47
|
preferOpenedSession: z.boolean().optional(),
|
|
38
48
|
sessionId: z.string().trim().min(1).optional()
|
|
39
49
|
};
|
|
@@ -367,6 +377,7 @@ function registerWeappIdeMcpTools(server, options) {
|
|
|
367
377
|
});
|
|
368
378
|
}
|
|
369
379
|
async function createWeappIdeMcpServer(options) {
|
|
380
|
+
const { McpServer } = await import("@modelcontextprotocol/server");
|
|
370
381
|
const server = new McpServer({
|
|
371
382
|
name: "weapp-ide-cli",
|
|
372
383
|
version: "1.0.0"
|
|
@@ -380,8 +391,12 @@ async function createWeappIdeMcpServer(options) {
|
|
|
380
391
|
//#endregion
|
|
381
392
|
//#region src/mcp/runtime.ts
|
|
382
393
|
async function startWeappIdeMcpServer(options = {}) {
|
|
394
|
+
const { serveStdio } = await import("@modelcontextprotocol/server/stdio");
|
|
383
395
|
const serverOptions = {
|
|
384
|
-
runtimeHooks: { withMiniProgram: withMiniProgram$1
|
|
396
|
+
runtimeHooks: { withMiniProgram: (input, runner) => withMiniProgram$1({
|
|
397
|
+
...input,
|
|
398
|
+
cliPath: input.cliPath ?? options.cliPath
|
|
399
|
+
}, runner) },
|
|
385
400
|
workspaceRoot: options.workspaceRoot
|
|
386
401
|
};
|
|
387
402
|
const handle = serveStdio(async () => {
|
|
@@ -415,6 +430,7 @@ function printMcpHelp() {
|
|
|
415
430
|
Start the weapp-ide-cli MCP server over stdio.
|
|
416
431
|
|
|
417
432
|
Options:
|
|
433
|
+
--cli-path <path> Select the WeChat DevTools installation
|
|
418
434
|
--workspace-root <path> Resolve relative project/output paths from this root
|
|
419
435
|
-h, --help Show this help
|
|
420
436
|
|
|
@@ -434,7 +450,10 @@ async function runMcpCommand(argv) {
|
|
|
434
450
|
printMcpHelp();
|
|
435
451
|
return;
|
|
436
452
|
}
|
|
437
|
-
await startWeappIdeMcpServer({
|
|
453
|
+
await startWeappIdeMcpServer({
|
|
454
|
+
cliPath: readOptionValue(argv, "--cli-path"),
|
|
455
|
+
workspaceRoot: readOptionValue(argv, "--workspace-root")
|
|
456
|
+
});
|
|
438
457
|
}
|
|
439
458
|
//#endregion
|
|
440
459
|
export { readElementSnapshot as a, registerWeappIdeMcpTools as i, startWeappIdeMcpServer as n, resolveProjectPath as o, createWeappIdeMcpServer as r, toSerializableValue as s, runMcpCommand as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-ide-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.3.0",
|
|
5
5
|
"description": "Command-line tools for automating WeChat DevTools and mini-program projects.",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -64,20 +64,20 @@
|
|
|
64
64
|
"registry": "https://registry.npmjs.org"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@modelcontextprotocol/server": "^2.
|
|
68
|
-
"@weapp-core/logger": "3.1.
|
|
69
|
-
"@weapp-core/shared": "3.
|
|
70
|
-
"@weapp-vite/devtools-runtime": "0.
|
|
71
|
-
"@weapp-vite/miniprogram-automator": "1.
|
|
72
|
-
"cac": "^7.
|
|
73
|
-
"execa": "10.
|
|
67
|
+
"@modelcontextprotocol/server": "^2.3.1",
|
|
68
|
+
"@weapp-core/logger": "3.1.10",
|
|
69
|
+
"@weapp-core/shared": "3.3.0",
|
|
70
|
+
"@weapp-vite/devtools-runtime": "0.6.0",
|
|
71
|
+
"@weapp-vite/miniprogram-automator": "1.4.0",
|
|
72
|
+
"cac": "^7.1.0",
|
|
73
|
+
"execa": "10.1.1",
|
|
74
74
|
"pathe": "^2.0.3",
|
|
75
75
|
"pixelmatch": "^7.2.0",
|
|
76
76
|
"pngjs": "^7.0.0",
|
|
77
|
-
"zod": "^4.6.
|
|
77
|
+
"zod": "^4.6.7"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@types/node": "^26.6.
|
|
80
|
+
"@types/node": "^26.6.5"
|
|
81
81
|
},
|
|
82
82
|
"tsd": {
|
|
83
83
|
"compilerOptions": {
|
|
@@ -91,11 +91,12 @@
|
|
|
91
91
|
"release": "node scripts/release.js",
|
|
92
92
|
"test:dev": "vitest",
|
|
93
93
|
"test": "vitest run",
|
|
94
|
-
"test:types": "pnpm build &&
|
|
94
|
+
"test:types": "pnpm build && pnpm run test:types:check",
|
|
95
|
+
"test:types:check": "tsd --files \"test-d/**/*.test-d.ts\"",
|
|
95
96
|
"typecheck": "tsc --noEmit",
|
|
96
97
|
"weapp": "tsx src/cli.ts",
|
|
97
98
|
"debug": "tsx src/cli.ts config",
|
|
98
99
|
"raw": "node bin/weapp.js",
|
|
99
|
-
"sync": "
|
|
100
|
+
"sync": "repo release sync-npmmirror --package weapp-ide-cli"
|
|
100
101
|
}
|
|
101
102
|
}
|