dsh-crate 0.5.5 → 0.5.7
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/client/client.js +1767 -617
- package/lib/changelog.js +71 -28
- package/lib/gist.js +1 -1
- package/lib/hot.js +18 -6
- package/lib/index.js +10 -3
- package/lib/install.js +200 -9
- package/lib/official-desktop.js +80 -16
- package/lib/patch.js +223 -25
- package/lib/pending-checkout-links.js +123 -0
- package/lib/pending-updates.js +7 -4
- package/lib/profile.js +36 -0
- package/lib/registry.js +38 -20
- package/lib/release-blockers.js +177 -0
- package/lib/release-history.js +149 -0
- package/lib/release-updates.js +1 -34
- package/lib/routes.js +843 -166
- package/lib/sources.js +42 -2
- package/lib/startup-repair-report.js +46 -0
- package/lib/themes.js +7 -5
- package/lib/types/changelog.d.ts +4 -1
- package/lib/types/dsh-cli.d.ts +8 -0
- package/lib/types/gist.d.ts +1 -1
- package/lib/types/hot.d.ts +2 -1
- package/lib/types/install.d.ts +22 -4
- package/lib/types/official-desktop.d.ts +4 -0
- package/lib/types/patch.d.ts +36 -0
- package/lib/types/pending-checkout-links.d.ts +35 -0
- package/lib/types/pending-updates.d.ts +2 -0
- package/lib/types/profile.d.ts +3 -0
- package/lib/types/registry.d.ts +6 -8
- package/lib/types/release-blockers.d.ts +34 -0
- package/lib/types/release-history.d.ts +34 -0
- package/lib/types/release-updates.d.ts +2 -11
- package/lib/types/routes.d.ts +3 -0
- package/lib/types/sources.d.ts +11 -0
- package/lib/types/startup-repair-report.d.ts +20 -0
- package/lib/types/themes.d.ts +2 -2
- package/lib/types/update-notifications.d.ts +6 -0
- package/lib/types/updates.d.ts +19 -0
- package/lib/update-notifications.js +6 -4
- package/lib/updates.js +16 -0
- package/locale/en.json +1 -1
- package/locale/ja.json +5 -0
- package/package.json +2 -2
package/lib/changelog.js
CHANGED
|
@@ -27,6 +27,8 @@ import { profileDir, readGitResolutionCommit, readInstalled, readInstalledRepoEv
|
|
|
27
27
|
import { githubRepoOfRemote, hostedRepoKey, isGitHostedSpec, lookupRepoFromUrl, parseHostShorthand, parseSourceUrl, repoOf, repoOfTarget } from './sources.js';
|
|
28
28
|
import { checkUpdates, compareVersions } from './updates.js';
|
|
29
29
|
import { loadRegistry } from './registry.js';
|
|
30
|
+
import { isStableReleaseVersion } from './release-candidates.js';
|
|
31
|
+
import { invalidateReleaseHistory, isCommitId, loadReleaseHistory, packageReleaseVersion, releaseHistoryBetween } from './release-history.js';
|
|
30
32
|
const UPDATES_PACKAGE = 'dsh-plugin-updates';
|
|
31
33
|
const UPDATES_FILE = 'package/updates.json';
|
|
32
34
|
/** The origin copy sits beside plugins.json on the catalog host. */
|
|
@@ -100,6 +102,7 @@ export async function loadUpdateNotes(force = false) {
|
|
|
100
102
|
/** Drop the cached payload (nothing currently invalidates it mid-process). */
|
|
101
103
|
export function invalidateUpdateNotes() {
|
|
102
104
|
notesCache = null;
|
|
105
|
+
invalidateReleaseHistory();
|
|
103
106
|
}
|
|
104
107
|
/**
|
|
105
108
|
* Slice the commit tail at the installed sha.
|
|
@@ -120,6 +123,15 @@ export function sliceCommitsAt(items, installed) {
|
|
|
120
123
|
}
|
|
121
124
|
return { items: out, found: false };
|
|
122
125
|
}
|
|
126
|
+
/** Report an exact interval only when both the requested target and install are in the tail. */
|
|
127
|
+
function commitsForTarget(items, installed, target) {
|
|
128
|
+
if (target === undefined)
|
|
129
|
+
return sliceCommitsAt(items, installed);
|
|
130
|
+
const upper = target === null ? -1 : items.findIndex(commit => commit.sha.toLowerCase() === target.toLowerCase());
|
|
131
|
+
if (upper >= 0)
|
|
132
|
+
return sliceCommitsAt(items.slice(upper), installed);
|
|
133
|
+
return { items: sliceCommitsAt(items, installed).items, found: false };
|
|
134
|
+
}
|
|
123
135
|
/**
|
|
124
136
|
* The version a release tag names, when it names one.
|
|
125
137
|
*
|
|
@@ -337,6 +349,14 @@ function catalogEntryForGitSource(plugins, spec) {
|
|
|
337
349
|
const matches = plugins.filter(p => hostedRepoKey(p.url) === repo);
|
|
338
350
|
return matches.length === 1 ? matches[0] : undefined;
|
|
339
351
|
}
|
|
352
|
+
function releaseHistorySource(plugins, plugin, packageName) {
|
|
353
|
+
const source = parseSourceUrl(plugin.url);
|
|
354
|
+
if (source === null || (plugin.npm != null && plugin.npm !== packageName))
|
|
355
|
+
return null;
|
|
356
|
+
const repo = source.repo.toLowerCase();
|
|
357
|
+
const hasSibling = plugins.some(row => row !== plugin && repoOf(row.url)?.toLowerCase() === repo);
|
|
358
|
+
return { repo, packageName, allowPlainTag: source.subpath === null && !hasSibling };
|
|
359
|
+
}
|
|
340
360
|
/**
|
|
341
361
|
* Resolve the notes for one installed plugin, or `{ kind: 'none' }`.
|
|
342
362
|
*
|
|
@@ -345,7 +365,7 @@ function catalogEntryForGitSource(plugins, spec) {
|
|
|
345
365
|
* a neutral statement, not an error.
|
|
346
366
|
*/
|
|
347
367
|
export async function updateNotesFor(profile, explicitDir, name,
|
|
348
|
-
/**
|
|
368
|
+
/** Exact version or Git SHA displayed as the update target. */
|
|
349
369
|
target) {
|
|
350
370
|
const activeProfileDir = profileDir(profile, explicitDir);
|
|
351
371
|
const spec = readInstalled(profile, activeProfileDir)[name];
|
|
@@ -382,13 +402,20 @@ target) {
|
|
|
382
402
|
// Loading the catalog on a root miss would wait out its timeout to
|
|
383
403
|
// answer "no notes".
|
|
384
404
|
const offGithub = specKey === null && npmName === null && isGitHostedSpec(spec);
|
|
405
|
+
const hasSubpath = githubIdentityOf(spec)?.includes('#path:/') ?? false;
|
|
385
406
|
const needsCatalog = (specKey === null && (npmName !== null || offGithub))
|
|
386
|
-
||
|
|
387
|
-
|
|
407
|
+
|| hasSubpath;
|
|
408
|
+
let historySource = null;
|
|
409
|
+
const installed = readInstalledVersion(profile, name, activeProfileDir);
|
|
410
|
+
const wantsHistory = target !== undefined && isStableReleaseVersion(installed)
|
|
411
|
+
&& (isCommitId(target) || (compareVersions(target, installed) ?? 0) > 0);
|
|
412
|
+
if ((!usableNotes(entry) && needsCatalog) || (wantsHistory && (entry?.releaseHistory === true || hasSubpath))) {
|
|
388
413
|
try {
|
|
389
414
|
const registry = await loadRegistry();
|
|
390
415
|
const plugin = specKey !== null
|
|
391
|
-
?
|
|
416
|
+
? hasSubpath
|
|
417
|
+
? catalogEntryForGitSubpath(registry.plugins, spec)
|
|
418
|
+
: registry.plugins.find(row => row.url.toLowerCase() === specKey.toLowerCase())
|
|
392
419
|
: npmName !== null
|
|
393
420
|
? catalogEntryForNpmInstall(registry.plugins, npmName, () => readInstalledRepoEvidence(profile, name, spec, explicitDir))
|
|
394
421
|
: catalogEntryForGitSource(registry.plugins, spec);
|
|
@@ -397,10 +424,18 @@ target) {
|
|
|
397
424
|
// An empty row does not become the key. Publish times for an npm
|
|
398
425
|
// install follow from `specKey` staying null, and a subpath install
|
|
399
426
|
// keeps the root key so a sibling's notes are not borrowed.
|
|
400
|
-
if (usableNotes(catalogEntry)) {
|
|
427
|
+
if (usableNotes(catalogEntry) && (!usableNotes(entry) || catalogEntry?.releaseHistory === true)) {
|
|
401
428
|
key = plugin.url;
|
|
402
429
|
entry = catalogEntry;
|
|
403
430
|
}
|
|
431
|
+
if (wantsHistory && catalogEntry?.releaseHistory === true) {
|
|
432
|
+
const source = releaseHistorySource(registry.plugins, plugin, npmName ?? name);
|
|
433
|
+
const identities = npmName === null ? [] : readInstalledRepoEvidence(profile, name, spec, explicitDir).identities;
|
|
434
|
+
if (source !== null && (identities.length === 0 || identities.some(id => id.split('#')[0]?.toLowerCase() === source.repo))) {
|
|
435
|
+
key = plugin.url;
|
|
436
|
+
historySource = source;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
404
439
|
}
|
|
405
440
|
}
|
|
406
441
|
catch {
|
|
@@ -417,14 +452,31 @@ target) {
|
|
|
417
452
|
let current = null;
|
|
418
453
|
if (key !== null && key.startsWith('https://github.com/')) {
|
|
419
454
|
const repo = (repoOf(key) ?? key.slice('https://github.com/'.length).split('#')[0]).toLowerCase();
|
|
420
|
-
current =
|
|
421
|
-
??
|
|
455
|
+
current = readGitResolutionCommit(profile, spec, explicitDir)
|
|
456
|
+
?? (hasSubpath ? null : readLockCommits(profile, activeProfileDir).get(`github.com/${repo}`) ?? null);
|
|
422
457
|
}
|
|
423
458
|
else {
|
|
424
459
|
const statuses = await checkUpdates(profile, false, explicitDir).catch(() => null);
|
|
425
460
|
current = statuses?.[name]?.current ?? null;
|
|
426
461
|
}
|
|
427
|
-
|
|
462
|
+
const interval = wantsHistory && historySource !== null
|
|
463
|
+
? releaseHistoryBetween(await loadReleaseHistory(ORIGIN_UPDATES, historySource.repo), historySource, installed, target, current)
|
|
464
|
+
: null;
|
|
465
|
+
const history = interval?.history ?? (wantsHistory && entry?.releaseHistory === true ? { items: [], partial: true } : null);
|
|
466
|
+
const withHistory = history === null ? {} : { history };
|
|
467
|
+
const targetVersion = interval?.targetVersion ?? (target !== undefined && !isCommitId(target) ? target : null);
|
|
468
|
+
const targetCommit = target === undefined ? undefined : interval?.targetCommit ?? (isCommitId(target) ? target : null);
|
|
469
|
+
const sliced = (entry?.commits?.length ?? 0) > 0
|
|
470
|
+
? commitsForTarget(entry.commits, current, targetCommit)
|
|
471
|
+
: undefined;
|
|
472
|
+
const snapshotRelease = entry?.release;
|
|
473
|
+
const snapshotVersion = historySource === null ? releaseVersionOf(snapshotRelease?.tag ?? null)
|
|
474
|
+
: packageReleaseVersion(snapshotRelease?.tag ?? null, historySource);
|
|
475
|
+
const preview = interval?.preview;
|
|
476
|
+
const usePreview = preview != null && (snapshotVersion === null || (compareVersions(preview.version, snapshotVersion) ?? 0) >= 0);
|
|
477
|
+
const release = usePreview ? preview : snapshotRelease;
|
|
478
|
+
const released = usePreview ? preview.version : snapshotVersion;
|
|
479
|
+
if (release != null && (release.body !== '' || release.tag !== null) && (historySource === null || released !== null)) {
|
|
428
480
|
// The release feed is a DAILY snapshot while the update target is read
|
|
429
481
|
// live from npm, so the snapshot's newest release is often the version
|
|
430
482
|
// already installed (or older). Showing it next to "1.66.39 → 1.66.40"
|
|
@@ -434,40 +486,31 @@ target) {
|
|
|
434
486
|
// install's sha, and npm publish times are newer than the install by
|
|
435
487
|
// construction. With nothing better, the stale release still beats an
|
|
436
488
|
// empty dialog.
|
|
437
|
-
const installed = readInstalledVersion(profile, name, activeProfileDir);
|
|
438
|
-
const released = releaseVersionOf(entry.release.tag);
|
|
439
489
|
const behind = installed !== null && released !== null
|
|
440
490
|
&& (compareVersions(released, installed) ?? 0) <= 0;
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const beyond = target !== undefined && released !== null
|
|
444
|
-
&& (compareVersions(released, target) ?? 0) > 0;
|
|
445
|
-
// Attach the commit slice so the dialog can list what changed between
|
|
446
|
-
// the installed commit and the update target, not just the release (#1193).
|
|
447
|
-
// Only when the installed commit is found in the list: otherwise the
|
|
448
|
-
// slice is just "recent commits" unrelated to this update, and next to
|
|
449
|
-
// release notes it would be noise (npm installs never match a sha).
|
|
450
|
-
const sliced = hasCommits ? sliceCommitsAt(entry.commits, current) : undefined;
|
|
491
|
+
if (!(behind && (sliced !== undefined || (specKey === null && npmName !== null)))) {
|
|
492
|
+
const beyond = targetVersion !== null && released !== null && (compareVersions(released, targetVersion) ?? 0) > 0;
|
|
451
493
|
const withCommits = sliced !== undefined && sliced.found && sliced.items.length > 0 ? { commits: sliced } : {};
|
|
452
494
|
return beyond
|
|
453
|
-
? { kind: 'release', release
|
|
454
|
-
: { kind: 'release', release
|
|
495
|
+
? { kind: 'release', release, beyondTarget: targetVersion, ...withCommits, ...withHistory }
|
|
496
|
+
: { kind: 'release', release, ...withCommits, ...withHistory };
|
|
455
497
|
}
|
|
456
498
|
}
|
|
457
|
-
if (
|
|
458
|
-
return { kind: 'commits', commits:
|
|
499
|
+
if (sliced !== undefined) {
|
|
500
|
+
return { kind: 'commits', commits: sliced, ...withHistory };
|
|
459
501
|
}
|
|
460
502
|
if (specKey === null && npmName !== null) {
|
|
461
503
|
// An npm install whose catalog row is missing or its probe has no
|
|
462
504
|
// notes: publish times remain.
|
|
463
|
-
|
|
505
|
+
const npmTimes = await npmPublishTimes(npmName).catch(() => null);
|
|
506
|
+
return npmTimes === null ? { kind: 'none', ...withHistory } : { kind: 'npm', npmTimes, ...withHistory };
|
|
464
507
|
}
|
|
465
508
|
// Every other source has its history where it came from. Only a probe
|
|
466
509
|
// that ran and found nothing — releases 404 AND an empty log — means the
|
|
467
510
|
// plugin really publishes nothing.
|
|
468
|
-
if (entry === undefined)
|
|
469
|
-
return fromSource('missing');
|
|
470
|
-
return { kind: 'none' };
|
|
511
|
+
if (entry === undefined && historySource === null)
|
|
512
|
+
return { ...fromSource('missing'), ...withHistory };
|
|
513
|
+
return { kind: 'none', ...withHistory };
|
|
471
514
|
}
|
|
472
515
|
catch {
|
|
473
516
|
return npmName === null ? fromSource('unavailable') : { kind: 'none' };
|
package/lib/gist.js
CHANGED
|
@@ -308,7 +308,7 @@ async function sendGistRequest(token, method, path, body, action, signal) {
|
|
|
308
308
|
throw parseGistError(response.status, response.body, action);
|
|
309
309
|
return response;
|
|
310
310
|
}
|
|
311
|
-
/** Create a
|
|
311
|
+
/** Create a secret Gist carrying one backup file. */
|
|
312
312
|
export async function createGist(token, content, signal) {
|
|
313
313
|
const body = JSON.stringify({
|
|
314
314
|
description: 'dsh-crate profile backup',
|
package/lib/hot.js
CHANGED
|
@@ -966,15 +966,16 @@ export async function hotUnmount(packageName) {
|
|
|
966
966
|
* @param ctx - market host context; the subtree unwinds with the market's fiber.
|
|
967
967
|
* @param profileDir - profile the package was installed into.
|
|
968
968
|
* @param packageName - installed package to activate.
|
|
969
|
+
* @param keepOff - component ids the user's profile keeps disabled.
|
|
969
970
|
* @returns whether the plugin is live without a restart, plus the reason
|
|
970
971
|
* when it is not (P0-2: the UI must distinguish "restart will fix it" from
|
|
971
972
|
* "this package can never hot-mount").
|
|
972
973
|
*/
|
|
973
|
-
export async function hotMount(ctx, profileDir, packageName) {
|
|
974
|
+
export async function hotMount(ctx, profileDir, packageName, keepOff) {
|
|
974
975
|
try {
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
976
|
+
const previousFailure = hotMountFailure(packageName, profileDir);
|
|
977
|
+
if (previousFailure !== null)
|
|
978
|
+
return mountResult(previousFailure);
|
|
978
979
|
const HotTree = await loadHotTreeClass();
|
|
979
980
|
if (HotTree === null) {
|
|
980
981
|
return {
|
|
@@ -1011,6 +1012,7 @@ export async function hotMount(ctx, profileDir, packageName) {
|
|
|
1011
1012
|
}
|
|
1012
1013
|
}
|
|
1013
1014
|
let rows;
|
|
1015
|
+
let clientOnly = false;
|
|
1014
1016
|
if (texts !== null && texts.length > 0) {
|
|
1015
1017
|
const scan = scanPatch(texts.join('\n'));
|
|
1016
1018
|
if (scan.blocker !== null) {
|
|
@@ -1020,7 +1022,10 @@ export async function hotMount(ctx, profileDir, packageName) {
|
|
|
1020
1022
|
reason: patchBlockerReason(scan.blocker, scan.key),
|
|
1021
1023
|
};
|
|
1022
1024
|
}
|
|
1023
|
-
rows = scan.rows;
|
|
1025
|
+
rows = keepOff === undefined ? scan.rows : scan.rows.filter(row => !keepOff.has(row.id));
|
|
1026
|
+
if (rows.length === 0) {
|
|
1027
|
+
return { ok: false, deferred: true, reason: patchBlockerReason('disabled', 'disabled') };
|
|
1028
|
+
}
|
|
1024
1029
|
}
|
|
1025
1030
|
else if (declared.length > 0) {
|
|
1026
1031
|
// The declaration is VOID — one of its files cannot be read. The host
|
|
@@ -1043,9 +1048,16 @@ export async function hotMount(ctx, profileDir, packageName) {
|
|
|
1043
1048
|
reason: '该包无 bundle patch 且未声明 dsh.client,没有可热挂载的内容 / no bundle patch and no dsh.client surface — nothing to hot-mount',
|
|
1044
1049
|
};
|
|
1045
1050
|
}
|
|
1046
|
-
|
|
1051
|
+
clientOnly = true;
|
|
1047
1052
|
rows = [{ id: `client-${packageName.replace(/[^A-Za-z0-9_.-]/g, '-')}`, name: packageName }];
|
|
1048
1053
|
}
|
|
1054
|
+
// Recheck the patch even when a tree is already live, but retain its
|
|
1055
|
+
// handle. Registering another include here would orphan the original.
|
|
1056
|
+
if (mountedFile(packageName, profileDir) !== undefined) {
|
|
1057
|
+
return mountResult(hotMountFailure(packageName, profileDir));
|
|
1058
|
+
}
|
|
1059
|
+
if (clientOnly)
|
|
1060
|
+
shimNames.add(packageName);
|
|
1049
1061
|
const dir = join(profileDir, HOT_DIR);
|
|
1050
1062
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
1051
1063
|
hotSequence += 1;
|
package/lib/index.js
CHANGED
|
@@ -6,12 +6,13 @@ import z from '@deepseek-ai/schemastery';
|
|
|
6
6
|
import { dirname, isAbsolute } from 'node:path';
|
|
7
7
|
import { createDesktopPluginRuntime, setHostPackageManager } from './dsh-cli.js';
|
|
8
8
|
import { createOfficialDesktopRuntime } from './official-desktop.js';
|
|
9
|
-
import { isDshProfileName } from './profile.js';
|
|
9
|
+
import { isDshProfileName, profileDir } from './profile.js';
|
|
10
10
|
import { setRequestGateSource, setTrustedHostsSource } from './http.js';
|
|
11
11
|
import { setLauncherInstallAnchorSource } from './dsh-install.js';
|
|
12
12
|
import { mountMarketRoutes } from './routes.js';
|
|
13
13
|
import { installDesktopMarketSettings, installMarketSettings } from './settings.js';
|
|
14
14
|
import { MAX_AUTO_REPAIR_ATTEMPTS } from './pending-updates.js';
|
|
15
|
+
import { observeStartupRepair } from './startup-repair-report.js';
|
|
15
16
|
export const name = 'dsh-crate';
|
|
16
17
|
/**
|
|
17
18
|
* How long after the market mounts an interrupted update is repaired.
|
|
@@ -314,20 +315,26 @@ export function apply(ctx, config) {
|
|
|
314
315
|
installDesktopMarketSettings(ctx);
|
|
315
316
|
host.effect(() => {
|
|
316
317
|
const restoreTrustedHosts = useTrustedHosts(ctx);
|
|
317
|
-
const
|
|
318
|
+
const startupRepair = observeStartupRepair(profileName, profileDir(profileName, profileDirectory));
|
|
319
|
+
const disposeRoutes = mountMarketRoutes(host, { ...resolved, startupRepair: startupRepair.read }, runtime, agentsLookupOf(ctx));
|
|
320
|
+
let started = false;
|
|
318
321
|
const repairTimer = setTimeout(() => {
|
|
322
|
+
started = true;
|
|
319
323
|
void runtime.repairPendingUpdates().then(report => {
|
|
324
|
+
startupRepair.finish(report);
|
|
320
325
|
if (report.reinstalled.length === 0 && report.failed.length === 0)
|
|
321
326
|
return;
|
|
322
327
|
const abandoned = report.abandoned.length === 0
|
|
323
328
|
? ''
|
|
324
329
|
: `, ${String(report.abandoned.length)} given up on after ${String(MAX_AUTO_REPAIR_ATTEMPTS)} starts — reinstall from Settings → Plugins: ${report.abandoned.join(', ')}`;
|
|
325
330
|
console.warn(`dsh-crate: ${String(report.reinstalled.length)} interrupted update(s) reinstalled, ${String(report.failed.length)} still pending${abandoned}`);
|
|
326
|
-
});
|
|
331
|
+
}, () => { startupRepair.finish(); });
|
|
327
332
|
}, PENDING_UPDATE_REPAIR_DELAY_MS);
|
|
328
333
|
repairTimer.unref?.();
|
|
329
334
|
return async () => {
|
|
330
335
|
clearTimeout(repairTimer);
|
|
336
|
+
if (!started)
|
|
337
|
+
startupRepair.finish();
|
|
331
338
|
const routesDisposed = disposeRoutes();
|
|
332
339
|
restoreTrustedHosts();
|
|
333
340
|
await Promise.all([routesDisposed, runtime.dispose()]);
|
package/lib/install.js
CHANGED
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
* update staleness detection. Every function takes the plugin runner as a
|
|
5
5
|
* parameter so tests can substitute a recording fake.
|
|
6
6
|
*/
|
|
7
|
-
import { closeSync, existsSync, lstatSync, openSync, readFileSync, readlinkSync, readSync, rmSync, statSync } from 'node:fs';
|
|
8
|
-
import {
|
|
7
|
+
import { closeSync, existsSync, lstatSync, mkdtempSync, openSync, readFileSync, readlinkSync, readSync, realpathSync, renameSync, rmSync, statSync, symlinkSync, unlinkSync } from 'node:fs';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
10
|
import { findDshInstallDir } from './dsh-install.js';
|
|
10
11
|
import { classifyPnpmFailure, HOST_NAMESPACE_RE } from './pnpm-compat.js';
|
|
11
12
|
import { conflictingEntryIds, dropFromManifest, hasDshManifest, hasLoadableEntry, mergeDuplicateReleaseAgeExcludes, pluginSubdirs, profileDir, readGitResolutionCommit, readInstalled, readInstalledVersion, readLockCommits, readManifestDeps, readProfileBundles, dropUnparseableBuildKeys } from './profile.js';
|
|
12
13
|
import { logEvent } from './log.js';
|
|
14
|
+
import { clearReleaseBlockers, parseReleaseAgeBlockers, recordReleaseBlockers } from './release-blockers.js';
|
|
13
15
|
import { registryNameOf } from './official-desktop.js';
|
|
14
|
-
import { hostedRepoKey } from './sources.js';
|
|
16
|
+
import { hostedRepoKey, NPM_NAME_RE } from './sources.js';
|
|
15
17
|
import { cleanOrphanedIgnored, cleanOrphanedStore } from './store.js';
|
|
16
18
|
/**
|
|
17
19
|
* One-shot bypass for pnpm's fresh-release hold; scoped to a single command.
|
|
@@ -119,6 +121,8 @@ export function isUnpublishedHostPeer(pkg, profile, explicitDir) {
|
|
|
119
121
|
*/
|
|
120
122
|
export async function withHoistRecovery(run, profile, pluginArgs, profileDirectory, options = {}) {
|
|
121
123
|
const marketFlags = options.marketFlags !== false;
|
|
124
|
+
/** The release-age bypass ran, so a success proves nothing about the lockfile (#1252). */
|
|
125
|
+
let bypassed = pluginArgs.includes(RELEASE_AGE_OVERRIDE);
|
|
122
126
|
// An already verified mature update must not rewrite the user's workspace
|
|
123
127
|
// policy as a side effect of market-level recovery (#991).
|
|
124
128
|
const repairProfilePolicy = options.preserveProfilePolicy !== true;
|
|
@@ -137,6 +141,8 @@ export async function withHoistRecovery(run, profile, pluginArgs, profileDirecto
|
|
|
137
141
|
}
|
|
138
142
|
}
|
|
139
143
|
let result = await run(profile, pluginArgs);
|
|
144
|
+
if (result.repairOnRestart === true)
|
|
145
|
+
return result;
|
|
140
146
|
const ok = (r) => r.exitCode === 0 && !r.timedOut && !r.cancelled;
|
|
141
147
|
// A shadowed rule written DURING the run is its own evidence (#732). The
|
|
142
148
|
// file was merged just before the run, so a duplicate now means pnpm — or
|
|
@@ -180,6 +186,8 @@ export async function withHoistRecovery(run, profile, pluginArgs, profileDirecto
|
|
|
180
186
|
// --no-frozen-lockfile: the market runs pnpm with CI=true (TTY hangs),
|
|
181
187
|
// where a lockfile written by the old major would otherwise be refused.
|
|
182
188
|
const rebuild = await run(profile, ['install', '--no-frozen-lockfile']);
|
|
189
|
+
if (rebuild.repairOnRestart === true)
|
|
190
|
+
return rebuild;
|
|
183
191
|
if (ok(rebuild))
|
|
184
192
|
result = await run(profile, pluginArgs);
|
|
185
193
|
}
|
|
@@ -208,6 +216,7 @@ export async function withHoistRecovery(run, profile, pluginArgs, profileDirecto
|
|
|
208
216
|
}
|
|
209
217
|
else {
|
|
210
218
|
logEvent('warn', 'install', `a too-young release blocks pnpm's lockfile verification (#39) — retrying once with ${RELEASE_AGE_OVERRIDE}`);
|
|
219
|
+
bypassed = true;
|
|
211
220
|
result = await run(profile, [pluginArgs[0], RELEASE_AGE_OVERRIDE, ...pluginArgs.slice(1)]);
|
|
212
221
|
}
|
|
213
222
|
}
|
|
@@ -277,6 +286,8 @@ export async function withHoistRecovery(run, profile, pluginArgs, profileDirecto
|
|
|
277
286
|
}
|
|
278
287
|
}
|
|
279
288
|
}
|
|
289
|
+
if (result.repairOnRestart === true)
|
|
290
|
+
return result;
|
|
280
291
|
if (!ok(result) && !result.cancelled) {
|
|
281
292
|
// A failed, timed-out, or killed run never finishes pnpm's staging, so
|
|
282
293
|
// its store tmp dirs (the WHOLE repo tarball for github: sources) are
|
|
@@ -338,7 +349,7 @@ export async function withHoistRecovery(run, profile, pluginArgs, profileDirecto
|
|
|
338
349
|
// to a shut door (#982).
|
|
339
350
|
const lockedTarget = pluginArgs.find(argument => !argument.startsWith('-') && argument !== verb) ?? '';
|
|
340
351
|
const lockedName = registryNameOf(lockedTarget) ?? lockedTarget;
|
|
341
|
-
if (lockedName !== 'dsh-crate') {
|
|
352
|
+
if (lockedName !== 'dsh-crate' && lockedName !== 'dsh-crate') {
|
|
342
353
|
result = {
|
|
343
354
|
...result,
|
|
344
355
|
stderr: `${result.stderr}\n\n这是官方桌面端:上面「在命令行执行」这一条在这里用不了,请改在应用自己的「设置 → 插件」里操作(退出重启后,或先停用加载该包的插件再重启)。 / This is the official desktop app: the "run it from the command line" option above is not available here — use the app's own Settings → Plugins instead (after restarting, or after disabling the plugin that loads this package and restarting).`,
|
|
@@ -413,6 +424,7 @@ export async function withHoistRecovery(run, profile, pluginArgs, profileDirecto
|
|
|
413
424
|
logEvent('warn', 'install', `could not merge minimumReleaseAgeExclude after success (#883, #878): ${String(error)}`);
|
|
414
425
|
}
|
|
415
426
|
}
|
|
427
|
+
learnReleaseBlockers(profile, profileDirectory, pluginArgs, result, bypassed);
|
|
416
428
|
// After every mutation — success, failure, and cancel. Garbage lands in
|
|
417
429
|
// `.ignored` on the NEXT pnpm run, so a success-only hook would miss the
|
|
418
430
|
// run that just moved it there (#974). Must not fail the user's command.
|
|
@@ -425,6 +437,34 @@ export async function withHoistRecovery(run, profile, pluginArgs, profileDirecto
|
|
|
425
437
|
catch { /* cleanup must never fail the install */ }
|
|
426
438
|
return result;
|
|
427
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* Keep what the last run taught about the profile's young lockfile entries
|
|
442
|
+
* (#1252): a refusal names them, a success without the bypass proves there
|
|
443
|
+
* are none. Must never fail the user's command.
|
|
444
|
+
*/
|
|
445
|
+
function learnReleaseBlockers(profile, profileDirectory, pluginArgs, result, bypassed) {
|
|
446
|
+
try {
|
|
447
|
+
const verb = pluginArgs.find(argument => !argument.startsWith('-'));
|
|
448
|
+
const mutates = verb === 'add' || verb === 'remove' || verb === 'install' || verb === 'update';
|
|
449
|
+
if (!mutates || result.cancelled)
|
|
450
|
+
return;
|
|
451
|
+
const dir = profileDir(profile, profileDirectory);
|
|
452
|
+
if (result.exitCode === 0 && !result.timedOut) {
|
|
453
|
+
if (!bypassed)
|
|
454
|
+
clearReleaseBlockers(dir);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const output = `${result.stderr}\n${result.stdout}`;
|
|
458
|
+
if (classifyPnpmFailure(output, result.exitCode, { profileDirectory })?.code !== 'release-age-violation')
|
|
459
|
+
return;
|
|
460
|
+
const blockers = parseReleaseAgeBlockers(output, readMinimumReleaseAgeMs(profile, profileDirectory));
|
|
461
|
+
if (blockers.length === 0)
|
|
462
|
+
return;
|
|
463
|
+
recordReleaseBlockers(dir, blockers);
|
|
464
|
+
logEvent('warn', 'install', `the profile's lockfile holds ${blockers.length} release(s) still inside the safety wait (${blockers.slice(0, 3).map(blocker => `${blocker.name}@${blocker.version}${blocker.readyAt === null ? ' (end unknown)' : ` until ${blocker.readyAt}`}`).join(', ')}) — updates are held until then (#1252)`);
|
|
465
|
+
}
|
|
466
|
+
catch { /* bookkeeping must never fail the install */ }
|
|
467
|
+
}
|
|
428
468
|
/**
|
|
429
469
|
* The tail of the diagnostics file the dsh CLI pointed at, when it pointed at
|
|
430
470
|
* one (#672).
|
|
@@ -953,6 +993,158 @@ function pointsAtProfilePackage(target, expected) {
|
|
|
953
993
|
const right = resolve(expected);
|
|
954
994
|
return process.platform === 'win32' ? left.toLowerCase() === right.toLowerCase() : left === right;
|
|
955
995
|
}
|
|
996
|
+
function assertProfileLinkParent(path) {
|
|
997
|
+
const parent = dirname(path);
|
|
998
|
+
if (!pointsAtProfilePackage(realpathSync(parent), parent)) {
|
|
999
|
+
throw new Error('the profile package directory now resolves outside its original location');
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
function absoluteLinkTarget(path, target) {
|
|
1003
|
+
return resolve(dirname(path), normalizedLinkTarget(target));
|
|
1004
|
+
}
|
|
1005
|
+
function sameCheckoutTarget(path, actual, raw) {
|
|
1006
|
+
return pointsAtProfilePackage(absoluteLinkTarget(path, actual), absoluteLinkTarget(path, raw));
|
|
1007
|
+
}
|
|
1008
|
+
function unlinkCheckoutEntry(path, entry, target) {
|
|
1009
|
+
const current = lstatSync(path, { throwIfNoEntry: false });
|
|
1010
|
+
if (current?.isSymbolicLink() !== true || current.dev !== entry.dev || current.ino !== entry.ino || readlinkSync(path) !== target) {
|
|
1011
|
+
throw new Error('the profile link changed while preparing the switch');
|
|
1012
|
+
}
|
|
1013
|
+
// unlinkSync removes the profile link, including a Windows junction.
|
|
1014
|
+
unlinkSync(path);
|
|
1015
|
+
}
|
|
1016
|
+
function checkoutSlot(profileDirectory, name) {
|
|
1017
|
+
if (!NPM_NAME_RE.test(name))
|
|
1018
|
+
throw new Error('invalid linked profile dependency');
|
|
1019
|
+
const root = realpathSync(profileDirectory);
|
|
1020
|
+
const moduleRoot = join(root, 'node_modules');
|
|
1021
|
+
return { root, moduleRoot, path: join(moduleRoot, name) };
|
|
1022
|
+
}
|
|
1023
|
+
/** Reconstruct a saved link using only the active profile and matching checkout. */
|
|
1024
|
+
export function recordedCheckoutLink(profileDirectory, name, spec, rawTarget) {
|
|
1025
|
+
if (!/^link:.+/i.test(spec))
|
|
1026
|
+
throw new Error('invalid linked profile dependency');
|
|
1027
|
+
const { root, moduleRoot, path } = checkoutSlot(profileDirectory, name);
|
|
1028
|
+
assertProfileLinkParent(path);
|
|
1029
|
+
const actual = absoluteLinkTarget(path, rawTarget);
|
|
1030
|
+
const recorded = spec.slice(5).replace(/^~(?=$|[\\/])/, () => homedir());
|
|
1031
|
+
const expected = resolve(root, normalizedLinkTarget(recorded));
|
|
1032
|
+
let matches = pointsAtProfilePackage(actual, expected);
|
|
1033
|
+
if (!matches) {
|
|
1034
|
+
try {
|
|
1035
|
+
matches = pointsAtProfilePackage(realpathSync(actual), realpathSync(expected));
|
|
1036
|
+
}
|
|
1037
|
+
catch { /* no filesystem alias proves this is the recorded checkout */ }
|
|
1038
|
+
}
|
|
1039
|
+
if (!matches)
|
|
1040
|
+
throw new Error('the profile link points to a different checkout');
|
|
1041
|
+
return { path, rawTarget, moduleRoot };
|
|
1042
|
+
}
|
|
1043
|
+
/** Check the saved checkout without creating its profile link. */
|
|
1044
|
+
export function checkoutSourceExists(link) {
|
|
1045
|
+
return statSync(absoluteLinkTarget(link.path, link.rawTarget), { throwIfNoEntry: false })?.isDirectory() === true;
|
|
1046
|
+
}
|
|
1047
|
+
/** Disconnect only the profile junction that still matches the recorded local checkout. */
|
|
1048
|
+
export function detachCheckoutLink(profileDirectory, name, spec, record) {
|
|
1049
|
+
const { path } = checkoutSlot(profileDirectory, name);
|
|
1050
|
+
const entry = lstatSync(path, { throwIfNoEntry: false });
|
|
1051
|
+
if (entry?.isSymbolicLink() !== true)
|
|
1052
|
+
return null;
|
|
1053
|
+
const rawTarget = readlinkSync(path);
|
|
1054
|
+
const link = recordedCheckoutLink(profileDirectory, name, spec, rawTarget);
|
|
1055
|
+
if (!pointsAtProfilePackage(link.path, path))
|
|
1056
|
+
throw new Error('the profile directory changed while preparing the switch');
|
|
1057
|
+
record(link);
|
|
1058
|
+
assertProfileLinkParent(path);
|
|
1059
|
+
unlinkCheckoutEntry(path, entry, rawTarget);
|
|
1060
|
+
return link;
|
|
1061
|
+
}
|
|
1062
|
+
function isPackageStoreLink(link) {
|
|
1063
|
+
try {
|
|
1064
|
+
const withinStore = relative(join(link.moduleRoot, '.pnpm'), realpathSync(link.path));
|
|
1065
|
+
return withinStore !== '' && !isAbsolute(withinStore) && withinStore !== '..' && !withinStore.startsWith(`..${sep}`);
|
|
1066
|
+
}
|
|
1067
|
+
catch {
|
|
1068
|
+
return false;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
/** Recheck the slot before a pnpm recovery retry can replace it again. */
|
|
1072
|
+
export function keepCheckoutDetached(link) {
|
|
1073
|
+
assertProfileLinkParent(link.path);
|
|
1074
|
+
const entry = lstatSync(link.path, { throwIfNoEntry: false });
|
|
1075
|
+
if (entry?.isSymbolicLink() !== true)
|
|
1076
|
+
return;
|
|
1077
|
+
const currentTarget = readlinkSync(link.path);
|
|
1078
|
+
if (sameCheckoutTarget(link.path, currentTarget, link.rawTarget)) {
|
|
1079
|
+
unlinkCheckoutEntry(link.path, entry, currentTarget);
|
|
1080
|
+
}
|
|
1081
|
+
else if (!isPackageStoreLink(link)) {
|
|
1082
|
+
throw new Error('the profile link now points to a different checkout');
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Restore the captured checkout link without asking pnpm to touch it. On
|
|
1087
|
+
* rollback a package materialized inside the profile can be staged until the
|
|
1088
|
+
* link and the caller's saved manifest are restored.
|
|
1089
|
+
*/
|
|
1090
|
+
export function restoreCheckoutLink(link, replacePackage, restoreMetadata) {
|
|
1091
|
+
const { path, rawTarget } = link;
|
|
1092
|
+
assertProfileLinkParent(path);
|
|
1093
|
+
const entry = lstatSync(path, { throwIfNoEntry: false });
|
|
1094
|
+
if (entry?.isSymbolicLink() === true && sameCheckoutTarget(path, readlinkSync(path), rawTarget)) {
|
|
1095
|
+
restoreMetadata();
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
let staging;
|
|
1099
|
+
let displaced;
|
|
1100
|
+
let created;
|
|
1101
|
+
try {
|
|
1102
|
+
if (entry !== undefined) {
|
|
1103
|
+
if (!replacePackage || !(entry.isDirectory() || (entry.isSymbolicLink() && isPackageStoreLink(link)))) {
|
|
1104
|
+
throw new Error('another entry occupies the profile package path');
|
|
1105
|
+
}
|
|
1106
|
+
staging = mkdtempSync(join(dirname(path), '.dshm-restore-'));
|
|
1107
|
+
displaced = join(staging, 'package');
|
|
1108
|
+
renameSync(path, displaced);
|
|
1109
|
+
const moved = lstatSync(displaced);
|
|
1110
|
+
if (moved.dev !== entry.dev || moved.ino !== entry.ino || moved.isSymbolicLink() !== entry.isSymbolicLink()) {
|
|
1111
|
+
throw new Error('the profile package changed before it could be restored');
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
if (process.platform === 'win32')
|
|
1115
|
+
symlinkSync(absoluteLinkTarget(path, rawTarget), path, 'junction');
|
|
1116
|
+
else
|
|
1117
|
+
symlinkSync(rawTarget, path, 'dir');
|
|
1118
|
+
created = lstatSync(path);
|
|
1119
|
+
restoreMetadata();
|
|
1120
|
+
}
|
|
1121
|
+
catch (error) {
|
|
1122
|
+
if (created !== undefined) {
|
|
1123
|
+
const now = lstatSync(path, { throwIfNoEntry: false });
|
|
1124
|
+
if (now?.isSymbolicLink() === true && now.dev === created.dev && now.ino === created.ino)
|
|
1125
|
+
unlinkSync(path);
|
|
1126
|
+
}
|
|
1127
|
+
if (displaced !== undefined && lstatSync(displaced, { throwIfNoEntry: false }) !== undefined) {
|
|
1128
|
+
// A concurrently installed entry takes precedence. Leave the displaced
|
|
1129
|
+
// directory available inside the profile if the original slot is taken.
|
|
1130
|
+
if (lstatSync(path, { throwIfNoEntry: false }) !== undefined) {
|
|
1131
|
+
throw new Error(`the profile package path changed; saved package is at ${displaced}`, { cause: error });
|
|
1132
|
+
}
|
|
1133
|
+
renameSync(displaced, path);
|
|
1134
|
+
}
|
|
1135
|
+
if (staging !== undefined)
|
|
1136
|
+
rmSync(staging, { force: true, recursive: true });
|
|
1137
|
+
throw error;
|
|
1138
|
+
}
|
|
1139
|
+
if (staging !== undefined) {
|
|
1140
|
+
try {
|
|
1141
|
+
rmSync(staging, { force: true, recursive: true });
|
|
1142
|
+
}
|
|
1143
|
+
catch (error) {
|
|
1144
|
+
logEvent('warn', 'update-rollback', `could not clean the staged profile package at ${staging}: ${String(error)}`);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
956
1148
|
/**
|
|
957
1149
|
* Remove the host-side bridge link a confirmed uninstall leaves dangling
|
|
958
1150
|
* (#662). The official boot projects profile packages into the host
|
|
@@ -1014,10 +1206,9 @@ export function removeDanglingHostBridge(name, profileDirectory, hostDirectory)
|
|
|
1014
1206
|
* release) makes pnpm rename `<name>_tmp_*` over it, which Windows refuses
|
|
1015
1207
|
* with EPERM.
|
|
1016
1208
|
*
|
|
1017
|
-
* Only a link is
|
|
1018
|
-
* `name`
|
|
1019
|
-
*
|
|
1020
|
-
* at (the same measurement the host-bridge cleanup above relies on).
|
|
1209
|
+
* Only a link is touched, and only when the manifest no longer lists
|
|
1210
|
+
* `name`. `unlinkSync` also handles directory junctions in Desktop's
|
|
1211
|
+
* embedded Node, which reports EISDIR for nonrecursive `rmSync`.
|
|
1021
1212
|
*
|
|
1022
1213
|
* @returns the checkout path the removed link pointed at, or null when there
|
|
1023
1214
|
* was nothing to remove. Never throws: the uninstall already succeeded.
|
|
@@ -1030,7 +1221,7 @@ export function removeLeftoverProfileLink(profile, name, profileDirectory) {
|
|
|
1030
1221
|
if (readInstalled(profile, profileDirectory)[name] !== undefined)
|
|
1031
1222
|
return null;
|
|
1032
1223
|
const target = readlinkSync(path);
|
|
1033
|
-
|
|
1224
|
+
unlinkSync(path);
|
|
1034
1225
|
logEvent('info', 'uninstall', `${name}: removed the leftover link at node_modules/${name} (it pointed at ${target}); the checkout itself was not touched (#1191)`);
|
|
1035
1226
|
return target;
|
|
1036
1227
|
}
|