dsh-maoying 0.1.3 → 0.1.4
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/docs/design.md +1 -1
- package/index.mjs +26 -0
- package/package.json +1 -1
package/docs/design.md
CHANGED
package/index.mjs
CHANGED
|
@@ -198,6 +198,32 @@ export function hostRejectsInlineDelegation(version) {
|
|
|
198
198
|
|
|
199
199
|
/** 宿主包版本:从 <home>/node_modules require('@deepseek-ai/dsh/package.json')。 */
|
|
200
200
|
export function readHostVersion(dshHome) {
|
|
201
|
+
// ① 运行入口锚定(最真):argv[1] 是宿主自己的入口脚本——CLI 下是
|
|
202
|
+
// @deepseek-ai/dsh 包里的 bin/入口,桌面应用下是 app.asar/dsh 内的入口
|
|
203
|
+
// (Electron 主进程的 fs 能透读 asar)。向上找最近的 @deepseek-ai/dsh
|
|
204
|
+
// package.json,读到的就是当前进程真实版本。home 全局安装的版本可能
|
|
205
|
+
// 陈旧(例如 CLI 升级前留下的 rc.7),绝不能只信它。
|
|
206
|
+
try {
|
|
207
|
+
let dir = path.dirname(path.resolve(process.argv?.[1] ?? ''))
|
|
208
|
+
for (let i = 0; i < 8 && dir && dir !== path.dirname(dir); i++, dir = path.dirname(dir)) {
|
|
209
|
+
const pkgPath = path.join(dir, 'package.json')
|
|
210
|
+
if (!existsSync(pkgPath)) continue
|
|
211
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
212
|
+
if (pkg?.name === '@deepseek-ai/dsh' && typeof pkg.version === 'string' && pkg.version !== '') {
|
|
213
|
+
return pkg.version
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
} catch { /* 入口缺失或不可读时落下一档 */ }
|
|
217
|
+
// ② Electron 主进程:桌面应用版本即其内置 dsh 的版本。纯 Node 下 require
|
|
218
|
+
// ('electron') 得到的是路径字符串(或直接找不到),类型守卫天然挡掉。
|
|
219
|
+
try {
|
|
220
|
+
const electron = createRequire(import.meta.url)('electron')
|
|
221
|
+
if (electron && typeof electron === 'object' && typeof electron.app?.getVersion === 'function') {
|
|
222
|
+
const v = electron.app.getVersion()
|
|
223
|
+
if (typeof v === 'string' && v !== '') return v
|
|
224
|
+
}
|
|
225
|
+
} catch { /* 非 Electron 环境常态 */ }
|
|
226
|
+
// ③ 兜底:home 全局安装(老 CLI 链路;可能陈旧,只在①②都拿不到时兜底)
|
|
201
227
|
try {
|
|
202
228
|
const req = createRequire(path.join(dshHome, 'node_modules', 'package.json'))
|
|
203
229
|
const pkg = req('@deepseek-ai/dsh/package.json')
|