dsh-modpack-kit 0.1.1 → 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/README.md +92 -9
- package/assets/icon-180.png +0 -0
- package/assets/install-stub.cmd +15 -0
- package/assets/install-stub.mjs +299 -0
- package/assets/install-stub.sh +9 -0
- package/client.js +827 -58
- package/docs/DETAIL.md +47 -1
- package/index.js +591 -69
- package/lib/install.mjs +102 -40
- package/lib/manifest.mjs +20 -10
- package/lib/pack.mjs +90 -12
- package/lib/scan.mjs +47 -0
- package/lib/store.mjs +10 -2
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +4 -3
package/lib/install.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import fs from 'node:fs'
|
|
9
9
|
import path from 'node:path'
|
|
10
10
|
import { readZip, readZipText, safeEntryName } from './zip.mjs'
|
|
11
|
-
import { scanEntries, renderScanReport } from './scan.mjs'
|
|
11
|
+
import { scanEntries, renderScanReport, groupFindings } from './scan.mjs'
|
|
12
12
|
import { MANIFEST_NAME, normalizeManifest, sha256 } from './manifest.mjs'
|
|
13
13
|
import { checkCompatibility } from './compat.mjs'
|
|
14
14
|
import { captureConfigs, collectFiles } from './pack.mjs'
|
|
@@ -105,11 +105,19 @@ export function inspectPackBuffer(buffer, options = {}) {
|
|
|
105
105
|
if (integrity.present && !integrity.ok) {
|
|
106
106
|
blockingReasons.push('完整性校验失败(' + (integrity.mismatches.length + integrity.missing.length) + ' 个文件对不上)')
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
// 打包方已确认(市场收录插件的确认放行)时,不再用高风险拦人;报告照常列明细。
|
|
109
|
+
const acknowledged = Boolean(manifest.security && (manifest.security.acknowledged === true || manifest.security.trustedOnly === true))
|
|
110
|
+
if (scan.counts.high > 0 && !options.force && !acknowledged) {
|
|
109
111
|
blockingReasons.push('安全检测发现 ' + scan.counts.high + ' 个高风险项')
|
|
110
112
|
}
|
|
113
|
+
if (scan.counts.high > 0 && acknowledged) {
|
|
114
|
+
notes.push('打包方已确认 ' + scan.counts.high + ' 个高风险项(市场收录插件),明细见扫描报告')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 界面要按来源(插件 / 配置 / 整合包本体)分栏展示,分组结果一并给出去
|
|
118
|
+
const scanGroups = groupFindings(scan.findings, manifest.plugins)
|
|
111
119
|
|
|
112
|
-
return { manifest, entries, integrity, scan, report, blockingReasons, notes }
|
|
120
|
+
return { manifest, entries, integrity, scan, scanGroups, report, blockingReasons, notes }
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
/** 从链接读取整合包(只允许 https 与白名单域名)。 */
|
|
@@ -169,7 +177,10 @@ function packDirOf(config, manifest) {
|
|
|
169
177
|
export async function installPack(input) {
|
|
170
178
|
const { manifest, entries, config, options = {}, context = {} } = input
|
|
171
179
|
const profileDir = context.profileDir || pathsFor(config).profile
|
|
172
|
-
|
|
180
|
+
// profile 名必须跟着 profileDir 走:DSH 命令行只认 --profile <名字>,
|
|
181
|
+
// 若拿 config.profile(桌面环境里恒为 desktop)去装,装进的是真 profile 而不是 targetDir。
|
|
182
|
+
const targetName = path.basename(path.resolve(profileDir))
|
|
183
|
+
const profile = targetName && targetName !== 'profiles' ? targetName : config.profile || 'desktop'
|
|
173
184
|
const installed = listInstalled(profileDir)
|
|
174
185
|
const compat = checkCompatibility(manifest.plugins, {
|
|
175
186
|
installed,
|
|
@@ -189,6 +200,7 @@ export async function installPack(input) {
|
|
|
189
200
|
reason: '兼容性检测有 ' + compat.counts.error + ' 个阻断问题',
|
|
190
201
|
compat,
|
|
191
202
|
actions,
|
|
203
|
+
deferred: [],
|
|
192
204
|
lines,
|
|
193
205
|
needsRestart: false,
|
|
194
206
|
}
|
|
@@ -199,74 +211,121 @@ export async function installPack(input) {
|
|
|
199
211
|
const packRoot = packDirOf(config, manifest)
|
|
200
212
|
// CLI 自己会把 bundle 登记进 profile;「装好先不启用」靠装完撤回列表实现,所以先记一份原始清单。
|
|
201
213
|
const bundlesBefore = readBundles(readProfilePackage(profileDir))
|
|
214
|
+
// 打包方已确认过风险的包,安装时不再因为 high 拦人(明细照样进报告)
|
|
215
|
+
const acknowledged = Boolean(manifest.security && (manifest.security.acknowledged === true || manifest.security.trustedOnly === true))
|
|
216
|
+
|
|
217
|
+
// 进度:和打包共用同一个进度窗(kind=install)
|
|
218
|
+
const progress = typeof options.onProgress === 'function' ? options.onProgress : () => {}
|
|
219
|
+
progress({ pct: 8, note: '检查本机已装的插件' })
|
|
220
|
+
const only = Array.isArray(options.only) && options.only.length > 0 ? new Set(options.only.map(String)) : null
|
|
221
|
+
// 默认「先跳过已装的,装完再问要不要换」;replaceExisting 时反过来,直接覆盖
|
|
222
|
+
const deferExisting = options.replaceExisting === true ? false : options.deferExisting !== false
|
|
223
|
+
const deferred = []
|
|
224
|
+
const total = manifest.plugins.length
|
|
202
225
|
|
|
203
226
|
for (const plugin of manifest.plugins) {
|
|
227
|
+
const index = manifest.plugins.indexOf(plugin)
|
|
228
|
+
progress({ pct: 12 + Math.round(((index + 1) / total) * 68), note: '安装 ' + plugin.name + (plugin.version ? ' ' + plugin.version : '') })
|
|
229
|
+
if (only && !only.has(plugin.name)) {
|
|
230
|
+
actions.push({ plugin: plugin.name, action: 'skipped', ok: true, message: '这次不动它(你只选了替换其中几个)' })
|
|
231
|
+
continue
|
|
232
|
+
}
|
|
204
233
|
const existing = installed.find((p) => p.name === plugin.name)
|
|
234
|
+
if (existing && deferExisting) {
|
|
235
|
+
// 同名或同插件不同版本都算已装:先跳过,其余照装,最后让你决定换不换
|
|
236
|
+
deferred.push({ name: plugin.name, localVersion: existing.version || '', packVersion: plugin.version || '', sameVersion: String(existing.version || '') === String(plugin.version || '') })
|
|
237
|
+
actions.push({ plugin: plugin.name, action: 'deferred', ok: true, message: '本机已装 ' + (existing.version || '(版本未知)') + ',先跳过;装完再问你换不换' })
|
|
238
|
+
continue
|
|
239
|
+
}
|
|
205
240
|
const keepLocal = options.keepLocal !== false && config.keepLocal !== false && manifest.options.keepLocalOnInstall !== false
|
|
206
|
-
if (existing && keepLocal) {
|
|
241
|
+
if (existing && !deferExisting && keepLocal && options.replaceExisting !== true) {
|
|
207
242
|
actions.push({ plugin: plugin.name, action: 'kept', ok: true, message: '本地已装 ' + existing.version + ',按“保留本地修改”跳过覆盖' })
|
|
208
243
|
continue
|
|
209
244
|
}
|
|
210
245
|
|
|
211
|
-
|
|
212
|
-
|
|
246
|
+
// 联网且插件市场可用时,优先按市场版本装(用户要求:装整合包时优先同步市场版本)
|
|
247
|
+
// 取不到 / 离线 / 关掉开关(options.preferMarket === false)时,按包内带来的那份装
|
|
248
|
+
let marketHit = null
|
|
249
|
+
if (options.preferMarket !== false && typeof context.resolveMarket === 'function') {
|
|
213
250
|
try {
|
|
214
|
-
|
|
251
|
+
marketHit = await context.resolveMarket(plugin)
|
|
215
252
|
} catch (error) {
|
|
216
|
-
|
|
217
|
-
continue
|
|
253
|
+
lines.push('查不到市场版本(' + plugin.name + '):' + String(error?.message || error) + ',按包内的来')
|
|
218
254
|
}
|
|
219
|
-
} else if (typeof context.resolveSource === 'function') {
|
|
220
|
-
try {
|
|
221
|
-
dir = await context.resolveSource(plugin, packRoot)
|
|
222
|
-
} catch (error) {
|
|
223
|
-
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '取包失败:' + String(error?.message || error) })
|
|
224
|
-
continue
|
|
225
|
-
}
|
|
226
|
-
} else {
|
|
227
|
-
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '轻量包需要在联网环境下解析来源' })
|
|
228
|
-
continue
|
|
229
255
|
}
|
|
230
256
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
})
|
|
239
|
-
const deep = scanEntries(brought.files, { extraRules: Array.isArray(config.extraScanRules) ? config.extraScanRules : [] })
|
|
240
|
-
if (deep.counts.high > 0 && !options.force) {
|
|
241
|
-
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '从市场取回的代码里有 ' + deep.counts.high + ' 个高风险项,已拦下' })
|
|
257
|
+
let dir = null
|
|
258
|
+
if (!marketHit) {
|
|
259
|
+
if (manifest.format === 'full' && pluginPayload(entries, plugin.dirName || plugin.name).length > 0) {
|
|
260
|
+
try {
|
|
261
|
+
dir = materializePayload(entries, manifest, plugin, config)
|
|
262
|
+
} catch (error) {
|
|
263
|
+
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: String(error?.message || error) })
|
|
242
264
|
continue
|
|
243
265
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
266
|
+
} else if (typeof context.resolveSource === 'function') {
|
|
267
|
+
try {
|
|
268
|
+
dir = await context.resolveSource(plugin, packRoot)
|
|
269
|
+
} catch (error) {
|
|
270
|
+
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '取包失败:' + String(error?.message || error) })
|
|
271
|
+
continue
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '轻量包需要在联网环境下解析来源' })
|
|
247
275
|
continue
|
|
248
276
|
}
|
|
249
|
-
}
|
|
250
277
|
|
|
251
|
-
|
|
252
|
-
|
|
278
|
+
if (manifest.format !== 'full') {
|
|
279
|
+
// 轻量包本体不夹带源码,真正的代码是刚下载回来的:装之前必须补扫一遍,否则「安装前检测」是空转
|
|
280
|
+
try {
|
|
281
|
+
const brought = collectFiles(dir, {
|
|
282
|
+
prefix: '',
|
|
283
|
+
maxFileBytes: config.maxFileBytes ?? 16 * 1024 * 1024,
|
|
284
|
+
maxTotalBytes: 64 * 1024 * 1024,
|
|
285
|
+
})
|
|
286
|
+
const deep = scanEntries(brought.files, { extraRules: Array.isArray(config.extraScanRules) ? config.extraScanRules : [] })
|
|
287
|
+
if (deep.counts.high > 0 && !options.force && !acknowledged) {
|
|
288
|
+
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '从市场取回的代码里有 ' + deep.counts.high + ' 个高风险项,已拦下' })
|
|
289
|
+
continue
|
|
290
|
+
}
|
|
291
|
+
lines.push('轻量包:已补扫从市场取回的 ' + deep.scannedFiles + ' 个文件(高 ' + deep.counts.high + ')')
|
|
292
|
+
} catch (error) {
|
|
293
|
+
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '补充扫描失败:' + String(error?.message || error) })
|
|
294
|
+
continue
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (options.dryRun) {
|
|
299
|
+
actions.push({ plugin: plugin.name, action: 'install', ok: true, message: '演练:将添加 ' + dir })
|
|
300
|
+
continue
|
|
301
|
+
}
|
|
302
|
+
} else if (options.dryRun) {
|
|
303
|
+
actions.push({ plugin: plugin.name, action: 'install', ok: true, message: '演练:将按市场版本安装 ' + marketHit.spec })
|
|
253
304
|
continue
|
|
254
305
|
}
|
|
255
306
|
|
|
256
307
|
const runCli = typeof context.runCli === 'function' ? context.runCli : runDshPlugin
|
|
257
|
-
const
|
|
308
|
+
const targetSpec = marketHit ? marketHit.spec : 'file:' + dir
|
|
309
|
+
const result = await runCli(profile, ['plugin', '--profile', profile, 'add', targetSpec], {
|
|
258
310
|
cwd: profileDir,
|
|
259
311
|
onLine: (line) => { lines.push(line); onLine(line) },
|
|
260
312
|
})
|
|
261
|
-
appendLog('install ' + plugin.name + ' exit=' + result.code)
|
|
313
|
+
appendLog('install ' + plugin.name + ' exit=' + result.code + ' via=' + (marketHit ? 'market' : 'pack'))
|
|
262
314
|
if (result.code !== 0) {
|
|
263
315
|
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: 'dsh plugin add 失败(退出码 ' + result.code + '),详见日志' })
|
|
264
316
|
continue
|
|
265
317
|
}
|
|
266
318
|
if (plugin.isBundle && plugin.hasPatch) touchedBundles.push(plugin.name)
|
|
267
|
-
actions.push({
|
|
319
|
+
actions.push({
|
|
320
|
+
plugin: plugin.name,
|
|
321
|
+
action: 'install',
|
|
322
|
+
ok: true,
|
|
323
|
+
source: marketHit ? 'market' : 'pack',
|
|
324
|
+
message: marketHit ? ('已按市场版本安装 ' + marketHit.spec) : ('已装 ' + (plugin.version || '')),
|
|
325
|
+
})
|
|
268
326
|
}
|
|
269
327
|
|
|
328
|
+
progress({ pct: 84, note: '登记启用清单' })
|
|
270
329
|
if (!options.dryRun) {
|
|
271
330
|
const before = bundlesBefore
|
|
272
331
|
const after = readBundles(readProfilePackage(profileDir))
|
|
@@ -284,6 +343,7 @@ export async function installPack(input) {
|
|
|
284
343
|
}
|
|
285
344
|
}
|
|
286
345
|
|
|
346
|
+
progress({ pct: 92, note: '回填包内配置' })
|
|
287
347
|
// 配置回填:只改目标条目,其它字节不动
|
|
288
348
|
if (options.applyConfig !== false && manifest.options.includeConfig) {
|
|
289
349
|
const patch = readPatch(profileDir)
|
|
@@ -331,10 +391,12 @@ export async function installPack(input) {
|
|
|
331
391
|
}
|
|
332
392
|
if (!options.dryRun) writeJsonAtomic(path.join(packRoot, 'install-result.json'), record)
|
|
333
393
|
|
|
394
|
+
progress({ pct: 100, note: '安装完成' })
|
|
334
395
|
return {
|
|
335
396
|
ok,
|
|
336
397
|
compat,
|
|
337
398
|
actions,
|
|
399
|
+
deferred,
|
|
338
400
|
configItems,
|
|
339
401
|
lines,
|
|
340
402
|
needsRestart: options.enableBundles === false ? false : actions.some((a) => a.action === 'install' && a.ok),
|
package/lib/manifest.mjs
CHANGED
|
@@ -104,6 +104,8 @@ export function normalizeManifest(raw) {
|
|
|
104
104
|
medium: num(raw.security?.medium),
|
|
105
105
|
low: num(raw.security?.low),
|
|
106
106
|
approvedRisk: bool(raw.security?.approvedRisk),
|
|
107
|
+
acknowledged: bool(raw.security?.acknowledged),
|
|
108
|
+
trustedOnly: bool(raw.security?.trustedOnly),
|
|
107
109
|
note: str(raw.security?.note, 500),
|
|
108
110
|
},
|
|
109
111
|
install: {
|
|
@@ -154,25 +156,33 @@ export function buildReadme(manifest, extra = {}) {
|
|
|
154
156
|
lines.push('')
|
|
155
157
|
lines.push('怎么装')
|
|
156
158
|
if (manifest.format === 'lite') {
|
|
157
|
-
lines.push('
|
|
158
|
-
lines.push('
|
|
159
|
-
lines.push('
|
|
159
|
+
lines.push(' 方式 A(有 dsh-modpack 插件):侧栏「整合包 → 安装」选择本文件,会联网按版本取包并校验完整性。')
|
|
160
|
+
lines.push(' 方式 B(裸 DSH 也能装):解压后运行 install/ 里的安装器,它会按清单里的名字与版本从 registry 取包:')
|
|
161
|
+
lines.push(' Windows: install\\install.cmd 其它: sh install/install.sh')
|
|
162
|
+
lines.push(' 指定 profile 或 DSH 位置:加 --profile <名字> --dsh "<DSH 可执行文件或 cli.js>"')
|
|
160
163
|
} else {
|
|
161
164
|
lines.push(' 方式 A(推荐,有 dsh-modpack 插件):侧栏「整合包 → 安装」选择本文件,会校验完整性、')
|
|
162
165
|
lines.push(' 重新扫描安全项、检查兼容性,并把打包时保存的配置同步回来。')
|
|
163
|
-
lines.push(' 方式 B
|
|
164
|
-
lines.push(' 1.
|
|
165
|
-
lines.push(' 2.
|
|
166
|
-
lines.push('
|
|
167
|
-
lines.push('
|
|
168
|
-
lines.push('
|
|
169
|
-
lines.push('
|
|
166
|
+
lines.push(' 方式 B(没有任何插件、裸 DSH 也能装,推荐给没装本插件的人):')
|
|
167
|
+
lines.push(' 1. 解压整个 zip;')
|
|
168
|
+
lines.push(' 2. 运行包内安装器(需要 Node 20+):')
|
|
169
|
+
lines.push(' Windows: install\\install.cmd 其它: sh install/install.sh')
|
|
170
|
+
lines.push(' 可加参数:--profile <名字>(默认 desktop)--dry-run(只看要做什么)')
|
|
171
|
+
lines.push(' --no-bundles(装了但先不启用)--replace(本机已装的也换成包内版本)')
|
|
172
|
+
lines.push(' --dsh "<DSH 可执行文件或 cli.js>"')
|
|
173
|
+
lines.push(' 3. 安装器会逐插件执行官方 dsh plugin add、把 configs/ 里的配置合并进 cordis.patch.yml;')
|
|
174
|
+
lines.push(' 本机已经装了的插件它会先跳过、装完列出来;要换成包内版本,加 --replace 重跑一次。')
|
|
175
|
+
lines.push(' 4. 重启 DSH。')
|
|
176
|
+
lines.push(' 方式 C(手工,没有 Node 时):解压后对 plugins/ 下每个目录执行')
|
|
177
|
+
lines.push(' dsh plugin --profile <你的profile> add "file:<绝对路径>/plugins/<插件名>"')
|
|
178
|
+
lines.push(' 再把插件名加进 ~/.dsh/profiles/<你的profile>/package.json 的 dsh.profile.bundles。')
|
|
170
179
|
}
|
|
171
180
|
lines.push('')
|
|
172
181
|
lines.push('目录结构')
|
|
173
182
|
lines.push(' dsh-modpack.json 清单(机器可读,schema ' + SCHEMA + ')')
|
|
174
183
|
lines.push(' integrity.json 每个文件的 sha256')
|
|
175
184
|
lines.push(' security/ 安全检测报告(已打码)')
|
|
185
|
+
lines.push(' install/ 独立安装器(不依赖本插件,裸 DSH 可用)')
|
|
176
186
|
lines.push(' configs/ 打包时的非默认配置(每个插件一个 json)')
|
|
177
187
|
if (manifest.format === 'full') lines.push(' plugins/ 插件本体,一个目录一个插件')
|
|
178
188
|
lines.push(' data/ 插件数据快照(如果打包时选了保留)')
|
package/lib/pack.mjs
CHANGED
|
@@ -11,20 +11,26 @@
|
|
|
11
11
|
import fs from 'node:fs'
|
|
12
12
|
import path from 'node:path'
|
|
13
13
|
import { writeZip } from './zip.mjs'
|
|
14
|
-
import { scanEntries, renderScanReport } from './scan.mjs'
|
|
14
|
+
import { scanEntries, renderScanReport, groupFindings } from './scan.mjs'
|
|
15
15
|
import { MANIFEST_NAME, SCHEMA, KIND, normalizeManifest, buildReadme, sha256, shortHash } from './manifest.mjs'
|
|
16
16
|
import { scanFileName } from './scan.mjs'
|
|
17
17
|
import { slugify } from './store.mjs'
|
|
18
18
|
|
|
19
|
+
const STUB_DIR = new URL('../assets/', import.meta.url)
|
|
20
|
+
const stub = (name) => fs.readFileSync(new URL(name, STUB_DIR))
|
|
21
|
+
|
|
19
22
|
const SKIP_DIRS = new Set(['node_modules', '.git', '.svn', '__pycache__', '.cache', '.turbo', '.next', 'coverage'])
|
|
20
23
|
const SKIP_FILES = new Set(['.DS_Store', 'Thumbs.db', 'desktop.ini'])
|
|
21
24
|
const DATA_EXT = new Set(['.json', '.md', '.txt', '.yml', '.yaml', '.csv', '.toml', '.ini'])
|
|
22
25
|
|
|
23
26
|
export class PackRefused extends Error {
|
|
24
|
-
constructor(message, scan) {
|
|
27
|
+
constructor(message, scan, extra = {}) {
|
|
25
28
|
super(message)
|
|
26
29
|
this.name = 'PackRefused'
|
|
27
30
|
this.scan = scan
|
|
31
|
+
this.needsAck = extra.needsAck === true
|
|
32
|
+
this.trustedOnly = extra.trustedOnly === true
|
|
33
|
+
this.checkpoint = extra.checkpoint || null
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
|
|
@@ -180,12 +186,30 @@ export async function buildPack(input) {
|
|
|
180
186
|
const { selection, options, context } = input
|
|
181
187
|
const config = context.config
|
|
182
188
|
const plugins = []
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
let payload = []
|
|
190
|
+
let notes = []
|
|
191
|
+
let manifestPlugins = []
|
|
192
|
+
let capturedFiles = []
|
|
193
|
+
let scan = null
|
|
194
|
+
let trustedOnly = false
|
|
186
195
|
const scanRules = context.extraScanRules || []
|
|
187
196
|
const format = options.includePayload === false ? 'lite' : 'full'
|
|
197
|
+
const progress = typeof options.onProgress === 'function' ? options.onProgress : () => {}
|
|
198
|
+
const tick = (stage, pct, note) => { try { progress({ stage, pct: Math.max(0, Math.min(100, Math.round(pct))), note }) } catch {} }
|
|
188
199
|
|
|
200
|
+
const resume = options && typeof options.resume === 'object' ? options.resume : null
|
|
201
|
+
if (resume) {
|
|
202
|
+
// 停在风险点之后点「我知道在干什么」:复用上次的结果,不重新收集、也不重新检测
|
|
203
|
+
payload = Array.isArray(resume.payload) ? resume.payload : []
|
|
204
|
+
capturedFiles = Array.isArray(resume.capturedFiles) ? resume.capturedFiles : []
|
|
205
|
+
manifestPlugins = Array.isArray(resume.manifestPlugins) ? resume.manifestPlugins : []
|
|
206
|
+
notes = Array.isArray(resume.notes) ? resume.notes.slice() : []
|
|
207
|
+
scan = resume.scan
|
|
208
|
+
trustedOnly = resume.trustedOnly === true
|
|
209
|
+
notes.push('已确认风险:检测结果沿用上一次,不重复扫描')
|
|
210
|
+
tick('capture', 62, '已确认风险,从检测点继续')
|
|
211
|
+
} else {
|
|
212
|
+
tick('collect', 4, '读取插件清单')
|
|
189
213
|
for (const pick of selection) {
|
|
190
214
|
if (!pick || typeof pick.name !== 'string') continue
|
|
191
215
|
let files = []
|
|
@@ -278,10 +302,11 @@ export async function buildPack(input) {
|
|
|
278
302
|
}
|
|
279
303
|
manifestPlugins.push(entry)
|
|
280
304
|
payload.push(...files.map((f) => ({ ...f, plugin: name })))
|
|
305
|
+
tick('collect', 6 + 34 * (manifestPlugins.length / Math.max(1, selection.length)), '收集 ' + name + ' 的文件')
|
|
281
306
|
}
|
|
282
307
|
|
|
283
308
|
// 配置与数据快照
|
|
284
|
-
|
|
309
|
+
capturedFiles = []
|
|
285
310
|
if (options.includeConfig) {
|
|
286
311
|
const { captured, notes: configNotes } = captureConfigs(context.patchText || '', manifestPlugins, context.parsePatch)
|
|
287
312
|
notes.push(...configNotes)
|
|
@@ -307,13 +332,55 @@ export async function buildPack(input) {
|
|
|
307
332
|
|
|
308
333
|
// 先扫描,再决定要不要写盘。扫描是强制的:没有「关掉扫描」这条路,
|
|
309
334
|
// 只有高风险默认阻断、显式 force 才继续(决定会写进清单 security.approvedRisk)。
|
|
335
|
+
// 信任名单:插件市场目录里能查到的插件(options.trusted)视为市场发行版。
|
|
336
|
+
// 这类插件的高危项不直接阻断,但必须由调用方 acknowledge 之后才出包。
|
|
337
|
+
const trustedSet = new Set((Array.isArray(options.trusted) ? options.trusted : []).map((n) => String(n)))
|
|
338
|
+
const dirToName = new Map()
|
|
339
|
+
for (const plugin of manifestPlugins) if (plugin.dirName) dirToName.set(plugin.dirName, plugin.name)
|
|
340
|
+
const dirOf = (file) => {
|
|
341
|
+
const hit = /^plugins\/([^/]+)\//.exec(String(file || ''))
|
|
342
|
+
return hit ? hit[1] : ''
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
tick('capture', 42, '抓取配置与数据快照')
|
|
310
346
|
const scanTargets = [...payload, ...capturedFiles]
|
|
311
|
-
|
|
347
|
+
tick('scan', 55, '扫描敏感信息与风险代码')
|
|
348
|
+
scan = scanEntries(scanTargets.map((f) => ({ name: f.name, data: f.data })), { extraRules: scanRules })
|
|
312
349
|
|
|
313
|
-
|
|
314
|
-
|
|
350
|
+
const highFindings = scan.findings.filter((f) => f.severity === 'high')
|
|
351
|
+
const highFromUntrusted = highFindings.filter((f) => {
|
|
352
|
+
const name = dirToName.get(dirOf(f.file))
|
|
353
|
+
return !name || !trustedSet.has(name)
|
|
354
|
+
})
|
|
355
|
+
trustedOnly = highFindings.length > 0 && highFromUntrusted.length === 0
|
|
356
|
+
// 高风险一律停在「等你点一下」:acknowledge 之后才出包,决定记进清单。
|
|
357
|
+
// 市场目录能查到的(trustedOnly)与查不到的(含本机自己改的)走同一条路,
|
|
358
|
+
// 只是提示措辞不同——这样界面上永远有「我知道在干什么」这个出口。
|
|
359
|
+
if (config?.blockHighRisk !== false && highFindings.length > 0 && options.acknowledge !== true && options.force !== true) {
|
|
360
|
+
const where = trustedOnly
|
|
361
|
+
? '均来自插件市场已收录的插件'
|
|
362
|
+
: (highFromUntrusted.length === highFindings.length ? '来自本机插件,市场目录里查不到同名条目' : '有一部分来自本机插件(市场目录里查不到同名条目)')
|
|
363
|
+
throw new PackRefused(
|
|
364
|
+
'检出 ' + highFindings.length + ' 个高风险项(' + where + ');确认了解风险后可继续打包',
|
|
365
|
+
scan,
|
|
366
|
+
{
|
|
367
|
+
needsAck: true,
|
|
368
|
+
trustedOnly,
|
|
369
|
+
checkpoint: {
|
|
370
|
+
payload,
|
|
371
|
+
capturedFiles,
|
|
372
|
+
manifestPlugins: JSON.parse(JSON.stringify(manifestPlugins)),
|
|
373
|
+
notes: notes.slice(),
|
|
374
|
+
scan,
|
|
375
|
+
trustedOnly,
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
)
|
|
379
|
+
}
|
|
315
380
|
}
|
|
316
381
|
|
|
382
|
+
tick('scan', 66, '完成安全检测')
|
|
383
|
+
const scanGroups = groupFindings(scan.findings, manifestPlugins)
|
|
317
384
|
const manifestBase = {
|
|
318
385
|
schema: SCHEMA,
|
|
319
386
|
kind: KIND,
|
|
@@ -330,7 +397,7 @@ export async function buildPack(input) {
|
|
|
330
397
|
options: {
|
|
331
398
|
includePayload: format === 'full',
|
|
332
399
|
includeConfig: Boolean(options.includeConfig),
|
|
333
|
-
includeLocalEdits:
|
|
400
|
+
includeLocalEdits: manifestPlugins.some((plugin) => plugin.mode === 'local'),
|
|
334
401
|
keepLocalOnInstall: options.keepLocal !== false,
|
|
335
402
|
},
|
|
336
403
|
plugins: manifestPlugins,
|
|
@@ -340,7 +407,9 @@ export async function buildPack(input) {
|
|
|
340
407
|
high: scan.counts.high,
|
|
341
408
|
medium: scan.counts.medium,
|
|
342
409
|
low: scan.counts.low,
|
|
343
|
-
approvedRisk: scan.
|
|
410
|
+
approvedRisk: scan.findings.some((f) => f.severity === 'high'),
|
|
411
|
+
acknowledged: options.acknowledge === true,
|
|
412
|
+
trustedOnly,
|
|
344
413
|
note: scan.note,
|
|
345
414
|
},
|
|
346
415
|
install: {
|
|
@@ -357,10 +426,17 @@ export async function buildPack(input) {
|
|
|
357
426
|
const report = renderScanReport(manifest.name, scan, { approvedRisk: manifest.security.approvedRisk })
|
|
358
427
|
const readme = buildReadme(manifest)
|
|
359
428
|
|
|
429
|
+
tick('write', 78, '写入清单与安装器')
|
|
430
|
+
const installScripts = [
|
|
431
|
+
{ name: 'install/install.mjs', data: stub('install-stub.mjs') },
|
|
432
|
+
{ name: 'install/install.cmd', data: stub('install-stub.cmd') },
|
|
433
|
+
{ name: 'install/install.sh', data: stub('install-stub.sh') },
|
|
434
|
+
]
|
|
360
435
|
const entries = [
|
|
361
436
|
{ name: MANIFEST_NAME, data: manifestBuf },
|
|
362
437
|
{ name: 'README.txt', data: Buffer.from(readme, 'utf8') },
|
|
363
438
|
{ name: 'security/report.txt', data: Buffer.from(report, 'utf8') },
|
|
439
|
+
...installScripts,
|
|
364
440
|
...(options.includePayload === false ? [] : payload),
|
|
365
441
|
...capturedFiles,
|
|
366
442
|
]
|
|
@@ -372,11 +448,13 @@ export async function buildPack(input) {
|
|
|
372
448
|
}
|
|
373
449
|
entries.push({ name: 'integrity.json', data: Buffer.from(JSON.stringify(integrity, null, 2), 'utf8') })
|
|
374
450
|
|
|
451
|
+
tick('write', 90, '压缩打包')
|
|
375
452
|
const buffer = writeZip(entries)
|
|
376
453
|
if (config?.maxPackBytes && buffer.length > config.maxPackBytes) {
|
|
377
454
|
throw new Error('整合包体积 ' + buffer.length + ' 字节,超过上限 ' + config.maxPackBytes)
|
|
378
455
|
}
|
|
379
456
|
const stamp = new Date().toISOString().slice(0, 10)
|
|
380
457
|
const fileName = slugify(manifest.name) + '-' + stamp + '-' + format + '.dshpack'
|
|
381
|
-
|
|
458
|
+
tick('done', 100, '完成')
|
|
459
|
+
return { buffer, fileName, manifest, scan, scanGroups, report, notes, size: buffer.length }
|
|
382
460
|
}
|
package/lib/scan.mjs
CHANGED
|
@@ -184,6 +184,53 @@ export function scanFile(name, data) {
|
|
|
184
184
|
|
|
185
185
|
const SEVERITY_ORDER = { high: 0, medium: 1, low: 2 }
|
|
186
186
|
|
|
187
|
+
/**
|
|
188
|
+
* 把命中按来源分组:插件本体 / 该插件的配置快照 / 数据快照 / 整合包自身文件。
|
|
189
|
+
* @param {object[]} findings
|
|
190
|
+
* @param {{name: string, dirName?: string, source?: string}[]} plugins
|
|
191
|
+
*/
|
|
192
|
+
export function groupFindings(findings, plugins = []) {
|
|
193
|
+
const byDir = new Map()
|
|
194
|
+
for (const p of plugins) {
|
|
195
|
+
if (!p || !p.name) continue
|
|
196
|
+
byDir.set(p.dirName || p.name, p)
|
|
197
|
+
}
|
|
198
|
+
const groups = new Map()
|
|
199
|
+
const originOf = (p) => (p.source === 'npm' ? 'market' : 'local')
|
|
200
|
+
const slot = (key, label, origin, pluginName) => {
|
|
201
|
+
if (!groups.has(key)) groups.set(key, { key, label, origin, plugin: pluginName || '', counts: { high: 0, medium: 0, low: 0 }, findings: [] })
|
|
202
|
+
return groups.get(key)
|
|
203
|
+
}
|
|
204
|
+
for (const finding of findings) {
|
|
205
|
+
const file = String(finding.file || '')
|
|
206
|
+
let hit
|
|
207
|
+
if ((hit = /^plugins\/([^/]+)\//u.exec(file))) {
|
|
208
|
+
const plugin = byDir.get(hit[1])
|
|
209
|
+
const group = slot('plugin:' + hit[1], (plugin && plugin.name) || hit[1], plugin ? originOf(plugin) : 'local', (plugin && plugin.name) || hit[1])
|
|
210
|
+
group.findings.push(finding)
|
|
211
|
+
group.counts[finding.severity] = (group.counts[finding.severity] || 0) + 1
|
|
212
|
+
} else if ((hit = /^configs\/([^/]+)\.json$/u.exec(file))) {
|
|
213
|
+
const plugin = byDir.get(hit[1])
|
|
214
|
+
const group = slot('config:' + hit[1], ((plugin && plugin.name) || hit[1]) + ' 的配置快照', 'config', (plugin && plugin.name) || hit[1])
|
|
215
|
+
group.findings.push(finding)
|
|
216
|
+
group.counts[finding.severity] = (group.counts[finding.severity] || 0) + 1
|
|
217
|
+
} else if ((hit = /^data\/([^/]+)\//u.exec(file))) {
|
|
218
|
+
const plugin = byDir.get(hit[1])
|
|
219
|
+
const group = slot('data:' + hit[1], ((plugin && plugin.name) || hit[1]) + ' 的数据快照', 'data', (plugin && plugin.name) || hit[1])
|
|
220
|
+
group.findings.push(finding)
|
|
221
|
+
group.counts[finding.severity] = (group.counts[finding.severity] || 0) + 1
|
|
222
|
+
} else {
|
|
223
|
+
const group = slot('pack', '整合包自身的清单与安装器', 'pack', '')
|
|
224
|
+
group.findings.push(finding)
|
|
225
|
+
group.counts[finding.severity] = (group.counts[finding.severity] || 0) + 1
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const weight = (g) => (g.counts.high > 0 ? 0 : g.counts.medium > 0 ? 1 : 2)
|
|
229
|
+
return [...groups.values()]
|
|
230
|
+
.map((g) => ({ ...g, findings: g.findings.sort((a, b) => severityRank(a.severity) - severityRank(b.severity) || a.line - b.line) }))
|
|
231
|
+
.sort((a, b) => weight(a) - weight(b) || b.findings.length - a.findings.length || a.label.localeCompare(b.label))
|
|
232
|
+
}
|
|
233
|
+
|
|
187
234
|
export function severityRank(severity) {
|
|
188
235
|
return SEVERITY_ORDER[severity] ?? 3
|
|
189
236
|
}
|
package/lib/store.mjs
CHANGED
|
@@ -53,9 +53,11 @@ export const DEFAULT_CONFIG = {
|
|
|
53
53
|
'cdn.jsdelivr.net', 'fastly.jsdelivr.net', 'gh-proxy.com',
|
|
54
54
|
'github.com', 'api.github.com', 'codeload.github.com', 'objects.githubusercontent.com', 'raw.githubusercontent.com',
|
|
55
55
|
],
|
|
56
|
-
maxDownloadBytes:
|
|
57
|
-
maxPackBytes:
|
|
56
|
+
maxDownloadBytes: 256 * 1024 * 1024,
|
|
57
|
+
maxPackBytes: 512 * 1024 * 1024,
|
|
58
58
|
maxFileBytes: 16 * 1024 * 1024,
|
|
59
|
+
// 进度窗里「收尾」的记录留多久(秒):正常的完成记录留久一点,失败/取消的留很短,别堆在眼前
|
|
60
|
+
jobKeepSeconds: 60,
|
|
59
61
|
// 二次开发用:额外扫描规则(形状同 lib/scan.mjs 的 SECRET_RULES)
|
|
60
62
|
extraScanRules: [],
|
|
61
63
|
historyLimit: 50,
|
|
@@ -68,6 +70,8 @@ export const DEFAULT_CONFIG = {
|
|
|
68
70
|
showInPluginsTab: false,
|
|
69
71
|
// 安装后是否直接登记到 bundles(默认关:只装文件,重启也不加载)
|
|
70
72
|
enableOnInstall: false,
|
|
73
|
+
// 装整合包时若联网且插件市场有同名条目,优先按市场版本装(关掉则严格按包内那份)
|
|
74
|
+
preferMarketOnInstall: true,
|
|
71
75
|
// 白名单迁移标记:跑过一次就别再往里并默认域名,尊重用户自己的增删
|
|
72
76
|
hostsVersion: HOSTS_VERSION,
|
|
73
77
|
}
|
|
@@ -105,6 +109,10 @@ function clampConfig(raw) {
|
|
|
105
109
|
// 分页大小与刷新周期:给了边界,避免有人把 10000 写进设置把页面拖死
|
|
106
110
|
cfg.catalogPageSize = Math.min(100, Math.max(5, Number(cfg.catalogPageSize) || DEFAULT_CONFIG.catalogPageSize))
|
|
107
111
|
cfg.catalogRefreshHours = Math.min(168, Math.max(1, Number(cfg.catalogRefreshHours) || DEFAULT_CONFIG.catalogRefreshHours))
|
|
112
|
+
// 0 是合法的:等于「收尾就立刻清掉」,测试也靠它把时间压到零
|
|
113
|
+
const keepRaw = raw && typeof raw.jobKeepSeconds === 'number' ? raw.jobKeepSeconds : DEFAULT_CONFIG.jobKeepSeconds
|
|
114
|
+
cfg.jobKeepSeconds = Math.min(3600, Math.max(0, Math.floor(Number(keepRaw) || 0)))
|
|
115
|
+
// 进度窗位置不在这里管:它由界面自己拖动并存在浏览器本地,服务端不需要知道
|
|
108
116
|
// 打包前安全检测是强制的:设置里怎么写都不认,打包一律扫。
|
|
109
117
|
cfg.scanBeforePack = true
|
|
110
118
|
return cfg
|
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Modpack",
|
|
4
|
-
"description": "Bundle several plugins into one .dshpack and install them in
|
|
4
|
+
"description": "Bundle several plugins into one .dshpack and install them in one pass: full packs carry the payloads, lite packs record names and versions and fetch them from the registry, and both ship a standalone installer so a machine with nothing but a bare DSH can install (payloads are copied under ~/.dsh/dsh-modpack/vendor and registered, so deleting the unpacked folder is safe; installed plugins are skipped unless you pass --replace). Each plugin can be packed as upstream-basic or as your local copy. Packing always runs an in-memory scan for secrets and risky code (masked, never written to disk); high-risk hits pause the job until you confirm, then the same job resumes from the scan checkpoint without scanning again, and the confirmation is recorded in the manifest. Installing shares the progress dock: plugins already present are skipped first, then you choose finish-as-is or replace with the packed version; when the market catalog has the same name and you are online, the market version is preferred (switchable). Integrity, compatibility and licences are re-checked, the packed config is re-applied, and install-without-enabling or enable-right-away are both available. Packs can be opened via a file picker, a folder picker, any directory, an imported-packs list (several at once, each showing its packed name, author and description) or an https link. Categories, search, sorting and entries come from the same plugin-market catalog (first screen lists only what you have, paged on the server), and the UI can be shown in settings, the sidebar or the plugins tab, each switchable. Installing the plugin market (dshmarket) first is recommended but not required.",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "整合包",
|
|
4
|
-
"description": "把多个插件打成一个 .dshpack
|
|
4
|
+
"description": "把多个插件打成一个 .dshpack,一次装好:完整版自带插件本体,轻量版只记名字与版本、安装时按记录取包;两种包都附独立安装器,对方只剩一个 DSH 本体也能装(复制到本机 vendor 后登记,删掉解压目录也不断,默认跳过已装的插件,加 --replace 才覆盖)。每个插件可单独选「基础配置」或「本地改动」。打包前强制做敏感信息与风险代码检测(命中只留掩码、原文不落盘),检出高危会停在「等决定」,确认后在同一任务里从检测点续跑、不重复扫描,确认状态写进清单。安装也走同一个进度窗:先跳过本机已装的插件,装完再让你选「直接完成」还是「替换为包内版本」;联网且市场有同名条目时优先装市场版本(可关)。安装前查完整性、兼容性与许可证,装完按条目回填配置,也可选先不启用或装完直接启用。取包支持「选择文件…」「浏览文件夹…」、任意目录、已导入列表(可同时留多份,显示打包时的名字/作者/描述)与 https 链接。分类、搜索、排序与条目都跟插件市场同源(首屏只列已装、服务端分页),三处入口(设置 / 侧边栏 / 插件页)可各自开关。建议先装插件市场(dshmarket)再一起用——不装也能打包、装包与检测。",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-modpack-kit",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Bundle several plugins into one .dshpack and install them in
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Bundle several plugins into one .dshpack and install them in one pass: full packs carry the payloads, lite packs record names and versions and fetch them from the registry, and both ship a standalone installer so a machine with nothing but a bare DSH can install (payloads are copied under ~/.dsh/dsh-modpack/vendor and registered, so deleting the unpacked folder is safe; installed plugins are skipped unless you pass --replace). Each plugin can be packed as upstream-basic or as your local copy. Packing always runs an in-memory scan for secrets and risky code (masked, never written to disk); high-risk hits pause the job until you confirm, then the same job resumes from the scan checkpoint without scanning again, and the confirmation is recorded in the manifest. Installing shares the progress dock: plugins already present are skipped first, then you choose finish-as-is or replace with the packed version; when the market catalog has the same name and you are online, the market version is preferred (switchable). Integrity, compatibility and licences are re-checked, the packed config is re-applied, and install-without-enabling or enable-right-away are both available. Packs can be opened via a file picker, a folder picker, any directory, an imported-packs list (several at once, each showing its packed name, author and description) or an https link. Categories, search, sorting and entries come from the same plugin-market catalog (first screen lists only what you have, paged on the server), and the UI can be shown in settings, the sidebar or the plugins tab, each switchable. Installing the plugin market (dshmarket) first is recommended but not required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"exports": {
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"docs",
|
|
21
21
|
"icon.svg",
|
|
22
22
|
"README.md",
|
|
23
|
-
"LICENSE"
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"assets"
|
|
24
25
|
],
|
|
25
26
|
"keywords": [
|
|
26
27
|
"dsh-plugin",
|