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/hot.js
CHANGED
|
@@ -23,17 +23,18 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
23
23
|
}
|
|
24
24
|
return path;
|
|
25
25
|
};
|
|
26
|
-
import { mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
26
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
27
27
|
import { createRequire } from 'node:module';
|
|
28
|
-
import { join } from 'node:path';
|
|
29
|
-
import { pathToFileURL } from 'node:url';
|
|
28
|
+
import { dirname, join } from 'node:path';
|
|
29
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
30
|
+
import { isUpdateCheckIntervalHours } from './update-notification-settings.js';
|
|
30
31
|
import { asChannel } from './channels.js';
|
|
31
32
|
import { asRegion, normalizeGithubProxy } from './regions.js';
|
|
33
|
+
import { findDshInstallDir } from './dsh-install.js';
|
|
32
34
|
import { logEvent } from './log.js';
|
|
33
35
|
import { bundlePatchTargets, declaredBundlePatchFiles, entryArtifactExists } from './profile.js';
|
|
34
|
-
import { stateDir, statePath } from './state.js';
|
|
35
36
|
/**
|
|
36
|
-
* Profile-scoped resolution for hot-mount
|
|
37
|
+
* Profile-scoped resolution for hot-mount imports: turn a bare package name into
|
|
37
38
|
* the absolute `file://` entry URL of the package just installed into
|
|
38
39
|
* `profileDir`.
|
|
39
40
|
*
|
|
@@ -47,7 +48,7 @@ import { stateDir, statePath } from './state.js';
|
|
|
47
48
|
* back to "restart required", blaming the plugin for what is a resolution
|
|
48
49
|
* anchor problem.
|
|
49
50
|
*
|
|
50
|
-
* Resolving the
|
|
51
|
+
* Resolving the module at import time, against the profile it was actually
|
|
51
52
|
* installed into, is anchor-independent: `require.resolve` walks
|
|
52
53
|
* `profileDir/node_modules` natively, so the tree hands the loader a
|
|
53
54
|
* `file://` URL needing no further resolution. Non-bare specifiers (relative
|
|
@@ -59,8 +60,8 @@ import { stateDir, statePath } from './state.js';
|
|
|
59
60
|
* whose entry cannot be located via `require.resolve` (no `main`/exports —
|
|
60
61
|
* the market's own `entryArtifactExists` heuristic covers those shapes before
|
|
61
62
|
* an install is accepted) is not something this resolver should guess about.
|
|
62
|
-
* Client-only shims never reach this function
|
|
63
|
-
*
|
|
63
|
+
* Client-only shims never reach this function: their import returns a no-op
|
|
64
|
+
* host module before attempting package resolution.
|
|
64
65
|
*/
|
|
65
66
|
export function resolveProfileEntry(profileDir, name) {
|
|
66
67
|
if (!name || name.startsWith('.') || name.startsWith('cordis:') || name.startsWith('file://'))
|
|
@@ -81,10 +82,11 @@ export function resolveProfileEntry(profileDir, name) {
|
|
|
81
82
|
return name;
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
|
-
//
|
|
85
|
+
// Row names and ids may contain apostrophes; YAML single-quoted scalars double them.
|
|
85
86
|
function yamlSingleQuoted(value) {
|
|
86
87
|
return value.replace(/'/g, "''");
|
|
87
88
|
}
|
|
89
|
+
const HOT_DIR = '.dsh-crate';
|
|
88
90
|
/**
|
|
89
91
|
* Ceiling for one hot-mount activation, env-overridable like the install
|
|
90
92
|
* timeout in dsh-cli.ts. An activation that exceeds it is treated as wedged
|
|
@@ -93,6 +95,12 @@ function yamlSingleQuoted(value) {
|
|
|
93
95
|
*/
|
|
94
96
|
const HOT_MOUNT_TIMEOUT_MS = Number(process.env.DSH_MARKET_HOT_MOUNT_TIMEOUT_MS) || 10000;
|
|
95
97
|
let hotTreeClass;
|
|
98
|
+
// Cordis declares FiberState as a const enum, so the installed host exposes its numeric values.
|
|
99
|
+
const FAILED_FIBER_STATE = 3;
|
|
100
|
+
/** Live hot-mount trees by input file URL, so an unmount can reach the entries. */
|
|
101
|
+
const hotTrees = new Map();
|
|
102
|
+
/** Package name -> the input file URL of its live hot mount. */
|
|
103
|
+
const hotTreeOf = new Map();
|
|
96
104
|
/**
|
|
97
105
|
* The Include subclass, built once per process; null when the loader's include
|
|
98
106
|
* plugin is not importable (older harness) — callers fall back to restart.
|
|
@@ -117,12 +125,19 @@ async function loadHotTreeClass() {
|
|
|
117
125
|
if (Include === undefined)
|
|
118
126
|
throw new Error('no Include export');
|
|
119
127
|
class MarketHotTree extends Include {
|
|
128
|
+
profileDir;
|
|
129
|
+
constructor(...args) {
|
|
130
|
+
super(...args);
|
|
131
|
+
const path = args[1].path;
|
|
132
|
+
this.profileDir = dirname(dirname(fileURLToPath(path)));
|
|
133
|
+
hotTrees.set(path, this);
|
|
134
|
+
}
|
|
120
135
|
/** Runtime-only mount list; the bundle layer owns persistence. */
|
|
121
136
|
write() { }
|
|
122
137
|
import(name, getOuterStack) {
|
|
123
138
|
if (shimNames.has(name))
|
|
124
139
|
return { name, apply: () => { } };
|
|
125
|
-
return super.import(name, getOuterStack);
|
|
140
|
+
return super.import(resolveProfileEntry(this.profileDir, name), getOuterStack);
|
|
126
141
|
}
|
|
127
142
|
}
|
|
128
143
|
hotTreeClass = MarketHotTree;
|
|
@@ -232,7 +247,7 @@ export function patchBlockerReason(blocker, key) {
|
|
|
232
247
|
* `state.json` (disable choices + groups) deliberately survives.
|
|
233
248
|
*/
|
|
234
249
|
export function cleanHotDir(profileDir) {
|
|
235
|
-
const dir =
|
|
250
|
+
const dir = join(profileDir, HOT_DIR);
|
|
236
251
|
let entries;
|
|
237
252
|
try {
|
|
238
253
|
entries = readdirSync(dir);
|
|
@@ -246,7 +261,7 @@ export function cleanHotDir(profileDir) {
|
|
|
246
261
|
}
|
|
247
262
|
}
|
|
248
263
|
function stateFile(profileDir) {
|
|
249
|
-
return
|
|
264
|
+
return join(profileDir, HOT_DIR, 'state.json');
|
|
250
265
|
}
|
|
251
266
|
const BROKEN_REASONS = new Set(['incomplete-build-locked', 'incomplete-build-cancelled']);
|
|
252
267
|
/** The on-disk shape of {@link MarketState.brokenPlugins}, sanitized. */
|
|
@@ -309,6 +324,69 @@ function blockedNames(value) {
|
|
|
309
324
|
function updateExemptNames(value) {
|
|
310
325
|
return cappedPackageNames(value, MAX_UPDATE_EXEMPT);
|
|
311
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* Upper bound on the install-time map (#1142). One entry per package the
|
|
329
|
+
* market itself installed, and a profile with 500 of those is already an
|
|
330
|
+
* outlier; the cap keeps state.json from growing with every plugin the user
|
|
331
|
+
* ever tried and removed.
|
|
332
|
+
*/
|
|
333
|
+
export const MAX_INSTALL_TIMES = 500;
|
|
334
|
+
/** An ISO 8601 timestamp, normalized; anything else is "not recorded". */
|
|
335
|
+
function installTimestamp(value) {
|
|
336
|
+
if (typeof value !== 'string' || value === '')
|
|
337
|
+
return undefined;
|
|
338
|
+
const at = Date.parse(value);
|
|
339
|
+
if (!Number.isFinite(at))
|
|
340
|
+
return undefined;
|
|
341
|
+
return new Date(at).toISOString();
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Sanitize the stored install-time map. A hand-edited file is not trusted:
|
|
345
|
+
* a key that is not a name, a value that is not an object, and a stamp that
|
|
346
|
+
* is not a timestamp are all dropped rather than carried into the UI, where
|
|
347
|
+
* an unparseable date would sort as `NaN` and land in the middle of the list.
|
|
348
|
+
*
|
|
349
|
+
* The cap keeps the entries with the most recent activity, not the first
|
|
350
|
+
* ones written: the map is a lookup for "when did I install this", and the
|
|
351
|
+
* oldest 50 installs are exactly the ones nobody is asking about.
|
|
352
|
+
*/
|
|
353
|
+
function installTimesFromUnknown(value) {
|
|
354
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
355
|
+
return undefined;
|
|
356
|
+
const out = {};
|
|
357
|
+
for (const [name, raw] of Object.entries(value)) {
|
|
358
|
+
if (name === '' || name.length > MAX_BLOCKED_NAME)
|
|
359
|
+
continue;
|
|
360
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
|
|
361
|
+
continue;
|
|
362
|
+
const record = raw;
|
|
363
|
+
const installedAt = installTimestamp(record.installedAt);
|
|
364
|
+
const updatedAt = installTimestamp(record.updatedAt);
|
|
365
|
+
// An entry with neither stamp says nothing; keeping it would list a row
|
|
366
|
+
// that looks known and sorts nowhere.
|
|
367
|
+
if (installedAt === undefined && updatedAt === undefined)
|
|
368
|
+
continue;
|
|
369
|
+
out[name] = {
|
|
370
|
+
...(installedAt === undefined ? {} : { installedAt }),
|
|
371
|
+
...(updatedAt === undefined ? {} : { updatedAt }),
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const names = Object.keys(out);
|
|
375
|
+
if (names.length === 0)
|
|
376
|
+
return undefined;
|
|
377
|
+
return trimInstallTimes(out);
|
|
378
|
+
}
|
|
379
|
+
/** Keep the cap, dropping the entries nobody is asking about (oldest first). */
|
|
380
|
+
function trimInstallTimes(map) {
|
|
381
|
+
const names = Object.keys(map);
|
|
382
|
+
if (names.length === 0)
|
|
383
|
+
return undefined;
|
|
384
|
+
if (names.length <= MAX_INSTALL_TIMES)
|
|
385
|
+
return map;
|
|
386
|
+
const stamp = (entry) => Date.parse(entry.updatedAt ?? entry.installedAt ?? '');
|
|
387
|
+
const recent = names.sort((a, b) => stamp(map[b]) - stamp(map[a])).slice(0, MAX_INSTALL_TIMES);
|
|
388
|
+
return Object.fromEntries(recent.map(name => [name, map[name]]));
|
|
389
|
+
}
|
|
312
390
|
/** A POSIX-looking environment variable name: the name part of `KEY=value`. */
|
|
313
391
|
const ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
314
392
|
/** Upper bound on one pinned env value, so state.json cannot balloon. */
|
|
@@ -378,6 +456,7 @@ export function readMarketState(profileDir) {
|
|
|
378
456
|
}
|
|
379
457
|
const githubProxy = normalizeGithubProxy(state.githubProxy);
|
|
380
458
|
const brokenPlugins = brokenPluginsFromUnknown(state.brokenPlugins);
|
|
459
|
+
const installTimes = installTimesFromUnknown(state.installTimes);
|
|
381
460
|
// The order and the map are two halves of one fact, and a state file can
|
|
382
461
|
// carry them out of step (#964): the UI then lists a group the routes
|
|
383
462
|
// cannot find, so "assign to" and even "delete" answer group-not-found
|
|
@@ -402,8 +481,11 @@ export function readMarketState(profileDir) {
|
|
|
402
481
|
favorites: favoriteUrls(state.favorites),
|
|
403
482
|
blocked: blockedNames(state.blocked),
|
|
404
483
|
updateExempt: updateExemptNames(state.updateExempt),
|
|
484
|
+
...(typeof state.backgroundUpdateChecks === 'boolean' ? { backgroundUpdateChecks: state.backgroundUpdateChecks } : {}),
|
|
485
|
+
...(isUpdateCheckIntervalHours(state.backgroundUpdateIntervalHours) ? { backgroundUpdateIntervalHours: state.backgroundUpdateIntervalHours } : {}),
|
|
405
486
|
...(githubProxy === null ? {} : { githubProxy }),
|
|
406
487
|
...(brokenPlugins === undefined ? {} : { brokenPlugins }),
|
|
488
|
+
...(installTimes === undefined ? {} : { installTimes }),
|
|
407
489
|
// true AND false are both preserved: on a host with no settings page
|
|
408
490
|
// this switch is the market's only entry, so "the user turned it off"
|
|
409
491
|
// must be distinguishable from "nobody has chosen yet" (#846).
|
|
@@ -488,7 +570,17 @@ function publishFile(path, contents) {
|
|
|
488
570
|
* the whole document" safe for callers that only hold part of it.
|
|
489
571
|
*/
|
|
490
572
|
export function writeMarketState(profileDir, state) {
|
|
491
|
-
|
|
573
|
+
writeState(profileDir, state, false);
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* `ownStamps` is true only for the three stamp functions below. Every other
|
|
577
|
+
* writer holds a whole-state object that may be minutes old (the routes keep
|
|
578
|
+
* one from boot and save it whole, #435), so a stamp it carries is a stale
|
|
579
|
+
* copy: letting it through put the install date of the last install back to
|
|
580
|
+
* what boot saw.
|
|
581
|
+
*/
|
|
582
|
+
function writeState(profileDir, state, ownStamps) {
|
|
583
|
+
mkdirSync(join(profileDir, HOT_DIR), { recursive: true, mode: 0o700 });
|
|
492
584
|
const onDisk = readMarketState(profileDir);
|
|
493
585
|
// `?? {}` only for the type: MarketState declares notes optional, while
|
|
494
586
|
// readMarketState always returns an object.
|
|
@@ -504,6 +596,8 @@ export function writeMarketState(profileDir, state) {
|
|
|
504
596
|
const favorites = state.favorites ?? onDisk.favorites ?? [];
|
|
505
597
|
const blocked = state.blocked ?? onDisk.blocked ?? [];
|
|
506
598
|
const updateExempt = state.updateExempt ?? onDisk.updateExempt ?? [];
|
|
599
|
+
const backgroundUpdateChecks = state.backgroundUpdateChecks ?? onDisk.backgroundUpdateChecks;
|
|
600
|
+
const backgroundUpdateIntervalHours = state.backgroundUpdateIntervalHours ?? onDisk.backgroundUpdateIntervalHours;
|
|
507
601
|
// This field does have a clear action ("restore automatic"). As with
|
|
508
602
|
// regionAuto, omission preserves while an explicit undefined removes it.
|
|
509
603
|
const githubProxy = Object.prototype.hasOwnProperty.call(state, 'githubProxy')
|
|
@@ -512,6 +606,9 @@ export function writeMarketState(profileDir, state) {
|
|
|
512
606
|
const broken = Object.prototype.hasOwnProperty.call(state, 'brokenPlugins')
|
|
513
607
|
? state.brokenPlugins
|
|
514
608
|
: onDisk.brokenPlugins;
|
|
609
|
+
// Only the stamp functions replace the map (an empty one, after the last
|
|
610
|
+
// uninstall, included); every other writer leaves what is on disk alone.
|
|
611
|
+
const installTimes = ownStamps ? state.installTimes : onDisk.installTimes;
|
|
515
612
|
const sidebarEntry = Object.prototype.hasOwnProperty.call(state, 'sidebarEntry')
|
|
516
613
|
? state.sidebarEntry
|
|
517
614
|
: onDisk.sidebarEntry;
|
|
@@ -530,6 +627,8 @@ export function writeMarketState(profileDir, state) {
|
|
|
530
627
|
...(favorites.length > 0 ? { favorites } : {}),
|
|
531
628
|
...(blocked.length > 0 ? { blocked } : {}),
|
|
532
629
|
...(updateExempt.length > 0 ? { updateExempt } : {}),
|
|
630
|
+
...(typeof backgroundUpdateChecks === 'boolean' ? { backgroundUpdateChecks } : {}),
|
|
631
|
+
...(isUpdateCheckIntervalHours(backgroundUpdateIntervalHours) ? { backgroundUpdateIntervalHours } : {}),
|
|
533
632
|
...(Object.keys(notes).length > 0 ? { notes } : {}),
|
|
534
633
|
// Omitted while unchosen, so "never picked" survives a round trip and
|
|
535
634
|
// keeps deriving from the running build — but only when disk has not
|
|
@@ -544,6 +643,9 @@ export function writeMarketState(profileDir, state) {
|
|
|
544
643
|
// githubProxy above, and the one a repaired plugin needs: the entry
|
|
545
644
|
// exists only while the declaration is still missing.
|
|
546
645
|
...(broken === undefined ? {} : { brokenPlugins: broken }),
|
|
646
|
+
// Omitted while empty, so a profile that never installed through the
|
|
647
|
+
// market keeps a state file with no such key at all.
|
|
648
|
+
...(installTimes === undefined || Object.keys(installTimes).length === 0 ? {} : { installTimes }),
|
|
547
649
|
// Written for both answers: on a host with no settings page this switch
|
|
548
650
|
// is the market's only entry, so a deliberate OFF has to survive a reload
|
|
549
651
|
// instead of being read back as "never chosen" (#846).
|
|
@@ -577,10 +679,89 @@ export function readDisabledThemes(profileDir) {
|
|
|
577
679
|
export function writeDisabledThemes(profileDir, disabled) {
|
|
578
680
|
writeDisabled(profileDir, disabled);
|
|
579
681
|
}
|
|
580
|
-
/**
|
|
682
|
+
/**
|
|
683
|
+
* The market installed these packages just now (#1142): both stamps are this
|
|
684
|
+
* moment, because the first install is also the last change so far.
|
|
685
|
+
*/
|
|
686
|
+
export function recordInstalled(profileDir, names, at = new Date()) {
|
|
687
|
+
const stamp = at.toISOString();
|
|
688
|
+
const state = readMarketState(profileDir);
|
|
689
|
+
const map = { ...state.installTimes };
|
|
690
|
+
for (const name of names) {
|
|
691
|
+
if (name === '')
|
|
692
|
+
continue;
|
|
693
|
+
map[name] = { installedAt: stamp, updatedAt: stamp };
|
|
694
|
+
}
|
|
695
|
+
state.installTimes = trimInstallTimes(map);
|
|
696
|
+
writeState(profileDir, state, true);
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* An update of these packages landed: only the update stamp moves.
|
|
700
|
+
*
|
|
701
|
+
* A package with no entry keeps `installedAt` absent — the market never saw
|
|
702
|
+
* it installed, and "when I first noticed it" is a different fact. Writing it
|
|
703
|
+
* here would make the sort report a guessed install order as history.
|
|
704
|
+
*/
|
|
705
|
+
export function recordUpdated(profileDir, names, at = new Date()) {
|
|
706
|
+
const stamp = at.toISOString();
|
|
707
|
+
const state = readMarketState(profileDir);
|
|
708
|
+
const map = { ...state.installTimes };
|
|
709
|
+
for (const name of names) {
|
|
710
|
+
if (name === '')
|
|
711
|
+
continue;
|
|
712
|
+
map[name] = { ...map[name], updatedAt: stamp };
|
|
713
|
+
}
|
|
714
|
+
state.installTimes = trimInstallTimes(map);
|
|
715
|
+
writeState(profileDir, state, true);
|
|
716
|
+
}
|
|
717
|
+
/** The package is gone: its stamps must not outlive it. */
|
|
718
|
+
export function forgetInstalled(profileDir, name) {
|
|
719
|
+
const state = readMarketState(profileDir);
|
|
720
|
+
if (state.installTimes === undefined || state.installTimes[name] === undefined)
|
|
721
|
+
return;
|
|
722
|
+
const map = { ...state.installTimes };
|
|
723
|
+
delete map[name];
|
|
724
|
+
state.installTimes = trimInstallTimes(map);
|
|
725
|
+
writeState(profileDir, state, true);
|
|
726
|
+
}
|
|
727
|
+
/** Package names whose hot-mount trees are still attached and can be removed. */
|
|
581
728
|
export function listHotMounts() {
|
|
582
729
|
return [...hotHandles.keys()];
|
|
583
730
|
}
|
|
731
|
+
function mountedFile(packageName, profileDir) {
|
|
732
|
+
const file = hotTreeOf.get(packageName);
|
|
733
|
+
if (file === undefined || profileDir === undefined)
|
|
734
|
+
return file;
|
|
735
|
+
return dirname(fileURLToPath(file)) === join(profileDir, HOT_DIR) ? file : undefined;
|
|
736
|
+
}
|
|
737
|
+
/** Report a failed child only when it belongs to this package's hot-mount tree. */
|
|
738
|
+
export function hotMountFailure(packageName, profileDir) {
|
|
739
|
+
const file = mountedFile(packageName, profileDir);
|
|
740
|
+
if (file === undefined)
|
|
741
|
+
return null;
|
|
742
|
+
const tree = hotTrees.get(file);
|
|
743
|
+
if (typeof tree?.entries !== 'function')
|
|
744
|
+
return null;
|
|
745
|
+
const failed = [];
|
|
746
|
+
try {
|
|
747
|
+
for (const entry of tree.entries()) {
|
|
748
|
+
if (entry.fiber?.state === FAILED_FIBER_STATE && typeof entry.id === 'string')
|
|
749
|
+
failed.push(entry.id);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
catch {
|
|
753
|
+
// Older loaders can have an unreadable activation state.
|
|
754
|
+
return null;
|
|
755
|
+
}
|
|
756
|
+
if (failed.length === 0)
|
|
757
|
+
return null;
|
|
758
|
+
const components = failed.join(', ');
|
|
759
|
+
return `组件 ${components} 启动失败。请在诊断中查看原因。 / Components failed to start (${components}). Check Diagnostics for the error.`;
|
|
760
|
+
}
|
|
761
|
+
/** Hot mounts the market can report as live. */
|
|
762
|
+
export function listLiveHotMounts() {
|
|
763
|
+
return listHotMounts().filter(name => hotMountFailure(name) === null);
|
|
764
|
+
}
|
|
584
765
|
let hotSequence = 0;
|
|
585
766
|
const hotHandles = new Map();
|
|
586
767
|
/** Activation did not settle within HOT_MOUNT_TIMEOUT_MS. */
|
|
@@ -602,6 +783,107 @@ function raceActivationTimeout(awaitable) {
|
|
|
602
783
|
Promise.resolve(awaitable).then(value => { clearTimeout(timer); resolve(value); }, error => { clearTimeout(timer); reject(error); });
|
|
603
784
|
});
|
|
604
785
|
}
|
|
786
|
+
/** Cap on host log lines attached to one hot mount (#1197). */
|
|
787
|
+
const MOUNT_LOG_MAX = 5;
|
|
788
|
+
const MOUNT_LOG_LINE_MAX = 200;
|
|
789
|
+
/** Render one structured host record as a single log line. */
|
|
790
|
+
function mountLogLine(message) {
|
|
791
|
+
const parts = Array.isArray(message.args) ? message.args : [message.args];
|
|
792
|
+
const text = parts
|
|
793
|
+
.filter(part => part !== undefined && part !== null)
|
|
794
|
+
.map(part => {
|
|
795
|
+
if (typeof part === 'string')
|
|
796
|
+
return part;
|
|
797
|
+
// Align with `Logger.format`: an Error records its stack (or message as
|
|
798
|
+
// a fallback), never the empty object `JSON.stringify` yields. cordis'
|
|
799
|
+
// `_method` hands the raw `args: [Error]` to exporters without
|
|
800
|
+
// formatting, so this is what keeps `the host logged this while
|
|
801
|
+
// mounting — name: Error: ...` readable in the exportable log.
|
|
802
|
+
if (part instanceof Error)
|
|
803
|
+
return part.stack || part.message;
|
|
804
|
+
try {
|
|
805
|
+
return JSON.stringify(part) ?? String(part);
|
|
806
|
+
}
|
|
807
|
+
catch {
|
|
808
|
+
return String(part);
|
|
809
|
+
}
|
|
810
|
+
})
|
|
811
|
+
.join(' ');
|
|
812
|
+
const name = typeof message.name === 'string' && message.name !== '' ? `${message.name}: ` : '';
|
|
813
|
+
return `${name}${text}`.slice(0, MOUNT_LOG_LINE_MAX);
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Collect the host's warn/error records for the duration of one hot mount.
|
|
817
|
+
*
|
|
818
|
+
* `Fiber#await()` resolves normally when an entry is still waiting on a
|
|
819
|
+
* service that never arrives (#1197): the mount reports live, and the only
|
|
820
|
+
* trace of the problem is whatever the host logged while composing it.
|
|
821
|
+
* Recording those lines next to the `live` event keeps that trace in the
|
|
822
|
+
* exportable log without changing the verdict — the mount really did finish,
|
|
823
|
+
* and "this entry was the one that complained" is not something the market can
|
|
824
|
+
* prove yet.
|
|
825
|
+
*
|
|
826
|
+
* Attribution stays open on purpose: the exporter is process-wide, so these
|
|
827
|
+
* lines read as "logged while mounting", not as this entry's own records.
|
|
828
|
+
* Filtering on a name prefix would bake in a naming contract the host has not
|
|
829
|
+
* promised.
|
|
830
|
+
*
|
|
831
|
+
* @param ctx - host context; the sink is skipped when there is no `exporter`.
|
|
832
|
+
* @returns the collected lines plus a disposer that is safe to call twice.
|
|
833
|
+
*/
|
|
834
|
+
function watchMountLog(ctx) {
|
|
835
|
+
const logger = ctx.logger;
|
|
836
|
+
const register = logger?.exporter;
|
|
837
|
+
if (logger === undefined || typeof register !== 'function')
|
|
838
|
+
return { finish: () => [], stop: () => { } };
|
|
839
|
+
const lines = [];
|
|
840
|
+
let disposable;
|
|
841
|
+
try {
|
|
842
|
+
disposable = register.call(logger, {
|
|
843
|
+
// Ask for every level and filter below: the sink exists to catch
|
|
844
|
+
// warnings, and the service's own default threshold (`1`) drops them
|
|
845
|
+
// before `export` is ever called.
|
|
846
|
+
levels: { default: 3 },
|
|
847
|
+
export(message) {
|
|
848
|
+
if (lines.length >= MOUNT_LOG_MAX)
|
|
849
|
+
return;
|
|
850
|
+
if (message?.type !== 'warn' && message?.type !== 'error')
|
|
851
|
+
return;
|
|
852
|
+
lines.push(mountLogLine(message));
|
|
853
|
+
},
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
catch {
|
|
857
|
+
// A host whose exporter rejects this sink shape is not a mount failure.
|
|
858
|
+
return { finish: () => [], stop: () => { } };
|
|
859
|
+
}
|
|
860
|
+
let stopped = false;
|
|
861
|
+
const stop = () => {
|
|
862
|
+
if (stopped)
|
|
863
|
+
return;
|
|
864
|
+
stopped = true;
|
|
865
|
+
try {
|
|
866
|
+
if (typeof disposable === 'function')
|
|
867
|
+
void disposable();
|
|
868
|
+
else if (disposable !== null && typeof disposable === 'object' && 'dispose' in disposable) {
|
|
869
|
+
void disposable.dispose();
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
catch {
|
|
873
|
+
// The mount result matters more than the sink teardown.
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
return {
|
|
877
|
+
finish: () => {
|
|
878
|
+
stop();
|
|
879
|
+
return lines.slice();
|
|
880
|
+
},
|
|
881
|
+
stop,
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
function mountResult(failure) {
|
|
885
|
+
return failure === null ? { ok: true, reason: null } : { ok: false, reason: failure, retained: true };
|
|
886
|
+
}
|
|
605
887
|
/**
|
|
606
888
|
* Dispose a plugin hot-mounted earlier in this session, removing it from the
|
|
607
889
|
* running composition immediately.
|
|
@@ -617,7 +899,29 @@ export async function hotUnmount(packageName) {
|
|
|
617
899
|
// state instead of reusing a handle already being disposed.
|
|
618
900
|
hotHandles.delete(packageName);
|
|
619
901
|
shimNames.delete(packageName);
|
|
620
|
-
const
|
|
902
|
+
const treeKey = hotTreeOf.get(packageName);
|
|
903
|
+
hotTreeOf.delete(packageName);
|
|
904
|
+
const tree = treeKey === undefined ? undefined : hotTrees.get(treeKey);
|
|
905
|
+
if (treeKey !== undefined)
|
|
906
|
+
hotTrees.delete(treeKey);
|
|
907
|
+
const disposal = Promise.resolve().then(async () => {
|
|
908
|
+
// Switch the tree's entries off BEFORE disposing the tree (#1188).
|
|
909
|
+
// Disposing the tree stops the plugins but leaves each entry still holding
|
|
910
|
+
// its fiber, and the host's client-module registry keeps serving a package
|
|
911
|
+
// to the page for as long as an entry names a live fiber: the browser half
|
|
912
|
+
// of a plugin switched off here stayed on screen, across reloads, until
|
|
913
|
+
// the host restarted. Updating the entry itself is the path the host's own
|
|
914
|
+
// entries take when they are switched off, and the registry follows it.
|
|
915
|
+
if (tree !== undefined) {
|
|
916
|
+
for (const entry of [...tree.entries()]) {
|
|
917
|
+
try {
|
|
918
|
+
await entry.update({ disabled: true }, false, true);
|
|
919
|
+
}
|
|
920
|
+
catch { /* the dispose below still stops it */ }
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
await handle.dispose();
|
|
924
|
+
});
|
|
621
925
|
// Same ceiling as mounting, and the same reason (#582, measured class of
|
|
622
926
|
// report): a plugin whose teardown waits for something that never arrives
|
|
623
927
|
// used to hold the toggle route open forever, and every later operation
|
|
@@ -668,6 +972,9 @@ export async function hotUnmount(packageName) {
|
|
|
668
972
|
*/
|
|
669
973
|
export async function hotMount(ctx, profileDir, packageName) {
|
|
670
974
|
try {
|
|
975
|
+
if (mountedFile(packageName, profileDir) !== undefined) {
|
|
976
|
+
return mountResult(hotMountFailure(packageName, profileDir));
|
|
977
|
+
}
|
|
671
978
|
const HotTree = await loadHotTreeClass();
|
|
672
979
|
if (HotTree === null) {
|
|
673
980
|
return {
|
|
@@ -739,25 +1046,36 @@ export async function hotMount(ctx, profileDir, packageName) {
|
|
|
739
1046
|
shimNames.add(packageName);
|
|
740
1047
|
rows = [{ id: `client-${packageName.replace(/[^A-Za-z0-9_.-]/g, '-')}`, name: packageName }];
|
|
741
1048
|
}
|
|
742
|
-
const dir =
|
|
1049
|
+
const dir = join(profileDir, HOT_DIR);
|
|
743
1050
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
744
1051
|
hotSequence += 1;
|
|
745
1052
|
const file = join(dir, `hot-${String(hotSequence)}.yml`);
|
|
746
|
-
//
|
|
747
|
-
//
|
|
748
|
-
//
|
|
749
|
-
//
|
|
750
|
-
// `cleanHotDir` wipes it on every boot and the bundle layer owns
|
|
751
|
-
// persistence, so nothing reads these files back.
|
|
1053
|
+
// Keep the package identity on loader entries: the host's client-module
|
|
1054
|
+
// registry uses it to find package.json and the browser bundle. Only the
|
|
1055
|
+
// import resolves against this profile, so closure-hosted loaders still
|
|
1056
|
+
// receive an absolute module URL without making it the plugin's name.
|
|
752
1057
|
const yml = rows
|
|
753
|
-
.map(row => `- id: '${yamlSingleQuoted(`mkt-${row.id}`)}'\n name: '${yamlSingleQuoted(
|
|
1058
|
+
.map(row => `- id: '${yamlSingleQuoted(`mkt-${row.id}`)}'\n name: '${yamlSingleQuoted(row.name)}'\n`)
|
|
754
1059
|
.join('');
|
|
755
1060
|
writeFileSync(file, yml);
|
|
756
|
-
const
|
|
1061
|
+
const mountLog = watchMountLog(ctx);
|
|
1062
|
+
let handle;
|
|
1063
|
+
try {
|
|
1064
|
+
handle = ctx.plugin(HotTree, { path: pathToFileURL(file).href });
|
|
1065
|
+
}
|
|
1066
|
+
catch (error) {
|
|
1067
|
+
// `ctx.plugin()` bails out before creating anything when the fiber is no
|
|
1068
|
+
// longer active (a mount issued during teardown) or the plugin is
|
|
1069
|
+
// rejected. The sink is already registered by then, so release it here:
|
|
1070
|
+
// the outer catch reports the failure, it does not clean this up.
|
|
1071
|
+
mountLog.stop();
|
|
1072
|
+
throw error;
|
|
1073
|
+
}
|
|
757
1074
|
try {
|
|
758
1075
|
await raceActivationTimeout(handle.await());
|
|
759
1076
|
}
|
|
760
1077
|
catch (error) {
|
|
1078
|
+
mountLog.stop();
|
|
761
1079
|
// A failed or wedged mount must leave NOTHING behind: the disposed
|
|
762
1080
|
// subtree stops retrying the import, and the input file is removed so
|
|
763
1081
|
// it cannot be re-imported by a later boot or replay (a leftover file
|
|
@@ -771,6 +1089,7 @@ export async function hotMount(ctx, profileDir, packageName) {
|
|
|
771
1089
|
rmSync(file, { force: true });
|
|
772
1090
|
}
|
|
773
1091
|
catch { /* best effort */ }
|
|
1092
|
+
hotTrees.delete(pathToFileURL(file).href);
|
|
774
1093
|
if (error instanceof ActivationTimeout) {
|
|
775
1094
|
// A wedged activation would otherwise hold this request open forever:
|
|
776
1095
|
// the route's `finally { installing = false }` never runs, so every
|
|
@@ -781,9 +1100,25 @@ export async function hotMount(ctx, profileDir, packageName) {
|
|
|
781
1100
|
throw error;
|
|
782
1101
|
}
|
|
783
1102
|
hotHandles.set(packageName, handle);
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
1103
|
+
hotTreeOf.set(packageName, pathToFileURL(file).href);
|
|
1104
|
+
const failure = hotMountFailure(packageName, profileDir);
|
|
1105
|
+
const lines = mountLog.finish();
|
|
1106
|
+
if (failure === null) {
|
|
1107
|
+
ctx.logger?.info?.(`[dsh-crate] hot-mounted ${packageName}`);
|
|
1108
|
+
logEvent('info', 'hot-mount', `${packageName}: live${shimNames.has(packageName) ? ' (client-only shim)' : ''}`);
|
|
1109
|
+
}
|
|
1110
|
+
else {
|
|
1111
|
+
ctx.logger?.warn(`[dsh-crate] ${packageName}: ${failure}`);
|
|
1112
|
+
logEvent('warn', 'hot-mount', `${packageName}: ${failure}`);
|
|
1113
|
+
}
|
|
1114
|
+
// A mount that resolves while an entry is still waiting on a service is
|
|
1115
|
+
// "live" by the host's own verdict, so the verdict stands — but the lines
|
|
1116
|
+
// the host logged meanwhile are the only record of why the entry never
|
|
1117
|
+
// started serving (#1197).
|
|
1118
|
+
for (const line of lines) {
|
|
1119
|
+
logEvent('warn', 'hot-mount', `${packageName}: the host logged this while mounting — ${line}`);
|
|
1120
|
+
}
|
|
1121
|
+
return mountResult(failure);
|
|
787
1122
|
}
|
|
788
1123
|
catch (error) {
|
|
789
1124
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -799,7 +1134,9 @@ export async function hotMount(ctx, profileDir, packageName) {
|
|
|
799
1134
|
* in every boot — this is what makes them behave like normal plugins.
|
|
800
1135
|
* @returns names that were mounted.
|
|
801
1136
|
*/
|
|
802
|
-
export async function mountClientOnlyDeps(ctx, profileDir
|
|
1137
|
+
export async function mountClientOnlyDeps(ctx, profileDir,
|
|
1138
|
+
/** The host's install directory; `undefined` finds it, `null` means "do not look". */
|
|
1139
|
+
hostDirectory) {
|
|
803
1140
|
let deps;
|
|
804
1141
|
let bundles;
|
|
805
1142
|
try {
|
|
@@ -813,7 +1150,7 @@ export async function mountClientOnlyDeps(ctx, profileDir) {
|
|
|
813
1150
|
}
|
|
814
1151
|
const disabled = readDisabled(profileDir);
|
|
815
1152
|
const userManaged = readUserPatchControls(profileDir);
|
|
816
|
-
const hostProvided = bundleLayerTargets(profileDir, bundles);
|
|
1153
|
+
const hostProvided = bundleLayerTargets(profileDir, bundles, hostDirectory);
|
|
817
1154
|
const mounted = [];
|
|
818
1155
|
for (const name of deps) {
|
|
819
1156
|
if (hotHandles.has(name) || disabled.has(name))
|
|
@@ -856,15 +1193,45 @@ export async function mountClientOnlyDeps(ctx, profileDir) {
|
|
|
856
1193
|
* today's behaviour (shim, possibly duplicated) rather than silently dropping
|
|
857
1194
|
* a client bundle that the bundle layer never mounts.
|
|
858
1195
|
*/
|
|
859
|
-
export function bundleLayerTargets(profileDir, bundles) {
|
|
1196
|
+
export function bundleLayerTargets(profileDir, bundles, hostDirectory) {
|
|
860
1197
|
const targets = new Set();
|
|
1198
|
+
// Looked up lazily: a profile with no bundle the host provides never pays.
|
|
1199
|
+
let host = hostDirectory;
|
|
861
1200
|
for (const bundle of bundles) {
|
|
862
|
-
|
|
863
|
-
|
|
1201
|
+
if (host === undefined)
|
|
1202
|
+
host = findDshInstallDir();
|
|
1203
|
+
for (const name of bundlePatchTargets(bundleDirectory(profileDir, host, bundle)))
|
|
864
1204
|
targets.add(name);
|
|
865
1205
|
}
|
|
866
1206
|
return targets;
|
|
867
1207
|
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Where the boot reads one bundle from (#1137).
|
|
1210
|
+
*
|
|
1211
|
+
* The official bundles — `@deepseek-ai/dsh-web-app` and its siblings — ship
|
|
1212
|
+
* inside the dsh installation, not in the profile: a plain `dsh web` profile's
|
|
1213
|
+
* `node_modules/@deepseek-ai/` holds only the few packages linked into it. The
|
|
1214
|
+
* boot (dsh-app-boot's resolveBundleDir) probes Node's search paths from the
|
|
1215
|
+
* installation first and the profile second, and so does this; looking only
|
|
1216
|
+
* in the profile made every in-box bundle read as empty, which is the one kind
|
|
1217
|
+
* of bundle whose rows mount other in-box packages.
|
|
1218
|
+
*
|
|
1219
|
+
* A host that cannot be read from here (null, or an archive plain Node cannot
|
|
1220
|
+
* open) leaves the profile path, which is what this always did.
|
|
1221
|
+
*/
|
|
1222
|
+
function bundleDirectory(profileDir, host, bundle) {
|
|
1223
|
+
if (host !== null) {
|
|
1224
|
+
try {
|
|
1225
|
+
for (const searchPath of createRequire(join(host, 'package.json')).resolve.paths(bundle) ?? []) {
|
|
1226
|
+
const candidate = join(searchPath, bundle);
|
|
1227
|
+
if (existsSync(join(candidate, 'package.json')))
|
|
1228
|
+
return candidate;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
catch { /* an unreadable anchor says nothing: fall back to the profile */ }
|
|
1232
|
+
}
|
|
1233
|
+
return join(profileDir, 'node_modules', ...bundle.split('/'));
|
|
1234
|
+
}
|
|
868
1235
|
/**
|
|
869
1236
|
* Row ids and package names the user's own patch layer (cordis.patch.yml)
|
|
870
1237
|
* already contains. Line-wise scan on purpose: the file may hold structures
|
|
@@ -907,7 +1274,7 @@ export function patchLayerManages(controls, name) {
|
|
|
907
1274
|
* @returns true when a directory was there to remove.
|
|
908
1275
|
*/
|
|
909
1276
|
export function purgeMarketState(profileDir) {
|
|
910
|
-
const dir =
|
|
1277
|
+
const dir = join(profileDir, HOT_DIR);
|
|
911
1278
|
try {
|
|
912
1279
|
rmSync(dir, { recursive: true, force: true });
|
|
913
1280
|
return true;
|