@mrrisega/dsh-remote 0.3.5 → 0.3.7

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.
Files changed (2) hide show
  1. package/dsh-setup.mjs +46 -56
  2. package/package.json +1 -1
package/dsh-setup.mjs CHANGED
@@ -469,14 +469,22 @@ async function setup(argv) {
469
469
  // ---------- plugin:安装/卸载 dsh web 远程控制插件 ----------
470
470
  const PLUGIN_MARKER_START = "# >>> dsh-remote-ui (managed by dsh-remote plugin; do not edit)";
471
471
  const PLUGIN_MARKER_END = "# <<< dsh-remote-ui";
472
- /** 插件在 profile 内的固定本地目录(安装时整目录拷贝,file: 引用;不依赖 pnpm 的 link:)。 */
472
+ /** 插件在 profile 内的固定本地目录(安装时整目录拷贝;include 直接指向其入口文件)。 */
473
473
  const PLUGIN_LOCAL_DIR = "dsh-remote-ui-plugin";
474
+ /** 插件 node 半入口(相对 profile 目录;加载器按 '.' 开头在配置文件旁解析)。 */
475
+ const PLUGIN_ENTRY_REL = `./${PLUGIN_LOCAL_DIR}/lib/index.js`;
474
476
 
477
+ /**
478
+ * include 块。v0.3.7 起 name 直接用「相对文件路径」指向已拷贝的插件入口:
479
+ * dsh 加载器对 '.' 开头的 name 会在配置文件(profile)目录旁解析并 import 该文件,
480
+ * 完全不经过 pnpm/npm/node_modules —— 任何机器装完即用,包管理器成不成功都不影响。
481
+ * (已用隔离 HOME + 独立端口真实启动 dsh web 验证:/dsh-remote/* 路由正常注册。)
482
+ */
475
483
  function pluginBlock(relayDir) {
476
484
  return `${PLUGIN_MARKER_START}
477
485
  - insert:
478
486
  - id: dsh-remote-ui
479
- name: 'dsh-remote-ui'
487
+ name: '${PLUGIN_ENTRY_REL}'
480
488
  config:
481
489
  relayDir: '${relayDir}'
482
490
  ${PLUGIN_MARKER_END}`;
@@ -529,19 +537,10 @@ function normalizePatchBase(patch) {
529
537
  .trimEnd();
530
538
  }
531
539
 
532
- /** 在 profile 目录执行依赖安装(pnpm 优先,npm 兜底)。 */
533
- function installProfileDeps(profileDir) {
534
- const pm = sh("command -v pnpm >/dev/null 2>&1 && echo pnpm || echo npm").stdout.trim() || "npm";
535
- const cmd = pm === "pnpm" ? "pnpm install" : "npm install";
536
- return sh(cmd, 120000, profileDir);
537
- }
538
-
539
540
  /**
540
541
  * 把插件整目录拷贝进 profile 的固定子目录并返回该目录。
541
- * 之所以拷贝而不是 link: 引用 npx 缓存目录:
542
- * - link: 协议只有 pnpm 支持,npm 会报 EUNSUPPORTEDPROTOCOL(很多用户机器没装 pnpm);
543
- * - npx 缓存目录是临时的,link 目标迟早失效。
544
- * 拷贝后用 file: 相对依赖即可,npm/pnpm 都能解析。
542
+ * 源(本包 packages/dsh-remote-ui)可能在 npx 临时缓存里,因此必须拷到 profile 内持久化,
543
+ * include 用相对路径直接指向拷贝出的入口,不写依赖、不跑任何包管理器。
545
544
  */
546
545
  function copyPluginIntoProfile(profileDir, pluginDir) {
547
546
  const dest = path.join(profileDir, PLUGIN_LOCAL_DIR);
@@ -557,26 +556,26 @@ function copyPluginIntoProfile(profileDir, pluginDir) {
557
556
  }
558
557
 
559
558
  /**
560
- * 兜底:确保 dsh 能从 profile 的 node_modules 解析到 dsh-remote-ui。
561
- * 部分机器上 pnpm/npm 可能因网络、锁文件或旧 node_modules 布局没真正放下链接,
562
- * 导致 dsh web 启动报 "Cannot find package 'dsh-remote-ui'"。这里直接自建链接/拷贝,
563
- * 保证“装完就能用”,不依赖包管理器的成败。返回 true 表示本次补建了链接。
559
+ * 清理 v0.3.0~0.3.6 旧机制的残留(避免与新 include 并存造成困惑/冲突):
560
+ * - package.json link:/file: dsh-remote-ui 依赖;
561
+ * - node_modules 里的 dsh-remote-ui 链接/目录。
564
562
  */
565
- function ensurePluginLinked(profileDir, pluginLocalDir) {
566
- const nmPlugin = path.join(profileDir, "node_modules", "dsh-remote-ui");
567
- if (fs.existsSync(nmPlugin)) return false; // 已可解析(含目标仍有效的软链)
563
+ function cleanupLegacyPluginState(profileDir, pkgFile) {
564
+ let changed = false;
568
565
  try {
569
- fs.mkdirSync(path.join(profileDir, "node_modules"), { recursive: true });
570
- fs.symlinkSync(pluginLocalDir, nmPlugin, "dir");
571
- return true;
572
- } catch {
573
- try {
574
- fs.cpSync(pluginLocalDir, nmPlugin, { recursive: true });
575
- return true;
576
- } catch {
577
- return false;
566
+ const pkg = JSON.parse(fs.readFileSync(pkgFile, "utf8"));
567
+ if (pkg.dependencies && pkg.dependencies["dsh-remote-ui"]) {
568
+ delete pkg.dependencies["dsh-remote-ui"];
569
+ fs.writeFileSync(pkgFile, JSON.stringify(pkg, null, 2) + "\n");
570
+ changed = true;
578
571
  }
579
- }
572
+ } catch { /* 无 package.json 或损坏则跳过 */ }
573
+ try {
574
+ const legacy = path.join(profileDir, "node_modules", "dsh-remote-ui");
575
+ fs.rmSync(legacy, { recursive: true, force: true });
576
+ // 顺手清理可能因旧依赖产生的空 node_modules 不影响 dsh
577
+ } catch { /* ignore */ }
578
+ return changed;
580
579
  }
581
580
 
582
581
  async function pluginCmd(argv) {
@@ -600,7 +599,6 @@ async function pluginCmd(argv) {
600
599
  }
601
600
 
602
601
  const patch = fs.readFileSync(patchFile, "utf8");
603
- const pkg = JSON.parse(fs.readFileSync(pkgFile, "utf8"));
604
602
 
605
603
  if (uninstall) {
606
604
  // 移除 patch 中的插件条目(兼容旧版无标记条目)
@@ -611,25 +609,22 @@ async function pluginCmd(argv) {
611
609
  } else {
612
610
  console.log("ℹ patch 中未发现 dsh-remote-ui 条目。");
613
611
  }
614
- if (pkg.dependencies && pkg.dependencies["dsh-remote-ui"]) {
615
- delete pkg.dependencies["dsh-remote-ui"];
616
- fs.writeFileSync(pkgFile, JSON.stringify(pkg, null, 2) + "\n");
617
- fs.rmSync(path.join(profileDir, PLUGIN_LOCAL_DIR), { recursive: true, force: true });
618
- console.log(`✅ 已从 ${pkgFile} 移除 dsh-remote-ui 依赖与本地插件目录`);
619
- }
620
- console.log(" 执行依赖更新...");
621
- const r = installProfileDeps(profileDir);
622
- if (!r.ok) console.warn(`⚠️ 依赖更新失败:${r.stderr.trim() || r.stdout.trim()}(请手动在 ${profileDir} 执行 pnpm/npm install)`);
612
+ fs.rmSync(path.join(profileDir, PLUGIN_LOCAL_DIR), { recursive: true, force: true });
613
+ console.log(`✅ 已删除本地插件目录 ${path.join(profileDir, PLUGIN_LOCAL_DIR)}`);
614
+ cleanupLegacyPluginState(profileDir, pkgFile);
623
615
  console.log("✅ 卸载完成。重启 dsh web 生效。");
624
616
  return;
625
617
  }
626
618
 
627
- // 安装:插件整目录拷贝进 profile,以 file: 相对依赖安装(npm/pnpm 均支持;不再用 link:)。
628
- pkg.dependencies = pkg.dependencies || {};
619
+ // 安装:整目录拷贝插件 + 写相对路径 include。不写 package.json 依赖、不跑 pnpm/npm,
620
+ // 不依赖 node_modules —— dsh 加载器按 name 的 './' 相对路径直接 import 入口文件。
629
621
  const pluginLocalDir = copyPluginIntoProfile(profileDir, pluginDir);
630
- pkg.dependencies["dsh-remote-ui"] = `file:./${PLUGIN_LOCAL_DIR}`;
631
- fs.writeFileSync(pkgFile, JSON.stringify(pkg, null, 2) + "\n");
632
- console.log(`✅ 插件已拷贝到 ${pluginLocalDir}(file: 依赖,npm/pnpm 均可安装)`);
622
+ const entryFile = path.join(pluginLocalDir, "lib", "index.js");
623
+ if (!fs.existsSync(entryFile)) {
624
+ console.error(`❌ 插件入口缺失:${entryFile}(本包不完整?)`);
625
+ process.exit(1);
626
+ }
627
+ console.log(`✅ 插件已拷贝到 ${pluginLocalDir}(include 直接指向其入口,无需 pnpm/npm)`);
633
628
 
634
629
  // 先清掉旧条目(含旧版无标记条目),再写入带标记的新块,保证不重复。
635
630
  // 关键:先清除默认的 [] 空文档占位行,否则拼接出的 YAML 非法,dsh web 启动即崩。
@@ -637,18 +632,13 @@ async function pluginCmd(argv) {
637
632
  const base = normalizePatchBase(stripped);
638
633
  const block = pluginBlock(CONFIG_DIR);
639
634
  fs.writeFileSync(patchFile, (base ? base + "\n" : "") + block + "\n");
640
- console.log(`✅ 已写入 ${patchFile}`);
641
- console.log(" 执行依赖更新(pnpm 优先,未装 pnpm 自动用 npm)...");
642
- const r = installProfileDeps(profileDir);
643
- if (!r.ok) {
644
- console.warn(`⚠️ 包管理器依赖更新未完全成功(${(r.stderr || r.stdout || "").trim().slice(0, 300) || "未知错误"})`);
645
- console.warn(" 将直接建立插件链接,不依赖包管理器,dsh web 仍可正常加载插件。");
635
+ console.log(`✅ 已写入 ${patchFile}(name: ${PLUGIN_ENTRY_REL})`);
636
+
637
+ // 清理 v0.3.0~0.3.6 旧机制的残留(file:/link: 依赖与 node_modules 链接)
638
+ if (cleanupLegacyPluginState(profileDir, pkgFile)) {
639
+ console.log("✅ 已清理旧版写入 package.json dsh-remote-ui 依赖与 node_modules 链接");
646
640
  }
647
- // 兜底:不依赖 pnpm/npm 的成败,确保 node_modules 里能解析到 dsh-remote-ui
648
- const linked = ensurePluginLinked(profileDir, pluginLocalDir);
649
- console.log(linked
650
- ? `✅ 插件链接已就绪:${path.join(profileDir, "node_modules", "dsh-remote-ui")} → ${pluginLocalDir}`
651
- : "✅ 插件依赖已就绪");
641
+
652
642
  console.log(`✅ 插件安装完成。配置目录: ${CONFIG_DIR}`);
653
643
  console.log(" 重启 dsh web(或重开 profile)后,在「设置 → 远程控制」查看面板。");
654
644
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrrisega/dsh-remote",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "手机远程控制 DeepSeek Harness · Remote control DeepSeek Harness (dsh web) from any phone browser — 100% 全功能 App 级体验:发消息、看工具执行、审批权限、改设置、管凭据,含特权操作,免内网穿透。一条命令安装 npx @mrrisega/dsh-remote。Mobile remote control for DSH, self-host or SaaS, no server needed on LAN.",
5
5
  "keywords": [
6
6
  "deepseek-harness",