dsh-crossterm 0.3.36 → 0.3.37

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 (3) hide show
  1. package/lib/bus.js +1 -1
  2. package/lib/web.js +48 -9
  3. package/package.json +1 -1
package/lib/bus.js CHANGED
@@ -22,7 +22,7 @@ import os from 'node:os'
22
22
  import path from 'node:path'
23
23
  import crypto from 'node:crypto'
24
24
 
25
- export const VERSION = '0.3.36'
25
+ export const VERSION = '0.3.37'
26
26
 
27
27
  /** DSH 的家目录:与宿主其它状态(sessions / profiles)同一个根,多终端天然共享 */
28
28
  export function dshHome() {
package/lib/web.js CHANGED
@@ -147,15 +147,16 @@ function decodeOutput(buffer) {
147
147
  return text.replace(/\u001b\[[0-9;?]*[A-Za-z]/g, '').replace(/\r/g, '\n')
148
148
  }
149
149
 
150
- function run(cmd, args, cwd) {
150
+ function run(cmd, args, cwd, opts) {
151
151
  return new Promise((resolve) => {
152
152
  const chunks = []
153
153
  let size = 0
154
154
  let child
155
+ const shell = opts && typeof opts.shell === 'boolean' ? opts.shell : process.platform === 'win32'
155
156
  try {
156
157
  child = spawn(cmd, args, {
157
158
  cwd,
158
- shell: process.platform === 'win32',
159
+ shell,
159
160
  windowsHide: true,
160
161
  })
161
162
  } catch (error) {
@@ -191,6 +192,39 @@ function updateErrorText(result) {
191
192
  return tail
192
193
  }
193
194
 
195
+ // 有些机器没把 `dsh` 命令放进 PATH(桌面版就是),这时退回 DSH 自带运行时里的
196
+ // node + pnpm 直接装:<DSH_HOME>\dsh-runtimes\dsh-primary-runtime\dependencies\{node,pnpm}
197
+ function runtimeTools(cfg) {
198
+ const busDir = (cfg && cfg.busDir) || ''
199
+ const home = busDir ? path.dirname(busDir) : path.join(os.homedir(), '.dsh')
200
+ const deps = path.join(home, 'dsh-runtimes', 'dsh-primary-runtime', 'dependencies')
201
+ return {
202
+ node: path.join(deps, 'node', 'bin', 'node.exe'),
203
+ pnpm: path.join(deps, 'pnpm', 'bin', 'pnpm.cjs'),
204
+ ok:
205
+ fs.existsSync(path.join(deps, 'node', 'bin', 'node.exe')) &&
206
+ fs.existsSync(path.join(deps, 'pnpm', 'bin', 'pnpm.cjs')),
207
+ }
208
+ }
209
+
210
+ function looksMissingCommand(result) {
211
+ return /not recognized|不是内部或外部命令|无法将.{0,12}项识别|command not found|ENOENT|is not recognized/i.test(
212
+ result.out || '',
213
+ )
214
+ }
215
+
216
+ async function updatePlugin(term, info) {
217
+ const target = `${PKG}@latest`
218
+ const direct = await run('dsh', ['plugin', '--profile', info.name, 'add', target], info.dir)
219
+ if (direct.code === 0) return { ok: true, via: 'dsh', out: direct.out }
220
+ const miss = looksMissingCommand(direct) || direct.out.trim() === ''
221
+ if (!miss) return { ok: false, via: 'dsh', out: direct.out }
222
+ const tools = runtimeTools(term.cfg)
223
+ if (!tools.ok) return { ok: false, via: 'none', out: updateErrorText(direct) }
224
+ const fallback = await run(tools.node, [tools.pnpm, 'add', target], info.dir, { shell: false })
225
+ return { ok: fallback.code === 0, via: 'pnpm', out: fallback.out || updateErrorText(fallback) }
226
+ }
227
+
194
228
  function statusOf(term) {
195
229
  const cfg = term.cfg || {}
196
230
  const info = profileInfo(cfg.busDir)
@@ -352,15 +386,17 @@ export function registerWeb(ctx, term, log) {
352
386
  })
353
387
  return
354
388
  }
355
- const result = await run('dsh', ['plugin', '--profile', info.name, 'add', `${PKG}@latest`], info.dir)
389
+ const result = await updatePlugin(term, info)
356
390
  json(res, 200, {
357
- ok: result.code === 0,
391
+ ok: result.ok,
358
392
  mode: 'registry',
359
- needRestart: result.code === 0,
360
- message:
361
- result.code === 0
362
- ? '已更新,重启 DSH 后生效'
363
- : updateErrorText(result),
393
+ via: result.via,
394
+ needRestart: result.ok,
395
+ message: result.ok
396
+ ? `已更新${result.via === 'pnpm' ? '(用 DSH 自带 pnpm)' : ''},重启 DSH 后生效`
397
+ : result.via === 'none'
398
+ ? result.out
399
+ : (result.out || '').slice(-1200) || `更新失败(退出码不明)`,
364
400
  })
365
401
  },
366
402
  }),
@@ -382,3 +418,6 @@ export function registerWeb(ctx, term, log) {
382
418
  if (typeof log === 'function') log(`web 路由注册失败:${(error && error.message) || error}`)
383
419
  }
384
420
  }
421
+
422
+ // 只给探针用:把内部小工具导出来,宿主运行时不依赖这些导出
423
+ export { decodeOutput, runtimeTools, looksMissingCommand, updateErrorText }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-crossterm",
3
- "version": "0.3.36",
3
+ "version": "0.3.37",
4
4
  "description": "DSH 跨终端互联:同一账号下的多个 DSH 终端/进程互发邮件与文件(主题内联、正文落盘,收件方自己读)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",