dsh-xdpool 2.6.3 → 2.6.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/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
  本项目的所有重要变更都会记录在此文件。
3
3
  版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
+ ## 2.6.4 — postinstall 真的会跑了
5
+
6
+ 2.6.3 的修复方向是对的,但 的改动在合并时丢了:`postinstall` 没挂上,`scripts/` 也没进 `files`。结果是 npm 上的 2.6.3 依然缺 peer 依赖,靠的是此前手动建的 junction。
7
+
8
+ 现在两者都补齐,并核对 `npm pack` 的内容确实包含 `scripts/link-host-peers.mjs`。
9
+
4
10
  ## 2.6.3 — 修掉 2.6.2 装上后插件起不来的问题
5
11
 
6
12
  > 2.6.2 从 npm 安装后,插件导入失败(`Cannot find package '@earendil-works/pi-ai'`),
package/lib/client.js CHANGED
@@ -13460,7 +13460,7 @@ window.__ModuleLoader__.load({
13460
13460
  *
13461
13461
  * @module dsh-xdpool/version
13462
13462
  */
13463
- const POOL_VERSION = "2.6.3";
13463
+ const POOL_VERSION = "2.6.4";
13464
13464
  //#endregion
13465
13465
  //#region src/client/PoolCard.tsx
13466
13466
  /**
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-xdpool",
3
3
  "displayName": "DSH XD Pool",
4
4
  "description": "One DSH model pool for every free quota you have: merge all locally signed-in WorkBuddy accounts with auto-failover, sign in to 13 vendors by QR/web, aggregate 76 vendors' free tiers, plus a usage dashboard, model routing, a local OpenAI-compatible gateway and a points-automation suite.",
5
- "version": "2.6.3",
5
+ "version": "2.6.4",
6
6
  "license": "MIT",
7
7
  "author": "XDTrees",
8
8
  "homepage": "https://github.com/XDTrees/dsh-xdpool#readme",
@@ -51,14 +51,16 @@
51
51
  "README.md",
52
52
  "README.en.md",
53
53
  "CHANGELOG.md",
54
- "LICENSE"
54
+ "LICENSE",
55
+ "scripts"
55
56
  ],
56
57
  "scripts": {
57
58
  "build": "tsdown",
58
59
  "prepublishOnly": "tsdown",
59
60
  "test": "vitest run",
60
61
  "typecheck": "tsc -p tsconfig.json --noEmit",
61
- "typecheck:client": "tsc -p tsconfig.client.json --noEmit"
62
+ "typecheck:client": "tsc -p tsconfig.client.json --noEmit",
63
+ "postinstall": "node scripts/link-host-peers.mjs"
62
64
  },
63
65
  "dsh": {
64
66
  "bundle": {
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Link the host-provided peer dependencies into this package's node_modules.
3
+ *
4
+ * WHY THIS IS NEEDED
5
+ *
6
+ * Seven of this plugin's dependencies are `peerDependencies`: they are supplied by the
7
+ * host, not by npm. A manual copy of the package into `node_modules/dsh-xdpool` resolved
8
+ * them by walking up to the host's own tree, so nothing was ever missing. Installing
9
+ * normally breaks that walk: the package ends up beside the host rather than inside it,
10
+ * and `import` fails with
11
+ *
12
+ * Cannot find package '@earendil-works/pi-ai'
13
+ *
14
+ * which — being a top-level import failure — prevents `apply()` from ever running, so
15
+ * EVERY web route is unregistered and the card renders empty while blaming the gateway.
16
+ *
17
+ * WHAT IT DOES
18
+ *
19
+ * For each peer dependency, find a copy the host actually runs with and point
20
+ * `node_modules/<name>` at it. Junctions on Windows, symlinks elsewhere. Skipped when a
21
+ * copy already resolves — an operator who installed a peer deliberately keeps theirs.
22
+ *
23
+ * WHERE IT LOOKS
24
+ *
25
+ * `DSH_HOST_ROOT` when set (the harness passes it), then the paths a packaged DSH
26
+ * install actually uses. Both `resources/app/node_modules` and
27
+ * `resources/app/dsh/node_modules` are searched because the host splits its tree between
28
+ * them: `pi-ai` lives in the latter, `cordis` in the former.
29
+ *
30
+ * FAILURE IS LOUD ON PURPOSE
31
+ *
32
+ * A silently skipped link is what produced the blank panel. If a peer cannot be found the
33
+ * script says which one and exits non-zero, so the install fails visibly instead of
34
+ * producing a package that cannot load.
35
+ */
36
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, symlinkSync } from 'node:fs'
37
+ import { createRequire } from 'node:module'
38
+ import { dirname, join, resolve } from 'node:path'
39
+ import { fileURLToPath } from 'node:url'
40
+
41
+ const HERE = dirname(fileURLToPath(import.meta.url))
42
+ const PACKAGE_ROOT = resolve(HERE, '..')
43
+ const REQUIRE = createRequire(import.meta.url)
44
+
45
+ /** The peer dependencies this plugin imports at runtime. */
46
+ function peerNames() {
47
+ const manifest = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf8'))
48
+ return Object.keys(manifest.peerDependencies ?? {})
49
+ }
50
+
51
+ /**
52
+ * Candidate host module roots, most specific first.
53
+ *
54
+ * Derived from this file's own location as well, because when the host loads the plugin
55
+ * from `app/dsh/node_modules`, two levels up IS the host root.
56
+ */
57
+ function hostRoots() {
58
+ const roots = []
59
+ const env = process.env['DSH_HOST_ROOT']
60
+ if (typeof env === 'string' && env !== '') roots.push(env)
61
+ // `<host>/resources/app/dsh/node_modules/dsh-xdpool` → `<host>/resources/app/dsh/node_modules`
62
+ roots.push(resolve(PACKAGE_ROOT, '..'))
63
+ // A source checkout beside the harness: look for the resources tree directly.
64
+ for (const base of [process.env['LOCALAPPDATA'], process.env['PROGRAMFILES']]) {
65
+ if (typeof base !== 'string' || base === '') continue
66
+ roots.push(join(base, 'DeepSeek Harness', 'resources', 'app', 'dsh', 'node_modules'))
67
+ roots.push(join(base, 'DeepSeek Harness', 'resources', 'app', 'node_modules'))
68
+ }
69
+ return roots
70
+ }
71
+
72
+ /** Resolve a package's directory without importing it. */
73
+ function locate(name) {
74
+ try {
75
+ return dirname(REQUIRE.resolve(`${name}/package.json`))
76
+ } catch {
77
+ // Some packages do not export package.json; fall back to the resolver's own answer.
78
+ try {
79
+ const entry = REQUIRE.resolve(name)
80
+ // Walk up to the package root — the first directory whose name is the package's.
81
+ let dir = dirname(entry)
82
+ const wanted = name.startsWith('@') ? name.split('/')[1] : name
83
+ while (dir !== dirname(dir)) {
84
+ if (dir.endsWith(`/${wanted}`) || dir.endsWith(`\\${wanted}`)) return dir
85
+ dir = dirname(dir)
86
+ }
87
+ } catch {
88
+ return undefined
89
+ }
90
+ return undefined
91
+ }
92
+ }
93
+
94
+ /**
95
+ * When to ENFORCE.
96
+ *
97
+ * This runs on `postinstall` of the published package, where a missing peer really does
98
+ * mean a plugin that cannot load — and it must fail loudly there. But the same script also
99
+ * runs when someone installs the repository for development or CI, where the host does not
100
+ * exist and the peers are resolved from `devDependencies` instead. Failing there would
101
+ * break every fresh clone and every pipeline for a condition that is not a problem.
102
+ *
103
+ * The two cases are told apart by whether this is a source checkout: `src/` ships in the
104
+ * repository and not in the tarball (`files` lists `lib`, `vendor`, `scripts`…).
105
+ */
106
+ const IS_SOURCE_CHECKOUT = existsSync(join(PACKAGE_ROOT, 'src'))
107
+ const ENFORCE = !IS_SOURCE_CHECKOUT
108
+
109
+ const linked = []
110
+ const missing = []
111
+ for (const name of peerNames()) {
112
+ // Already resolvable: leave it alone. Someone who installed a peer on purpose keeps
113
+ // control, and re-linking would overwrite that choice.
114
+ if (locate(name) !== undefined) continue
115
+ let target
116
+ for (const root of hostRoots()) {
117
+ const candidate = join(root, name)
118
+ if (existsSync(candidate)) { target = candidate; break }
119
+ }
120
+ if (target === undefined) { missing.push(name); continue }
121
+ const dest = join(PACKAGE_ROOT, 'node_modules', name)
122
+ try {
123
+ mkdirSync(dirname(dest), { recursive: true })
124
+ // A previous run may have left a link (or a partial one); replacing it is correct
125
+ // because the resolve check above already skipped anything that works.
126
+ if (existsSync(dest)) rmSync(dest, { recursive: true, force: true })
127
+ // Junction on Windows because creating a real symlink needs elevation there; a
128
+ // junction needs none and behaves the same for directory reads.
129
+ symlinkSync(target, dest, process.platform === 'win32' ? 'junction' : 'dir')
130
+ linked.push(`${name} → ${target}`)
131
+ } catch (error) {
132
+ missing.push(`${name} (${error instanceof Error ? error.message : String(error)})`)
133
+ }
134
+ }
135
+
136
+ if (linked.length > 0) {
137
+ process.stdout.write(`dsh-xdpool: linked ${String(linked.length)} host dependency(ies)\n`)
138
+ for (const line of linked) process.stdout.write(` ${line}\n`)
139
+ }
140
+ if (missing.length > 0) {
141
+ const where = IS_SOURCE_CHECKOUT
142
+ ? 'a source checkout, so the host is not expected to be present'
143
+ : 'an installed package, where a missing peer prevents the plugin from loading'
144
+ process.stderr.write(
145
+ `dsh-xdpool: could not satisfy ${String(missing.length)} peer dependency(ies) `
146
+ + `(${where}):\n`
147
+ + missing.map(name => ` ${name}\n`).join(''),
148
+ )
149
+ if (ENFORCE) {
150
+ process.stderr.write(
151
+ 'The plugin will fail to load without them. Install them into this profile, or set\n'
152
+ + 'DSH_HOST_ROOT to the directory containing node_modules.\n',
153
+ )
154
+ // Hard failure on purpose: a silently skipped link is what produced a package that
155
+ // installed cleanly and then could not load at all.
156
+ process.exit(1)
157
+ }
158
+ // A source checkout keeps going: `devDependencies` provide these for build and test,
159
+ // and CI has no harness to link against. Failing here would break the pipeline for a
160
+ // condition that is not a defect.
161
+ process.stdout.write('dsh-xdpool: continuing — this looks like a development checkout\n')
162
+ } else {
163
+ /**
164
+ * Self-check: confirm every peer RESOLVES from the package root.
165
+ *
166
+ * Not a full `import` of the entry: that would also pull the host's own runtime (cordis,
167
+ * the llm plumbing) and can only succeed inside a live harness, so it would fail in a
168
+ * source checkout and in CI for a reason unrelated to this script's job.
169
+ *
170
+ * Resolution is the exact property that broke: a top-level import failure aborts
171
+ * `apply()`, and every web route then goes unregistered while the card blames the
172
+ * gateway. Checking `require.resolve` from inside the package reproduces that failure
173
+ * without needing the host running.
174
+ */
175
+ const unresolved = []
176
+ const localRequire = createRequire(join(PACKAGE_ROOT, 'lib', 'index.js'))
177
+ for (const name of peerNames()) {
178
+ try {
179
+ localRequire.resolve(name)
180
+ } catch {
181
+ unresolved.push(name)
182
+ }
183
+ }
184
+ if (unresolved.length > 0) {
185
+ process.stderr.write(
186
+ `dsh-xdpool: ${String(unresolved.length)} peer dependency(ies) still do not resolve:\n`
187
+ + unresolved.map(name => ` ${name}\n`).join(''),
188
+ )
189
+ // Same split as above: fatal for an installed package, informational in a checkout.
190
+ if (ENFORCE) process.exit(1)
191
+ process.stdout.write('dsh-xdpool: continuing — this looks like a development checkout\n')
192
+ } else {
193
+ process.stdout.write('dsh-xdpool: all peer dependencies resolve; the build should load\n')
194
+ }
195
+ }
196
+
197
+ // Keep the unused helper referenced so a tree-shaker cannot hide it if this file is ever
198
+ // bundled; it is intentionally exported for a maintenance script.
199
+ export { readdirSync }