@dsh-sup/dsh-core-linux-x64 0.1.6-BETA.8 → 0.1.6-BETA.9

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 (2) hide show
  1. package/core.cjs +129 -121
  2. package/package.json +1 -1
package/core.cjs CHANGED
@@ -947,7 +947,7 @@ var require_version = __commonJS({
947
947
  var fs2 = require("node:fs");
948
948
  var path2 = require("node:path");
949
949
  function guardVersion() {
950
- if (true) return String("0.1.6-BETA.8");
950
+ if (true) return String("0.1.6-BETA.9");
951
951
  try {
952
952
  return JSON.parse(fs2.readFileSync(path2.join(__dirname, "..", "..", "package.json"), "utf8")).version || "unknown";
953
953
  } catch {
@@ -6571,6 +6571,16 @@ var require_registry_ref = __commonJS({
6571
6571
  const tail = segments.filter((s) => s !== "" && s != null).map((s) => String(s).replace(/^\/+/, "").replace(/\/+$/, "")).filter(Boolean).join("/");
6572
6572
  return tail ? parsed.base + "/" + tail : parsed.base;
6573
6573
  }
6574
+ function registryEnvPair(base) {
6575
+ const parsed = parseRegistryBase(base);
6576
+ if (!parsed.ok) return { ok: false, violation: parsed.violation, base: null, env: null };
6577
+ return {
6578
+ ok: true,
6579
+ violation: null,
6580
+ base: parsed.base,
6581
+ env: { npm_config_registry: parsed.base, NPM_CONFIG_REGISTRY: parsed.base }
6582
+ };
6583
+ }
6574
6584
  async function readCapped(res, maxBytes) {
6575
6585
  const cl = Number(res.headers && res.headers.get("content-length")) || 0;
6576
6586
  if (cl > maxBytes) return null;
@@ -6666,6 +6676,7 @@ var require_registry_ref = __commonJS({
6666
6676
  normalizeBase,
6667
6677
  hostViolation,
6668
6678
  parseRegistryBase,
6679
+ registryEnvPair,
6669
6680
  registryPackagePath,
6670
6681
  registryUrl,
6671
6682
  fetchRegistry
@@ -6678,6 +6689,7 @@ var require_policies = __commonJS({
6678
6689
  "src/platform/distribution/policies.js"(exports2, module2) {
6679
6690
  "use strict";
6680
6691
  var registryRef = require_registry_ref();
6692
+ var NPM_TIMEOUT_MS = { install: 6e5, uninstall: 9e5 };
6681
6693
  var FALLBACK_REGISTRIES = [
6682
6694
  "https://registry.npmjs.org",
6683
6695
  "https://registry.npmmirror.com"
@@ -6720,6 +6732,7 @@ var require_policies = __commonJS({
6720
6732
  }
6721
6733
  module2.exports = {
6722
6734
  FALLBACK_REGISTRIES,
6735
+ NPM_TIMEOUT_MS,
6723
6736
  registryOriginViolation,
6724
6737
  effectiveOrigins,
6725
6738
  rebuildRegistryConfig,
@@ -7387,21 +7400,31 @@ var require_version_check = __commonJS({
7387
7400
  return null;
7388
7401
  }
7389
7402
  }
7390
- async function fetchLatestVersion(state, pkg, channel, opts) {
7403
+ async function fetchVersionInfo(state, pkg, channel, opts) {
7391
7404
  const ch = channel || "npm";
7392
7405
  const o = opts || {};
7393
7406
  if (ch === "github") {
7394
7407
  const slash = String(pkg).split("/");
7395
- if (slash.length >= 2) return fetchGithubLatest(slash[0], slash.slice(1).join("/"));
7396
- return null;
7408
+ const version = slash.length >= 2 ? await fetchGithubLatest(slash[0], slash.slice(1).join("/")) : null;
7409
+ return {
7410
+ ok: !!version,
7411
+ version: version || null,
7412
+ origin: null,
7413
+ attempts: [],
7414
+ error: version ? null : "GitHub Releases \u672A\u67E5\u8BE2\u5230 " + pkg + " \u7684\u6700\u65B0\u7248"
7415
+ };
7397
7416
  }
7398
- const r = await fetchNpmLatest(state, pkg, { authoritative: o.authoritative === true });
7417
+ return fetchNpmLatest(state, pkg, { authoritative: o.authoritative === true });
7418
+ }
7419
+ async function fetchLatestVersion(state, pkg, channel, opts) {
7420
+ const r = await fetchVersionInfo(state, pkg, channel, opts);
7399
7421
  return r.ok ? r.version : null;
7400
7422
  }
7401
7423
  module2.exports = {
7402
7424
  METADATA_TIMEOUT_MS,
7403
7425
  FETCH_BUDGET_MS,
7404
7426
  fetchNpmLatest,
7427
+ fetchVersionInfo,
7405
7428
  fetchLatestVersion
7406
7429
  };
7407
7430
  }
@@ -7485,6 +7508,7 @@ var require_install = __commonJS({
7485
7508
  var service = require_service().current();
7486
7509
  var { VERSION_RE } = require_version2();
7487
7510
  var ref = require_registry_ref();
7511
+ var policies = require_policies();
7488
7512
  var input = require_input();
7489
7513
  var PKG_NAME_RE = input.PKG_NAME_RE;
7490
7514
  var BAD_ARGV_CHAR_RE = input.ARGV_UNSAFE_RE;
@@ -7505,51 +7529,55 @@ var require_install = __commonJS({
7505
7529
  }
7506
7530
  function runNpmInstall(opts) {
7507
7531
  const o = opts || {};
7532
+ const action = o.action === void 0 || o.action === null ? "install" : String(o.action);
7533
+ const bad = (r) => ({ ok: false, error: null, output: [], exitCode: null, timedOut: false, aborted: false, ...r });
7534
+ const fail = (error) => Promise.resolve(bad({ error }));
7535
+ if (action !== "install" && action !== "uninstall") return fail("runNpmInstall: \u672A\u77E5 action\uFF08\u53EA\u63A5\u53D7 install/uninstall\uFF09: " + action.slice(0, 40));
7508
7536
  const pkg = o.pkg || "@deepseek-ai/dsh";
7509
- if (!o.version) return Promise.resolve({ ok: false, error: "runNpmInstall: \u7F3A\u5C11 version\uFF08\u5FC5\u987B\u663E\u5F0F\u643A\u5E26\uFF09", output: [] });
7510
- if (!PKG_NAME_RE.test(pkg)) return Promise.resolve({ ok: false, error: "runNpmInstall: \u975E\u6CD5\u5305\u540D\uFF08\u5B57\u7B26\u96C6\u767D\u540D\u5355\u4E0D\u901A\u8FC7\uFF09: " + String(pkg).slice(0, 80), output: [] });
7511
- if (!VERSION_RE.test(String(o.version))) return Promise.resolve({ ok: false, error: "runNpmInstall: \u975E\u6CD5\u7248\u672C\u53F7\uFF08\u987B\u4E3A\u4E25\u683C semver\uFF09: " + String(o.version).slice(0, 80), output: [] });
7537
+ if (action === "install" && !o.version) return fail("runNpmInstall: \u7F3A\u5C11 version\uFF08\u5FC5\u987B\u663E\u5F0F\u643A\u5E26\uFF09");
7538
+ if (!PKG_NAME_RE.test(pkg)) return fail("runNpmInstall: \u975E\u6CD5\u5305\u540D\uFF08\u5B57\u7B26\u96C6\u767D\u540D\u5355\u4E0D\u901A\u8FC7\uFF09: " + String(pkg).slice(0, 80));
7539
+ if (action === "install" && !VERSION_RE.test(String(o.version))) return fail("runNpmInstall: \u975E\u6CD5\u7248\u672C\u53F7\uFF08\u987B\u4E3A\u4E25\u683C semver\uFF09: " + String(o.version).slice(0, 80));
7512
7540
  let argv;
7513
- const launcher = runtimeContract.npmLauncher();
7541
+ const contractLauncher = runtimeContract.npmLauncher();
7542
+ const launcher = o.launcher && o.launcher.program ? { program: String(o.launcher.program), args: Array.isArray(o.launcher.args) ? o.launcher.args.map(String) : [] } : contractLauncher;
7514
7543
  let bin = launcher.program;
7515
7544
  if (Array.isArray(o.commandTemplate) && o.commandTemplate.length) {
7516
- argv = o.commandTemplate.map((s) => String(s).replace(/{pkg}/g, pkg).replace(/{version}/g, o.version).replace(/{prefix}/g, o.prefix || ""));
7545
+ argv = o.commandTemplate.map((s) => String(s).replace(/{pkg}/g, pkg).replace(/{version}/g, o.version || "").replace(/{prefix}/g, o.prefix || ""));
7517
7546
  const fromTemplate = argv[0] !== "npm";
7518
7547
  bin = fromTemplate ? argv[0] : launcher.program;
7519
7548
  argv = (fromTemplate ? [] : launcher.args).concat(argv.slice(1));
7520
7549
  if (!fromTemplate && launcher.source === "path" && bin === "npm" && !execPath.resolveExecutable("npm")) {
7521
- return Promise.resolve({ ok: false, error: 'runNpmInstall: \u672A\u627E\u5230\u53EF\u6267\u884C\u7684 npm\uFF08commandTemplate[0]="npm" \u89E3\u6790\u5931\u8D25\uFF09', output: [] });
7550
+ return fail('runNpmInstall: \u672A\u627E\u5230\u53EF\u6267\u884C\u7684 npm\uFF08commandTemplate[0]="npm" \u89E3\u6790\u5931\u8D25\uFF09');
7522
7551
  }
7523
7552
  for (const a of argv) {
7524
7553
  if (BAD_ARGV_CHAR_RE.test(String(a)) && !WIN_DRIVE_ABS_RE.test(String(a))) {
7525
- return Promise.resolve({ ok: false, error: "runNpmInstall: commandTemplate \u66FF\u6362\u540E\u542B\u7981\u7528\u5B57\u7B26\uFF08\u7A7A\u767D/shell \u5143\u5B57\u7B26\uFF09: " + String(a).slice(0, 80), output: [] });
7554
+ return fail("runNpmInstall: commandTemplate \u66FF\u6362\u540E\u542B\u7981\u7528\u5B57\u7B26\uFF08\u7A7A\u767D/shell \u5143\u5B57\u7B26\uFF09: " + String(a).slice(0, 80));
7526
7555
  }
7527
7556
  }
7528
7557
  } else {
7529
- argv = [...launcher.args, "install", "-g", "--no-audit", "--no-fund"];
7558
+ argv = [...launcher.args, action, "-g"];
7559
+ if (action === "install") argv.push("--no-audit", "--no-fund");
7530
7560
  argv.push("--ignore-scripts");
7531
7561
  if (o.prefix) {
7532
7562
  const pv = input.prefixViolation(o.prefix);
7533
- if (pv) return Promise.resolve({ ok: false, error: "runNpmInstall: " + pv, output: [] });
7563
+ if (pv) return fail("runNpmInstall: " + pv);
7534
7564
  argv.push("--prefix", String(o.prefix));
7535
7565
  }
7536
- argv.push(pkg + "@" + o.version);
7566
+ argv.push(action === "install" ? pkg + "@" + o.version : pkg);
7537
7567
  }
7538
7568
  const envVars = runtimeContract.withPath(process.env);
7539
- if (o.registry) {
7540
- const rv = ref.parseRegistryBase(o.registry);
7541
- if (!rv.ok) {
7542
- return Promise.resolve({ ok: false, error: "runNpmInstall: \u975E\u6CD5 registry \u57FA\u5740\uFF08" + rv.violation + "\uFF09: " + String(o.registry).slice(0, 80), output: [] });
7543
- }
7544
- envVars.npm_config_registry = rv.base;
7545
- envVars.NPM_CONFIG_REGISTRY = rv.base;
7569
+ if (o.registry && action === "install") {
7570
+ const rp = ref.registryEnvPair(o.registry);
7571
+ if (!rp.ok) return fail("runNpmInstall: \u975E\u6CD5 registry \u57FA\u5740\uFF08" + rp.violation + "\uFF09: " + String(o.registry).slice(0, 80));
7572
+ Object.assign(envVars, rp.env);
7546
7573
  }
7574
+ const timeoutMs = Number(o.timeoutMs) > 0 ? Number(o.timeoutMs) : policies.NPM_TIMEOUT_MS[action];
7547
7575
  return new Promise((resolve) => {
7548
7576
  let child;
7549
7577
  try {
7550
7578
  child = spawnOS.piped(bin, argv, { env: envVars, detached: o.detached !== false });
7551
7579
  } catch (e) {
7552
- return resolve({ ok: false, error: e.message, output: [] });
7580
+ return resolve(bad({ error: e.message }));
7553
7581
  }
7554
7582
  const out = [];
7555
7583
  let settled = false;
@@ -7576,13 +7604,13 @@ var require_install = __commonJS({
7576
7604
  pid: child.pid,
7577
7605
  abort: (reason) => {
7578
7606
  killTree();
7579
- finish({ ok: false, aborted: true, error: "\u5B89\u88C5\u88AB\u4E2D\u6B62: " + (reason || "guard-exit"), output: out });
7607
+ finish(bad({ aborted: true, error: "npm " + action + " \u88AB\u4E2D\u6B62: " + (reason || "guard-exit"), output: out }));
7580
7608
  }
7581
7609
  };
7582
7610
  const timer = setTimeout(() => {
7583
7611
  killTree();
7584
- finish({ ok: false, error: "\u5B89\u88C5\u8D85\u65F6", output: out });
7585
- }, o.timeoutMs || 6e5);
7612
+ finish(bad({ timedOut: true, error: "npm " + action + " \u8D85\u65F6\uFF08" + Math.round(timeoutMs / 1e3) + "s\uFF09\u5DF2\u7EC8\u6B62", output: out }));
7613
+ }, timeoutMs);
7586
7614
  INFLIGHT_NPM.add(handle);
7587
7615
  const onLine = (buf) => {
7588
7616
  for (const l of String(buf).split(/\r?\n/)) {
@@ -7600,10 +7628,11 @@ var require_install = __commonJS({
7600
7628
  child.stdout.on("data", onLine);
7601
7629
  child.stderr.on("data", onLine);
7602
7630
  child.on("error", (e) => {
7603
- finish({ ok: false, error: e.message, output: out });
7631
+ finish(bad({ error: e.message, output: out }));
7604
7632
  });
7605
7633
  child.on("exit", (code) => {
7606
- finish({ ok: code === 0, error: code === 0 ? null : "npm install \u9000\u51FA\u7801 " + code, output: out });
7634
+ const c = code === null ? -1 : code;
7635
+ finish({ ok: c === 0, error: c === 0 ? null : "npm " + action + " \u9000\u51FA\u7801 " + c, output: out, exitCode: c, timedOut: false, aborted: false });
7607
7636
  });
7608
7637
  });
7609
7638
  }
@@ -7724,10 +7753,15 @@ var require_distribution = __commonJS({
7724
7753
  return policies.isInCanaryList(this);
7725
7754
  }
7726
7755
  // ---- 版本检查 / 安装 / 健康(version-check.js + install.js)----
7727
- // fetchNpmLatest 回结构化结果(含实际给出该版本的 origin 与逐源原因);fetchLatestVersion 只回版本字符串。
7756
+ // fetchNpmLatest 回 npm 通道的结构化结果(含给出该版本的 origin 与逐源原因)。
7757
+ // fetchVersionInfo 是**跨通道**的结构化口(npm|github,github 的 origin 恒 null);
7758
+ // fetchLatestVersion 只回版本字符串,只要版本号的调用方走它。
7728
7759
  fetchNpmLatest(pkg, opts) {
7729
7760
  return versionCheck.fetchNpmLatest(this, pkg, opts);
7730
7761
  }
7762
+ fetchVersionInfo(pkg, channel, opts) {
7763
+ return versionCheck.fetchVersionInfo(this, pkg, channel, opts);
7764
+ }
7731
7765
  fetchLatestVersion(pkg, channel, opts) {
7732
7766
  return versionCheck.fetchLatestVersion(this, pkg, channel, opts);
7733
7767
  }
@@ -15429,6 +15463,7 @@ var require_pkg_cache = __commonJS({
15429
15463
  var fs2 = require("node:fs");
15430
15464
  var ex2 = require_exec();
15431
15465
  var { npxCacheDir, npxLauncher } = require_npx_forms();
15466
+ var registryRef = require_registry_ref();
15432
15467
  var HASH_DIR_RE = /^[0-9a-f]{8,}$/i;
15433
15468
  function pkgCacheDirs(pkg) {
15434
15469
  if (!pkg) return [];
@@ -15495,10 +15530,8 @@ var require_pkg_cache = __commonJS({
15495
15530
  try {
15496
15531
  const regOrigin = provider.dist ? await provider.dist.registryOrigin(false).catch(() => null) : null;
15497
15532
  const env = Object.assign({}, process.env);
15498
- if (regOrigin) {
15499
- env.npm_config_registry = regOrigin;
15500
- env.NPM_CONFIG_REGISTRY = regOrigin;
15501
- }
15533
+ const rp = registryRef.registryEnvPair(regOrigin);
15534
+ if (rp.ok) Object.assign(env, rp.env);
15502
15535
  const launcher = npxLauncher();
15503
15536
  await ex2.runOutAsync(launcher.program, [...launcher.args, "--yes", app.pkg, "--help"], { env, timeoutMs: 12e4 });
15504
15537
  return { ok: !!cachedPkgBin(app.pkg) };
@@ -15526,6 +15559,7 @@ var require_probe5 = __commonJS({
15526
15559
  var { cachedPkgBin, ensurePkgCached } = require_pkg_cache();
15527
15560
  var stateRoot2 = require_state_root();
15528
15561
  var { Rotator } = require_log();
15562
+ var registryRef = require_registry_ref();
15529
15563
  var INSTANCE_LOG_MAX_BYTES = 2 * 1024 * 1024;
15530
15564
  async function spawnInstance(provider, inst) {
15531
15565
  const app = provider.app;
@@ -15595,10 +15629,9 @@ var require_probe5 = __commonJS({
15595
15629
  envVars[k] = String(v).replace("{{key}}", inst.key).replace("{{port}}", String(port));
15596
15630
  }
15597
15631
  }
15598
- if (launch.registry) {
15599
- envVars.npm_config_registry = launch.registry;
15600
- envVars.NPM_CONFIG_REGISTRY = launch.registry;
15601
- }
15632
+ const rpReg = registryRef.registryEnvPair(launch.registry);
15633
+ if (rpReg.ok) Object.assign(envVars, rpReg.env);
15634
+ else if (launch.registry && provider.logger) provider.logger.warn("[proxy-instance] \u5951\u7EA6 registry \u975E\u6CD5\uFF08" + rpReg.violation + "\uFF09\uFF0C\u6539\u7528 npx \u9ED8\u8BA4\u6E90");
15602
15635
  const logFilter = /error|streaming|idle|timeout|ECONN|abort|socket|finish|truncat/i;
15603
15636
  const baseDir = provider.stateDir || stateRoot2.supervisorDir();
15604
15637
  let logWriter = null;
@@ -22071,6 +22104,7 @@ var require_cli = __commonJS({
22071
22104
  "use strict";
22072
22105
  var spawn = require_spawn();
22073
22106
  var procOS = require_process();
22107
+ var registryRef = require_registry_ref();
22074
22108
  var { assertSafeCliArgs, cliArgv } = require_policies2();
22075
22109
  var CLI_TIMEOUT_MS = 18e4;
22076
22110
  var DEFAULT_REGISTRY = "https://registry.npmjs.org";
@@ -22099,12 +22133,10 @@ var require_cli = __commonJS({
22099
22133
  }
22100
22134
  };
22101
22135
  Promise.resolve().then(() => registryOrigin2()).then((regRaw) => {
22102
- const reg = regRaw || null;
22136
+ const rp = registryRef.registryEnvPair(regRaw);
22103
22137
  const envBase = Object.assign({}, process.env, target.env);
22104
- if (reg) {
22105
- envBase.npm_config_registry = reg;
22106
- envBase.NPM_CONFIG_REGISTRY = reg;
22107
- } else if (logger && logger.warn) logger.warn("plugin CLI: \u65E0\u53EF\u7528\u7684 registry \u955C\u50CF\uFF0C\u56DE\u9000 pnpm \u9ED8\u8BA4\uFF08npmjs.org\uFF09");
22138
+ if (rp.ok) Object.assign(envBase, rp.env);
22139
+ else if (logger && logger.warn) logger.warn("plugin CLI: \u65E0\u53EF\u7528\u7684 registry \u955C\u50CF\uFF08" + rp.violation + "\uFF09\uFF0C\u56DE\u9000 pnpm \u9ED8\u8BA4\uFF08npmjs.org\uFF09");
22108
22140
  const env = envBase;
22109
22141
  let child;
22110
22142
  try {
@@ -23635,7 +23667,7 @@ var require_npm = __commonJS({
23635
23667
  async function latestVersion(host2) {
23636
23668
  if (!host2.dist || !host2.config.packageName) throw new Error("\u5206\u53D1\u670D\u52A1\u672A\u521D\u59CB\u5316\uFF0C\u65E0\u6CD5\u67E5\u8BE2\u6700\u65B0\u7248\u672C");
23637
23669
  const channel = host2.config.releaseChannel || "npm";
23638
- return host2.dist.fetchLatestVersion(host2.config.packageName, channel);
23670
+ return host2.dist.fetchVersionInfo(host2.config.packageName, channel);
23639
23671
  }
23640
23672
  async function selectRegistry(host2) {
23641
23673
  if (!host2.dist) return null;
@@ -23645,23 +23677,29 @@ var require_npm = __commonJS({
23645
23677
  return null;
23646
23678
  }
23647
23679
  }
23648
- function runInstall(host2, version, registry) {
23649
- if (!host2.dist) return Promise.resolve({ ok: false, error: "dist \u5206\u53D1\u670D\u52A1\u4E0D\u53EF\u7528\uFF0C\u65E0\u6CD5\u5B89\u88C5", output: [] });
23650
- const pkg = host2.config.packageName || "@deepseek-ai/dsh";
23651
- const tpl = host2.config.installCommandTemplate;
23680
+ function runNpm(host2, opts) {
23681
+ const a = opts && opts.action || "install";
23682
+ const verb = a === "uninstall" ? "\u5378\u8F7D" : "\u5B89\u88C5";
23683
+ if (!host2.dist) return Promise.resolve({ ok: false, error: "dist \u5206\u53D1\u670D\u52A1\u4E0D\u53EF\u7528\uFF0C\u65E0\u6CD5" + verb, output: [] });
23684
+ const tpl = a === "install" ? host2.config.installCommandTemplate : null;
23652
23685
  return host2.dist.runNpmInstall({
23653
- pkg,
23654
- version,
23655
- registry,
23686
+ action: a,
23687
+ pkg: host2.config.packageName || "@deepseek-ai/dsh",
23688
+ version: opts && opts.version,
23689
+ // 前缀单源:装与卸必须落在同一个全局前缀,否则「卸载成功」而包还在原地。
23690
+ prefix: host2.npmRoot || null,
23691
+ registry: opts && opts.registry,
23692
+ // 只在显式注入过 npm 形态时接管启动形态;生产留空,由执行器按运行期契约解析一次。
23693
+ launcher: host2._npmBin ? npmLaunch(host2) : null,
23656
23694
  commandTemplate: Array.isArray(tpl) && tpl.length ? tpl : null,
23657
- timeoutMs: host2.config.upgradeTimeoutMs || 6e5,
23695
+ timeoutMs: a === "uninstall" ? host2.config.uninstallTimeoutMs : host2.config.upgradeTimeoutMs,
23658
23696
  onLine: (l) => {
23659
23697
  host2._appendUpgradeLog(l);
23660
23698
  if (host2.installing) host2._appendInstallLog(l);
23661
23699
  }
23662
23700
  });
23663
23701
  }
23664
- module2.exports = { npmLaunch, resolveNpmRoot, checkEnvironment, latestVersion, selectRegistry, runInstall };
23702
+ module2.exports = { npmLaunch, resolveNpmRoot, checkEnvironment, latestVersion, selectRegistry, runNpm };
23665
23703
  }
23666
23704
  });
23667
23705
 
@@ -23670,9 +23708,6 @@ var require_ops4 = __commonJS({
23670
23708
  "src/app/native/ops.js"(exports2, module2) {
23671
23709
  "use strict";
23672
23710
  var fs2 = require("node:fs");
23673
- var spawnOS = require_spawn();
23674
- var { killTree } = require_process();
23675
- var { npmLaunch } = require_npm();
23676
23711
  var policies = require_policies3();
23677
23712
  var PKG_DEFAULT = "@deepseek-ai/dsh";
23678
23713
  function status(host2) {
@@ -23704,13 +23739,15 @@ var require_ops4 = __commonJS({
23704
23739
  host2.lastCheck = { at: (/* @__PURE__ */ new Date()).toISOString(), installed: null, latest: null, updateAvailable: false, note: "not-installed" };
23705
23740
  return policies.versionInfo(host2, installed);
23706
23741
  }
23707
- const latest = await host2._latestVersion();
23742
+ const info = await host2._latestVersion();
23743
+ const latest = info.ok ? info.version : null;
23708
23744
  host2.lastCheck = {
23709
23745
  at: (/* @__PURE__ */ new Date()).toISOString(),
23710
23746
  installed,
23711
23747
  latest,
23712
23748
  updateAvailable: latest ? policies.isNewer(latest, installed) : false,
23713
- error: latest ? null : "\u955C\u50CF\u6E90\u4E0D\u53EF\u8FBE\u6216\u672A\u67E5\u8BE2\u5230\u7248\u672C"
23749
+ // 拒因指名到源:「镜像源全挂」与「确实没有更新」显示成两句话是这块的全部意义。
23750
+ error: latest ? null : info.error || "\u955C\u50CF\u6E90\u4E0D\u53EF\u8FBE\u6216\u672A\u67E5\u8BE2\u5230\u7248\u672C"
23714
23751
  };
23715
23752
  if (host2.events) host2.events.append("version_checked", { installed, latest, updateAvailable: host2.lastCheck.updateAvailable });
23716
23753
  } catch (e) {
@@ -23737,20 +23774,24 @@ var require_ops4 = __commonJS({
23737
23774
  if (!env.ok) return { ok: false, error: "\u73AF\u5883\u68C0\u67E5\u5931\u8D25: " + env.errors.join("; ") };
23738
23775
  task = beginTask(host2, "install", { to: version || null, createdBy: "user" });
23739
23776
  let target = version;
23777
+ let registry = null;
23740
23778
  if (!target) {
23741
- target = await host2._latestVersion().catch(() => null);
23742
- if (!target) {
23779
+ const info = await host2._latestVersion().catch(() => null);
23780
+ if (!info || !info.ok || !info.version) {
23743
23781
  host2.installing = null;
23744
- if (task) host2.tasks.fail(task.id, "\u65E0\u6CD5\u4ECE\u955C\u50CF\u6E90\u83B7\u53D6\u6700\u65B0\u7248\u672C");
23745
- return { ok: false, error: "\u65E0\u6CD5\u4ECE\u955C\u50CF\u6E90\u83B7\u53D6\u6700\u65B0\u7248\u672C" };
23782
+ const why = info && info.error || "\u65E0\u6CD5\u4ECE\u955C\u50CF\u6E90\u83B7\u53D6\u6700\u65B0\u7248\u672C";
23783
+ if (task) host2.tasks.fail(task.id, why);
23784
+ return { ok: false, error: why };
23746
23785
  }
23786
+ target = info.version;
23787
+ registry = info.origin;
23747
23788
  }
23748
- const registry = await host2._selectRegistry();
23789
+ if (!registry) registry = await host2._selectRegistry();
23749
23790
  const pkg = host2.config.packageName || PKG_DEFAULT;
23750
23791
  if (task) host2.tasks.log(task.id, "\u5B89\u88C5 " + pkg + "@" + target + (registry ? " via " + registry : ""));
23751
23792
  if (host2.events) host2.events.append("native_install_started", { version: target, registry });
23752
23793
  if (host2.logger.info) host2.logger.info("native install: " + pkg + "@" + target + (registry ? " via " + registry : ""));
23753
- const res = await host2._runInstall(target, registry);
23794
+ const res = await host2._runNpm({ action: "install", version: target, registry });
23754
23795
  if (!res.ok) {
23755
23796
  host2.installing = null;
23756
23797
  host2.lastInstall = { ok: false, version: null, error: res.error, at: (/* @__PURE__ */ new Date()).toISOString(), log: host2.installLog.slice(-8) };
@@ -23842,46 +23883,9 @@ var require_ops4 = __commonJS({
23842
23883
  host2.tasks.start(task.id);
23843
23884
  host2.tasks.log(task.id, "\u5378\u8F7D " + (host2.config.packageName || PKG_DEFAULT));
23844
23885
  }
23845
- const pkg = host2.config.packageName || PKG_DEFAULT;
23846
- const uninstallArgs = ["uninstall", "-g"];
23847
- if (host2.npmRoot) uninstallArgs.push("--prefix", host2.npmRoot);
23848
- uninstallArgs.push(pkg);
23849
- const UNINSTALL_TIMEOUT_MS = typeof host2.config.uninstallTimeoutMs === "number" && host2.config.uninstallTimeoutMs > 0 ? host2.config.uninstallTimeoutMs : 15 * 60 * 1e3;
23850
- let uninstallTimedOut = false;
23851
- const exitCode = await new Promise((resolve) => {
23852
- let child;
23853
- try {
23854
- const np = npmLaunch(host2);
23855
- child = spawnOS.piped(np.program, np.args.concat(uninstallArgs));
23856
- } catch (e) {
23857
- return resolve(-1);
23858
- }
23859
- child.stdout.resume();
23860
- child.stderr.resume();
23861
- let done = false;
23862
- const finish = (code) => {
23863
- if (done) return;
23864
- done = true;
23865
- clearTimeout(timer);
23866
- resolve(code);
23867
- };
23868
- const timer = setTimeout(() => {
23869
- uninstallTimedOut = true;
23870
- host2.logger.warn && host2.logger.warn("npm uninstall \u8D85\u65F6\uFF08" + Math.round(UNINSTALL_TIMEOUT_MS / 1e3) + "s\uFF09\uFF0C\u7EC8\u6B62\u8FDB\u7A0B\u6811");
23871
- try {
23872
- killTree(child.pid, "SIGKILL", () => finish(-1));
23873
- } catch (e) {
23874
- try {
23875
- child.kill("SIGKILL");
23876
- } catch (e2) {
23877
- }
23878
- finish(-1);
23879
- }
23880
- }, UNINSTALL_TIMEOUT_MS);
23881
- if (timer.unref) timer.unref();
23882
- child.on("error", () => finish(-1));
23883
- child.on("exit", (code) => finish(code == null ? -1 : code));
23884
- });
23886
+ const res = await host2._runNpm({ action: "uninstall" });
23887
+ const exitCode = res.ok === true ? 0 : Number.isFinite(res.exitCode) ? res.exitCode : -1;
23888
+ const timedOut = res.timedOut === true || res.aborted === true;
23885
23889
  if (exitCode === 0 && m) {
23886
23890
  if (m.packageDir) rm(m.packageDir);
23887
23891
  if (m.binPath) rm(m.binPath);
@@ -23892,17 +23896,17 @@ var require_ops4 = __commonJS({
23892
23896
  } else {
23893
23897
  host2.logger.warn && host2.logger.warn("npm uninstall exit " + exitCode + "\uFF0C\u4FDD\u7559 manifest \u4EE5\u4FBF\u91CD\u8BD5\uFF08\u6570\u636E\u8DEF\u5F84\u672A\u5220\uFF09");
23894
23898
  }
23895
- const uninstallError = exitCode === 0 ? null : uninstallTimedOut ? "npm uninstall \u8D85\u65F6\uFF08" + Math.round(UNINSTALL_TIMEOUT_MS / 1e3) + "s\uFF09\u5DF2\u7EC8\u6B62\uFF0C\u5305\u53EF\u80FD\u4ECD\u5728\uFF0C\u53EF\u91CD\u8BD5" : "npm uninstall \u9000\u51FA\u7801 " + exitCode;
23896
- host2.lastUninstall = { ok: exitCode === 0, removed, error: uninstallError, timedOut: uninstallTimedOut, at: (/* @__PURE__ */ new Date()).toISOString() };
23899
+ const uninstallError = exitCode === 0 ? null : timedOut ? (res.error || "npm uninstall \u8D85\u65F6\u5DF2\u7EC8\u6B62") + "\uFF0C\u5305\u53EF\u80FD\u4ECD\u5728\uFF0C\u53EF\u91CD\u8BD5" : "npm uninstall \u9000\u51FA\u7801 " + exitCode;
23900
+ host2.lastUninstall = { ok: exitCode === 0, removed, error: uninstallError, timedOut, at: (/* @__PURE__ */ new Date()).toISOString() };
23897
23901
  if (host2.events) host2.events.append("native_uninstalled", { removed });
23898
23902
  if (host2.logger.info) host2.logger.info("native uninstalled, removed " + removed.length + " paths");
23899
23903
  if (task) {
23900
23904
  if (exitCode === 0) {
23901
23905
  host2.tasks.log(task.id, "\u5378\u8F7D\u5B8C\u6210\uFF0C\u6E05\u7406 " + removed.length + " \u4E2A\u8DEF\u5F84");
23902
23906
  host2.tasks.succeed(task.id);
23903
- } else host2.tasks.fail(task.id, "npm uninstall \u9000\u51FA\u7801 " + exitCode);
23907
+ } else host2.tasks.fail(task.id, uninstallError || "npm uninstall \u9000\u51FA\u7801 " + exitCode);
23904
23908
  }
23905
- return { ok: exitCode === 0, removed, timedOut: uninstallTimedOut, error: uninstallError };
23909
+ return { ok: exitCode === 0, removed, timedOut, error: uninstallError };
23906
23910
  } finally {
23907
23911
  host2.uninstalling = null;
23908
23912
  }
@@ -23951,12 +23955,12 @@ var require_upgrade2 = __commonJS({
23951
23955
  return task;
23952
23956
  }
23953
23957
  async function resolveTarget(host2, requestedVersion, task) {
23954
- if (requestedVersion) return requestedVersion;
23958
+ if (requestedVersion) return { version: requestedVersion, origin: null };
23955
23959
  taskLog(host2, task, "\u67E5\u8BE2\u6700\u65B0\u7248\u672C\u2026");
23956
23960
  log(host2, "\u67E5\u8BE2\u6700\u65B0\u7248\u672C\u2026");
23957
- const target = await host2._latestVersion();
23958
- if (!target) throw new Error("\u65E0\u6CD5\u4ECE\u4EFB\u4F55 registry \u83B7\u53D6\u6700\u65B0\u7248\u672C");
23959
- return target;
23961
+ const info = await host2._latestVersion();
23962
+ if (!info || !info.ok || !info.version) throw new Error(info && info.error || "\u65E0\u6CD5\u4ECE\u4EFB\u4F55 registry \u83B7\u53D6\u6700\u65B0\u7248\u672C");
23963
+ return { version: info.version, origin: info.origin };
23960
23964
  }
23961
23965
  async function stopForUpgrade(host2, task) {
23962
23966
  if (!(host2.hooks.isDshActive && host2.hooks.isDshActive())) return;
@@ -23969,10 +23973,10 @@ var require_upgrade2 = __commonJS({
23969
23973
  }
23970
23974
  if (host2.hooks.stopForUpgrade) await host2.hooks.stopForUpgrade();
23971
23975
  }
23972
- async function installTarget(host2, oldV, target, task) {
23973
- const registry = await host2._selectRegistry();
23976
+ async function installTarget(host2, oldV, target, origin, task) {
23977
+ const registry = origin || await host2._selectRegistry();
23974
23978
  markStep(host2, task, "\u5B89\u88C5 " + target);
23975
- const res = await host2._runInstall(target, registry);
23979
+ const res = await host2._runNpm({ action: "install", version: target, registry });
23976
23980
  if (!res.ok) throw new Error(res.error || "install failed");
23977
23981
  const newV = host2.installedVersion();
23978
23982
  if (newV !== target) throw new Error("\u5B89\u88C5\u540E\u7248\u672C\u6821\u9A8C\u5931\u8D25\uFF1A\u671F\u671B " + target + "\uFF0C\u5B9E\u9645 " + newV);
@@ -24068,7 +24072,7 @@ var require_upgrade2 = __commonJS({
24068
24072
  }
24069
24073
  tlog("\u81EA\u52A8\u56DE\u6EDA\u5230 " + oldVersion + "\u2026");
24070
24074
  const registry = await host2._selectRegistry();
24071
- const res = await host2._runInstall(oldVersion, registry);
24075
+ const res = await host2._runNpm({ action: "install", version: oldVersion, registry });
24072
24076
  let okVer = false;
24073
24077
  try {
24074
24078
  okVer = host2.installedVersion() === oldVersion;
@@ -24098,7 +24102,7 @@ var require_upgrade2 = __commonJS({
24098
24102
  if (host2.events) host2.events.append("upgrade_rollback_started", { to: host2.oldVersion });
24099
24103
  log(host2, "\u56DE\u6EDA\u5230 " + host2.oldVersion + "\u2026");
24100
24104
  const registry = await host2._selectRegistry();
24101
- const res = await host2._runInstall(host2.oldVersion, registry);
24105
+ const res = await host2._runNpm({ action: "install", version: host2.oldVersion, registry });
24102
24106
  let okVer = false;
24103
24107
  try {
24104
24108
  okVer = host2.installedVersion() === host2.oldVersion;
@@ -24162,7 +24166,8 @@ var require_upgrade2 = __commonJS({
24162
24166
  try {
24163
24167
  const oldV = host2.installedVersion();
24164
24168
  host2.oldVersion = oldV;
24165
- const target = await resolveTarget(host2, requestedVersion, task);
24169
+ const pick = await resolveTarget(host2, requestedVersion, task);
24170
+ const target = pick.version;
24166
24171
  host2.targetVersion = target;
24167
24172
  taskLog(host2, task, "\u76EE\u6807\u7248\u672C " + target);
24168
24173
  if (!oldV) {
@@ -24176,7 +24181,7 @@ var require_upgrade2 = __commonJS({
24176
24181
  log(host2, "\u5347\u7EA7 " + oldV + " \u2192 " + target);
24177
24182
  taskLog(host2, task, "\u5347\u7EA7 " + oldV + " \u2192 " + target);
24178
24183
  await stopForUpgrade(host2, task);
24179
- await installTarget(host2, oldV, target, task);
24184
+ await installTarget(host2, oldV, target, pick.origin, task);
24180
24185
  if (!(host2.hooks.desiredRunning && host2.hooks.desiredRunning())) return finishStopped(host2, oldV, target, task);
24181
24186
  return await verifyAndFinalize(host2, oldV, target, task);
24182
24187
  } catch (err) {
@@ -24230,7 +24235,7 @@ var require_installer = __commonJS({
24230
24235
  this.lastInstall = null;
24231
24236
  this.lastUninstall = null;
24232
24237
  }
24233
- /** 追加安装输出(有界,仅任务进行中由 _runInstall 写入)。 */
24238
+ /** 追加安装输出(有界,仅任务进行中由 _runNpm 的行日志写入)。 */
24234
24239
  _appendInstallLog(line) {
24235
24240
  this.installLog.push(line);
24236
24241
  if (this.installLog.length > 60) this.installLog.splice(0, this.installLog.length - 60);
@@ -24273,12 +24278,15 @@ var require_installer = __commonJS({
24273
24278
  _claimDataPaths() {
24274
24279
  return manifest.claimDataPaths(this);
24275
24280
  }
24276
- _runInstall(version, registry) {
24277
- return npm.runInstall(this, version, registry);
24281
+ /** npm 动作的唯一出口(装/升/回滚/卸载同源),入参见 npm.runNpm。 */
24282
+ _runNpm(opts) {
24283
+ return npm.runNpm(this, opts);
24278
24284
  }
24285
+ /** 最新版本 + 给出它的那个镜像源(结构化,回 {ok,version,origin,error})。 */
24279
24286
  _latestVersion() {
24280
24287
  return npm.latestVersion(this);
24281
24288
  }
24289
+ /** 只选源(钉死版本的安装与回滚用);查询过版本的安装路径走 _latestVersion 的 origin。 */
24282
24290
  _selectRegistry() {
24283
24291
  return npm.selectRegistry(this);
24284
24292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-sup/dsh-core-linux-x64",
3
- "version": "0.1.6-BETA.8",
3
+ "version": "0.1.6-BETA.9",
4
4
  "description": "DSH lifecycle guard core (Node launcher) for linux-x64 — requires Node >=18.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {