dsh-recall-plugin 1.2.2 → 1.4.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/CHANGELOG.md +109 -0
- package/README.en.md +124 -118
- package/README.md +125 -119
- package/cordis.patch.yml +19 -11
- package/lib/client.js +780 -456
- package/lib/config.js +36 -0
- package/lib/index.js +541 -164
- package/lib/maintenance.js +120 -107
- package/lib/scripts.posix.js +366 -290
- package/lib/scripts.pwsh.js +432 -334
- package/lib/snapshots.js +214 -192
- package/lib/store.js +342 -249
- package/package.json +52 -57
package/lib/config.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-recall-plugin — 配置域(ctx 绑定的工厂,无模块级副作用)
|
|
3
|
+
*
|
|
4
|
+
* 职责:把「用户大概率不改的默认值」从硬编码/环境变量迁移到 DSH 官方
|
|
5
|
+
* 插件配置机制——cordis.patch.yml 的 insert 行声明 config 默认值,用户在
|
|
6
|
+
* 自己 profile 的 cordis.patch.yml 里按 id 重述该行即可覆盖(层叠规则见
|
|
7
|
+
* 《DSH 插件开发规范》第五节),无需设环境变量、无需改包。
|
|
8
|
+
*
|
|
9
|
+
* 环境变量 DSH_RECALL_GC_SNAPS / DSH_RECALL_GC_HOURS 保留为最高优先级
|
|
10
|
+
* 覆盖:已用它们调档的用户(含冒烟测试脚本)升级后行为不漂移。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// 平台分叉的默认值:Windows 用 \\ 拼基础排除表,POSIX 用 /——但排除表是
|
|
14
|
+
// gitignore 语法(内部一律正斜杠),与平台无关,只有「是否含该项」的差异
|
|
15
|
+
const BASE_EXCLUDES = ['.git', 'node_modules/', '.dsh-recall-snapshots/']
|
|
16
|
+
|
|
17
|
+
export function createConfig(raw) {
|
|
18
|
+
const cfg = raw && typeof raw === 'object' ? raw : {}
|
|
19
|
+
|
|
20
|
+
function pickNumber(value, fallback, min) {
|
|
21
|
+
const n = typeof value === 'number' ? value : parseInt(String(value == null ? '' : value), 10)
|
|
22
|
+
if (!Number.isFinite(n) || n < min) return fallback
|
|
23
|
+
return n
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 环境变量优先(向后兼容),其次 config,最后默认值
|
|
27
|
+
const gcSnaps = pickNumber(process.env.DSH_RECALL_GC_SNAPS, pickNumber(cfg.gcSnaps, 50, 1), 1)
|
|
28
|
+
const gcHours = pickNumber(process.env.DSH_RECALL_GC_HOURS, pickNumber(cfg.gcHours, 24, 1), 1)
|
|
29
|
+
const maxFileBytes = pickNumber(cfg.maxFileBytes, 104857600, 1024)
|
|
30
|
+
|
|
31
|
+
const baseExcludes = Array.isArray(cfg.baseExcludes) && cfg.baseExcludes.length
|
|
32
|
+
? cfg.baseExcludes.filter((p) => typeof p === 'string' && p.trim())
|
|
33
|
+
: BASE_EXCLUDES
|
|
34
|
+
|
|
35
|
+
return { gcSnaps, gcHours, maxFileBytes, baseExcludes }
|
|
36
|
+
}
|