pubm 0.2.9 → 0.2.11

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
@@ -4728,6 +4728,12 @@ import { createHash as createHash2 } from "node:crypto";
4728
4728
  import { ListrEnquirerPromptAdapter } from "@listr2/prompt-adapter-enquirer";
4729
4729
  import { exec as exec2 } from "tinyexec";
4730
4730
 
4731
+ // src/utils/cli.ts
4732
+ var warningBadge = color.bgYellow(" Warning ");
4733
+ function link2(text, url) {
4734
+ return `\x1B]8;;${url}\x07${text}\x1B]8;;\x07`;
4735
+ }
4736
+
4731
4737
  // src/utils/db.ts
4732
4738
  import { createCipheriv, createDecipheriv, createHash } from "node:crypto";
4733
4739
  import { mkdirSync as mkdirSync5, readFileSync as readFileSync2, statSync, writeFileSync as writeFileSync4 } from "node:fs";
@@ -4805,19 +4811,25 @@ var TOKEN_CONFIG = {
4805
4811
  envVar: "NODE_AUTH_TOKEN",
4806
4812
  dbKey: "npm-token",
4807
4813
  ghSecretName: "NODE_AUTH_TOKEN",
4808
- promptLabel: "npm access token"
4814
+ promptLabel: "npm access token",
4815
+ tokenUrl: "https://www.npmjs.com/settings/~/tokens/granular-access-tokens/new",
4816
+ tokenUrlLabel: "npmjs.com"
4809
4817
  },
4810
4818
  jsr: {
4811
4819
  envVar: "JSR_TOKEN",
4812
4820
  dbKey: "jsr-token",
4813
4821
  ghSecretName: "JSR_TOKEN",
4814
- promptLabel: "jsr API token"
4822
+ promptLabel: "jsr API token",
4823
+ tokenUrl: "https://jsr.io/account/tokens/create",
4824
+ tokenUrlLabel: "jsr.io"
4815
4825
  },
4816
4826
  crates: {
4817
4827
  envVar: "CARGO_REGISTRY_TOKEN",
4818
4828
  dbKey: "cargo-token",
4819
4829
  ghSecretName: "CARGO_REGISTRY_TOKEN",
4820
- promptLabel: "crates.io API token"
4830
+ promptLabel: "crates.io API token",
4831
+ tokenUrl: "https://crates.io/settings/tokens/new",
4832
+ tokenUrlLabel: "crates.io"
4821
4833
  }
4822
4834
  };
4823
4835
  function loadTokensFromDb(registries) {
@@ -4831,6 +4843,7 @@ function loadTokensFromDb(registries) {
4831
4843
  }
4832
4844
  return tokens;
4833
4845
  }
4846
+ var NPM_AUTH_ENV_VAR = "npm_config_//registry.npmjs.org/:_authToken";
4834
4847
  function injectTokensToEnv(tokens) {
4835
4848
  const originals = {};
4836
4849
  for (const [registry, token] of Object.entries(tokens)) {
@@ -4838,6 +4851,10 @@ function injectTokensToEnv(tokens) {
4838
4851
  if (!config) continue;
4839
4852
  originals[config.envVar] = process.env[config.envVar];
4840
4853
  process.env[config.envVar] = token;
4854
+ if (registry === "npm") {
4855
+ originals[NPM_AUTH_ENV_VAR] = process.env[NPM_AUTH_ENV_VAR];
4856
+ process.env[NPM_AUTH_ENV_VAR] = token;
4857
+ }
4841
4858
  }
4842
4859
  return () => {
4843
4860
  for (const [envVar, original] of Object.entries(originals)) {
@@ -4863,10 +4880,18 @@ async function collectTokens(registries, task) {
4863
4880
  for (const registry of registries) {
4864
4881
  const config = TOKEN_CONFIG[registry];
4865
4882
  if (!config || tokens[registry]) continue;
4883
+ let { tokenUrl } = config;
4884
+ if (registry === "npm" && tokenUrl.includes("~")) {
4885
+ const result = await exec2("npm", ["whoami"]);
4886
+ const username = result.stdout.trim();
4887
+ if (username) tokenUrl = tokenUrl.replace("~", username);
4888
+ }
4866
4889
  task.output = `Enter ${config.promptLabel}`;
4867
4890
  const token = await task.prompt(ListrEnquirerPromptAdapter).run({
4868
4891
  type: "password",
4869
- message: `Enter ${config.promptLabel}`
4892
+ message: `Enter ${config.promptLabel}`,
4893
+ footer: `
4894
+ Generate a token from ${color.bold(link2(config.tokenUrlLabel, tokenUrl))}`
4870
4895
  });
4871
4896
  tokens[registry] = token;
4872
4897
  new Db().set(config.dbKey, token);
@@ -5617,12 +5642,6 @@ var RustEcosystem = class extends Ecosystem {
5617
5642
  }
5618
5643
  };
5619
5644
 
5620
- // src/utils/cli.ts
5621
- var warningBadge = color.bgYellow(" Warning ");
5622
- function link2(text, url) {
5623
- return `\x1B]8;;${url}\x07${text}\x1B]8;;\x07`;
5624
- }
5625
-
5626
5645
  // src/utils/crate-graph.ts
5627
5646
  async function sortCratesByDependencyOrder(cratePaths) {
5628
5647
  if (cratePaths.length <= 1) return cratePaths;
@@ -6230,7 +6249,7 @@ function getScope(packageName) {
6230
6249
  return packageName.match(/^@([^/]+)/)?.[1] ?? null;
6231
6250
  }
6232
6251
  function getScopeAndName(packageName) {
6233
- const matches = packageName.match(/^@([a-zA-Z0-9]+)\/([a-zA-Z0-9]+)$/);
6252
+ const matches = packageName.match(/^@([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_.-]+)$/);
6234
6253
  if (!matches) {
6235
6254
  throw new Error(
6236
6255
  `Invalid scoped package name: '${packageName}'. Expected format: @scope/name`
@@ -6275,7 +6294,7 @@ var JsrError = class extends AbstractError {
6275
6294
  function getApiEndpoint(registry) {
6276
6295
  const url = new URL(registry);
6277
6296
  url.host = `api.${url.host}`;
6278
- return `${url}`;
6297
+ return url.href.replace(/\/$/, "");
6279
6298
  }
6280
6299
  var JsrRegisry = class extends Registry {
6281
6300
  constructor(packageName, registry) {
@@ -6360,9 +6379,14 @@ ${stderr}` : ""}`,
6360
6379
  { throwOnError: true }
6361
6380
  );
6362
6381
  } catch (error) {
6363
- throw new JsrError("Failed to run `jsr publish --dry-run`", {
6364
- cause: error
6365
- });
6382
+ const stderr = error instanceof NonZeroExitError3 ? error.output?.stderr : void 0;
6383
+ throw new JsrError(
6384
+ `Failed to run \`jsr publish --dry-run\`${stderr ? `
6385
+ ${stderr}` : ""}`,
6386
+ {
6387
+ cause: error
6388
+ }
6389
+ );
6366
6390
  }
6367
6391
  }
6368
6392
  async version() {
@@ -6394,7 +6418,7 @@ ${stderr}` : ""}`,
6394
6418
  }
6395
6419
  }
6396
6420
  async hasPermission() {
6397
- return this.client.scopePermission(`${getScope(this.packageName)}`) !== null;
6421
+ return await this.client.scopePermission(`${getScope(this.packageName)}`) !== null;
6398
6422
  }
6399
6423
  async isPackageNameAvaliable() {
6400
6424
  return isValidPackageName(this.packageName);
@@ -6834,16 +6858,23 @@ ${stderr}` : ""}`,
6834
6858
  }
6835
6859
  if (stderr.includes("403") || stderr.includes("Forbidden")) {
6836
6860
  return new NpmError(
6837
- "Permission denied (403 Forbidden). Check your npm access token permissions.",
6861
+ `Permission denied (403 Forbidden). Check your npm access token permissions.${stderr ? `
6862
+ ${stderr}` : ""}`,
6838
6863
  { cause: error }
6839
6864
  );
6840
6865
  }
6841
6866
  if (stderr.includes("429") || stderr.includes("Too Many Requests")) {
6842
6867
  return new NpmError(
6843
- "Rate limited by npm registry. Please wait and try again.",
6868
+ `Rate limited by npm registry. Please wait and try again.${stderr ? `
6869
+ ${stderr}` : ""}`,
6844
6870
  { cause: error }
6845
6871
  );
6846
6872
  }
6873
+ return new NpmError(
6874
+ `Failed to publish to npm${stderr ? `
6875
+ ${stderr}` : ""}`,
6876
+ { cause: error }
6877
+ );
6847
6878
  }
6848
6879
  return new NpmError("Failed to publish to npm", { cause: error });
6849
6880
  }
@@ -7794,6 +7825,12 @@ async function run(options) {
7794
7825
  promptEnabled: !isCI2 && process14.stdin.isTTY
7795
7826
  };
7796
7827
  let cleanupEnv;
7828
+ const onSigint = async () => {
7829
+ cleanupEnv?.();
7830
+ await rollback();
7831
+ process14.exit(130);
7832
+ };
7833
+ process14.on("SIGINT", onSigint);
7797
7834
  try {
7798
7835
  if (options.contents) process14.chdir(options.contents);
7799
7836
  if (options.preflight) {
@@ -7885,9 +7922,14 @@ async function run(options) {
7885
7922
  try {
7886
7923
  rollbackLog("Resetting commits");
7887
7924
  await git.reset();
7888
- await git.stash();
7925
+ const dirty = await git.status() !== "";
7926
+ if (dirty) {
7927
+ await git.stash();
7928
+ }
7889
7929
  await git.reset("HEAD^", "--hard");
7890
- await git.popStash();
7930
+ if (dirty) {
7931
+ await git.popStash();
7932
+ }
7891
7933
  } catch (error) {
7892
7934
  rollbackError(
7893
7935
  `Failed to reset commits: ${error instanceof Error ? error.message : error}`
@@ -7984,6 +8026,7 @@ ${repositoryUrl}/compare/${lastRev}...${latestTag}`;
7984
8026
  parts.push(`${color.bold(name)} on ${color.red("crates.io")}`);
7985
8027
  }
7986
8028
  }
8029
+ process14.removeListener("SIGINT", onSigint);
7987
8030
  if (options.preflight) {
7988
8031
  cleanupEnv?.();
7989
8032
  console.log(
@@ -8001,6 +8044,7 @@ ${repositoryUrl}/compare/${lastRev}...${latestTag}`;
8001
8044
  );
8002
8045
  }
8003
8046
  } catch (e2) {
8047
+ process14.removeListener("SIGINT", onSigint);
8004
8048
  cleanupEnv?.();
8005
8049
  consoleError(e2);
8006
8050
  await rollback();
package/dist/index.cjs CHANGED
@@ -5405,19 +5405,25 @@ var TOKEN_CONFIG = {
5405
5405
  envVar: "NODE_AUTH_TOKEN",
5406
5406
  dbKey: "npm-token",
5407
5407
  ghSecretName: "NODE_AUTH_TOKEN",
5408
- promptLabel: "npm access token"
5408
+ promptLabel: "npm access token",
5409
+ tokenUrl: "https://www.npmjs.com/settings/~/tokens/granular-access-tokens/new",
5410
+ tokenUrlLabel: "npmjs.com"
5409
5411
  },
5410
5412
  jsr: {
5411
5413
  envVar: "JSR_TOKEN",
5412
5414
  dbKey: "jsr-token",
5413
5415
  ghSecretName: "JSR_TOKEN",
5414
- promptLabel: "jsr API token"
5416
+ promptLabel: "jsr API token",
5417
+ tokenUrl: "https://jsr.io/account/tokens/create",
5418
+ tokenUrlLabel: "jsr.io"
5415
5419
  },
5416
5420
  crates: {
5417
5421
  envVar: "CARGO_REGISTRY_TOKEN",
5418
5422
  dbKey: "cargo-token",
5419
5423
  ghSecretName: "CARGO_REGISTRY_TOKEN",
5420
- promptLabel: "crates.io API token"
5424
+ promptLabel: "crates.io API token",
5425
+ tokenUrl: "https://crates.io/settings/tokens/new",
5426
+ tokenUrlLabel: "crates.io"
5421
5427
  }
5422
5428
  };
5423
5429
  function loadTokensFromDb(registries) {
@@ -5431,6 +5437,7 @@ function loadTokensFromDb(registries) {
5431
5437
  }
5432
5438
  return tokens;
5433
5439
  }
5440
+ var NPM_AUTH_ENV_VAR = "npm_config_//registry.npmjs.org/:_authToken";
5434
5441
  function injectTokensToEnv(tokens) {
5435
5442
  const originals = {};
5436
5443
  for (const [registry, token] of Object.entries(tokens)) {
@@ -5438,6 +5445,10 @@ function injectTokensToEnv(tokens) {
5438
5445
  if (!config) continue;
5439
5446
  originals[config.envVar] = process.env[config.envVar];
5440
5447
  process.env[config.envVar] = token;
5448
+ if (registry === "npm") {
5449
+ originals[NPM_AUTH_ENV_VAR] = process.env[NPM_AUTH_ENV_VAR];
5450
+ process.env[NPM_AUTH_ENV_VAR] = token;
5451
+ }
5441
5452
  }
5442
5453
  return () => {
5443
5454
  for (const [envVar, original] of Object.entries(originals)) {
@@ -5693,7 +5704,7 @@ function getScope(packageName) {
5693
5704
  return packageName.match(/^@([^/]+)/)?.[1] ?? null;
5694
5705
  }
5695
5706
  function getScopeAndName(packageName) {
5696
- const matches = packageName.match(/^@([a-zA-Z0-9]+)\/([a-zA-Z0-9]+)$/);
5707
+ const matches = packageName.match(/^@([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_.-]+)$/);
5697
5708
  if (!matches) {
5698
5709
  throw new Error(
5699
5710
  `Invalid scoped package name: '${packageName}'. Expected format: @scope/name`
@@ -5739,7 +5750,7 @@ var JsrError = class extends AbstractError {
5739
5750
  function getApiEndpoint(registry) {
5740
5751
  const url = new URL(registry);
5741
5752
  url.host = `api.${url.host}`;
5742
- return `${url}`;
5753
+ return url.href.replace(/\/$/, "");
5743
5754
  }
5744
5755
  var JsrRegisry = class extends Registry {
5745
5756
  constructor(packageName, registry) {
@@ -5824,9 +5835,14 @@ ${stderr}` : ""}`,
5824
5835
  { throwOnError: true }
5825
5836
  );
5826
5837
  } catch (error) {
5827
- throw new JsrError("Failed to run `jsr publish --dry-run`", {
5828
- cause: error
5829
- });
5838
+ const stderr = error instanceof import_tinyexec5.NonZeroExitError ? error.output?.stderr : void 0;
5839
+ throw new JsrError(
5840
+ `Failed to run \`jsr publish --dry-run\`${stderr ? `
5841
+ ${stderr}` : ""}`,
5842
+ {
5843
+ cause: error
5844
+ }
5845
+ );
5830
5846
  }
5831
5847
  }
5832
5848
  async version() {
@@ -5858,7 +5874,7 @@ ${stderr}` : ""}`,
5858
5874
  }
5859
5875
  }
5860
5876
  async hasPermission() {
5861
- return this.client.scopePermission(`${getScope(this.packageName)}`) !== null;
5877
+ return await this.client.scopePermission(`${getScope(this.packageName)}`) !== null;
5862
5878
  }
5863
5879
  async isPackageNameAvaliable() {
5864
5880
  return isValidPackageName(this.packageName);
@@ -6298,16 +6314,23 @@ ${stderr}` : ""}`,
6298
6314
  }
6299
6315
  if (stderr.includes("403") || stderr.includes("Forbidden")) {
6300
6316
  return new NpmError(
6301
- "Permission denied (403 Forbidden). Check your npm access token permissions.",
6317
+ `Permission denied (403 Forbidden). Check your npm access token permissions.${stderr ? `
6318
+ ${stderr}` : ""}`,
6302
6319
  { cause: error }
6303
6320
  );
6304
6321
  }
6305
6322
  if (stderr.includes("429") || stderr.includes("Too Many Requests")) {
6306
6323
  return new NpmError(
6307
- "Rate limited by npm registry. Please wait and try again.",
6324
+ `Rate limited by npm registry. Please wait and try again.${stderr ? `
6325
+ ${stderr}` : ""}`,
6308
6326
  { cause: error }
6309
6327
  );
6310
6328
  }
6329
+ return new NpmError(
6330
+ `Failed to publish to npm${stderr ? `
6331
+ ${stderr}` : ""}`,
6332
+ { cause: error }
6333
+ );
6311
6334
  }
6312
6335
  return new NpmError("Failed to publish to npm", { cause: error });
6313
6336
  }
@@ -6841,10 +6864,18 @@ async function collectTokens(registries, task) {
6841
6864
  for (const registry of registries) {
6842
6865
  const config = TOKEN_CONFIG[registry];
6843
6866
  if (!config || tokens[registry]) continue;
6867
+ let { tokenUrl } = config;
6868
+ if (registry === "npm" && tokenUrl.includes("~")) {
6869
+ const result = await (0, import_tinyexec7.exec)("npm", ["whoami"]);
6870
+ const username = result.stdout.trim();
6871
+ if (username) tokenUrl = tokenUrl.replace("~", username);
6872
+ }
6844
6873
  task.output = `Enter ${config.promptLabel}`;
6845
6874
  const token = await task.prompt(import_prompt_adapter_enquirer4.ListrEnquirerPromptAdapter).run({
6846
6875
  type: "password",
6847
- message: `Enter ${config.promptLabel}`
6876
+ message: `Enter ${config.promptLabel}`,
6877
+ footer: `
6878
+ Generate a token from ${color.bold(link2(config.tokenUrlLabel, tokenUrl))}`
6848
6879
  });
6849
6880
  tokens[registry] = token;
6850
6881
  new Db().set(config.dbKey, token);
@@ -7333,6 +7364,12 @@ async function run(options) {
7333
7364
  promptEnabled: !import_std_env.isCI && import_node_process8.default.stdin.isTTY
7334
7365
  };
7335
7366
  let cleanupEnv;
7367
+ const onSigint = async () => {
7368
+ cleanupEnv?.();
7369
+ await rollback();
7370
+ import_node_process8.default.exit(130);
7371
+ };
7372
+ import_node_process8.default.on("SIGINT", onSigint);
7336
7373
  try {
7337
7374
  if (options.contents) import_node_process8.default.chdir(options.contents);
7338
7375
  if (options.preflight) {
@@ -7424,9 +7461,14 @@ async function run(options) {
7424
7461
  try {
7425
7462
  rollbackLog("Resetting commits");
7426
7463
  await git.reset();
7427
- await git.stash();
7464
+ const dirty = await git.status() !== "";
7465
+ if (dirty) {
7466
+ await git.stash();
7467
+ }
7428
7468
  await git.reset("HEAD^", "--hard");
7429
- await git.popStash();
7469
+ if (dirty) {
7470
+ await git.popStash();
7471
+ }
7430
7472
  } catch (error) {
7431
7473
  rollbackError(
7432
7474
  `Failed to reset commits: ${error instanceof Error ? error.message : error}`
@@ -7523,6 +7565,7 @@ ${repositoryUrl}/compare/${lastRev}...${latestTag}`;
7523
7565
  parts.push(`${color.bold(name)} on ${color.red("crates.io")}`);
7524
7566
  }
7525
7567
  }
7568
+ import_node_process8.default.removeListener("SIGINT", onSigint);
7526
7569
  if (options.preflight) {
7527
7570
  cleanupEnv?.();
7528
7571
  console.log(
@@ -7540,6 +7583,7 @@ ${repositoryUrl}/compare/${lastRev}...${latestTag}`;
7540
7583
  );
7541
7584
  }
7542
7585
  } catch (e2) {
7586
+ import_node_process8.default.removeListener("SIGINT", onSigint);
7543
7587
  cleanupEnv?.();
7544
7588
  consoleError(e2);
7545
7589
  await rollback();
package/dist/index.js CHANGED
@@ -5371,19 +5371,25 @@ var TOKEN_CONFIG = {
5371
5371
  envVar: "NODE_AUTH_TOKEN",
5372
5372
  dbKey: "npm-token",
5373
5373
  ghSecretName: "NODE_AUTH_TOKEN",
5374
- promptLabel: "npm access token"
5374
+ promptLabel: "npm access token",
5375
+ tokenUrl: "https://www.npmjs.com/settings/~/tokens/granular-access-tokens/new",
5376
+ tokenUrlLabel: "npmjs.com"
5375
5377
  },
5376
5378
  jsr: {
5377
5379
  envVar: "JSR_TOKEN",
5378
5380
  dbKey: "jsr-token",
5379
5381
  ghSecretName: "JSR_TOKEN",
5380
- promptLabel: "jsr API token"
5382
+ promptLabel: "jsr API token",
5383
+ tokenUrl: "https://jsr.io/account/tokens/create",
5384
+ tokenUrlLabel: "jsr.io"
5381
5385
  },
5382
5386
  crates: {
5383
5387
  envVar: "CARGO_REGISTRY_TOKEN",
5384
5388
  dbKey: "cargo-token",
5385
5389
  ghSecretName: "CARGO_REGISTRY_TOKEN",
5386
- promptLabel: "crates.io API token"
5390
+ promptLabel: "crates.io API token",
5391
+ tokenUrl: "https://crates.io/settings/tokens/new",
5392
+ tokenUrlLabel: "crates.io"
5387
5393
  }
5388
5394
  };
5389
5395
  function loadTokensFromDb(registries) {
@@ -5397,6 +5403,7 @@ function loadTokensFromDb(registries) {
5397
5403
  }
5398
5404
  return tokens;
5399
5405
  }
5406
+ var NPM_AUTH_ENV_VAR = "npm_config_//registry.npmjs.org/:_authToken";
5400
5407
  function injectTokensToEnv(tokens) {
5401
5408
  const originals = {};
5402
5409
  for (const [registry, token] of Object.entries(tokens)) {
@@ -5404,6 +5411,10 @@ function injectTokensToEnv(tokens) {
5404
5411
  if (!config) continue;
5405
5412
  originals[config.envVar] = process.env[config.envVar];
5406
5413
  process.env[config.envVar] = token;
5414
+ if (registry === "npm") {
5415
+ originals[NPM_AUTH_ENV_VAR] = process.env[NPM_AUTH_ENV_VAR];
5416
+ process.env[NPM_AUTH_ENV_VAR] = token;
5417
+ }
5407
5418
  }
5408
5419
  return () => {
5409
5420
  for (const [envVar, original] of Object.entries(originals)) {
@@ -5659,7 +5670,7 @@ function getScope(packageName) {
5659
5670
  return packageName.match(/^@([^/]+)/)?.[1] ?? null;
5660
5671
  }
5661
5672
  function getScopeAndName(packageName) {
5662
- const matches = packageName.match(/^@([a-zA-Z0-9]+)\/([a-zA-Z0-9]+)$/);
5673
+ const matches = packageName.match(/^@([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_.-]+)$/);
5663
5674
  if (!matches) {
5664
5675
  throw new Error(
5665
5676
  `Invalid scoped package name: '${packageName}'. Expected format: @scope/name`
@@ -5704,7 +5715,7 @@ var JsrError = class extends AbstractError {
5704
5715
  function getApiEndpoint(registry) {
5705
5716
  const url = new URL(registry);
5706
5717
  url.host = `api.${url.host}`;
5707
- return `${url}`;
5718
+ return url.href.replace(/\/$/, "");
5708
5719
  }
5709
5720
  var JsrRegisry = class extends Registry {
5710
5721
  constructor(packageName, registry) {
@@ -5789,9 +5800,14 @@ ${stderr}` : ""}`,
5789
5800
  { throwOnError: true }
5790
5801
  );
5791
5802
  } catch (error) {
5792
- throw new JsrError("Failed to run `jsr publish --dry-run`", {
5793
- cause: error
5794
- });
5803
+ const stderr = error instanceof NonZeroExitError3 ? error.output?.stderr : void 0;
5804
+ throw new JsrError(
5805
+ `Failed to run \`jsr publish --dry-run\`${stderr ? `
5806
+ ${stderr}` : ""}`,
5807
+ {
5808
+ cause: error
5809
+ }
5810
+ );
5795
5811
  }
5796
5812
  }
5797
5813
  async version() {
@@ -5823,7 +5839,7 @@ ${stderr}` : ""}`,
5823
5839
  }
5824
5840
  }
5825
5841
  async hasPermission() {
5826
- return this.client.scopePermission(`${getScope(this.packageName)}`) !== null;
5842
+ return await this.client.scopePermission(`${getScope(this.packageName)}`) !== null;
5827
5843
  }
5828
5844
  async isPackageNameAvaliable() {
5829
5845
  return isValidPackageName(this.packageName);
@@ -6263,16 +6279,23 @@ ${stderr}` : ""}`,
6263
6279
  }
6264
6280
  if (stderr.includes("403") || stderr.includes("Forbidden")) {
6265
6281
  return new NpmError(
6266
- "Permission denied (403 Forbidden). Check your npm access token permissions.",
6282
+ `Permission denied (403 Forbidden). Check your npm access token permissions.${stderr ? `
6283
+ ${stderr}` : ""}`,
6267
6284
  { cause: error }
6268
6285
  );
6269
6286
  }
6270
6287
  if (stderr.includes("429") || stderr.includes("Too Many Requests")) {
6271
6288
  return new NpmError(
6272
- "Rate limited by npm registry. Please wait and try again.",
6289
+ `Rate limited by npm registry. Please wait and try again.${stderr ? `
6290
+ ${stderr}` : ""}`,
6273
6291
  { cause: error }
6274
6292
  );
6275
6293
  }
6294
+ return new NpmError(
6295
+ `Failed to publish to npm${stderr ? `
6296
+ ${stderr}` : ""}`,
6297
+ { cause: error }
6298
+ );
6276
6299
  }
6277
6300
  return new NpmError("Failed to publish to npm", { cause: error });
6278
6301
  }
@@ -6806,10 +6829,18 @@ async function collectTokens(registries, task) {
6806
6829
  for (const registry of registries) {
6807
6830
  const config = TOKEN_CONFIG[registry];
6808
6831
  if (!config || tokens[registry]) continue;
6832
+ let { tokenUrl } = config;
6833
+ if (registry === "npm" && tokenUrl.includes("~")) {
6834
+ const result = await exec7("npm", ["whoami"]);
6835
+ const username = result.stdout.trim();
6836
+ if (username) tokenUrl = tokenUrl.replace("~", username);
6837
+ }
6809
6838
  task.output = `Enter ${config.promptLabel}`;
6810
6839
  const token = await task.prompt(ListrEnquirerPromptAdapter4).run({
6811
6840
  type: "password",
6812
- message: `Enter ${config.promptLabel}`
6841
+ message: `Enter ${config.promptLabel}`,
6842
+ footer: `
6843
+ Generate a token from ${color.bold(link2(config.tokenUrlLabel, tokenUrl))}`
6813
6844
  });
6814
6845
  tokens[registry] = token;
6815
6846
  new Db().set(config.dbKey, token);
@@ -7297,6 +7328,12 @@ async function run(options) {
7297
7328
  promptEnabled: !isCI2 && process10.stdin.isTTY
7298
7329
  };
7299
7330
  let cleanupEnv;
7331
+ const onSigint = async () => {
7332
+ cleanupEnv?.();
7333
+ await rollback();
7334
+ process10.exit(130);
7335
+ };
7336
+ process10.on("SIGINT", onSigint);
7300
7337
  try {
7301
7338
  if (options.contents) process10.chdir(options.contents);
7302
7339
  if (options.preflight) {
@@ -7388,9 +7425,14 @@ async function run(options) {
7388
7425
  try {
7389
7426
  rollbackLog("Resetting commits");
7390
7427
  await git.reset();
7391
- await git.stash();
7428
+ const dirty = await git.status() !== "";
7429
+ if (dirty) {
7430
+ await git.stash();
7431
+ }
7392
7432
  await git.reset("HEAD^", "--hard");
7393
- await git.popStash();
7433
+ if (dirty) {
7434
+ await git.popStash();
7435
+ }
7394
7436
  } catch (error) {
7395
7437
  rollbackError(
7396
7438
  `Failed to reset commits: ${error instanceof Error ? error.message : error}`
@@ -7487,6 +7529,7 @@ ${repositoryUrl}/compare/${lastRev}...${latestTag}`;
7487
7529
  parts.push(`${color.bold(name)} on ${color.red("crates.io")}`);
7488
7530
  }
7489
7531
  }
7532
+ process10.removeListener("SIGINT", onSigint);
7490
7533
  if (options.preflight) {
7491
7534
  cleanupEnv?.();
7492
7535
  console.log(
@@ -7504,6 +7547,7 @@ ${repositoryUrl}/compare/${lastRev}...${latestTag}`;
7504
7547
  );
7505
7548
  }
7506
7549
  } catch (e2) {
7550
+ process10.removeListener("SIGINT", onSigint);
7507
7551
  cleanupEnv?.();
7508
7552
  consoleError(e2);
7509
7553
  await rollback();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubm",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "engines": {
5
5
  "node": ">=18",
6
6
  "git": ">=2.11.0"