@deepseek-ai/dsh-plugin-manager 0.2.2-alpha.3 → 0.2.2-rc.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.
Files changed (70) hide show
  1. package/README.i18n.yaml +4 -4
  2. package/README.md +6 -5
  3. package/README.zh.md +6 -5
  4. package/lib/index.js +255 -68
  5. package/lib/typert.host.js +84 -66
  6. package/lib/typert.remote-client.d.ts.map +1 -0
  7. package/lib/typert.remote-client.js +77 -59
  8. package/lib/types/build-approval.d.ts.map +1 -0
  9. package/lib/types/build-approval.js.map +1 -0
  10. package/lib/types/bundle-detail.d.ts.map +1 -0
  11. package/lib/types/bundle-detail.js.map +1 -0
  12. package/lib/types/diagnostic.d.ts.map +1 -0
  13. package/lib/types/diagnostic.js +1 -0
  14. package/lib/types/diagnostic.js.map +1 -0
  15. package/lib/types/failure.d.ts.map +1 -0
  16. package/lib/types/failure.js.map +1 -0
  17. package/lib/types/git-transport.d.ts.map +1 -0
  18. package/lib/types/git-transport.js.map +1 -0
  19. package/lib/types/github-connection.d.ts +16 -5
  20. package/lib/types/github-connection.d.ts.map +1 -0
  21. package/lib/types/github-connection.js +18 -8
  22. package/lib/types/github-connection.js.map +1 -0
  23. package/lib/types/index.d.ts +39 -10
  24. package/lib/types/index.d.ts.map +1 -0
  25. package/lib/types/index.js +144 -46
  26. package/lib/types/index.js.map +1 -0
  27. package/lib/types/install-failure.d.ts.map +1 -0
  28. package/lib/types/install-failure.js.map +1 -0
  29. package/lib/types/install-spec.d.ts +13 -1
  30. package/lib/types/install-spec.d.ts.map +1 -0
  31. package/lib/types/install-spec.js +41 -1
  32. package/lib/types/install-spec.js.map +1 -0
  33. package/lib/types/official-install-target.d.ts.map +1 -0
  34. package/lib/types/official-install-target.js.map +1 -0
  35. package/lib/types/operations.d.ts +16 -4
  36. package/lib/types/operations.d.ts.map +1 -0
  37. package/lib/types/operations.js +38 -5
  38. package/lib/types/operations.js.map +1 -0
  39. package/lib/types/patch.d.ts.map +1 -0
  40. package/lib/types/patch.js.map +1 -0
  41. package/lib/types/registry.d.ts.map +1 -0
  42. package/lib/types/registry.js.map +1 -0
  43. package/lib/types/run-tree.d.ts.map +1 -0
  44. package/lib/types/run-tree.js.map +1 -0
  45. package/lib/types/tools.d.ts.map +1 -0
  46. package/lib/types/tools.js +2 -1
  47. package/lib/types/tools.js.map +1 -0
  48. package/lib/types/types.d.ts +31 -5
  49. package/lib/types/types.d.ts.map +1 -0
  50. package/lib/types/types.js.map +1 -0
  51. package/lib/types/versions.d.ts.map +1 -0
  52. package/lib/types/versions.js.map +1 -0
  53. package/package.json +45 -41
  54. package/src/build-approval.ts +96 -0
  55. package/src/bundle-detail.ts +104 -0
  56. package/src/diagnostic.ts +86 -0
  57. package/src/failure.ts +29 -0
  58. package/src/git-transport.ts +72 -0
  59. package/src/github-connection.ts +102 -0
  60. package/src/index.ts +1458 -0
  61. package/src/install-failure.ts +44 -0
  62. package/src/install-spec.ts +159 -0
  63. package/src/official-install-target.ts +58 -0
  64. package/src/operations.ts +695 -0
  65. package/src/patch.ts +78 -0
  66. package/src/registry.ts +98 -0
  67. package/src/run-tree.ts +77 -0
  68. package/src/tools.ts +164 -0
  69. package/src/types.ts +477 -0
  70. package/src/versions.ts +80 -0
package/lib/index.js CHANGED
@@ -104,7 +104,8 @@ async function readBundleImage(bundle, document, destination, preferred, options
104
104
  //#region lib/types/install-spec.js
105
105
  /**
106
106
  * Reading an install spec before pnpm sees it: which of pnpm's spec forms it
107
- * takes, and for a registry name whether it is one the registry can accept.
107
+ * takes, for a registry name whether it is one the registry can accept, and
108
+ * for a Git spec pinned to a commit the repository directory it installs from.
108
109
  * @module @deepseek-ai/dsh-plugin-manager/install-spec
109
110
  */
110
111
  /** The forms pnpm resolves through a git host: a host shorthand, a git URL, or a hosted repository URL. */
@@ -204,6 +205,36 @@ function parseInstallSpec(raw) {
204
205
  range
205
206
  };
206
207
  }
208
+ /** A full SHA-1 commit name, as a fragment parameter of a Git spec. */
209
+ const FULL_COMMIT = /^[0-9a-f]{40}$/i;
210
+ /**
211
+ * Where a Git spec pinned to a full commit installs from: the lower-case host and the repository path, without
212
+ * transport, user, or `.git`, then `#` and the `path:` directory. The origin ignores the form pnpm saves, so the SSH
213
+ * form saved for an HTTPS repository it cannot read, and the host shortcut saved for a known host, have the HTTPS
214
+ * form's origin. Equal origins name one repository on a host that serves it at the same path over every transport,
215
+ * as Git forges do; on a plain SSH server, an scp-like path is relative to the login's home directory.
216
+ * @param spec - an install spec, such as a saved dependency or an update's target.
217
+ * @returns the origin, or undefined for a spec that is not Git, or whose fragment is not one full commit and at most
218
+ * one `path:` directory.
219
+ */
220
+ function pinnedGitOrigin(spec) {
221
+ let parsed;
222
+ try {
223
+ parsed = parseInstallSpec(spec);
224
+ } catch (error) {
225
+ /* v8 ignore next -- parseInstallSpec throws nothing but its own refusal */
226
+ if (!(error instanceof InvalidInstallSpecError)) throw error;
227
+ return;
228
+ }
229
+ const hash = parsed.spec.indexOf("#");
230
+ if (parsed.kind !== "git" || hash === -1) return void 0;
231
+ const parameters = parsed.spec.slice(hash + 1).split("&");
232
+ const paths = parameters.filter((part) => part.startsWith("path:"));
233
+ const others = parameters.filter((part) => !part.startsWith("path:"));
234
+ if (paths.length > 1 || others.length !== 1 || !FULL_COMMIT.test(others.join(""))) return void 0;
235
+ const path = (paths[0]?.slice(5) ?? "").replace(/^\/+|\/+$/g, "");
236
+ return `${parsed.spec.slice(0, hash).replace(/^(github|gitlab|bitbucket|gist):/i, (_prefix, shorthand) => `${GIT_SHORTHAND_HOSTS[shorthand.toLowerCase()]}/`).replace(/^git\+/i, "").replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").replace(/^[^@/]+@/, "").replace(/^([^/:]+):(?!\d)/, "$1/").replace(/\/+$/, "").replace(/\.git$/i, "").replace(/^[^/]+/, (host) => host.toLowerCase())}#${path}`;
237
+ }
207
238
  /** A recorded dependency value pnpm resolves outside a registry: a protocol other than a registry alias, or an scp-like git address. */
208
239
  const NON_REGISTRY_VALUE = /^(?!(?:npm|jsr|workspace|catalog):)[a-z][a-z0-9+.-]*:|^[^@/:\s]+@[^:/\s]+:/i;
209
240
  /** The user information of an http(s) URL, up to the last `@` before the path, which holds a password or access token when present. */
@@ -610,16 +641,19 @@ function bundleComponentManifests(manifest, dir, anchor) {
610
641
  });
611
642
  }
612
643
  /** Execute pnpm inside a profile whose caller already holds the profile write lock.
613
- * Newly installed or updated direct dependencies are checked even when activation is disabled;
614
- * an untouched dependency never blocks an unrelated operation and stays denied at startup.
615
- * Compatibility denial restores the profile manifest and lockfile, but leaves downloaded modules on disk.
644
+ * Newly installed or updated direct dependencies are checked even when activation is disabled. With `expected`, each
645
+ * of them must be the expected package, which must be installed at its version with a bundle declaration. Any other
646
+ * untouched dependency never blocks an unrelated operation and stays denied at startup.
647
+ * A denial before pnpm runs changes nothing; one after it restores the profile manifest and lockfile and reinstalls
648
+ * the restored lockfile, while downloaded files stay in the pnpm store.
616
649
  * @param context Launcher-owned profile and resolution locations.
617
650
  * @param args Pnpm arguments, before relative path anchoring.
618
651
  * @param options Output, activation and cancellation policy.
619
652
  * @returns Exit status, whether the silence bound stopped the run, and the diagnostic path.
620
- * A compatibility denial returns exit code 1. Service output is bounded; CLI output uses inherited descriptors.
653
+ * A compatibility or `expected` denial returns exit code 1 and names what it refused.
621
654
  * Unsupported Host activation returns exit code 1 with named diagnostics; installed dependencies remain,
622
655
  * and no bundle selection changes are saved. Other reconciliation or filesystem errors reject.
656
+ * Service output is bounded; CLI output uses inherited descriptors.
623
657
  * The diagnostic file is closed on return or rejection, including preparation and spawn failures.
624
658
  */
625
659
  async function runProfilePnpm(context, args, options) {
@@ -676,6 +710,14 @@ async function runProfilePnpm(context, args, options) {
676
710
  };
677
711
  /** Packages a compatibility check refused; callers render them for their own surface. */
678
712
  const incompatible = [];
713
+ /** Why the post-install check undoes a successful run. */
714
+ const warnings = [];
715
+ /** What `options.expected` found wrong with the run, `unexpected-package` taking precedence. */
716
+ let unmet;
717
+ const fail = (code, warning) => {
718
+ if (unmet !== "unexpected-package") unmet = code;
719
+ warnings.push(warning);
720
+ };
679
721
  const rejected = async (warnings, restoration) => {
680
722
  const diagnostic = `\ndsh: installation rejected: ${warnings.join("\n")}\ndsh: ${restoration}.\n`;
681
723
  await log.write(diagnostic);
@@ -808,7 +850,8 @@ async function runProfilePnpm(context, args, options) {
808
850
  }
809
851
  if (exitCode === 0 && !control.stalled) {
810
852
  const after = readProfileManifest("dsh", dir);
811
- const warnings = [];
853
+ const { expected } = options;
854
+ let seen = false;
812
855
  for (const [name, spec] of Object.entries(directDependencies(after))) {
813
856
  const packageDir = join(dir, "node_modules", name);
814
857
  const installed = optionalFile(join(packageDir, "package.json"));
@@ -818,6 +861,14 @@ async function runProfilePnpm(context, args, options) {
818
861
  const issues = [];
819
862
  try {
820
863
  const manifest = readProfileManifest("dsh", packageDir);
864
+ const installedAs = `${name}@${String(manifest.version)}`;
865
+ const wanted = expected === void 0 ? void 0 : `${expected.name}@${expected.version}`;
866
+ if (name === expected?.name) {
867
+ seen = true;
868
+ if (installedAs !== wanted) fail("unexpected-package", `${installedAs} is installed where ${String(wanted)} was expected`);
869
+ else if (manifest.dsh?.bundle === void 0) fail("not-bundle", `${installedAs} declares no bundle`);
870
+ else for (const file of bundlePatchPaths(packageDir, manifest.dsh.bundle)) loadOverlayPatches("dsh", file);
871
+ } else if (wanted !== void 0 && !untouched) fail("unexpected-package", `${installedAs} is installed where ${wanted} was expected`);
821
872
  for (const candidate of [manifest, ...bundleComponentManifests(manifest, packageDir, context.installAnchor)]) {
822
873
  const issue = evaluatePluginCompatibility(candidate, readProfileVersionExemptions(dir));
823
874
  if (issue !== void 0 && !issue.exempted) {
@@ -838,6 +889,7 @@ async function runProfilePnpm(context, args, options) {
838
889
  options.onOutput?.(notice, "stderr");
839
890
  }
840
891
  }
892
+ if (expected !== void 0 && !seen) fail("unexpected-package", `${expected.name}@${expected.version} is not installed`);
841
893
  if (warnings.length > 0) {
842
894
  await restore();
843
895
  const repair = ["install", savedFiles.some((file) => file.path.endsWith("pnpm-lock.yaml") && file.text !== void 0) ? "--frozen-lockfile" : "--config.lockfile=false"];
@@ -883,7 +935,8 @@ async function runProfilePnpm(context, args, options) {
883
935
  truncated,
884
936
  logPath,
885
937
  ...control.stalled ? { timedOut: true } : {},
886
- ...incompatible.length > 0 ? { incompatible } : {}
938
+ ...incompatible.length > 0 ? { incompatible } : {},
939
+ ...unmet === void 0 ? {} : { unmet }
887
940
  };
888
941
  } catch (e_1) {
889
942
  env_1.error = e_1;
@@ -1270,22 +1323,33 @@ async function approveBuilds(dir, names) {
1270
1323
  }
1271
1324
  //#endregion
1272
1325
  //#region lib/types/github-connection.js
1273
- /** Bounded GitHub repository checks using the installer's Git configuration and environment. */
1326
+ /** Bounded Git repository connection checks using the installer's Git configuration and environment. */
1274
1327
  /**
1275
1328
  * Check a GitHub repository before pnpm starts, without downloading or building its package.
1276
- * Git reads the profile's Git and proxy configuration without invoking credential helpers or prompting.
1277
- * Timeout and cancellation terminate its descendants too; pnpm owns authentication and transport fallback.
1278
1329
  * @param spec The parsed installation address; npm packages, local paths and other hosts are not checked.
1279
1330
  * @param dir The profile directory where installation runs.
1280
1331
  * @param options The connection deadline, output bound and operation cancellation.
1281
- * @returns A failed check carrying the command line it ran (without URL user information) and its bounded output, with a
1282
- * complete log at logPath, or undefined for a reachable repository or an unhandled spec.
1332
+ * @returns As {@link checkGitConnection}, or undefined for a spec that does not name a GitHub repository.
1283
1333
  */
1284
1334
  async function checkGithubConnection(spec, dir, options) {
1285
1335
  if (spec.kind !== "git") return void 0;
1286
1336
  const host = spec.host.toLowerCase().replace(/:.*$/, "");
1287
1337
  if (host !== "github.com" && !host.endsWith(".github.com")) return void 0;
1288
- const repository = spec.spec.replace(/#.*$/s, "").replace(/^github:/i, "https://github.com/").replace(/^gist:/i, "https://gist.github.com/").replace(/^git\+/i, "");
1338
+ return checkGitConnection(spec, dir, options);
1339
+ }
1340
+ /**
1341
+ * Check a Git repository with `git ls-remote`, without downloading or building its package. A host shorthand is read
1342
+ * over HTTPS; any other spec over the URL it names. Git reads the profile's Git and proxy configuration without
1343
+ * invoking credential helpers or prompting, so a repository that needs credentials fails as `unknown`, not as a
1344
+ * connection failure. Timeout and cancellation terminate its descendants too.
1345
+ * @param spec The parsed address of a Git repository.
1346
+ * @param dir The profile directory where installation runs.
1347
+ * @param options The connection deadline, output bound and operation cancellation.
1348
+ * @returns A failed check carrying the command line it ran (without URL user information), its bounded output and its
1349
+ * failure kind, with a complete log at logPath, or undefined for a reachable repository.
1350
+ */
1351
+ async function checkGitConnection(spec, dir, options) {
1352
+ const repository = spec.spec.replace(/#.*$/s, "").replace(/^(?:github|gitlab|bitbucket|gist):/i, `https://${spec.host}/`).replace(/^git\+/i, "");
1289
1353
  const logRoot = join(dir, ".plugin-manager", "logs");
1290
1354
  await mkdir(logRoot, {
1291
1355
  recursive: true,
@@ -1332,7 +1396,7 @@ async function checkGithubConnection(spec, dir, options) {
1332
1396
  });
1333
1397
  if (!result.failed) return void 0;
1334
1398
  if (result.timedOut) await log.write(`dsh: connection to ${spec.host} timed out after ${String(options.timeoutMs)}ms\n`);
1335
- if ((await log.stat()).size === 0) await log.write(result.shortMessage ?? "GitHub connection check failed");
1399
+ if ((await log.stat()).size === 0) await log.write(result.shortMessage ?? "Git connection check failed");
1336
1400
  const { size } = await log.stat();
1337
1401
  const bytes = Buffer.alloc(Math.min(size, options.outputBytes));
1338
1402
  await log.read(bytes, 0, bytes.length, size - bytes.length);
@@ -1610,16 +1674,25 @@ function refused(problem, reason) {
1610
1674
  * Why an update cannot replace a listed bundle, or what it replaces.
1611
1675
  * @param bundle The listed bundle, or undefined for a name the inventory does not list.
1612
1676
  * @param name The package name, for the refusal.
1613
- * @returns The bundle, its installed version, and its registry spec; or the refusal's diagnostic.
1677
+ * @returns The bundle, its installed version, and how it was installed; or the refusal's diagnostic.
1614
1678
  */
1615
1679
  function updateRefusal(bundle, name) {
1616
1680
  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`;
1617
1681
  if (bundle.readOnlyReason !== void 0) return `${bundle.name} carries plugin management and cannot be removed`;
1618
1682
  const installed = bundle.version;
1619
1683
  if (installed === void 0 || semver.valid(installed) === null) return `${bundle.name} declares no semver version`;
1684
+ const origin = pinnedGitOrigin(bundle.source);
1685
+ if (origin !== void 0) return {
1686
+ kind: "git",
1687
+ bundle,
1688
+ installed,
1689
+ source: bundle.source,
1690
+ origin
1691
+ };
1620
1692
  const parsed = parsedForRegistry(bundle.source);
1621
- 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`;
1693
+ if (parsed.kind !== "registry" || parsed.name !== bundle.name || parsed.range?.includes(":") === true) return `${bundle.name} is installed neither from a registry under its own name nor from a Git commit`;
1622
1694
  return {
1695
+ kind: "registry",
1623
1696
  bundle,
1624
1697
  installed,
1625
1698
  parsed
@@ -2121,10 +2194,13 @@ let PluginManager = (() => {
2121
2194
  * display metadata, activation selections, whether the installation offers the bundle, and removal availability.
2122
2195
  */
2123
2196
  listBundles() {
2124
- return Promise.resolve(this.readBundles().map((bundle) => ({
2125
- ...bundle,
2126
- updatable: typeof updateRefusal(bundle, bundle.name) !== "string"
2127
- })));
2197
+ return Promise.resolve(this.readBundles().map((bundle) => {
2198
+ const target = updateRefusal(bundle, bundle.name);
2199
+ return typeof target === "string" ? bundle : {
2200
+ ...bundle,
2201
+ update: target.kind
2202
+ };
2203
+ }));
2128
2204
  }
2129
2205
  /** The bundle inventory before update eligibility, which is derived from each listed bundle. */
2130
2206
  readBundles() {
@@ -2175,7 +2251,6 @@ let PluginManager = (() => {
2175
2251
  enabled,
2176
2252
  installed,
2177
2253
  optional,
2178
- ...offered.listedByDefault === void 0 ? {} : { listedByDefault: offered.listedByDefault },
2179
2254
  ...platformError?.code === "unsupported-platform" ? { listedByDefault: false } : {},
2180
2255
  removable: enabled,
2181
2256
  rows: [],
@@ -2215,14 +2290,16 @@ let PluginManager = (() => {
2215
2290
  }
2216
2291
  version = info.version;
2217
2292
  const listedByDefault = info.dsh?.bundle?.listedByDefault;
2218
- if (listedByDefault !== void 0) {
2219
- if (typeof listedByDefault !== "boolean") throw new Error("dsh.bundle.listedByDefault must be a boolean");
2220
- listing = { listedByDefault };
2221
- }
2293
+ const listingDiagnostic = listedByDefault === void 0 || typeof listedByDefault === "boolean" ? void 0 : "dsh.bundle.listedByDefault must be a boolean";
2294
+ if (typeof listedByDefault === "boolean") listing = { listedByDefault };
2222
2295
  const compatibility = evaluatePluginCompatibility(info, exemptions);
2223
2296
  if (compatibility !== void 0 && !compatibility.exempted) throw new ManagementFailure("incompatible-version", [incompatiblePlugin(compatibility)]);
2224
2297
  const dir = resolveBundleDir("dsh", name, this.profile.installAnchor, this.profile.dir);
2225
- const meta = offered?.meta ?? readPluginMeta(info.name ?? name, pathToFileURL(join(dir, "package.json")).href);
2298
+ const read = offered?.meta ?? readPluginMeta(info.name ?? name, pathToFileURL(join(dir, "package.json")).href);
2299
+ const meta = listingDiagnostic === void 0 ? read : {
2300
+ ...read,
2301
+ error: read?.error === void 0 ? listingDiagnostic : `${read.error}; ${listingDiagnostic}`
2302
+ };
2226
2303
  let platformError;
2227
2304
  try {
2228
2305
  assertBundlePlatform(info.dsh?.bundle?.platforms, process.platform);
@@ -2388,6 +2465,12 @@ let PluginManager = (() => {
2388
2465
  reason: target,
2389
2466
  attempts: []
2390
2467
  };
2468
+ if (target.kind === "git") return {
2469
+ status: "refused",
2470
+ problem: "not-updatable",
2471
+ reason: `${name} is installed from Git, which lists no versions`,
2472
+ attempts: []
2473
+ };
2391
2474
  const plan = registryPlan(this.registryFor(name, options?.registry), await this.registries());
2392
2475
  const listing = await this.askRegistries(name, VERSION_LIST_FIELDS, plan, target.parsed, signal);
2393
2476
  if (listing.status === "refused") return listing;
@@ -2454,15 +2537,21 @@ let PluginManager = (() => {
2454
2537
  };
2455
2538
  }
2456
2539
  /**
2457
- * Replace an installed registry bundle with a newer published version. The target is checked on the registry first:
2458
- * it must exist, declare a bundle, and accept the running DSH version, or nothing changes. With HMR the installed
2459
- * version is removed, so its plugins stop, and the target is installed with the same selection; when that
2460
- * installation fails or is cancelled, the removed version is installed again from the registry it came from.
2461
- * Without HMR the target is installed over the running version and the result reports the restart.
2540
+ * Replace an installed bundle with a newer version. A registry copy updates to `name@version`, checked on the registry
2541
+ * first: it must exist, declare a bundle, and accept the running DSH version, or nothing changes. A Git copy updates
2542
+ * to the Git spec `options.spec` names, which must pin a full commit of the repository directory the copy came from;
2543
+ * with HMR, a network failure or timeout reaching its repository stops the update before anything changes. pnpm reads
2544
+ * a Git package only while installing it, so its bundle and compatibility are checked then. Either target
2545
+ * installation is undone, profile files and modules included, before its bundle loads unless it installs `name` at
2546
+ * `version`. With HMR the installed version is removed, so its plugins stop, and the target is installed with the same
2547
+ * selection; when that installation fails or is cancelled, the removed version is installed again: a registry copy
2548
+ * from the registry it came from, a Git copy from its saved spec. Without HMR the target is installed over the running
2549
+ * version and the result reports the restart.
2462
2550
  * @param name Installed profile dependency name.
2463
- * @param version Exact published version newer than the installed one.
2464
- * @param options The registry asked first, as for `listVersions`, and the request id naming the progress and the
2465
- * target installation's logs and cancellation.
2551
+ * @param version Exact version newer than the installed one.
2552
+ * @param options The registry asked first, as for `listVersions`; the Git spec of `version`, required for and accepted
2553
+ * only by a bundle `listBundles` lists with `update: 'git'`; and the request id naming the progress and the target
2554
+ * installation's logs and cancellation.
2466
2555
  * @returns The versions, the last step that ran with its result, and the reinstallation when one ran.
2467
2556
  */
2468
2557
  async updateBundle(name, version, options) {
@@ -2497,32 +2586,9 @@ let PluginManager = (() => {
2497
2586
  code: "invalid-spec",
2498
2587
  diagnostic: `${version} is not a version newer than the installed ${from}`
2499
2588
  });
2500
- const spec = `${name}@${version}`;
2501
- const plan = registryPlan(this.registryFor(name, options?.registry), await this.registries());
2502
- const checked = await this.askRegistries(spec, VERSION_FIELDS, plan, {
2503
- kind: "registry",
2504
- spec,
2505
- name
2506
- });
2507
- if (checked.status === "refused") return refusedBefore({
2508
- code: "operation-error",
2509
- diagnostic: checked.reason
2510
- });
2511
- const facts = versionFacts(checked.answer, name, version);
2512
- if (!facts.bundle) return refusedBefore({ code: "not-bundle" });
2513
- let compatibility;
2514
- try {
2515
- compatibility = evaluatePluginCompatibility(facts.manifest, readProfileVersionExemptions(this.profile.dir));
2516
- } catch (error) {
2517
- return refusedBefore({
2518
- code: "operation-error",
2519
- diagnostic: messageOf(error)
2520
- });
2521
- }
2522
- if (compatibility !== void 0 && !compatibility.exempted) return refusedBefore({
2523
- code: "incompatible-version",
2524
- incompatible: [incompatiblePlugin(compatibility)]
2525
- });
2589
+ const planned = target.kind === "git" ? this.planGitUpdate(name, target.origin, options) : await this.checkRegistryUpdate(name, version, options);
2590
+ if ("code" in planned) return refusedBefore(planned);
2591
+ const { spec, registry, saveExact } = planned;
2526
2592
  const { enabled } = bundle;
2527
2593
  const settled = (stage, target, operation) => operation.catch((error) => ({
2528
2594
  changed: false,
@@ -2532,9 +2598,13 @@ let PluginManager = (() => {
2532
2598
  error: managementError(error)
2533
2599
  }));
2534
2600
  const installTarget = () => settled("install", spec, this.installBundle(spec, {
2535
- saveExact: true,
2536
- registry: checked.registry,
2601
+ saveExact,
2537
2602
  enabled,
2603
+ expected: {
2604
+ name,
2605
+ version
2606
+ },
2607
+ ...registry === void 0 ? {} : { registry },
2538
2608
  ...requestId === void 0 ? {} : { requestId }
2539
2609
  }));
2540
2610
  if (this.ownerContext.get("hmr") === void 0) {
@@ -2546,6 +2616,24 @@ let PluginManager = (() => {
2546
2616
  result: await installTarget()
2547
2617
  };
2548
2618
  }
2619
+ const unreachable = target.kind === "git" ? await this.gitHostUnreachable(spec) : void 0;
2620
+ if (unreachable !== void 0) return {
2621
+ from,
2622
+ to: version,
2623
+ step: "check",
2624
+ result: {
2625
+ changed: false,
2626
+ application: "failed",
2627
+ stage: "install",
2628
+ target: name,
2629
+ failedAt: "spec-host",
2630
+ packageResult: unreachable,
2631
+ error: {
2632
+ code: "operation-error",
2633
+ diagnostic: unreachable.output
2634
+ }
2635
+ }
2636
+ };
2549
2637
  const previousRegistry = this.installedFrom.get(name);
2550
2638
  announce("removing");
2551
2639
  const removal = await settled("remove", name, this.removeBundle(name));
@@ -2565,20 +2653,117 @@ let PluginManager = (() => {
2565
2653
  };
2566
2654
  announce("restoring");
2567
2655
  if (result.stage === "enable") await settled("remove", name, this.removeBundle(name));
2568
- const previous = `${name}@${from}`;
2656
+ const previous = target.kind === "git" ? target.source : `${name}@${from}`;
2569
2657
  return {
2570
2658
  from,
2571
2659
  to: version,
2572
2660
  step: "install",
2573
2661
  result,
2574
2662
  restore: await settled("install", previous, this.installBundle(previous, {
2575
- saveExact: true,
2663
+ saveExact,
2576
2664
  enabled,
2577
2665
  ...previousRegistry === void 0 ? {} : { registry: previousRegistry }
2578
2666
  }))
2579
2667
  };
2580
2668
  }
2581
2669
  /**
2670
+ * The target of a Git copy's update: the caller's Git spec, pinned to a full commit of the copy's repository directory.
2671
+ * @param name The package name.
2672
+ * @param origin The repository directory the installed copy pins.
2673
+ * @param options The caller's spec and registry.
2674
+ * @returns The spec and the registry its dependencies are asked from first, or why the update is refused.
2675
+ */
2676
+ planGitUpdate(name, origin, options) {
2677
+ const spec = options?.spec;
2678
+ const pinned = spec === void 0 ? void 0 : pinnedGitOrigin(spec);
2679
+ if (spec === void 0 || pinned === void 0) return {
2680
+ code: "invalid-spec",
2681
+ diagnostic: `${name} is installed from Git and updates only to a Git spec pinned to a full commit`
2682
+ };
2683
+ if (pinned !== origin) return {
2684
+ code: "invalid-spec",
2685
+ diagnostic: `${spec} is not in the repository directory ${name} is installed from, ${origin}`
2686
+ };
2687
+ return {
2688
+ spec,
2689
+ registry: this.registryFor(name, options?.registry),
2690
+ saveExact: false
2691
+ };
2692
+ }
2693
+ /**
2694
+ * Check that the network reaches the repository of a Git update's target. Only a network failure or a timeout
2695
+ * counts: a check Git cannot run, or one the repository refuses without credentials, leaves the answer to pnpm.
2696
+ * @param spec The target's pinned Git spec.
2697
+ * @returns The failed check, or undefined when the host answered or the check could not tell.
2698
+ */
2699
+ async gitHostUnreachable(spec) {
2700
+ const parsed = parseInstallSpec(spec);
2701
+ /* v8 ignore next -- planGitUpdate accepts only a pinned Git spec */
2702
+ if (parsed.kind !== "git") return void 0;
2703
+ const env = this.profile.packageManager?.env === void 0 ? {} : { env: this.profile.packageManager.env };
2704
+ const check = checkGitConnection(parsed, this.profile.dir, {
2705
+ timeoutMs: this.githubConnectionTimeoutMs,
2706
+ outputBytes: this.outputBytes,
2707
+ signal: this.abort.signal,
2708
+ ...env
2709
+ });
2710
+ this.packageOperations.add(check);
2711
+ let failure;
2712
+ try {
2713
+ failure = await check;
2714
+ } finally {
2715
+ this.packageOperations.delete(check);
2716
+ }
2717
+ this.abort.signal.throwIfAborted();
2718
+ if (failure?.kind !== "network" && failure?.kind !== "timeout") return void 0;
2719
+ const { argv: _argv, ...packageResult } = failure;
2720
+ return packageResult;
2721
+ }
2722
+ /**
2723
+ * Check a registry copy's update target on the registry plan before anything changes.
2724
+ * @param name The package name.
2725
+ * @param version The target version.
2726
+ * @param options The caller's registry, as for `listVersions`; a spec is refused.
2727
+ * @returns The exact spec and the registry that answered for it, or why the target cannot replace the bundle.
2728
+ */
2729
+ async checkRegistryUpdate(name, version, options) {
2730
+ const spec = `${name}@${version}`;
2731
+ if (options?.spec !== void 0) return {
2732
+ code: "invalid-spec",
2733
+ diagnostic: `${name} is installed from a registry and updates only to ${spec}`
2734
+ };
2735
+ const plan = registryPlan(this.registryFor(name, options?.registry), await this.registries());
2736
+ const checked = await this.askRegistries(spec, VERSION_FIELDS, plan, {
2737
+ kind: "registry",
2738
+ spec,
2739
+ name
2740
+ });
2741
+ if (checked.status === "refused") return {
2742
+ code: "operation-error",
2743
+ diagnostic: checked.reason
2744
+ };
2745
+ const facts = versionFacts(checked.answer, name, version);
2746
+ if (!facts.bundle) return { code: "not-bundle" };
2747
+ let compatibility;
2748
+ try {
2749
+ compatibility = evaluatePluginCompatibility(facts.manifest, readProfileVersionExemptions(this.profile.dir));
2750
+ } catch (error) {
2751
+ return {
2752
+ code: "operation-error",
2753
+ diagnostic: messageOf(error)
2754
+ };
2755
+ }
2756
+ if (compatibility !== void 0 && !compatibility.exempted) return {
2757
+ code: "incompatible-version",
2758
+ incompatible: [incompatiblePlugin(compatibility)]
2759
+ };
2760
+ return {
2761
+ spec,
2762
+ registry: checked.registry,
2763
+ saveExact: true
2764
+ };
2765
+ }
2766
+ /**
2582
2767
  * The registry a version listing or an update asks first.
2583
2768
  * @param name The package name.
2584
2769
  * @param requested The caller's registry, when it named one.
@@ -2803,10 +2988,11 @@ let PluginManager = (() => {
2803
2988
  installSpec,
2804
2989
  ...options?.saveExact === true ? ["--save-exact"] : [],
2805
2990
  ...registryArguments(registry)
2806
- ], control.abort.signal, requestId);
2991
+ ], control.abort.signal, requestId, options?.expected);
2807
2992
  result.packageResult = run;
2808
2993
  if (stopped()) throw new InstallCancelledError();
2809
2994
  if (run.incompatible !== void 0) throw new ManagementFailure("incompatible-version", run.incompatible);
2995
+ if (run.unmet !== void 0) throw new ManagementFailure(run.unmet);
2810
2996
  if (run.exitCode === 0 && run.timedOut !== true) break;
2811
2997
  /* v8 ignore next 2 -- runPnpm classifies every run it does not report as succeeded */
2812
2998
  if (run.kind === void 0) break;
@@ -2968,8 +3154,8 @@ let PluginManager = (() => {
2968
3154
  overrides: [...new Set(patches.flatMap((item) => item.insert === void 0 && typeof item.id === "string" && !declared.has(item.id) ? [item.id] : []))]
2969
3155
  };
2970
3156
  }
2971
- /** Run one pnpm command in the profile, streaming its output as install-log chunks. */
2972
- async runPnpm(args, signal, requestId) {
3157
+ /** Run one pnpm command in the profile, streaming its output as install-log chunks; `expected` is the package an `add` must install. */
3158
+ async runPnpm(args, signal, requestId, expected) {
2973
3159
  const jobId = randomUUID();
2974
3160
  const argv = ["pnpm", ...args];
2975
3161
  const cwd = this.profile.dir;
@@ -2985,6 +3171,7 @@ let PluginManager = (() => {
2985
3171
  activateNewBundles: false,
2986
3172
  idleTimeoutMs: this.idleTimeoutMs,
2987
3173
  lookupTimeoutMs: this.inspectTimeoutMs,
3174
+ ...expected === void 0 ? {} : { expected },
2988
3175
  onOutput: (text, stream) => {
2989
3176
  this.ownerContext.emit("plugin-manager/install-log", {
2990
3177
  ...identity,
@@ -3252,4 +3439,4 @@ let PluginManager = (() => {
3252
3439
  };
3253
3440
  })();
3254
3441
  //#endregion
3255
- export { InvalidInstallSpecError, PluginManager, PluginManager as default, classifyInstallFailure, parseInstallSpec };
3442
+ export { InvalidInstallSpecError, PluginManager, PluginManager as default, classifyInstallFailure, parseInstallSpec, pinnedGitOrigin };