dsh-config-sync-plugin 0.4.10 → 0.4.11

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/runtime/sync.ps1 CHANGED
@@ -32,6 +32,7 @@ param(
32
32
  [switch]$WorkspaceOnly,
33
33
  [switch]$SkipWorkspace,
34
34
  [switch]$SkipInstall,
35
+ # 已废弃:0.4.10 起默认放行版本差异,此开关不参与判据,仅为兼容旧调用保留
35
36
  [switch]$AllowVersionDrift,
36
37
  # 推送前强制全量重扫历史里的超大文件(默认只在首次或推送被拒时才扫,省 20s)
37
38
  [switch]$ScanHistory,
@@ -567,7 +568,7 @@ function Get-RemoteFileCount([string]$RemoteUrl, [int]$Heads = -2) {
567
568
  初始化推送:本机空目录 + 云端空仓库,把本机配置当作仓库的初始内容推上去。
568
569
  骨架要一起带进仓库 —— 历史仓库本来就有 apply.ps1 / capture.ps1 / dsh-sync-common.ps1 这几份副本,
569
570
  少拷了它们,远端就变成「只有 settings 没有执行体」的半截仓库,另一台 pull 下来跑不起来。
570
- profile\host-contract.json 用本机客户端版本生成(apply 靠它校验两端版本,缺了只会跳过校验)。
571
+ profile\host-contract.json 用本机客户端版本生成(apply 仅用于实验 bundle 门控;版本差异不再阻断,只提示)。
571
572
  #>
572
573
  function Initialize-EmptyRepo([string]$RemoteUrl) {
573
574
  if (-not $RemoteUrl) {
@@ -1109,6 +1110,7 @@ $applyArgs = @{ RepoRoot = $RepoRoot; DshHome = $DshHome; ProfileName = $Profile
1109
1110
  if ($WorkspaceOnly) { $applyArgs['WorkspaceOnly'] = $true }
1110
1111
  if ($SkipWorkspace) { $applyArgs['SkipWorkspace'] = $true }
1111
1112
  if ($SkipInstall) { $applyArgs['SkipInstall'] = $true }
1113
+ # AllowVersionDrift 已废弃;apply.ps1 从 0.4.10 起忽略版本差异门控,这里仅为兼容旧调用继续透传
1112
1114
  if ($AllowVersionDrift) { $applyArgs['AllowVersionDrift'] = $true }
1113
1115
  if ($Force) { $applyArgs['Force'] = $true }
1114
1116
  & (Join-Path $PSScriptRoot 'apply.ps1') @applyArgs
@@ -122,9 +122,10 @@ check('设置摘要行展开时 fetch 远端再刷新(远端信息不陈旧)
122
122
  && source.includes("callAuto({ action: 'check' })")
123
123
  && source.includes('setInterval(refreshRemoteNow, 30000)')
124
124
  && source.includes('onClick: refreshRemoteNow'))
125
+ // 0.4.11 等价重构:dirty/uncommitted 读取口径统一抽成 uncommittedOf() helper
125
126
  check('远端「未提交」纳入本机待同步、刷新按钮触发 fetch(0.3.92)',
126
- source.includes('repo.uncommitted ?? repo.dirty')
127
- && source.includes('data.repo.uncommitted ?? data.repo.dirty')
127
+ source.includes('const uncommittedOf = (repo) => (repo?.uncommitted ?? repo?.dirty ?? 0)')
128
+ && source.includes('uncommittedOf(data.repo)')
128
129
  && source.includes('本机待同步 ${data.repo.pending}'))
129
130
  check('设置摘要行两个立即按钮走 pull-now / push-now 队列',
130
131
  source.includes("actNow('pull-now')")
@@ -40,9 +40,17 @@ try {
40
40
  $from = Join-Path $RepoRoot $item
41
41
  if (Test-Path -LiteralPath $from) { Copy-Item -LiteralPath $from -Destination (Join-Path $pkgDir $item) -Recurse }
42
42
  }
43
- # 排除 .git 目录(避免把仓库对象/历史打进 tgz,导致体积爆炸)
44
- Get-ChildItem -LiteralPath $pkgDir -Recurse -Directory -Force -ErrorAction SilentlyContinue |
45
- Where-Object { $_.Name -eq '.git' } |
43
+ # 排除 .git 与临时/备份目录、文件(避免把仓库对象、历史或 apply.ps1.bak-0410 之类临时备份打进 tgz)
44
+ $excludedDirNames = @('.git', '_stage-*', '_v4*', '_refactor-*', '_local-backup-*', '_pre-sync-*')
45
+ $excludedFilePatterns = @('*.bak*', '*.tmp')
46
+ Get-ChildItem -LiteralPath $pkgDir -Recurse -Force -ErrorAction SilentlyContinue |
47
+ Where-Object {
48
+ $hitDir = $false
49
+ foreach ($pattern in $excludedDirNames) { if ($_.PSIsContainer -and $_.Name -like $pattern) { $hitDir = $true; break } }
50
+ $hitFile = $false
51
+ foreach ($pattern in $excludedFilePatterns) { if (-not $_.PSIsContainer -and $_.Name -like $pattern) { $hitFile = $true; break } }
52
+ $hitDir -or $hitFile
53
+ } |
46
54
  ForEach-Object { Remove-Item -LiteralPath $_.FullName -Recurse -Force -ErrorAction SilentlyContinue }
47
55
  # package.json 必须带进包(npm 装包靠它认入口)
48
56
  Copy-Item -LiteralPath $pkgFile -Destination (Join-Path $pkgDir 'package.json') -Force
@@ -968,9 +968,8 @@ if (pullNote.statusCode === 400) {
968
968
  }
969
969
 
970
970
  // 配置仓库根目录那 6 个执行体,是「插件还没装 / 正在升级」时的兜底副本。
971
- // 它们一直靠人工同步,结果漂成半新半旧:sync/apply/common/post-exit 已升到 0.3.23,
972
- // capture/restore 还停在两天前的旧版 —— 平时不显形,只有 pull 真正走进「仓库副本」
973
- // 那条兜底路才会跑到旧逻辑。所以按字节比对,漂了就报,不再指望人记得。
971
+ // 版本不同步时平时不显形,只有 pull 真正走进「仓库副本」那条兜底路才会跑到旧逻辑;
972
+ // 因此按字节比对,漂了就报,不再指望人工记得同步。
974
973
  console.log('')
975
974
  console.log('== 配置仓库执行体副本一致性 ==')
976
975
  const execNames = ['apply.ps1', 'capture.ps1', 'dsh-sync-common.ps1', 'post-exit.ps1', 'restore.ps1', 'sync.ps1']
@@ -991,7 +990,7 @@ if (!existsSync(repoArg) || !existsSync(pluginRuntime) || !repoReady) {
991
990
  else if (!existsSync(source)) detail = `插件 runtime 没有 ${name}`
992
991
  else {
993
992
  same = readFileSync(mirror).equals(readFileSync(source))
994
- if (!same) detail = `副本 ${readFileSync(mirror).length}B / 正本 ${readFileSync(source).length}B,跑 tools/sync-plugin-mirror.ps1 重新同步`
993
+ if (!same) detail = `副本 ${readFileSync(mirror).length}B / 正本 ${readFileSync(source).length}B,按 runtime/sync.ps1 重新同步执行体副本`
995
994
  }
996
995
  check(`执行体副本与插件 runtime 逐字节一致:${name}`, same, detail)
997
996
  }
@@ -1000,13 +999,13 @@ if (!existsSync(repoArg) || !existsSync(pluginRuntime) || !repoReady) {
1000
999
  const sourceTool = join(pluginRuntime, 'tools', 'fix-session-cwd.mjs')
1001
1000
  const toolSame = existsSync(mirrorTool) && existsSync(sourceTool) && readFileSync(mirrorTool).equals(readFileSync(sourceTool))
1002
1001
  check('执行体副本与插件 runtime 逐字节一致:tools/fix-session-cwd.mjs', toolSame,
1003
- existsSync(mirrorTool) ? '内容已漂移,跑 tools/sync-plugin-mirror.ps1 重新同步' : '配置仓库没有 tools/fix-session-cwd.mjs')
1002
+ existsSync(mirrorTool) ? '内容已漂移,按 runtime/sync.ps1 重新同步执行体副本' : '配置仓库没有 tools/fix-session-cwd.mjs')
1004
1003
  for (const tname of ['session-log-guard.mjs', 'session-log-lib.mjs', 'bili-state.mjs']) {
1005
1004
  const m = join(repoArg, 'tools', tname)
1006
1005
  const s = join(pluginRuntime, 'tools', tname)
1007
1006
  const ok = existsSync(m) && existsSync(s) && readFileSync(m).equals(readFileSync(s))
1008
1007
  check(`执行体副本与插件 runtime 逐字节一致:tools/${tname}`, ok,
1009
- !existsSync(m) ? `配置仓库没有 tools/${tname}` : (existsSync(s) ? '内容已漂移,跑 tools/sync-plugin-mirror.ps1 重新同步' : `插件 runtime 没有 tools/${tname}`))
1008
+ !existsSync(m) ? `配置仓库没有 tools/${tname}` : (existsSync(s) ? '内容已漂移,按 runtime/sync.ps1 重新同步执行体副本' : `插件 runtime 没有 tools/${tname}`))
1010
1009
  }
1011
1010
  }
1012
1011
 
@@ -1048,11 +1047,16 @@ console.log('== 空白本机仓库:只允许拉取 ==')
1048
1047
  check('只有插件自己生成的 同步-*.cmd 与隐藏项算「空」',
1049
1048
  /同步-\[\\s\\S\]\*\\?\.cmd/i.test(indexNew) || /同步-\[/i.test(indexNew),
1050
1049
  'empty 判据没有排除 同步-*.cmd:生成过脚本之后就会被误判成 unusable')
1050
+ // 0.4.11 等价重构:门禁判据抽成 canPush()/canPull() 单一来源,内联判据改调用;断言同时覆盖函数定义与调用点
1051
1051
  check('status 暴露 phase / remoteFiles / pushAllowed / pullAllowed',
1052
1052
  /phase,\s*\n\s*empty: phase === 'empty'/.test(indexNew)
1053
1053
  && /remoteFiles,/.test(indexNew) && /remoteEmpty: remoteFiles === 0/.test(indexNew)
1054
- && /pushAllowed: phase === 'ok' \|\| \(phase === 'empty' && remoteFiles === 0\)/.test(indexNew)
1055
- && /pullAllowed: phase === 'ok' \|\| \(\(phase === 'empty' \|\| phase === 'missing'\) && remoteFiles !== 0\)/.test(indexNew),
1054
+ && (/pushAllowed: phase === 'ok' \|\| \(phase === 'empty' && remoteFiles === 0\)/.test(indexNew)
1055
+ || (/pushAllowed: canPush\(phase, remoteFiles\)/.test(indexNew)
1056
+ && /function canPush\(phase, remoteFiles\)/.test(indexNew)))
1057
+ && (/pullAllowed: phase === 'ok' \|\| \(\(phase === 'empty' \|\| phase === 'missing'\) && remoteFiles !== 0\)/.test(indexNew)
1058
+ || (/pullAllowed: canPull\(phase, remoteFiles\)/.test(indexNew)
1059
+ && /function canPull\(phase, remoteFiles\)/.test(indexNew))),
1056
1060
  'status 没有暴露新门禁字段(remoteFiles / pushAllowed / pullAllowed),面板只能靠分支数猜')
1057
1061
  check('仓库三态 mode(ok / await-pull / await-init)按文件数算',
1058
1062
  /mode: phase === 'ok'[\s\S]{0,120}?remoteFiles === 0 \? 'await-init' : 'await-pull'/.test(indexNew),
@@ -1972,8 +1976,9 @@ console.log('')
1972
1976
  console.log('== 0.4.05:定时复查预排 watcher,不依赖前端信标 ==')
1973
1977
  {
1974
1978
  const idxSrc = readFileSync(join(pluginRootSelf, 'index.js'), 'utf8')
1979
+ // 0.4.11 等价重构:调用点新增 driftOverride 复用本次复查的 drift,核心参数不变
1975
1980
  check('scheduleAutoStart 的 run 调用 checkAndQueueAutoSync 预排 watcher',
1976
- /await checkAndQueueAutoSync\(dshHome, config, settings, repo, appRoot, \{ shouldCloseDsh: false, isPeriodic: true \}\)/.test(idxSrc), 'index.js 定时预排')
1981
+ /await checkAndQueueAutoSync\(dshHome, config, settings, repo, appRoot, \{ shouldCloseDsh: false, isPeriodic: true(?:, driftOverride: drift)? \}\)/.test(idxSrc), 'index.js 定时预排')
1977
1982
  check('checkAndQueueAutoSync 支持 isPeriodic 参数',
1978
1983
  /isPeriodic = false/.test(idxSrc) && /isManualTrigger/.test(idxSrc), 'index.js isPeriodic 参数')
1979
1984
  check('定时复查无人值守不弹确认框',