dsh-crate 0.5.0 → 0.5.1
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/lib/check.js +1 -1
- package/lib/compatibility.js +54 -32
- package/lib/discovery-compatibility.js +30 -1
- package/lib/hot.js +55 -8
- package/lib/profile.js +13 -2
- package/lib/types/check.d.ts +28 -0
- package/lib/types/hot.d.ts +29 -0
- package/lib/verify.js +35 -9
- package/package.json +1 -1
package/lib/check.js
CHANGED
|
@@ -340,7 +340,7 @@ function parseSemver(value) {
|
|
|
340
340
|
* (`>=1.2.0 <1.3.0`), so it stays as is and parses as unknown below rather
|
|
341
341
|
* than being mistaken for the exact version `1.2.0`.
|
|
342
342
|
*/
|
|
343
|
-
function expandPartialComparator(part, includePrerelease) {
|
|
343
|
+
export function expandPartialComparator(part, includePrerelease) {
|
|
344
344
|
const m = /^(\^|~|>=|<=|>|<)(\d+)(?:\.(\d+))?$/u.exec(part.trim());
|
|
345
345
|
if (m === null)
|
|
346
346
|
return [part];
|
package/lib/compatibility.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* Everything else stays informational: `*`, prerelease-vs-`*` artifacts,
|
|
17
17
|
* unparseable ranges, and optional peers never produce a risk here.
|
|
18
18
|
*/
|
|
19
|
-
import { analyzeProfile, compareSemver } from './check.js';
|
|
19
|
+
import { analyzeProfile, compareSemver, expandPartialComparator } from './check.js';
|
|
20
20
|
import { profileDir, readInstalledManifest } from './profile.js';
|
|
21
21
|
const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
22
22
|
function parseComparator(part) {
|
|
@@ -30,6 +30,26 @@ function parseComparator(part) {
|
|
|
30
30
|
const raw = m[1] ?? '';
|
|
31
31
|
return { op: raw === '' || raw === '=' ? 'exact' : raw, target };
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* One written comparator as full-version comparators. A partial target
|
|
35
|
+
* (`<0.3`, `^0.1`, `~1`) goes through the same node-semver expansion the gate
|
|
36
|
+
* uses in `satisfiesRange`, so both sides agree on where the line ends.
|
|
37
|
+
* A bare partial (`1.2`) stays unparseable, as it does there.
|
|
38
|
+
*/
|
|
39
|
+
function parseWritten(part) {
|
|
40
|
+
const full = parseComparator(part);
|
|
41
|
+
if (full !== null)
|
|
42
|
+
return [full];
|
|
43
|
+
const expanded = expandPartialComparator(part, false);
|
|
44
|
+
if (expanded.length === 1 && expanded[0] === part)
|
|
45
|
+
return null;
|
|
46
|
+
const parsed = expanded.map(parseComparator);
|
|
47
|
+
return parsed.every(p => p !== null) ? parsed : null;
|
|
48
|
+
}
|
|
49
|
+
/** A `^` / `~` comparator, whose ceiling the author implied rather than wrote. */
|
|
50
|
+
function isImplicitCeiling(part) {
|
|
51
|
+
return /^[\^~]/.test(part.trim());
|
|
52
|
+
}
|
|
33
53
|
/** Next breaking bump for `^` / `~`, using `-0` so prereleases compare consistently. */
|
|
34
54
|
function nextBound(target, kind) {
|
|
35
55
|
const m = /^(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?$/.exec(target);
|
|
@@ -51,39 +71,41 @@ function boundsFor(range) {
|
|
|
51
71
|
const alternatives = [];
|
|
52
72
|
for (const rawAlternative of range.split('||')) {
|
|
53
73
|
const parts = rawAlternative.trim().split(/\s+/).filter(Boolean);
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
74
|
+
const written = parts.map(part => ({ implicit: isImplicitCeiling(part), parsed: parseWritten(part) }));
|
|
75
|
+
if (written.some(part => part.parsed === null))
|
|
56
76
|
return null;
|
|
57
77
|
let lower = null;
|
|
58
78
|
let upper = null;
|
|
59
79
|
let explicitUpper = false;
|
|
60
80
|
let exact = null;
|
|
61
|
-
for (const
|
|
62
|
-
const p
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
81
|
+
for (const { implicit, parsed } of written)
|
|
82
|
+
for (const p of parsed) {
|
|
83
|
+
if (p.op === 'exact') {
|
|
84
|
+
exact = p.target;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (p.op === '^' || p.op === '~') {
|
|
88
|
+
const bound = nextBound(p.target, p.op);
|
|
89
|
+
if (bound === null)
|
|
90
|
+
return null;
|
|
91
|
+
if (lower === null || compareSemver(p.target, lower.target) > 0)
|
|
92
|
+
lower = p;
|
|
93
|
+
if (upper === null || compareSemver(bound, upper.target) < 0)
|
|
94
|
+
upper = { op: '<=', target: bound };
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (p.op === '>=' || p.op === '>') {
|
|
98
|
+
if (lower === null || compareSemver(p.target, lower.target) > 0)
|
|
99
|
+
lower = p;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (upper === null || compareSemver(p.target, upper.target) < 0)
|
|
103
|
+
upper = p;
|
|
104
|
+
// A partial `^0.1` arrives here as `<0.2.0-0`; its ceiling is still implied.
|
|
105
|
+
if (!implicit)
|
|
106
|
+
explicitUpper = true;
|
|
107
|
+
}
|
|
66
108
|
}
|
|
67
|
-
if (p.op === '^' || p.op === '~') {
|
|
68
|
-
const bound = nextBound(p.target, p.op);
|
|
69
|
-
if (bound === null)
|
|
70
|
-
return null;
|
|
71
|
-
if (lower === null || compareSemver(p.target, lower.target) > 0)
|
|
72
|
-
lower = p;
|
|
73
|
-
if (upper === null || compareSemver(bound, upper.target) < 0)
|
|
74
|
-
upper = { op: '<=', target: bound };
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (p.op === '>=' || p.op === '>') {
|
|
78
|
-
if (lower === null || compareSemver(p.target, lower.target) > 0)
|
|
79
|
-
lower = p;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
if (upper === null || compareSemver(p.target, upper.target) < 0)
|
|
83
|
-
upper = p;
|
|
84
|
-
explicitUpper = true;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
109
|
alternatives.push({ lower, upper, explicitUpper, exact });
|
|
88
110
|
}
|
|
89
111
|
return alternatives;
|
|
@@ -116,12 +138,12 @@ function declaredLines(range) {
|
|
|
116
138
|
const lines = [];
|
|
117
139
|
for (const rawAlternative of range.split('||')) {
|
|
118
140
|
for (const raw of rawAlternative.trim().split(/\s+/).filter(Boolean)) {
|
|
119
|
-
|
|
120
|
-
if (parsed === null)
|
|
141
|
+
if (parseWritten(raw) === null)
|
|
121
142
|
return null;
|
|
122
|
-
if (
|
|
143
|
+
if (!isImplicitCeiling(raw))
|
|
123
144
|
continue;
|
|
124
|
-
|
|
145
|
+
// `^0.1` names the 0.1 line like `^0.1.0`; `^1` names no minor line.
|
|
146
|
+
const m = /^[\^~](\d+)\.(\d+)(?:\.|$)/.exec(raw.trim());
|
|
125
147
|
if (m !== null)
|
|
126
148
|
lines.push(`${m[1]}.${m[2]}`);
|
|
127
149
|
}
|
|
@@ -13,6 +13,7 @@ import { dirname } from 'node:path';
|
|
|
13
13
|
import { compareSemver, isSemver, satisfiesRange } from './check.js';
|
|
14
14
|
import { classifyPeer, crossesImplicitCeiling } from './compatibility.js';
|
|
15
15
|
import { marketFetch } from './net.js';
|
|
16
|
+
import { activeRegion, githubRoutesFor, rememberGithubRoute, throughProxy } from './regions.js';
|
|
16
17
|
import { parseSourceUrl } from './sources.js';
|
|
17
18
|
const CACHE_SCHEMA = 'dsh-crate/discovery-compatibility-cache/v1';
|
|
18
19
|
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
@@ -65,10 +66,38 @@ async function githubManifest(source, fetcher) {
|
|
|
65
66
|
throw new Error('invalid GitHub reference');
|
|
66
67
|
}
|
|
67
68
|
const file = parsed.subpath === null ? 'package.json' : `${parsed.subpath}/package.json`;
|
|
68
|
-
const manifest = await
|
|
69
|
+
const manifest = await rawJson(`https://raw.githubusercontent.com/${parsed.repo}/${encodeURIComponent(ref)}/${file}`);
|
|
69
70
|
if (record(manifest) === null)
|
|
70
71
|
throw new Error('package manifest unavailable');
|
|
71
72
|
return manifest;
|
|
73
|
+
/**
|
|
74
|
+
* Read a raw file through the region's configured routes, in order.
|
|
75
|
+
*
|
|
76
|
+
* `raw.githubusercontent.com` is blockable on its own — the report (#1148)
|
|
77
|
+
* measured an `ECONNRESET` with no proxy and a 200 through one — while the
|
|
78
|
+
* catalog and the registry answered fine, so "the market page loads" said
|
|
79
|
+
* nothing about this read. This path used to compose the host directly and
|
|
80
|
+
* give up on the first error, and the card then said the host's requirement
|
|
81
|
+
* was unknown even though the release declares one. The routes are the same
|
|
82
|
+
* list the update path walks; one retry per route covers the transient
|
|
83
|
+
* resets that made a single miss look permanent.
|
|
84
|
+
*/
|
|
85
|
+
async function rawJson(url) {
|
|
86
|
+
let last;
|
|
87
|
+
for (const route of githubRoutesFor('raw', activeRegion())) {
|
|
88
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
89
|
+
try {
|
|
90
|
+
const value = await json(throughProxy(route, url));
|
|
91
|
+
rememberGithubRoute('raw', route);
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
last = error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
throw last instanceof Error ? last : new Error('GitHub raw content unavailable');
|
|
100
|
+
}
|
|
72
101
|
}
|
|
73
102
|
function range(value) {
|
|
74
103
|
if (typeof value !== 'string')
|
package/lib/hot.js
CHANGED
|
@@ -148,8 +148,17 @@ function readPkgDsh(profileDir, packageName) {
|
|
|
148
148
|
* expressions) — those compositions fall back to restart activation.
|
|
149
149
|
*/
|
|
150
150
|
export function parseSimplePatch(patchText) {
|
|
151
|
+
const scan = scanPatch(patchText);
|
|
152
|
+
return scan.blocker === null ? scan.rows : null;
|
|
153
|
+
}
|
|
154
|
+
export function scanPatch(patchText) {
|
|
151
155
|
const rows = [];
|
|
152
156
|
let pending = null;
|
|
157
|
+
// A patch row at column 0 targets an EXISTING entry (the long-standing way
|
|
158
|
+
// to disable one); only rows indented inside `- insert:` bring a plugin in.
|
|
159
|
+
// Tracked so the walk can say which of the two it met instead of calling
|
|
160
|
+
// every top-level row "a config block" (#1102, dsh-mnemon's shipped patch).
|
|
161
|
+
let topLevelRow = false;
|
|
153
162
|
// Split on CRLF too. `#.*$` cannot strip a comment that ends in \r —
|
|
154
163
|
// JS treats \r as a line terminator, so `.` will not cross it and `$`
|
|
155
164
|
// only anchors at the very end — leaving the comment text in place,
|
|
@@ -162,10 +171,15 @@ export function parseSimplePatch(patchText) {
|
|
|
162
171
|
continue;
|
|
163
172
|
if (/^-\s+insert:\s*$/.test(line))
|
|
164
173
|
continue;
|
|
174
|
+
if (/^-\s+id:\s*\S+\s*$/.test(line)) {
|
|
175
|
+
topLevelRow = true;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
165
178
|
const id = /^\s+-\s+id:\s*(\S+)\s*$/.exec(line);
|
|
166
179
|
if (id !== null) {
|
|
180
|
+
// A second id before the first got its name: the row was cut short.
|
|
167
181
|
if (pending !== null)
|
|
168
|
-
return
|
|
182
|
+
return { rows, blocker: 'incomplete' };
|
|
169
183
|
pending = id[1];
|
|
170
184
|
continue;
|
|
171
185
|
}
|
|
@@ -175,11 +189,43 @@ export function parseSimplePatch(patchText) {
|
|
|
175
189
|
pending = null;
|
|
176
190
|
continue;
|
|
177
191
|
}
|
|
178
|
-
|
|
192
|
+
const leaf = /^\s*(?:-\s+)?([A-Za-z_][\w-]*)\s*:/.exec(line);
|
|
193
|
+
const key = leaf?.[1];
|
|
194
|
+
if (key === 'config')
|
|
195
|
+
return { rows, blocker: 'config', key };
|
|
196
|
+
if (key === 'disabled' || key === 'enabled')
|
|
197
|
+
return { rows, blocker: 'disabled', key };
|
|
198
|
+
return { rows, blocker: 'other', key };
|
|
199
|
+
}
|
|
200
|
+
if (pending !== null)
|
|
201
|
+
return { rows, blocker: 'incomplete' };
|
|
202
|
+
// A top-level row whose body never arrived: still not an insert list, and
|
|
203
|
+
// saying so keeps `parseSimplePatch` from mounting the inserts around it
|
|
204
|
+
// while silently dropping the entry it patched.
|
|
205
|
+
if (topLevelRow)
|
|
206
|
+
return { rows, blocker: 'other', key: 'id' };
|
|
207
|
+
if (rows.length === 0)
|
|
208
|
+
return { rows, blocker: 'empty' };
|
|
209
|
+
return { rows, blocker: null };
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* One sentence for a refusal that is only about the patch's shape, naming the
|
|
213
|
+
* cause and what happens next. Shared by the hot mount and the activation
|
|
214
|
+
* verdict so the two cannot drift apart on the same fact again.
|
|
215
|
+
*/
|
|
216
|
+
export function patchBlockerReason(blocker, key) {
|
|
217
|
+
switch (blocker) {
|
|
218
|
+
case 'config':
|
|
219
|
+
return 'bundle patch 里有 config 块,热挂载只重放纯 insert 行;重启后由 bundle 层按原样加载 / the bundle patch has a config block; hot-mount replays plain insert rows only — a restart loads the bundle as written';
|
|
220
|
+
case 'disabled':
|
|
221
|
+
return '这个包有一行被关掉了(disabled),热挂载不重放开关行;重启后按原样加载,那一行仍然是关的 / one of its rows is switched off (disabled); hot-mount does not replay switch rows — a restart loads the bundle as written and that row stays off';
|
|
222
|
+
case 'incomplete':
|
|
223
|
+
return 'bundle patch 里有一行 id 没有配 name,市场读不懂这一行;重启后由 bundle 层按原样加载,仍不生效就修这个包的 patch / a row has an id but no name, so the market cannot read it — a restart loads the bundle as written; fix the package patch if it still does not work';
|
|
224
|
+
case 'empty':
|
|
225
|
+
return 'bundle patch 里没有 insert 行,热挂载没有可重放的内容;重启后由 bundle 层生效 / the bundle patch has no insert rows, so there is nothing to replay — it activates on restart';
|
|
226
|
+
default:
|
|
227
|
+
return `bundle patch 里有 insert 之外的行(${key ?? '未识别的键'}),热挂载只重放纯 insert;重启后由 bundle 层按原样加载 / the bundle patch has a row beyond plain inserts (${key ?? 'an unrecognised key'}); hot-mount replays plain inserts only — a restart loads the bundle as written`;
|
|
179
228
|
}
|
|
180
|
-
if (pending !== null || rows.length === 0)
|
|
181
|
-
return null;
|
|
182
|
-
return rows;
|
|
183
229
|
}
|
|
184
230
|
/**
|
|
185
231
|
* Wipe leftover hot-mount inputs; call once when the market host starts.
|
|
@@ -659,14 +705,15 @@ export async function hotMount(ctx, profileDir, packageName) {
|
|
|
659
705
|
}
|
|
660
706
|
let rows;
|
|
661
707
|
if (texts !== null && texts.length > 0) {
|
|
662
|
-
|
|
663
|
-
if (
|
|
708
|
+
const scan = scanPatch(texts.join('\n'));
|
|
709
|
+
if (scan.blocker !== null) {
|
|
664
710
|
return {
|
|
665
711
|
ok: false,
|
|
666
712
|
deferred: true,
|
|
667
|
-
reason:
|
|
713
|
+
reason: patchBlockerReason(scan.blocker, scan.key),
|
|
668
714
|
};
|
|
669
715
|
}
|
|
716
|
+
rows = scan.rows;
|
|
670
717
|
}
|
|
671
718
|
else if (declared.length > 0) {
|
|
672
719
|
// The declaration is VOID — one of its files cannot be read. The host
|
package/lib/profile.js
CHANGED
|
@@ -10,7 +10,7 @@ import { isDeepStrictEqual } from 'node:util';
|
|
|
10
10
|
import { JSON_SCHEMA, load } from 'js-yaml';
|
|
11
11
|
import { findDshInstallDir } from './dsh-install.js';
|
|
12
12
|
import { resolveDshHome } from './home-paths.js';
|
|
13
|
-
import { githubRemoteIdentities, githubRepoIdentities, hostedRepoKey, isGenerationLink, isGitHostedSpec, repoOfTarget } from './sources.js';
|
|
13
|
+
import { catalogRepoKey, githubRemoteIdentities, githubRepoIdentities, hostedRepoKey, isGenerationLink, isGitHostedSpec, lookupRepoFromUrl, repoOfTarget } from './sources.js';
|
|
14
14
|
/**
|
|
15
15
|
* Whether a profile name follows DSH's own directory-name contract.
|
|
16
16
|
*
|
|
@@ -669,9 +669,20 @@ export function readInstalledRepoEvidence(profile, name, spec, explicitDir) {
|
|
|
669
669
|
// The URL still must not be resolved through the package's OWN manifest:
|
|
670
670
|
// a fork installed as `github:myfork/plugin` carries upstream's repository
|
|
671
671
|
// field, and trusting it made upstream's card read as installed (#580).
|
|
672
|
+
//
|
|
673
|
+
// A Release asset URL names its source just as plainly, but it is not an
|
|
674
|
+
// install TARGET this build will fetch from later, so it stays out of
|
|
675
|
+
// repoOfTarget (that one answers "where will this come from"). Reading it
|
|
676
|
+
// here keeps the display-only promise lookupRepoFromUrl makes: the identity
|
|
677
|
+
// links an installed package to its catalog entry, and nothing in install,
|
|
678
|
+
// rollback, duplicate detection, or build-script approval reads it.
|
|
672
679
|
if (!local && (isGitHostedSpec(spec) || /^https?:/i.test(spec.trim()))) {
|
|
673
680
|
const repo = repoOfTarget(spec);
|
|
674
|
-
|
|
681
|
+
if (repo !== null)
|
|
682
|
+
return { identities: [repo], hints: [] };
|
|
683
|
+
const release = lookupRepoFromUrl(spec.trim());
|
|
684
|
+
const key = release === null ? null : catalogRepoKey(release);
|
|
685
|
+
return key === null ? { identities: [], hints: [] } : { identities: [key], hints: [] };
|
|
675
686
|
}
|
|
676
687
|
const root = profileDir(profile, explicitDir);
|
|
677
688
|
const sourceDir = local ? localSpecDirectory(root, spec) : null;
|
package/lib/types/check.d.ts
CHANGED
|
@@ -235,6 +235,34 @@ export declare function parsePatchText(text: string): unknown[] | null;
|
|
|
235
235
|
export declare function parsePatchFile(path: string): unknown[] | null;
|
|
236
236
|
/** DSH host core packages: what the dsh installation ships under @deepseek-ai. */
|
|
237
237
|
export declare function corePackageNames(dshInstallDir: string | null): Set<string>;
|
|
238
|
+
/**
|
|
239
|
+
* Rewrite a comparator whose target is a PARTIAL version into the full
|
|
240
|
+
* comparators node-semver desugars it to. Anything else comes back as is.
|
|
241
|
+
*
|
|
242
|
+
* The `@deepseek-ai/dsh-*` peers of a whole family of connector plugins are
|
|
243
|
+
* written this way (`>=0.1.5 <0.3`, `>=0.1.7-rc <2`, `>=0.2.0-rc.0 <0.3`).
|
|
244
|
+
* Read as unknown, they left the activation gate standing aside: measured
|
|
245
|
+
* against the host's own evaluator over 699 live catalog manifests, those
|
|
246
|
+
* were the last 7 of 2796 (package, runtime) pairs where the host refuses a
|
|
247
|
+
* plugin and the market still promised a restart would apply it.
|
|
248
|
+
*
|
|
249
|
+
* Zero-filling the target is right for `>=` and wrong for the rest. A partial
|
|
250
|
+
* names a whole release line, so node-semver (`replaceXRange`, `replaceTilde`,
|
|
251
|
+
* `replaceCaret`) moves the bound to the edge of that line:
|
|
252
|
+
*
|
|
253
|
+
* `<0.3` → `<0.3.0-0` `<=0.3` → `<0.4.0-0`
|
|
254
|
+
* `>0.3` → `>=0.4.0` `>1` → `>=2.0.0`
|
|
255
|
+
* `~1` → `>=1.0.0 <2.0.0-0` `^0` → `>=0.0.0 <1.0.0-0`
|
|
256
|
+
* `^0.0` → `>=0.0.0 <0.1.0-0`
|
|
257
|
+
*
|
|
258
|
+
* Comparing against the raw partial string instead ordered `9.1.0` above
|
|
259
|
+
* `10` and `0.10.0` below `0.3`, character by character.
|
|
260
|
+
*
|
|
261
|
+
* A BARE partial (`1.2`) has no operator and is an x-range in semver
|
|
262
|
+
* (`>=1.2.0 <1.3.0`), so it stays as is and parses as unknown below rather
|
|
263
|
+
* than being mistaken for the exact version `1.2.0`.
|
|
264
|
+
*/
|
|
265
|
+
export declare function expandPartialComparator(part: string, includePrerelease: boolean): string[];
|
|
238
266
|
/** Compare two semver strings: negative | zero | positive (prerelease < release of same base). */
|
|
239
267
|
/** Whether a string is a well-formed semver `compareSemver` can order. */
|
|
240
268
|
export declare function isSemver(value: string): boolean;
|
package/lib/types/hot.d.ts
CHANGED
|
@@ -69,6 +69,35 @@ export declare function resolveProfileEntry(profileDir: string, name: string): s
|
|
|
69
69
|
* expressions) — those compositions fall back to restart activation.
|
|
70
70
|
*/
|
|
71
71
|
export declare function parseSimplePatch(patchText: string): HotRow[] | null;
|
|
72
|
+
/**
|
|
73
|
+
* Which shape stopped `parseSimplePatch` — the CAUSE, not just "not plain".
|
|
74
|
+
*
|
|
75
|
+
* `parseSimplePatch` collapses five different inputs into one `null`: a
|
|
76
|
+
* `config` block, a `disabled`/`enabled` switch row, any other key (`inject`,
|
|
77
|
+
* a nested mapping), a row whose `name` never arrives, and a patch with no
|
|
78
|
+
* insert rows at all. Every caller that had to explain the refusal threw all
|
|
79
|
+
* five into one sentence written for the first, and told users their patch
|
|
80
|
+
* "contains config/expression rows" when it merely switched a row off
|
|
81
|
+
* (#1102). Naming the shape is the difference between a sentence the reader
|
|
82
|
+
* can act on and one they cannot (#813, AGENTS.md: 说不出来就别用一句话把
|
|
83
|
+
* 空缺填上).
|
|
84
|
+
*/
|
|
85
|
+
export type PatchBlocker = 'config' | 'disabled' | 'incomplete' | 'empty' | 'other';
|
|
86
|
+
export interface PatchScan {
|
|
87
|
+
/** Insert rows read before the scan stopped; empty when it did not. */
|
|
88
|
+
rows: HotRow[];
|
|
89
|
+
/** null when the patch IS a plain insert list (`rows` is then non-empty). */
|
|
90
|
+
blocker: PatchBlocker | null;
|
|
91
|
+
/** The key that stopped the scan, when there is one to name. */
|
|
92
|
+
key?: string;
|
|
93
|
+
}
|
|
94
|
+
export declare function scanPatch(patchText: string): PatchScan;
|
|
95
|
+
/**
|
|
96
|
+
* One sentence for a refusal that is only about the patch's shape, naming the
|
|
97
|
+
* cause and what happens next. Shared by the hot mount and the activation
|
|
98
|
+
* verdict so the two cannot drift apart on the same fact again.
|
|
99
|
+
*/
|
|
100
|
+
export declare function patchBlockerReason(blocker: PatchBlocker, key?: string): string;
|
|
72
101
|
/**
|
|
73
102
|
* Wipe leftover hot-mount inputs; call once when the market host starts.
|
|
74
103
|
* `state.json` (disable choices + groups) deliberately survives.
|
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 { listHotMounts,
|
|
33
|
+
import { listHotMounts, 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';
|
|
@@ -135,13 +135,34 @@ function readPkgDsh(profile, name, explicitDir) {
|
|
|
135
135
|
return null;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* The patch text the HOST reads for this package, or null when it reads none.
|
|
140
|
+
*
|
|
141
|
+
* #1102: this used to read the package root's `cordis.patch.yml`
|
|
142
|
+
* unconditionally, while hot mount (#646, #792) and `bundlePatchIsEmpty`
|
|
143
|
+
* resolve `dsh.bundle.patch` through `declaredBundlePatchFiles`. Two
|
|
144
|
+
* consumers of one fact disagreed: a patch declared in a subdirectory, or as
|
|
145
|
+
* a list, was judged from a file the host never reads (or from no file at
|
|
146
|
+
* all), and a leftover root file could decide the verdict by itself.
|
|
147
|
+
*
|
|
148
|
+
* Same rule as hot mount, deliberately: the declared files, the root file as
|
|
149
|
+
* the fallback for packages that declare nothing, and all-or-nothing — the
|
|
150
|
+
* host throws on one unreadable overlay file and skips the whole bundle.
|
|
151
|
+
*/
|
|
138
152
|
function patchTextOf(profile, name, explicitDir) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
const dir = join(profileDir(profile, explicitDir), 'node_modules', name);
|
|
154
|
+
const declared = declaredBundlePatchFiles(dir);
|
|
155
|
+
const sources = declared.length > 0 ? declared : [join(dir, 'cordis.patch.yml')];
|
|
156
|
+
const texts = [];
|
|
157
|
+
for (const file of sources) {
|
|
158
|
+
try {
|
|
159
|
+
texts.push(readFileSync(file, 'utf8'));
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
144
164
|
}
|
|
165
|
+
return texts.join('\n');
|
|
145
166
|
}
|
|
146
167
|
/**
|
|
147
168
|
* Verify the activation state of one installed package.
|
|
@@ -570,12 +591,17 @@ loaderNeverStarted = false) {
|
|
|
570
591
|
};
|
|
571
592
|
}
|
|
572
593
|
const patch = patchTextOf(profile, name, activeProfileDir);
|
|
573
|
-
const
|
|
594
|
+
const scan = patch === null ? null : scanPatch(patch);
|
|
595
|
+
// #1102: a patch the market cannot replay has five shapes, and saying
|
|
596
|
+
// "config/expression" for all of them told users something about their
|
|
597
|
+
// package that was not true — a switched-off row is not a config block.
|
|
598
|
+
// Name the shape when it is known; keep the honest "not hot-mounted this
|
|
599
|
+
// session" when the declaration could not be read at all.
|
|
574
600
|
return {
|
|
575
601
|
state: 'restart',
|
|
576
602
|
reasons: [
|
|
577
|
-
|
|
578
|
-
?
|
|
603
|
+
scan !== null && scan.blocker !== null
|
|
604
|
+
? patchBlockerReason(scan.blocker, scan.key)
|
|
579
605
|
: '已进入 profile bundle 层但本次未能热挂载;重启后生效 / in the bundle layer but not hot-mounted this session — it activates on restart',
|
|
580
606
|
],
|
|
581
607
|
bundle: true,
|