@deepseek-ai/dsh-plugin-manager 0.2.1-rc.4 → 0.2.2-alpha.2
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/README.i18n.yaml +13 -10
- package/README.md +40 -5
- package/README.zh.md +40 -5
- package/lib/index.js +943 -128
- package/lib/typert.host.js +498 -40
- package/lib/typert.remote-client.d.ts +11 -1
- package/lib/typert.remote-client.js +399 -36
- package/lib/types/build-approval.d.ts +5 -5
- package/lib/types/build-approval.js +23 -10
- package/lib/types/bundle-detail.d.ts +40 -0
- package/lib/types/bundle-detail.js +85 -0
- package/lib/types/diagnostic.d.ts +17 -0
- package/lib/types/diagnostic.js +72 -0
- package/lib/types/git-transport.d.ts +27 -0
- package/lib/types/git-transport.js +65 -0
- package/lib/types/index.d.ts +90 -2
- package/lib/types/index.js +517 -100
- package/lib/types/install-failure.js +1 -1
- package/lib/types/operations.d.ts +5 -1
- package/lib/types/operations.js +29 -6
- package/lib/types/tools.js +5 -1
- package/lib/types/types.d.ts +159 -2
- package/lib/types/versions.d.ts +40 -0
- package/lib/types/versions.js +61 -0
- package/locale/de.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/tools/de.json +5 -0
- package/locale/tools/es.json +5 -0
- package/locale/tools/fr.json +5 -0
- package/locale/tools/ja.json +5 -0
- package/locale/tools/pt.json +5 -0
- package/locale/tools/ru.json +5 -0
- package/package.json +48 -34
package/lib/index.js
CHANGED
|
@@ -5,14 +5,102 @@ import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
import { withFileLock, writeFileAtomic } from "@deepseek-ai/dsh-atomic-write";
|
|
7
7
|
import z from "@deepseek-ai/schemastery";
|
|
8
|
-
import
|
|
8
|
+
import semver from "semver";
|
|
9
|
+
import { Remote, RemoteError, TypertRemoteService, remoteErrorOf } from "@deepseek-ai/dsh-typert-protocol";
|
|
10
|
+
import { DetailFailure, NPM_FILE_SOURCES, detailImage, detailImageResponse, languageChain, localFiles, npmFileSourceOrder, npmFiles, readPackageDocument } from "@deepseek-ai/dsh-plugin-detail";
|
|
11
|
+
import { MAX_TIMER_DELAY_MS } from "@deepseek-ai/dsh-timeout";
|
|
12
|
+
import { PROFILE_COMPATIBILITY_FILENAME, ResolutionRestartRequired, UnsupportedBundlePlatformError, assertBundlePlatform, bundlePatchPaths, composeEntries, evaluatePluginCompatibility, getDshRuntimeVersion, loadOptionalPatches, loadOverlayPatches, pluginCompatibilityWarning, readBundlePatches, readPluginMeta, readProfileCompatibility, readProfileManifest, readProfilePatches, readProfileVersionExemptions, resolveBundleDir, resolveProfileDir, setProfileVersionExemption, validatePluginVersionExemption } from "@deepseek-ai/dsh-app-boot";
|
|
9
13
|
import { pluginEntryId, readPluginInventory } from "@deepseek-ai/dsh-host-plugin-inventory";
|
|
10
|
-
import { OFFICIAL_ON_DEMAND_CATALOG, OPTIONAL_BUNDLES,
|
|
14
|
+
import { OFFICIAL_ON_DEMAND_CATALOG, OPTIONAL_BUNDLES, PROTECTED_PLUGINS } from "@deepseek-ai/dsh-official-bundles";
|
|
11
15
|
import { once } from "node:events";
|
|
12
16
|
import { execa } from "execa";
|
|
13
17
|
import { scrubbedParentEnv } from "@deepseek-ai/dsh-subprocess";
|
|
14
18
|
import { homedir } from "node:os";
|
|
15
19
|
import { isAlias, isMap, isNode, isScalar, isSeq, parseDocument, visit } from "yaml";
|
|
20
|
+
import hostedGitInfo from "hosted-git-info";
|
|
21
|
+
//#region lib/types/bundle-detail.js
|
|
22
|
+
/**
|
|
23
|
+
* Detail documents of profile bundles: an installed bundle's `meta.detail` file or README from its directory, and an
|
|
24
|
+
* official bundle the installation offers, before it is installed, from the npm file CDNs at its offered version. Reads
|
|
25
|
+
* keep no state; an image request resolves its bundle and document again.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* The files of a listed bundle: its directory when its files can be read, otherwise its offered npm version.
|
|
29
|
+
* @param bundle - the bundle as `listBundles()` reports it.
|
|
30
|
+
* @param preferred - npm file CDNs to ask first for an offered version; see `npmFileSourceOrder`.
|
|
31
|
+
* @param options - profile, sources, and limits.
|
|
32
|
+
* @returns the files, or undefined for a bundle offered at no published version.
|
|
33
|
+
* @throws {RemoteError} `plugin-manager/unknown-bundle` when the bundle's directory cannot be resolved.
|
|
34
|
+
*/
|
|
35
|
+
function filesOf(bundle, preferred, options) {
|
|
36
|
+
if (bundle.availability !== "missing") {
|
|
37
|
+
let dir;
|
|
38
|
+
try {
|
|
39
|
+
dir = resolveBundleDir("dsh", bundle.name, options.profile.installAnchor, options.profile.dir);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw new RemoteError("plugin-manager/unknown-bundle", error.message, { name: bundle.name }, { cause: error });
|
|
42
|
+
}
|
|
43
|
+
return localFiles(dir, String(bundle.version));
|
|
44
|
+
}
|
|
45
|
+
const version = bundle.installTarget?.version;
|
|
46
|
+
if (version === void 0 || semver.valid(version) !== version) return void 0;
|
|
47
|
+
const sources = npmFileSourceOrder(options.npmFileSources, preferred);
|
|
48
|
+
return npmFiles(bundle.name, version, sources, {
|
|
49
|
+
timeoutMs: options.timeoutMs,
|
|
50
|
+
lifetime: options.lifetime
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Rethrow a detail failure as the Remote error clients read. */
|
|
54
|
+
function remoteFailure(error) {
|
|
55
|
+
if (error instanceof DetailFailure) throw new RemoteError("plugin-manager/detail-unavailable", error.message, { reason: error.reason }, { cause: error });
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Read a bundle's detail document in a display language.
|
|
60
|
+
* @param bundle - the bundle as `listBundles()` reports it.
|
|
61
|
+
* @param language - a BCP 47 language id.
|
|
62
|
+
* @param preferred - npm file CDNs to ask first for an offered version; see `npmFileSourceOrder`.
|
|
63
|
+
* @param options - profile, sources, and limits.
|
|
64
|
+
* @returns the document, or `none` when the bundle has neither a `meta.detail` file nor a README.
|
|
65
|
+
* @throws {RemoteError} `plugin-manager/invalid-language`, `plugin-manager/unknown-bundle`, or
|
|
66
|
+
* `plugin-manager/detail-unavailable`.
|
|
67
|
+
*/
|
|
68
|
+
async function readBundleDocument(bundle, language, preferred, options) {
|
|
69
|
+
let languages;
|
|
70
|
+
try {
|
|
71
|
+
languages = languageChain(language);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new RemoteError("plugin-manager/invalid-language", error.message, { language }, { cause: error });
|
|
74
|
+
}
|
|
75
|
+
const files = filesOf(bundle, preferred, options);
|
|
76
|
+
if (files === void 0) return { status: "none" };
|
|
77
|
+
const document = await readPackageDocument(files, "", languages, options.maxDocumentBytes, options.lifetime).catch(remoteFailure);
|
|
78
|
+
return document === void 0 ? { status: "none" } : {
|
|
79
|
+
status: "found",
|
|
80
|
+
...document
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Read an image beside a bundle's detail document.
|
|
85
|
+
* @param bundle - the bundle as `listBundles()` reports it.
|
|
86
|
+
* @param document - the document's path inside the bundle, as {@link readBundleDocument} returned it.
|
|
87
|
+
* @param destination - the image destination as the document writes it.
|
|
88
|
+
* @param preferred - npm file CDNs to ask first for an offered version; see `npmFileSourceOrder`.
|
|
89
|
+
* @param options - profile, sources, and limits.
|
|
90
|
+
* @returns the bytes and media type, or undefined for a path outside the bundle, an unsupported type, or a missing file.
|
|
91
|
+
* @throws {RemoteError} `plugin-manager/unknown-bundle` or `plugin-manager/detail-unavailable`.
|
|
92
|
+
*/
|
|
93
|
+
async function readBundleImage(bundle, document, destination, preferred, options) {
|
|
94
|
+
const image = detailImage(document, destination);
|
|
95
|
+
const files = image === void 0 ? void 0 : filesOf(bundle, preferred, options);
|
|
96
|
+
if (image === void 0 || files === void 0) return void 0;
|
|
97
|
+
const bytes = await files.read(image.path, options.maxImageBytes, options.lifetime).catch(remoteFailure);
|
|
98
|
+
return bytes === void 0 ? void 0 : {
|
|
99
|
+
bytes,
|
|
100
|
+
mediaType: image.mediaType
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
16
104
|
//#region lib/types/install-spec.js
|
|
17
105
|
/**
|
|
18
106
|
* Reading an install spec before pnpm sees it: which of pnpm's spec forms it
|
|
@@ -319,12 +407,13 @@ function bundleManifest(name, dir, anchor) {
|
|
|
319
407
|
async function saveManifest(dir, manifest) {
|
|
320
408
|
await writeFileAtomic(join(dir, "package.json"), JSON.stringify(manifest, void 0, 2) + "\n", { mode: 384 });
|
|
321
409
|
}
|
|
322
|
-
/** Reconcile
|
|
410
|
+
/** Reconcile bundle selection, returning platform denials without saving any selection changes. */
|
|
323
411
|
async function reconcile(before, dir, anchor, options) {
|
|
324
412
|
const after = readProfileManifest("dsh", dir);
|
|
325
413
|
const dependencies = Object.keys(after.dependencies ?? {});
|
|
326
414
|
const beforeDeps = new Set(Object.keys(before.dependencies ?? {}));
|
|
327
415
|
const previous = after.dsh?.profile?.bundles ?? [];
|
|
416
|
+
const unsupported = [];
|
|
328
417
|
const bundles = previous.filter((name) => {
|
|
329
418
|
if (!beforeDeps.has(name) && !dependencies.includes(name)) return true;
|
|
330
419
|
return dependencies.includes(name) && bundleManifest(name, dir, anchor) !== void 0;
|
|
@@ -336,10 +425,18 @@ async function reconcile(before, dir, anchor, options) {
|
|
|
336
425
|
options.onOutput?.(`dsh: warning: ${name} declares no dsh.bundle — installed as a plain dependency, not a profile layer\n`, "stderr");
|
|
337
426
|
continue;
|
|
338
427
|
}
|
|
428
|
+
try {
|
|
429
|
+
assertBundlePlatform(metadata.dsh.bundle.platforms, process.platform);
|
|
430
|
+
} catch (error) {
|
|
431
|
+
if (!(error instanceof UnsupportedBundlePlatformError)) throw error;
|
|
432
|
+
unsupported.push(`${name}: ${error.message}`);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
339
435
|
for (const file of bundlePatchPaths(resolveBundleDir("dsh", name, anchor, dir), metadata.dsh.bundle)) loadOverlayPatches("dsh", file);
|
|
340
436
|
if (!bundles.includes(name)) bundles.push(name);
|
|
341
437
|
}
|
|
342
|
-
if (
|
|
438
|
+
if (unsupported.length > 0) return unsupported;
|
|
439
|
+
if (JSON.stringify(previous) === JSON.stringify(bundles)) return [];
|
|
343
440
|
after.dsh = {
|
|
344
441
|
...after.dsh,
|
|
345
442
|
profile: {
|
|
@@ -348,6 +445,7 @@ async function reconcile(before, dir, anchor, options) {
|
|
|
348
445
|
}
|
|
349
446
|
};
|
|
350
447
|
await saveManifest(dir, after);
|
|
448
|
+
return [];
|
|
351
449
|
}
|
|
352
450
|
/**
|
|
353
451
|
* How long the pipes keep draining after their process exited, as a fixed part of
|
|
@@ -520,6 +618,8 @@ function bundleComponentManifests(manifest, dir, anchor) {
|
|
|
520
618
|
* @param options Output, activation and cancellation policy.
|
|
521
619
|
* @returns Exit status, whether the silence bound stopped the run, and the diagnostic path.
|
|
522
620
|
* A compatibility denial returns exit code 1. Service output is bounded; CLI output uses inherited descriptors.
|
|
621
|
+
* Unsupported Host activation returns exit code 1 with named diagnostics; installed dependencies remain,
|
|
622
|
+
* and no bundle selection changes are saved. Other reconciliation or filesystem errors reject.
|
|
523
623
|
* The diagnostic file is closed on return or rejection, including preparation and spawn failures.
|
|
524
624
|
*/
|
|
525
625
|
async function runProfilePnpm(context, args, options) {
|
|
@@ -759,7 +859,16 @@ async function runProfilePnpm(context, args, options) {
|
|
|
759
859
|
await log.write(diagnostic);
|
|
760
860
|
options.onOutput?.(diagnostic, "stderr");
|
|
761
861
|
append(Buffer.from(diagnostic));
|
|
762
|
-
} else if (options.activateNewBundles !== false)
|
|
862
|
+
} else if (options.activateNewBundles !== false) {
|
|
863
|
+
const unsupported = await reconcile(before, dir, context.installAnchor, options);
|
|
864
|
+
if (unsupported.length > 0) {
|
|
865
|
+
exitCode = 1;
|
|
866
|
+
const diagnostic = `\ndsh: bundle activation rejected: ${unsupported.join("\n")}\ndsh: installed dependencies remain; bundle selection is unchanged. Use a supported Host or remove the unwanted dependencies with 'dsh plugin remove <package>'.\n`;
|
|
867
|
+
await log.write(diagnostic);
|
|
868
|
+
options.onOutput?.(diagnostic, "stderr");
|
|
869
|
+
append(Buffer.from(diagnostic));
|
|
870
|
+
}
|
|
871
|
+
}
|
|
763
872
|
}
|
|
764
873
|
} finally {
|
|
765
874
|
control.settled = true;
|
|
@@ -826,7 +935,7 @@ function registryArguments(registry) {
|
|
|
826
935
|
* configured after it are the retry.
|
|
827
936
|
* @param dir Profile directory.
|
|
828
937
|
* @param spec One registry spec: a package name with an optional range.
|
|
829
|
-
* @param options The registry, cancellation, and the time bound.
|
|
938
|
+
* @param options The fields printed, the registry, cancellation, and the time bound.
|
|
830
939
|
* @returns pnpm's exit, output, and how the lookup ended.
|
|
831
940
|
*/
|
|
832
941
|
async function viewProfilePackage(dir, spec, options) {
|
|
@@ -834,10 +943,7 @@ async function viewProfilePackage(dir, spec, options) {
|
|
|
834
943
|
...options.args ?? [],
|
|
835
944
|
"view",
|
|
836
945
|
spec,
|
|
837
|
-
|
|
838
|
-
"version",
|
|
839
|
-
"description",
|
|
840
|
-
"dsh",
|
|
946
|
+
...options.fields,
|
|
841
947
|
"--json",
|
|
842
948
|
...registryArguments(options.registry ?? null),
|
|
843
949
|
"--config.fetch-retries=0"
|
|
@@ -872,7 +978,7 @@ async function viewProfilePackage(dir, spec, options) {
|
|
|
872
978
|
*/
|
|
873
979
|
/** Patterns in the order they decide: a specific code before the generic network family. */
|
|
874
980
|
const LOG_KINDS = [
|
|
875
|
-
["build-blocked", /ERR_PNPM_IGNORED_BUILDS|Ignored build scripts/],
|
|
981
|
+
["build-blocked", /ERR_PNPM_IGNORED_BUILDS|Ignored build scripts|ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED/],
|
|
876
982
|
["not-found", /ERR_PNPM_FETCH_404|\bE404\b|404 Not Found|Not Found - GET/],
|
|
877
983
|
["no-matching-version", /ERR_PNPM_NO_MATCHING_VERSION|\bETARGET\b|No matching version/],
|
|
878
984
|
["disk-full", /\bENOSPC\b|no space left on device/i],
|
|
@@ -1085,6 +1191,18 @@ async function writePluginEnabled(profile, id, name, enabled) {
|
|
|
1085
1191
|
const UNDECIDED_BUILD = "set this to true or false";
|
|
1086
1192
|
/** Where a non-interactive run names the build scripts it skipped. */
|
|
1087
1193
|
const IGNORED_BUILDS = /\bIgnored build scripts: (.+)/;
|
|
1194
|
+
/** The `allowBuilds` key pnpm suggests when it refuses to prepare a git-hosted package; a subdirectory key can contain spaces. */
|
|
1195
|
+
const GIT_DEP_PREPARE = /ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED[\s\S]*?^allowBuilds:\r?\n[ \t]+(.+?): true$/m;
|
|
1196
|
+
/**
|
|
1197
|
+
* Whether an `allowBuilds` key names a git URL that carries a credential: a password, or any user name over HTTP(S).
|
|
1198
|
+
* Such a key is not recorded, so the credential stays out of the profile settings and the pending list.
|
|
1199
|
+
*/
|
|
1200
|
+
function carriesCredential(key) {
|
|
1201
|
+
const at = key.indexOf("@git+");
|
|
1202
|
+
if (at === -1) return false;
|
|
1203
|
+
const url = URL.parse(key.slice(at + 5).replace(/#.*$/s, ""));
|
|
1204
|
+
return url !== null && (url.password !== "" || url.username !== "" && /^https?:$/.test(url.protocol));
|
|
1205
|
+
}
|
|
1088
1206
|
async function readPolicy(dir) {
|
|
1089
1207
|
let text;
|
|
1090
1208
|
try {
|
|
@@ -1109,33 +1227,33 @@ async function readPolicy(dir) {
|
|
|
1109
1227
|
};
|
|
1110
1228
|
}
|
|
1111
1229
|
/**
|
|
1112
|
-
* Record the build scripts a failed run reported as
|
|
1230
|
+
* Record the build scripts a failed run reported as blocked, then list every `allowBuilds` key awaiting a decision.
|
|
1113
1231
|
*
|
|
1114
1232
|
* pnpm writes those policy entries itself only when it can prompt, and the
|
|
1115
1233
|
* manager always runs it non-interactively, so the run's own report is the
|
|
1116
1234
|
* record that survives.
|
|
1117
1235
|
* @param dir Current profile directory.
|
|
1118
1236
|
* @param output Captured output of the failed run.
|
|
1119
|
-
* @returns Exact
|
|
1237
|
+
* @returns Exact `allowBuilds` keys awaiting a build decision; wildcard rules are excluded.
|
|
1120
1238
|
*/
|
|
1121
1239
|
async function recordPendingBuilds(dir, output) {
|
|
1122
1240
|
const { document, pending, keys } = await readPolicy(dir);
|
|
1123
1241
|
const known = new Set(keys);
|
|
1124
|
-
const added =
|
|
1242
|
+
const added = blockedBuildNames(output).filter((name) => !known.has(name));
|
|
1125
1243
|
if (added.length === 0) return pending;
|
|
1126
1244
|
for (const name of added) document.setIn(["allowBuilds", name], UNDECIDED_BUILD);
|
|
1127
1245
|
await writeFileAtomic(join(dir, "pnpm-workspace.yaml"), String(document), { mode: 384 });
|
|
1128
1246
|
return [...pending, ...added];
|
|
1129
1247
|
}
|
|
1130
1248
|
/**
|
|
1131
|
-
* Read the
|
|
1249
|
+
* Read the `allowBuilds` keys a pnpm run reported as ignored build scripts or as a git-hosted package it refused to prepare.
|
|
1132
1250
|
* @param output Captured output of the run.
|
|
1133
|
-
* @returns Exact
|
|
1251
|
+
* @returns Exact keys in report order; wildcard patterns and git keys carrying a credential are excluded.
|
|
1134
1252
|
*/
|
|
1135
|
-
function
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
return
|
|
1253
|
+
function blockedBuildNames(output) {
|
|
1254
|
+
const ignored = IGNORED_BUILDS.exec(output)?.[1]?.split(",") ?? [];
|
|
1255
|
+
const git = GIT_DEP_PREPARE.exec(output)?.[1];
|
|
1256
|
+
return [...ignored, ...git === void 0 ? [] : [git]].map((name) => name.trim()).filter((name) => name !== "" && !/[*?]/.test(name) && !carriesCredential(name));
|
|
1139
1257
|
}
|
|
1140
1258
|
/** Persist approval without running scripts; the caller holds the profile manifest lock.
|
|
1141
1259
|
* @param dir Current profile directory.
|
|
@@ -1228,6 +1346,150 @@ async function checkGithubConnection(spec, dir, options) {
|
|
|
1228
1346
|
}
|
|
1229
1347
|
}
|
|
1230
1348
|
//#endregion
|
|
1349
|
+
//#region lib/types/git-transport.js
|
|
1350
|
+
/** The Git transport an installation of a self-hosted repository uses, chosen by probing access before pnpm starts. */
|
|
1351
|
+
/** An HTTP(S) Git URL with an optional `git+` prefix, which pnpm clones over that transport as written. */
|
|
1352
|
+
const HTTP_GIT_URL = /^(?:git\+)?https?:\/\//i;
|
|
1353
|
+
/**
|
|
1354
|
+
* The SSH form of an HTTP(S) Git spec on a host pnpm has no transport fallback for. pnpm tries HTTPS and SSH itself
|
|
1355
|
+
* for the hosts `hosted-git-info` knows, such as GitHub and GitLab.com, and clones any other URL over the transport
|
|
1356
|
+
* it names.
|
|
1357
|
+
* @param spec The parsed installation address.
|
|
1358
|
+
* @returns `git+ssh://git@<host>/<path>` on SSH's default port with the spec's fragment, or `undefined` for a spec that
|
|
1359
|
+
* is not an HTTP(S) Git URL on such a host, or whose URL carries credentials or a query.
|
|
1360
|
+
*/
|
|
1361
|
+
function sshGitSpec(spec) {
|
|
1362
|
+
if (spec.kind !== "git" || !HTTP_GIT_URL.test(spec.spec) || hostedGitInfo.fromUrl(spec.spec) !== void 0) return void 0;
|
|
1363
|
+
const url = new URL(spec.spec.replace(/^git\+/i, ""));
|
|
1364
|
+
if (url.username !== "" || url.password !== "" || url.search !== "") return void 0;
|
|
1365
|
+
const hash = /#.*$/s.exec(spec.spec)?.[0] ?? "";
|
|
1366
|
+
return `git+ssh://git@${url.hostname}${url.pathname}${hash}`;
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Probe whether Git can read a repository with the installer's Git configuration and credential helpers. Git's
|
|
1370
|
+
* terminal and askpass prompts are disabled, `core.askPass` included because Windows drops the empty `GIT_ASKPASS`,
|
|
1371
|
+
* and on POSIX the probe has no controlling terminal, so SSH cannot ask about host keys or passphrases either.
|
|
1372
|
+
* @param repository The repository URL Git reads.
|
|
1373
|
+
* @param dir The profile directory where installation runs.
|
|
1374
|
+
* @param options The probe deadline, cancellation and environment.
|
|
1375
|
+
* @returns Whether `git ls-remote` listed the repository's HEAD.
|
|
1376
|
+
*/
|
|
1377
|
+
async function readable(repository, dir, options) {
|
|
1378
|
+
return !(await execa("git", [
|
|
1379
|
+
"-c",
|
|
1380
|
+
"core.askPass=",
|
|
1381
|
+
"ls-remote",
|
|
1382
|
+
"--exit-code",
|
|
1383
|
+
"--",
|
|
1384
|
+
repository,
|
|
1385
|
+
"HEAD"
|
|
1386
|
+
], {
|
|
1387
|
+
cwd: dir,
|
|
1388
|
+
env: {
|
|
1389
|
+
...scrubbedParentEnv(),
|
|
1390
|
+
...options.env,
|
|
1391
|
+
LC_ALL: "C",
|
|
1392
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
1393
|
+
GCM_INTERACTIVE: "never",
|
|
1394
|
+
GIT_ASKPASS: "",
|
|
1395
|
+
SSH_ASKPASS: "",
|
|
1396
|
+
SSH_ASKPASS_REQUIRE: "never"
|
|
1397
|
+
},
|
|
1398
|
+
extendEnv: false,
|
|
1399
|
+
stdin: "ignore",
|
|
1400
|
+
stdout: "ignore",
|
|
1401
|
+
stderr: "ignore",
|
|
1402
|
+
reject: false,
|
|
1403
|
+
timeout: options.timeoutMs,
|
|
1404
|
+
cancelSignal: options.signal,
|
|
1405
|
+
killDescendants: true,
|
|
1406
|
+
killSignal: "SIGKILL"
|
|
1407
|
+
})).failed;
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Choose how pnpm clones an HTTP(S) Git repository that {@link sshGitSpec} has an SSH form for: probe the spec's URL,
|
|
1411
|
+
* and when HTTP(S) cannot read it, probe the SSH form.
|
|
1412
|
+
* @param spec The parsed installation address.
|
|
1413
|
+
* @param dir The profile directory where installation runs.
|
|
1414
|
+
* @param options The deadline of each probe, cancellation and the installer's environment.
|
|
1415
|
+
* @returns The SSH form when only SSH can read the repository; otherwise the spec unchanged.
|
|
1416
|
+
*/
|
|
1417
|
+
async function chooseGitTransport(spec, dir, options) {
|
|
1418
|
+
const ssh = sshGitSpec(spec);
|
|
1419
|
+
if (ssh === void 0) return spec.spec;
|
|
1420
|
+
const strip = (value) => value.replace(/^git\+/i, "").replace(/#.*$/s, "");
|
|
1421
|
+
if (await readable(strip(spec.spec), dir, options)) return spec.spec;
|
|
1422
|
+
if (options.signal.aborted || !await readable(strip(ssh), dir, options)) return spec.spec;
|
|
1423
|
+
return ssh;
|
|
1424
|
+
}
|
|
1425
|
+
//#endregion
|
|
1426
|
+
//#region lib/types/versions.js
|
|
1427
|
+
/** Read `pnpm view` answers about a package's published versions. */
|
|
1428
|
+
/** The fields a version listing prints for the package: every version, its publication times, and its dist-tags. */
|
|
1429
|
+
const VERSION_LIST_FIELDS = [
|
|
1430
|
+
"versions",
|
|
1431
|
+
"time",
|
|
1432
|
+
"dist-tags"
|
|
1433
|
+
];
|
|
1434
|
+
/** The fields read for one version: what decides whether it can replace an installed bundle. */
|
|
1435
|
+
const VERSION_FIELDS = [
|
|
1436
|
+
"name",
|
|
1437
|
+
"version",
|
|
1438
|
+
"engines",
|
|
1439
|
+
"peerDependencies",
|
|
1440
|
+
"deprecated",
|
|
1441
|
+
"dsh"
|
|
1442
|
+
];
|
|
1443
|
+
/** A JSON object, or undefined for anything else. */
|
|
1444
|
+
function recordOf(value) {
|
|
1445
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* The published versions newer than the installed one, newest first.
|
|
1449
|
+
* @param answer - parsed `pnpm view <name> versions time dist-tags --json` output.
|
|
1450
|
+
* @param installed - the installed version.
|
|
1451
|
+
* @returns the newer versions with their publication times and dist-tags.
|
|
1452
|
+
* @throws when the answer names no versions.
|
|
1453
|
+
*/
|
|
1454
|
+
function newerVersions(answer, installed) {
|
|
1455
|
+
const fields = recordOf(answer);
|
|
1456
|
+
const listed = typeof fields?.versions === "string" ? [fields.versions] : fields?.versions;
|
|
1457
|
+
if (!Array.isArray(listed)) throw new Error("pnpm view answered no versions");
|
|
1458
|
+
const time = recordOf(fields?.time) ?? {};
|
|
1459
|
+
const tags = Object.entries(recordOf(fields?.["dist-tags"]) ?? {});
|
|
1460
|
+
return listed.filter((version) => typeof version === "string" && semver.valid(version) !== null && semver.gt(version, installed)).sort(semver.rcompare).map((version) => {
|
|
1461
|
+
const published = time[version];
|
|
1462
|
+
return {
|
|
1463
|
+
version,
|
|
1464
|
+
...typeof published === "string" ? { publishedAt: published } : {},
|
|
1465
|
+
tags: tags.filter(([, tagged]) => tagged === version).map(([tag]) => tag),
|
|
1466
|
+
prerelease: semver.prerelease(version) !== null
|
|
1467
|
+
};
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* What one exact version's manifest says, from `pnpm view <name>@<version> name version engines peerDependencies deprecated dsh --json`.
|
|
1472
|
+
* @param answer - the parsed output.
|
|
1473
|
+
* @param name - the package name, used when the answer omits it.
|
|
1474
|
+
* @param version - the version asked for, used when the answer omits it.
|
|
1475
|
+
* @returns the manifest fields compatibility reads, whether the version declares a bundle, and its deprecation message.
|
|
1476
|
+
*/
|
|
1477
|
+
function versionFacts(answer, name, version) {
|
|
1478
|
+
const fields = recordOf(answer) ?? {};
|
|
1479
|
+
const dsh = recordOf(fields.dsh);
|
|
1480
|
+
const deprecated = fields.deprecated;
|
|
1481
|
+
return {
|
|
1482
|
+
manifest: {
|
|
1483
|
+
name: typeof fields.name === "string" ? fields.name : name,
|
|
1484
|
+
version: typeof fields.version === "string" ? fields.version : version,
|
|
1485
|
+
...Object.hasOwn(fields, "engines") ? { engines: fields.engines } : {},
|
|
1486
|
+
...Object.hasOwn(fields, "peerDependencies") ? { peerDependencies: fields.peerDependencies } : {}
|
|
1487
|
+
},
|
|
1488
|
+
bundle: recordOf(dsh?.bundle) !== void 0,
|
|
1489
|
+
...typeof deprecated === "string" && deprecated !== "" ? { deprecated } : {}
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
//#endregion
|
|
1231
1493
|
//#region lib/types/index.js
|
|
1232
1494
|
/** Current-profile plugin and bundle management over shared dsh plugin operations. */
|
|
1233
1495
|
var __runInitializers = function(thisArg, initializers, value) {
|
|
@@ -1268,29 +1530,19 @@ var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializ
|
|
|
1268
1530
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
1269
1531
|
done = true;
|
|
1270
1532
|
};
|
|
1533
|
+
/** The Fetch route serving images beside bundle detail documents. */
|
|
1534
|
+
const DETAIL_FILE_PATH = "/api/plugin-manager/detail-file";
|
|
1271
1535
|
/** An http(s) URL, as pnpm's `--registry` takes it. */
|
|
1272
1536
|
const REGISTRY_URL = /^https?:\/\/\S+$/;
|
|
1273
|
-
const protectedModules = new Set([
|
|
1274
|
-
"@deepseek-ai/dsh-plugin-manager",
|
|
1275
|
-
"@deepseek-ai/cordis-plugin-loader",
|
|
1276
|
-
"@deepseek-ai/cordis-plugin-include",
|
|
1277
|
-
"@deepseek-ai/dsh-api-gateway",
|
|
1278
|
-
"@deepseek-ai/dsh-host-webserver",
|
|
1279
|
-
"@deepseek-ai/dsh-client-modules",
|
|
1280
|
-
"@deepseek-ai/dsh-client-ui-settings-plugin-inventory",
|
|
1281
|
-
"@deepseek-ai/dsh-client-ui-plugin-manager",
|
|
1282
|
-
"@deepseek-ai/dsh-host-plugin-inventory",
|
|
1283
|
-
"@deepseek-ai/dsh-typert-registry",
|
|
1284
|
-
"@deepseek-ai/dsh-api-remotes",
|
|
1285
|
-
"@deepseek-ai/dsh-api-remote-access",
|
|
1286
|
-
"@deepseek-ai/cordis-plugin-timer",
|
|
1287
|
-
"@deepseek-ai/dsh-client-connection",
|
|
1288
|
-
"@deepseek-ai/dsh-host-frontend-static",
|
|
1289
|
-
"@deepseek-ai/dsh-tools",
|
|
1290
|
-
"@deepseek-ai/dsh-hmr"
|
|
1291
|
-
]);
|
|
1292
1537
|
/** The profile files an installation writes and a failed or cancelled one restores. */
|
|
1293
1538
|
const RESTORED_FILES = ["package.json", "pnpm-lock.yaml"];
|
|
1539
|
+
/** The manifest fields an inspection reads for a registry spec. */
|
|
1540
|
+
const INSPECT_FIELDS = [
|
|
1541
|
+
"name",
|
|
1542
|
+
"version",
|
|
1543
|
+
"description",
|
|
1544
|
+
"dsh"
|
|
1545
|
+
];
|
|
1294
1546
|
/** pnpm's colour escapes, which a JSON answer may be wrapped in. */
|
|
1295
1547
|
const ANSI_SEQUENCE = /\x1b\[[0-9;]*m/g;
|
|
1296
1548
|
/** Preserve the exact observed diagnostic, including non-Error failures. */
|
|
@@ -1299,6 +1551,7 @@ function messageOf(error) {
|
|
|
1299
1551
|
}
|
|
1300
1552
|
/** An expected refusal keeps its code; anything else becomes an operation error carrying its exact diagnostic. */
|
|
1301
1553
|
function managementError(error) {
|
|
1554
|
+
if (error instanceof UnsupportedBundlePlatformError) return { code: "unsupported-platform" };
|
|
1302
1555
|
if (!(error instanceof ManagementFailure)) return {
|
|
1303
1556
|
code: "operation-error",
|
|
1304
1557
|
diagnostic: messageOf(error)
|
|
@@ -1345,6 +1598,47 @@ function refused(problem, reason) {
|
|
|
1345
1598
|
reason
|
|
1346
1599
|
};
|
|
1347
1600
|
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Why an update cannot replace a listed bundle, or what it replaces.
|
|
1603
|
+
* @param bundle The listed bundle, or undefined for a name the inventory does not list.
|
|
1604
|
+
* @param name The package name, for the refusal.
|
|
1605
|
+
* @returns The bundle, its installed version, and its registry spec; or the refusal's diagnostic.
|
|
1606
|
+
*/
|
|
1607
|
+
function updateRefusal(bundle, name) {
|
|
1608
|
+
if (bundle === void 0 || !bundle.installed || bundle.availability !== "profile" || bundle.official || bundle.source === void 0) return `${name} is not a third-party package installed in this profile`;
|
|
1609
|
+
if (bundle.readOnlyReason !== void 0) return `${bundle.name} carries plugin management and cannot be removed`;
|
|
1610
|
+
const installed = bundle.version;
|
|
1611
|
+
if (installed === void 0 || semver.valid(installed) === null) return `${bundle.name} declares no semver version`;
|
|
1612
|
+
const parsed = parsedForRegistry(bundle.source);
|
|
1613
|
+
if (parsed.kind !== "registry" || parsed.name !== bundle.name || parsed.range?.includes(":") === true) return `${bundle.name} is not installed from a registry under its own name`;
|
|
1614
|
+
return {
|
|
1615
|
+
bundle,
|
|
1616
|
+
installed,
|
|
1617
|
+
parsed
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Map items with at most `limit` calls in flight, stopping new calls once one answers `stop`.
|
|
1622
|
+
* @param items - the items, in order.
|
|
1623
|
+
* @param limit - the most calls in flight.
|
|
1624
|
+
* @param map - the call for one item.
|
|
1625
|
+
* @param stop - whether an answer ends the remaining calls.
|
|
1626
|
+
* @returns the answers of the calls that ran, in item order; items after a stop stay absent.
|
|
1627
|
+
*/
|
|
1628
|
+
async function mapConcurrent(items, limit, map, stop) {
|
|
1629
|
+
const answers = items.map(() => void 0);
|
|
1630
|
+
let next = 0;
|
|
1631
|
+
let stopped = false;
|
|
1632
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
1633
|
+
while (!stopped && next < items.length) {
|
|
1634
|
+
const index = next++;
|
|
1635
|
+
const answer = await map(items[index]);
|
|
1636
|
+
answers[index] = answer;
|
|
1637
|
+
if (stop(answer)) stopped = true;
|
|
1638
|
+
}
|
|
1639
|
+
}));
|
|
1640
|
+
return answers;
|
|
1641
|
+
}
|
|
1348
1642
|
/** The refusal `pnpm view --json` prints on stdout, `{ error: { code, message } }`, as one log line; empty for anything else. */
|
|
1349
1643
|
function printedError(printed) {
|
|
1350
1644
|
let parsed;
|
|
@@ -1364,7 +1658,7 @@ function bundleSelection(manifest) {
|
|
|
1364
1658
|
}
|
|
1365
1659
|
/**
|
|
1366
1660
|
* The package an installation spec names before pnpm runs: a registry name, a local directory's manifest name, or the
|
|
1367
|
-
* dependency saved with this git or tarball spec, compared as the plugin list shows saved specs.
|
|
1661
|
+
* dependency saved with this git or tarball spec or the SSH form of its Git URL, compared as the plugin list shows saved specs.
|
|
1368
1662
|
* @param spec The installation spec.
|
|
1369
1663
|
* @param dependencies The profile's saved dependencies.
|
|
1370
1664
|
* @param profileDir The profile directory saved local paths are relative to.
|
|
@@ -1374,7 +1668,8 @@ function specPackageName(spec, dependencies, profileDir) {
|
|
|
1374
1668
|
const parsed = parsedForRegistry(spec);
|
|
1375
1669
|
if (parsed.kind === "registry") return parsed.name;
|
|
1376
1670
|
if (parsed.kind === "path") return packageName(parsed.path);
|
|
1377
|
-
const
|
|
1671
|
+
const alternative = parsed.kind === "tarball" && parsed.path !== void 0 ? `file:${parsed.path}` : sshGitSpec(parsed);
|
|
1672
|
+
const specs = alternative === void 0 ? [spec] : [spec, alternative];
|
|
1378
1673
|
return Object.entries(dependencies).find(([dependency, saved]) => specs.includes(dependencySpec(dependency, saved, profileDir)))?.[0];
|
|
1379
1674
|
}
|
|
1380
1675
|
/** The package name a local directory declares, or `undefined` without a readable manifest. */
|
|
@@ -1399,16 +1694,46 @@ function parsedForRegistry(spec) {
|
|
|
1399
1694
|
};
|
|
1400
1695
|
}
|
|
1401
1696
|
}
|
|
1697
|
+
/** Only registry package names are retained before installation resolves its target. */
|
|
1698
|
+
function installOperationTarget(spec) {
|
|
1699
|
+
let parsed;
|
|
1700
|
+
try {
|
|
1701
|
+
parsed = parseInstallSpec(spec);
|
|
1702
|
+
} catch (_error) {
|
|
1703
|
+
return null;
|
|
1704
|
+
}
|
|
1705
|
+
return parsed.kind === "registry" ? parsed.name : null;
|
|
1706
|
+
}
|
|
1707
|
+
/** Exemption facts use canonical package identity, never the raw request or installed version. */
|
|
1708
|
+
function exemptionOperationIdentity(packageVersion, runtimeVersion) {
|
|
1709
|
+
try {
|
|
1710
|
+
validatePluginVersionExemption(packageVersion, runtimeVersion);
|
|
1711
|
+
} catch (_error) {
|
|
1712
|
+
return { target: null };
|
|
1713
|
+
}
|
|
1714
|
+
const separator = packageVersion.lastIndexOf("@");
|
|
1715
|
+
return {
|
|
1716
|
+
target: installOperationTarget(packageVersion.slice(0, separator)),
|
|
1717
|
+
version: diagnosticVersion(packageVersion.slice(separator + 1))
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
/** Unusable file metadata must not discard the rest of an operation record. */
|
|
1721
|
+
function diagnosticVersion(value) {
|
|
1722
|
+
return typeof value === "string" && value.length <= 128 ? value : void 0;
|
|
1723
|
+
}
|
|
1402
1724
|
/** Manage profile files and apply their declared reload lifecycle. */
|
|
1403
1725
|
let PluginManager = (() => {
|
|
1404
1726
|
let _classSuper = TypertRemoteService;
|
|
1405
1727
|
let _instanceExtraInitializers = [];
|
|
1728
|
+
let _readBundleDetail_decorators;
|
|
1406
1729
|
let _listVersionExemptions_decorators;
|
|
1407
1730
|
let _setVersionExemption_decorators;
|
|
1408
1731
|
let _listPlugins_decorators;
|
|
1409
1732
|
let _listBundles_decorators;
|
|
1410
1733
|
let _registries_decorators;
|
|
1411
1734
|
let _inspect_decorators;
|
|
1735
|
+
let _listVersions_decorators;
|
|
1736
|
+
let _updateBundle_decorators;
|
|
1412
1737
|
let _setPluginEnabled_decorators;
|
|
1413
1738
|
let _setBundleEnabled_decorators;
|
|
1414
1739
|
let _installBundle_decorators;
|
|
@@ -1418,18 +1743,32 @@ let PluginManager = (() => {
|
|
|
1418
1743
|
return class PluginManager extends _classSuper {
|
|
1419
1744
|
static {
|
|
1420
1745
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
1746
|
+
_readBundleDetail_decorators = [Remote];
|
|
1421
1747
|
_listVersionExemptions_decorators = [Remote];
|
|
1422
1748
|
_setVersionExemption_decorators = [Remote];
|
|
1423
1749
|
_listPlugins_decorators = [Remote];
|
|
1424
1750
|
_listBundles_decorators = [Remote];
|
|
1425
1751
|
_registries_decorators = [Remote];
|
|
1426
1752
|
_inspect_decorators = [Remote];
|
|
1753
|
+
_listVersions_decorators = [Remote];
|
|
1754
|
+
_updateBundle_decorators = [Remote];
|
|
1427
1755
|
_setPluginEnabled_decorators = [Remote];
|
|
1428
1756
|
_setBundleEnabled_decorators = [Remote];
|
|
1429
1757
|
_installBundle_decorators = [Remote];
|
|
1430
1758
|
_waitForInstall_decorators = [Remote];
|
|
1431
1759
|
_cancelInstall_decorators = [Remote];
|
|
1432
1760
|
_removeBundle_decorators = [Remote];
|
|
1761
|
+
__esDecorate(this, null, _readBundleDetail_decorators, {
|
|
1762
|
+
kind: "method",
|
|
1763
|
+
name: "readBundleDetail",
|
|
1764
|
+
static: false,
|
|
1765
|
+
private: false,
|
|
1766
|
+
access: {
|
|
1767
|
+
has: (obj) => "readBundleDetail" in obj,
|
|
1768
|
+
get: (obj) => obj.readBundleDetail
|
|
1769
|
+
},
|
|
1770
|
+
metadata: _metadata
|
|
1771
|
+
}, null, _instanceExtraInitializers);
|
|
1433
1772
|
__esDecorate(this, null, _listVersionExemptions_decorators, {
|
|
1434
1773
|
kind: "method",
|
|
1435
1774
|
name: "listVersionExemptions",
|
|
@@ -1496,6 +1835,28 @@ let PluginManager = (() => {
|
|
|
1496
1835
|
},
|
|
1497
1836
|
metadata: _metadata
|
|
1498
1837
|
}, null, _instanceExtraInitializers);
|
|
1838
|
+
__esDecorate(this, null, _listVersions_decorators, {
|
|
1839
|
+
kind: "method",
|
|
1840
|
+
name: "listVersions",
|
|
1841
|
+
static: false,
|
|
1842
|
+
private: false,
|
|
1843
|
+
access: {
|
|
1844
|
+
has: (obj) => "listVersions" in obj,
|
|
1845
|
+
get: (obj) => obj.listVersions
|
|
1846
|
+
},
|
|
1847
|
+
metadata: _metadata
|
|
1848
|
+
}, null, _instanceExtraInitializers);
|
|
1849
|
+
__esDecorate(this, null, _updateBundle_decorators, {
|
|
1850
|
+
kind: "method",
|
|
1851
|
+
name: "updateBundle",
|
|
1852
|
+
static: false,
|
|
1853
|
+
private: false,
|
|
1854
|
+
access: {
|
|
1855
|
+
has: (obj) => "updateBundle" in obj,
|
|
1856
|
+
get: (obj) => obj.updateBundle
|
|
1857
|
+
},
|
|
1858
|
+
metadata: _metadata
|
|
1859
|
+
}, null, _instanceExtraInitializers);
|
|
1499
1860
|
__esDecorate(this, null, _setPluginEnabled_decorators, {
|
|
1500
1861
|
kind: "method",
|
|
1501
1862
|
name: "setPluginEnabled",
|
|
@@ -1576,9 +1937,16 @@ let PluginManager = (() => {
|
|
|
1576
1937
|
lockWaitMs: z.number().step(1).min(0).default(12e4),
|
|
1577
1938
|
inspectTimeoutMs: z.number().step(1).min(1e3).default(2e4),
|
|
1578
1939
|
githubConnectionTimeoutMs: z.number().step(1).min(1e3).default(5e3),
|
|
1940
|
+
gitTransportTimeoutMs: z.number().step(1).min(1e3).default(5e3),
|
|
1579
1941
|
idleTimeoutMs: z.number().step(1).min(1e3).default(6e5),
|
|
1580
1942
|
registry: z.string().pattern(REGISTRY_URL),
|
|
1581
|
-
fallbackRegistries: z.array(z.string().pattern(REGISTRY_URL)).default([NPMMIRROR_REGISTRY])
|
|
1943
|
+
fallbackRegistries: z.array(z.string().pattern(REGISTRY_URL)).default([NPMMIRROR_REGISTRY]),
|
|
1944
|
+
versionListLimit: z.number().step(1).min(1).default(20),
|
|
1945
|
+
versionLookupConcurrency: z.number().step(1).min(1).default(4),
|
|
1946
|
+
detailMaxBytes: z.natural().min(1).default(1024 * 1024),
|
|
1947
|
+
detailImageMaxBytes: z.natural().min(1).default(5 * 1024 * 1024),
|
|
1948
|
+
detailFetchTimeoutMs: z.natural().min(1).max(MAX_TIMER_DELAY_MS).default(15e3),
|
|
1949
|
+
detailNpmFileSources: z.array(z.union(NPM_FILE_SOURCES)).min(1).default([...NPM_FILE_SOURCES])
|
|
1582
1950
|
});
|
|
1583
1951
|
/** Management bundles remain protected if their files become unreadable. */
|
|
1584
1952
|
managementBundles = (__runInitializers(this, _instanceExtraInitializers), /* @__PURE__ */ new Set());
|
|
@@ -1594,13 +1962,17 @@ let PluginManager = (() => {
|
|
|
1594
1962
|
lockWaitMs;
|
|
1595
1963
|
inspectTimeoutMs;
|
|
1596
1964
|
githubConnectionTimeoutMs;
|
|
1965
|
+
gitTransportTimeoutMs;
|
|
1597
1966
|
idleTimeoutMs;
|
|
1598
1967
|
pnpmCommand;
|
|
1968
|
+
versionListLimit;
|
|
1969
|
+
versionLookupConcurrency;
|
|
1599
1970
|
configuredRegistries;
|
|
1600
1971
|
ownerContext;
|
|
1601
1972
|
abort = new AbortController();
|
|
1602
1973
|
/** Installations by request id, from their call until it settles. */
|
|
1603
1974
|
installs = /* @__PURE__ */ new Map();
|
|
1975
|
+
detail;
|
|
1604
1976
|
constructor(ctx, config) {
|
|
1605
1977
|
super(ctx, "pluginManager");
|
|
1606
1978
|
this.ownerEntryId = ctx.fiber.entry?.id;
|
|
@@ -1611,16 +1983,78 @@ let PluginManager = (() => {
|
|
|
1611
1983
|
this.lockWaitMs = config.lockWaitMs;
|
|
1612
1984
|
this.inspectTimeoutMs = config.inspectTimeoutMs;
|
|
1613
1985
|
this.githubConnectionTimeoutMs = config.githubConnectionTimeoutMs;
|
|
1986
|
+
this.gitTransportTimeoutMs = config.gitTransportTimeoutMs;
|
|
1614
1987
|
this.idleTimeoutMs = config.idleTimeoutMs;
|
|
1615
1988
|
this.pnpmCommand = config.pnpmCommand;
|
|
1989
|
+
this.versionListLimit = config.versionListLimit;
|
|
1990
|
+
this.versionLookupConcurrency = config.versionLookupConcurrency;
|
|
1616
1991
|
this.configuredRegistries = {
|
|
1617
1992
|
registry: config.registry === void 0 ? null : normalizeRegistry(config.registry),
|
|
1618
1993
|
fallbackRegistries: config.fallbackRegistries.map(normalizeRegistry)
|
|
1619
1994
|
};
|
|
1995
|
+
const required = config;
|
|
1996
|
+
this.detail = {
|
|
1997
|
+
profile: this.profile,
|
|
1998
|
+
maxDocumentBytes: required.detailMaxBytes,
|
|
1999
|
+
maxImageBytes: required.detailImageMaxBytes,
|
|
2000
|
+
npmFileSources: required.detailNpmFileSources,
|
|
2001
|
+
timeoutMs: required.detailFetchTimeoutMs,
|
|
2002
|
+
lifetime: this.abort.signal
|
|
2003
|
+
};
|
|
1620
2004
|
ctx.effect(() => async () => {
|
|
1621
2005
|
this.abort.abort();
|
|
1622
2006
|
await Promise.allSettled([...this.packageOperations]);
|
|
1623
2007
|
}, "plugin-manager: package cancellation");
|
|
2008
|
+
ctx.inject(["connection"], (scope) => {
|
|
2009
|
+
scope.effect(() => scope.connection.fetch.register({
|
|
2010
|
+
path: DETAIL_FILE_PATH,
|
|
2011
|
+
methods: ["GET"],
|
|
2012
|
+
requestBody: "buffered",
|
|
2013
|
+
fetch: (request) => this.serveDetailFile(request)
|
|
2014
|
+
}), `plugin-manager: ${DETAIL_FILE_PATH}`);
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Read a bundle's long description: the Markdown file its locale `meta.detail` names in `language`, otherwise its
|
|
2019
|
+
* README. An installed bundle is read from its directory without network access; an official bundle the installation
|
|
2020
|
+
* offers before it is installed is read from the npm file CDNs at its offered version. Nothing is cached.
|
|
2021
|
+
* @param name - the bundle's package name, as `listBundles()` lists it.
|
|
2022
|
+
* @param language - the display language, such as `zh-CN`; documents fall back through its prefixes to English.
|
|
2023
|
+
* @param options - `npmFileSources` names npm file CDNs to ask first for an offered bundle, in order, such as the one
|
|
2024
|
+
* a Client measured as fastest; configured CDNs it omits follow, and CDNs that are not configured are not asked.
|
|
2025
|
+
* @returns the document with its origin and path, or `none`.
|
|
2026
|
+
* @throws {RemoteError} `plugin-manager/unknown-bundle`, `plugin-manager/invalid-language`, or
|
|
2027
|
+
* `plugin-manager/detail-unavailable`.
|
|
2028
|
+
*/
|
|
2029
|
+
async readBundleDetail(name, language, options) {
|
|
2030
|
+
return await readBundleDocument(await this.listedBundle(name), language, options?.npmFileSources ?? [], this.detail);
|
|
2031
|
+
}
|
|
2032
|
+
async listedBundle(name) {
|
|
2033
|
+
const bundle = (await this.listBundles()).find((candidate) => candidate.name === name);
|
|
2034
|
+
if (bundle === void 0) throw new RemoteError("plugin-manager/unknown-bundle", `No such bundle: ${name}`, { name });
|
|
2035
|
+
return bundle;
|
|
2036
|
+
}
|
|
2037
|
+
/**
|
|
2038
|
+
* Answer `GET ${DETAIL_FILE_PATH}?bundle=<name>&document=<path>&path=<destination>[&sources=<cdn>,...]` with one image
|
|
2039
|
+
* beside a bundle document; `sources` names npm file CDNs to ask first for an offered bundle, as `readBundleDetail` does.
|
|
2040
|
+
*/
|
|
2041
|
+
async serveDetailFile(request) {
|
|
2042
|
+
const params = new URL(request.url).searchParams;
|
|
2043
|
+
const [bundle, document, path] = [
|
|
2044
|
+
params.get("bundle"),
|
|
2045
|
+
params.get("document"),
|
|
2046
|
+
params.get("path")
|
|
2047
|
+
];
|
|
2048
|
+
const cache = "no-store";
|
|
2049
|
+
if (bundle === null || document === null || path === null) return detailImageResponse("invalid", cache);
|
|
2050
|
+
try {
|
|
2051
|
+
return detailImageResponse(await readBundleImage(await this.listedBundle(bundle), document, path, params.get("sources")?.split(",") ?? [], this.detail), cache);
|
|
2052
|
+
} catch (error) {
|
|
2053
|
+
const failure = remoteErrorOf(error);
|
|
2054
|
+
if (failure?.code === "plugin-manager/unknown-bundle") return detailImageResponse(void 0, cache);
|
|
2055
|
+
if (failure?.code === "plugin-manager/detail-unavailable") return detailImageResponse(failure.details.reason, cache);
|
|
2056
|
+
throw error;
|
|
2057
|
+
}
|
|
1624
2058
|
}
|
|
1625
2059
|
/** Read exact plugin-version exemptions saved in this profile.
|
|
1626
2060
|
* @returns Accepted package-name@version keys with the runtime versions they may run on, and any
|
|
@@ -1648,7 +2082,7 @@ let PluginManager = (() => {
|
|
|
1648
2082
|
stage: "enable",
|
|
1649
2083
|
target: packageVersion,
|
|
1650
2084
|
enabled
|
|
1651
|
-
}, "bundle");
|
|
2085
|
+
}, "bundle", exemptionOperationIdentity(packageVersion, runtimeVersion));
|
|
1652
2086
|
}
|
|
1653
2087
|
/** Read current plugins, including why a row cannot be changed through the profile patch.
|
|
1654
2088
|
* @returns Current runtime entries with persistent patch targets.
|
|
@@ -1659,7 +2093,7 @@ let PluginManager = (() => {
|
|
|
1659
2093
|
const actual = [...this.ctx.loader.entries()].find((row) => row.id === entry.entryId);
|
|
1660
2094
|
const candidates = rows.filter((row) => row.id === actual?.options.id);
|
|
1661
2095
|
const candidate = candidates[0];
|
|
1662
|
-
if (
|
|
2096
|
+
if (PROTECTED_PLUGINS.has(entry.moduleName) || entry.entryId === this.ownerEntryId) return {
|
|
1663
2097
|
...entry,
|
|
1664
2098
|
readOnlyReason: "management-required"
|
|
1665
2099
|
};
|
|
@@ -1679,6 +2113,13 @@ let PluginManager = (() => {
|
|
|
1679
2113
|
* display metadata, activation selections, whether the installation offers the bundle, and removal availability.
|
|
1680
2114
|
*/
|
|
1681
2115
|
listBundles() {
|
|
2116
|
+
return Promise.resolve(this.readBundles().map((bundle) => ({
|
|
2117
|
+
...bundle,
|
|
2118
|
+
updatable: typeof updateRefusal(bundle, bundle.name) !== "string"
|
|
2119
|
+
})));
|
|
2120
|
+
}
|
|
2121
|
+
/** The bundle inventory before update eligibility, which is derived from each listed bundle. */
|
|
2122
|
+
readBundles() {
|
|
1682
2123
|
const manifest = readProfileManifest("dsh", this.profile.dir);
|
|
1683
2124
|
const exemptions = readProfileVersionExemptions(this.profile.dir);
|
|
1684
2125
|
const selected = bundleSelection(manifest);
|
|
@@ -1710,6 +2151,13 @@ let PluginManager = (() => {
|
|
|
1710
2151
|
}
|
|
1711
2152
|
const catalogMeta = offered === void 0 ? {} : { meta: offered.meta };
|
|
1712
2153
|
if (offered !== void 0 && !installed && !shipped) {
|
|
2154
|
+
let platformError;
|
|
2155
|
+
try {
|
|
2156
|
+
assertBundlePlatform(offered.platforms, process.platform);
|
|
2157
|
+
} catch (error) {
|
|
2158
|
+
platformError = managementError(error);
|
|
2159
|
+
}
|
|
2160
|
+
const error = platformError ?? targetError ?? (enabled ? { code: "not-bundle" } : void 0);
|
|
1713
2161
|
bundles.push({
|
|
1714
2162
|
name,
|
|
1715
2163
|
official,
|
|
@@ -1719,10 +2167,11 @@ let PluginManager = (() => {
|
|
|
1719
2167
|
enabled,
|
|
1720
2168
|
installed,
|
|
1721
2169
|
optional,
|
|
2170
|
+
...platformError?.code === "unsupported-platform" ? { listedByDefault: false } : {},
|
|
1722
2171
|
removable: enabled,
|
|
1723
2172
|
rows: [],
|
|
1724
2173
|
overrides: [],
|
|
1725
|
-
...
|
|
2174
|
+
...error === void 0 ? {} : { error }
|
|
1726
2175
|
});
|
|
1727
2176
|
continue;
|
|
1728
2177
|
}
|
|
@@ -1732,6 +2181,7 @@ let PluginManager = (() => {
|
|
|
1732
2181
|
const readOnlyReason = this.protectsManager(name) ? "management-required" : void 0;
|
|
1733
2182
|
let availability = "missing";
|
|
1734
2183
|
let version;
|
|
2184
|
+
let listing = {};
|
|
1735
2185
|
try {
|
|
1736
2186
|
const info = bundleManifest(name, this.profile.dir, this.profile.installAnchor);
|
|
1737
2187
|
availability = shipped ? "installation" : "profile";
|
|
@@ -1755,14 +2205,28 @@ let PluginManager = (() => {
|
|
|
1755
2205
|
continue;
|
|
1756
2206
|
}
|
|
1757
2207
|
version = info.version;
|
|
2208
|
+
const listedByDefault = info.dsh?.bundle?.listedByDefault;
|
|
2209
|
+
if (listedByDefault !== void 0) {
|
|
2210
|
+
if (typeof listedByDefault !== "boolean") throw new Error("dsh.bundle.listedByDefault must be a boolean");
|
|
2211
|
+
listing = { listedByDefault };
|
|
2212
|
+
}
|
|
1758
2213
|
const compatibility = evaluatePluginCompatibility(info, exemptions);
|
|
1759
2214
|
if (compatibility !== void 0 && !compatibility.exempted) throw new ManagementFailure("incompatible-version", [incompatiblePlugin(compatibility)]);
|
|
1760
2215
|
const dir = resolveBundleDir("dsh", name, this.profile.installAnchor, this.profile.dir);
|
|
1761
2216
|
const meta = offered?.meta ?? readPluginMeta(info.name ?? name, pathToFileURL(join(dir, "package.json")).href);
|
|
2217
|
+
let platformError;
|
|
2218
|
+
try {
|
|
2219
|
+
assertBundlePlatform(info.dsh?.bundle?.platforms, process.platform);
|
|
2220
|
+
} catch (error) {
|
|
2221
|
+
platformError = managementError(error);
|
|
2222
|
+
}
|
|
2223
|
+
if (platformError?.code === "unsupported-platform") listing = { listedByDefault: false };
|
|
2224
|
+
const error = platformError ?? targetError;
|
|
1762
2225
|
bundles.push({
|
|
1763
2226
|
name,
|
|
1764
2227
|
official,
|
|
1765
2228
|
availability,
|
|
2229
|
+
...listing,
|
|
1766
2230
|
...target,
|
|
1767
2231
|
...version === void 0 ? {} : { version },
|
|
1768
2232
|
...info.description === void 0 || info.description === "" ? {} : { description: info.description },
|
|
@@ -1774,13 +2238,14 @@ let PluginManager = (() => {
|
|
|
1774
2238
|
removable: removable && readOnlyReason === void 0,
|
|
1775
2239
|
...readOnlyReason === void 0 ? {} : { readOnlyReason },
|
|
1776
2240
|
...this.declaredRows(name, info),
|
|
1777
|
-
...
|
|
2241
|
+
...error === void 0 ? {} : { error }
|
|
1778
2242
|
});
|
|
1779
2243
|
} catch (error) {
|
|
1780
2244
|
if (enabled || installed || optional || offered !== void 0) bundles.push({
|
|
1781
2245
|
name,
|
|
1782
2246
|
official,
|
|
1783
2247
|
availability,
|
|
2248
|
+
...listing,
|
|
1784
2249
|
...catalogMeta,
|
|
1785
2250
|
...target,
|
|
1786
2251
|
...version === void 0 ? {} : { version },
|
|
@@ -1796,7 +2261,7 @@ let PluginManager = (() => {
|
|
|
1796
2261
|
});
|
|
1797
2262
|
}
|
|
1798
2263
|
}
|
|
1799
|
-
return
|
|
2264
|
+
return bundles;
|
|
1800
2265
|
}
|
|
1801
2266
|
/** Read the registries this manager asks: the configured first one, its fallbacks in order, and what pnpm's own configuration names.
|
|
1802
2267
|
* @returns The registries in pnpm's comparison form; null is the one pnpm's own configuration names, `resolved` as pnpm reads it now.
|
|
@@ -1868,59 +2333,324 @@ let PluginManager = (() => {
|
|
|
1868
2333
|
}
|
|
1869
2334
|
case "registry": {
|
|
1870
2335
|
if (known.has(parsed.name)) return refused("already-installed", `${parsed.name} is already installed`);
|
|
1871
|
-
const
|
|
1872
|
-
const
|
|
2336
|
+
const asked = await this.askRegistries(spec.trim(), INSPECT_FIELDS, plan, parsed, signal);
|
|
2337
|
+
const registries = asked.attempts.map((attempt) => attempt.registry);
|
|
2338
|
+
if (asked.status === "refused") return {
|
|
2339
|
+
status: "refused",
|
|
2340
|
+
problem: asked.problem,
|
|
2341
|
+
reason: asked.reason,
|
|
2342
|
+
registries
|
|
2343
|
+
};
|
|
2344
|
+
const latest = Array.isArray(asked.answer) ? asked.answer.at(-1) : asked.answer;
|
|
2345
|
+
if (typeof latest !== "object" || latest === null) return {
|
|
2346
|
+
status: "refused",
|
|
2347
|
+
problem: "unknown",
|
|
2348
|
+
reason: "pnpm view answered no package",
|
|
2349
|
+
registries
|
|
2350
|
+
};
|
|
2351
|
+
const inspection = inspectionOf("registry", latest, asked.registry);
|
|
2352
|
+
const named = inspection.name === void 0 ? {
|
|
2353
|
+
...inspection,
|
|
2354
|
+
name: parsed.name
|
|
2355
|
+
} : inspection;
|
|
2356
|
+
if (!named.bundle) return {
|
|
2357
|
+
status: "refused",
|
|
2358
|
+
problem: "not-a-bundle",
|
|
2359
|
+
reason: `${named.name} declares no dsh.bundle`,
|
|
2360
|
+
registries
|
|
2361
|
+
};
|
|
2362
|
+
return named;
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
/** Read the published versions newer than an installed registry package's version, from the first registry that answers.
|
|
2367
|
+
* Official bundles follow the DSH version and are not listed.
|
|
2368
|
+
* @param name Installed profile dependency name.
|
|
2369
|
+
* @param options The registry asked first; absent, the one the package was installed from in this process, else the configured one.
|
|
2370
|
+
* @param signal Ends the lookups early.
|
|
2371
|
+
* @returns At most `versionListLimit` newer versions, newest first, with their tags, deprecation, bundle declaration,
|
|
2372
|
+
* and DSH compatibility, and the registry that answered; or why no list could be read, with every registry asked.
|
|
2373
|
+
*/
|
|
2374
|
+
async listVersions(name, options, signal) {
|
|
2375
|
+
const target = updateRefusal((await this.listBundles()).find((bundle) => bundle.name === name), name);
|
|
2376
|
+
if (typeof target === "string") return {
|
|
2377
|
+
status: "refused",
|
|
2378
|
+
problem: "not-updatable",
|
|
2379
|
+
reason: target,
|
|
2380
|
+
attempts: []
|
|
2381
|
+
};
|
|
2382
|
+
const plan = registryPlan(this.registryFor(name, options?.registry), await this.registries());
|
|
2383
|
+
const listing = await this.askRegistries(name, VERSION_LIST_FIELDS, plan, target.parsed, signal);
|
|
2384
|
+
if (listing.status === "refused") return listing;
|
|
2385
|
+
let newer;
|
|
2386
|
+
try {
|
|
2387
|
+
newer = newerVersions(listing.answer, target.installed);
|
|
2388
|
+
} catch (error) {
|
|
2389
|
+
return {
|
|
2390
|
+
status: "refused",
|
|
2391
|
+
problem: "unknown",
|
|
2392
|
+
reason: messageOf(error),
|
|
2393
|
+
attempts: listing.attempts
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
const listed = newer.slice(0, this.versionListLimit);
|
|
2397
|
+
const exemptions = readProfileVersionExemptions(this.profile.dir);
|
|
2398
|
+
const looked = await mapConcurrent(listed, this.versionLookupConcurrency, async (published) => {
|
|
2399
|
+
const spec = `${name}@${published.version}`;
|
|
2400
|
+
const answer = await this.askRegistries(spec, VERSION_FIELDS, [listing.registry], {
|
|
2401
|
+
kind: "registry",
|
|
2402
|
+
spec,
|
|
2403
|
+
name
|
|
2404
|
+
}, signal);
|
|
2405
|
+
if (answer.status === "refused") return answer;
|
|
2406
|
+
const facts = versionFacts(answer.answer, name, published.version);
|
|
2407
|
+
let compatibility;
|
|
2408
|
+
try {
|
|
2409
|
+
compatibility = evaluatePluginCompatibility(facts.manifest, exemptions);
|
|
2410
|
+
} catch (error) {
|
|
2411
|
+
return {
|
|
2412
|
+
status: "refused",
|
|
2413
|
+
problem: "unknown",
|
|
2414
|
+
reason: messageOf(error),
|
|
2415
|
+
attempts: answer.attempts
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
return {
|
|
2419
|
+
status: "read",
|
|
2420
|
+
version: {
|
|
2421
|
+
...published,
|
|
2422
|
+
bundle: facts.bundle,
|
|
2423
|
+
...facts.deprecated === void 0 ? {} : { deprecated: facts.deprecated },
|
|
2424
|
+
...compatibility === void 0 || compatibility.exempted ? {} : { incompatible: incompatiblePlugin(compatibility) }
|
|
2425
|
+
}
|
|
2426
|
+
};
|
|
2427
|
+
}, (answer) => answer.status === "refused");
|
|
2428
|
+
const versions = [];
|
|
2429
|
+
for (const answer of looked) {
|
|
2430
|
+
/* v8 ignore next -- a lookup stops the rest only by refusing, which returns below */
|
|
2431
|
+
if (answer === void 0) continue;
|
|
2432
|
+
if (answer.status === "refused") return {
|
|
2433
|
+
...answer,
|
|
2434
|
+
attempts: [...listing.attempts.slice(0, -1), ...answer.attempts]
|
|
2435
|
+
};
|
|
2436
|
+
versions.push(answer.version);
|
|
2437
|
+
}
|
|
2438
|
+
return {
|
|
2439
|
+
status: "listed",
|
|
2440
|
+
installed: target.installed,
|
|
2441
|
+
registry: listing.registry,
|
|
2442
|
+
attempts: listing.attempts,
|
|
2443
|
+
versions,
|
|
2444
|
+
omitted: newer.length - listed.length
|
|
2445
|
+
};
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Replace an installed registry bundle with a newer published version. The target is checked on the registry first:
|
|
2449
|
+
* it must exist, declare a bundle, and accept the running DSH version, or nothing changes. With HMR the installed
|
|
2450
|
+
* version is removed, so its plugins stop, and the target is installed with the same selection; when that
|
|
2451
|
+
* installation fails or is cancelled, the removed version is installed again from the registry it came from.
|
|
2452
|
+
* Without HMR the target is installed over the running version and the result reports the restart.
|
|
2453
|
+
* @param name Installed profile dependency name.
|
|
2454
|
+
* @param version Exact published version newer than the installed one.
|
|
2455
|
+
* @param options The registry asked first, as for `listVersions`, and the request id naming the progress and the
|
|
2456
|
+
* target installation's logs and cancellation.
|
|
2457
|
+
* @returns The versions, the last step that ran with its result, and the reinstallation when one ran.
|
|
2458
|
+
*/
|
|
2459
|
+
async updateBundle(name, version, options) {
|
|
2460
|
+
const requestId = options?.requestId;
|
|
2461
|
+
const announce = (step) => {
|
|
2462
|
+
if (requestId !== void 0) this.ownerContext.emit("plugin-manager/update-state", {
|
|
2463
|
+
requestId,
|
|
2464
|
+
step
|
|
2465
|
+
});
|
|
2466
|
+
};
|
|
2467
|
+
announce("checking");
|
|
2468
|
+
const target = updateRefusal((await this.listBundles()).find((item) => item.name === name), name);
|
|
2469
|
+
const from = typeof target === "string" ? "" : target.installed;
|
|
2470
|
+
const refusedBefore = (error) => ({
|
|
2471
|
+
from,
|
|
2472
|
+
to: version,
|
|
2473
|
+
step: "check",
|
|
2474
|
+
result: {
|
|
2475
|
+
changed: false,
|
|
2476
|
+
application: "failed",
|
|
2477
|
+
stage: "install",
|
|
2478
|
+
target: name,
|
|
2479
|
+
error
|
|
2480
|
+
}
|
|
2481
|
+
});
|
|
2482
|
+
if (typeof target === "string") return refusedBefore({
|
|
2483
|
+
code: "invalid-spec",
|
|
2484
|
+
diagnostic: target
|
|
2485
|
+
});
|
|
2486
|
+
const { bundle } = target;
|
|
2487
|
+
if (semver.valid(version) === null || !semver.gt(version, from)) return refusedBefore({
|
|
2488
|
+
code: "invalid-spec",
|
|
2489
|
+
diagnostic: `${version} is not a version newer than the installed ${from}`
|
|
2490
|
+
});
|
|
2491
|
+
const spec = `${name}@${version}`;
|
|
2492
|
+
const plan = registryPlan(this.registryFor(name, options?.registry), await this.registries());
|
|
2493
|
+
const checked = await this.askRegistries(spec, VERSION_FIELDS, plan, {
|
|
2494
|
+
kind: "registry",
|
|
2495
|
+
spec,
|
|
2496
|
+
name
|
|
2497
|
+
});
|
|
2498
|
+
if (checked.status === "refused") return refusedBefore({
|
|
2499
|
+
code: "operation-error",
|
|
2500
|
+
diagnostic: checked.reason
|
|
2501
|
+
});
|
|
2502
|
+
const facts = versionFacts(checked.answer, name, version);
|
|
2503
|
+
if (!facts.bundle) return refusedBefore({ code: "not-bundle" });
|
|
2504
|
+
let compatibility;
|
|
2505
|
+
try {
|
|
2506
|
+
compatibility = evaluatePluginCompatibility(facts.manifest, readProfileVersionExemptions(this.profile.dir));
|
|
2507
|
+
} catch (error) {
|
|
2508
|
+
return refusedBefore({
|
|
2509
|
+
code: "operation-error",
|
|
2510
|
+
diagnostic: messageOf(error)
|
|
2511
|
+
});
|
|
2512
|
+
}
|
|
2513
|
+
if (compatibility !== void 0 && !compatibility.exempted) return refusedBefore({
|
|
2514
|
+
code: "incompatible-version",
|
|
2515
|
+
incompatible: [incompatiblePlugin(compatibility)]
|
|
2516
|
+
});
|
|
2517
|
+
const { enabled } = bundle;
|
|
2518
|
+
const settled = (stage, target, operation) => operation.catch((error) => ({
|
|
2519
|
+
changed: false,
|
|
2520
|
+
application: "failed",
|
|
2521
|
+
stage,
|
|
2522
|
+
target,
|
|
2523
|
+
error: managementError(error)
|
|
2524
|
+
}));
|
|
2525
|
+
const installTarget = () => settled("install", spec, this.installBundle(spec, {
|
|
2526
|
+
saveExact: true,
|
|
2527
|
+
registry: checked.registry,
|
|
2528
|
+
enabled,
|
|
2529
|
+
...requestId === void 0 ? {} : { requestId }
|
|
2530
|
+
}));
|
|
2531
|
+
if (this.ownerContext.get("hmr") === void 0) {
|
|
2532
|
+
announce("installing");
|
|
2533
|
+
return {
|
|
2534
|
+
from,
|
|
2535
|
+
to: version,
|
|
2536
|
+
step: "install",
|
|
2537
|
+
result: await installTarget()
|
|
2538
|
+
};
|
|
2539
|
+
}
|
|
2540
|
+
const previousRegistry = this.installedFrom.get(name);
|
|
2541
|
+
announce("removing");
|
|
2542
|
+
const removal = await settled("remove", name, this.removeBundle(name));
|
|
2543
|
+
if (removal.application === "failed" || removal.application === "cancelled") return {
|
|
2544
|
+
from,
|
|
2545
|
+
to: version,
|
|
2546
|
+
step: "remove",
|
|
2547
|
+
result: removal
|
|
2548
|
+
};
|
|
2549
|
+
announce("installing");
|
|
2550
|
+
const result = await installTarget();
|
|
2551
|
+
if (result.application !== "failed" && result.application !== "cancelled") return {
|
|
2552
|
+
from,
|
|
2553
|
+
to: version,
|
|
2554
|
+
step: "install",
|
|
2555
|
+
result
|
|
2556
|
+
};
|
|
2557
|
+
announce("restoring");
|
|
2558
|
+
if (result.stage === "enable") await settled("remove", name, this.removeBundle(name));
|
|
2559
|
+
const previous = `${name}@${from}`;
|
|
2560
|
+
return {
|
|
2561
|
+
from,
|
|
2562
|
+
to: version,
|
|
2563
|
+
step: "install",
|
|
2564
|
+
result,
|
|
2565
|
+
restore: await settled("install", previous, this.installBundle(previous, {
|
|
2566
|
+
saveExact: true,
|
|
2567
|
+
enabled,
|
|
2568
|
+
...previousRegistry === void 0 ? {} : { registry: previousRegistry }
|
|
2569
|
+
}))
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
/**
|
|
2573
|
+
* The registry a version listing or an update asks first.
|
|
2574
|
+
* @param name The package name.
|
|
2575
|
+
* @param requested The caller's registry, when it named one.
|
|
2576
|
+
* @returns The requested registry, else the one this process last installed the package from, else undefined for the configured one.
|
|
2577
|
+
*/
|
|
2578
|
+
registryFor(name, requested) {
|
|
2579
|
+
return requested !== void 0 ? requested : this.installedFrom.get(name);
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* Ask registries in turn through `pnpm view`, moving to the next one while a failure is the registry's: unreachable,
|
|
2583
|
+
* timed out, or without the package or version, which a mirror not yet synced reports.
|
|
2584
|
+
* @param spec The registry spec viewed.
|
|
2585
|
+
* @param fields The manifest fields printed.
|
|
2586
|
+
* @param plan The registries, in order; never empty.
|
|
2587
|
+
* @param parsed The spec's form, which decides whether a failure was the registry's.
|
|
2588
|
+
* @param signal Ends the lookup; a dropped lookup is not carried to the next registry.
|
|
2589
|
+
* @returns The parsed answer and the registry that gave it, or the last refusal, with every registry asked.
|
|
2590
|
+
*/
|
|
2591
|
+
async askRegistries(spec, fields, plan, parsed, signal) {
|
|
2592
|
+
const attempts = [];
|
|
2593
|
+
for (const [index, registry] of plan.entries()) {
|
|
2594
|
+
const view = await viewProfilePackage(this.profile.dir, spec, {
|
|
2595
|
+
...this.profile.packageManager ?? { command: this.pnpmCommand },
|
|
2596
|
+
fields,
|
|
2597
|
+
timeoutMs: this.inspectTimeoutMs,
|
|
2598
|
+
...signal === void 0 ? {} : { signal },
|
|
2599
|
+
registry
|
|
2600
|
+
});
|
|
2601
|
+
const printed = view.stdout.replace(ANSI_SEQUENCE, "").trim();
|
|
2602
|
+
if (view.exitCode !== 0 || view.cause !== void 0 || view.timedOut) {
|
|
2603
|
+
const log = [
|
|
2604
|
+
view.stderr.trim(),
|
|
2605
|
+
printedError(printed),
|
|
2606
|
+
view.cause === void 0 ? "" : messageOf(view.cause)
|
|
2607
|
+
].filter(Boolean).join("\n");
|
|
2608
|
+
const kind = classifyInstallFailure({
|
|
2609
|
+
log,
|
|
2610
|
+
timedOut: view.timedOut,
|
|
2611
|
+
...view.cause === void 0 ? {} : { cause: view.cause }
|
|
2612
|
+
});
|
|
2613
|
+
const reason = view.timedOut ? `pnpm view timed out after ${String(this.inspectTimeoutMs)}ms` : log || printed || `pnpm view exited with ${String(view.exitCode)}`;
|
|
2614
|
+
const problem = kind === "not-found" || kind === "no-matching-version" ? "not-found" : kind === "network" || kind === "timeout" ? "network" : "unknown";
|
|
2615
|
+
attempts.push({
|
|
2616
|
+
registry,
|
|
2617
|
+
problem,
|
|
2618
|
+
reason
|
|
2619
|
+
});
|
|
2620
|
+
if (index < plan.length - 1 && signal?.aborted !== true && attributeFailure(kind, log, parsed) === "registry") continue;
|
|
2621
|
+
return {
|
|
1873
2622
|
status: "refused",
|
|
1874
2623
|
problem,
|
|
1875
2624
|
reason,
|
|
1876
|
-
|
|
2625
|
+
attempts
|
|
2626
|
+
};
|
|
2627
|
+
}
|
|
2628
|
+
try {
|
|
2629
|
+
const answer = JSON.parse(printed || "null");
|
|
2630
|
+
attempts.push({ registry });
|
|
2631
|
+
return {
|
|
2632
|
+
status: "answered",
|
|
2633
|
+
answer,
|
|
2634
|
+
registry,
|
|
2635
|
+
attempts
|
|
2636
|
+
};
|
|
2637
|
+
} catch (error) {
|
|
2638
|
+
const reason = `unreadable pnpm view output: ${messageOf(error)}`;
|
|
2639
|
+
attempts.push({
|
|
2640
|
+
registry,
|
|
2641
|
+
problem: "unknown",
|
|
2642
|
+
reason
|
|
1877
2643
|
});
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
registry: current
|
|
1885
|
-
});
|
|
1886
|
-
const printed = view.stdout.replace(ANSI_SEQUENCE, "").trim();
|
|
1887
|
-
if (view.exitCode !== 0 || view.cause !== void 0 || view.timedOut) {
|
|
1888
|
-
const log = [
|
|
1889
|
-
view.stderr.trim(),
|
|
1890
|
-
printedError(printed),
|
|
1891
|
-
view.cause === void 0 ? "" : messageOf(view.cause)
|
|
1892
|
-
].filter(Boolean).join("\n");
|
|
1893
|
-
const kind = classifyInstallFailure({
|
|
1894
|
-
log,
|
|
1895
|
-
timedOut: view.timedOut,
|
|
1896
|
-
...view.cause === void 0 ? {} : { cause: view.cause }
|
|
1897
|
-
});
|
|
1898
|
-
if (registries.length < plan.length && signal?.aborted !== true && attributeFailure(kind, log, parsed) === "registry") continue;
|
|
1899
|
-
const reason = view.timedOut ? `pnpm view timed out after ${String(this.inspectTimeoutMs)}ms` : log || printed || `pnpm view exited with ${String(view.exitCode)}`;
|
|
1900
|
-
if (kind === "not-found" || kind === "no-matching-version") return refusedBy("not-found", reason);
|
|
1901
|
-
if (kind === "network" || kind === "timeout") return refusedBy("network", reason);
|
|
1902
|
-
return refusedBy("unknown", reason);
|
|
1903
|
-
}
|
|
1904
|
-
let answer;
|
|
1905
|
-
try {
|
|
1906
|
-
answer = JSON.parse(printed || "null");
|
|
1907
|
-
} catch (error) {
|
|
1908
|
-
return refusedBy("unknown", `unreadable pnpm view output: ${messageOf(error)}`);
|
|
1909
|
-
}
|
|
1910
|
-
const latest = Array.isArray(answer) ? answer.at(-1) : answer;
|
|
1911
|
-
if (typeof latest !== "object" || latest === null) return refusedBy("unknown", "pnpm view answered no package");
|
|
1912
|
-
const inspection = inspectionOf("registry", latest, current);
|
|
1913
|
-
const named = inspection.name === void 0 ? {
|
|
1914
|
-
...inspection,
|
|
1915
|
-
name: parsed.name
|
|
1916
|
-
} : inspection;
|
|
1917
|
-
if (!named.bundle) return refusedBy("not-a-bundle", `${named.name} declares no dsh.bundle`);
|
|
1918
|
-
return named;
|
|
1919
|
-
}
|
|
1920
|
-
/* v8 ignore next -- the plan is never empty: every attempt returns or continues to the next */
|
|
1921
|
-
throw new Error("no registry was asked");
|
|
2644
|
+
return {
|
|
2645
|
+
status: "refused",
|
|
2646
|
+
problem: "unknown",
|
|
2647
|
+
reason,
|
|
2648
|
+
attempts
|
|
2649
|
+
};
|
|
1922
2650
|
}
|
|
1923
2651
|
}
|
|
2652
|
+
/* v8 ignore next -- the plan is never empty: every attempt returns or continues to the next */
|
|
2653
|
+
throw new Error("no registry was asked");
|
|
1924
2654
|
}
|
|
1925
2655
|
/** Persist a plugin entry's desired enablement and apply it on live profiles.
|
|
1926
2656
|
* @param id Loader entry identity returned by listPlugins.
|
|
@@ -1959,7 +2689,9 @@ let PluginManager = (() => {
|
|
|
1959
2689
|
/**
|
|
1960
2690
|
* Install a package using the same pnpm implementation as dsh plugin. GitHub
|
|
1961
2691
|
* repositories get a connection check bounded by githubConnectionTimeoutMs before pnpm starts;
|
|
1962
|
-
* only network failures or timeouts stop installation, while pnpm owns authentication and transport fallback.
|
|
2692
|
+
* only network failures or timeouts stop installation, while pnpm owns authentication and transport fallback. An
|
|
2693
|
+
* HTTP(S) Git URL on another host is installed over SSH instead when access probes bounded by gitTransportTimeoutMs
|
|
2694
|
+
* find that only SSH can read it. A run
|
|
1963
2695
|
* that fails, is cancelled, or adds a package without a bundle patch restores
|
|
1964
2696
|
* `package.json` and `pnpm-lock.yaml` as they were; downloaded files can stay.
|
|
1965
2697
|
* @param spec One package spec, including local paths relative to the invocation directory.
|
|
@@ -1998,11 +2730,14 @@ let PluginManager = (() => {
|
|
|
1998
2730
|
let version;
|
|
1999
2731
|
try {
|
|
2000
2732
|
result.registries = [];
|
|
2001
|
-
const
|
|
2733
|
+
const parsed = parsedForRegistry(spec);
|
|
2734
|
+
const signal = AbortSignal.any([this.abort.signal, control.abort.signal]);
|
|
2735
|
+
const env = this.profile.packageManager?.env === void 0 ? {} : { env: this.profile.packageManager.env };
|
|
2736
|
+
const connection = checkGithubConnection(parsed, this.profile.dir, {
|
|
2002
2737
|
timeoutMs: this.githubConnectionTimeoutMs,
|
|
2003
2738
|
outputBytes: this.outputBytes,
|
|
2004
|
-
signal
|
|
2005
|
-
...
|
|
2739
|
+
signal,
|
|
2740
|
+
...env
|
|
2006
2741
|
});
|
|
2007
2742
|
this.packageOperations.add(connection);
|
|
2008
2743
|
let connectionFailure;
|
|
@@ -2017,6 +2752,19 @@ let PluginManager = (() => {
|
|
|
2017
2752
|
result.failedAt = "spec-host";
|
|
2018
2753
|
throw new Error(connectionFailure.output);
|
|
2019
2754
|
}
|
|
2755
|
+
const transport = chooseGitTransport(parsed, this.profile.dir, {
|
|
2756
|
+
timeoutMs: this.gitTransportTimeoutMs,
|
|
2757
|
+
signal,
|
|
2758
|
+
...env
|
|
2759
|
+
});
|
|
2760
|
+
this.packageOperations.add(transport);
|
|
2761
|
+
let installSpec;
|
|
2762
|
+
try {
|
|
2763
|
+
installSpec = await transport;
|
|
2764
|
+
} finally {
|
|
2765
|
+
this.packageOperations.delete(transport);
|
|
2766
|
+
}
|
|
2767
|
+
if (stopped()) throw new InstallCancelledError();
|
|
2020
2768
|
const plan = registryPlan(options?.registry, await this.registries());
|
|
2021
2769
|
let run;
|
|
2022
2770
|
let used = null;
|
|
@@ -2032,7 +2780,7 @@ let PluginManager = (() => {
|
|
|
2032
2780
|
});
|
|
2033
2781
|
run = await this.runPnpm([
|
|
2034
2782
|
"add",
|
|
2035
|
-
|
|
2783
|
+
installSpec,
|
|
2036
2784
|
...options?.saveExact === true ? ["--save-exact"] : [],
|
|
2037
2785
|
...registryArguments(registry)
|
|
2038
2786
|
], control.abort.signal, requestId);
|
|
@@ -2044,7 +2792,7 @@ let PluginManager = (() => {
|
|
|
2044
2792
|
if (run.kind === void 0) break;
|
|
2045
2793
|
delete result.failedAt;
|
|
2046
2794
|
if (run.timedOut === true) break;
|
|
2047
|
-
const failedAt = attributeFailure(run.kind, run.output, parsedForRegistry(
|
|
2795
|
+
const failedAt = attributeFailure(run.kind, run.output, parsedForRegistry(installSpec));
|
|
2048
2796
|
if (failedAt !== "other") result.failedAt = failedAt;
|
|
2049
2797
|
if (failedAt !== "registry" || index === plan.length - 1) break;
|
|
2050
2798
|
}
|
|
@@ -2284,6 +3032,7 @@ let PluginManager = (() => {
|
|
|
2284
3032
|
const metadata = bundleManifest(name, this.profile.dir, this.profile.installAnchor);
|
|
2285
3033
|
if (metadata === void 0) throw new ManagementFailure("not-bundle");
|
|
2286
3034
|
if (enabled) {
|
|
3035
|
+
assertBundlePlatform(metadata.dsh?.bundle?.platforms, process.platform);
|
|
2287
3036
|
const compatibility = evaluatePluginCompatibility(metadata, readProfileVersionExemptions(this.profile.dir));
|
|
2288
3037
|
if (compatibility !== void 0 && !compatibility.exempted) throw new ManagementFailure("incompatible-version", [incompatiblePlugin(compatibility)]);
|
|
2289
3038
|
this.bundleRows(name);
|
|
@@ -2317,7 +3066,7 @@ let PluginManager = (() => {
|
|
|
2317
3066
|
} catch (_error) {
|
|
2318
3067
|
return false;
|
|
2319
3068
|
}
|
|
2320
|
-
const protectedBundle = rows.some((row) =>
|
|
3069
|
+
const protectedBundle = rows.some((row) => PROTECTED_PLUGINS.has(row.name) || `include:${row.id}` === this.ownerEntryId);
|
|
2321
3070
|
if (protectedBundle) this.managementBundles.add(name);
|
|
2322
3071
|
return protectedBundle;
|
|
2323
3072
|
}
|
|
@@ -2370,34 +3119,100 @@ let PluginManager = (() => {
|
|
|
2370
3119
|
restartReason: restart
|
|
2371
3120
|
};
|
|
2372
3121
|
}
|
|
2373
|
-
async change(operation, request, reason) {
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
3122
|
+
async change(operation, request, reason, identity) {
|
|
3123
|
+
const id = randomUUID();
|
|
3124
|
+
const target = identity === void 0 ? this.operationTarget(reason, request.target) : identity.target;
|
|
3125
|
+
const version = identity === void 0 ? this.operationVersion(reason, reason === "plugin" ? request.target : target) : identity.version;
|
|
3126
|
+
const facts = {
|
|
3127
|
+
id,
|
|
3128
|
+
reason,
|
|
3129
|
+
stage: request.stage,
|
|
3130
|
+
target,
|
|
3131
|
+
...version === void 0 ? {} : { version },
|
|
3132
|
+
...request.enabled === void 0 ? {} : { enabled: request.enabled }
|
|
3133
|
+
};
|
|
3134
|
+
this.reportOperation({
|
|
3135
|
+
...facts,
|
|
3136
|
+
time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3137
|
+
phase: "started"
|
|
3138
|
+
});
|
|
3139
|
+
let settled;
|
|
3140
|
+
try {
|
|
3141
|
+
settled = await withFileLock(join(this.profile.dir, "package.json"), async () => {
|
|
3142
|
+
this.abort.signal.throwIfAborted();
|
|
3143
|
+
const before = this.diskState();
|
|
3144
|
+
const result = {
|
|
3145
|
+
...request,
|
|
3146
|
+
changed: false,
|
|
3147
|
+
...this.ownerContext.get("hmr") !== void 0 ? { application: "applied" } : {
|
|
3148
|
+
application: "restart-required",
|
|
3149
|
+
restartReason: "no-hmr"
|
|
3150
|
+
}
|
|
3151
|
+
};
|
|
3152
|
+
try {
|
|
3153
|
+
const outcome = await operation(result);
|
|
3154
|
+
if (outcome !== void 0) result.application = outcome;
|
|
3155
|
+
else if (result.application === "applied" && result.restartReason !== void 0) result.application = "restart-required";
|
|
3156
|
+
} catch (error) {
|
|
3157
|
+
if (error instanceof InstallCancelledError) result.application = "cancelled";
|
|
3158
|
+
else {
|
|
3159
|
+
result.application = "failed";
|
|
3160
|
+
result.error = managementError(error);
|
|
3161
|
+
}
|
|
2394
3162
|
}
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
}
|
|
3163
|
+
if (result.application !== "restart-required") delete result.restartReason;
|
|
3164
|
+
result.changed = before !== this.diskState();
|
|
3165
|
+
this.ownerContext.emit("plugin-manager/changed", { reason });
|
|
3166
|
+
return result;
|
|
3167
|
+
}, { waitMs: this.lockWaitMs });
|
|
3168
|
+
} catch (error) {
|
|
3169
|
+
this.reportOperation({
|
|
3170
|
+
...facts,
|
|
3171
|
+
time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3172
|
+
phase: "unknown"
|
|
3173
|
+
});
|
|
3174
|
+
throw error;
|
|
3175
|
+
}
|
|
3176
|
+
const refusedVersion = reason === "install" ? settled.error?.incompatible?.find((plugin) => plugin.name === facts.target)?.version : void 0;
|
|
3177
|
+
const observedVersion = diagnosticVersion(settled.version ?? refusedVersion);
|
|
3178
|
+
this.reportOperation({
|
|
3179
|
+
...facts,
|
|
3180
|
+
time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3181
|
+
phase: "settled",
|
|
3182
|
+
stage: settled.stage,
|
|
3183
|
+
target: settled.bundle === void 0 ? facts.target : installOperationTarget(settled.bundle),
|
|
3184
|
+
application: settled.application,
|
|
3185
|
+
changed: settled.changed,
|
|
3186
|
+
...observedVersion === void 0 ? {} : { version: observedVersion },
|
|
3187
|
+
...settled.error === void 0 ? {} : { errorCode: settled.error.code },
|
|
3188
|
+
...settled.restartReason === void 0 ? {} : { restartReason: settled.restartReason }
|
|
3189
|
+
});
|
|
3190
|
+
return settled;
|
|
3191
|
+
}
|
|
3192
|
+
reportOperation(operation) {
|
|
3193
|
+
this.ownerContext.parallel("plugin-manager/operation", operation).catch((_error) => {
|
|
3194
|
+
console.error("dsh plugin-manager: operation diagnostic delivery failed");
|
|
3195
|
+
});
|
|
3196
|
+
}
|
|
3197
|
+
operationTarget(reason, target) {
|
|
3198
|
+
if (reason !== "plugin") {
|
|
3199
|
+
const name = installOperationTarget(target);
|
|
3200
|
+
return reason === "install" || name === target ? name : null;
|
|
3201
|
+
}
|
|
3202
|
+
return target.length <= 256 && [...this.ctx.loader.entries()].some((entry) => entry.id === target) ? target : null;
|
|
3203
|
+
}
|
|
3204
|
+
/** Read the request-time package version without preventing recovery from damaged metadata. */
|
|
3205
|
+
operationVersion(reason, target) {
|
|
3206
|
+
if (reason === "install" || target === null) return void 0;
|
|
3207
|
+
try {
|
|
3208
|
+
if (reason !== "plugin") return diagnosticVersion(bundleManifest(target, this.profile.dir, this.profile.installAnchor)?.version);
|
|
3209
|
+
const entry = [...this.ctx.loader.entries()].find((row) => row.id === target);
|
|
3210
|
+
const source = entry?.parent.tree.ctx.baseUrl;
|
|
3211
|
+
if (entry === void 0 || source === void 0) return void 0;
|
|
3212
|
+
return diagnosticVersion(this.ownerContext.get("pluginPackages")?.packageOf(entry.options.name, source)?.version);
|
|
3213
|
+
} catch (_error) {
|
|
3214
|
+
return;
|
|
3215
|
+
}
|
|
2401
3216
|
}
|
|
2402
3217
|
diskState() {
|
|
2403
3218
|
return [
|