dsh-db-tool 1.7.1 → 1.7.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-db-tool",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "DSH community plugin: chat-operated multi-database admin tool with sidebar management, project-scoped grants, ro/rw modes and dangerous-operation confirmation",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -0,0 +1,155 @@
1
+ <#
2
+ .SYNOPSIS
3
+ 诊断并修复「npm 上已发新版,但本机装不上 / 装到旧版 / 插件链接失效」。
4
+ .DESCRIPTION
5
+ 三类阻塞:① node_modules\dsh-db-tool 是 link 残留或死链;② minimumReleaseAge
6
+ 未豁免目标版本(pnpm 会静默保留旧版并 exit 0);③ allowBuilds 缺 oracledb /
7
+ better-sqlite3(安装报 ERR_PNPM_IGNORED_BUILDS)。默认只诊断,-Apply 才写入。
8
+ .PARAMETER Version
9
+ 目标版本;省略时读包内 package.json 的 version。
10
+ .PARAMETER ProfileDir
11
+ profile 目录;默认 %USERPROFILE%\.dsh\profiles\desktop。
12
+ .PARAMETER Apply
13
+ 执行修复(默认仅诊断)。写入前自动备份。
14
+ .EXAMPLE
15
+ pwsh -File scripts\fix-dsh-install.ps1
16
+ pwsh -File scripts\fix-dsh-install.ps1 -Apply
17
+ #>
18
+ [CmdletBinding()]
19
+ param(
20
+ [string]$Version,
21
+ [string]$ProfileDir,
22
+ [switch]$Apply
23
+ )
24
+
25
+ $ErrorActionPreference = 'Stop'
26
+
27
+ $prof = if ($ProfileDir) { $ProfileDir } else { Join-Path $env:USERPROFILE '.dsh\profiles\desktop' }
28
+ if (-not (Test-Path -LiteralPath $prof)) { throw "找不到 DSH profile:$prof(DSH 桌面端是否装过并启动过?)" }
29
+ $ws = Join-Path $prof 'pnpm-workspace.yaml'
30
+ if (-not (Test-Path -LiteralPath $ws)) { throw "找不到 $ws(profile 尚未初始化)" }
31
+
32
+ if (-not $Version) {
33
+ $pkg = Join-Path $PSScriptRoot '..\package.json'
34
+ $Version = if (Test-Path -LiteralPath $pkg) { (Get-Content -LiteralPath $pkg -Raw | ConvertFrom-Json).version } else { '0.0.0' }
35
+ }
36
+
37
+ # 固定编码,不依赖各 PowerShell 版本的默认值:5.1 的 Get-Content/Set-Content 走 ANSI
38
+ # (会把非 ASCII 写坏),且两者默认都丢 BOM。这两个函数只在脚本自己的读写路径上使用。
39
+ $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
40
+ function Read-Yaml([string]$p) { [System.IO.File]::ReadAllText($p, $utf8NoBom) }
41
+ function Write-Yaml([string]$p, [string]$t) { [System.IO.File]::WriteAllText($p, $t, $utf8NoBom) }
42
+
43
+ # 换行归一化为 LF:CRLF 文件会让 `(?m)$` 锚点全部失效——豁免静默丢失,并写出重复的
44
+ # YAML 段头(pnpm 报 duplicate mapping key,配置直接不可用)。插入统一用 `n。
45
+ $text = (Read-Yaml $ws) -replace "`r`n", "`n"
46
+
47
+ $link = Join-Path $prof 'node_modules\dsh-db-tool'
48
+ $pkgs = @('oracledb', 'better-sqlite3') # 需要执行构建脚本的原生依赖
49
+ $stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
50
+ $fix = @()
51
+
52
+ Write-Host "`n[1/3] 插件链接形态" -ForegroundColor Cyan
53
+ if (Test-Path -LiteralPath $link) {
54
+ $it = Get-Item -LiteralPath $link -Force
55
+ $target = [string]$it.Target
56
+ Write-Host (" node_modules\dsh-db-tool -> {0} : {1}" -f $it.LinkType, $target)
57
+ if ($it.LinkType -eq 'SymbolicLink' -or $it.LinkType -eq 'Junction') {
58
+ # Target 是「as defined」的原样字符串,可能是相对路径;必须按链接所在目录解析,
59
+ # 否则会按当前工作目录误判为死链并删掉一个完好的链接。
60
+ $resolved = if ($target -and -not [System.IO.Path]::IsPathRooted($target)) {
61
+ Join-Path (Split-Path -LiteralPath $link -Parent) $target
62
+ } else { $target }
63
+ if ($resolved -and (Test-Path -LiteralPath $resolved)) {
64
+ Write-Host " [!] 指向真实目录的 link:npm 更新不会生效(加载的是该目录)" -ForegroundColor Yellow
65
+ Write-Host " 如该机不做本地开发,先 remove 再 add 改用 npm 包(见结尾)" -ForegroundColor Yellow
66
+ } else {
67
+ Write-Host " [X] link 目标不存在 -> 安装/加载必定失败" -ForegroundColor Red
68
+ $fix += 'del-dead-link'
69
+ }
70
+ } else {
71
+ Write-Host " OK:正常安装目录(非链接)" -ForegroundColor Green
72
+ }
73
+ } else {
74
+ Write-Host " 未安装(无 node_modules\dsh-db-tool)"
75
+ }
76
+
77
+ Write-Host "`n[2/3] minimumReleaseAge 豁免" -ForegroundColor Cyan
78
+ $m = [regex]::Match($text, '(?m)^[ \t]*-[ \t]*[''"]?dsh-db-tool@([^\r\n]*)')
79
+ if (-not $m.Success) {
80
+ Write-Host " [X] 没有 dsh-db-tool 豁免行 -> 新版本会被年龄窗口拦住" -ForegroundColor Red
81
+ $fix += 'add-exclude'
82
+ } else {
83
+ Write-Host (" 现有:dsh-db-tool@" + $m.Groups[1].Value.TrimEnd())
84
+ # 版本边界:否则 1.7.1 会命中 1.7.10
85
+ $bound = '(?<![\d.])' + [regex]::Escape($Version) + '(?![\d.])'
86
+ if ($m.Groups[1].Value -match $bound) {
87
+ Write-Host " OK:已豁免 $Version" -ForegroundColor Green
88
+ } else {
89
+ Write-Host " [X] 未豁免 $Version -> pnpm 会静默装旧版或报 MINIMUM_RELEASE_AGE_VIOLATION" -ForegroundColor Red
90
+ $fix += 'extend-exclude'
91
+ }
92
+ }
93
+
94
+ Write-Host "`n[3/3] allowBuilds 原生模块白名单" -ForegroundColor Cyan
95
+ $missingAllow = @($pkgs | Where-Object { $text -notmatch ('(?m)^[ \t]*' + [regex]::Escape($_) + ':[ \t]*true') })
96
+ foreach ($n in $pkgs) {
97
+ if ($missingAllow -contains $n) {
98
+ Write-Host " [X] $n 未获允许 -> 安装会以 ERR_PNPM_IGNORED_BUILDS 失败" -ForegroundColor Red
99
+ $fix += "allow-$n"
100
+ } else {
101
+ Write-Host " OK:$n" -ForegroundColor Green
102
+ }
103
+ }
104
+
105
+ Write-Host "`n===== 结论 =====" -ForegroundColor Cyan
106
+ if ($fix.Count -eq 0) {
107
+ Write-Host "未发现阻塞项。" -ForegroundColor Green
108
+ } else {
109
+ Write-Host ("待处理 $($fix.Count) 项(见上方 [X])") -ForegroundColor Yellow
110
+ }
111
+
112
+ if (-not $Apply) {
113
+ Write-Host "`n(诊断模式:未做任何修改。确认后加 -Apply 执行修复)"
114
+ return
115
+ }
116
+
117
+ $new = $text
118
+ if ($fix -contains 'del-dead-link') { Remove-Item -LiteralPath $link -Force }
119
+
120
+ if ($fix -contains 'extend-exclude') {
121
+ # 保留原行的引号与前缀,只追加版本(pnpm 对同名包只认第一条,故必须改原行)
122
+ $new = $new -replace '(?m)^([ \t]*-[ \t]*[''"]?dsh-db-tool@[^\r\n]*?)[ \t]*$', ('$1 || ' + $Version)
123
+ }
124
+ if ($fix -contains 'add-exclude') {
125
+ if ($new -match '(?m)^minimumReleaseAgeExclude:[ \t]*$') {
126
+ $new = $new -replace '(?m)^(minimumReleaseAgeExclude:[ \t]*)$', ('$1' + "`n - dsh-db-tool@$Version")
127
+ } else {
128
+ # 段头缺失:插入无处可落,必须整段追加,否则静默无变更却报告成功
129
+ $new = $new.TrimEnd() + "`nminimumReleaseAgeExclude:`n - dsh-db-tool@$Version`n"
130
+ }
131
+ }
132
+ if ($missingAllow.Count -gt 0) {
133
+ # 一次性补齐:逐项插入会各插一次段头,产出重复的 YAML 键
134
+ $block = ($missingAllow | ForEach-Object { ' ' + $_ + ': true' }) -join "`n"
135
+ if ($new -match '(?m)^allowBuilds:[ \t]*$') {
136
+ $new = $new -replace '(?m)^(allowBuilds:[ \t]*)$', ('$1' + "`n" + $block)
137
+ } else {
138
+ $new = $new.TrimEnd() + "`nallowBuilds:`n" + $block + "`n"
139
+ }
140
+ }
141
+
142
+ if ($new -eq $text) {
143
+ Write-Host "`n无需写入(配置已是目标状态)。" -ForegroundColor Green
144
+ } else {
145
+ Copy-Item -LiteralPath $ws -Destination "$ws.bak-$stamp" -Force
146
+ Write-Yaml $ws $new
147
+ Write-Host "`n已更新 pnpm-workspace.yaml(备份:pnpm-workspace.yaml.bak-$stamp)" -ForegroundColor Green
148
+ }
149
+
150
+ Write-Host "`n===== 下一步 =====" -ForegroundColor Cyan
151
+ Write-Host " 1) 完全退出并重启 DSH 桌面端"
152
+ Write-Host " 2) 若上面提示过 link,先移除再安装:"
153
+ Write-Host ' & "<DSH安装目录>\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop remove dsh-db-tool'
154
+ Write-Host " 3) 安装目标版本:"
155
+ Write-Host (' & "<DSH安装目录>\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add dsh-db-tool@' + $Version + ' --registry=https://registry.npmjs.org/')