pubm 0.0.1 → 0.0.2-1

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
@@ -713,7 +713,7 @@ var init_mjs = __esm({
713
713
  "node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js"() {
714
714
  "use strict";
715
715
  init_signals();
716
- processOk = (process9) => !!process9 && typeof process9 === "object" && typeof process9.removeListener === "function" && typeof process9.emit === "function" && typeof process9.reallyExit === "function" && typeof process9.listeners === "function" && typeof process9.kill === "function" && typeof process9.pid === "number" && typeof process9.on === "function";
716
+ processOk = (process11) => !!process11 && typeof process11 === "object" && typeof process11.removeListener === "function" && typeof process11.emit === "function" && typeof process11.reallyExit === "function" && typeof process11.listeners === "function" && typeof process11.kill === "function" && typeof process11.pid === "number" && typeof process11.on === "function";
717
717
  kExitEmitter = Symbol.for("signal-exit emitter");
718
718
  global = globalThis;
719
719
  ObjectDefineProperty = Object.defineProperty.bind(Object);
@@ -795,7 +795,7 @@ var init_mjs = __esm({
795
795
  }
796
796
  };
797
797
  SignalExit = class extends SignalExitBase {
798
- constructor(process9) {
798
+ constructor(process11) {
799
799
  super();
800
800
  __privateAdd(this, _SignalExit_instances);
801
801
  // "SIGHUP" throws an `ENOSYS` error on Windows,
@@ -809,13 +809,13 @@ var init_mjs = __esm({
809
809
  __privateAdd(this, _originalProcessReallyExit);
810
810
  __privateAdd(this, _sigListeners, {});
811
811
  __privateAdd(this, _loaded, false);
812
- __privateSet(this, _process, process9);
812
+ __privateSet(this, _process, process11);
813
813
  __privateSet(this, _sigListeners, {});
814
814
  for (const sig of signals) {
815
815
  __privateGet(this, _sigListeners)[sig] = () => {
816
816
  const listeners = __privateGet(this, _process).listeners(sig);
817
817
  let { count } = __privateGet(this, _emitter);
818
- const p = process9;
818
+ const p = process11;
819
819
  if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") {
820
820
  count += p.__signal_exit_emitter__.count;
821
821
  }
@@ -824,12 +824,12 @@ var init_mjs = __esm({
824
824
  const ret = __privateGet(this, _emitter).emit("exit", null, sig);
825
825
  const s = sig === "SIGHUP" ? __privateGet(this, _hupSig) : sig;
826
826
  if (!ret)
827
- process9.kill(process9.pid, s);
827
+ process11.kill(process11.pid, s);
828
828
  }
829
829
  };
830
830
  }
831
- __privateSet(this, _originalProcessReallyExit, process9.reallyExit);
832
- __privateSet(this, _originalProcessEmit, process9.emit);
831
+ __privateSet(this, _originalProcessReallyExit, process11.reallyExit);
832
+ __privateSet(this, _originalProcessEmit, process11.emit);
833
833
  }
834
834
  onExit(cb, opts) {
835
835
  if (!processOk(__privateGet(this, _process))) {
@@ -4411,9 +4411,10 @@ function resolveOptions(options2) {
4411
4411
  }
4412
4412
 
4413
4413
  // src/tasks/runner.ts
4414
- import process8 from "node:process";
4414
+ import process10 from "node:process";
4415
4415
  import npmCli from "@npmcli/promise-spawn";
4416
4416
  import SemVer from "semver";
4417
+ import { isCI as isCI2 } from "std-env";
4417
4418
  import { exec as exec6 } from "tinyexec";
4418
4419
 
4419
4420
  // src/git.ts
@@ -4904,6 +4905,7 @@ async function getPackageManager() {
4904
4905
  }
4905
4906
 
4906
4907
  // src/tasks/jsr.ts
4908
+ import process8 from "node:process";
4907
4909
  import { ListrEnquirerPromptAdapter } from "@listr2/prompt-adapter-enquirer";
4908
4910
 
4909
4911
  // src/registry/jsr.ts
@@ -5360,6 +5362,19 @@ var NpmRegistry = class extends Registry {
5360
5362
  throw new NpmError("Failed to run `npm ping`", { cause: error });
5361
5363
  }
5362
5364
  }
5365
+ async publishProvenance() {
5366
+ try {
5367
+ await this.npm(["publish", "--provenance", "--access", "public"]);
5368
+ return true;
5369
+ } catch (error) {
5370
+ throw new NpmError(
5371
+ "Failed to run `npm publish --provenance --access public`",
5372
+ {
5373
+ cause: error
5374
+ }
5375
+ );
5376
+ }
5377
+ }
5363
5378
  async publish(otp) {
5364
5379
  const args = otp ? ["publish", "--otp", otp] : ["publish"];
5365
5380
  try {
@@ -5410,18 +5425,27 @@ var jsrAvailableCheckTasks = {
5410
5425
  }, ctx);
5411
5426
  if (!JsrClient.token) {
5412
5427
  task.output = "Retrieving jsr API token";
5413
- while (true) {
5414
- JsrClient.token = await task.prompt(ListrEnquirerPromptAdapter).run({
5415
- type: "password",
5416
- message: `Please enter the jsr ${color.bold("API token")}`,
5417
- footer: `
5428
+ if (ctx.promptEnabled) {
5429
+ while (true) {
5430
+ JsrClient.token = await task.prompt(ListrEnquirerPromptAdapter).run({
5431
+ type: "password",
5432
+ message: `Please enter the jsr ${color.bold("API token")}`,
5433
+ footer: `
5418
5434
  Generate a token from ${color.bold(link2("jsr.io", "https://jsr.io/account/tokens/create/"))}. ${color.red("You should select")} ${color.bold("'Interact with the JSR API'")}.`
5419
- });
5420
- try {
5421
- if (await jsr.client.user()) break;
5422
- task.output = "The jsr API token is invalid. Please re-enter a valid token.";
5423
- } catch {
5435
+ });
5436
+ try {
5437
+ if (await jsr.client.user()) break;
5438
+ task.output = "The jsr API token is invalid. Please re-enter a valid token.";
5439
+ } catch {
5440
+ }
5424
5441
  }
5442
+ } else {
5443
+ const jsrTokenEnv = process8.env.JSR_TOKEN;
5444
+ if (!jsrTokenEnv)
5445
+ throw new JsrAvailableError(
5446
+ "JSR_TOKEN not found in the environment variables. Please set the token and try again."
5447
+ );
5448
+ JsrClient.token = jsrTokenEnv;
5425
5449
  }
5426
5450
  if (ctx.saveToken) new Db().set("jsr-token", JsrClient.token);
5427
5451
  }
@@ -5529,14 +5553,24 @@ More information: ${link2("npm naming rules", "https://github.com/npm/validate-n
5529
5553
  };
5530
5554
  var jsrPublishTasks = {
5531
5555
  title: "Running jsr publish",
5532
- task: async (_, task) => {
5556
+ task: async (ctx, task) => {
5533
5557
  const jsr = await jsrRegistry();
5534
5558
  task.output = "Publishing on jsr...";
5559
+ if (!JsrClient.token && !ctx.promptEnabled) {
5560
+ const jsrTokenEnv = process8.env.JSR_TOKEN;
5561
+ if (!jsrTokenEnv) {
5562
+ throw new JsrAvailableError(
5563
+ "JSR_TOKEN not found in the environment variables. Please set the token and try again."
5564
+ );
5565
+ }
5566
+ JsrClient.token = jsrTokenEnv;
5567
+ }
5535
5568
  await jsr.publish();
5536
5569
  }
5537
5570
  };
5538
5571
 
5539
5572
  // src/tasks/npm.ts
5573
+ import process9 from "node:process";
5540
5574
  import { ListrEnquirerPromptAdapter as ListrEnquirerPromptAdapter2 } from "@listr2/prompt-adapter-enquirer";
5541
5575
  var NpmAvailableError = class extends AbstractError {
5542
5576
  constructor(message, { cause } = {}) {
@@ -5569,24 +5603,34 @@ More information: ${link2("npm naming rules", "https://github.com/npm/validate-n
5569
5603
  var npmPublishTasks = {
5570
5604
  title: "Running npm publish",
5571
5605
  skip: (ctx) => !!ctx.preview,
5572
- task: async (_, task) => {
5606
+ task: async (ctx, task) => {
5573
5607
  const npm = await npmRegistry();
5574
5608
  task.output = "Publishing on npm...";
5575
- let result = await npm.publish();
5576
- if (!result) {
5577
- task.title = "Running npm publish (OTP code needed)";
5578
- while (!result) {
5579
- result = await npm.publish(
5580
- await task.prompt(ListrEnquirerPromptAdapter2).run({
5581
- type: "password",
5582
- message: "npm OTP code"
5583
- })
5584
- );
5585
- if (!result) {
5586
- task.output = "2FA failed";
5609
+ if (ctx.promptEnabled) {
5610
+ let result = await npm.publish();
5611
+ if (!result) {
5612
+ task.title = "Running npm publish (OTP code needed)";
5613
+ while (!result) {
5614
+ result = await npm.publish(
5615
+ await task.prompt(ListrEnquirerPromptAdapter2).run({
5616
+ type: "password",
5617
+ message: "npm OTP code"
5618
+ })
5619
+ );
5620
+ if (!result) {
5621
+ task.output = "2FA failed";
5622
+ }
5587
5623
  }
5624
+ task.title = "Running npm publish (2FA passed)";
5625
+ }
5626
+ } else {
5627
+ const npmTokenEnv = process9.env.NODE_AUTH_TOKEN;
5628
+ if (!npmTokenEnv) {
5629
+ throw new NpmAvailableError(
5630
+ "NODE_AUTH_TOKEN not found in the environment variables. Please set the token and try again."
5631
+ );
5588
5632
  }
5589
- task.title = "Running npm publish (2FA passed)";
5633
+ await npm.publishProvenance();
5590
5634
  }
5591
5635
  }
5592
5636
  };
@@ -5914,88 +5958,23 @@ async function run(options2) {
5914
5958
  const git = new Git();
5915
5959
  const ctx = {
5916
5960
  ...options2,
5961
+ promptEnabled: !isCI2 && process10.stdin.isTTY,
5917
5962
  npmOnly: options2.registries.every((registry) => registry !== "jsr"),
5918
5963
  jsrOnly: options2.registries.every((registry) => registry === "jsr"),
5919
5964
  lastRev: await git.latestTag() || await git.firstCommit()
5920
5965
  };
5921
5966
  try {
5922
- if (options2.contents) process8.chdir(options2.contents);
5923
- await prerequisitesCheckTask({ skip: options2.skipPrerequisitesCheck }).run(
5924
- ctx
5925
- );
5926
- await requiredConditionsCheckTask({
5927
- skip: options2.skipConditionsCheck
5928
- }).run(ctx);
5929
- await createListr([
5930
- {
5931
- skip: options2.skipTests,
5932
- title: "Running tests",
5933
- task: async (ctx2) => {
5934
- const packageManager = await getPackageManager();
5935
- const { stderr } = await exec6(packageManager, [
5936
- "run",
5937
- ctx2.testScript
5938
- ]);
5939
- if (stderr) {
5940
- throw new AbstractError(
5941
- `Failed to run \`${packageManager} run ${ctx2.testScript}\``,
5942
- { cause: stderr }
5943
- );
5944
- }
5945
- }
5946
- },
5947
- {
5948
- skip: options2.skipBuild,
5949
- title: "Building the project",
5950
- task: async (ctx2) => {
5951
- const packageManager = await getPackageManager();
5952
- try {
5953
- await exec6(packageManager, ["run", ctx2.buildScript], {
5954
- throwOnError: true
5955
- });
5956
- } catch (error) {
5957
- throw new AbstractError(
5958
- `Failed to run \`${packageManager} run ${ctx2.buildScript}\``,
5959
- { cause: error }
5960
- );
5961
- }
5962
- }
5963
- },
5964
- {
5965
- title: "Bumping version",
5966
- skip: (ctx2) => !!ctx2.preview,
5967
- task: async (ctx2, task) => {
5968
- const git2 = new Git();
5969
- let tagCreated = false;
5970
- let commited = false;
5971
- addRollback(async () => {
5972
- if (tagCreated) {
5973
- console.log("Deleting tag...");
5974
- await git2.deleteTag(`${await git2.latestTag()}`);
5975
- }
5976
- if (commited) {
5977
- console.log("Reset commits...");
5978
- await git2.reset();
5979
- await git2.stash();
5980
- await git2.reset("HEAD^", "--hard");
5981
- await git2.popStash();
5982
- }
5983
- }, ctx2);
5984
- await git2.reset();
5985
- const replaced = await replaceVersion(ctx2.version);
5986
- for (const replacedFile of replaced) {
5987
- await git2.stage(replacedFile);
5988
- }
5989
- const nextVersion = `v${ctx2.version}`;
5990
- const commit = await git2.commit(nextVersion);
5991
- commited = true;
5992
- task.output = "Creating tag...";
5993
- await git2.createTag(nextVersion, commit);
5994
- tagCreated = true;
5995
- }
5996
- },
5997
- {
5998
- skip: (ctx2) => options2.skipPublish || !!ctx2.preview,
5967
+ if (options2.contents) process10.chdir(options2.contents);
5968
+ if (!options2.publishOnly) {
5969
+ await prerequisitesCheckTask({
5970
+ skip: options2.skipPrerequisitesCheck
5971
+ }).run(ctx);
5972
+ await requiredConditionsCheckTask({
5973
+ skip: options2.skipConditionsCheck
5974
+ }).run(ctx);
5975
+ }
5976
+ await createListr(
5977
+ options2.publishOnly ? {
5999
5978
  title: "Publishing",
6000
5979
  task: (ctx2, parentTask) => parentTask.newListr(
6001
5980
  ctx2.registries.map((registry) => {
@@ -6010,46 +5989,133 @@ async function run(options2) {
6010
5989
  }),
6011
5990
  { concurrent: true }
6012
5991
  )
6013
- },
6014
- {
6015
- title: "Pushing tags to GitHub",
6016
- skip: (ctx2) => !!ctx2.preview,
6017
- task: async (_, task) => {
6018
- const git2 = new Git();
6019
- const result = await git2.push("--follow-tags");
6020
- if (!result) {
6021
- task.title += " (Only tags were pushed because the release branch is protected. Please push the branch manually.)";
6022
- await git2.push("--tags");
5992
+ } : [
5993
+ {
5994
+ skip: options2.skipTests,
5995
+ title: "Running tests",
5996
+ task: async (ctx2) => {
5997
+ const packageManager = await getPackageManager();
5998
+ const { stderr } = await exec6(packageManager, [
5999
+ "run",
6000
+ ctx2.testScript
6001
+ ]);
6002
+ if (stderr) {
6003
+ throw new AbstractError(
6004
+ `Failed to run \`${packageManager} run ${ctx2.testScript}\``,
6005
+ { cause: stderr }
6006
+ );
6007
+ }
6023
6008
  }
6024
- }
6025
- },
6026
- {
6027
- skip: (ctx2) => options2.skipReleaseDraft || !!ctx2.preview,
6028
- title: "Creating release draft on GitHub",
6029
- task: async (ctx2, task) => {
6030
- const git2 = new Git();
6031
- const repositoryUrl = await git2.repository();
6032
- const commits = (await git2.commits(ctx2.lastRev, `${await git2.latestTag()}`)).slice(1);
6033
- const latestTag = await git2.latestTag();
6034
- let body = commits.map(
6035
- ({ id, message }) => `- ${message.replace("#", `${repositoryUrl}/issues/`)} ${repositoryUrl}/commit/${id}`
6036
- ).join("\n");
6037
- body += `
6009
+ },
6010
+ {
6011
+ skip: options2.skipBuild,
6012
+ title: "Building the project",
6013
+ task: async (ctx2) => {
6014
+ const packageManager = await getPackageManager();
6015
+ try {
6016
+ await exec6(packageManager, ["run", ctx2.buildScript], {
6017
+ throwOnError: true
6018
+ });
6019
+ } catch (error) {
6020
+ throw new AbstractError(
6021
+ `Failed to run \`${packageManager} run ${ctx2.buildScript}\``,
6022
+ { cause: error }
6023
+ );
6024
+ }
6025
+ }
6026
+ },
6027
+ {
6028
+ title: "Bumping version",
6029
+ skip: (ctx2) => !!ctx2.preview,
6030
+ task: async (ctx2, task) => {
6031
+ const git2 = new Git();
6032
+ let tagCreated = false;
6033
+ let commited = false;
6034
+ addRollback(async () => {
6035
+ if (tagCreated) {
6036
+ console.log("Deleting tag...");
6037
+ await git2.deleteTag(`${await git2.latestTag()}`);
6038
+ }
6039
+ if (commited) {
6040
+ console.log("Reset commits...");
6041
+ await git2.reset();
6042
+ await git2.stash();
6043
+ await git2.reset("HEAD^", "--hard");
6044
+ await git2.popStash();
6045
+ }
6046
+ }, ctx2);
6047
+ await git2.reset();
6048
+ const replaced = await replaceVersion(ctx2.version);
6049
+ for (const replacedFile of replaced) {
6050
+ await git2.stage(replacedFile);
6051
+ }
6052
+ const nextVersion = `v${ctx2.version}`;
6053
+ const commit = await git2.commit(nextVersion);
6054
+ commited = true;
6055
+ task.output = "Creating tag...";
6056
+ await git2.createTag(nextVersion, commit);
6057
+ tagCreated = true;
6058
+ }
6059
+ },
6060
+ {
6061
+ skip: (ctx2) => options2.skipPublish || !!ctx2.preview,
6062
+ title: "Publishing",
6063
+ task: (ctx2, parentTask) => parentTask.newListr(
6064
+ ctx2.registries.map((registry) => {
6065
+ switch (registry) {
6066
+ case "npm":
6067
+ return npmPublishTasks;
6068
+ case "jsr":
6069
+ return jsrPublishTasks;
6070
+ default:
6071
+ return npmPublishTasks;
6072
+ }
6073
+ }),
6074
+ { concurrent: true }
6075
+ )
6076
+ },
6077
+ {
6078
+ title: "Pushing tags to GitHub",
6079
+ skip: (ctx2) => !!ctx2.preview,
6080
+ task: async (_, task) => {
6081
+ const git2 = new Git();
6082
+ const result = await git2.push("--follow-tags");
6083
+ if (!result) {
6084
+ task.title += " (Only tags were pushed because the release branch is protected. Please push the branch manually.)";
6085
+ await git2.push("--tags");
6086
+ }
6087
+ }
6088
+ },
6089
+ {
6090
+ skip: (ctx2) => options2.skipReleaseDraft || !!ctx2.preview,
6091
+ title: "Creating release draft on GitHub",
6092
+ task: async (ctx2, task) => {
6093
+ const git2 = new Git();
6094
+ const repositoryUrl = await git2.repository();
6095
+ const commits = (await git2.commits(ctx2.lastRev, `${await git2.latestTag()}`)).slice(1);
6096
+ const latestTag = await git2.latestTag();
6097
+ let body = commits.map(
6098
+ ({ id, message }) => `- ${message.replace("#", `${repositoryUrl}/issues/`)} ${repositoryUrl}/commit/${id}`
6099
+ ).join("\n");
6100
+ body += `
6038
6101
 
6039
6102
  ${repositoryUrl}/compare/${ctx2.lastRev}...${latestTag}`;
6040
- const releaseDraftUrl = new URL(`${repositoryUrl}/releases/new`);
6041
- releaseDraftUrl.searchParams.set("tag", `${latestTag}`);
6042
- releaseDraftUrl.searchParams.set("body", body);
6043
- releaseDraftUrl.searchParams.set(
6044
- "prerelease",
6045
- `${!!prerelease(ctx2.version)}`
6046
- );
6047
- const linkUrl = link2("Link", releaseDraftUrl.toString());
6048
- task.title += ` ${linkUrl}`;
6049
- await open(releaseDraftUrl.toString());
6103
+ const releaseDraftUrl = new URL(
6104
+ `${repositoryUrl}/releases/new`
6105
+ );
6106
+ releaseDraftUrl.searchParams.set("tag", `${latestTag}`);
6107
+ releaseDraftUrl.searchParams.set("body", body);
6108
+ releaseDraftUrl.searchParams.set(
6109
+ "prerelease",
6110
+ `${!!prerelease(ctx2.version)}`
6111
+ );
6112
+ const linkUrl = link2("Link", releaseDraftUrl.toString());
6113
+ task.title += ` ${linkUrl}`;
6114
+ await open(releaseDraftUrl.toString());
6115
+ }
6050
6116
  }
6051
- }
6052
- ]).run(ctx);
6117
+ ]
6118
+ ).run(ctx);
6053
6119
  const npmPackageName = (await getPackageJson()).name;
6054
6120
  const jsrPackageName = (await getJsrJson()).name;
6055
6121
  console.log(
@@ -6061,7 +6127,7 @@ ${repositoryUrl}/compare/${ctx2.lastRev}...${latestTag}`;
6061
6127
  } catch (e2) {
6062
6128
  consoleError(e2);
6063
6129
  await rollback();
6064
- process8.exit(1);
6130
+ process10.exit(1);
6065
6131
  }
6066
6132
  }
6067
6133
 
@@ -6259,6 +6325,11 @@ var options = [
6259
6325
  description: "Skip creating a GitHub release draft",
6260
6326
  options: { type: Boolean }
6261
6327
  },
6328
+ {
6329
+ rawName: "--publish-only",
6330
+ description: "Run only publish task for latest tag",
6331
+ options: { type: Boolean }
6332
+ },
6262
6333
  {
6263
6334
  rawName: "-t, --tag <name>",
6264
6335
  description: "Publish under a specific dist-tag",