@ssamurias/dsh-fish 1.1.0 → 1.1.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.
- package/AGENTS.md +371 -368
- package/CHANGELOG.md +36 -0
- package/README.md +390 -377
- package/RELEASE-NOTES-1.1.1.md +61 -0
- package/docs/troubleshooting.md +4 -4
- package/docs//350/256/244/344/272/272/345/210/244/346/215/256.md +19 -5
- package/lib/bridgeclaim.js +138 -0
- package/lib/claim.js +118 -11
- package/lib/client/06-tab-status-grow.js +12 -1
- package/lib/client/11-tab-data-frame.js +3 -1
- package/lib/client.js +15 -2
- package/lib/identity.js +38 -20
- package/lib/index.js +9 -4
- package/lib/observe-home.js +58 -3
- package/lib/observe.js +8 -2
- package/lib/proactive.js +11 -0
- package/lib/restrict.js +58 -18
- package/lib/settings.js +20 -0
- package/lib/tenant.js +21 -4
- package/lib/types.d.ts +2 -0
- package/lib/use.js +3 -3
- package/lib/wiki.js +7 -0
- package/package.json +1 -1
- package/scripts/build-client.mjs +15 -1
- package/tools/check-install.mjs +64 -23
package/tools/check-install.mjs
CHANGED
|
@@ -15,9 +15,28 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
|
15
15
|
import { homedir } from 'node:os'
|
|
16
16
|
import { join, posix, resolve } from 'node:path'
|
|
17
17
|
|
|
18
|
-
export const PKG_NAME = 'dsh-fish'
|
|
18
|
+
export const PKG_NAME = '@ssamurias/dsh-fish'
|
|
19
|
+
// 改名(0.8.10)之前的裸名。老 profile 里留下的还是它,认它只为把「装的是哪条鱼」查清楚。
|
|
20
|
+
const LEGACY_NAMES = ['dsh-fish']
|
|
19
21
|
const DEP_FIELDS = ['dependencies', 'devDependencies', 'optionalDependencies']
|
|
20
22
|
|
|
23
|
+
/** 这个脚本自己所属的包名:跟着 package.json 走,以后再改名不用回来改这里。 */
|
|
24
|
+
export function ownName() {
|
|
25
|
+
try {
|
|
26
|
+
const name = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))?.name
|
|
27
|
+
if (typeof name === 'string' && name.trim()) return name.trim()
|
|
28
|
+
} catch {
|
|
29
|
+
// 落在只拷贝了 tools/ 的地方时读不到,用默认值
|
|
30
|
+
}
|
|
31
|
+
return PKG_NAME
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 认哪些依赖键:自己的名字优先,再认改名前的裸名。 */
|
|
35
|
+
export function pkgNames() {
|
|
36
|
+
const own = ownName()
|
|
37
|
+
return LEGACY_NAMES.includes(own) ? [own] : [own, ...LEGACY_NAMES]
|
|
38
|
+
}
|
|
39
|
+
|
|
21
40
|
/** 形如 `D:/x`、`D:\x`、`\\server\share` 的 Windows 绝对路径 */
|
|
22
41
|
function isWinAbs(p) {
|
|
23
42
|
return /^[A-Za-z]:[\\/]/.test(p) || /^\\\\/.test(p)
|
|
@@ -48,19 +67,31 @@ export function parseFileDep(spec, profileDir) {
|
|
|
48
67
|
return resolve(profileDir, raw)
|
|
49
68
|
}
|
|
50
69
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
70
|
+
/**
|
|
71
|
+
* 从 package.json 文本里找出这个包是哪条依赖。
|
|
72
|
+
* 返回 {name, dep}:name 是命中的依赖键(决定 node_modules 里的副本在哪),dep 是写法。
|
|
73
|
+
* 坏 JSON 返回 null;没装这个包返回 {name:'', dep:''}。
|
|
74
|
+
*/
|
|
75
|
+
export function readDepEntry(text) {
|
|
53
76
|
let pkg
|
|
54
77
|
try {
|
|
55
78
|
pkg = JSON.parse(text)
|
|
56
79
|
} catch {
|
|
57
80
|
return null
|
|
58
81
|
}
|
|
59
|
-
for (const
|
|
60
|
-
const
|
|
61
|
-
|
|
82
|
+
for (const name of pkgNames()) {
|
|
83
|
+
for (const f of DEP_FIELDS) {
|
|
84
|
+
const v = pkg?.[f]?.[name]
|
|
85
|
+
if (typeof v === 'string') return { name, dep: v }
|
|
86
|
+
}
|
|
62
87
|
}
|
|
63
|
-
return ''
|
|
88
|
+
return { name: '', dep: '' }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** 从 package.json 文本里取依赖写法;坏 JSON 返回 null,没装返回空串。 */
|
|
92
|
+
export function readDep(text) {
|
|
93
|
+
const entry = readDepEntry(text)
|
|
94
|
+
return entry === null ? null : entry.dep
|
|
64
95
|
}
|
|
65
96
|
|
|
66
97
|
/** 读一个目录里 package.json 的版本号;读不到返回 ''。 */
|
|
@@ -95,16 +126,17 @@ export function countJs(dir) {
|
|
|
95
126
|
|
|
96
127
|
/**
|
|
97
128
|
* 查一个 profile。
|
|
98
|
-
* 返回 {profile, source, sourceVersion, copy, copyVersion, sourceJs, copyJs, verdict, why}
|
|
99
|
-
* verdict: ok | empty-copy | stale-copy | no-dep | no-profile
|
|
129
|
+
* 返回 {profile, pkgName, source, sourceVersion, copy, copyVersion, sourceJs, copyJs, verdict, why}
|
|
130
|
+
* verdict: ok | linked | empty-copy | stale-copy | no-dep | no-profile
|
|
100
131
|
*/
|
|
101
132
|
export function inspectProfile(profileDir) {
|
|
102
133
|
const pkgFile = join(profileDir, 'package.json')
|
|
103
134
|
const out = {
|
|
104
135
|
profile: profileDir,
|
|
136
|
+
pkgName: '',
|
|
105
137
|
source: '',
|
|
106
138
|
sourceVersion: '',
|
|
107
|
-
copy:
|
|
139
|
+
copy: '',
|
|
108
140
|
copyVersion: '',
|
|
109
141
|
sourceJs: 0,
|
|
110
142
|
copyJs: 0,
|
|
@@ -122,19 +154,25 @@ export function inspectProfile(profileDir) {
|
|
|
122
154
|
out.why = `package.json 读不了:${err?.message ?? err}`
|
|
123
155
|
return out
|
|
124
156
|
}
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
157
|
+
const entry = readDepEntry(text)
|
|
158
|
+
if (entry === null) {
|
|
127
159
|
out.why = 'package.json 不是合法 JSON'
|
|
128
160
|
return out
|
|
129
161
|
}
|
|
130
|
-
if (!dep) {
|
|
162
|
+
if (!entry.dep) {
|
|
131
163
|
out.verdict = 'no-dep'
|
|
132
|
-
out.why =
|
|
164
|
+
out.why = `profile 的 dependencies 里没有 ${pkgNames().join(' 或 ')}`
|
|
133
165
|
return out
|
|
134
166
|
}
|
|
167
|
+
const dep = entry.dep
|
|
168
|
+
out.pkgName = entry.name
|
|
169
|
+
// 副本按**命中的依赖键**拼:带 scope 的包落在 node_modules/@scope/name,
|
|
170
|
+
// 不能拿短名去猜(0.8.10 改名后这里一直指着一个不存在的路径)。
|
|
171
|
+
out.copy = join(profileDir, 'node_modules', entry.name)
|
|
135
172
|
out.verdict = 'no-dep'
|
|
136
173
|
out.why = `依赖写法是 ${dep}`
|
|
137
174
|
if (dep.startsWith('link:')) {
|
|
175
|
+
out.verdict = 'linked'
|
|
138
176
|
out.why = `依赖写法是 ${dep}(软链安装,没有副本,不需要比对)`
|
|
139
177
|
return out
|
|
140
178
|
}
|
|
@@ -151,10 +189,10 @@ export function inspectProfile(profileDir) {
|
|
|
151
189
|
|
|
152
190
|
if (!existsSync(out.copy)) {
|
|
153
191
|
out.verdict = 'empty-copy'
|
|
154
|
-
out.why =
|
|
192
|
+
out.why = `node_modules 里没有 ${entry.name}:pnpm 根本没装成功`
|
|
155
193
|
} else if (!out.copyVersion) {
|
|
156
194
|
out.verdict = 'empty-copy'
|
|
157
|
-
out.why =
|
|
195
|
+
out.why = `node_modules/${entry.name} 里没有能读的 package.json:副本是空的或只落了一半`
|
|
158
196
|
} else if (out.copyJs < out.sourceJs * 0.8) {
|
|
159
197
|
out.verdict = 'empty-copy'
|
|
160
198
|
out.why = `副本只有 ${out.copyJs} 个 js 文件,源目录有 ${out.sourceJs} 个:装了一半`
|
|
@@ -168,7 +206,7 @@ export function inspectProfile(profileDir) {
|
|
|
168
206
|
return out
|
|
169
207
|
}
|
|
170
208
|
|
|
171
|
-
/** 找出一个 DSH_HOME
|
|
209
|
+
/** 找出一个 DSH_HOME 下所有装过这个包的 profile。 */
|
|
172
210
|
export function findProfiles(home = join(homedir(), '.dsh')) {
|
|
173
211
|
const root = join(home, 'profiles')
|
|
174
212
|
if (!existsSync(root)) return []
|
|
@@ -181,14 +219,15 @@ export function findProfiles(home = join(homedir(), '.dsh')) {
|
|
|
181
219
|
continue
|
|
182
220
|
}
|
|
183
221
|
if (!existsSync(join(dir, 'package.json'))) continue
|
|
184
|
-
const
|
|
185
|
-
if (dep) out.push(dir)
|
|
222
|
+
const entry = readDepEntry(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
223
|
+
if (entry?.dep) out.push(dir)
|
|
186
224
|
}
|
|
187
225
|
return out
|
|
188
226
|
}
|
|
189
227
|
|
|
190
228
|
const LABEL = {
|
|
191
229
|
ok: '正常',
|
|
230
|
+
linked: '软链安装(不需要比对副本)',
|
|
192
231
|
'stale-copy': '装的是旧副本',
|
|
193
232
|
'empty-copy': '副本空的/装了一半',
|
|
194
233
|
'no-dep': '不是这套装法',
|
|
@@ -202,16 +241,17 @@ export function main(argv = process.argv.slice(2)) {
|
|
|
202
241
|
}
|
|
203
242
|
const home = arg('home', join(homedir(), '.dsh'))
|
|
204
243
|
const only = arg('profile', '').toLowerCase()
|
|
244
|
+
const names = pkgNames().join(' 或 ')
|
|
205
245
|
let dirs = findProfiles(home)
|
|
206
246
|
if (only) {
|
|
207
247
|
dirs = dirs.filter((d) => d.split(/[\\/]/).pop().toLowerCase() === only)
|
|
208
248
|
if (!dirs.length) {
|
|
209
|
-
console.error(`在 ${home} 里没找到 profile「${only}」,或者它没装
|
|
249
|
+
console.error(`在 ${home} 里没找到 profile「${only}」,或者它没装 ${names}`)
|
|
210
250
|
return 2
|
|
211
251
|
}
|
|
212
252
|
}
|
|
213
253
|
if (!dirs.length) {
|
|
214
|
-
console.error(`在 ${home}\\profiles 里没找到任何装过
|
|
254
|
+
console.error(`在 ${home}\\profiles 里没找到任何装过 ${names} 的 profile`)
|
|
215
255
|
return 2
|
|
216
256
|
}
|
|
217
257
|
|
|
@@ -221,11 +261,12 @@ export function main(argv = process.argv.slice(2)) {
|
|
|
221
261
|
const name = dir.split(/[\\/]/).pop()
|
|
222
262
|
console.log(`\n[${name}] ${LABEL[r.verdict] ?? r.verdict}`)
|
|
223
263
|
if (r.source) console.log(` 源目录 ${r.source}`)
|
|
224
|
-
if (r.copy) console.log(` 实际跑 ${r.copy}`)
|
|
264
|
+
if (r.copy && existsSync(r.copy)) console.log(` 实际跑 ${r.copy}`)
|
|
225
265
|
console.log(` 说明 ${r.why}`)
|
|
226
266
|
if (r.verdict === 'empty-copy' || r.verdict === 'stale-copy') {
|
|
227
267
|
bad += 1
|
|
228
|
-
|
|
268
|
+
const rel = `node_modules/${r.pkgName || ownName()}`
|
|
269
|
+
console.log(` 修法 关掉 DSH → 在 profile 目录里 pnpm install --force(或删掉 ${rel})→ 再启动`)
|
|
229
270
|
}
|
|
230
271
|
}
|
|
231
272
|
console.log(bad ? '\n有问题:上面标出来的那几条按「修法」重装一次。' : '\n看着没问题。')
|