pubm 0.0.1 → 0.0.2-12

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,13 +5362,32 @@ 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
+ try {
5368
+ await this.npm(["publish", "--provenance", "--access", "public"]);
5369
+ } catch (error) {
5370
+ if (`${error}`.includes("EOTP")) {
5371
+ return false;
5372
+ }
5373
+ }
5374
+ return true;
5375
+ } catch (error) {
5376
+ throw new NpmError(
5377
+ "Failed to run `npm publish --provenance --access public`",
5378
+ {
5379
+ cause: error
5380
+ }
5381
+ );
5382
+ }
5383
+ }
5363
5384
  async publish(otp) {
5364
5385
  const args = otp ? ["publish", "--otp", otp] : ["publish"];
5365
5386
  try {
5366
5387
  try {
5367
5388
  await this.npm(args);
5368
5389
  } catch (error) {
5369
- if (`${error}`.includes("OTP")) {
5390
+ if (`${error}`.includes("EOTP")) {
5370
5391
  return false;
5371
5392
  }
5372
5393
  }
@@ -5410,18 +5431,27 @@ var jsrAvailableCheckTasks = {
5410
5431
  }, ctx);
5411
5432
  if (!JsrClient.token) {
5412
5433
  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: `
5434
+ if (ctx.promptEnabled) {
5435
+ while (true) {
5436
+ JsrClient.token = await task.prompt(ListrEnquirerPromptAdapter).run({
5437
+ type: "password",
5438
+ message: `Please enter the jsr ${color.bold("API token")}`,
5439
+ footer: `
5418
5440
  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 {
5441
+ });
5442
+ try {
5443
+ if (await jsr.client.user()) break;
5444
+ task.output = "The jsr API token is invalid. Please re-enter a valid token.";
5445
+ } catch {
5446
+ }
5424
5447
  }
5448
+ } else {
5449
+ const jsrTokenEnv = process8.env.JSR_TOKEN;
5450
+ if (!jsrTokenEnv)
5451
+ throw new JsrAvailableError(
5452
+ "JSR_TOKEN not found in the environment variables. Please set the token and try again."
5453
+ );
5454
+ JsrClient.token = jsrTokenEnv;
5425
5455
  }
5426
5456
  if (ctx.saveToken) new Db().set("jsr-token", JsrClient.token);
5427
5457
  }
@@ -5529,14 +5559,24 @@ More information: ${link2("npm naming rules", "https://github.com/npm/validate-n
5529
5559
  };
5530
5560
  var jsrPublishTasks = {
5531
5561
  title: "Running jsr publish",
5532
- task: async (_, task) => {
5562
+ task: async (ctx, task) => {
5533
5563
  const jsr = await jsrRegistry();
5534
5564
  task.output = "Publishing on jsr...";
5565
+ if (!JsrClient.token && !ctx.promptEnabled) {
5566
+ const jsrTokenEnv = process8.env.JSR_TOKEN;
5567
+ if (!jsrTokenEnv) {
5568
+ throw new JsrAvailableError(
5569
+ "JSR_TOKEN not found in the environment variables. Please set the token and try again."
5570
+ );
5571
+ }
5572
+ JsrClient.token = jsrTokenEnv;
5573
+ }
5535
5574
  await jsr.publish();
5536
5575
  }
5537
5576
  };
5538
5577
 
5539
5578
  // src/tasks/npm.ts
5579
+ import process9 from "node:process";
5540
5580
  import { ListrEnquirerPromptAdapter as ListrEnquirerPromptAdapter2 } from "@listr2/prompt-adapter-enquirer";
5541
5581
  var NpmAvailableError = class extends AbstractError {
5542
5582
  constructor(message, { cause } = {}) {
@@ -5569,24 +5609,39 @@ More information: ${link2("npm naming rules", "https://github.com/npm/validate-n
5569
5609
  var npmPublishTasks = {
5570
5610
  title: "Running npm publish",
5571
5611
  skip: (ctx) => !!ctx.preview,
5572
- task: async (_, task) => {
5612
+ task: async (ctx, task) => {
5573
5613
  const npm = await npmRegistry();
5574
5614
  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";
5615
+ if (ctx.promptEnabled) {
5616
+ let result = await npm.publish();
5617
+ if (!result) {
5618
+ task.title = "Running npm publish (OTP code needed)";
5619
+ while (!result) {
5620
+ result = await npm.publish(
5621
+ await task.prompt(ListrEnquirerPromptAdapter2).run({
5622
+ type: "password",
5623
+ message: "npm OTP code"
5624
+ })
5625
+ );
5626
+ if (!result) {
5627
+ task.output = "2FA failed";
5628
+ }
5587
5629
  }
5630
+ task.title = "Running npm publish (2FA passed)";
5631
+ }
5632
+ } else {
5633
+ const npmTokenEnv = process9.env.NODE_AUTH_TOKEN;
5634
+ if (!npmTokenEnv) {
5635
+ throw new NpmAvailableError(
5636
+ "NODE_AUTH_TOKEN not found in the environment variables. Please set the token and try again."
5637
+ );
5638
+ }
5639
+ const result = await npm.publishProvenance();
5640
+ if (!result) {
5641
+ throw new NpmAvailableError(
5642
+ `In CI environment, publishing with 2FA is not allowed. Please disable 2FA when accessing with a token from ${link2("npm", `https://www.npmjs.com/package/${npm.packageName}/access`)}.`
5643
+ );
5588
5644
  }
5589
- task.title = "Running npm publish (2FA passed)";
5590
5645
  }
5591
5646
  }
5592
5647
  };
@@ -5914,88 +5969,23 @@ async function run(options2) {
5914
5969
  const git = new Git();
5915
5970
  const ctx = {
5916
5971
  ...options2,
5972
+ promptEnabled: !isCI2 && process10.stdin.isTTY,
5917
5973
  npmOnly: options2.registries.every((registry) => registry !== "jsr"),
5918
5974
  jsrOnly: options2.registries.every((registry) => registry === "jsr"),
5919
5975
  lastRev: await git.latestTag() || await git.firstCommit()
5920
5976
  };
5921
5977
  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,
5978
+ if (options2.contents) process10.chdir(options2.contents);
5979
+ if (!options2.publishOnly) {
5980
+ await prerequisitesCheckTask({
5981
+ skip: options2.skipPrerequisitesCheck
5982
+ }).run(ctx);
5983
+ await requiredConditionsCheckTask({
5984
+ skip: options2.skipConditionsCheck
5985
+ }).run(ctx);
5986
+ }
5987
+ await createListr(
5988
+ options2.publishOnly ? {
5999
5989
  title: "Publishing",
6000
5990
  task: (ctx2, parentTask) => parentTask.newListr(
6001
5991
  ctx2.registries.map((registry) => {
@@ -6010,46 +6000,133 @@ async function run(options2) {
6010
6000
  }),
6011
6001
  { concurrent: true }
6012
6002
  )
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");
6003
+ } : [
6004
+ {
6005
+ skip: options2.skipTests,
6006
+ title: "Running tests",
6007
+ task: async (ctx2) => {
6008
+ const packageManager = await getPackageManager();
6009
+ const { stderr } = await exec6(packageManager, [
6010
+ "run",
6011
+ ctx2.testScript
6012
+ ]);
6013
+ if (stderr) {
6014
+ throw new AbstractError(
6015
+ `Failed to run \`${packageManager} run ${ctx2.testScript}\``,
6016
+ { cause: stderr }
6017
+ );
6018
+ }
6023
6019
  }
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 += `
6020
+ },
6021
+ {
6022
+ skip: options2.skipBuild,
6023
+ title: "Building the project",
6024
+ task: async (ctx2) => {
6025
+ const packageManager = await getPackageManager();
6026
+ try {
6027
+ await exec6(packageManager, ["run", ctx2.buildScript], {
6028
+ throwOnError: true
6029
+ });
6030
+ } catch (error) {
6031
+ throw new AbstractError(
6032
+ `Failed to run \`${packageManager} run ${ctx2.buildScript}\``,
6033
+ { cause: error }
6034
+ );
6035
+ }
6036
+ }
6037
+ },
6038
+ {
6039
+ title: "Bumping version",
6040
+ skip: (ctx2) => !!ctx2.preview,
6041
+ task: async (ctx2, task) => {
6042
+ const git2 = new Git();
6043
+ let tagCreated = false;
6044
+ let commited = false;
6045
+ addRollback(async () => {
6046
+ if (tagCreated) {
6047
+ console.log("Deleting tag...");
6048
+ await git2.deleteTag(`${await git2.latestTag()}`);
6049
+ }
6050
+ if (commited) {
6051
+ console.log("Reset commits...");
6052
+ await git2.reset();
6053
+ await git2.stash();
6054
+ await git2.reset("HEAD^", "--hard");
6055
+ await git2.popStash();
6056
+ }
6057
+ }, ctx2);
6058
+ await git2.reset();
6059
+ const replaced = await replaceVersion(ctx2.version);
6060
+ for (const replacedFile of replaced) {
6061
+ await git2.stage(replacedFile);
6062
+ }
6063
+ const nextVersion = `v${ctx2.version}`;
6064
+ const commit = await git2.commit(nextVersion);
6065
+ commited = true;
6066
+ task.output = "Creating tag...";
6067
+ await git2.createTag(nextVersion, commit);
6068
+ tagCreated = true;
6069
+ }
6070
+ },
6071
+ {
6072
+ skip: (ctx2) => options2.skipPublish || !!ctx2.preview,
6073
+ title: "Publishing",
6074
+ task: (ctx2, parentTask) => parentTask.newListr(
6075
+ ctx2.registries.map((registry) => {
6076
+ switch (registry) {
6077
+ case "npm":
6078
+ return npmPublishTasks;
6079
+ case "jsr":
6080
+ return jsrPublishTasks;
6081
+ default:
6082
+ return npmPublishTasks;
6083
+ }
6084
+ }),
6085
+ { concurrent: true }
6086
+ )
6087
+ },
6088
+ {
6089
+ title: "Pushing tags to GitHub",
6090
+ skip: (ctx2) => !!ctx2.preview,
6091
+ task: async (_, task) => {
6092
+ const git2 = new Git();
6093
+ const result = await git2.push("--follow-tags");
6094
+ if (!result) {
6095
+ task.title += " (Only tags were pushed because the release branch is protected. Please push the branch manually.)";
6096
+ await git2.push("--tags");
6097
+ }
6098
+ }
6099
+ },
6100
+ {
6101
+ skip: (ctx2) => options2.skipReleaseDraft || !!ctx2.preview,
6102
+ title: "Creating release draft on GitHub",
6103
+ task: async (ctx2, task) => {
6104
+ const git2 = new Git();
6105
+ const repositoryUrl = await git2.repository();
6106
+ const commits = (await git2.commits(ctx2.lastRev, `${await git2.latestTag()}`)).slice(1);
6107
+ const latestTag = await git2.latestTag();
6108
+ let body = commits.map(
6109
+ ({ id, message }) => `- ${message.replace("#", `${repositoryUrl}/issues/`)} ${repositoryUrl}/commit/${id}`
6110
+ ).join("\n");
6111
+ body += `
6038
6112
 
6039
6113
  ${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());
6114
+ const releaseDraftUrl = new URL(
6115
+ `${repositoryUrl}/releases/new`
6116
+ );
6117
+ releaseDraftUrl.searchParams.set("tag", `${latestTag}`);
6118
+ releaseDraftUrl.searchParams.set("body", body);
6119
+ releaseDraftUrl.searchParams.set(
6120
+ "prerelease",
6121
+ `${!!prerelease(ctx2.version)}`
6122
+ );
6123
+ const linkUrl = link2("Link", releaseDraftUrl.toString());
6124
+ task.title += ` ${linkUrl}`;
6125
+ await open(releaseDraftUrl.toString());
6126
+ }
6050
6127
  }
6051
- }
6052
- ]).run(ctx);
6128
+ ]
6129
+ ).run(ctx);
6053
6130
  const npmPackageName = (await getPackageJson()).name;
6054
6131
  const jsrPackageName = (await getJsrJson()).name;
6055
6132
  console.log(
@@ -6061,7 +6138,7 @@ ${repositoryUrl}/compare/${ctx2.lastRev}...${latestTag}`;
6061
6138
  } catch (e2) {
6062
6139
  consoleError(e2);
6063
6140
  await rollback();
6064
- process8.exit(1);
6141
+ process10.exit(1);
6065
6142
  }
6066
6143
  }
6067
6144
 
@@ -6202,7 +6279,8 @@ Update available! \`${name}\` ${color.red(currentVersion)} \u2192 ${color.green(
6202
6279
  }
6203
6280
 
6204
6281
  // src/cli.ts
6205
- var { RELEASE_TYPES: RELEASE_TYPES2 } = semver2;
6282
+ import { isCI as isCI3 } from "std-env";
6283
+ var { RELEASE_TYPES: RELEASE_TYPES2, valid } = semver2;
6206
6284
  var options = [
6207
6285
  {
6208
6286
  rawName: "--test-script <script>",
@@ -6259,6 +6337,11 @@ var options = [
6259
6337
  description: "Skip creating a GitHub release draft",
6260
6338
  options: { type: Boolean }
6261
6339
  },
6340
+ {
6341
+ rawName: "--publish-only",
6342
+ description: "Run only publish task for latest tag",
6343
+ options: { type: Boolean }
6344
+ },
6262
6345
  {
6263
6346
  rawName: "-t, --tag <name>",
6264
6347
  description: "Publish under a specific dist-tag",
@@ -6298,13 +6381,37 @@ function resolveCliOptions(options2) {
6298
6381
  }
6299
6382
  cli.command("[version]").action(async (nextVersion, options2) => {
6300
6383
  console.clear();
6301
- await notifyNewVersion();
6384
+ if (!isCI3) {
6385
+ await notifyNewVersion();
6386
+ }
6302
6387
  const context = {
6303
6388
  version: nextVersion,
6304
6389
  tag: options2.tag
6305
6390
  };
6306
6391
  try {
6307
- await requiredMissingInformationTasks().run(context);
6392
+ if (isCI3) {
6393
+ if (options2.publishOnly) {
6394
+ const git = new Git();
6395
+ const latestVersion = (await git.latestTag())?.slice(1);
6396
+ if (!latestVersion) {
6397
+ throw new Error(
6398
+ "Cannot find the latest tag. Please ensure tags exist in the repository."
6399
+ );
6400
+ }
6401
+ if (!valid(latestVersion)) {
6402
+ throw new Error(
6403
+ "Cannot parse the latest tag to a valid SemVer version. Please check the tag format."
6404
+ );
6405
+ }
6406
+ context.version = latestVersion;
6407
+ } else {
6408
+ throw new Error(
6409
+ "Version must be set in the CI environment. Please define the version before proceeding."
6410
+ );
6411
+ }
6412
+ } else {
6413
+ await requiredMissingInformationTasks().run(context);
6414
+ }
6308
6415
  await pubm(
6309
6416
  resolveCliOptions({
6310
6417
  ...options2,