weapp-vite 6.14.0 → 6.14.2

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 CHANGED
@@ -209,7 +209,21 @@ wv ide preview --project ./dist/build/mp-weixin
209
209
  `weapp-vite` 已集成 `@weapp-vite/mcp`:
210
210
 
211
211
  - 默认不自动启动 MCP 服务(可通过配置开启自动启动)
212
- - 也可以手动启动 MCP Server
212
+ - 优先推荐直接生成客户端配置,而不是手写 MCP 地址
213
+
214
+ ```sh
215
+ wv mcp init codex
216
+ wv mcp init claude-code
217
+ wv mcp init cursor
218
+ ```
219
+
220
+ 检查配置是否可用:
221
+
222
+ ```sh
223
+ wv mcp doctor codex
224
+ ```
225
+
226
+ 仍然需要手动启动 MCP Server 时:
213
227
 
214
228
  ```sh
215
229
  weapp-vite mcp
@@ -1,2 +1,2 @@
1
- import { a as ExternalMetadataFileCandidates, c as Resolver, d as ResolverObject, f as ResolverSupportFilesStrategy, i as CreateResolver, l as ResolverFn, n as VantResolver, o as Options, r as TDesignResolver, s as ResolvedValue, t as WeuiResolver, u as ResolverMeta } from "../index-hN5mdpQ_.mjs";
1
+ import { a as ExternalMetadataFileCandidates, c as Resolver, d as ResolverObject, f as ResolverSupportFilesStrategy, i as CreateResolver, l as ResolverFn, n as VantResolver, o as Options, r as TDesignResolver, s as ResolvedValue, t as WeuiResolver, u as ResolverMeta } from "../index-6QUk3Zbc.mjs";
2
2
  export { CreateResolver, ExternalMetadataFileCandidates, Options, ResolvedValue, Resolver, ResolverFn, ResolverMeta, ResolverObject, ResolverSupportFilesStrategy, TDesignResolver, VantResolver, WeuiResolver };
@@ -109,6 +109,7 @@ const TDesignResolver = (opts) => {
109
109
  }, {});
110
110
  return {
111
111
  components: Object.freeze({ ...map }),
112
+ componentLookupStrategy: "static",
112
113
  supportFilesStrategy,
113
114
  resolve(componentName) {
114
115
  const from = map[componentName];
@@ -241,6 +242,7 @@ const VantResolver = (opts) => {
241
242
  }, {});
242
243
  return {
243
244
  components: Object.freeze({ ...map }),
245
+ componentLookupStrategy: "static",
244
246
  supportFilesStrategy,
245
247
  resolve(componentName) {
246
248
  const from = map[componentName];
@@ -311,6 +313,7 @@ const WeuiResolver = (opts) => {
311
313
  }, {});
312
314
  return {
313
315
  components: Object.freeze({ ...map }),
316
+ componentLookupStrategy: "static",
314
317
  supportFilesStrategy,
315
318
  resolve(componentName) {
316
319
  const from = map[componentName];
@@ -1,4 +1,4 @@
1
- import { i as getCompilerContext, u as getRouteRuntimeGlobalKeys } from "./createContext-BolxgJjC.mjs";
1
+ import { i as getCompilerContext, u as getRouteRuntimeGlobalKeys } from "./createContext-utz68GiW.mjs";
2
2
  //#region src/auto-routes.ts
3
3
  const ROUTE_RUNTIME_OVERRIDE_KEY = Symbol.for("weapp-vite.route-runtime");
4
4
  function createGetter(resolver) {
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { S as isPathInside, _ as DEFAULT_MP_PLATFORM, b as resolveMiniPlatform, c as createSharedBuildConfig, d as resolveWeappConfigFile, f as checkRuntime, g as createCjsConfigLoadError, h as parseCommentJson, l as SHARED_CHUNK_VIRTUAL_PREFIX, m as loadViteConfigFile, n as syncProjectSupportFiles, p as getProjectConfigFileName, r as syncManagedTsconfigBootstrapFiles, s as formatBytes, t as createCompilerContext, v as getDefaultIdeProjectRoot, x as shouldPassPlatformArgToIdeOpen, y as normalizeMiniPlatform } from "./createContext-BolxgJjC.mjs";
1
+ import { S as isPathInside, _ as DEFAULT_MP_PLATFORM, b as resolveMiniPlatform, c as createSharedBuildConfig, d as resolveWeappConfigFile, f as checkRuntime, g as createCjsConfigLoadError, h as parseCommentJson, l as SHARED_CHUNK_VIRTUAL_PREFIX, m as loadViteConfigFile, n as syncProjectSupportFiles, p as getProjectConfigFileName, r as syncManagedTsconfigBootstrapFiles, s as formatBytes, t as createCompilerContext, v as getDefaultIdeProjectRoot, x as shouldPassPlatformArgToIdeOpen, y as normalizeMiniPlatform } from "./createContext-utz68GiW.mjs";
2
2
  import { r as logger_default, t as colors } from "./logger-CgxdNjvb.mjs";
3
- import { m as VERSION } from "./file-Ej-4GoYg.mjs";
3
+ import { m as VERSION } from "./file-PUFdKeUd.mjs";
4
4
  import { a as resolveWeappMcpConfig, o as startWeappViteMcpServer } from "./mcp-DRlj32v4.mjs";
5
5
  import { createRequire } from "node:module";
6
6
  import { defu, fs } from "@weapp-core/shared";
@@ -8,6 +8,7 @@ import path, { posix } from "pathe";
8
8
  import process from "node:process";
9
9
  import fs$1 from "node:fs/promises";
10
10
  import { build, createServer } from "vite";
11
+ import os from "node:os";
11
12
  import { execFile } from "node:child_process";
12
13
  import { Buffer } from "node:buffer";
13
14
  import fs$2 from "node:fs";
@@ -18,6 +19,8 @@ import { closeSharedMiniProgram, connectOpenedAutomator, formatRetryHotkeyPrompt
18
19
  import { generateJs, generateJson, generateWxml, generateWxss } from "@weapp-core/schematics";
19
20
  import { determineAgent } from "@vercel/detect-agent";
20
21
  import { initConfig } from "@weapp-core/init";
22
+ import { createInterface } from "node:readline/promises";
23
+ import { clearTimeout, setTimeout as setTimeout$1 } from "node:timers";
21
24
  import { emitKeypressEvents } from "node:readline";
22
25
  //#region src/analyze/subpackages/classifier.ts
23
26
  const VIRTUAL_MODULE_INDICATOR = "\0";
@@ -1133,7 +1136,10 @@ function registerBuildCommand(cli) {
1133
1136
  configFile,
1134
1137
  inlineConfig,
1135
1138
  cliPlatform: targets.rawPlatform,
1136
- projectConfigPath: options.projectConfig
1139
+ projectConfigPath: options.projectConfig,
1140
+ emitDefaultAutoImportOutputs: false,
1141
+ syncSupportFiles: false,
1142
+ preloadAppEntry: false
1137
1143
  });
1138
1144
  const { buildService, configService, webService } = ctx;
1139
1145
  logRuntimeTarget(targets, { resolvedConfigPlatform: configService.platform });
@@ -1604,6 +1610,278 @@ function registerInitCommand(cli) {
1604
1610
  });
1605
1611
  }
1606
1612
  //#endregion
1613
+ //#region src/cli/mcpClient.ts
1614
+ const CODEX_BLOCK_PREFIX = "# >>> weapp-vite mcp ";
1615
+ const CODEX_BLOCK_SUFFIX = " >>>";
1616
+ const CODEX_BLOCK_END_PREFIX = "# <<< weapp-vite mcp ";
1617
+ const CODEX_BLOCK_END_SUFFIX = " <<<";
1618
+ const DEFAULT_HTTP_TIMEOUT_MS = 1500;
1619
+ const WORKSPACE_FOLDER_TOKEN = "${workspaceFolder}";
1620
+ const REG_CodexUrl = /^\s*url\s*=\s*"([^"]+)"/m;
1621
+ const REG_CodexCommand = /^\s*command\s*=\s*"([^"]+)"/m;
1622
+ const REG_CodexArgs = /^\s*args\s*=\s*\[([^\]]*)\]/m;
1623
+ const REG_FirstTomlString = /"([^"]+)"/;
1624
+ function resolveTargetWorkspaceRoot(target) {
1625
+ if (target.client === "cursor") return path.dirname(path.dirname(target.configPath));
1626
+ if (target.client === "claude-code") return path.dirname(target.configPath);
1627
+ return process.cwd();
1628
+ }
1629
+ function escapeRegExp(value) {
1630
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1631
+ }
1632
+ function renderTomlString(value) {
1633
+ return JSON.stringify(value);
1634
+ }
1635
+ function sanitizeServerNameSegment(value) {
1636
+ return value.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/-{2,}/g, "-").replace(/^-|-$/g, "");
1637
+ }
1638
+ function resolveServerName(workspaceRoot) {
1639
+ return `weapp-vite-${sanitizeServerNameSegment(path.basename(workspaceRoot)) || "project"}`;
1640
+ }
1641
+ function resolveNodeBinCommand() {
1642
+ return process.execPath || "node";
1643
+ }
1644
+ function resolveProjectCliBin(workspaceRoot) {
1645
+ return path.join(workspaceRoot, "node_modules", "weapp-vite", "bin", "weapp-vite.js");
1646
+ }
1647
+ function renderCommandArgs(args) {
1648
+ return args.map(renderTomlString).join(", ");
1649
+ }
1650
+ function renderCodexBlock(serverName, entry) {
1651
+ const startMarker = `${CODEX_BLOCK_PREFIX}${serverName}${CODEX_BLOCK_SUFFIX}`;
1652
+ const endMarker = `${CODEX_BLOCK_END_PREFIX}${serverName}${CODEX_BLOCK_END_SUFFIX}`;
1653
+ if (entry.url) return `${startMarker}
1654
+ [mcp_servers.${serverName}]
1655
+ url = ${renderTomlString(entry.url)}
1656
+ ${endMarker}
1657
+ `;
1658
+ return `${startMarker}
1659
+ [mcp_servers.${serverName}]
1660
+ command = ${renderTomlString(entry.command ?? resolveNodeBinCommand())}
1661
+ args = [${renderCommandArgs(entry.args ?? [])}]
1662
+ ${endMarker}
1663
+ `;
1664
+ }
1665
+ function renderJsonPreview(serverName, entry) {
1666
+ return `${JSON.stringify({ mcpServers: { [serverName]: entry } }, null, 2)}
1667
+ `;
1668
+ }
1669
+ function resolveCommandEntry(client, workspaceRoot) {
1670
+ const binPath = resolveProjectCliBin(workspaceRoot);
1671
+ if (client === "cursor") return {
1672
+ command: "node",
1673
+ args: [
1674
+ `${WORKSPACE_FOLDER_TOKEN}/node_modules/weapp-vite/bin/weapp-vite.js`,
1675
+ "mcp",
1676
+ "--workspace-root",
1677
+ WORKSPACE_FOLDER_TOKEN
1678
+ ]
1679
+ };
1680
+ return {
1681
+ command: resolveNodeBinCommand(),
1682
+ args: [
1683
+ binPath,
1684
+ "mcp",
1685
+ "--workspace-root",
1686
+ workspaceRoot
1687
+ ]
1688
+ };
1689
+ }
1690
+ function resolveHttpEntry(client, url) {
1691
+ if (client === "claude-code") return {
1692
+ type: "http",
1693
+ url
1694
+ };
1695
+ return { url };
1696
+ }
1697
+ function resolveCodexBlockPattern(serverName) {
1698
+ const startMarker = `${CODEX_BLOCK_PREFIX}${serverName}${CODEX_BLOCK_SUFFIX}`;
1699
+ const endMarker = `${CODEX_BLOCK_END_PREFIX}${serverName}${CODEX_BLOCK_END_SUFFIX}`;
1700
+ return new RegExp(`${escapeRegExp(startMarker)}[\\s\\S]*?${escapeRegExp(endMarker)}\\n?`, "g");
1701
+ }
1702
+ function upsertCodexManagedBlock(content, serverName, block) {
1703
+ const withoutExisting = content.trimEnd().replace(resolveCodexBlockPattern(serverName), "").trimEnd();
1704
+ if (!withoutExisting) return block;
1705
+ return `${withoutExisting}\n\n${block}`;
1706
+ }
1707
+ function parseJsonConfig(content, configPath) {
1708
+ if (!content.trim()) return {};
1709
+ try {
1710
+ return JSON.parse(content);
1711
+ } catch (error) {
1712
+ const message = error instanceof Error ? error.message : String(error);
1713
+ throw new Error(`无法解析 MCP 配置文件 ${configPath}:${message}`);
1714
+ }
1715
+ }
1716
+ function resolveTarget(client, workspaceRoot) {
1717
+ const serverName = resolveServerName(workspaceRoot);
1718
+ if (client === "codex") return {
1719
+ client,
1720
+ configPath: path.join(os.homedir(), ".codex", "config.toml"),
1721
+ displayName: "Codex",
1722
+ serverName
1723
+ };
1724
+ if (client === "claude-code") return {
1725
+ client,
1726
+ configPath: path.join(workspaceRoot, ".mcp.json"),
1727
+ displayName: "Claude Code",
1728
+ serverName
1729
+ };
1730
+ return {
1731
+ client,
1732
+ configPath: path.join(workspaceRoot, ".cursor", "mcp.json"),
1733
+ displayName: "Cursor",
1734
+ serverName
1735
+ };
1736
+ }
1737
+ function resolveSupportedMcpClient(input) {
1738
+ if (input === "codex" || input === "claude-code" || input === "cursor") return input;
1739
+ throw new Error(`不支持的 MCP 客户端:${input}。当前仅支持 codex、claude-code、cursor。`);
1740
+ }
1741
+ function buildMcpClientConfigPlan(options) {
1742
+ const workspaceRoot = path.resolve(options.workspaceRoot);
1743
+ const target = resolveTarget(options.client, workspaceRoot);
1744
+ const entry = options.transport === "http" ? resolveHttpEntry(options.client, options.url ?? "") : resolveCommandEntry(options.client, workspaceRoot);
1745
+ if (options.transport === "http" && !entry.url) throw new Error("HTTP 模式缺少 MCP 服务地址,请使用 --url 指定或在当前项目中检测到可用地址。");
1746
+ return {
1747
+ entry,
1748
+ preview: target.client === "codex" ? renderCodexBlock(target.serverName, entry) : renderJsonPreview(target.serverName, entry),
1749
+ target,
1750
+ transport: options.transport
1751
+ };
1752
+ }
1753
+ async function writeMcpClientConfig(plan) {
1754
+ await fs.ensureDir(path.dirname(plan.target.configPath));
1755
+ const existing = await fs.readFile(plan.target.configPath, "utf8").catch(() => "");
1756
+ if (plan.target.client === "codex") {
1757
+ const nextContent = upsertCodexManagedBlock(existing, plan.target.serverName, plan.preview);
1758
+ await fs.writeFile(plan.target.configPath, nextContent, "utf8");
1759
+ return;
1760
+ }
1761
+ const parsed = parseJsonConfig(existing, plan.target.configPath);
1762
+ const nextConfig = {
1763
+ ...parsed,
1764
+ mcpServers: {
1765
+ ...parsed.mcpServers ?? {},
1766
+ [plan.target.serverName]: plan.entry
1767
+ }
1768
+ };
1769
+ await fs.writeFile(plan.target.configPath, `${JSON.stringify(nextConfig, null, 2)}\n`, "utf8");
1770
+ }
1771
+ async function probeHttpEndpoint(url) {
1772
+ const controller = new AbortController();
1773
+ const timer = setTimeout$1(() => {
1774
+ controller.abort();
1775
+ }, DEFAULT_HTTP_TIMEOUT_MS);
1776
+ try {
1777
+ return (await fetch(url, {
1778
+ method: "GET",
1779
+ signal: controller.signal
1780
+ })).status > 0;
1781
+ } catch {
1782
+ return false;
1783
+ } finally {
1784
+ clearTimeout(timer);
1785
+ controller.abort();
1786
+ }
1787
+ }
1788
+ async function inspectJsonConfig(target) {
1789
+ if (!await fs.pathExists(target.configPath)) return {
1790
+ configExists: false,
1791
+ configPath: target.configPath,
1792
+ displayName: target.displayName,
1793
+ issues: [`未找到配置文件:${target.configPath}`],
1794
+ serverName: target.serverName
1795
+ };
1796
+ const entry = parseJsonConfig(await fs.readFile(target.configPath, "utf8"), target.configPath).mcpServers?.[target.serverName];
1797
+ if (!entry) return {
1798
+ configExists: true,
1799
+ configPath: target.configPath,
1800
+ displayName: target.displayName,
1801
+ issues: [`配置文件中未找到服务器 ${target.serverName}`],
1802
+ serverName: target.serverName
1803
+ };
1804
+ const transport = entry.url ? "http" : "command";
1805
+ const issues = [];
1806
+ let httpReachable;
1807
+ if (transport === "command") {
1808
+ const normalizedBin = (entry.args?.[0])?.replaceAll(WORKSPACE_FOLDER_TOKEN, resolveTargetWorkspaceRoot(target));
1809
+ if (!normalizedBin || !await fs.pathExists(normalizedBin)) issues.push(`未找到本地 CLI 入口:${normalizedBin ?? "缺少 args[0]"}`);
1810
+ } else if (entry.url) {
1811
+ httpReachable = await probeHttpEndpoint(entry.url);
1812
+ if (!httpReachable) issues.push(`HTTP MCP 地址不可达:${entry.url}`);
1813
+ }
1814
+ return {
1815
+ configExists: true,
1816
+ configPath: target.configPath,
1817
+ displayName: target.displayName,
1818
+ httpReachable,
1819
+ issues,
1820
+ serverName: target.serverName,
1821
+ transport
1822
+ };
1823
+ }
1824
+ async function inspectCodexConfig(target) {
1825
+ if (!await fs.pathExists(target.configPath)) return {
1826
+ configExists: false,
1827
+ configPath: target.configPath,
1828
+ displayName: target.displayName,
1829
+ issues: [`未找到配置文件:${target.configPath}`],
1830
+ serverName: target.serverName
1831
+ };
1832
+ const blockMatch = (await fs.readFile(target.configPath, "utf8")).match(resolveCodexBlockPattern(target.serverName));
1833
+ if (!blockMatch?.[0]) return {
1834
+ configExists: true,
1835
+ configPath: target.configPath,
1836
+ displayName: target.displayName,
1837
+ issues: [`未找到 weapp-vite 生成的 Codex 配置区块:${target.serverName}`],
1838
+ serverName: target.serverName
1839
+ };
1840
+ const block = blockMatch[0];
1841
+ const issues = [];
1842
+ const urlMatch = block.match(REG_CodexUrl);
1843
+ const commandMatch = block.match(REG_CodexCommand);
1844
+ const argsMatch = block.match(REG_CodexArgs);
1845
+ if (urlMatch?.[1]) {
1846
+ const reachable = await probeHttpEndpoint(urlMatch[1]);
1847
+ if (!reachable) issues.push(`HTTP MCP 地址不可达:${urlMatch[1]}`);
1848
+ return {
1849
+ configExists: true,
1850
+ configPath: target.configPath,
1851
+ displayName: target.displayName,
1852
+ httpReachable: reachable,
1853
+ issues,
1854
+ serverName: target.serverName,
1855
+ transport: "http"
1856
+ };
1857
+ }
1858
+ const binPath = (argsMatch?.[1]?.match(REG_FirstTomlString))?.[1];
1859
+ if (!commandMatch?.[1]) issues.push("Codex 配置区块缺少 command 字段");
1860
+ if (!binPath || !await fs.pathExists(binPath)) issues.push(`未找到本地 CLI 入口:${binPath ?? "缺少 args[0]"}`);
1861
+ return {
1862
+ configExists: true,
1863
+ configPath: target.configPath,
1864
+ displayName: target.displayName,
1865
+ issues,
1866
+ serverName: target.serverName,
1867
+ transport: "command"
1868
+ };
1869
+ }
1870
+ async function inspectMcpClientConfig(options) {
1871
+ const target = resolveTarget(options.client, path.resolve(options.workspaceRoot));
1872
+ if (target.client === "codex") return await inspectCodexConfig(target);
1873
+ return await inspectJsonConfig(target);
1874
+ }
1875
+ function formatMcpQuickStart(options) {
1876
+ const suffix = options.transport === "http" && options.httpUrl ? ` --transport http --url ${options.httpUrl}` : "";
1877
+ return [
1878
+ "在 AI 工具中接入 weapp-vite MCP:",
1879
+ ` - Codex: wv mcp init codex${suffix}`,
1880
+ ` - Claude Code: wv mcp init claude-code${suffix}`,
1881
+ ` - Cursor: wv mcp init cursor${suffix}`
1882
+ ];
1883
+ }
1884
+ //#endregion
1607
1885
  //#region src/cli/commands/mcp.ts
1608
1886
  function resolvePort(port) {
1609
1887
  if (typeof port === "number" && Number.isInteger(port)) return port;
@@ -1612,17 +1890,109 @@ function resolvePort(port) {
1612
1890
  if (Number.isInteger(parsed)) return parsed;
1613
1891
  }
1614
1892
  }
1893
+ async function resolveHttpUrl(options) {
1894
+ if (options.url?.trim()) return options.url.trim();
1895
+ const workspaceRoot = options.workspaceRoot ? path.resolve(options.workspaceRoot) : process.cwd();
1896
+ const originalCwd = process.cwd();
1897
+ try {
1898
+ if (workspaceRoot !== originalCwd) process.chdir(workspaceRoot);
1899
+ const resolved = resolveWeappMcpConfig((await loadConfig(resolveConfigFile(options)))?.config?.weapp?.mcp);
1900
+ return `http://${resolved.host}:${resolved.port}${resolved.endpoint}`;
1901
+ } catch {
1902
+ const resolved = resolveWeappMcpConfig(void 0);
1903
+ return `http://${resolved.host}:${resolved.port}${resolved.endpoint}`;
1904
+ } finally {
1905
+ if (process.cwd() !== originalCwd) process.chdir(originalCwd);
1906
+ }
1907
+ }
1908
+ async function confirmWrite() {
1909
+ if (!process.stdin.isTTY || !process.stdout.isTTY) return false;
1910
+ const rl = createInterface({
1911
+ input: process.stdin,
1912
+ output: process.stdout
1913
+ });
1914
+ try {
1915
+ const normalized = (await rl.question("是否写入配置文件?(Y/n) ")).trim().toLowerCase();
1916
+ return normalized === "" || normalized === "y" || normalized === "yes";
1917
+ } finally {
1918
+ rl.close();
1919
+ }
1920
+ }
1921
+ function resolveClientTransport(transport) {
1922
+ return transport === "http" ? "http" : "command";
1923
+ }
1924
+ async function handlePrint(clientName, options, write = false) {
1925
+ const client = resolveSupportedMcpClient(clientName);
1926
+ const workspaceRoot = options.workspaceRoot ?? process.cwd();
1927
+ const transport = resolveClientTransport(options.transport);
1928
+ const plan = buildMcpClientConfigPlan({
1929
+ client,
1930
+ transport,
1931
+ url: transport === "http" ? await resolveHttpUrl(options) : void 0,
1932
+ workspaceRoot
1933
+ });
1934
+ logger_default.info(`${plan.target.displayName} 配置文件:${plan.target.configPath}`);
1935
+ logger_default.info(`服务器名称:${plan.target.serverName}`);
1936
+ process.stdout.write(`${plan.preview}\n`);
1937
+ if (!write) return;
1938
+ if (options.yes || await confirmWrite()) {
1939
+ await writeMcpClientConfig(plan);
1940
+ logger_default.success(`已写入 ${plan.target.displayName} MCP 配置。`);
1941
+ logger_default.info(`请重启 ${plan.target.displayName},然后执行:wv mcp doctor ${client}`);
1942
+ return;
1943
+ }
1944
+ logger_default.info("已取消写入。");
1945
+ }
1946
+ async function handleDoctor(clientName, options) {
1947
+ const result = await inspectMcpClientConfig({
1948
+ client: resolveSupportedMcpClient(clientName),
1949
+ workspaceRoot: options.workspaceRoot ?? process.cwd()
1950
+ });
1951
+ logger_default.info(`${result.displayName} 配置文件:${result.configPath}`);
1952
+ logger_default.info(`服务器名称:${result.serverName}`);
1953
+ if (!result.configExists || result.issues.length > 0) {
1954
+ for (const issue of result.issues) logger_default.warn(issue);
1955
+ throw new Error("MCP 客户端配置检查未通过。");
1956
+ }
1957
+ if (result.transport) logger_default.info(`传输模式:${result.transport}`);
1958
+ if (result.httpReachable !== void 0) logger_default.info(`HTTP 服务可达:${result.httpReachable ? "是" : "否"}`);
1959
+ logger_default.success("MCP 客户端配置检查通过。");
1960
+ }
1961
+ async function handleServer(options) {
1962
+ const resolvedTransport = options.transport === "http" ? "streamable-http" : options.transport;
1963
+ await startWeappViteMcpServer({
1964
+ endpoint: options.endpoint,
1965
+ host: options.host,
1966
+ port: resolvePort(options.port),
1967
+ transport: resolvedTransport,
1968
+ unref: options.unref,
1969
+ workspaceRoot: options.workspaceRoot
1970
+ });
1971
+ for (const line of formatMcpQuickStart({
1972
+ httpUrl: resolvedTransport === "streamable-http" ? `http://${options.host ?? "127.0.0.1"}:${resolvePort(options.port) ?? 3088}${options.endpoint ?? "/mcp"}` : void 0,
1973
+ transport: resolvedTransport === "streamable-http" ? "http" : "command"
1974
+ })) logger_default.info(line);
1975
+ }
1615
1976
  function registerMcpCommand(cli) {
1616
- cli.command("mcp", "start weapp-vite MCP server").option("--transport <type>", "[string] stdio | streamable-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("--unref", "[boolean] unref HTTP server to not block process exit").option("--workspace-root <path>", "[string] workspace root path, defaults to auto detect from cwd").action(async (options) => {
1617
- const { startWeappViteMcpServer } = await import("./mcp.mjs");
1618
- await startWeappViteMcpServer({
1619
- endpoint: options.endpoint,
1620
- host: options.host,
1621
- port: resolvePort(options.port),
1622
- transport: options.transport,
1623
- unref: options.unref,
1624
- workspaceRoot: options.workspaceRoot
1625
- });
1977
+ 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("--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) => {
1978
+ const [subcommand, client] = args;
1979
+ if (subcommand === "init") {
1980
+ if (!client) throw new Error("缺少客户端名称,请使用:wv mcp init <codex|claude-code|cursor>");
1981
+ await handlePrint(client, options, true);
1982
+ return;
1983
+ }
1984
+ if (subcommand === "print") {
1985
+ if (!client) throw new Error("缺少客户端名称,请使用:wv mcp print <codex|claude-code|cursor>");
1986
+ await handlePrint(client, options, false);
1987
+ return;
1988
+ }
1989
+ if (subcommand === "doctor") {
1990
+ if (!client) throw new Error("缺少客户端名称,请使用:wv mcp doctor <codex|claude-code|cursor>");
1991
+ await handleDoctor(client, options);
1992
+ return;
1993
+ }
1994
+ if (subcommand) throw new Error(`未知的 mcp 子命令:${subcommand}`);
1995
+ await handleServer(options);
1626
1996
  });
1627
1997
  }
1628
1998
  //#endregion
@@ -1682,10 +2052,10 @@ function registerPrepareCommand(cli) {
1682
2052
  }
1683
2053
  //#endregion
1684
2054
  //#region package.json
1685
- var version = "6.14.0";
2055
+ var version = "6.14.2";
1686
2056
  //#endregion
1687
2057
  //#region src/cli/devHotkeys.ts
1688
- const DEV_SCREENSHOT_DIR = ".tmp/weapp-vite-dev-screenshots";
2058
+ const DEV_SCREENSHOT_DIR = ".weapp-vite/dev-screenshots";
1689
2059
  const DEFAULT_SCREENSHOT_TIMEOUT = 3e4;
1690
2060
  const REG_PENDING_PREFIX = /^正在/;
1691
2061
  const FULLWIDTH_ASCII_START = 65281;
@@ -1917,6 +2287,10 @@ function startDevHotkeys(options) {
1917
2287
  workspaceRoot: options.cwd
1918
2288
  });
1919
2289
  logger_default.success(`[dev action] MCP 服务已启动:${colors.cyan(url)}`);
2290
+ for (const line of formatMcpQuickStart({
2291
+ httpUrl: url,
2292
+ transport: "http"
2293
+ })) logger_default.info(line);
1920
2294
  return `MCP 已启动 (${url})`;
1921
2295
  };
1922
2296
  const runAction = (label, pendingLabel, action) => {
@@ -2467,6 +2841,10 @@ async function maybeAutoStartMcpServer(argv, cliOptions) {
2467
2841
  const mcpUrl = `http://${resolvedMcp.host}:${resolvedMcp.port}${resolvedMcp.endpoint}`;
2468
2842
  logger_default.success("MCP 服务已自动启动:");
2469
2843
  logger_default.info(` ➜ ${colors.cyan(mcpUrl)}`);
2844
+ for (const line of formatMcpQuickStart({
2845
+ httpUrl: mcpUrl,
2846
+ transport: "http"
2847
+ })) logger_default.info(line);
2470
2848
  } catch (error) {
2471
2849
  const message = error instanceof Error ? error.message : String(error);
2472
2850
  if (REG_EADDRINUSE.test(message)) {
@@ -1,4 +1,4 @@
1
- import { c as Resolver, s as ResolvedValue } from "./index-hN5mdpQ_.mjs";
1
+ import { c as Resolver, s as ResolvedValue } from "./index-6QUk3Zbc.mjs";
2
2
  import { t as AutoRoutes } from "./routes-DiEBrMtj.mjs";
3
3
  import { LRUCache } from "lru-cache";
4
4
  import { LoggerConfig } from "@weapp-core/logger";
@@ -351,6 +351,7 @@ interface ScanWxmlOptions {
351
351
  * @description WXML 处理阶段配置
352
352
  */
353
353
  interface HandleWxmlOptions {
354
+ defineImportMetaEnv?: Record<string, any>;
354
355
  removeComment?: boolean;
355
356
  transformEvent?: boolean;
356
357
  scriptModuleExtension?: string;
@@ -413,7 +414,7 @@ interface WeappInjectWeapiConfig {
413
414
  replaceWx?: boolean;
414
415
  globalName?: string;
415
416
  }
416
- type WeappInjectRequestGlobalsTarget = 'fetch' | 'Headers' | 'Request' | 'Response' | 'AbortController' | 'AbortSignal' | 'XMLHttpRequest';
417
+ type WeappInjectRequestGlobalsTarget = 'fetch' | 'Headers' | 'Request' | 'Response' | 'AbortController' | 'AbortSignal' | 'XMLHttpRequest' | 'WebSocket';
417
418
  /**
418
419
  * @description 请求相关全局对象注入配置
419
420
  */
@@ -1022,6 +1023,7 @@ interface LoadConfigOptions {
1022
1023
  cwd: string;
1023
1024
  isDev: boolean;
1024
1025
  mode: string;
1026
+ emitDefaultAutoImportOutputs?: boolean;
1025
1027
  pluginOnly?: boolean;
1026
1028
  inlineConfig?: InlineConfig;
1027
1029
  configFile?: string;
@@ -1037,6 +1039,7 @@ interface LoadConfigResult {
1037
1039
  cwd: string;
1038
1040
  isDev: boolean;
1039
1041
  mode: string;
1042
+ emitDefaultAutoImportOutputs: boolean;
1040
1043
  chunksConfigured?: boolean;
1041
1044
  projectConfig: Record<string, any>;
1042
1045
  projectConfigPath?: string;
@@ -1085,6 +1088,7 @@ interface ConfigService {
1085
1088
  readonly defineImportMetaEnv: Record<string, any>;
1086
1089
  readonly cwd: string;
1087
1090
  readonly isDev: boolean;
1091
+ readonly emitDefaultAutoImportOutputs: boolean;
1088
1092
  readonly mpDistRoot: string;
1089
1093
  readonly outDir: string;
1090
1094
  readonly inlineConfig: InlineConfig;
@@ -1202,7 +1206,18 @@ interface RemovalRange {
1202
1206
  end: number;
1203
1207
  }
1204
1208
  interface WxmlToken {
1209
+ /**
1210
+ * @description 参与常规组件分析的标签集合。
1211
+ * 会应用 `excludeComponent` 过滤,通常会排除宿主内置组件,
1212
+ * 供原有的 `usingComponents` 推断与模板依赖聚合使用。
1213
+ */
1205
1214
  components: ComponentsMap;
1215
+ /**
1216
+ * @description 供自动导入使用的完整标签集合。
1217
+ * 不会因为“这是宿主内置组件名”而被提前过滤,
1218
+ * 用来支持“本地组件与内置组件重名时仍优先命中用户组件”的场景。
1219
+ */
1220
+ autoImportComponents?: ComponentsMap;
1206
1221
  deps: WxmlDep[];
1207
1222
  removalRanges: RemovalRange[];
1208
1223
  commentTokens: Token[];
@@ -1269,6 +1284,7 @@ interface RuntimeState {
1269
1284
  resolvedResolverComponents: Map<string, string>;
1270
1285
  matcher?: (input: string) => boolean;
1271
1286
  matcherKey: string;
1287
+ version: number;
1272
1288
  };
1273
1289
  build: {
1274
1290
  queue: PQueue;
@@ -1279,10 +1295,15 @@ interface RuntimeState {
1279
1295
  };
1280
1296
  json: {
1281
1297
  cache: FileCache<any>;
1298
+ emittedSource: Map<string, string>;
1299
+ };
1300
+ asset: {
1301
+ emittedBuffer: Map<string, Buffer>;
1282
1302
  };
1283
1303
  css: {
1284
1304
  importerToDependencies: Map<string, Set<string>>;
1285
1305
  dependencyToImporters: Map<string, Set<string>>;
1306
+ emittedSource: Map<string, string>;
1286
1307
  };
1287
1308
  watcher: {
1288
1309
  rollupWatcherMap: Map<string, WatcherInstance>;
@@ -1293,6 +1314,8 @@ interface RuntimeState {
1293
1314
  importerMap: Map<string, Set<string>>;
1294
1315
  tokenMap: Map<string, ScanWxmlResult>;
1295
1316
  componentsMap: Map<string, ComponentsMap>;
1317
+ aggregatedComponentsMap: Map<string, ComponentsMap>;
1318
+ templatePathMap: Map<string, string>;
1296
1319
  cache: FileCache<ScanWxmlResult>;
1297
1320
  emittedCode: Map<string, string>;
1298
1321
  };
@@ -1359,12 +1382,23 @@ interface WxmlService {
1359
1382
  depsMap: Map<string, Set<string>>;
1360
1383
  importerMap: Map<string, Set<string>>;
1361
1384
  tokenMap: Map<string, ScanWxmlResult>;
1385
+ /**
1386
+ * @description 常规组件索引缓存。
1387
+ * 这里沿用历史行为,只保留“应参与 usingComponents 推断”的组件标签。
1388
+ */
1362
1389
  wxmlComponentsMap: Map<string, ComponentsMap>;
1390
+ /**
1391
+ * @description 常规组件聚合缓存。
1392
+ * 会递归合并 import/include 进来的模板组件,但仍遵循内置组件过滤规则。
1393
+ */
1394
+ aggregatedComponentsMap: Map<string, ComponentsMap>;
1363
1395
  addDeps: (filepath: string, deps?: string[]) => Promise<void>;
1364
1396
  setDeps: (filepath: string, deps?: string[]) => Promise<void>;
1365
1397
  collectDepsFromToken: (filepath: string, deps?: ScanWxmlResult['deps']) => string[];
1366
1398
  getImporters: (filepath: string) => Set<string>;
1367
1399
  getAllDeps: () => Set<string>;
1400
+ getAggregatedComponents: (filepathOrBaseName: string) => ComponentsMap | undefined;
1401
+ getAggregatedAutoImportComponents: (filepathOrBaseName: string) => ComponentsMap | undefined;
1368
1402
  clearAll: () => void;
1369
1403
  analyze: (wxml: string) => ScanWxmlResult;
1370
1404
  scan: (filepath: string) => Promise<ScanWxmlResult | undefined>;
@@ -1379,6 +1413,8 @@ interface ResolverAutoImportMatch {
1379
1413
  type AutoImportMatch = LocalAutoImportMatch | ResolverAutoImportMatch;
1380
1414
  interface AutoImportService {
1381
1415
  reset: () => void;
1416
+ getVersion: () => number;
1417
+ runInBatch: <T>(task: () => T | Promise<T>) => Promise<T>;
1382
1418
  registerPotentialComponent: (filePath: string) => Promise<void>;
1383
1419
  removePotentialComponent: (filePath: string) => void;
1384
1420
  resolve: (componentName: string, importerBaseName?: string) => AutoImportMatch | undefined;
package/dist/config.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { An as createWeappViteHostMeta, Dn as WeappViteHostMeta, En as WEAPP_VITE_HOST_NAME, Mn as resolveWeappViteHostMeta, On as WeappViteRuntime, _ as definePageJson, a as UserConfigFnNoEnvPlain, c as UserConfigFnPromise, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, jn as isWeappViteHost, kn as applyWeappViteHostMeta, l as defineConfig, m as Theme, n as UserConfigExport, nt as WeappViteConfig, o as UserConfigFnObject, p as Sitemap, r as UserConfigFn, s as UserConfigFnObjectPlain, t as UserConfig, u as App, v as defineSitemapJson, y as defineThemeJson } from "./config-bkgtM4wZ.mjs";
1
+ import { An as createWeappViteHostMeta, Dn as WeappViteHostMeta, En as WEAPP_VITE_HOST_NAME, Mn as resolveWeappViteHostMeta, On as WeappViteRuntime, _ as definePageJson, a as UserConfigFnNoEnvPlain, c as UserConfigFnPromise, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, jn as isWeappViteHost, kn as applyWeappViteHostMeta, l as defineConfig, m as Theme, n as UserConfigExport, nt as WeappViteConfig, o as UserConfigFnObject, p as Sitemap, r as UserConfigFn, s as UserConfigFnObjectPlain, t as UserConfig, u as App, v as defineSitemapJson, y as defineThemeJson } from "./config-BHVrIbhx.mjs";
2
2
  export { App, Component, Page, Sitemap, Theme, UserConfig, UserConfigExport, UserConfigFn, UserConfigFnNoEnv, UserConfigFnNoEnvPlain, UserConfigFnObject, UserConfigFnObjectPlain, UserConfigFnPromise, WEAPP_VITE_HOST_NAME, WeappViteConfig, WeappViteHostMeta, WeappViteRuntime, applyWeappViteHostMeta, createWeappViteHostMeta, defineAppJson, defineComponentJson, defineConfig, definePageJson, defineSitemapJson, defineThemeJson, isWeappViteHost, resolveWeappViteHostMeta };
package/dist/config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as defineThemeJson, i as defineSitemapJson, n as defineComponentJson, r as definePageJson, t as defineAppJson } from "./json-D0HkutE0.mjs";
2
- import { a as resolveWeappViteHostMeta, i as isWeappViteHost, n as applyWeappViteHostMeta, r as createWeappViteHostMeta, t as WEAPP_VITE_HOST_NAME } from "./pluginHost-SJdl15d3.mjs";
3
- import { t as defineConfig } from "./config-DJjSbpNX.mjs";
1
+ import { a as defineThemeJson, i as defineSitemapJson, n as defineComponentJson, r as definePageJson, t as defineAppJson } from "./json-wnfVS9jE.mjs";
2
+ import { a as resolveWeappViteHostMeta, i as isWeappViteHost, n as applyWeappViteHostMeta, r as createWeappViteHostMeta, t as WEAPP_VITE_HOST_NAME } from "./pluginHost-BzPJL4F-.mjs";
3
+ import { t as defineConfig } from "./config-B2xtjEug.mjs";
4
4
  export { WEAPP_VITE_HOST_NAME, applyWeappViteHostMeta, createWeappViteHostMeta, defineAppJson, defineComponentJson, defineConfig, definePageJson, defineSitemapJson, defineThemeJson, isWeappViteHost, resolveWeappViteHostMeta };