ai-project-manage-cli 6.0.100 → 6.0.101

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/dist/index.js +112 -59
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4241,48 +4241,109 @@ function runNpm2(args, options = {}) {
4241
4241
  shell: useNpmShell2
4242
4242
  });
4243
4243
  }
4244
+ function resolveNpmGlobalBin() {
4245
+ const binResult = runNpm2(["bin", "-g"], {
4246
+ encoding: "utf8",
4247
+ stdio: ["ignore", "pipe", "pipe"]
4248
+ });
4249
+ if (binResult.status !== 0) return null;
4250
+ return binResult.stdout?.toString().trim() || null;
4251
+ }
4252
+ function resolvePm2FromNpmRoot() {
4253
+ const rootResult = runNpm2(["root", "-g"], {
4254
+ encoding: "utf8",
4255
+ stdio: ["ignore", "pipe", "pipe"]
4256
+ });
4257
+ if (rootResult.status !== 0) return null;
4258
+ const root = rootResult.stdout?.toString().trim();
4259
+ if (!root) return null;
4260
+ for (const rel of ["pm2/bin/pm2", "pm2/bin/pm2.js"]) {
4261
+ const candidate = join15(root, ...rel.split("/"));
4262
+ if (existsSync14(candidate)) {
4263
+ return candidate;
4264
+ }
4265
+ }
4266
+ return null;
4267
+ }
4268
+ function isPm2NodeScript(path13) {
4269
+ return path13.endsWith(".js") || /[\\/]pm2[\\/]bin[\\/]pm2$/.test(path13);
4270
+ }
4271
+ function buildPm2SpawnTarget(binPath) {
4272
+ if (isPm2NodeScript(binPath)) {
4273
+ return {
4274
+ command: process.execPath,
4275
+ prefixArgs: [binPath],
4276
+ displayPath: binPath
4277
+ };
4278
+ }
4279
+ return {
4280
+ command: binPath,
4281
+ prefixArgs: [],
4282
+ displayPath: binPath
4283
+ };
4284
+ }
4285
+ function spawnPm2Target(target, args, options = {}) {
4286
+ const useShell = useNpmShell2 && target.prefixArgs.length === 0;
4287
+ return spawnSync3(target.command, [...target.prefixArgs, ...args], {
4288
+ encoding: "utf8",
4289
+ env: process.env,
4290
+ shell: useShell,
4291
+ windowsHide: useNpmShell2,
4292
+ ...options
4293
+ });
4294
+ }
4295
+ function spawnPm2At(binPath, args, options = {}) {
4296
+ return spawnPm2Target(buildPm2SpawnTarget(binPath), args, options);
4297
+ }
4244
4298
  function verifyPm2Bin(pm2Bin) {
4245
4299
  if (!pm2Bin.trim() || !existsSync14(pm2Bin)) {
4246
4300
  return false;
4247
4301
  }
4248
- const result = spawnSync3(pm2Bin, ["--version"], {
4249
- encoding: "utf8",
4250
- shell: useNpmShell2,
4251
- stdio: ["ignore", "pipe", "pipe"],
4252
- timeout: 15e3
4302
+ const result = spawnPm2At(pm2Bin, ["--version"], {
4303
+ stdio: ["ignore", "pipe", "pipe"]
4253
4304
  });
4254
4305
  return !result.error && result.status === 0;
4255
4306
  }
4256
- function findGlobalPm2() {
4307
+ function collectPm2Candidates() {
4257
4308
  const candidates = [];
4309
+ const globalBin = resolveNpmGlobalBin();
4310
+ if (globalBin) {
4311
+ if (useNpmShell2) {
4312
+ candidates.push(join15(globalBin, "pm2.cmd"));
4313
+ candidates.push(join15(globalBin, "pm2"));
4314
+ } else {
4315
+ candidates.push(join15(globalBin, "pm2"));
4316
+ }
4317
+ }
4318
+ const fromRoot = resolvePm2FromNpmRoot();
4319
+ if (fromRoot) {
4320
+ candidates.push(fromRoot);
4321
+ }
4258
4322
  const whichResult = spawnSync3(useNpmShell2 ? "where" : "which", ["pm2"], {
4259
4323
  encoding: "utf8",
4260
4324
  shell: useNpmShell2,
4325
+ env: process.env,
4261
4326
  stdio: ["ignore", "pipe", "pipe"]
4262
4327
  });
4263
4328
  if (whichResult.status === 0) {
4264
- const lines = whichResult.stdout?.toString().trim().split(/\r?\n/) ?? [];
4265
- for (const line of lines) {
4266
- const candidate = line.trim();
4267
- if (candidate) {
4268
- candidates.push(candidate);
4269
- }
4270
- }
4271
- }
4272
- const binResult = runNpm2(["bin", "-g"], {
4273
- encoding: "utf8",
4274
- stdio: ["ignore", "pipe", "pipe"]
4275
- });
4276
- if (binResult.status === 0) {
4277
- const globalBin = binResult.stdout?.toString().trim();
4278
- if (globalBin) {
4279
- candidates.push(join15(globalBin, useNpmShell2 ? "pm2.cmd" : "pm2"));
4329
+ const fromPath = whichResult.stdout?.toString().trim().split(/\r?\n/).map((line) => line.trim()).filter(Boolean) ?? [];
4330
+ if (useNpmShell2) {
4331
+ fromPath.sort((a, b) => {
4332
+ const aCmd = a.toLowerCase().endsWith(".cmd") ? 0 : 1;
4333
+ const bCmd = b.toLowerCase().endsWith(".cmd") ? 0 : 1;
4334
+ return aCmd - bCmd;
4335
+ });
4280
4336
  }
4337
+ candidates.push(...fromPath);
4281
4338
  }
4339
+ return candidates;
4340
+ }
4341
+ function findGlobalPm2() {
4282
4342
  const seen = /* @__PURE__ */ new Set();
4283
- for (const candidate of candidates) {
4284
- if (seen.has(candidate)) continue;
4285
- seen.add(candidate);
4343
+ for (const candidate of collectPm2Candidates()) {
4344
+ const key = useNpmShell2 ? candidate.toLowerCase() : candidate;
4345
+ if (seen.has(key)) continue;
4346
+ seen.add(key);
4286
4347
  if (verifyPm2Bin(candidate)) {
4287
4348
  return candidate;
4288
4349
  }
@@ -4301,11 +4362,8 @@ function installGlobalPm2() {
4301
4362
  }
4302
4363
  }
4303
4364
  function readPm2Version(pm2Bin) {
4304
- const result = spawnSync3(pm2Bin, ["--version"], {
4305
- encoding: "utf8",
4306
- shell: useNpmShell2,
4307
- stdio: ["ignore", "pipe", "pipe"],
4308
- timeout: 15e3
4365
+ const result = spawnPm2At(pm2Bin, ["--version"], {
4366
+ stdio: ["ignore", "pipe", "pipe"]
4309
4367
  });
4310
4368
  if (result.error || result.status !== 0) {
4311
4369
  return null;
@@ -4325,11 +4383,8 @@ function isPm2DaemonOutOfDate(output) {
4325
4383
  return /In-memory PM2 is out-of-date/i.test(output);
4326
4384
  }
4327
4385
  function ensurePm2DaemonUpdated(pm2Bin) {
4328
- const probe = spawnSync3(pm2Bin, ["jlist"], {
4329
- encoding: "utf8",
4330
- shell: useNpmShell2,
4331
- stdio: ["ignore", "pipe", "pipe"],
4332
- timeout: 15e3
4386
+ const probe = spawnPm2At(pm2Bin, ["jlist"], {
4387
+ stdio: ["ignore", "pipe", "pipe"]
4333
4388
  });
4334
4389
  const combined = `${probe.stdout ?? ""}
4335
4390
  ${probe.stderr ?? ""}`;
@@ -4337,11 +4392,8 @@ ${probe.stderr ?? ""}`;
4337
4392
  return;
4338
4393
  }
4339
4394
  console.log("[apm] \u68C0\u6D4B\u5230 PM2 \u5185\u5B58\u7248\u672C\u4E0E\u672C\u5730\u4E0D\u4E00\u81F4\uFF0C\u6B63\u5728\u6267\u884C pm2 update \u2026");
4340
- const update = spawnSync3(pm2Bin, ["update"], {
4341
- encoding: "utf8",
4342
- shell: useNpmShell2,
4343
- stdio: "inherit",
4344
- timeout: 6e4
4395
+ const update = spawnPm2At(pm2Bin, ["update"], {
4396
+ stdio: "inherit"
4345
4397
  });
4346
4398
  if (update.error || update.status !== 0) {
4347
4399
  console.error("[apm] pm2 update \u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u6267\u884C: pm2 update");
@@ -4359,9 +4411,20 @@ function ensureGlobalPm2(options) {
4359
4411
  installGlobalPm2();
4360
4412
  const installed2 = findGlobalPm2();
4361
4413
  if (!installed2) {
4414
+ const globalBin = resolveNpmGlobalBin();
4415
+ const moduleEntry = resolvePm2FromNpmRoot();
4362
4416
  console.error(
4363
4417
  "[apm] \u5B89\u88C5 pm2 \u540E\u4ECD\u65E0\u6CD5\u627E\u5230\u53EF\u6267\u884C\u6587\u4EF6\uFF0C\u8BF7\u624B\u52A8\u6267\u884C: npm install -g pm2"
4364
4418
  );
4419
+ if (globalBin) {
4420
+ console.error(`[apm] npm \u5168\u5C40 bin: ${globalBin}`);
4421
+ }
4422
+ if (moduleEntry) {
4423
+ console.error(`[apm] \u5DF2\u68C0\u6D4B\u5230 pm2 \u6A21\u5757: ${moduleEntry}`);
4424
+ console.error(
4425
+ "[apm] \u82E5 pm2 --version \u53EF\u7528\uFF0C\u8BF7\u68C0\u67E5 Node/npm \u5168\u5C40\u5B89\u88C5\u6743\u9650\u6216 PATH"
4426
+ );
4427
+ }
4365
4428
  process.exit(1);
4366
4429
  }
4367
4430
  ensurePm2DaemonUpdated(installed2);
@@ -4431,11 +4494,8 @@ function deletePm2AppIfExists(name) {
4431
4494
  return;
4432
4495
  }
4433
4496
  ensurePm2DaemonUpdated(pm2Bin);
4434
- spawnSync3(pm2Bin, ["delete", name], {
4435
- encoding: "utf8",
4436
- shell: useNpmShell2,
4437
- stdio: "ignore",
4438
- windowsHide: useNpmShell2
4497
+ spawnPm2At(pm2Bin, ["delete", name], {
4498
+ stdio: "ignore"
4439
4499
  });
4440
4500
  }
4441
4501
  function removePm2ConnectProcesses() {
@@ -4454,13 +4514,9 @@ function removePm2ConnectProcesses() {
4454
4514
  }
4455
4515
  function runPm2(args, options) {
4456
4516
  const pm2Bin = ensureGlobalPm2({ quiet: true });
4457
- const spawnOptions = {
4458
- encoding: "utf8",
4459
- stdio: options?.inherit ? "inherit" : ["ignore", "pipe", "pipe"],
4460
- shell: useNpmShell2,
4461
- windowsHide: useNpmShell2
4462
- };
4463
- const result = spawnSync3(pm2Bin, args, spawnOptions);
4517
+ const result = spawnPm2At(pm2Bin, args, {
4518
+ stdio: options?.inherit ? "inherit" : ["ignore", "pipe", "pipe"]
4519
+ });
4464
4520
  if (result.error) {
4465
4521
  console.error("[apm] \u6267\u884C pm2 \u5931\u8D25:", result.error.message);
4466
4522
  process.exit(1);
@@ -4479,11 +4535,8 @@ function runPm2Json(args) {
4479
4535
  return "[]";
4480
4536
  }
4481
4537
  ensurePm2DaemonUpdated(pm2Bin);
4482
- const result = spawnSync3(pm2Bin, args, {
4483
- encoding: "utf8",
4484
- stdio: ["ignore", "pipe", "pipe"],
4485
- shell: useNpmShell2,
4486
- windowsHide: useNpmShell2
4538
+ const result = spawnPm2At(pm2Bin, args, {
4539
+ stdio: ["ignore", "pipe", "pipe"]
4487
4540
  });
4488
4541
  if (result.status !== 0) return "[]";
4489
4542
  return result.stdout?.toString() ?? "[]";
@@ -4729,7 +4782,7 @@ async function runDaemonLogs(options) {
4729
4782
  // src/commands/deploy/internal/deploy-shell-env.ts
4730
4783
  var PATH_SEP = process.platform === "win32" ? ";" : ":";
4731
4784
  var useNpmShell3 = process.platform === "win32";
4732
- function resolveNpmGlobalBin() {
4785
+ function resolveNpmGlobalBin2() {
4733
4786
  const result = spawnSync4(useNpmShell3 ? "npm.cmd" : "npm", ["bin", "-g"], {
4734
4787
  encoding: "utf8",
4735
4788
  shell: useNpmShell3,
@@ -4757,7 +4810,7 @@ function prependPath(pathValue, segment) {
4757
4810
  function buildDeployShellEnv(extra) {
4758
4811
  const env = { ...process.env, ...extra };
4759
4812
  const pathSegments = [dirname4(process.execPath)];
4760
- const globalBin = resolveNpmGlobalBin();
4813
+ const globalBin = resolveNpmGlobalBin2();
4761
4814
  if (globalBin) {
4762
4815
  pathSegments.push(globalBin);
4763
4816
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "6.0.100",
3
+ "version": "6.0.101",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,