dsh-plugin-update-hub 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +90 -2
- package/README.zh.md +91 -0
- package/client.js +957 -0
- package/cordis.patch.yml +3 -0
- package/icon.png +0 -0
- package/index.js +195 -0
- package/package.json +61 -3
package/cordis.patch.yml
ADDED
package/icon.png
ADDED
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, statSync } from 'node:fs'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
export const name = 'dsh-plugin-update-hub'
|
|
7
|
+
export const inject = ['webServer']
|
|
8
|
+
|
|
9
|
+
const ROUTE = '/dsh-plugin-update-hub-api'
|
|
10
|
+
const SAFE_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/i
|
|
11
|
+
|
|
12
|
+
function moduleDir() {
|
|
13
|
+
try {
|
|
14
|
+
return dirname(fileURLToPath(import.meta.url))
|
|
15
|
+
} catch (error) {
|
|
16
|
+
return process.cwd()
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isDirectory(path) {
|
|
21
|
+
try {
|
|
22
|
+
return statSync(path).isDirectory()
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A DSH profile directory keeps its installed packages in node_modules and
|
|
30
|
+
* always describes its own composition, so the marker file tells a real
|
|
31
|
+
* profile apart from the read-only installation bundle directory.
|
|
32
|
+
*/
|
|
33
|
+
function isProfileDir(dir) {
|
|
34
|
+
return isDirectory(join(dir, 'node_modules')) && existsSync(join(dir, 'cordis.patch.yml'))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function hasNodeModules(dir) {
|
|
38
|
+
return isDirectory(join(dir, 'node_modules'))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function profileCandidates() {
|
|
42
|
+
const candidates = []
|
|
43
|
+
const envProfile = process.env.DSH_PROFILE_DIR
|
|
44
|
+
if (envProfile) candidates.push(envProfile)
|
|
45
|
+
const home = process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
46
|
+
const envProfileName = process.env.DSH_PROFILE
|
|
47
|
+
if (envProfileName) candidates.push(join(home, 'profiles', envProfileName))
|
|
48
|
+
for (const arg of process.argv.slice(1)) {
|
|
49
|
+
if (!arg || arg.charAt(0) === '-' || arg.charAt(0) !== '/') continue
|
|
50
|
+
candidates.push(arg)
|
|
51
|
+
}
|
|
52
|
+
let dir = moduleDir()
|
|
53
|
+
for (let step = 0; step < 8; step += 1) {
|
|
54
|
+
candidates.push(dir)
|
|
55
|
+
const parent = dirname(dir)
|
|
56
|
+
if (parent === dir) break
|
|
57
|
+
dir = parent
|
|
58
|
+
}
|
|
59
|
+
const profilesRoot = join(home, 'profiles')
|
|
60
|
+
try {
|
|
61
|
+
for (const entry of readdirSync(profilesRoot)) {
|
|
62
|
+
if (entry.charAt(0) !== '.') candidates.push(join(profilesRoot, entry))
|
|
63
|
+
}
|
|
64
|
+
} catch (error) { /* no profiles directory */ }
|
|
65
|
+
const seen = new Set()
|
|
66
|
+
return candidates.filter((candidate) => {
|
|
67
|
+
if (seen.has(candidate)) return false
|
|
68
|
+
seen.add(candidate)
|
|
69
|
+
return true
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let resolvedProfileDir
|
|
74
|
+
|
|
75
|
+
function findProfileDir() {
|
|
76
|
+
if (resolvedProfileDir !== undefined) return resolvedProfileDir
|
|
77
|
+
const candidates = profileCandidates()
|
|
78
|
+
const strict = candidates.find((candidate) => isProfileDir(candidate))
|
|
79
|
+
if (strict !== undefined) {
|
|
80
|
+
resolvedProfileDir = strict
|
|
81
|
+
return resolvedProfileDir
|
|
82
|
+
}
|
|
83
|
+
const loose = candidates.find((candidate) => hasNodeModules(candidate))
|
|
84
|
+
resolvedProfileDir = loose
|
|
85
|
+
return resolvedProfileDir
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Installation time of one installed package: the moment its directory entry
|
|
90
|
+
* appeared inside the profile's node_modules. The entry itself is usually a
|
|
91
|
+
* pnpm symlink, so read the link's own timestamp first and only fall back to
|
|
92
|
+
* the followed target when the entry is a real directory.
|
|
93
|
+
*/
|
|
94
|
+
function installedAtOf(profileDir, packageName) {
|
|
95
|
+
const entry = join(profileDir, 'node_modules', packageName)
|
|
96
|
+
try {
|
|
97
|
+
return Math.round(lstatSync(entry).mtimeMs)
|
|
98
|
+
} catch (error) {
|
|
99
|
+
try {
|
|
100
|
+
return Math.round(statSync(join(entry, 'package.json')).mtimeMs)
|
|
101
|
+
} catch (inner) {
|
|
102
|
+
return undefined
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function listInstalled(profileDir) {
|
|
108
|
+
try {
|
|
109
|
+
return readdirSync(join(profileDir, 'node_modules')).filter((entry) => entry !== '.bin' && !entry.startsWith('.'))
|
|
110
|
+
} catch (error) {
|
|
111
|
+
return []
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Package metadata the plugin manager does not surface: the short description
|
|
117
|
+
* a publisher wrote in package.json, used as a fallback when the bundle meta
|
|
118
|
+
* carries no localized description.
|
|
119
|
+
*/
|
|
120
|
+
function packageInfo(profileDir, packageName) {
|
|
121
|
+
try {
|
|
122
|
+
const raw = readFileSync(join(profileDir, 'node_modules', packageName, 'package.json'), 'utf8')
|
|
123
|
+
const parsed = JSON.parse(raw)
|
|
124
|
+
const description = typeof parsed.description === 'string' ? parsed.description.slice(0, 400) : ''
|
|
125
|
+
const version = typeof parsed.version === 'string' ? parsed.version : ''
|
|
126
|
+
const info = {}
|
|
127
|
+
if (description) info.description = description
|
|
128
|
+
if (version) info.version = version
|
|
129
|
+
return info
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return undefined
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function collect(profileDir, requested) {
|
|
136
|
+
const names = requested && requested.length
|
|
137
|
+
? requested.filter((entry) => SAFE_NAME.test(entry))
|
|
138
|
+
: listInstalled(profileDir).flatMap((entry) => {
|
|
139
|
+
if (!entry.startsWith('@')) return [entry]
|
|
140
|
+
try {
|
|
141
|
+
return readdirSync(join(profileDir, 'node_modules', entry))
|
|
142
|
+
.filter((child) => !child.startsWith('.'))
|
|
143
|
+
.map((child) => `${entry}/${child}`)
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return []
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
const installedAt = {}
|
|
149
|
+
const info = {}
|
|
150
|
+
for (const packageName of names) {
|
|
151
|
+
const at = installedAtOf(profileDir, packageName)
|
|
152
|
+
if (at !== undefined) installedAt[packageName] = at
|
|
153
|
+
const meta = packageInfo(profileDir, packageName)
|
|
154
|
+
if (meta !== undefined && (meta.description || meta.version)) info[packageName] = meta
|
|
155
|
+
}
|
|
156
|
+
return { installedAt, info }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function respond(res, status, payload) {
|
|
160
|
+
res.writeHead(status, {
|
|
161
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
162
|
+
'Cache-Control': 'no-store',
|
|
163
|
+
})
|
|
164
|
+
res.end(JSON.stringify(payload))
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function apply(ctx) {
|
|
168
|
+
const webServer = ctx.webServer ?? ctx.get('webServer')
|
|
169
|
+
if (webServer === undefined) return
|
|
170
|
+
ctx.effect(() => webServer.register({
|
|
171
|
+
kind: 'exact',
|
|
172
|
+
path: ROUTE,
|
|
173
|
+
async handler(req, res) {
|
|
174
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
175
|
+
respond(res, 405, { error: 'method-not-allowed' })
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
const profileDir = findProfileDir()
|
|
179
|
+
if (profileDir === undefined) {
|
|
180
|
+
respond(res, 503, { error: 'profile-not-found' })
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
let requested
|
|
184
|
+
try {
|
|
185
|
+
const url = new URL(req.url ?? ROUTE, 'http://localhost')
|
|
186
|
+
const raw = url.searchParams.get('names')
|
|
187
|
+
if (raw !== null) requested = raw.split(',').map((entry) => entry.trim()).filter(Boolean)
|
|
188
|
+
} catch (error) {
|
|
189
|
+
requested = undefined
|
|
190
|
+
}
|
|
191
|
+
const collected = collect(profileDir, requested)
|
|
192
|
+
respond(res, 200, collected)
|
|
193
|
+
},
|
|
194
|
+
}))
|
|
195
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-update-hub",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "已安装插件版本中枢:一次并发检查所有插件的落后情况,展示安装时间与可升级版本,按版本批量排队升级并实时显示进度。",
|
|
5
|
+
"icon": "icon.png",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "darianzes",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/darianzes/dsh-plugin-update-hub.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/darianzes/dsh-plugin-update-hub#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/darianzes/dsh-plugin-update-hub/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "index.js",
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"client.js",
|
|
21
|
+
"cordis.patch.yml",
|
|
22
|
+
"icon.png",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"README.zh.md"
|
|
26
|
+
],
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./index.js",
|
|
29
|
+
"./client": "./client.js",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "node test/smoke.mjs"
|
|
34
|
+
},
|
|
35
|
+
"dsh": {
|
|
36
|
+
"bundle": {
|
|
37
|
+
"patch": "./cordis.patch.yml"
|
|
38
|
+
},
|
|
39
|
+
"client": {
|
|
40
|
+
"inject": [
|
|
41
|
+
"@deepseek-ai/dsh-api-remotes",
|
|
42
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
43
|
+
"@deepseek-ai/dsh-client-connection",
|
|
44
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
45
|
+
],
|
|
46
|
+
"platform": "web"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=22.13.0",
|
|
51
|
+
"dsh": ">=0.2.2-0 <0.3.0"
|
|
52
|
+
},
|
|
53
|
+
"keywords": [
|
|
54
|
+
"dsh",
|
|
55
|
+
"dsh-plugin",
|
|
56
|
+
"deepseek-harness",
|
|
57
|
+
"cordis",
|
|
58
|
+
"client-plugin",
|
|
59
|
+
"plugin-manager",
|
|
60
|
+
"update",
|
|
61
|
+
"upgrade",
|
|
62
|
+
"versions"
|
|
63
|
+
]
|
|
6
64
|
}
|