@szc-ft/mcp-szcd-client 0.19.0 → 0.19.1

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.
@@ -361,16 +361,44 @@ export class BrowserEngine {
361
361
  }
362
362
 
363
363
  /**
364
- * 动态加载 puppeteer-core
364
+ * 动态加载 puppeteer-core,缺失时自动安装
365
365
  */
366
366
  async function loadPuppeteer() {
367
+ // 首次尝试直接加载
367
368
  try {
368
369
  const mod = await import("puppeteer-core");
369
370
  return mod.default || mod;
370
- } catch (err) {
371
+ } catch {
372
+ // 未安装,尝试自动安装
373
+ }
374
+
375
+ process.stderr.write("[browser-engine] puppeteer-core 未安装,正在自动安装...\n");
376
+ const { execSync } = await import("node:child_process");
377
+
378
+ const mirrorFlag = "--sharp_binary_host=https://npmmirror.com/mirrors/sharp";
379
+ const packages = "puppeteer-core pixelmatch pngjs sharp";
380
+
381
+ try {
382
+ execSync(`npm install --no-save ${mirrorFlag} ${packages}`, {
383
+ stdio: "inherit",
384
+ timeout: 120000,
385
+ });
386
+ } catch (installErr) {
371
387
  const error = new Error(
372
- `puppeteer-core 未安装。请执行:npm install puppeteer-core\n原始错误:${err.message}`
388
+ `浏览器测试依赖安装失败。请手动执行:\n` +
389
+ ` npm install puppeteer-core pixelmatch pngjs sharp --sharp_binary_host=https://npmmirror.com/mirrors/sharp\n` +
390
+ `原始错误:${installErr.message}`
373
391
  );
392
+ error.code = "DEPENDENCY_INSTALL_FAILED";
393
+ throw error;
394
+ }
395
+
396
+ // 安装成功,重新加载
397
+ try {
398
+ const mod = await import("puppeteer-core");
399
+ return mod.default || mod;
400
+ } catch (err) {
401
+ const error = new Error(`puppeteer-core 安装后仍无法加载:${err.message}`);
374
402
  error.code = "DEPENDENCY_MISSING";
375
403
  throw error;
376
404
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@szc-ft/mcp-szcd-client",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "MCP client for szcd component library - auto-configures AI coding tools with MCP server, skills, agents and commands",
5
5
  "keywords": [
6
6
  "mcp",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "szcd-component-helper",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "szcd 组件库 MCP 助手 — 查询组件信息、匹配需求、生成代码",
5
5
  "mcpServers": {
6
6
  "szcd-component-helper": {