dsh-crate 0.5.2 → 0.5.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/assets/logo.svg +11 -33
- package/client/client.js +2271 -561
- package/lib/body-progress.js +4 -3
- package/lib/changelog.js +15 -2
- package/lib/discovery-cache.js +210 -0
- package/lib/discovery-compatibility.js +135 -90
- package/lib/drain.js +28 -9
- package/lib/dsh-cli.js +36 -6
- package/lib/github-install-target.js +53 -0
- package/lib/hot.js +400 -33
- package/lib/index.js +23 -9
- package/lib/install.js +37 -0
- package/lib/patch.js +123 -73
- package/lib/pending-rows.js +3 -4
- package/lib/pnpm-compat.js +234 -2
- package/lib/proc-text.js +16 -1
- package/lib/profile.js +17 -1
- package/lib/recovery.js +2 -1
- package/lib/registry.js +24 -16
- package/lib/release-candidates.js +4 -0
- package/lib/release-updates.js +9 -2
- package/lib/routes.js +459 -134
- package/lib/themes.js +42 -9
- package/lib/types/body-progress.d.ts +2 -1
- package/lib/types/changelog.d.ts +10 -1
- package/lib/types/discovery-cache.d.ts +38 -0
- package/lib/types/discovery-compatibility.d.ts +24 -14
- package/lib/types/dsh-cli.d.ts +19 -2
- package/lib/types/github-install-target.d.ts +11 -0
- package/lib/types/hot.d.ts +91 -7
- package/lib/types/index.d.ts +17 -0
- package/lib/types/install.d.ts +19 -0
- package/lib/types/patch.d.ts +6 -2
- package/lib/types/profile.d.ts +4 -1
- package/lib/types/registry.d.ts +9 -8
- package/lib/types/release-candidates.d.ts +2 -0
- package/lib/types/routes.d.ts +2 -2
- package/lib/types/themes.d.ts +7 -1
- package/lib/types/update-notification-settings.d.ts +5 -0
- package/lib/types/update-notifications.d.ts +51 -0
- package/lib/types/updates.d.ts +5 -1
- package/lib/update-notification-settings.js +6 -0
- package/lib/update-notifications.js +166 -0
- package/lib/updates.js +41 -11
- package/lib/verify.js +24 -2
- package/package.json +1 -1
package/lib/pnpm-compat.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { existsSync, readFileSync } from 'node:fs';
|
|
17
17
|
import { join } from 'node:path';
|
|
18
18
|
import { CHINA_NPM_REGISTRY } from './regions.js';
|
|
19
|
+
import { classifyPeer } from './compatibility.js';
|
|
19
20
|
/**
|
|
20
21
|
* Decide the argv for a `dsh plugin <add|remove> …` call in the given profile.
|
|
21
22
|
*
|
|
@@ -251,6 +252,173 @@ function storesFromNdjson(output) {
|
|
|
251
252
|
function storeVersionSegment(path) {
|
|
252
253
|
return path === undefined ? undefined : /[/\\](v\d+)[/\\]*$/.exec(path)?.[1];
|
|
253
254
|
}
|
|
255
|
+
function readStorePin(profileDirectory) {
|
|
256
|
+
if (profileDirectory === undefined)
|
|
257
|
+
return null;
|
|
258
|
+
let yaml;
|
|
259
|
+
try {
|
|
260
|
+
yaml = readFileSync(join(profileDirectory, 'pnpm-workspace.yaml'), 'utf8');
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
const camel = /^storeDir:[ \t]*['"]?([^'"\r\n]+?)['"]?[ \t]*$/mu.exec(yaml);
|
|
266
|
+
if (camel !== null)
|
|
267
|
+
return { path: camel[1].trim(), honoured: true };
|
|
268
|
+
const kebab = /^store-dir:[ \t]*['"]?([^'"\r\n]+?)['"]?[ \t]*$/mu.exec(yaml);
|
|
269
|
+
return kebab === null ? null : { path: kebab[1].trim(), honoured: false };
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* The store pnpm takes from the environment, which outranks the profile's
|
|
273
|
+
* own pnpm-workspace.yaml.
|
|
274
|
+
*
|
|
275
|
+
* Measured on pnpm 11.28.5 with a profile pinning one store: setting
|
|
276
|
+
* `PNPM_CONFIG_STORE_DIR` (or the lowercase `pnpm_config_store_dir`) to
|
|
277
|
+
* another path made `pnpm store path` print that other path. `npm_config_
|
|
278
|
+
* store_dir` did NOT — verified twice, with and without a workspace pin — so
|
|
279
|
+
* it is deliberately not read here: naming a variable that changes nothing
|
|
280
|
+
* would send the reader to the wrong place.
|
|
281
|
+
*/
|
|
282
|
+
function storeFromEnvironment() {
|
|
283
|
+
for (const [name, value] of Object.entries(process.env)) {
|
|
284
|
+
if (value !== undefined && value !== '' && /^pnpm_config_store_dir$/iu.test(name))
|
|
285
|
+
return { name, value };
|
|
286
|
+
}
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
/** Two store paths the same, tolerating separator style and Windows case. */
|
|
290
|
+
function sameStorePath(left, right) {
|
|
291
|
+
const normalise = (path) => path.replace(/\\/gu, '/').replace(/\/+$/u, '').toLowerCase();
|
|
292
|
+
return normalise(left) === normalise(right);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* The way out of ERR_PNPM_UNEXPECTED_STORE, said in terms of the layer that
|
|
296
|
+
* actually decides the store (#244, #715; the layer order below was measured).
|
|
297
|
+
*
|
|
298
|
+
* The old text told every user the same thing: write the recorded store into
|
|
299
|
+
* the profile's pnpm-workspace.yaml. That is right for exactly one of the
|
|
300
|
+
* shapes this error has, and wrong — silently, repeatedly — for the others:
|
|
301
|
+
*
|
|
302
|
+
* - the file may already carry that line, in which case repeating the advice
|
|
303
|
+
* is a loop (the reporter's profile had it, and the fix that worked was
|
|
304
|
+
* elsewhere);
|
|
305
|
+
* - it may carry the kebab spelling, which pnpm ignores with a warning;
|
|
306
|
+
* - it may carry a DIFFERENT path from the record, so following "write the
|
|
307
|
+
* recorded store" means first seeing the two disagree;
|
|
308
|
+
* - an environment variable outranks the file, so on those machines the
|
|
309
|
+
* advice cannot work at all until the variable is changed;
|
|
310
|
+
* - the recorded store may no longer exist (the drive was moved or removed),
|
|
311
|
+
* and pinning a dead path is worse than the error it replaces.
|
|
312
|
+
*
|
|
313
|
+
* Each of those is readable from files and the environment the market already
|
|
314
|
+
* has, so the message can name the one that applies — and give a command that
|
|
315
|
+
* proves the result, since this is the branch where "I followed the advice and
|
|
316
|
+
* nothing changed" has been the actual experience.
|
|
317
|
+
*/
|
|
318
|
+
function storeRelinkAdvice(linked, wanted, profileDirectory) {
|
|
319
|
+
const pin = readStorePin(profileDirectory);
|
|
320
|
+
const env = storeFromEnvironment();
|
|
321
|
+
const envWins = env !== null && !sameStorePath(env.value, linked);
|
|
322
|
+
const wantedZh = wanted ?? '(上面列出的那个)';
|
|
323
|
+
const wantedEn = wanted ?? 'the one listed above';
|
|
324
|
+
const paste = `storeDir: '${linked}'`;
|
|
325
|
+
const verifyZh = '改完先在 profile 目录里执行 `pnpm store path` 验证:它必须**正好**打印上面第一个路径;打出别的就说明这一行没有生效,先别急着重试。';
|
|
326
|
+
const verifyEn = 'Verify before retrying: run `pnpm store path` in the profile directory — it must print the first path above, exactly. Anything else means that line did not take effect.';
|
|
327
|
+
const envZh = env === null ? '' : `(当前环境里 ${env.name}=${env.value})`;
|
|
328
|
+
const envEn = env === null ? '' : ` (currently ${env.name}=${env.value} in this environment)`;
|
|
329
|
+
const ladderZh = 'pnpm 解析 store 的优先级(高→低):--store-dir 命令行参数 → 环境变量 PNPM_CONFIG_STORE_DIR → profile 的 pnpm-workspace.yaml → 全局 pnpm 配置(`pnpm config get store-dir` 看到的就是它)→ 默认位置。';
|
|
330
|
+
const ladderEn = "The order pnpm resolves a store in (highest first): the --store-dir flag → the environment variable PNPM_CONFIG_STORE_DIR → the profile's pnpm-workspace.yaml → the global pnpm config (what `pnpm config get store-dir` reports) → the default location.";
|
|
331
|
+
// The file already names the recorded store and the error is still here:
|
|
332
|
+
// repeating the advice cannot help. Say which layer outranked it. Checked
|
|
333
|
+
// before the "different path" case, because same-path-plus-still-failing is
|
|
334
|
+
// the loop this branch exists to end.
|
|
335
|
+
if (pin !== null && pin.honoured && sameStorePath(pin.path, linked)) {
|
|
336
|
+
const causeZh = envWins
|
|
337
|
+
? `**上面那个环境变量把它覆盖了**:${env.name}=${env.value} 比 profile 文件优先,所以把 storeDir 改多少遍都没有用。`
|
|
338
|
+
: '覆盖它的是更高优先级的一层,而这个文件本身已经没有可改的地方了。';
|
|
339
|
+
const causeEn = envWins
|
|
340
|
+
? `**The environment variable above overrides it**: ${env.name}=${env.value} outranks the profile file, so editing storeDir there changes nothing.`
|
|
341
|
+
: 'A higher-priority layer overrides it, and there is nothing left to change in this file.';
|
|
342
|
+
return {
|
|
343
|
+
zh: `profile 的 pnpm-workspace.yaml 已经写了 storeDir: '${pin.path}'(就是记录里的那个 store),pnpm 却仍然解析到 ${wantedZh}:这说明这一行被更高优先级的东西压住了,再改这个文件不会有任何效果。${causeZh}${ladderZh}把上面那一层改成这个路径,或者去掉它让文件生效${envWins ? `(在这个环境里,去掉 ${env.name} 往往比改它更省事)` : ''}。${verifyZh}`,
|
|
344
|
+
en: `the profile's pnpm-workspace.yaml already pins storeDir: '${pin.path}' — the recorded store — yet pnpm still resolves ${wantedEn}, so a higher-priority layer overrides the file and editing it cannot help. ${causeEn} ${ladderEn} Change that layer to this path, or remove it so the file applies${envWins ? ` (in this environment, dropping ${env.name} is usually simpler than rewriting it)` : ''}. ${verifyEn}`,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
// A pin in the file that names something else: the file beats the global
|
|
348
|
+
// config, so the line is the right seat for the fix — but it must be
|
|
349
|
+
// corrected rather than added a second time.
|
|
350
|
+
if (pin !== null && pin.honoured && !envWins) {
|
|
351
|
+
return {
|
|
352
|
+
zh: `profile 的 pnpm-workspace.yaml 里写的是 storeDir: '${pin.path}',但 node_modules 记录的是上面第一个路径——两处不一致,pnpm 会按文件里的走,于是继续对不上。把这一行改成记录里的那个路径:\n\n ${paste}\n\n${verifyZh}`,
|
|
353
|
+
en: `the profile's pnpm-workspace.yaml pins storeDir: '${pin.path}' while node_modules records the first path above, so pnpm follows the file and still disagrees with the record. Change that line to the recorded path:\n\n ${paste}\n\n${verifyEn}`,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
// The file pins something in a spelling this pnpm does not read.
|
|
357
|
+
if (pin !== null && !pin.honoured) {
|
|
358
|
+
return {
|
|
359
|
+
zh: `profile 的 pnpm-workspace.yaml 里写的是 kebab 写法 store-dir: '${pin.path}'——pnpm **不认这个键**(它只在 stderr 留一行 WARN,然后当作没写,pnpm 11.28 实测),所以现在解析到的还是 ${wantedZh}。改成驼峰写法(单引号,Windows 路径在双引号里会被当成转义):\n\n ${paste}\n\n${envWins ? `另外,${env.name}=${env.value} 的优先级比这个文件更高,它还在的时候这一行同样不起作用。` : ''}${verifyZh}`,
|
|
360
|
+
en: `the profile's pnpm-workspace.yaml spells it the kebab way, store-dir: '${pin.path}' — a key this pnpm does **not** read (it prints one WARN to stderr and behaves as if the line were absent; measured on 11.28.5), so pnpm still resolves ${wantedEn}. Use the camelCase key with single quotes (a Windows path in double quotes is read as escape sequences):\n\n ${paste}\n\n${envWins ? `Also, ${env.name}=${env.value} outranks this file, so the line still would not apply while it is set. ` : ''}${verifyEn}`,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
// Nothing pinned yet: the ordinary case. When the environment is what pnpm
|
|
364
|
+
// obeys, that is the layer to change — the file loses to it unconditionally.
|
|
365
|
+
if (envWins) {
|
|
366
|
+
return {
|
|
367
|
+
zh: `现在生效的是**环境变量**${envZh},它比 profile 的 pnpm-workspace.yaml 优先——文件里的 storeDir 写了也会被它压住,所以改那个文件没有任何作用。要改的是这一层:把 ${env.name} 指向上面第一个路径,或者去掉它(让 pnpm 回到全局配置 / 默认位置),然后再验证。${ladderZh}${verifyZh}`,
|
|
368
|
+
en: `the store in effect comes from **the environment**${envEn}, which outranks the profile's pnpm-workspace.yaml — a storeDir written there is overridden, so editing that file cannot work. Change this layer instead: point ${env.name} at the first path above, or remove it (letting pnpm fall back to the global config / default), then verify. ${ladderEn}${verifyEn}`,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
zh: `持久的修法:把**记录里的那个** store 写进 profile 的 pnpm-workspace.yaml,顶层、驼峰、单引号(Windows 路径在双引号里会被当成转义,整份文件会读不了):\n\n ${paste}\n\n加完不用重装任何东西——包本来就在那个 store 里,直接重试即可(dsh 正在运行可能占用文件,必要时先退出 dsh)。${verifyZh}如果那个路径其实已经不存在了(盘换了、目录被删),写它只会把 profile 钉在一个空 store 上,那就只能改用 pnpm 现在解析出的这个(包要重新下载)。`,
|
|
373
|
+
en: `durable fix: write the store from the RECORD into the profile's pnpm-workspace.yaml, top level, camelCase, single quotes (a Windows path in double quotes is read as escape sequences and the whole file fails to parse):\n\n ${paste}\n\nNothing has to be reinstalled — the packages are already in that store, so just retry (stop dsh first if it holds the files open). ${verifyEn}If that path no longer exists (the drive changed, the directory was deleted), pinning it would tie the profile to an empty store — adopt the store pnpm now resolves instead (every package is downloaded again).`,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
/** The DSH version the host's own rejection line names, or null when it is absent. */
|
|
377
|
+
function hostVersionInRejection(output) {
|
|
378
|
+
return /is incompatible with dsh ([0-9][0-9A-Za-z.+-]*)/.exec(output)?.[1] ?? null;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Which side of its declared range the host actually sits on (#1210).
|
|
382
|
+
*
|
|
383
|
+
* The host's line carries both facts this needs: the version it rejected
|
|
384
|
+
* against, and `requirements {...}` — the ranges it evaluated. Direction comes
|
|
385
|
+
* from {@link classifyPeer}, the same predicate the pre-flight uses, so the
|
|
386
|
+
* dialog and the pre-flight cannot disagree about which side is behind.
|
|
387
|
+
*
|
|
388
|
+
* null means "not provable from this text" — an unparseable range, no version,
|
|
389
|
+
* or declarations pointing opposite ways. Callers must then name no direction
|
|
390
|
+
* rather than assume the one the branch was originally written for.
|
|
391
|
+
*/
|
|
392
|
+
function rejectedSide(output) {
|
|
393
|
+
const host = hostVersionInRejection(output);
|
|
394
|
+
const raw = /requirements (\{[^}]*\})/.exec(output)?.[1] ?? '';
|
|
395
|
+
if (host === null || raw === '')
|
|
396
|
+
return null;
|
|
397
|
+
let declared;
|
|
398
|
+
try {
|
|
399
|
+
declared = JSON.parse(raw);
|
|
400
|
+
}
|
|
401
|
+
catch {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
if (declared === null || typeof declared !== 'object' || Array.isArray(declared))
|
|
405
|
+
return null;
|
|
406
|
+
const sides = new Set();
|
|
407
|
+
for (const [key, value] of Object.entries(declared)) {
|
|
408
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
409
|
+
continue;
|
|
410
|
+
const verdict = classifyPeer('', key, value, host, false);
|
|
411
|
+
if (verdict.kind === 'risk') {
|
|
412
|
+
sides.add(verdict.risk.direction === 'belowMin' ? 'host-too-old' : 'plugin-too-old');
|
|
413
|
+
}
|
|
414
|
+
else if (verdict.kind === 'warning' && verdict.warning.reason === 'aboveMax') {
|
|
415
|
+
// A `^` / `~` ceiling the author never wrote still names the line the
|
|
416
|
+
// host has left behind; the host is above it either way.
|
|
417
|
+
sides.add('plugin-too-old');
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return sides.size === 1 ? [...sides][0] ?? null : null;
|
|
421
|
+
}
|
|
254
422
|
export function classifyPnpmFailure(output, exitCode, context) {
|
|
255
423
|
// #817: the host's silence watchdog (@deepseek-ai/dsh-plugin-manager,
|
|
256
424
|
// `idleTimeoutMs`, 10 minutes by default) killed pnpm. Checked first: it is
|
|
@@ -311,6 +479,27 @@ export function classifyPnpmFailure(output, exitCode, context) {
|
|
|
311
479
|
// a repair that goes wrong here leaves a profile in worse shape than the
|
|
312
480
|
// clear error it replaced. The paths are in the message; the choice is
|
|
313
481
|
// the user's.
|
|
482
|
+
//
|
|
483
|
+
// Measured on pnpm 11.28.5 (2026-11), for the #1100 report, the layer order
|
|
484
|
+
// that advice depends on
|
|
485
|
+
// (a scratch workspace and `pnpm store path`, each layer set alone and then
|
|
486
|
+
// against the others, because the previous sentence had not been re-checked
|
|
487
|
+
// since #715 and #244 were filed):
|
|
488
|
+
// --store-dir > PNPM_CONFIG_STORE_DIR > pnpm-workspace.yaml `storeDir`
|
|
489
|
+
// > the global npmrc `store-dir` > the default.
|
|
490
|
+
// Three things follow, and the message now states them instead of assuming
|
|
491
|
+
// the middle layer is always the one that decides:
|
|
492
|
+
// - the camelCase key IS honoured (#715), the kebab `store-dir` is NOT:
|
|
493
|
+
// pnpm prints `…ignored because they are not written in camelCase` on
|
|
494
|
+
// stderr and resolves exactly as if the line were absent;
|
|
495
|
+
// - an environment variable outranks the profile file, so a user who
|
|
496
|
+
// relocated the store that way cannot fix it in the profile at all —
|
|
497
|
+
// the advice has to name the variable (storeRelinkAdvice does);
|
|
498
|
+
// - a project `.npmrc` is ignored, the global one is not, so "the npmrc"
|
|
499
|
+
// is the global file and `pnpm config get store-dir` names its value.
|
|
500
|
+
// Each shape also gets a check the user can run (`pnpm store path`), since
|
|
501
|
+
// this branch's real-world failure was "I wrote exactly what it said and
|
|
502
|
+
// the next run failed the same way".
|
|
314
503
|
if (output.includes('ERR_PNPM_UNEXPECTED_STORE')) {
|
|
315
504
|
const ndjson = storesFromNdjson(output);
|
|
316
505
|
// pnpm 12's default reporter wraps long lines, inside the quotes too.
|
|
@@ -368,10 +557,22 @@ export function classifyPnpmFailure(output, exitCode, context) {
|
|
|
368
557
|
message: `这个 profile 的 node_modules 是用另一个大版本的 pnpm${named} 建的,而正在跑的这个 pnpm 大版本不同:它会在任何 storeDir 下面再拼自己的版本目录(上面第二个路径末尾那一段),所以**写 storeDir 修不好**,自动回滚也会以同样的方式失败。${detail}\n出路(任选):\n 1) 用建这份 node_modules 的那个 pnpm 大版本重新执行——${recorded === null ? '版本号写在 profile 的 node_modules/.modules.yaml 里(packageManager)' : `即 pnpm ${recorded}`},装好后让它排在 PATH 前面;\n 2) 或者留在这个新大版本上,清空 node_modules 重新安装(包会重新下载)。 / this profile's node_modules was built by a different pnpm${named === '' ? '' : ` (${recorded})`} major than the one now running: pnpm appends its own store-version segment under whatever storeDir says (the second path above ends with it), so **writing storeDir cannot fix this**, and the automatic rollback fails the same way.${detail}\nTwo ways out: 1) run the pnpm major that built this node_modules — ${recorded === null ? 'its version is recorded in the profile’s node_modules/.modules.yaml (packageManager)' : `pnpm ${recorded}`} — with it ahead of the current one on PATH; or 2) stay on the new major and reinstall node_modules from scratch (every package is downloaded again).`,
|
|
369
558
|
};
|
|
370
559
|
}
|
|
560
|
+
// The paths pnpm names are the whole diagnosis, so when its wording
|
|
561
|
+
// changes and they cannot be read, say so instead of inventing them — and
|
|
562
|
+
// still leave the reader with the key (`storeDir`) and the check
|
|
563
|
+
// (`pnpm store path`), because an unreadable path is not a missing remedy.
|
|
564
|
+
if (linked === undefined) {
|
|
565
|
+
return {
|
|
566
|
+
code: 'unexpected-store',
|
|
567
|
+
recoverable: false,
|
|
568
|
+
message: `这个 profile 的 node_modules 链接到的 pnpm store,和 pnpm 现在解析出的 store 不是同一个,pnpm 因此拒绝这个 profile 的所有安装与卸载。这次没能从 pnpm 的输出里读出两个路径(它的措辞变了),请按上面的原文核对。修法是在 profile 的 pnpm-workspace.yaml 里用驼峰 \`storeDir\` 指定记录里的那个 store(单引号),改完用 \`pnpm store path\` 验证;注意环境变量 PNPM_CONFIG_STORE_DIR 比这个文件优先,而 kebab 写法 \`store-dir\` 会被 pnpm 忽略。\`pnpm install --store-dir\` 不是修复。 / this profile's node_modules is linked to a different pnpm store than the one pnpm now resolves, so pnpm refuses every install and uninstall for it. This time the two paths could not be read from pnpm's output (its wording changed) — check the text above. The fix is to name the recorded store in the profile's pnpm-workspace.yaml under the camelCase key \`storeDir\` (single-quoted), then verify with \`pnpm store path\`; note that the environment variable PNPM_CONFIG_STORE_DIR outranks that file, and the kebab spelling \`store-dir\` is ignored. \`pnpm install --store-dir\` is not a fix.`,
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
const advice = storeRelinkAdvice(linked, wanted, context?.profileDirectory);
|
|
371
572
|
return {
|
|
372
573
|
code: 'unexpected-store',
|
|
373
574
|
recoverable: false,
|
|
374
|
-
message: `这个 profile 的 node_modules 链接到的 pnpm store,和 pnpm 现在解析出的 store 不是同一个,pnpm 因此拒绝这个 profile 的所有安装与卸载。典型触发是把 $DSH_HOME
|
|
575
|
+
message: `这个 profile 的 node_modules 链接到的 pnpm store,和 pnpm 现在解析出的 store 不是同一个,pnpm 因此拒绝这个 profile 的所有安装与卸载。典型触发是把 $DSH_HOME 或 pnpm 的 store 移到另一个盘:搬迁前建的 node_modules 记着旧盘上的 store,而 pnpm 会按新位置另选一个(#244 的另一种触发,见 #715)。${detail}\n${advice.zh}\n注意 \`pnpm install --store-dir <路径>\` **不是修复**:它只对那一次命令生效,也不会改写 node_modules/.modules.yaml 里的记录,所以下一条命令会报同样的错(pnpm 11.7 与 11.22 实测)。想改用 pnpm 现在解析出的那个 store 也行,但那要求清空并重装整个 node_modules(包全部重新下载),代价由你决定。 / this profile's node_modules is linked to a different pnpm store than the one pnpm now resolves, so pnpm refuses every install and uninstall for it. The usual trigger is moving $DSH_HOME or the pnpm store to another drive: a node_modules built before the move records the old disk's store while pnpm selects one for the new location (the other trigger for #244, see #715).${detail}\n${advice.en}\nNote that \`pnpm install --store-dir <path>\` is NOT a fix: it applies to that one command and does not rewrite the record in node_modules/.modules.yaml, so the next command fails exactly the same way (measured on pnpm 11.7 and 11.22). Switching to the store pnpm now resolves is also possible, but it requires purging and reinstalling the whole node_modules (every package re-downloaded) — your call, not the market's.`,
|
|
375
576
|
};
|
|
376
577
|
}
|
|
377
578
|
// #367: pnpm verifies every tarball resolution in the lockfile before it
|
|
@@ -537,10 +738,41 @@ export function classifyPnpmFailure(output, exitCode, context) {
|
|
|
537
738
|
// market failure (#404's question, answered by the host).
|
|
538
739
|
if (output.includes('dsh: installation rejected:') && /is incompatible with dsh \d/.test(output)) {
|
|
539
740
|
const requirement = /requirements (\{[^}]*\})/.exec(output)?.[1] ?? '';
|
|
741
|
+
// #1210: which SIDE of the range the host sits on decides what the user can
|
|
742
|
+
// do about it, and both sides land in this one branch. The old text named
|
|
743
|
+
// one direction only ("needs a newer DSH"), so a release whose ceiling is
|
|
744
|
+
// BELOW the running host — @anionex/dsh-vision-toolkit capping at
|
|
745
|
+
// 0.2.2-rc.2 on a 0.2.2-rc.3 host — told the reader to upgrade a host that
|
|
746
|
+
// was already ahead, and pointed the report at the host instead of the
|
|
747
|
+
// plugin. Direction comes from the same predicate the pre-flight uses
|
|
748
|
+
// (`classifyPeer` → belowMin/aboveMax), not from a second one written here.
|
|
749
|
+
const exemption = '确实要装这一个,需要先在宿主的插件管理器(或 dsh 的 allow-version)里为这个具体版本授权,再重试';
|
|
750
|
+
const exemptionEn = 'to install this exact one anyway, grant the host\'s exact-version exemption for it first (plugin manager, or dsh\'s allow-version) and retry';
|
|
751
|
+
const declared = requirement === '' ? '' : `(它声明的需求:${requirement})`;
|
|
752
|
+
const declaredEn = requirement === '' ? '' : ` (it declares ${requirement})`;
|
|
753
|
+
const side = rejectedSide(output);
|
|
754
|
+
if (side === 'plugin-too-old') {
|
|
755
|
+
const host = hostVersionInRejection(output) ?? '当前版本';
|
|
756
|
+
return {
|
|
757
|
+
code: 'host-incompatible-install',
|
|
758
|
+
recoverable: false,
|
|
759
|
+
message: `这个插件的兼容上界低于当前运行的 DSH ${host},宿主在安装时自己拒绝了${declared}——是插件还没适配这个宿主版本,不是宿主落后。等插件发布覆盖 ${host} 的新版本,或改装一个仍覆盖它的旧版插件;${exemption} / this plugin's compatible ceiling is below the running DSH ${host}, and the HOST refused the install itself${declaredEn} — the plugin has not caught up with this host line, the host is not behind. Wait for a plugin release that covers ${host}, or install an older plugin version that still does; ${exemptionEn}`,
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
if (side === 'host-too-old') {
|
|
763
|
+
return {
|
|
764
|
+
code: 'host-incompatible-install',
|
|
765
|
+
recoverable: false,
|
|
766
|
+
message: `这个版本要求的 DSH 比当前运行的新,宿主在安装时自己拒绝了${declared}。换一个兼容的版本即可;${exemption} / this release needs a newer DSH than the one running, and the HOST refused the install itself${declaredEn} — not the market's check. Pick a compatible version; ${exemptionEn}`,
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
// Neither side is provable from the host's own text (an unparseable range,
|
|
770
|
+
// several declarations pointing opposite ways, or a rejection the two
|
|
771
|
+
// bounds do not explain). Keep the facts and name no direction.
|
|
540
772
|
return {
|
|
541
773
|
code: 'host-incompatible-install',
|
|
542
774
|
recoverable: false,
|
|
543
|
-
message:
|
|
775
|
+
message: `宿主在安装时以「与当前运行的 DSH 不兼容」为由拒绝了${declared}。换一个兼容的版本即可;${exemption} / the HOST refused the install as incompatible with the running DSH${declaredEn} — not the market's check. Pick a compatible version; ${exemptionEn}`,
|
|
544
776
|
};
|
|
545
777
|
}
|
|
546
778
|
// #69: pnpm >= 10 blocks dependency build scripts by default. The install
|
package/lib/proc-text.js
CHANGED
|
@@ -21,6 +21,21 @@ export function decodeChildOutput(bytes, platform = process.platform) {
|
|
|
21
21
|
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
22
22
|
}
|
|
23
23
|
catch {
|
|
24
|
+
// A window cut through the middle of a UTF-8 character starts with its
|
|
25
|
+
// continuation bytes. Dropping them is what makes the rest UTF-8 again;
|
|
26
|
+
// without this the whole tail was read as GBK on Windows. Only taken when
|
|
27
|
+
// what remains is non-ASCII UTF-8, which GBK text does not happen to be.
|
|
28
|
+
let start = 0;
|
|
29
|
+
while (start < 3 && start < bytes.length && (bytes[start] & 0xc0) === 0x80)
|
|
30
|
+
start += 1;
|
|
31
|
+
if (start > 0) {
|
|
32
|
+
try {
|
|
33
|
+
const rest = new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(start));
|
|
34
|
+
if (/[^\x00-\x7f]/u.test(rest))
|
|
35
|
+
return rest;
|
|
36
|
+
}
|
|
37
|
+
catch { /* not UTF-8 either way */ }
|
|
38
|
+
}
|
|
24
39
|
// Not UTF-8. Only Windows consoles hand a child a non-UTF-8 code page;
|
|
25
40
|
// elsewhere keep the previous behaviour (replace the bad bytes) rather
|
|
26
41
|
// than invent Chinese out of binary noise.
|
|
@@ -53,7 +68,7 @@ export function createOutputBuffer(limit, platform = process.platform) {
|
|
|
53
68
|
return;
|
|
54
69
|
chunks.push(chunk);
|
|
55
70
|
size += chunk.length;
|
|
56
|
-
while (
|
|
71
|
+
while (chunks.length > 1 && size - chunks[0].length >= limit) {
|
|
57
72
|
size -= chunks.shift().length;
|
|
58
73
|
}
|
|
59
74
|
const first = chunks[0];
|
package/lib/profile.js
CHANGED
|
@@ -1891,11 +1891,14 @@ function readReleaseAgeBlock(file) {
|
|
|
1891
1891
|
* nothing in the file says which main package it belongs to — guessing would
|
|
1892
1892
|
* delete policy that may still be in effect for something installed.
|
|
1893
1893
|
*
|
|
1894
|
+
* With `keepVersion` (the update path) the rows that name that version are
|
|
1895
|
+
* kept and only the older ones go.
|
|
1896
|
+
*
|
|
1894
1897
|
* @returns the entries removed, for the caller to log; empty when there is no
|
|
1895
1898
|
* such block, no such row, or the file cannot be read exactly (in which case
|
|
1896
1899
|
* it is left byte-for-byte as it was).
|
|
1897
1900
|
*/
|
|
1898
|
-
export function dropReleaseAgeExcludes(profile, name, explicitDir) {
|
|
1901
|
+
export function dropReleaseAgeExcludes(profile, name, explicitDir, keepVersion) {
|
|
1899
1902
|
const block = readReleaseAgeBlock(join(profileDir(profile, explicitDir), 'pnpm-workspace.yaml'));
|
|
1900
1903
|
if (block === null)
|
|
1901
1904
|
return [];
|
|
@@ -1906,6 +1909,19 @@ export function dropReleaseAgeExcludes(profile, name, explicitDir) {
|
|
|
1906
1909
|
return [item.line];
|
|
1907
1910
|
if (item.rule.name !== name)
|
|
1908
1911
|
return [item.original];
|
|
1912
|
+
// After an update (#1093) only rows that do not name the installed version
|
|
1913
|
+
// are stale. A row that names it stays whole — it may be the one pnpm just
|
|
1914
|
+
// wrote for this very update, which the next install's age check needs. A
|
|
1915
|
+
// union that also lists older versions stays too: it is kept or dropped as
|
|
1916
|
+
// written, never rewritten, so nothing here can loosen the gate. A bare
|
|
1917
|
+
// name already covers every version; that is a policy someone chose, not a
|
|
1918
|
+
// leftover.
|
|
1919
|
+
if (keepVersion !== undefined) {
|
|
1920
|
+
if (item.rule.selector === null)
|
|
1921
|
+
return [item.original];
|
|
1922
|
+
if (item.rule.selector.split('||').some(version => version.trim() === keepVersion))
|
|
1923
|
+
return [item.original];
|
|
1924
|
+
}
|
|
1909
1925
|
dropped.push(item.rule.selector === null ? item.rule.name : `${item.rule.name}@${item.rule.selector}`);
|
|
1910
1926
|
return [];
|
|
1911
1927
|
});
|
package/lib/recovery.js
CHANGED
|
@@ -305,7 +305,8 @@ export async function applyRecovery(config, enabled) {
|
|
|
305
305
|
}
|
|
306
306
|
if (error === null) {
|
|
307
307
|
for (const row of plugin.rows) {
|
|
308
|
-
const
|
|
308
|
+
const options = { packageName: plugin.name };
|
|
309
|
+
const result = want ? await enableRow(config.patchPath, row, options) : await disableRow(config.patchPath, row, options);
|
|
309
310
|
if (!result.ok) {
|
|
310
311
|
error = result.reason ?? 'the patch layer refused the write';
|
|
311
312
|
break;
|
package/lib/registry.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Registry access:
|
|
3
|
-
*
|
|
2
|
+
* Registry access: the curated list from awesome-dsh-plugin.com, fetched
|
|
3
|
+
* fresh on every request. See `loadRegistry` for why there is nothing
|
|
4
|
+
* behind it any more.
|
|
4
5
|
*/
|
|
5
6
|
import { BODY_STALL_TIMEOUT_MS, HEADERS_TIMEOUT_MS, readBodyWhileProgressing } from './body-progress.js';
|
|
6
7
|
import { logEvent } from './log.js';
|
|
7
8
|
import { configuredProxy, marketFetch } from './net.js';
|
|
8
9
|
import { catalogFromPackage } from './catalog-npm.js';
|
|
9
10
|
import { activeRegion, catalogSourcesFor, routesFor } from './regions.js';
|
|
10
|
-
import { asCrateRegistry, isCrateCatalog } from './crate-catalog.js';
|
|
11
11
|
import { NPM_NAME_RE } from './sources.js';
|
|
12
|
+
/**
|
|
13
|
+
* How long a successful catalog load may take before it leaves a line behind.
|
|
14
|
+
*
|
|
15
|
+
* A load that fails already documents itself: the thrown message carries the
|
|
16
|
+
* elapsed time and the attempt count. A load that SUCCEEDS carries nothing,
|
|
17
|
+
* so a market that took forty seconds and one that took two produce the same
|
|
18
|
+
* export — "(none — the buffer starts empty on every start)" — and a report
|
|
19
|
+
* cannot tell them apart (#1181: thirteen seconds, twenty, forty on the same
|
|
20
|
+
* machine, five minutes on the run that failed, all with an empty session).
|
|
21
|
+
* The threshold sits above any healthy load, so the ordinary case stays quiet.
|
|
22
|
+
*/
|
|
23
|
+
const SLOW_CATALOG_MS = 5_000;
|
|
12
24
|
/**
|
|
13
25
|
* Category ids for one catalog entry, de-duplicated in declaration order.
|
|
14
26
|
*
|
|
@@ -98,18 +110,6 @@ let served = null;
|
|
|
98
110
|
function sourceKey(source) {
|
|
99
111
|
return source.kind === 'npm' ? `npm:${source.registry}/${source.pkg}` : `url:${source.url}`;
|
|
100
112
|
}
|
|
101
|
-
/**
|
|
102
|
-
* 目录载荷分派:按结构选适配器,而不是按地区或地址。
|
|
103
|
-
*
|
|
104
|
-
* crate 的载荷带 `entries`,旧的目录带 `plugins`;两套结构各自校验,夹具
|
|
105
|
-
* 与真实数据都不会误入对方的分支。
|
|
106
|
-
*
|
|
107
|
-
* @param value - 已经 `JSON.parse` 过的目录载荷。
|
|
108
|
-
* @throws 两个适配器都可能因为数据不可用而抛出,异常留给调用方重试。
|
|
109
|
-
*/
|
|
110
|
-
function parseCatalog(value) {
|
|
111
|
-
return isCrateCatalog(value) ? asCrateRegistry(value) : asRegistry(value);
|
|
112
|
-
}
|
|
113
113
|
/** A parsed catalog, or a thrown explanation of why it is not one. */
|
|
114
114
|
function asRegistry(value) {
|
|
115
115
|
const data = value;
|
|
@@ -193,6 +193,14 @@ export async function loadRegistry(region = activeRegion()) {
|
|
|
193
193
|
if (sourceIndex >= ownSources) {
|
|
194
194
|
logEvent('warn', 'registry', `catalog: the ${region} sources did not answer; read the catalog package from ${key} instead (#891)`);
|
|
195
195
|
}
|
|
196
|
+
// Success is silent by default, which is what makes a slow one
|
|
197
|
+
// undiagnosable: the export says the same thing whether the market
|
|
198
|
+
// appeared in two seconds or in forty (#1181). One line above the
|
|
199
|
+
// threshold, none below it.
|
|
200
|
+
const elapsed = Date.now() - started;
|
|
201
|
+
if (elapsed >= SLOW_CATALOG_MS) {
|
|
202
|
+
logEvent('info', 'registry', `catalog: ${key} answered in ${(elapsed / 1000).toFixed(1)}s after ${String(attempts)} request attempt(s)`);
|
|
203
|
+
}
|
|
196
204
|
return data;
|
|
197
205
|
};
|
|
198
206
|
// Two attempts each. A catalog fetch crossing a long, lossy path fails
|
|
@@ -252,7 +260,7 @@ export async function loadRegistry(region = activeRegion()) {
|
|
|
252
260
|
}
|
|
253
261
|
if (!res.ok)
|
|
254
262
|
throw new Error(`HTTP ${String(res.status)}`);
|
|
255
|
-
const data =
|
|
263
|
+
const data = asRegistry(JSON.parse(new TextDecoder().decode(await readBodyWhileProgressing(res, BODY_STALL_TIMEOUT_MS))));
|
|
256
264
|
served = {
|
|
257
265
|
key, etag: res.headers.get('etag'), modified: res.headers.get('last-modified'), version: null, data,
|
|
258
266
|
};
|
|
@@ -14,6 +14,10 @@ export function isStableReleaseVersion(value) {
|
|
|
14
14
|
const parsed = semver(value);
|
|
15
15
|
return parsed !== null && parsed.prerelease.length === 0;
|
|
16
16
|
}
|
|
17
|
+
/** Accept a bounded exact npm release version, including prereleases. */
|
|
18
|
+
export function isExactReleaseVersion(value) {
|
|
19
|
+
return typeof value === 'string' && value.length <= 256 && value === value.trim() && semver(value) !== null;
|
|
20
|
+
}
|
|
17
21
|
function compare(a, b) {
|
|
18
22
|
for (let i = 0; i < 3; i++) {
|
|
19
23
|
if (a.core[i] !== b.core[i])
|
package/lib/release-updates.js
CHANGED
|
@@ -19,9 +19,16 @@ export function catalogReleaseSourceOf(spec, entry) {
|
|
|
19
19
|
if (url.protocol !== 'https:' || url.host !== 'github.com' || url.username !== '' || url.password !== '' || url.search !== '' || url.hash !== '')
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
|
-
const match = /^\/([^/]+\/[^/]+)\/releases\/(?:latest\/download|download\/[^/]+)\/([^/]+)$/.exec(installed.pathname);
|
|
23
|
-
if (match === null || match[1].toLowerCase() !== source.repo.toLowerCase()
|
|
22
|
+
const match = /^\/([^/]+\/[^/]+)\/releases\/(?:latest\/download|download\/([^/]+))\/([^/]+)$/.exec(installed.pathname);
|
|
23
|
+
if (match === null || match[1].toLowerCase() !== source.repo.toLowerCase())
|
|
24
24
|
return null;
|
|
25
|
+
const [, , tag, installedAsset] = match;
|
|
26
|
+
if (installedAsset !== asset) {
|
|
27
|
+
// A legacy filename can only add the version from its own stable release tag.
|
|
28
|
+
const version = /^v?(\d+\.\d+\.\d+)$/.exec(tag ?? '')?.[1];
|
|
29
|
+
if (version === undefined || installedAsset !== asset.replace(/\.(?:tgz|tar\.gz)$/, extension => `-${version}${extension}`))
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
25
32
|
return { repo: source.repo, asset, manifest: source.subpath === null ? 'package.json' : `${source.subpath}/package.json` };
|
|
26
33
|
}
|
|
27
34
|
catch {
|