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/types/routes.d.ts
CHANGED
|
@@ -125,6 +125,6 @@ export declare function marketVersion(): string;
|
|
|
125
125
|
* Register the market's HTTP routes.
|
|
126
126
|
* @param host - Acquired webServer + shell services.
|
|
127
127
|
* @param config - Validated market configuration.
|
|
128
|
-
* @returns Disposer removing every registered route.
|
|
128
|
+
* @returns Disposer removing every registered route and draining queued cache writes.
|
|
129
129
|
*/
|
|
130
|
-
export declare function mountMarketRoutes(host: MarketHost, config: MarketConfig, commandRuntime?: PluginCommandRuntime, agentsLookup?: AgentsLookup, hostActivation?: HostPluginActivation): () => void
|
|
130
|
+
export declare function mountMarketRoutes(host: MarketHost, config: MarketConfig, commandRuntime?: PluginCommandRuntime, agentsLookup?: AgentsLookup, hostActivation?: HostPluginActivation): () => Promise<void>;
|
package/lib/types/themes.d.ts
CHANGED
|
@@ -36,7 +36,12 @@ export interface ThemeHost {
|
|
|
36
36
|
export interface ThemeManager {
|
|
37
37
|
installedThemeNames(): Promise<Set<string>>;
|
|
38
38
|
setEntryDisabled(name: string, disabledFlag: boolean, requireLive?: boolean, rejectPending?: boolean): Promise<boolean>;
|
|
39
|
-
activateTheme(name: string): Promise<
|
|
39
|
+
activateTheme(name: string): Promise<ThemeActivationResult>;
|
|
40
|
+
}
|
|
41
|
+
interface ThemeActivationResult {
|
|
42
|
+
ok: boolean;
|
|
43
|
+
/** Verified component failure before rolling back the attempted switch. */
|
|
44
|
+
reason?: string;
|
|
40
45
|
}
|
|
41
46
|
/**
|
|
42
47
|
* Create the theme manager. `disabledThemes` is the live, shared set of
|
|
@@ -44,3 +49,4 @@ export interface ThemeManager {
|
|
|
44
49
|
* replaying it; the manager mutates and persists it on switches.
|
|
45
50
|
*/
|
|
46
51
|
export declare function createThemeManager(host: ThemeHost, profile: string, disabledThemes: Set<string>, explicitDir?: string): ThemeManager;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Persisted choices shared by the profile monitor and its settings UI. */
|
|
2
|
+
export declare const UPDATE_CHECK_INTERVAL_HOURS: readonly [6, 12, 72, 168];
|
|
3
|
+
export type UpdateCheckIntervalHours = typeof UPDATE_CHECK_INTERVAL_HOURS[number];
|
|
4
|
+
export declare const DEFAULT_UPDATE_CHECK_INTERVAL_HOURS: UpdateCheckIntervalHours;
|
|
5
|
+
export declare function isUpdateCheckIntervalHours(value: unknown): value is UpdateCheckIntervalHours;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Shared, read-only update checks for every market surface in one profile. */
|
|
2
|
+
import type { UpdateStatus } from './updates.ts';
|
|
3
|
+
import { type UpdateCheckIntervalHours } from './update-notification-settings.ts';
|
|
4
|
+
export declare const UPDATE_CHECK_START_DELAY_MS = 30000;
|
|
5
|
+
export declare const UPDATE_CHECK_INTERVAL_MS: number;
|
|
6
|
+
/** Notification data; reading a snapshot never contacts an update source. */
|
|
7
|
+
export interface UpdateNotificationSnapshot {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
intervalHours: UpdateCheckIntervalHours;
|
|
10
|
+
checking: boolean;
|
|
11
|
+
checkedAt: number | null;
|
|
12
|
+
lastSuccessAt: number | null;
|
|
13
|
+
nextCheckAt: number | null;
|
|
14
|
+
stale: boolean;
|
|
15
|
+
error: string | null;
|
|
16
|
+
updates: Record<string, UpdateStatus>;
|
|
17
|
+
boot: string;
|
|
18
|
+
/** Stable opaque profile identity for client-side read receipts. */
|
|
19
|
+
profileKey?: string;
|
|
20
|
+
updateExempt: string[];
|
|
21
|
+
disabled: string[];
|
|
22
|
+
blocked: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface UpdateNotificationInventory {
|
|
25
|
+
/** Includes the profile and release channel; a change invalidates all results. */
|
|
26
|
+
context: string;
|
|
27
|
+
/** Per-package source, installed version and locked commit identity. */
|
|
28
|
+
packages: Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
interface MonitorDependencies {
|
|
31
|
+
boot: string;
|
|
32
|
+
profileKey?: string;
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
intervalHours?: UpdateCheckIntervalHours;
|
|
35
|
+
inventory(): UpdateNotificationInventory;
|
|
36
|
+
preferences(): Pick<UpdateNotificationSnapshot, 'updateExempt' | 'disabled' | 'blocked'>;
|
|
37
|
+
check(force: boolean): Promise<{
|
|
38
|
+
updates: Record<string, UpdateStatus>;
|
|
39
|
+
error?: string;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
export interface UpdateNotificationMonitor {
|
|
43
|
+
snapshot(): UpdateNotificationSnapshot;
|
|
44
|
+
check(force?: boolean): Promise<Record<string, UpdateStatus>>;
|
|
45
|
+
setEnabled(enabled: boolean): void;
|
|
46
|
+
setIntervalHours(intervalHours: UpdateCheckIntervalHours): void;
|
|
47
|
+
dispose(): void;
|
|
48
|
+
}
|
|
49
|
+
/** Start one profile-scoped timer; callers own persistence of the preferences. */
|
|
50
|
+
export declare function createUpdateNotificationMonitor(deps: MonitorDependencies): UpdateNotificationMonitor;
|
|
51
|
+
export {};
|
package/lib/types/updates.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export interface UpdateStatus {
|
|
|
23
23
|
* as "there is an upgrade" and labels a button accordingly.
|
|
24
24
|
*/
|
|
25
25
|
updateAvailable: boolean;
|
|
26
|
+
/** Source lookup failed; notification surfaces may retain a previous confirmed result. */
|
|
27
|
+
checkError?: 'unavailable';
|
|
28
|
+
/** The upstream check failed, so this row does not establish that the plugin is current. */
|
|
29
|
+
checkFailed?: true;
|
|
26
30
|
/** Exact mature npm stable target for Desktop; `latest` remains the registry tag. */
|
|
27
31
|
eligibleVersion?: string;
|
|
28
32
|
/**
|
|
@@ -237,7 +241,7 @@ export declare function fetchNpmLatest(name: string): Promise<string | null>;
|
|
|
237
241
|
* without the market volunteering anyone's prerelease as an update.
|
|
238
242
|
*/
|
|
239
243
|
export declare function newerPrereleaseFor(name: string, installed: string | null): Promise<string | null>;
|
|
240
|
-
/**
|
|
244
|
+
/** Check each plugin independently so a failed lookup leaves the other results usable. */
|
|
241
245
|
export declare function checkUpdates(profile: string, force?: boolean, explicitDir?: string,
|
|
242
246
|
/**
|
|
243
247
|
* Packages that follow a release channel instead of plain `latest`. Only
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Persisted choices shared by the profile monitor and its settings UI. */
|
|
2
|
+
export const UPDATE_CHECK_INTERVAL_HOURS = [6, 12, 72, 168];
|
|
3
|
+
export const DEFAULT_UPDATE_CHECK_INTERVAL_HOURS = 6;
|
|
4
|
+
export function isUpdateCheckIntervalHours(value) {
|
|
5
|
+
return typeof value === 'number' && UPDATE_CHECK_INTERVAL_HOURS.includes(value);
|
|
6
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { DEFAULT_UPDATE_CHECK_INTERVAL_HOURS, isUpdateCheckIntervalHours } from './update-notification-settings.js';
|
|
2
|
+
export const UPDATE_CHECK_START_DELAY_MS = 30_000;
|
|
3
|
+
export const UPDATE_CHECK_INTERVAL_MS = DEFAULT_UPDATE_CHECK_INTERVAL_HOURS * 60 * 60_000;
|
|
4
|
+
const RETRY_BASE_MS = 60_000;
|
|
5
|
+
const RETRY_MAX_MS = 30 * 60_000;
|
|
6
|
+
/** Start one profile-scoped timer; callers own persistence of the preferences. */
|
|
7
|
+
export function createUpdateNotificationMonitor(deps) {
|
|
8
|
+
let enabled = deps.enabled;
|
|
9
|
+
let intervalHours = isUpdateCheckIntervalHours(deps.intervalHours) ? deps.intervalHours : DEFAULT_UPDATE_CHECK_INTERVAL_HOURS;
|
|
10
|
+
let disposed = false;
|
|
11
|
+
let timer;
|
|
12
|
+
let nextCheckAt = null;
|
|
13
|
+
let checkedAt = null;
|
|
14
|
+
let lastSuccessAt = null;
|
|
15
|
+
let error = null;
|
|
16
|
+
let stale = false;
|
|
17
|
+
let failures = 0;
|
|
18
|
+
let updates = {};
|
|
19
|
+
let identity = deps.inventory();
|
|
20
|
+
let pending = null;
|
|
21
|
+
let pendingForced = false;
|
|
22
|
+
let queuedForce = null;
|
|
23
|
+
const reconcile = () => {
|
|
24
|
+
const current = deps.inventory();
|
|
25
|
+
if (current.context !== identity.context) {
|
|
26
|
+
updates = {};
|
|
27
|
+
checkedAt = null;
|
|
28
|
+
lastSuccessAt = null;
|
|
29
|
+
error = null;
|
|
30
|
+
stale = true;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const kept = {};
|
|
34
|
+
for (const [name, status] of Object.entries(updates)) {
|
|
35
|
+
if (current.packages[name] !== undefined && current.packages[name] === identity.packages[name])
|
|
36
|
+
kept[name] = status;
|
|
37
|
+
else
|
|
38
|
+
stale = true;
|
|
39
|
+
}
|
|
40
|
+
if (Object.keys(current.packages).some(name => current.packages[name] !== identity.packages[name]))
|
|
41
|
+
stale = true;
|
|
42
|
+
updates = kept;
|
|
43
|
+
}
|
|
44
|
+
identity = current;
|
|
45
|
+
return current;
|
|
46
|
+
};
|
|
47
|
+
const stopTimer = () => {
|
|
48
|
+
if (timer !== undefined)
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
timer = undefined;
|
|
51
|
+
nextCheckAt = null;
|
|
52
|
+
};
|
|
53
|
+
const schedule = (delay) => {
|
|
54
|
+
stopTimer();
|
|
55
|
+
if (disposed || !enabled)
|
|
56
|
+
return;
|
|
57
|
+
nextCheckAt = Date.now() + delay;
|
|
58
|
+
timer = setTimeout(() => { void check(stale); }, delay);
|
|
59
|
+
timer.unref?.();
|
|
60
|
+
};
|
|
61
|
+
const nextDelay = () => failures > 0
|
|
62
|
+
? Math.min(RETRY_MAX_MS, RETRY_BASE_MS * 2 ** Math.min(failures - 1, 5))
|
|
63
|
+
: intervalHours * 60 * 60_000;
|
|
64
|
+
const check = (force = false) => {
|
|
65
|
+
if (disposed)
|
|
66
|
+
return Promise.resolve({ ...updates });
|
|
67
|
+
if (pending !== null) {
|
|
68
|
+
if (!force || pendingForced)
|
|
69
|
+
return pending;
|
|
70
|
+
// A manual refresh arriving during a cache-eligible read must still
|
|
71
|
+
// bypass that cache, once. Several such callers share the follow-up.
|
|
72
|
+
queuedForce ??= pending.then(() => check(true)).finally(() => { queuedForce = null; });
|
|
73
|
+
return queuedForce;
|
|
74
|
+
}
|
|
75
|
+
stopTimer();
|
|
76
|
+
const started = reconcile();
|
|
77
|
+
pendingForced = force || stale;
|
|
78
|
+
// Scheduling into a microtask also makes simultaneous callers share the
|
|
79
|
+
// promise before input gathering starts.
|
|
80
|
+
pending = Promise.resolve().then(async () => {
|
|
81
|
+
try {
|
|
82
|
+
const result = await deps.check(pendingForced);
|
|
83
|
+
if (disposed)
|
|
84
|
+
return { ...updates };
|
|
85
|
+
const current = reconcile();
|
|
86
|
+
const next = { ...updates };
|
|
87
|
+
let incomplete = result.error !== undefined;
|
|
88
|
+
for (const [name, status] of Object.entries(result.updates)) {
|
|
89
|
+
if (current.context !== started.context || current.packages[name] === undefined
|
|
90
|
+
|| current.packages[name] !== started.packages[name]) {
|
|
91
|
+
incomplete = true;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (status.checkFailed === true || status.checkError !== undefined) {
|
|
95
|
+
incomplete = true;
|
|
96
|
+
next[name] = { ...(updates[name] ?? status), checkFailed: true, checkError: 'unavailable',
|
|
97
|
+
...(status.sourceMigration === undefined ? {} : { sourceMigration: status.sourceMigration }) };
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
next[name] = status;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (Object.keys(current.packages).some(name => result.updates[name] === undefined
|
|
104
|
+
|| current.context !== started.context || current.packages[name] !== started.packages[name]))
|
|
105
|
+
incomplete = true;
|
|
106
|
+
updates = next;
|
|
107
|
+
checkedAt = Date.now();
|
|
108
|
+
stale = incomplete;
|
|
109
|
+
error = incomplete ? result.error ?? 'Some plugin updates could not be checked. Try again later.' : null;
|
|
110
|
+
if (!incomplete)
|
|
111
|
+
lastSuccessAt = checkedAt;
|
|
112
|
+
failures = incomplete ? failures + 1 : 0;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
if (disposed)
|
|
116
|
+
return { ...updates };
|
|
117
|
+
reconcile();
|
|
118
|
+
updates = Object.fromEntries(Object.entries(updates).map(([name, status]) => [name, { ...status, checkFailed: true, checkError: 'unavailable' }]));
|
|
119
|
+
checkedAt = Date.now();
|
|
120
|
+
stale = true;
|
|
121
|
+
error = 'Plugin updates could not be checked. Try again later.';
|
|
122
|
+
failures += 1;
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
pending = null;
|
|
126
|
+
if (!disposed)
|
|
127
|
+
schedule(nextDelay());
|
|
128
|
+
}
|
|
129
|
+
return { ...updates };
|
|
130
|
+
});
|
|
131
|
+
return pending;
|
|
132
|
+
};
|
|
133
|
+
schedule(UPDATE_CHECK_START_DELAY_MS);
|
|
134
|
+
return {
|
|
135
|
+
snapshot: () => {
|
|
136
|
+
reconcile();
|
|
137
|
+
return {
|
|
138
|
+
enabled, intervalHours, checking: pending !== null, checkedAt, lastSuccessAt, nextCheckAt,
|
|
139
|
+
stale, error, updates: { ...updates }, boot: deps.boot, ...deps.preferences(),
|
|
140
|
+
...(deps.profileKey === undefined ? {} : { profileKey: deps.profileKey }),
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
check,
|
|
144
|
+
setEnabled: value => {
|
|
145
|
+
if (enabled === value || disposed)
|
|
146
|
+
return;
|
|
147
|
+
enabled = value;
|
|
148
|
+
stopTimer();
|
|
149
|
+
if (enabled && pending === null)
|
|
150
|
+
schedule(UPDATE_CHECK_START_DELAY_MS);
|
|
151
|
+
},
|
|
152
|
+
setIntervalHours: value => {
|
|
153
|
+
if (!isUpdateCheckIntervalHours(value) || intervalHours === value || disposed)
|
|
154
|
+
return;
|
|
155
|
+
intervalHours = value;
|
|
156
|
+
// Keep a pending check single-flight; its completion uses the newest
|
|
157
|
+
// choice. Changing a disabled monitor never opts the user in.
|
|
158
|
+
if (pending === null)
|
|
159
|
+
schedule(checkedAt === null ? UPDATE_CHECK_START_DELAY_MS : nextDelay());
|
|
160
|
+
},
|
|
161
|
+
dispose: () => {
|
|
162
|
+
disposed = true;
|
|
163
|
+
stopTimer();
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
package/lib/updates.js
CHANGED
|
@@ -57,6 +57,7 @@ export function isUpdatablePlugin(activeProfileDir, name, bundles) {
|
|
|
57
57
|
const UPDATES_TTL_MS = 30 * 60 * 1000;
|
|
58
58
|
const GIT_REMOTE_HEAD_TIMEOUT_MS = 6000;
|
|
59
59
|
let updatesCache = null;
|
|
60
|
+
let updateCheckGeneration = 0;
|
|
60
61
|
/**
|
|
61
62
|
* HEAD for an arbitrary smart-HTTP git remote (Gitea, GitLab, …). Same
|
|
62
63
|
* advertisement format as GitHub's info/refs; kept here so accelerate.ts
|
|
@@ -179,6 +180,7 @@ export function invalidateUpdates() {
|
|
|
179
180
|
// because a request merely entered the queue.
|
|
180
181
|
if (inProbe())
|
|
181
182
|
return;
|
|
183
|
+
updateCheckGeneration += 1;
|
|
182
184
|
updatesCache = null;
|
|
183
185
|
}
|
|
184
186
|
/**
|
|
@@ -205,6 +207,7 @@ export function setUpdateRegistry(base) {
|
|
|
205
207
|
if (next === registryBase)
|
|
206
208
|
return;
|
|
207
209
|
registryBase = next;
|
|
210
|
+
updateCheckGeneration += 1;
|
|
208
211
|
updatesCache = null;
|
|
209
212
|
}
|
|
210
213
|
/** A registry URL for `path`, on whichever registry is currently in force. */
|
|
@@ -409,7 +412,7 @@ export async function readVersionMaturity(name, version, profile, activeProfileD
|
|
|
409
412
|
reason: maturity.mature ? 'eligible' : maturity.publishedAt === null ? 'unknown-age' : 'held',
|
|
410
413
|
};
|
|
411
414
|
}
|
|
412
|
-
async function fetchJson(url) {
|
|
415
|
+
async function fetchJson(url, allowNotFound = false) {
|
|
413
416
|
// Through the proxy when one is configured: Node's global fetch ignores
|
|
414
417
|
// HTTP_PROXY, so on a machine whose route out is a local proxy every
|
|
415
418
|
// update check silently took the slow path — or none at all.
|
|
@@ -417,6 +420,8 @@ async function fetchJson(url) {
|
|
|
417
420
|
headers: { accept: 'application/json', 'user-agent': 'dsh-crate' },
|
|
418
421
|
signal: AbortSignal.timeout(10_000),
|
|
419
422
|
});
|
|
423
|
+
if (allowNotFound && res.status === 404)
|
|
424
|
+
return undefined;
|
|
420
425
|
if (!res.ok)
|
|
421
426
|
throw new Error(`HTTP ${res.status}`);
|
|
422
427
|
return res.json();
|
|
@@ -736,7 +741,7 @@ function profilePolicyFingerprint(dir) {
|
|
|
736
741
|
}
|
|
737
742
|
return hash.digest('hex');
|
|
738
743
|
}
|
|
739
|
-
/**
|
|
744
|
+
/** Check each plugin independently so a failed lookup leaves the other results usable. */
|
|
740
745
|
export async function checkUpdates(profile, force = false, explicitDir,
|
|
741
746
|
/**
|
|
742
747
|
* Packages that follow a release channel instead of plain `latest`. Only
|
|
@@ -768,16 +773,19 @@ catalogNpmByRepo = new Map(),
|
|
|
768
773
|
*/
|
|
769
774
|
options = {}) {
|
|
770
775
|
const activeProfileDir = profileDir(profile, explicitDir);
|
|
776
|
+
const installed = readInstalled(profile, activeProfileDir);
|
|
777
|
+
const lockCommits = readLockCommits(profile, activeProfileDir);
|
|
778
|
+
const installedIdentity = JSON.stringify(Object.entries(installed).sort(([a], [b]) => a.localeCompare(b))
|
|
779
|
+
.map(([name, spec]) => [name, spec, readInstalledVersion(profile, name, activeProfileDir), readGitResolutionCommit(profile, spec, activeProfileDir)]));
|
|
771
780
|
// The channel is part of the key: switching to betas has to change the
|
|
772
781
|
// answer immediately, and a cache keyed on the profile alone would serve
|
|
773
782
|
// the stable verdict for the rest of the TTL — reading as "the setting did
|
|
774
783
|
// nothing".
|
|
775
|
-
const cacheKey = `${activeProfileDir}\u0000${options.holdYoungReleases === true ? 'hold' : 'any'}\u0000${[...channelFor].map(([n, c]) => `${n}:${c}`).sort().join(',')}\u0000${[...onlineSourceFor].map(([n, s]) => `${n}:${s}`).sort().join(',')}\u0000${[...catalogNpmByRepo].map(([n, s]) => `${n}:${s}`).sort().join(',')}\u0000${options.holdYoungReleases === true ? profilePolicyFingerprint(activeProfileDir) : ''}` + JSON.stringify([...(options.releaseSources ?? [])]);
|
|
784
|
+
const cacheKey = `${activeProfileDir}\u0000${options.holdYoungReleases === true ? 'hold' : 'any'}\u0000${[...channelFor].map(([n, c]) => `${n}:${c}`).sort().join(',')}\u0000${[...onlineSourceFor].map(([n, s]) => `${n}:${s}`).sort().join(',')}\u0000${[...catalogNpmByRepo].map(([n, s]) => `${n}:${s}`).sort().join(',')}\u0000${options.holdYoungReleases === true ? profilePolicyFingerprint(activeProfileDir) : ''}` + JSON.stringify([...(options.releaseSources ?? [])]) + installedIdentity + JSON.stringify([...lockCommits].sort());
|
|
776
785
|
if (!force && updatesCache?.key === cacheKey && Date.now() < updatesCache.recheckAt) {
|
|
777
786
|
return updatesCache.data;
|
|
778
787
|
}
|
|
779
|
-
const
|
|
780
|
-
const lockCommits = readLockCommits(profile, activeProfileDir);
|
|
788
|
+
const generation = ++updateCheckGeneration;
|
|
781
789
|
const result = {};
|
|
782
790
|
let nextCandidateMaturityAt = Infinity;
|
|
783
791
|
await Promise.all(Object.entries(installed).map(async ([name, spec]) => {
|
|
@@ -795,6 +803,7 @@ options = {}) {
|
|
|
795
803
|
result[name] = {
|
|
796
804
|
kind: 'linked', version, current: version, latest,
|
|
797
805
|
updateAvailable: upgrade && !held,
|
|
806
|
+
...(latest === null ? { checkFailed: true, checkError: 'unavailable' } : {}),
|
|
798
807
|
...(held ? { heldUpdate: { latest: latest, until: hold.until, ...(hold.estimated ? { estimated: true } : {}) } } : {}),
|
|
799
808
|
...(upgrade ? { restoreRequired: true } : {}),
|
|
800
809
|
};
|
|
@@ -823,6 +832,7 @@ options = {}) {
|
|
|
823
832
|
kind: 'generation', version, current: version,
|
|
824
833
|
latest: isUpgrade(version, newest) ? newest : null,
|
|
825
834
|
updateAvailable: false,
|
|
835
|
+
...(onlineSource !== undefined && newest === null ? { checkFailed: true, checkError: 'unavailable' } : {}),
|
|
826
836
|
};
|
|
827
837
|
return;
|
|
828
838
|
}
|
|
@@ -861,6 +871,7 @@ options = {}) {
|
|
|
861
871
|
result[name] = {
|
|
862
872
|
kind: 'github', version, current, latest,
|
|
863
873
|
updateAvailable: byVersion ?? (current !== null && latest !== null && current !== latest),
|
|
874
|
+
...(latest === null && byVersion === null ? { checkFailed: true, checkError: 'unavailable' } : {}),
|
|
864
875
|
...(byVersion === false && current !== null && latest !== null && current !== latest
|
|
865
876
|
? { unreleasedCommit: latest } : {}),
|
|
866
877
|
};
|
|
@@ -888,6 +899,7 @@ options = {}) {
|
|
|
888
899
|
result[name] = {
|
|
889
900
|
kind: 'github', version, current, latest,
|
|
890
901
|
updateAvailable: byVersion ?? (current !== null && latest !== null && current !== latest),
|
|
902
|
+
...(latest === null && byVersion === null ? { checkFailed: true, checkError: 'unavailable' } : {}),
|
|
891
903
|
...(byVersion === false && current !== null && latest !== null && current !== latest
|
|
892
904
|
? { unreleasedCommit: latest } : {}),
|
|
893
905
|
};
|
|
@@ -902,7 +914,7 @@ options = {}) {
|
|
|
902
914
|
const source = options.releaseSources?.get(name);
|
|
903
915
|
if (source !== undefined) {
|
|
904
916
|
const release = await publishedReleaseUpdate(source, name);
|
|
905
|
-
result[name] = { kind: 'npm', version, current: version, latest: release?.version ?? null, updateAvailable: isUpgrade(version, release?.version ?? null) };
|
|
917
|
+
result[name] = { kind: 'npm', version, current: version, latest: release?.version ?? null, updateAvailable: isUpgrade(version, release?.version ?? null), ...(release === null ? { checkFailed: true, checkError: 'unavailable' } : {}) };
|
|
906
918
|
return;
|
|
907
919
|
}
|
|
908
920
|
const repo = lookupRepoFromUrl(spec);
|
|
@@ -912,8 +924,10 @@ options = {}) {
|
|
|
912
924
|
return;
|
|
913
925
|
}
|
|
914
926
|
}
|
|
915
|
-
const meta = (await fetchJson(npmUrl(`${encodeURIComponent(name)}/latest`)));
|
|
916
|
-
const stable = typeof meta
|
|
927
|
+
const meta = (await fetchJson(npmUrl(`${encodeURIComponent(name)}/latest`), true));
|
|
928
|
+
const stable = typeof meta?.version === 'string' && parseSemver(meta.version) !== null ? meta.version : null;
|
|
929
|
+
if (meta !== undefined && stable === null)
|
|
930
|
+
throw new Error('npm latest response has no valid version');
|
|
917
931
|
const channel = channelFor.get(name);
|
|
918
932
|
const latest = channel === undefined ? stable : await versionOnChannel(name, channel, stable);
|
|
919
933
|
// Forwards is an update; a difference in the other direction is a
|
|
@@ -954,6 +968,7 @@ options = {}) {
|
|
|
954
968
|
result[name] = {
|
|
955
969
|
kind: 'npm', version, current: version, latest,
|
|
956
970
|
updateAvailable: mature === null ? upgrade && !held : mature.candidate !== null,
|
|
971
|
+
...(mature?.reason === 'registry-unavailable' ? { checkFailed: true, checkError: 'unavailable' } : {}),
|
|
957
972
|
...(mature?.candidate !== null && mature?.candidate !== undefined ? { eligibleVersion: mature.candidate } : {}),
|
|
958
973
|
...(mature?.heldUpdate !== undefined ? { heldUpdate: mature.heldUpdate }
|
|
959
974
|
: hold !== null && hold !== 'past' ? { heldUpdate: { latest: latest, until: hold.until, ...(hold.estimated ? { estimated: true } : {}) } } : {}),
|
|
@@ -963,7 +978,10 @@ options = {}) {
|
|
|
963
978
|
}
|
|
964
979
|
}
|
|
965
980
|
catch {
|
|
966
|
-
result[name] = {
|
|
981
|
+
result[name] = {
|
|
982
|
+
kind: (spec.startsWith('github:') || isGitHostedSpec(spec)) ? 'github' : 'npm',
|
|
983
|
+
version, current: null, latest: null, updateAvailable: false, checkFailed: true, checkError: 'unavailable',
|
|
984
|
+
};
|
|
967
985
|
}
|
|
968
986
|
}));
|
|
969
987
|
// A plain dependency can have a newer release; it is just not an update the
|
|
@@ -975,7 +993,19 @@ options = {}) {
|
|
|
975
993
|
continue;
|
|
976
994
|
result[name] = { ...status, updateAvailable: false, notAPlugin: true };
|
|
977
995
|
}
|
|
978
|
-
|
|
979
|
-
|
|
996
|
+
// A delayed check must not replace a newer snapshot or refill a cache that
|
|
997
|
+
// was invalidated while the request was in flight.
|
|
998
|
+
if (generation === updateCheckGeneration) {
|
|
999
|
+
const now = Date.now();
|
|
1000
|
+
if (Object.values(result).some(status => status.checkFailed === true || status.checkError !== undefined)) {
|
|
1001
|
+
// Keep the last confirmed data, but let the next ordinary refresh try
|
|
1002
|
+
// again even when this was a forced refresh during the normal TTL.
|
|
1003
|
+
if (updatesCache?.key === cacheKey)
|
|
1004
|
+
updatesCache.recheckAt = now;
|
|
1005
|
+
}
|
|
1006
|
+
else {
|
|
1007
|
+
updatesCache = { key: cacheKey, recheckAt: Math.min(now + UPDATES_TTL_MS, nextHoldRecheck(result), nextCandidateMaturityAt), data: result };
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
980
1010
|
return result;
|
|
981
1011
|
}
|
package/lib/verify.js
CHANGED
|
@@ -30,7 +30,7 @@ import { readFileSync, realpathSync, statSync } from 'node:fs';
|
|
|
30
30
|
import { createRequire, isBuiltin } from 'node:module';
|
|
31
31
|
import { Script } from 'node:vm';
|
|
32
32
|
import { join } from 'node:path';
|
|
33
|
-
import {
|
|
33
|
+
import { hotMountFailure, listLiveHotMounts, patchBlockerReason, scanPatch } from './hot.js';
|
|
34
34
|
import { userPatchPackageReferences } from './patch.js';
|
|
35
35
|
import { nameMatchesPackage } from './entry-identity.js';
|
|
36
36
|
import { bundlePatchInsertedIds, declaredBundlePatchFiles, hasDshManifest, hasLoadableEntry, pluginSubdirs, profileDir, readInstalled } from './profile.js';
|
|
@@ -72,6 +72,20 @@ function profilePatchMentions(activeProfileDir, name) {
|
|
|
72
72
|
};
|
|
73
73
|
return rows.some(visit);
|
|
74
74
|
}
|
|
75
|
+
const isRow = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
76
|
+
/** The Agent presets in the profile's own patch that mount this package (#1144).
|
|
77
|
+
* A preset owns its plugin rows and mounts them per session, so nothing there
|
|
78
|
+
* ever reaches the loader — this row is the only evidence it runs, and where. */
|
|
79
|
+
function presetLoadsReason(dir, name) {
|
|
80
|
+
const rows = parsePatchFile(join(dir, 'cordis.patch.yml')) ?? [];
|
|
81
|
+
const ids = rows.flatMap(row => !isRow(row) || row.id !== 'agent-preset' || !isRow(row.config) || !Array.isArray(row.config.presets) ? []
|
|
82
|
+
: row.config.presets.flatMap(preset => !isRow(preset) || typeof preset.id !== 'string' || !Array.isArray(preset.plugins) ? []
|
|
83
|
+
: preset.plugins.some(p => isRow(p) && nameMatchesPackage(p.name, name)) ? [preset.id] : []));
|
|
84
|
+
if (ids.length === 0)
|
|
85
|
+
return null;
|
|
86
|
+
const list = [...new Set(ids)];
|
|
87
|
+
return `已装入预设组合(${list.join('、')}):运行于这些预设的会话会加载它 / loaded by these Agent presets (${list.join(', ')}): sessions running them load it`;
|
|
88
|
+
}
|
|
75
89
|
/** The profile manifest's `dsh.profile.bundles` — what the CLI reconciled. */
|
|
76
90
|
function readBundles(profile, explicitDir) {
|
|
77
91
|
try {
|
|
@@ -400,7 +414,7 @@ export function defaultHostRuntimeFacts(activeProfileDir) {
|
|
|
400
414
|
catch { /* no exemption file — nothing may bypass the gate */ }
|
|
401
415
|
return { runtimeVersion: discoverRuntimeVersion(), exemptions };
|
|
402
416
|
}
|
|
403
|
-
export function verifyActivation(profile, name, live = new Set(
|
|
417
|
+
export function verifyActivation(profile, name, live = new Set(listLiveHotMounts()), explicitDir, isDisabled = false, hostFacts, loaderObserved = false,
|
|
404
418
|
/**
|
|
405
419
|
* The host's OWN row for this package exists and has no fiber (#1023).
|
|
406
420
|
* The loader creates an entry before it imports the module, so an entry
|
|
@@ -430,6 +444,9 @@ loaderNeverStarted = false) {
|
|
|
430
444
|
hot: false,
|
|
431
445
|
};
|
|
432
446
|
}
|
|
447
|
+
const mountFailure = hotMountFailure(name, activeProfileDir);
|
|
448
|
+
if (mountFailure !== null)
|
|
449
|
+
return { state: 'failed', reasons: [mountFailure], bundle: inBundles, hot: false };
|
|
433
450
|
const dir = join(activeProfileDir, 'node_modules', name);
|
|
434
451
|
// OBSERVED beats INFERRED (#135): the loader inventory is ground truth, so
|
|
435
452
|
// a package the loader is running is live no matter what its manifest says.
|
|
@@ -476,6 +493,11 @@ loaderNeverStarted = false) {
|
|
|
476
493
|
const more = carried.length > 3 ? `等 ${carried.length} 个` : '';
|
|
477
494
|
const shownEn = carried.slice(0, 3).join(', ');
|
|
478
495
|
const moreEn = carried.length > 3 ? ` and ${carried.length - 3} more` : '';
|
|
496
|
+
// #1144: a dependency with no dsh field loads per session when an Agent
|
|
497
|
+
// preset names it — nothing else can show that.
|
|
498
|
+
const reason = carried.length === 0 ? presetLoadsReason(activeProfileDir, name) : null;
|
|
499
|
+
if (reason !== null)
|
|
500
|
+
return { state: 'inert', loadedByProfile: true, reasons: [reason], bundle: false, hot: false };
|
|
479
501
|
return {
|
|
480
502
|
state: 'inert',
|
|
481
503
|
reasons: [carried.length > 0
|