pubm 0.2.8 → 0.2.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.
package/bin/cli.js CHANGED
@@ -4655,6 +4655,7 @@ var Listr = (_a23 = class {
4655
4655
  }, __name(_a23, "Listr"), _a23);
4656
4656
 
4657
4657
  // src/error.ts
4658
+ import { NonZeroExitError } from "tinyexec";
4658
4659
  var AbstractError = class extends Error {
4659
4660
  constructor(message, { cause } = {}) {
4660
4661
  super(message, { cause });
@@ -4665,20 +4666,49 @@ var AbstractError = class extends Error {
4665
4666
  function replaceCode(code) {
4666
4667
  return code.replace(/`([^`].+)`/g, color.bold(color.underline("$1")));
4667
4668
  }
4669
+ function formatStderr(stderr) {
4670
+ return stderr.split("\n").map((line) => ` ${color.dim("\u2502")} ${line}`).join("\n");
4671
+ }
4672
+ function isNoisyCause(cause) {
4673
+ if (cause instanceof NonZeroExitError) return true;
4674
+ if (cause instanceof Error && /Process exited with non-zero status/i.test(cause.message))
4675
+ return true;
4676
+ return false;
4677
+ }
4668
4678
  function formatError(error) {
4669
4679
  if (!(error instanceof Error)) return `${error}`;
4670
- const message = typeof error.message === "string" ? replaceCode(error.message) : (
4680
+ const rawMessage = typeof error.message === "string" ? error.message : (
4671
4681
  /* v8 ignore next */
4672
- formatError(error)
4682
+ String(error)
4673
4683
  );
4674
- let stringifyError = `${color.bgRed(` ${error.name} `)}${color.reset("")} ${message}
4684
+ const newlineIndex = rawMessage.indexOf("\n");
4685
+ let summary;
4686
+ let detail;
4687
+ if (newlineIndex !== -1) {
4688
+ summary = rawMessage.slice(0, newlineIndex);
4689
+ detail = rawMessage.slice(newlineIndex + 1);
4690
+ } else {
4691
+ summary = rawMessage;
4692
+ }
4693
+ let result = `${color.bgRed(` ${error.name} `)}${color.reset("")} ${replaceCode(summary)}
4675
4694
  `;
4676
- stringifyError += error.stack?.split("\n").slice(1).join("\n").replace(/at/g, color.dim("at")).replace(/\(([^(].+)\)/g, `(${color.blue("$1")})`);
4677
- if (error.cause) {
4678
- stringifyError += "\n\nCaused: ";
4679
- stringifyError += formatError(error.cause);
4695
+ if (detail) {
4696
+ result += `
4697
+ ${formatStderr(detail)}
4698
+ `;
4699
+ }
4700
+ if (process.env.DEBUG === "pubm" && error.stack) {
4701
+ result += error.stack.split("\n").slice(1).join("\n").replace(/at/g, color.dim("at")).replace(/\(([^(].+)\)/g, `(${color.blue("$1")})`);
4702
+ }
4703
+ if (error.cause && !isNoisyCause(error.cause)) {
4704
+ const causeMsg = error.cause instanceof Error ? error.cause.message : String(error.cause);
4705
+ if (causeMsg !== summary) {
4706
+ result += `
4707
+ ${color.dim("Caused by:")} `;
4708
+ result += formatError(error.cause);
4709
+ }
4680
4710
  }
4681
- return stringifyError;
4711
+ return result;
4682
4712
  }
4683
4713
  function consoleError(error) {
4684
4714
  let errorText = "\n";
@@ -5645,12 +5675,19 @@ var rollbacks = [];
5645
5675
  function addRollback(rollback2, context) {
5646
5676
  rollbacks.push({ fn: rollback2, ctx: context });
5647
5677
  }
5678
+ function rollbackLog(message) {
5679
+ console.log(` ${color.yellow("\u21A9")} ${message}`);
5680
+ }
5681
+ function rollbackError(message) {
5682
+ console.error(` ${color.red("\u2717")} ${message}`);
5683
+ }
5648
5684
  var called = false;
5649
5685
  async function rollback() {
5650
5686
  if (called) return void 0;
5651
5687
  called = true;
5652
5688
  if (rollbacks.length <= 0) return void 0;
5653
- console.log("Rollback...");
5689
+ console.log(`
5690
+ ${color.yellow("\u27F2")} ${color.yellow("Rolling back...")}`);
5654
5691
  const results = await Promise.allSettled(
5655
5692
  rollbacks.map(({ fn, ctx }) => fn(ctx))
5656
5693
  );
@@ -5659,15 +5696,15 @@ async function rollback() {
5659
5696
  );
5660
5697
  if (failures.length > 0) {
5661
5698
  for (const failure of failures) {
5662
- console.error(
5663
- `Rollback operation failed: ${failure.reason instanceof Error ? failure.reason.message : failure.reason}`
5699
+ rollbackError(
5700
+ failure.reason instanceof Error ? failure.reason.message : failure.reason
5664
5701
  );
5665
5702
  }
5666
5703
  console.log(
5667
- "Rollback completed with errors. Some operations may require manual recovery."
5704
+ `${color.red("\u2717")} ${color.red("Rollback completed with errors.")} Some operations may require manual recovery.`
5668
5705
  );
5669
5706
  } else {
5670
- console.log("Rollback completed");
5707
+ console.log(`${color.green("\u2713")} Rollback completed`);
5671
5708
  }
5672
5709
  }
5673
5710
 
@@ -5952,7 +5989,7 @@ function collectRegistries(ctx) {
5952
5989
 
5953
5990
  // src/registry/crates.ts
5954
5991
  import path10 from "node:path";
5955
- import { exec as exec5, NonZeroExitError } from "tinyexec";
5992
+ import { exec as exec5, NonZeroExitError as NonZeroExitError2 } from "tinyexec";
5956
5993
 
5957
5994
  // src/registry/registry.ts
5958
5995
  var Registry = class {
@@ -5972,6 +6009,14 @@ var CratesError = class extends AbstractError {
5972
6009
  }
5973
6010
  };
5974
6011
  var USER_AGENT = "pubm (https://github.com/syi0808/pubm)";
6012
+ function cleanCargoStderr(stderr) {
6013
+ return stderr.split("\n").filter((line) => {
6014
+ const trimmed = line.trim();
6015
+ if (trimmed === "Updating crates.io index") return false;
6016
+ if (trimmed === "") return false;
6017
+ return true;
6018
+ }).join("\n");
6019
+ }
5975
6020
  var CratesRegistry = class extends Registry {
5976
6021
  constructor() {
5977
6022
  super(...arguments);
@@ -6036,9 +6081,9 @@ var CratesRegistry = class extends Registry {
6036
6081
  await exec5("cargo", args, { throwOnError: true });
6037
6082
  return true;
6038
6083
  } catch (error) {
6039
- const stderr = error instanceof NonZeroExitError ? error.output?.stderr : void 0;
6084
+ const stderr = error instanceof NonZeroExitError2 ? error.output?.stderr : void 0;
6040
6085
  const message = stderr ? `Failed to run \`cargo publish\`:
6041
- ${stderr}` : "Failed to run `cargo publish`";
6086
+ ${cleanCargoStderr(stderr)}` : "Failed to run `cargo publish`";
6042
6087
  throw new CratesError(message, { cause: error });
6043
6088
  }
6044
6089
  }
@@ -6050,9 +6095,9 @@ ${stderr}` : "Failed to run `cargo publish`";
6050
6095
  }
6051
6096
  await exec5("cargo", args, { throwOnError: true });
6052
6097
  } catch (error) {
6053
- const stderr = error instanceof NonZeroExitError ? error.output?.stderr : void 0;
6098
+ const stderr = error instanceof NonZeroExitError2 ? error.output?.stderr : void 0;
6054
6099
  const message = stderr ? `Failed to run \`cargo publish --dry-run\`:
6055
- ${stderr}` : "Failed to run `cargo publish --dry-run`";
6100
+ ${cleanCargoStderr(stderr)}` : "Failed to run `cargo publish --dry-run`";
6056
6101
  throw new CratesError(message, { cause: error });
6057
6102
  }
6058
6103
  }
@@ -6174,7 +6219,7 @@ var cratesPublishTasks = createCratesPublishTask();
6174
6219
  import { ListrEnquirerPromptAdapter as ListrEnquirerPromptAdapter2 } from "@listr2/prompt-adapter-enquirer";
6175
6220
 
6176
6221
  // src/registry/jsr.ts
6177
- import { exec as exec6, NonZeroExitError as NonZeroExitError2 } from "tinyexec";
6222
+ import { exec as exec6, NonZeroExitError as NonZeroExitError3 } from "tinyexec";
6178
6223
 
6179
6224
  // src/utils/package-name.ts
6180
6225
  import { builtinModules } from "node:module";
@@ -6282,7 +6327,7 @@ var JsrRegisry = class extends Registry {
6282
6327
  this.packageCreationUrls = void 0;
6283
6328
  return true;
6284
6329
  } catch (error) {
6285
- const stderr = error instanceof NonZeroExitError2 ? error.output?.stderr : void 0;
6330
+ const stderr = error instanceof NonZeroExitError3 ? error.output?.stderr : void 0;
6286
6331
  if (stderr?.includes("don't exist")) {
6287
6332
  const urls = [...stderr.matchAll(/https:\/\/jsr\.io\/new\S+/g)].map(
6288
6333
  (m) => m[0]
@@ -6577,7 +6622,7 @@ async function jsrRegistry() {
6577
6622
  // src/registry/npm.ts
6578
6623
  import { tmpdir } from "node:os";
6579
6624
  import { join } from "node:path";
6580
- import { exec as exec7, NonZeroExitError as NonZeroExitError3 } from "tinyexec";
6625
+ import { exec as exec7, NonZeroExitError as NonZeroExitError4 } from "tinyexec";
6581
6626
  var NpmError = class extends AbstractError {
6582
6627
  constructor() {
6583
6628
  super(...arguments);
@@ -6647,7 +6692,7 @@ var NpmRegistry = class extends Registry {
6647
6692
  await this.npm(["whoami"]);
6648
6693
  return true;
6649
6694
  } catch (error) {
6650
- if (error instanceof NonZeroExitError3) {
6695
+ if (error instanceof NonZeroExitError4) {
6651
6696
  return false;
6652
6697
  }
6653
6698
  throw new NpmError("Failed to run `npm whoami`", { cause: error });
@@ -6725,7 +6770,7 @@ var NpmRegistry = class extends Registry {
6725
6770
  await this.npm(["publish", "--provenance", "--access", "public"]);
6726
6771
  return true;
6727
6772
  } catch (error) {
6728
- if (error instanceof NonZeroExitError3 && error.output?.stderr.includes("EOTP")) {
6773
+ if (error instanceof NonZeroExitError4 && error.output?.stderr.includes("EOTP")) {
6729
6774
  return false;
6730
6775
  }
6731
6776
  throw this.classifyPublishError(error);
@@ -6737,7 +6782,7 @@ var NpmRegistry = class extends Registry {
6737
6782
  await this.npm(args);
6738
6783
  return true;
6739
6784
  } catch (error) {
6740
- if (error instanceof NonZeroExitError3 && error.output?.stderr.includes("EOTP")) {
6785
+ if (error instanceof NonZeroExitError4 && error.output?.stderr.includes("EOTP")) {
6741
6786
  return false;
6742
6787
  }
6743
6788
  throw this.classifyPublishError(error);
@@ -6755,7 +6800,7 @@ var NpmRegistry = class extends Registry {
6755
6800
  }
6756
6801
  });
6757
6802
  } catch (error) {
6758
- const stderr = error instanceof NonZeroExitError3 ? error.output?.stderr : void 0;
6803
+ const stderr = error instanceof NonZeroExitError4 ? error.output?.stderr : void 0;
6759
6804
  throw new NpmError(
6760
6805
  `Failed to run \`npm publish --dry-run\`${stderr ? `
6761
6806
  ${stderr}` : ""}`,
@@ -6782,7 +6827,7 @@ ${stderr}` : ""}`,
6782
6827
  };
6783
6828
  }
6784
6829
  classifyPublishError(error) {
6785
- if (error instanceof NonZeroExitError3) {
6830
+ if (error instanceof NonZeroExitError4) {
6786
6831
  const stderr = error.output?.stderr ?? "";
6787
6832
  if (stderr.includes("EOTP")) {
6788
6833
  return new NpmError("OTP required for publishing", { cause: error });
@@ -7828,23 +7873,23 @@ async function run(options) {
7828
7873
  addRollback(async () => {
7829
7874
  if (tagCreated) {
7830
7875
  try {
7831
- console.log("Deleting tag...");
7876
+ rollbackLog("Deleting tag");
7832
7877
  await git.deleteTag(`${await git.latestTag()}`);
7833
7878
  } catch (error) {
7834
- console.error(
7879
+ rollbackError(
7835
7880
  `Failed to delete tag: ${error instanceof Error ? error.message : error}`
7836
7881
  );
7837
7882
  }
7838
7883
  }
7839
7884
  if (commited) {
7840
7885
  try {
7841
- console.log("Reset commits...");
7886
+ rollbackLog("Resetting commits");
7842
7887
  await git.reset();
7843
7888
  await git.stash();
7844
7889
  await git.reset("HEAD^", "--hard");
7845
7890
  await git.popStash();
7846
7891
  } catch (error) {
7847
- console.error(
7892
+ rollbackError(
7848
7893
  `Failed to reset commits: ${error instanceof Error ? error.message : error}`
7849
7894
  );
7850
7895
  }
package/dist/index.cjs CHANGED
@@ -4486,7 +4486,7 @@ var Listr = (_a23 = class {
4486
4486
  // src/tasks/runner.ts
4487
4487
  var import_semver3 = __toESM(require("semver"), 1);
4488
4488
  var import_std_env = require("std-env");
4489
- var import_tinyexec8 = require("tinyexec");
4489
+ var import_tinyexec9 = require("tinyexec");
4490
4490
 
4491
4491
  // src/ecosystem/rust.ts
4492
4492
  var import_promises2 = require("fs/promises");
@@ -4608,6 +4608,7 @@ var RustEcosystem = class extends Ecosystem {
4608
4608
  };
4609
4609
 
4610
4610
  // src/error.ts
4611
+ var import_tinyexec2 = require("tinyexec");
4611
4612
  var AbstractError = class extends Error {
4612
4613
  constructor(message, { cause } = {}) {
4613
4614
  super(message, { cause });
@@ -4618,20 +4619,49 @@ var AbstractError = class extends Error {
4618
4619
  function replaceCode(code) {
4619
4620
  return code.replace(/`([^`].+)`/g, color.bold(color.underline("$1")));
4620
4621
  }
4622
+ function formatStderr(stderr) {
4623
+ return stderr.split("\n").map((line) => ` ${color.dim("\u2502")} ${line}`).join("\n");
4624
+ }
4625
+ function isNoisyCause(cause) {
4626
+ if (cause instanceof import_tinyexec2.NonZeroExitError) return true;
4627
+ if (cause instanceof Error && /Process exited with non-zero status/i.test(cause.message))
4628
+ return true;
4629
+ return false;
4630
+ }
4621
4631
  function formatError(error) {
4622
4632
  if (!(error instanceof Error)) return `${error}`;
4623
- const message = typeof error.message === "string" ? replaceCode(error.message) : (
4633
+ const rawMessage = typeof error.message === "string" ? error.message : (
4624
4634
  /* v8 ignore next */
4625
- formatError(error)
4635
+ String(error)
4626
4636
  );
4627
- let stringifyError = `${color.bgRed(` ${error.name} `)}${color.reset("")} ${message}
4637
+ const newlineIndex = rawMessage.indexOf("\n");
4638
+ let summary;
4639
+ let detail;
4640
+ if (newlineIndex !== -1) {
4641
+ summary = rawMessage.slice(0, newlineIndex);
4642
+ detail = rawMessage.slice(newlineIndex + 1);
4643
+ } else {
4644
+ summary = rawMessage;
4645
+ }
4646
+ let result = `${color.bgRed(` ${error.name} `)}${color.reset("")} ${replaceCode(summary)}
4628
4647
  `;
4629
- stringifyError += error.stack?.split("\n").slice(1).join("\n").replace(/at/g, color.dim("at")).replace(/\(([^(].+)\)/g, `(${color.blue("$1")})`);
4630
- if (error.cause) {
4631
- stringifyError += "\n\nCaused: ";
4632
- stringifyError += formatError(error.cause);
4648
+ if (detail) {
4649
+ result += `
4650
+ ${formatStderr(detail)}
4651
+ `;
4652
+ }
4653
+ if (process.env.DEBUG === "pubm" && error.stack) {
4654
+ result += error.stack.split("\n").slice(1).join("\n").replace(/at/g, color.dim("at")).replace(/\(([^(].+)\)/g, `(${color.blue("$1")})`);
4633
4655
  }
4634
- return stringifyError;
4656
+ if (error.cause && !isNoisyCause(error.cause)) {
4657
+ const causeMsg = error.cause instanceof Error ? error.cause.message : String(error.cause);
4658
+ if (causeMsg !== summary) {
4659
+ result += `
4660
+ ${color.dim("Caused by:")} `;
4661
+ result += formatError(error.cause);
4662
+ }
4663
+ }
4664
+ return result;
4635
4665
  }
4636
4666
  function consoleError(error) {
4637
4667
  let errorText = "\n";
@@ -4648,7 +4678,7 @@ function consoleError(error) {
4648
4678
 
4649
4679
  // src/git.ts
4650
4680
  var import_semver = __toESM(require("semver"), 1);
4651
- var import_tinyexec2 = require("tinyexec");
4681
+ var import_tinyexec3 = require("tinyexec");
4652
4682
  var GitError = class extends AbstractError {
4653
4683
  constructor() {
4654
4684
  super(...arguments);
@@ -4657,7 +4687,7 @@ var GitError = class extends AbstractError {
4657
4687
  };
4658
4688
  var Git = class {
4659
4689
  async git(args) {
4660
- const { stdout } = await (0, import_tinyexec2.exec)("git", args, { throwOnError: true });
4690
+ const { stdout } = await (0, import_tinyexec3.exec)("git", args, { throwOnError: true });
4661
4691
  return stdout;
4662
4692
  }
4663
4693
  async userName() {
@@ -4911,7 +4941,7 @@ var Git = class {
4911
4941
  async push(options) {
4912
4942
  const args = ["push", options].filter((v) => v);
4913
4943
  try {
4914
- const { stderr } = await (0, import_tinyexec2.exec)("git", args, { throwOnError: true });
4944
+ const { stderr } = await (0, import_tinyexec3.exec)("git", args, { throwOnError: true });
4915
4945
  if (`${stderr}`.includes("GH006")) {
4916
4946
  return false;
4917
4947
  }
@@ -4985,12 +5015,19 @@ var rollbacks = [];
4985
5015
  function addRollback(rollback2, context) {
4986
5016
  rollbacks.push({ fn: rollback2, ctx: context });
4987
5017
  }
5018
+ function rollbackLog(message) {
5019
+ console.log(` ${color.yellow("\u21A9")} ${message}`);
5020
+ }
5021
+ function rollbackError(message) {
5022
+ console.error(` ${color.red("\u2717")} ${message}`);
5023
+ }
4988
5024
  var called = false;
4989
5025
  async function rollback() {
4990
5026
  if (called) return void 0;
4991
5027
  called = true;
4992
5028
  if (rollbacks.length <= 0) return void 0;
4993
- console.log("Rollback...");
5029
+ console.log(`
5030
+ ${color.yellow("\u27F2")} ${color.yellow("Rolling back...")}`);
4994
5031
  const results = await Promise.allSettled(
4995
5032
  rollbacks.map(({ fn, ctx }) => fn(ctx))
4996
5033
  );
@@ -4999,15 +5036,15 @@ async function rollback() {
4999
5036
  );
5000
5037
  if (failures.length > 0) {
5001
5038
  for (const failure of failures) {
5002
- console.error(
5003
- `Rollback operation failed: ${failure.reason instanceof Error ? failure.reason.message : failure.reason}`
5039
+ rollbackError(
5040
+ failure.reason instanceof Error ? failure.reason.message : failure.reason
5004
5041
  );
5005
5042
  }
5006
5043
  console.log(
5007
- "Rollback completed with errors. Some operations may require manual recovery."
5044
+ `${color.red("\u2717")} ${color.red("Rollback completed with errors.")} Some operations may require manual recovery.`
5008
5045
  );
5009
5046
  } else {
5010
- console.log("Rollback completed");
5047
+ console.log(`${color.green("\u2713")} Rollback completed`);
5011
5048
  }
5012
5049
  }
5013
5050
 
@@ -5415,7 +5452,7 @@ function injectTokensToEnv(tokens) {
5415
5452
 
5416
5453
  // src/registry/crates.ts
5417
5454
  var import_node_path5 = __toESM(require("path"), 1);
5418
- var import_tinyexec3 = require("tinyexec");
5455
+ var import_tinyexec4 = require("tinyexec");
5419
5456
 
5420
5457
  // src/registry/registry.ts
5421
5458
  var Registry = class {
@@ -5435,6 +5472,14 @@ var CratesError = class extends AbstractError {
5435
5472
  }
5436
5473
  };
5437
5474
  var USER_AGENT = "pubm (https://github.com/syi0808/pubm)";
5475
+ function cleanCargoStderr(stderr) {
5476
+ return stderr.split("\n").filter((line) => {
5477
+ const trimmed = line.trim();
5478
+ if (trimmed === "Updating crates.io index") return false;
5479
+ if (trimmed === "") return false;
5480
+ return true;
5481
+ }).join("\n");
5482
+ }
5438
5483
  var CratesRegistry = class extends Registry {
5439
5484
  constructor() {
5440
5485
  super(...arguments);
@@ -5455,7 +5500,7 @@ var CratesRegistry = class extends Registry {
5455
5500
  }
5456
5501
  async isInstalled() {
5457
5502
  try {
5458
- await (0, import_tinyexec3.exec)("cargo", ["--version"]);
5503
+ await (0, import_tinyexec4.exec)("cargo", ["--version"]);
5459
5504
  return true;
5460
5505
  } catch {
5461
5506
  return false;
@@ -5496,12 +5541,12 @@ var CratesRegistry = class extends Registry {
5496
5541
  if (manifestDir) {
5497
5542
  args.push("--manifest-path", import_node_path5.default.join(manifestDir, "Cargo.toml"));
5498
5543
  }
5499
- await (0, import_tinyexec3.exec)("cargo", args, { throwOnError: true });
5544
+ await (0, import_tinyexec4.exec)("cargo", args, { throwOnError: true });
5500
5545
  return true;
5501
5546
  } catch (error) {
5502
- const stderr = error instanceof import_tinyexec3.NonZeroExitError ? error.output?.stderr : void 0;
5547
+ const stderr = error instanceof import_tinyexec4.NonZeroExitError ? error.output?.stderr : void 0;
5503
5548
  const message = stderr ? `Failed to run \`cargo publish\`:
5504
- ${stderr}` : "Failed to run `cargo publish`";
5549
+ ${cleanCargoStderr(stderr)}` : "Failed to run `cargo publish`";
5505
5550
  throw new CratesError(message, { cause: error });
5506
5551
  }
5507
5552
  }
@@ -5511,11 +5556,11 @@ ${stderr}` : "Failed to run `cargo publish`";
5511
5556
  if (manifestDir) {
5512
5557
  args.push("--manifest-path", import_node_path5.default.join(manifestDir, "Cargo.toml"));
5513
5558
  }
5514
- await (0, import_tinyexec3.exec)("cargo", args, { throwOnError: true });
5559
+ await (0, import_tinyexec4.exec)("cargo", args, { throwOnError: true });
5515
5560
  } catch (error) {
5516
- const stderr = error instanceof import_tinyexec3.NonZeroExitError ? error.output?.stderr : void 0;
5561
+ const stderr = error instanceof import_tinyexec4.NonZeroExitError ? error.output?.stderr : void 0;
5517
5562
  const message = stderr ? `Failed to run \`cargo publish --dry-run\`:
5518
- ${stderr}` : "Failed to run `cargo publish --dry-run`";
5563
+ ${cleanCargoStderr(stderr)}` : "Failed to run `cargo publish --dry-run`";
5519
5564
  throw new CratesError(message, { cause: error });
5520
5565
  }
5521
5566
  }
@@ -5637,7 +5682,7 @@ var cratesPublishTasks = createCratesPublishTask();
5637
5682
  var import_prompt_adapter_enquirer = require("@listr2/prompt-adapter-enquirer");
5638
5683
 
5639
5684
  // src/registry/jsr.ts
5640
- var import_tinyexec4 = require("tinyexec");
5685
+ var import_tinyexec5 = require("tinyexec");
5641
5686
 
5642
5687
  // src/utils/package-name.ts
5643
5688
  var import_node_module = require("module");
@@ -5705,7 +5750,7 @@ var JsrRegisry = class extends Registry {
5705
5750
  this.client = new JsrClient(getApiEndpoint(this.registry));
5706
5751
  }
5707
5752
  async jsr(args) {
5708
- const { stdout } = await (0, import_tinyexec4.exec)("jsr", args, { throwOnError: true });
5753
+ const { stdout } = await (0, import_tinyexec5.exec)("jsr", args, { throwOnError: true });
5709
5754
  return stdout;
5710
5755
  }
5711
5756
  async isInstalled() {
@@ -5721,7 +5766,7 @@ var JsrRegisry = class extends Registry {
5721
5766
  }
5722
5767
  async ping() {
5723
5768
  try {
5724
- const { stdout } = await (0, import_tinyexec4.exec)(
5769
+ const { stdout } = await (0, import_tinyexec5.exec)(
5725
5770
  "ping",
5726
5771
  [new URL(this.registry).hostname, "-c", "1"],
5727
5772
  { throwOnError: true }
@@ -5736,7 +5781,7 @@ var JsrRegisry = class extends Registry {
5736
5781
  }
5737
5782
  async publish() {
5738
5783
  try {
5739
- await (0, import_tinyexec4.exec)(
5784
+ await (0, import_tinyexec5.exec)(
5740
5785
  "jsr",
5741
5786
  ["publish", "--allow-dirty", "--token", `${JsrClient.token}`],
5742
5787
  {
@@ -5746,7 +5791,7 @@ var JsrRegisry = class extends Registry {
5746
5791
  this.packageCreationUrls = void 0;
5747
5792
  return true;
5748
5793
  } catch (error) {
5749
- const stderr = error instanceof import_tinyexec4.NonZeroExitError ? error.output?.stderr : void 0;
5794
+ const stderr = error instanceof import_tinyexec5.NonZeroExitError ? error.output?.stderr : void 0;
5750
5795
  if (stderr?.includes("don't exist")) {
5751
5796
  const urls = [...stderr.matchAll(/https:\/\/jsr\.io\/new\S+/g)].map(
5752
5797
  (m) => m[0]
@@ -5767,7 +5812,7 @@ ${stderr}` : ""}`,
5767
5812
  }
5768
5813
  async dryRunPublish() {
5769
5814
  try {
5770
- await (0, import_tinyexec4.exec)(
5815
+ await (0, import_tinyexec5.exec)(
5771
5816
  "jsr",
5772
5817
  [
5773
5818
  "publish",
@@ -6041,7 +6086,7 @@ async function jsrRegistry() {
6041
6086
  // src/registry/npm.ts
6042
6087
  var import_node_os = require("os");
6043
6088
  var import_node_path6 = require("path");
6044
- var import_tinyexec5 = require("tinyexec");
6089
+ var import_tinyexec6 = require("tinyexec");
6045
6090
  var NpmError = class extends AbstractError {
6046
6091
  constructor() {
6047
6092
  super(...arguments);
@@ -6054,7 +6099,7 @@ var NpmRegistry = class extends Registry {
6054
6099
  __publicField(this, "registry", "https://registry.npmjs.org");
6055
6100
  }
6056
6101
  async npm(args) {
6057
- const { stdout } = await (0, import_tinyexec5.exec)("npm", args, { throwOnError: true });
6102
+ const { stdout } = await (0, import_tinyexec6.exec)("npm", args, { throwOnError: true });
6058
6103
  return stdout;
6059
6104
  }
6060
6105
  async isInstalled() {
@@ -6111,7 +6156,7 @@ var NpmRegistry = class extends Registry {
6111
6156
  await this.npm(["whoami"]);
6112
6157
  return true;
6113
6158
  } catch (error) {
6114
- if (error instanceof import_tinyexec5.NonZeroExitError) {
6159
+ if (error instanceof import_tinyexec6.NonZeroExitError) {
6115
6160
  return false;
6116
6161
  }
6117
6162
  throw new NpmError("Failed to run `npm whoami`", { cause: error });
@@ -6178,7 +6223,7 @@ var NpmRegistry = class extends Registry {
6178
6223
  }
6179
6224
  async ping() {
6180
6225
  try {
6181
- await (0, import_tinyexec5.exec)("npm", ["ping"], { throwOnError: true });
6226
+ await (0, import_tinyexec6.exec)("npm", ["ping"], { throwOnError: true });
6182
6227
  return true;
6183
6228
  } catch (error) {
6184
6229
  throw new NpmError("Failed to run `npm ping`", { cause: error });
@@ -6189,7 +6234,7 @@ var NpmRegistry = class extends Registry {
6189
6234
  await this.npm(["publish", "--provenance", "--access", "public"]);
6190
6235
  return true;
6191
6236
  } catch (error) {
6192
- if (error instanceof import_tinyexec5.NonZeroExitError && error.output?.stderr.includes("EOTP")) {
6237
+ if (error instanceof import_tinyexec6.NonZeroExitError && error.output?.stderr.includes("EOTP")) {
6193
6238
  return false;
6194
6239
  }
6195
6240
  throw this.classifyPublishError(error);
@@ -6201,7 +6246,7 @@ var NpmRegistry = class extends Registry {
6201
6246
  await this.npm(args);
6202
6247
  return true;
6203
6248
  } catch (error) {
6204
- if (error instanceof import_tinyexec5.NonZeroExitError && error.output?.stderr.includes("EOTP")) {
6249
+ if (error instanceof import_tinyexec6.NonZeroExitError && error.output?.stderr.includes("EOTP")) {
6205
6250
  return false;
6206
6251
  }
6207
6252
  throw this.classifyPublishError(error);
@@ -6209,7 +6254,7 @@ var NpmRegistry = class extends Registry {
6209
6254
  }
6210
6255
  async dryRunPublish() {
6211
6256
  try {
6212
- await (0, import_tinyexec5.exec)("npm", ["publish", "--dry-run"], {
6257
+ await (0, import_tinyexec6.exec)("npm", ["publish", "--dry-run"], {
6213
6258
  throwOnError: true,
6214
6259
  nodeOptions: {
6215
6260
  env: {
@@ -6219,7 +6264,7 @@ var NpmRegistry = class extends Registry {
6219
6264
  }
6220
6265
  });
6221
6266
  } catch (error) {
6222
- const stderr = error instanceof import_tinyexec5.NonZeroExitError ? error.output?.stderr : void 0;
6267
+ const stderr = error instanceof import_tinyexec6.NonZeroExitError ? error.output?.stderr : void 0;
6223
6268
  throw new NpmError(
6224
6269
  `Failed to run \`npm publish --dry-run\`${stderr ? `
6225
6270
  ${stderr}` : ""}`,
@@ -6246,7 +6291,7 @@ ${stderr}` : ""}`,
6246
6291
  };
6247
6292
  }
6248
6293
  classifyPublishError(error) {
6249
- if (error instanceof import_tinyexec5.NonZeroExitError) {
6294
+ if (error instanceof import_tinyexec6.NonZeroExitError) {
6250
6295
  const stderr = error.output?.stderr ?? "";
6251
6296
  if (stderr.includes("EOTP")) {
6252
6297
  return new NpmError("OTP required for publishing", { cause: error });
@@ -6783,7 +6828,7 @@ var npmPublishTasks = {
6783
6828
  // src/tasks/preflight.ts
6784
6829
  var import_node_crypto2 = require("crypto");
6785
6830
  var import_prompt_adapter_enquirer4 = require("@listr2/prompt-adapter-enquirer");
6786
- var import_tinyexec6 = require("tinyexec");
6831
+ var import_tinyexec7 = require("tinyexec");
6787
6832
  var PreflightError = class extends AbstractError {
6788
6833
  constructor() {
6789
6834
  super(...arguments);
@@ -6810,7 +6855,7 @@ async function syncGhSecrets(tokens) {
6810
6855
  for (const [registry, token] of Object.entries(tokens)) {
6811
6856
  const config = TOKEN_CONFIG[registry];
6812
6857
  if (!config) continue;
6813
- const result = (0, import_tinyexec6.exec)("gh", ["secret", "set", config.ghSecretName], {
6858
+ const result = (0, import_tinyexec7.exec)("gh", ["secret", "set", config.ghSecretName], {
6814
6859
  throwOnError: true
6815
6860
  });
6816
6861
  const proc = result.process;
@@ -7004,10 +7049,10 @@ var prerequisitesCheckTask = (options) => {
7004
7049
  var import_prompt_adapter_enquirer6 = require("@listr2/prompt-adapter-enquirer");
7005
7050
 
7006
7051
  // src/registry/custom-registry.ts
7007
- var import_tinyexec7 = require("tinyexec");
7052
+ var import_tinyexec8 = require("tinyexec");
7008
7053
  var CustomRegistry = class extends NpmRegistry {
7009
7054
  async npm(args) {
7010
- const { stdout } = await (0, import_tinyexec7.exec)(
7055
+ const { stdout } = await (0, import_tinyexec8.exec)(
7011
7056
  "npm",
7012
7057
  args.concat("--registry", this.registry),
7013
7058
  { throwOnError: true }
@@ -7329,7 +7374,7 @@ async function run(options) {
7329
7374
  task: async (ctx2) => {
7330
7375
  const packageManager = await getPackageManager();
7331
7376
  try {
7332
- await (0, import_tinyexec8.exec)(packageManager, ["run", ctx2.testScript], {
7377
+ await (0, import_tinyexec9.exec)(packageManager, ["run", ctx2.testScript], {
7333
7378
  throwOnError: true
7334
7379
  });
7335
7380
  } catch (error) {
@@ -7346,7 +7391,7 @@ async function run(options) {
7346
7391
  task: async (ctx2) => {
7347
7392
  const packageManager = await getPackageManager();
7348
7393
  try {
7349
- await (0, import_tinyexec8.exec)(packageManager, ["run", ctx2.buildScript], {
7394
+ await (0, import_tinyexec9.exec)(packageManager, ["run", ctx2.buildScript], {
7350
7395
  throwOnError: true
7351
7396
  });
7352
7397
  } catch (error) {
@@ -7367,23 +7412,23 @@ async function run(options) {
7367
7412
  addRollback(async () => {
7368
7413
  if (tagCreated) {
7369
7414
  try {
7370
- console.log("Deleting tag...");
7415
+ rollbackLog("Deleting tag");
7371
7416
  await git.deleteTag(`${await git.latestTag()}`);
7372
7417
  } catch (error) {
7373
- console.error(
7418
+ rollbackError(
7374
7419
  `Failed to delete tag: ${error instanceof Error ? error.message : error}`
7375
7420
  );
7376
7421
  }
7377
7422
  }
7378
7423
  if (commited) {
7379
7424
  try {
7380
- console.log("Reset commits...");
7425
+ rollbackLog("Resetting commits");
7381
7426
  await git.reset();
7382
7427
  await git.stash();
7383
7428
  await git.reset("HEAD^", "--hard");
7384
7429
  await git.popStash();
7385
7430
  } catch (error) {
7386
- console.error(
7431
+ rollbackError(
7387
7432
  `Failed to reset commits: ${error instanceof Error ? error.message : error}`
7388
7433
  );
7389
7434
  }
package/dist/index.js CHANGED
@@ -4575,6 +4575,7 @@ var RustEcosystem = class extends Ecosystem {
4575
4575
  };
4576
4576
 
4577
4577
  // src/error.ts
4578
+ import { NonZeroExitError } from "tinyexec";
4578
4579
  var AbstractError = class extends Error {
4579
4580
  constructor(message, { cause } = {}) {
4580
4581
  super(message, { cause });
@@ -4585,20 +4586,49 @@ var AbstractError = class extends Error {
4585
4586
  function replaceCode(code) {
4586
4587
  return code.replace(/`([^`].+)`/g, color.bold(color.underline("$1")));
4587
4588
  }
4589
+ function formatStderr(stderr) {
4590
+ return stderr.split("\n").map((line) => ` ${color.dim("\u2502")} ${line}`).join("\n");
4591
+ }
4592
+ function isNoisyCause(cause) {
4593
+ if (cause instanceof NonZeroExitError) return true;
4594
+ if (cause instanceof Error && /Process exited with non-zero status/i.test(cause.message))
4595
+ return true;
4596
+ return false;
4597
+ }
4588
4598
  function formatError(error) {
4589
4599
  if (!(error instanceof Error)) return `${error}`;
4590
- const message = typeof error.message === "string" ? replaceCode(error.message) : (
4600
+ const rawMessage = typeof error.message === "string" ? error.message : (
4591
4601
  /* v8 ignore next */
4592
- formatError(error)
4602
+ String(error)
4593
4603
  );
4594
- let stringifyError = `${color.bgRed(` ${error.name} `)}${color.reset("")} ${message}
4604
+ const newlineIndex = rawMessage.indexOf("\n");
4605
+ let summary;
4606
+ let detail;
4607
+ if (newlineIndex !== -1) {
4608
+ summary = rawMessage.slice(0, newlineIndex);
4609
+ detail = rawMessage.slice(newlineIndex + 1);
4610
+ } else {
4611
+ summary = rawMessage;
4612
+ }
4613
+ let result = `${color.bgRed(` ${error.name} `)}${color.reset("")} ${replaceCode(summary)}
4595
4614
  `;
4596
- stringifyError += error.stack?.split("\n").slice(1).join("\n").replace(/at/g, color.dim("at")).replace(/\(([^(].+)\)/g, `(${color.blue("$1")})`);
4597
- if (error.cause) {
4598
- stringifyError += "\n\nCaused: ";
4599
- stringifyError += formatError(error.cause);
4615
+ if (detail) {
4616
+ result += `
4617
+ ${formatStderr(detail)}
4618
+ `;
4619
+ }
4620
+ if (process.env.DEBUG === "pubm" && error.stack) {
4621
+ result += error.stack.split("\n").slice(1).join("\n").replace(/at/g, color.dim("at")).replace(/\(([^(].+)\)/g, `(${color.blue("$1")})`);
4600
4622
  }
4601
- return stringifyError;
4623
+ if (error.cause && !isNoisyCause(error.cause)) {
4624
+ const causeMsg = error.cause instanceof Error ? error.cause.message : String(error.cause);
4625
+ if (causeMsg !== summary) {
4626
+ result += `
4627
+ ${color.dim("Caused by:")} `;
4628
+ result += formatError(error.cause);
4629
+ }
4630
+ }
4631
+ return result;
4602
4632
  }
4603
4633
  function consoleError(error) {
4604
4634
  let errorText = "\n";
@@ -4952,12 +4982,19 @@ var rollbacks = [];
4952
4982
  function addRollback(rollback2, context) {
4953
4983
  rollbacks.push({ fn: rollback2, ctx: context });
4954
4984
  }
4985
+ function rollbackLog(message) {
4986
+ console.log(` ${color.yellow("\u21A9")} ${message}`);
4987
+ }
4988
+ function rollbackError(message) {
4989
+ console.error(` ${color.red("\u2717")} ${message}`);
4990
+ }
4955
4991
  var called = false;
4956
4992
  async function rollback() {
4957
4993
  if (called) return void 0;
4958
4994
  called = true;
4959
4995
  if (rollbacks.length <= 0) return void 0;
4960
- console.log("Rollback...");
4996
+ console.log(`
4997
+ ${color.yellow("\u27F2")} ${color.yellow("Rolling back...")}`);
4961
4998
  const results = await Promise.allSettled(
4962
4999
  rollbacks.map(({ fn, ctx }) => fn(ctx))
4963
5000
  );
@@ -4966,15 +5003,15 @@ async function rollback() {
4966
5003
  );
4967
5004
  if (failures.length > 0) {
4968
5005
  for (const failure of failures) {
4969
- console.error(
4970
- `Rollback operation failed: ${failure.reason instanceof Error ? failure.reason.message : failure.reason}`
5006
+ rollbackError(
5007
+ failure.reason instanceof Error ? failure.reason.message : failure.reason
4971
5008
  );
4972
5009
  }
4973
5010
  console.log(
4974
- "Rollback completed with errors. Some operations may require manual recovery."
5011
+ `${color.red("\u2717")} ${color.red("Rollback completed with errors.")} Some operations may require manual recovery.`
4975
5012
  );
4976
5013
  } else {
4977
- console.log("Rollback completed");
5014
+ console.log(`${color.green("\u2713")} Rollback completed`);
4978
5015
  }
4979
5016
  }
4980
5017
 
@@ -5381,7 +5418,7 @@ function injectTokensToEnv(tokens) {
5381
5418
 
5382
5419
  // src/registry/crates.ts
5383
5420
  import path5 from "node:path";
5384
- import { exec as exec4, NonZeroExitError } from "tinyexec";
5421
+ import { exec as exec4, NonZeroExitError as NonZeroExitError2 } from "tinyexec";
5385
5422
 
5386
5423
  // src/registry/registry.ts
5387
5424
  var Registry = class {
@@ -5401,6 +5438,14 @@ var CratesError = class extends AbstractError {
5401
5438
  }
5402
5439
  };
5403
5440
  var USER_AGENT = "pubm (https://github.com/syi0808/pubm)";
5441
+ function cleanCargoStderr(stderr) {
5442
+ return stderr.split("\n").filter((line) => {
5443
+ const trimmed = line.trim();
5444
+ if (trimmed === "Updating crates.io index") return false;
5445
+ if (trimmed === "") return false;
5446
+ return true;
5447
+ }).join("\n");
5448
+ }
5404
5449
  var CratesRegistry = class extends Registry {
5405
5450
  constructor() {
5406
5451
  super(...arguments);
@@ -5465,9 +5510,9 @@ var CratesRegistry = class extends Registry {
5465
5510
  await exec4("cargo", args, { throwOnError: true });
5466
5511
  return true;
5467
5512
  } catch (error) {
5468
- const stderr = error instanceof NonZeroExitError ? error.output?.stderr : void 0;
5513
+ const stderr = error instanceof NonZeroExitError2 ? error.output?.stderr : void 0;
5469
5514
  const message = stderr ? `Failed to run \`cargo publish\`:
5470
- ${stderr}` : "Failed to run `cargo publish`";
5515
+ ${cleanCargoStderr(stderr)}` : "Failed to run `cargo publish`";
5471
5516
  throw new CratesError(message, { cause: error });
5472
5517
  }
5473
5518
  }
@@ -5479,9 +5524,9 @@ ${stderr}` : "Failed to run `cargo publish`";
5479
5524
  }
5480
5525
  await exec4("cargo", args, { throwOnError: true });
5481
5526
  } catch (error) {
5482
- const stderr = error instanceof NonZeroExitError ? error.output?.stderr : void 0;
5527
+ const stderr = error instanceof NonZeroExitError2 ? error.output?.stderr : void 0;
5483
5528
  const message = stderr ? `Failed to run \`cargo publish --dry-run\`:
5484
- ${stderr}` : "Failed to run `cargo publish --dry-run`";
5529
+ ${cleanCargoStderr(stderr)}` : "Failed to run `cargo publish --dry-run`";
5485
5530
  throw new CratesError(message, { cause: error });
5486
5531
  }
5487
5532
  }
@@ -5603,7 +5648,7 @@ var cratesPublishTasks = createCratesPublishTask();
5603
5648
  import { ListrEnquirerPromptAdapter } from "@listr2/prompt-adapter-enquirer";
5604
5649
 
5605
5650
  // src/registry/jsr.ts
5606
- import { exec as exec5, NonZeroExitError as NonZeroExitError2 } from "tinyexec";
5651
+ import { exec as exec5, NonZeroExitError as NonZeroExitError3 } from "tinyexec";
5607
5652
 
5608
5653
  // src/utils/package-name.ts
5609
5654
  import { builtinModules } from "node:module";
@@ -5711,7 +5756,7 @@ var JsrRegisry = class extends Registry {
5711
5756
  this.packageCreationUrls = void 0;
5712
5757
  return true;
5713
5758
  } catch (error) {
5714
- const stderr = error instanceof NonZeroExitError2 ? error.output?.stderr : void 0;
5759
+ const stderr = error instanceof NonZeroExitError3 ? error.output?.stderr : void 0;
5715
5760
  if (stderr?.includes("don't exist")) {
5716
5761
  const urls = [...stderr.matchAll(/https:\/\/jsr\.io\/new\S+/g)].map(
5717
5762
  (m) => m[0]
@@ -6006,7 +6051,7 @@ async function jsrRegistry() {
6006
6051
  // src/registry/npm.ts
6007
6052
  import { tmpdir } from "node:os";
6008
6053
  import { join } from "node:path";
6009
- import { exec as exec6, NonZeroExitError as NonZeroExitError3 } from "tinyexec";
6054
+ import { exec as exec6, NonZeroExitError as NonZeroExitError4 } from "tinyexec";
6010
6055
  var NpmError = class extends AbstractError {
6011
6056
  constructor() {
6012
6057
  super(...arguments);
@@ -6076,7 +6121,7 @@ var NpmRegistry = class extends Registry {
6076
6121
  await this.npm(["whoami"]);
6077
6122
  return true;
6078
6123
  } catch (error) {
6079
- if (error instanceof NonZeroExitError3) {
6124
+ if (error instanceof NonZeroExitError4) {
6080
6125
  return false;
6081
6126
  }
6082
6127
  throw new NpmError("Failed to run `npm whoami`", { cause: error });
@@ -6154,7 +6199,7 @@ var NpmRegistry = class extends Registry {
6154
6199
  await this.npm(["publish", "--provenance", "--access", "public"]);
6155
6200
  return true;
6156
6201
  } catch (error) {
6157
- if (error instanceof NonZeroExitError3 && error.output?.stderr.includes("EOTP")) {
6202
+ if (error instanceof NonZeroExitError4 && error.output?.stderr.includes("EOTP")) {
6158
6203
  return false;
6159
6204
  }
6160
6205
  throw this.classifyPublishError(error);
@@ -6166,7 +6211,7 @@ var NpmRegistry = class extends Registry {
6166
6211
  await this.npm(args);
6167
6212
  return true;
6168
6213
  } catch (error) {
6169
- if (error instanceof NonZeroExitError3 && error.output?.stderr.includes("EOTP")) {
6214
+ if (error instanceof NonZeroExitError4 && error.output?.stderr.includes("EOTP")) {
6170
6215
  return false;
6171
6216
  }
6172
6217
  throw this.classifyPublishError(error);
@@ -6184,7 +6229,7 @@ var NpmRegistry = class extends Registry {
6184
6229
  }
6185
6230
  });
6186
6231
  } catch (error) {
6187
- const stderr = error instanceof NonZeroExitError3 ? error.output?.stderr : void 0;
6232
+ const stderr = error instanceof NonZeroExitError4 ? error.output?.stderr : void 0;
6188
6233
  throw new NpmError(
6189
6234
  `Failed to run \`npm publish --dry-run\`${stderr ? `
6190
6235
  ${stderr}` : ""}`,
@@ -6211,7 +6256,7 @@ ${stderr}` : ""}`,
6211
6256
  };
6212
6257
  }
6213
6258
  classifyPublishError(error) {
6214
- if (error instanceof NonZeroExitError3) {
6259
+ if (error instanceof NonZeroExitError4) {
6215
6260
  const stderr = error.output?.stderr ?? "";
6216
6261
  if (stderr.includes("EOTP")) {
6217
6262
  return new NpmError("OTP required for publishing", { cause: error });
@@ -7331,23 +7376,23 @@ async function run(options) {
7331
7376
  addRollback(async () => {
7332
7377
  if (tagCreated) {
7333
7378
  try {
7334
- console.log("Deleting tag...");
7379
+ rollbackLog("Deleting tag");
7335
7380
  await git.deleteTag(`${await git.latestTag()}`);
7336
7381
  } catch (error) {
7337
- console.error(
7382
+ rollbackError(
7338
7383
  `Failed to delete tag: ${error instanceof Error ? error.message : error}`
7339
7384
  );
7340
7385
  }
7341
7386
  }
7342
7387
  if (commited) {
7343
7388
  try {
7344
- console.log("Reset commits...");
7389
+ rollbackLog("Resetting commits");
7345
7390
  await git.reset();
7346
7391
  await git.stash();
7347
7392
  await git.reset("HEAD^", "--hard");
7348
7393
  await git.popStash();
7349
7394
  } catch (error) {
7350
- console.error(
7395
+ rollbackError(
7351
7396
  `Failed to reset commits: ${error instanceof Error ? error.message : error}`
7352
7397
  );
7353
7398
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubm",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "engines": {
5
5
  "node": ">=18",
6
6
  "git": ">=2.11.0"