pubm 0.0.5 → 0.1.3

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/dist/index.cjs 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 = (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";
716
+ processOk = (process16) => !!process16 && typeof process16 === "object" && typeof process16.removeListener === "function" && typeof process16.emit === "function" && typeof process16.reallyExit === "function" && typeof process16.listeners === "function" && typeof process16.kill === "function" && typeof process16.pid === "number" && typeof process16.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(process11) {
798
+ constructor(process16) {
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, process11);
812
+ __privateSet(this, _process, process16);
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 = process11;
818
+ const p = process16;
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
- process11.kill(process11.pid, s);
827
+ process16.kill(process16.pid, s);
828
828
  }
829
829
  };
830
830
  }
831
- __privateSet(this, _originalProcessReallyExit, process11.reallyExit);
832
- __privateSet(this, _originalProcessEmit, process11.emit);
831
+ __privateSet(this, _originalProcessReallyExit, process16.reallyExit);
832
+ __privateSet(this, _originalProcessEmit, process16.emit);
833
833
  }
834
834
  onExit(cb, opts) {
835
835
  if (!processOk(__privateGet(this, _process))) {
@@ -1932,7 +1932,31 @@ var init_cli_truncate = __esm({
1932
1932
  // src/index.ts
1933
1933
  var src_exports = {};
1934
1934
  __export(src_exports, {
1935
- pubm: () => pubm
1935
+ applyFixedGroup: () => applyFixedGroup,
1936
+ applyLinkedGroup: () => applyLinkedGroup,
1937
+ buildDependencyGraph: () => buildDependencyGraph,
1938
+ calculateVersionBumps: () => calculateVersionBumps,
1939
+ defineConfig: () => defineConfig,
1940
+ detectExtraneousFiles: () => detectExtraneousFiles,
1941
+ detectWorkspace: () => detectWorkspace,
1942
+ enterPreMode: () => enterPreMode,
1943
+ exitPreMode: () => exitPreMode,
1944
+ generateChangelog: () => generateChangelog,
1945
+ generateChangesetContent: () => generateChangesetContent,
1946
+ generateChangesetId: () => generateChangesetId,
1947
+ generateSnapshotVersion: () => generateSnapshotVersion,
1948
+ getStatus: () => getStatus,
1949
+ loadConfig: () => loadConfig,
1950
+ migrateFromChangesets: () => migrateFromChangesets,
1951
+ parseChangeset: () => parseChangeset,
1952
+ pubm: () => pubm,
1953
+ readChangesets: () => readChangesets,
1954
+ readPreState: () => readPreState,
1955
+ resolveConfig: () => resolveConfig,
1956
+ resolveGroups: () => resolveGroups,
1957
+ topologicalSort: () => topologicalSort,
1958
+ validateEntryPoints: () => validateEntryPoints,
1959
+ writeChangeset: () => writeChangeset
1936
1960
  });
1937
1961
  module.exports = __toCommonJS(src_exports);
1938
1962
 
@@ -4385,7 +4409,7 @@ var Listr = (_a23 = class {
4385
4409
  // src/tasks/runner.ts
4386
4410
  var import_semver3 = __toESM(require("semver"), 1);
4387
4411
  var import_std_env = require("std-env");
4388
- var import_tinyexec5 = require("tinyexec");
4412
+ var import_tinyexec6 = require("tinyexec");
4389
4413
 
4390
4414
  // src/error.ts
4391
4415
  var AbstractError = class extends Error {
@@ -4400,10 +4424,13 @@ function replaceCode(code) {
4400
4424
  }
4401
4425
  function formatError(error) {
4402
4426
  if (!(error instanceof Error)) return `${error}`;
4403
- const message = typeof error.message === "string" ? replaceCode(error.message) : formatError(error);
4427
+ const message = typeof error.message === "string" ? replaceCode(error.message) : (
4428
+ /* v8 ignore next */
4429
+ formatError(error)
4430
+ );
4404
4431
  let stringifyError = `${color.bgRed(` ${error.name} `)}${color.reset("")} ${message}
4405
4432
  `;
4406
- stringifyError += error.stack?.split("\n").slice(1).join("\n").replace(/at/g, color.dim("at")).replace(/\(([^\(].+)\)/g, `(${color.blue("$1")})`);
4433
+ stringifyError += error.stack?.split("\n").slice(1).join("\n").replace(/at/g, color.dim("at")).replace(/\(([^(].+)\)/g, `(${color.blue("$1")})`);
4407
4434
  if (error.cause) {
4408
4435
  stringifyError += "\n\nCaused: ";
4409
4436
  stringifyError += formatError(error.cause);
@@ -4434,8 +4461,7 @@ var GitError = class extends AbstractError {
4434
4461
  };
4435
4462
  var Git = class {
4436
4463
  async git(args) {
4437
- const { stdout, stderr } = await (0, import_tinyexec.exec)("git", args);
4438
- if (stderr) throw stderr;
4464
+ const { stdout } = await (0, import_tinyexec.exec)("git", args, { throwOnError: true });
4439
4465
  return stdout;
4440
4466
  }
4441
4467
  async userName() {
@@ -4456,7 +4482,7 @@ var Git = class {
4456
4482
  }
4457
4483
  async tags() {
4458
4484
  try {
4459
- return (await this.git(["tag", "-l"])).trim().split("\n").map((v) => v.slice(1)).sort(import_semver.default.compareIdentifiers);
4485
+ return (await this.git(["tag", "-l"])).trim().split("\n").sort(import_semver.default.compareIdentifiers);
4460
4486
  } catch (error) {
4461
4487
  throw new GitError("Failed to run `git config --get user.name`", {
4462
4488
  cause: error
@@ -4466,7 +4492,8 @@ var Git = class {
4466
4492
  async previousTag(tag) {
4467
4493
  try {
4468
4494
  const tags = await this.tags();
4469
- return tags.at(tags.findIndex((t) => t === tag) - 1) ?? null;
4495
+ const strip = (t) => t.replace(/^v/, "");
4496
+ return tags.at(tags.findIndex((t) => strip(t) === strip(tag)) - 1) ?? null;
4470
4497
  } catch {
4471
4498
  return null;
4472
4499
  }
@@ -4571,13 +4598,8 @@ var Git = class {
4571
4598
  async checkTagExist(tag) {
4572
4599
  try {
4573
4600
  return (await this.git(["rev-parse", "-q", "--verify", `refs/tags/${tag}`])).trim() !== "";
4574
- } catch (error) {
4575
- throw new GitError(
4576
- `Failed to run \`git rev-parse -q --verify refs/tags/${tag}\``,
4577
- {
4578
- cause: error
4579
- }
4580
- );
4601
+ } catch {
4602
+ return false;
4581
4603
  }
4582
4604
  }
4583
4605
  async deleteTag(tag) {
@@ -4928,17 +4950,222 @@ async function getPackageManager() {
4928
4950
  return "npm";
4929
4951
  }
4930
4952
 
4953
+ // src/ecosystem/rust.ts
4954
+ var import_promises2 = require("fs/promises");
4955
+ var import_node_path2 = __toESM(require("path"), 1);
4956
+ var import_smol_toml = require("smol-toml");
4957
+
4958
+ // src/ecosystem/ecosystem.ts
4959
+ var Ecosystem = class {
4960
+ constructor(packagePath) {
4961
+ this.packagePath = packagePath;
4962
+ }
4963
+ };
4964
+
4965
+ // src/ecosystem/rust.ts
4966
+ var RustEcosystem = class extends Ecosystem {
4967
+ static async detect(packagePath) {
4968
+ try {
4969
+ return (await (0, import_promises2.stat)(import_node_path2.default.join(packagePath, "Cargo.toml"))).isFile();
4970
+ } catch {
4971
+ return false;
4972
+ }
4973
+ }
4974
+ async readCargoToml() {
4975
+ const raw = await (0, import_promises2.readFile)(
4976
+ import_node_path2.default.join(this.packagePath, "Cargo.toml"),
4977
+ "utf-8"
4978
+ );
4979
+ return (0, import_smol_toml.parse)(raw);
4980
+ }
4981
+ async packageName() {
4982
+ const cargo = await this.readCargoToml();
4983
+ const pkg = cargo.package;
4984
+ return pkg.name;
4985
+ }
4986
+ async readVersion() {
4987
+ const cargo = await this.readCargoToml();
4988
+ const pkg = cargo.package;
4989
+ return pkg.version;
4990
+ }
4991
+ async writeVersion(newVersion) {
4992
+ const filePath = import_node_path2.default.join(this.packagePath, "Cargo.toml");
4993
+ const raw = await (0, import_promises2.readFile)(filePath, "utf-8");
4994
+ const cargo = (0, import_smol_toml.parse)(raw);
4995
+ const pkg = cargo.package;
4996
+ pkg.version = newVersion;
4997
+ await (0, import_promises2.writeFile)(filePath, (0, import_smol_toml.stringify)(cargo));
4998
+ }
4999
+ manifestFiles() {
5000
+ return ["Cargo.toml"];
5001
+ }
5002
+ defaultTestCommand() {
5003
+ return "cargo test";
5004
+ }
5005
+ defaultBuildCommand() {
5006
+ return "cargo build --release";
5007
+ }
5008
+ supportedRegistries() {
5009
+ return ["crates"];
5010
+ }
5011
+ };
5012
+
5013
+ // src/registry/crates.ts
5014
+ var import_tinyexec2 = require("tinyexec");
5015
+
5016
+ // src/registry/registry.ts
5017
+ var Registry = class {
5018
+ constructor(packageName, registry) {
5019
+ this.packageName = packageName;
5020
+ this.registry = registry;
5021
+ }
5022
+ };
5023
+
5024
+ // src/registry/crates.ts
5025
+ var CratesError = class extends AbstractError {
5026
+ constructor() {
5027
+ super(...arguments);
5028
+ __publicField(this, "name", "crates.io Error");
5029
+ }
5030
+ };
5031
+ var USER_AGENT = "pubm (https://github.com/syi0808/pubm)";
5032
+ var CratesRegistry = class extends Registry {
5033
+ constructor() {
5034
+ super(...arguments);
5035
+ __publicField(this, "registry", "https://crates.io");
5036
+ }
5037
+ get headers() {
5038
+ return { "User-Agent": USER_AGENT };
5039
+ }
5040
+ async ping() {
5041
+ try {
5042
+ const response = await fetch(`${this.registry}/api/v1`, {
5043
+ headers: this.headers
5044
+ });
5045
+ return response.ok;
5046
+ } catch (error) {
5047
+ throw new CratesError("Failed to ping crates.io", { cause: error });
5048
+ }
5049
+ }
5050
+ async isInstalled() {
5051
+ try {
5052
+ await (0, import_tinyexec2.exec)("cargo", ["--version"]);
5053
+ return true;
5054
+ } catch {
5055
+ return false;
5056
+ }
5057
+ }
5058
+ async distTags() {
5059
+ return [];
5060
+ }
5061
+ async version() {
5062
+ try {
5063
+ const response = await fetch(
5064
+ `${this.registry}/api/v1/crates/${this.packageName}`,
5065
+ { headers: this.headers }
5066
+ );
5067
+ if (!response.ok) {
5068
+ throw new Error(`Crate '${this.packageName}' not found`);
5069
+ }
5070
+ const data = await response.json();
5071
+ return data.crate.max_version;
5072
+ } catch (error) {
5073
+ throw new CratesError(
5074
+ `Failed to fetch version for crate '${this.packageName}'`,
5075
+ { cause: error }
5076
+ );
5077
+ }
5078
+ }
5079
+ async publish() {
5080
+ try {
5081
+ await (0, import_tinyexec2.exec)("cargo", ["publish"], { throwOnError: true });
5082
+ return true;
5083
+ } catch (error) {
5084
+ throw new CratesError("Failed to run `cargo publish`", {
5085
+ cause: error
5086
+ });
5087
+ }
5088
+ }
5089
+ async isPublished() {
5090
+ try {
5091
+ const response = await fetch(
5092
+ `${this.registry}/api/v1/crates/${this.packageName}`,
5093
+ { headers: this.headers }
5094
+ );
5095
+ return response.ok;
5096
+ } catch {
5097
+ return false;
5098
+ }
5099
+ }
5100
+ async hasPermission() {
5101
+ if (process.env.CARGO_REGISTRY_TOKEN) return true;
5102
+ return this.isInstalled();
5103
+ }
5104
+ async isPackageNameAvaliable() {
5105
+ try {
5106
+ const response = await fetch(
5107
+ `${this.registry}/api/v1/crates/${this.packageName}`,
5108
+ { headers: this.headers }
5109
+ );
5110
+ return !response.ok;
5111
+ } catch {
5112
+ return true;
5113
+ }
5114
+ }
5115
+ };
5116
+ async function cratesRegistry(packageName) {
5117
+ return new CratesRegistry(packageName);
5118
+ }
5119
+
5120
+ // src/tasks/crates.ts
5121
+ var CratesError2 = class extends AbstractError {
5122
+ constructor(message, { cause } = {}) {
5123
+ super(message, { cause });
5124
+ __publicField(this, "name", "crates.io Error");
5125
+ this.stack = "";
5126
+ }
5127
+ };
5128
+ async function getCrateName() {
5129
+ const eco = new RustEcosystem(process.cwd());
5130
+ return await eco.packageName();
5131
+ }
5132
+ var cratesAvailableCheckTasks = {
5133
+ title: "Checking crates.io availability",
5134
+ task: async () => {
5135
+ const packageName = await getCrateName();
5136
+ const registry = new CratesRegistry(packageName);
5137
+ if (!await registry.isInstalled()) {
5138
+ throw new CratesError2(
5139
+ "cargo is not installed. Please install Rust toolchain to proceed."
5140
+ );
5141
+ }
5142
+ if (!await registry.hasPermission()) {
5143
+ throw new CratesError2(
5144
+ "No crates.io credentials found. Run `cargo login` or set CARGO_REGISTRY_TOKEN."
5145
+ );
5146
+ }
5147
+ }
5148
+ };
5149
+ var cratesPublishTasks = {
5150
+ title: "Publishing to crates.io",
5151
+ task: async () => {
5152
+ const packageName = await getCrateName();
5153
+ const registry = new CratesRegistry(packageName);
5154
+ await registry.publish();
5155
+ }
5156
+ };
5157
+
4931
5158
  // src/tasks/jsr.ts
4932
5159
  var import_node_process6 = __toESM(require("process"), 1);
4933
5160
  var import_prompt_adapter_enquirer = require("@listr2/prompt-adapter-enquirer");
4934
5161
 
4935
5162
  // src/registry/jsr.ts
4936
- var import_tinyexec2 = require("tinyexec");
5163
+ var import_tinyexec3 = require("tinyexec");
4937
5164
 
4938
5165
  // src/utils/db.ts
4939
5166
  var import_node_crypto = require("crypto");
4940
5167
  var import_node_fs = require("fs");
4941
- var import_node_path2 = __toESM(require("path"), 1);
5168
+ var import_node_path3 = __toESM(require("path"), 1);
4942
5169
  var import_meta = {};
4943
5170
  var a = "aes-256-cbc";
4944
5171
  var n = (0, import_node_fs.statSync)(import_meta.dirname);
@@ -4954,7 +5181,7 @@ function d(g, h) {
4954
5181
  }
4955
5182
  var Db = class {
4956
5183
  constructor() {
4957
- __publicField(this, "path", import_node_path2.default.resolve(import_meta.dirname, ".pubm"));
5184
+ __publicField(this, "path", import_node_path3.default.resolve(import_meta.dirname, ".pubm"));
4958
5185
  try {
4959
5186
  if (!(0, import_node_fs.statSync)(this.path).isDirectory()) {
4960
5187
  (0, import_node_fs.mkdirSync)(this.path);
@@ -4965,7 +5192,7 @@ var Db = class {
4965
5192
  }
4966
5193
  set(field, value) {
4967
5194
  (0, import_node_fs.writeFileSync)(
4968
- import_node_path2.default.resolve(this.path, Buffer.from(e(field, field)).toString("base64")),
5195
+ import_node_path3.default.resolve(this.path, Buffer.from(e(field, field)).toString("base64")),
4969
5196
  Buffer.from(e(`${value}`, field)),
4970
5197
  { encoding: "binary" }
4971
5198
  );
@@ -4975,7 +5202,7 @@ var Db = class {
4975
5202
  return d(
4976
5203
  Buffer.from(
4977
5204
  (0, import_node_fs.readFileSync)(
4978
- import_node_path2.default.resolve(
5205
+ import_node_path3.default.resolve(
4979
5206
  this.path,
4980
5207
  Buffer.from(e(field, field)).toString("base64")
4981
5208
  )
@@ -5030,14 +5257,6 @@ function isValidPackageName(packageName) {
5030
5257
  return true;
5031
5258
  }
5032
5259
 
5033
- // src/registry/registry.ts
5034
- var Registry = class {
5035
- constructor(packageName, registry) {
5036
- this.packageName = packageName;
5037
- this.registry = registry;
5038
- }
5039
- };
5040
-
5041
5260
  // src/registry/jsr.ts
5042
5261
  var import_meta2 = {};
5043
5262
  var JsrError = class extends AbstractError {
@@ -5059,13 +5278,12 @@ var JsrRegisry = class extends Registry {
5059
5278
  this.client = new JsrClient(getApiEndpoint(this.registry));
5060
5279
  }
5061
5280
  async jsr(args) {
5062
- const { stdout, stderr } = await (0, import_tinyexec2.exec)("jsr", args);
5063
- if (stderr) throw stderr;
5281
+ const { stdout } = await (0, import_tinyexec3.exec)("jsr", args, { throwOnError: true });
5064
5282
  return stdout;
5065
5283
  }
5066
5284
  async isInstalled() {
5067
5285
  try {
5068
- await this.jsr(["--help"]);
5286
+ await this.jsr(["--version"]);
5069
5287
  return true;
5070
5288
  } catch {
5071
5289
  return false;
@@ -5076,12 +5294,11 @@ var JsrRegisry = class extends Registry {
5076
5294
  }
5077
5295
  async ping() {
5078
5296
  try {
5079
- const { stdout, stderr } = await (0, import_tinyexec2.exec)("ping", [
5080
- new URL(this.registry).hostname,
5081
- "-c",
5082
- "1"
5083
- ]);
5084
- if (stderr) throw stderr;
5297
+ const { stdout } = await (0, import_tinyexec3.exec)(
5298
+ "ping",
5299
+ [new URL(this.registry).hostname, "-c", "1"],
5300
+ { throwOnError: true }
5301
+ );
5085
5302
  return stdout.includes("1 packets transmitted");
5086
5303
  } catch (error) {
5087
5304
  throw new JsrError(
@@ -5092,7 +5309,7 @@ var JsrRegisry = class extends Registry {
5092
5309
  }
5093
5310
  async publish() {
5094
5311
  try {
5095
- await (0, import_tinyexec2.exec)(
5312
+ await (0, import_tinyexec3.exec)(
5096
5313
  "jsr",
5097
5314
  ["publish", "--allow-dirty", "--token", `${JsrClient.token}`],
5098
5315
  {
@@ -5101,8 +5318,10 @@ var JsrRegisry = class extends Registry {
5101
5318
  );
5102
5319
  return true;
5103
5320
  } catch (error) {
5321
+ const stderr = error instanceof import_tinyexec3.NonZeroExitError ? error.output?.stderr : void 0;
5104
5322
  throw new JsrError(
5105
- "Failed to run `jsr publish --allow-dirty --token ***`",
5323
+ `Failed to run \`jsr publish --allow-dirty --token ***\`${stderr ? `
5324
+ ${stderr}` : ""}`,
5106
5325
  {
5107
5326
  cause: error
5108
5327
  }
@@ -5149,6 +5368,11 @@ var _JsrClient = class _JsrClient {
5149
5368
  try {
5150
5369
  const response = await this.fetch("/user");
5151
5370
  if (response.status === 401) return null;
5371
+ if (!response.ok) {
5372
+ throw new Error(
5373
+ `HTTP ${response.status}: ${response.statusText}`
5374
+ );
5375
+ }
5152
5376
  return await response.json();
5153
5377
  } catch (error) {
5154
5378
  throw new JsrError(`Failed to fetch \`${this.apiEndpoint}/user\``, {
@@ -5160,6 +5384,11 @@ var _JsrClient = class _JsrClient {
5160
5384
  try {
5161
5385
  const response = await this.fetch(`/user/member/${scope}`);
5162
5386
  if (response.status === 401) return null;
5387
+ if (!response.ok) {
5388
+ throw new Error(
5389
+ `HTTP ${response.status}: ${response.statusText}`
5390
+ );
5391
+ }
5163
5392
  return await response.json();
5164
5393
  } catch (error) {
5165
5394
  throw new JsrError(
@@ -5174,9 +5403,18 @@ var _JsrClient = class _JsrClient {
5174
5403
  try {
5175
5404
  const response = await this.fetch("/user/scopes");
5176
5405
  if (response.status === 401) return [];
5177
- return (await response.json()).map(
5178
- ({ scope }) => scope
5179
- );
5406
+ if (!response.ok) {
5407
+ throw new Error(
5408
+ `HTTP ${response.status}: ${response.statusText}`
5409
+ );
5410
+ }
5411
+ const body = await response.json();
5412
+ if (!Array.isArray(body)) {
5413
+ throw new Error(
5414
+ `Expected array response but got ${typeof body}`
5415
+ );
5416
+ }
5417
+ return body.map(({ scope }) => scope);
5180
5418
  } catch (error) {
5181
5419
  throw new JsrError(
5182
5420
  `Failed to fetch \`${this.apiEndpoint}/user/scopes\``,
@@ -5190,10 +5428,11 @@ var _JsrClient = class _JsrClient {
5190
5428
  const [scope, name] = getScopeAndName(packageName);
5191
5429
  try {
5192
5430
  const response = await this.fetch(`/scopes/${scope}/packages/${name}`);
5431
+ if (!response.ok) return null;
5193
5432
  return await response.json();
5194
5433
  } catch (error) {
5195
5434
  throw new JsrError(
5196
- `Failed to fetch \`${this.apiEndpoint}/user/scopes\``,
5435
+ `Failed to fetch \`${this.apiEndpoint}/scopes/${scope}/packages/${name}\``,
5197
5436
  {
5198
5437
  cause: error
5199
5438
  }
@@ -5264,6 +5503,11 @@ var _JsrClient = class _JsrClient {
5264
5503
  async searchPackage(query) {
5265
5504
  try {
5266
5505
  const response = await this.fetch(`/packages?query=${query}`);
5506
+ if (!response.ok) {
5507
+ throw new Error(
5508
+ `HTTP ${response.status}: ${response.statusText}`
5509
+ );
5510
+ }
5267
5511
  return await response.json();
5268
5512
  } catch (error) {
5269
5513
  throw new JsrError(
@@ -5283,7 +5527,7 @@ async function jsrRegistry() {
5283
5527
  }
5284
5528
 
5285
5529
  // src/registry/npm.ts
5286
- var import_tinyexec3 = require("tinyexec");
5530
+ var import_tinyexec4 = require("tinyexec");
5287
5531
  var NpmError = class extends AbstractError {
5288
5532
  constructor() {
5289
5533
  super(...arguments);
@@ -5296,13 +5540,12 @@ var NpmRegistry = class extends Registry {
5296
5540
  __publicField(this, "registry", "https://registry.npmjs.org");
5297
5541
  }
5298
5542
  async npm(args) {
5299
- const { stdout, stderr } = await (0, import_tinyexec3.exec)("npm", args);
5300
- if (stderr) throw stderr;
5543
+ const { stdout } = await (0, import_tinyexec4.exec)("npm", args, { throwOnError: true });
5301
5544
  return stdout;
5302
5545
  }
5303
5546
  async isInstalled() {
5304
5547
  try {
5305
- await this.npm(["--help"]);
5548
+ await this.npm(["--version"]);
5306
5549
  return true;
5307
5550
  } catch {
5308
5551
  return false;
@@ -5341,7 +5584,7 @@ var NpmRegistry = class extends Registry {
5341
5584
  await this.npm(["whoami"]);
5342
5585
  return true;
5343
5586
  } catch (error) {
5344
- if (`${error}`.includes("ENEEDAUTH")) {
5587
+ if (error instanceof import_tinyexec4.NonZeroExitError && error.output?.stderr.includes("ENEEDAUTH")) {
5345
5588
  return false;
5346
5589
  }
5347
5590
  throw new NpmError("Failed to run `npm whoami`", { cause: error });
@@ -5393,7 +5636,7 @@ var NpmRegistry = class extends Registry {
5393
5636
  }
5394
5637
  async ping() {
5395
5638
  try {
5396
- await (0, import_tinyexec3.exec)("npm", ["ping"], { throwOnError: true });
5639
+ await (0, import_tinyexec4.exec)("npm", ["ping"], { throwOnError: true });
5397
5640
  return true;
5398
5641
  } catch (error) {
5399
5642
  throw new NpmError("Failed to run `npm ping`", { cause: error });
@@ -5401,15 +5644,12 @@ var NpmRegistry = class extends Registry {
5401
5644
  }
5402
5645
  async publishProvenance() {
5403
5646
  try {
5404
- try {
5405
- await this.npm(["publish", "--provenance", "--access", "public"]);
5406
- } catch (error) {
5407
- if (`${error}`.includes("EOTP")) {
5408
- return false;
5409
- }
5410
- }
5647
+ await this.npm(["publish", "--provenance", "--access", "public"]);
5411
5648
  return true;
5412
5649
  } catch (error) {
5650
+ if (error instanceof import_tinyexec4.NonZeroExitError && error.output?.stderr.includes("EOTP")) {
5651
+ return false;
5652
+ }
5413
5653
  throw new NpmError(
5414
5654
  "Failed to run `npm publish --provenance --access public`",
5415
5655
  {
@@ -5421,15 +5661,12 @@ var NpmRegistry = class extends Registry {
5421
5661
  async publish(otp) {
5422
5662
  const args = otp ? ["publish", "--otp", otp] : ["publish"];
5423
5663
  try {
5424
- try {
5425
- await this.npm(args);
5426
- } catch (error) {
5427
- if (`${error}`.includes("EOTP")) {
5428
- return false;
5429
- }
5430
- }
5664
+ await this.npm(args);
5431
5665
  return true;
5432
5666
  } catch (error) {
5667
+ if (error instanceof import_tinyexec4.NonZeroExitError && error.output?.stderr.includes("EOTP")) {
5668
+ return false;
5669
+ }
5433
5670
  throw new NpmError(`Failed to run \`npm ${args.join(" ")}\``, {
5434
5671
  cause: error
5435
5672
  });
@@ -5502,7 +5739,7 @@ Generate a token from ${color.bold(link2("jsr.io", "https://jsr.io/account/token
5502
5739
  scopes.map(
5503
5740
  (scope2) => jsr.client.package(`@${scope2}/${jsr.packageName}`)
5504
5741
  )
5505
- )).filter((v) => v);
5742
+ )).filter((v) => v !== null);
5506
5743
  if (searchResults.length > 0) {
5507
5744
  jsrName = await task.prompt(import_prompt_adapter_enquirer.ListrEnquirerPromptAdapter).run({
5508
5745
  type: "select",
@@ -5837,14 +6074,14 @@ var prerequisitesCheckTask = (options) => {
5837
6074
  var import_prompt_adapter_enquirer4 = require("@listr2/prompt-adapter-enquirer");
5838
6075
 
5839
6076
  // src/registry/custom-registry.ts
5840
- var import_tinyexec4 = require("tinyexec");
6077
+ var import_tinyexec5 = require("tinyexec");
5841
6078
  var CustomRegistry = class extends NpmRegistry {
5842
6079
  async npm(args) {
5843
- const { stdout, stderr } = await (0, import_tinyexec4.exec)(
6080
+ const { stdout } = await (0, import_tinyexec5.exec)(
5844
6081
  "npm",
5845
- args.concat("--registry", this.registry)
6082
+ args.concat("--registry", this.registry),
6083
+ { throwOnError: true }
5846
6084
  );
5847
- if (stderr) throw stderr;
5848
6085
  return stdout;
5849
6086
  }
5850
6087
  };
@@ -5858,7 +6095,10 @@ var registryMap = {
5858
6095
  npm: npmRegistry,
5859
6096
  jsr: jsrRegistry
5860
6097
  };
5861
- async function getRegistry(registryKey) {
6098
+ async function getRegistry(registryKey, packageName) {
6099
+ if (registryKey === "crates") {
6100
+ return await cratesRegistry(packageName ?? "unknown");
6101
+ }
5862
6102
  const registry = registryMap[registryKey];
5863
6103
  if (!registry) {
5864
6104
  return await customRegistry();
@@ -5989,6 +6229,8 @@ var requiredConditionsCheckTask = (options) => createListr({
5989
6229
  return npmAvailableCheckTasks;
5990
6230
  case "jsr":
5991
6231
  return jsrAvailableCheckTasks;
6232
+ case "crates":
6233
+ return cratesAvailableCheckTasks;
5992
6234
  default:
5993
6235
  return npmAvailableCheckTasks;
5994
6236
  }
@@ -6035,6 +6277,8 @@ async function run(options) {
6035
6277
  return npmPublishTasks;
6036
6278
  case "jsr":
6037
6279
  return jsrPublishTasks;
6280
+ case "crates":
6281
+ return cratesPublishTasks;
6038
6282
  default:
6039
6283
  return npmPublishTasks;
6040
6284
  }
@@ -6047,16 +6291,9 @@ async function run(options) {
6047
6291
  title: "Running tests",
6048
6292
  task: async (ctx2) => {
6049
6293
  const packageManager = await getPackageManager();
6050
- const { stderr } = await (0, import_tinyexec5.exec)(packageManager, [
6051
- "run",
6052
- ctx2.testScript
6053
- ]);
6054
- if (stderr) {
6055
- throw new AbstractError(
6056
- `Failed to run \`${packageManager} run ${ctx2.testScript}\``,
6057
- { cause: stderr }
6058
- );
6059
- }
6294
+ await (0, import_tinyexec6.exec)(packageManager, ["run", ctx2.testScript], {
6295
+ throwOnError: true
6296
+ });
6060
6297
  }
6061
6298
  },
6062
6299
  {
@@ -6065,7 +6302,7 @@ async function run(options) {
6065
6302
  task: async (ctx2) => {
6066
6303
  const packageManager = await getPackageManager();
6067
6304
  try {
6068
- await (0, import_tinyexec5.exec)(packageManager, ["run", ctx2.buildScript], {
6305
+ await (0, import_tinyexec6.exec)(packageManager, ["run", ctx2.buildScript], {
6069
6306
  throwOnError: true
6070
6307
  });
6071
6308
  } catch (error) {
@@ -6119,6 +6356,8 @@ async function run(options) {
6119
6356
  return npmPublishTasks;
6120
6357
  case "jsr":
6121
6358
  return jsrPublishTasks;
6359
+ case "crates":
6360
+ return cratesPublishTasks;
6122
6361
  default:
6123
6362
  return npmPublishTasks;
6124
6363
  }
@@ -6184,6 +6423,684 @@ ${repositoryUrl}/compare/${lastRev}...${latestTag}`;
6184
6423
  }
6185
6424
  }
6186
6425
 
6426
+ // src/changeset/bump-utils.ts
6427
+ var BUMP_ORDER = {
6428
+ patch: 0,
6429
+ minor: 1,
6430
+ major: 2
6431
+ };
6432
+ function maxBump(a2, b) {
6433
+ return BUMP_ORDER[a2] >= BUMP_ORDER[b] ? a2 : b;
6434
+ }
6435
+
6436
+ // src/changeset/changelog.ts
6437
+ var SECTION_ORDER = [
6438
+ { type: "major", heading: "Major Changes" },
6439
+ { type: "minor", heading: "Minor Changes" },
6440
+ { type: "patch", heading: "Patch Changes" }
6441
+ ];
6442
+ function generateChangelog(version2, entries, depUpdates) {
6443
+ const lines = [`## ${version2}`];
6444
+ for (const section of SECTION_ORDER) {
6445
+ const sectionEntries = entries.filter((e2) => e2.type === section.type);
6446
+ if (sectionEntries.length === 0) continue;
6447
+ lines.push("");
6448
+ lines.push(`### ${section.heading}`);
6449
+ lines.push("");
6450
+ for (const entry of sectionEntries) {
6451
+ lines.push(`- ${entry.summary}`);
6452
+ }
6453
+ }
6454
+ if (depUpdates && depUpdates.length > 0) {
6455
+ lines.push("");
6456
+ lines.push("### Dependency Updates");
6457
+ lines.push("");
6458
+ for (const dep of depUpdates) {
6459
+ lines.push(`- Updated \`${dep.name}\` to ${dep.version}`);
6460
+ }
6461
+ }
6462
+ return `${lines.join("\n")}
6463
+ `;
6464
+ }
6465
+
6466
+ // src/changeset/migrate.ts
6467
+ var import_node_fs2 = require("fs");
6468
+ var import_node_path4 = __toESM(require("path"), 1);
6469
+ var import_node_process9 = __toESM(require("process"), 1);
6470
+ var SKIPPED_FILES = /* @__PURE__ */ new Set(["config.json", "README.md"]);
6471
+ function migrateFromChangesets(cwd = import_node_process9.default.cwd()) {
6472
+ const changesetDir = import_node_path4.default.join(cwd, ".changeset");
6473
+ if (!(0, import_node_fs2.existsSync)(changesetDir)) {
6474
+ return {
6475
+ success: false,
6476
+ error: ".changeset/ directory not found",
6477
+ migratedFiles: [],
6478
+ configMigrated: false
6479
+ };
6480
+ }
6481
+ const pubmDir = import_node_path4.default.join(cwd, ".pubm", "changesets");
6482
+ (0, import_node_fs2.mkdirSync)(pubmDir, { recursive: true });
6483
+ const files = (0, import_node_fs2.readdirSync)(changesetDir);
6484
+ const migratedFiles = [];
6485
+ let configMigrated = false;
6486
+ for (const file of files) {
6487
+ if (file === "config.json") {
6488
+ configMigrated = true;
6489
+ continue;
6490
+ }
6491
+ if (SKIPPED_FILES.has(file)) {
6492
+ continue;
6493
+ }
6494
+ if (file === "pre.json") {
6495
+ (0, import_node_fs2.copyFileSync)(
6496
+ import_node_path4.default.join(changesetDir, file),
6497
+ import_node_path4.default.resolve(cwd, ".pubm", "pre.json")
6498
+ );
6499
+ migratedFiles.push(file);
6500
+ continue;
6501
+ }
6502
+ if (file.endsWith(".md")) {
6503
+ const src = import_node_path4.default.join(changesetDir, file);
6504
+ const dest = import_node_path4.default.join(pubmDir, file);
6505
+ (0, import_node_fs2.copyFileSync)(src, dest);
6506
+ migratedFiles.push(file);
6507
+ }
6508
+ }
6509
+ return {
6510
+ success: true,
6511
+ migratedFiles,
6512
+ configMigrated
6513
+ };
6514
+ }
6515
+
6516
+ // src/changeset/parser.ts
6517
+ var import_yaml = require("yaml");
6518
+ var VALID_BUMP_TYPES = /* @__PURE__ */ new Set(["patch", "minor", "major"]);
6519
+ function parseChangeset(content, fileName) {
6520
+ const frontmatterRegex = /^---\n([\s\S]*?)---/;
6521
+ const match = content.match(frontmatterRegex);
6522
+ if (!match) {
6523
+ throw new Error(
6524
+ `Invalid changeset format in "${fileName}": missing frontmatter`
6525
+ );
6526
+ }
6527
+ const yamlContent = match[1];
6528
+ const body = content.slice(match[0].length).trim();
6529
+ const parsed = (0, import_yaml.parse)(yamlContent);
6530
+ const releases = [];
6531
+ if (parsed) {
6532
+ for (const [name, type] of Object.entries(parsed)) {
6533
+ if (!VALID_BUMP_TYPES.has(type)) {
6534
+ throw new Error(
6535
+ `Invalid bump type "${type}" for package "${name}" in "${fileName}". Expected: patch, minor, or major.`
6536
+ );
6537
+ }
6538
+ releases.push({ name, type });
6539
+ }
6540
+ }
6541
+ const id = fileName.replace(/\.md$/, "");
6542
+ return {
6543
+ id,
6544
+ summary: body,
6545
+ releases
6546
+ };
6547
+ }
6548
+
6549
+ // src/changeset/reader.ts
6550
+ var import_node_fs3 = require("fs");
6551
+ var import_node_path5 = __toESM(require("path"), 1);
6552
+ var import_node_process10 = __toESM(require("process"), 1);
6553
+ function readChangesets(cwd = import_node_process10.default.cwd()) {
6554
+ const changesetsDir = import_node_path5.default.join(cwd, ".pubm", "changesets");
6555
+ if (!(0, import_node_fs3.existsSync)(changesetsDir)) {
6556
+ return [];
6557
+ }
6558
+ const files = (0, import_node_fs3.readdirSync)(changesetsDir);
6559
+ const changesets = [];
6560
+ for (const file of files) {
6561
+ if (!file.endsWith(".md") || file === "README.md") {
6562
+ continue;
6563
+ }
6564
+ const filePath = import_node_path5.default.join(changesetsDir, file);
6565
+ const content = (0, import_node_fs3.readFileSync)(filePath, "utf-8");
6566
+ changesets.push(parseChangeset(content, file));
6567
+ }
6568
+ return changesets;
6569
+ }
6570
+
6571
+ // src/changeset/status.ts
6572
+ var import_node_process11 = __toESM(require("process"), 1);
6573
+ function getStatus(cwd = import_node_process11.default.cwd()) {
6574
+ const changesets = readChangesets(cwd);
6575
+ const packages = /* @__PURE__ */ new Map();
6576
+ for (const changeset of changesets) {
6577
+ for (const release of changeset.releases) {
6578
+ const existing = packages.get(release.name);
6579
+ if (existing) {
6580
+ existing.bumpType = maxBump(existing.bumpType, release.type);
6581
+ existing.changesetCount += 1;
6582
+ existing.summaries.push(changeset.summary);
6583
+ } else {
6584
+ packages.set(release.name, {
6585
+ bumpType: release.type,
6586
+ changesetCount: 1,
6587
+ summaries: [changeset.summary]
6588
+ });
6589
+ }
6590
+ }
6591
+ }
6592
+ return {
6593
+ packages,
6594
+ changesets,
6595
+ hasChangesets: changesets.length > 0
6596
+ };
6597
+ }
6598
+
6599
+ // src/changeset/version.ts
6600
+ var import_node_process12 = __toESM(require("process"), 1);
6601
+ var import_semver4 = require("semver");
6602
+ function calculateVersionBumps(currentVersions, cwd = import_node_process12.default.cwd()) {
6603
+ const changesets = readChangesets(cwd);
6604
+ const bumpTypes = /* @__PURE__ */ new Map();
6605
+ for (const changeset of changesets) {
6606
+ for (const release of changeset.releases) {
6607
+ if (!currentVersions.has(release.name)) continue;
6608
+ const existing = bumpTypes.get(release.name);
6609
+ if (existing) {
6610
+ bumpTypes.set(release.name, maxBump(existing, release.type));
6611
+ } else {
6612
+ bumpTypes.set(release.name, release.type);
6613
+ }
6614
+ }
6615
+ }
6616
+ const result = /* @__PURE__ */ new Map();
6617
+ for (const [name, bumpType] of bumpTypes) {
6618
+ const currentVersion = currentVersions.get(name);
6619
+ if (!currentVersion) continue;
6620
+ const newVersion = (0, import_semver4.inc)(currentVersion, bumpType);
6621
+ if (newVersion) {
6622
+ result.set(name, {
6623
+ currentVersion,
6624
+ newVersion,
6625
+ bumpType
6626
+ });
6627
+ }
6628
+ }
6629
+ return result;
6630
+ }
6631
+
6632
+ // src/changeset/writer.ts
6633
+ var import_node_fs4 = require("fs");
6634
+ var import_node_path6 = __toESM(require("path"), 1);
6635
+ var import_node_process13 = __toESM(require("process"), 1);
6636
+ var import_yaml2 = require("yaml");
6637
+ var adjectives = [
6638
+ "brave",
6639
+ "calm",
6640
+ "dark",
6641
+ "eager",
6642
+ "fair",
6643
+ "glad",
6644
+ "happy",
6645
+ "idle",
6646
+ "jolly",
6647
+ "keen",
6648
+ "lame",
6649
+ "mild",
6650
+ "neat",
6651
+ "odd",
6652
+ "pale",
6653
+ "quick",
6654
+ "rare",
6655
+ "safe",
6656
+ "tall",
6657
+ "ugly",
6658
+ "vast",
6659
+ "warm",
6660
+ "young",
6661
+ "zany",
6662
+ "bold",
6663
+ "cool",
6664
+ "dry",
6665
+ "fast",
6666
+ "good",
6667
+ "hot",
6668
+ "icy",
6669
+ "loud"
6670
+ ];
6671
+ var nouns = [
6672
+ "ant",
6673
+ "bear",
6674
+ "cat",
6675
+ "dog",
6676
+ "elk",
6677
+ "fox",
6678
+ "goat",
6679
+ "hawk",
6680
+ "ibis",
6681
+ "jay",
6682
+ "kite",
6683
+ "lion",
6684
+ "mole",
6685
+ "newt",
6686
+ "owl",
6687
+ "puma",
6688
+ "quail",
6689
+ "ram",
6690
+ "seal",
6691
+ "toad",
6692
+ "urchin",
6693
+ "vole",
6694
+ "wolf",
6695
+ "yak",
6696
+ "zebra",
6697
+ "ape",
6698
+ "bat",
6699
+ "cow",
6700
+ "deer",
6701
+ "emu",
6702
+ "frog",
6703
+ "gull"
6704
+ ];
6705
+ function generateChangesetId() {
6706
+ const adjective = adjectives[Math.floor(Math.random() * adjectives.length)];
6707
+ const noun = nouns[Math.floor(Math.random() * nouns.length)];
6708
+ const suffix = Math.random().toString(36).slice(2, 6);
6709
+ return `${adjective}-${noun}-${suffix}`;
6710
+ }
6711
+ function generateChangesetContent(releases, summary) {
6712
+ let content = "---\n";
6713
+ if (releases.length > 0) {
6714
+ const yamlObj = {};
6715
+ for (const release of releases) {
6716
+ yamlObj[release.name] = release.type;
6717
+ }
6718
+ content += (0, import_yaml2.stringify)(yamlObj);
6719
+ }
6720
+ content += "---\n";
6721
+ if (summary) {
6722
+ content += `
6723
+ ${summary}
6724
+ `;
6725
+ }
6726
+ return content;
6727
+ }
6728
+ function writeChangeset(releases, summary, cwd = import_node_process13.default.cwd()) {
6729
+ const changesetsDir = import_node_path6.default.join(cwd, ".pubm", "changesets");
6730
+ (0, import_node_fs4.mkdirSync)(changesetsDir, { recursive: true });
6731
+ const id = generateChangesetId();
6732
+ const fileName = `${id}.md`;
6733
+ const filePath = import_node_path6.default.join(changesetsDir, fileName);
6734
+ const content = generateChangesetContent(releases, summary);
6735
+ (0, import_node_fs4.writeFileSync)(filePath, content, "utf-8");
6736
+ return filePath;
6737
+ }
6738
+
6739
+ // src/config/defaults.ts
6740
+ var defaultValidate = {
6741
+ cleanInstall: true,
6742
+ entryPoints: true,
6743
+ extraneousFiles: true
6744
+ };
6745
+ var defaultSnapshot = {
6746
+ useCalculatedVersion: false,
6747
+ prereleaseTemplate: "{tag}-{timestamp}"
6748
+ };
6749
+ var defaultConfig = {
6750
+ versioning: "independent",
6751
+ branch: "main",
6752
+ changelog: true,
6753
+ changelogFormat: "default",
6754
+ commit: false,
6755
+ access: "public",
6756
+ fixed: [],
6757
+ linked: [],
6758
+ updateInternalDependencies: "patch",
6759
+ ignore: [],
6760
+ tag: "latest",
6761
+ contents: ".",
6762
+ saveToken: true,
6763
+ releaseDraft: true,
6764
+ releaseNotes: true,
6765
+ registries: ["npm", "jsr"],
6766
+ rollbackStrategy: "individual"
6767
+ };
6768
+ function resolveConfig(config) {
6769
+ const packages = config.packages ?? [
6770
+ { path: ".", registries: ["npm", "jsr"] }
6771
+ ];
6772
+ return {
6773
+ ...defaultConfig,
6774
+ ...config,
6775
+ packages,
6776
+ validate: { ...defaultValidate, ...config.validate },
6777
+ snapshot: { ...defaultSnapshot, ...config.snapshot }
6778
+ };
6779
+ }
6780
+
6781
+ // src/config/loader.ts
6782
+ var import_promises3 = require("fs/promises");
6783
+ var import_node_path7 = __toESM(require("path"), 1);
6784
+ var CONFIG_FILES = [
6785
+ "pubm.config.ts",
6786
+ "pubm.config.mts",
6787
+ "pubm.config.cts",
6788
+ "pubm.config.js",
6789
+ "pubm.config.mjs",
6790
+ "pubm.config.cjs"
6791
+ ];
6792
+ async function findConfigFile(cwd) {
6793
+ for (const file of CONFIG_FILES) {
6794
+ const filePath = import_node_path7.default.join(cwd, file);
6795
+ try {
6796
+ if ((await (0, import_promises3.stat)(filePath)).isFile()) {
6797
+ return filePath;
6798
+ }
6799
+ } catch {
6800
+ }
6801
+ }
6802
+ return null;
6803
+ }
6804
+ async function loadConfig(cwd = process.cwd()) {
6805
+ const configPath = await findConfigFile(cwd);
6806
+ if (!configPath) return null;
6807
+ const { createJiti } = await import("jiti");
6808
+ const jiti = createJiti(cwd, { interopDefault: true });
6809
+ const mod = await jiti.import(configPath);
6810
+ return mod.default ?? mod;
6811
+ }
6812
+
6813
+ // src/config/types.ts
6814
+ function defineConfig(config) {
6815
+ return config;
6816
+ }
6817
+
6818
+ // src/monorepo/dependency-graph.ts
6819
+ function buildDependencyGraph(packages) {
6820
+ const packageNames = new Set(packages.map((pkg) => pkg.name));
6821
+ const graph = /* @__PURE__ */ new Map();
6822
+ for (const pkg of packages) {
6823
+ const internalDeps = Object.keys(pkg.dependencies).filter(
6824
+ (dep) => packageNames.has(dep)
6825
+ );
6826
+ graph.set(pkg.name, internalDeps);
6827
+ }
6828
+ return graph;
6829
+ }
6830
+ function topologicalSort(graph) {
6831
+ const inDegree = /* @__PURE__ */ new Map();
6832
+ for (const name of graph.keys()) {
6833
+ inDegree.set(name, 0);
6834
+ }
6835
+ for (const [, deps] of graph) {
6836
+ for (const dep of deps) {
6837
+ inDegree.set(dep, (inDegree.get(dep) ?? 0) + 1);
6838
+ }
6839
+ }
6840
+ const queue = [];
6841
+ for (const [name, degree] of inDegree) {
6842
+ if (degree === 0) {
6843
+ queue.push(name);
6844
+ }
6845
+ }
6846
+ const sorted = [];
6847
+ while (queue.length > 0) {
6848
+ const node = queue.shift();
6849
+ sorted.push(node);
6850
+ for (const dep of graph.get(node) ?? []) {
6851
+ const newDegree = (inDegree.get(dep) ?? 0) - 1;
6852
+ inDegree.set(dep, newDegree);
6853
+ if (newDegree === 0) {
6854
+ queue.push(dep);
6855
+ }
6856
+ }
6857
+ }
6858
+ if (sorted.length !== graph.size) {
6859
+ throw new Error("Circular dependency detected");
6860
+ }
6861
+ return sorted.reverse();
6862
+ }
6863
+
6864
+ // src/monorepo/groups.ts
6865
+ var import_micromatch = __toESM(require("micromatch"), 1);
6866
+ function resolveGroups(groups, allPackages) {
6867
+ return groups.map((group) => {
6868
+ const resolved = /* @__PURE__ */ new Set();
6869
+ for (const pattern of group) {
6870
+ const matches = (0, import_micromatch.default)(allPackages, pattern);
6871
+ for (const match of matches) {
6872
+ resolved.add(match);
6873
+ }
6874
+ }
6875
+ return [...resolved];
6876
+ });
6877
+ }
6878
+ function applyFixedGroup(bumps, group) {
6879
+ let max = null;
6880
+ for (const pkg of group) {
6881
+ const bump = bumps.get(pkg);
6882
+ if (bump) {
6883
+ max = max ? maxBump(max, bump) : bump;
6884
+ }
6885
+ }
6886
+ if (!max) return;
6887
+ for (const pkg of group) {
6888
+ bumps.set(pkg, max);
6889
+ }
6890
+ }
6891
+ function applyLinkedGroup(bumps, group) {
6892
+ let max = null;
6893
+ for (const pkg of group) {
6894
+ const bump = bumps.get(pkg);
6895
+ if (bump) {
6896
+ max = max ? maxBump(max, bump) : bump;
6897
+ }
6898
+ }
6899
+ if (!max) return;
6900
+ for (const pkg of group) {
6901
+ if (bumps.has(pkg)) {
6902
+ bumps.set(pkg, max);
6903
+ }
6904
+ }
6905
+ }
6906
+
6907
+ // src/monorepo/workspace.ts
6908
+ var import_node_fs5 = require("fs");
6909
+ var import_node_path8 = require("path");
6910
+ var import_yaml3 = require("yaml");
6911
+ function detectWorkspace(cwd) {
6912
+ const root = cwd ?? process.cwd();
6913
+ const pnpmWorkspacePath = (0, import_node_path8.join)(root, "pnpm-workspace.yaml");
6914
+ if ((0, import_node_fs5.existsSync)(pnpmWorkspacePath)) {
6915
+ const content = (0, import_node_fs5.readFileSync)(pnpmWorkspacePath, "utf-8");
6916
+ const parsed = (0, import_yaml3.parse)(content);
6917
+ const packages = parsed?.packages ?? [];
6918
+ return { type: "pnpm", patterns: packages };
6919
+ }
6920
+ const packageJsonPath = (0, import_node_path8.join)(root, "package.json");
6921
+ if ((0, import_node_fs5.existsSync)(packageJsonPath)) {
6922
+ const content = (0, import_node_fs5.readFileSync)(packageJsonPath, "utf-8");
6923
+ const pkg = JSON.parse(content);
6924
+ if (pkg.workspaces) {
6925
+ if (Array.isArray(pkg.workspaces)) {
6926
+ return { type: "npm", patterns: pkg.workspaces };
6927
+ }
6928
+ if (typeof pkg.workspaces === "object" && Array.isArray(pkg.workspaces.packages)) {
6929
+ return { type: "yarn", patterns: pkg.workspaces.packages };
6930
+ }
6931
+ }
6932
+ }
6933
+ return null;
6934
+ }
6935
+
6936
+ // src/prerelease/pre.ts
6937
+ var import_node_fs6 = require("fs");
6938
+ var import_node_path9 = __toESM(require("path"), 1);
6939
+ function getPreStatePath(cwd) {
6940
+ return import_node_path9.default.resolve(cwd ?? process.cwd(), ".pubm", "pre.json");
6941
+ }
6942
+ function readPreState(cwd) {
6943
+ const filePath = getPreStatePath(cwd);
6944
+ if (!(0, import_node_fs6.existsSync)(filePath)) {
6945
+ return null;
6946
+ }
6947
+ const content = (0, import_node_fs6.readFileSync)(filePath, "utf-8");
6948
+ return JSON.parse(content);
6949
+ }
6950
+ function enterPreMode(tag, cwd) {
6951
+ const filePath = getPreStatePath(cwd);
6952
+ if ((0, import_node_fs6.existsSync)(filePath)) {
6953
+ throw new Error(
6954
+ "Already in pre mode. Exit pre mode first before entering a new one."
6955
+ );
6956
+ }
6957
+ const dir = import_node_path9.default.dirname(filePath);
6958
+ if (!(0, import_node_fs6.existsSync)(dir)) {
6959
+ (0, import_node_fs6.mkdirSync)(dir, { recursive: true });
6960
+ }
6961
+ const state = {
6962
+ mode: "pre",
6963
+ tag,
6964
+ packages: {}
6965
+ };
6966
+ (0, import_node_fs6.writeFileSync)(filePath, JSON.stringify(state, null, 2), "utf-8");
6967
+ }
6968
+ function exitPreMode(cwd) {
6969
+ const filePath = getPreStatePath(cwd);
6970
+ if (!(0, import_node_fs6.existsSync)(filePath)) {
6971
+ throw new Error("Not in pre mode. Enter pre mode first before exiting.");
6972
+ }
6973
+ (0, import_node_fs6.rmSync)(filePath);
6974
+ }
6975
+
6976
+ // src/prerelease/snapshot.ts
6977
+ function formatTimestamp(date) {
6978
+ const year = date.getUTCFullYear();
6979
+ const month = String(date.getUTCMonth() + 1).padStart(2, "0");
6980
+ const day = String(date.getUTCDate()).padStart(2, "0");
6981
+ const hours = String(date.getUTCHours()).padStart(2, "0");
6982
+ const minutes = String(date.getUTCMinutes()).padStart(2, "0");
6983
+ const seconds = String(date.getUTCSeconds()).padStart(2, "0");
6984
+ return `${year}${month}${day}T${hours}${minutes}${seconds}`;
6985
+ }
6986
+ function generateSnapshotVersion(options) {
6987
+ const tag = options.tag ?? "snapshot";
6988
+ const base = options.useCalculatedVersion && options.baseVersion ? options.baseVersion : "0.0.0";
6989
+ const now = /* @__PURE__ */ new Date();
6990
+ const timestamp = formatTimestamp(now);
6991
+ if (options.template) {
6992
+ return options.template.replace(/\{base\}/g, base).replace(/\{tag\}/g, tag).replace(/\{timestamp\}/g, timestamp).replace(/\{commit\}/g, options.commit ?? "").replace(/\{datetime\}/g, timestamp);
6993
+ }
6994
+ return `${base}-${tag}-${timestamp}`;
6995
+ }
6996
+
6997
+ // src/validate/entry-points.ts
6998
+ var import_node_fs7 = require("fs");
6999
+ var import_node_path10 = __toESM(require("path"), 1);
7000
+ var SIMPLE_FIELDS = ["main", "module", "types", "typings"];
7001
+ function checkPath(filePath, cwd) {
7002
+ return (0, import_node_fs7.existsSync)(import_node_path10.default.resolve(cwd, filePath));
7003
+ }
7004
+ function validateExports(exports2, cwd, prefix = "exports") {
7005
+ const errors = [];
7006
+ if (typeof exports2 === "string") {
7007
+ if (!checkPath(exports2, cwd)) {
7008
+ errors.push({ field: prefix, path: exports2 });
7009
+ }
7010
+ return errors;
7011
+ }
7012
+ if (typeof exports2 === "object" && exports2 !== null) {
7013
+ for (const [key, value] of Object.entries(exports2)) {
7014
+ if (typeof value === "string") {
7015
+ if (!checkPath(value, cwd)) {
7016
+ errors.push({ field: `${prefix}["${key}"]`, path: value });
7017
+ }
7018
+ } else if (typeof value === "object" && value !== null) {
7019
+ errors.push(...validateExports(value, cwd, `${prefix}["${key}"]`));
7020
+ }
7021
+ }
7022
+ }
7023
+ return errors;
7024
+ }
7025
+ function validateEntryPoints(pkg, cwd) {
7026
+ const errors = [];
7027
+ for (const field of SIMPLE_FIELDS) {
7028
+ const value = pkg[field];
7029
+ if (typeof value === "string" && !checkPath(value, cwd)) {
7030
+ errors.push({ field, path: value });
7031
+ }
7032
+ }
7033
+ if (pkg.exports !== void 0) {
7034
+ errors.push(...validateExports(pkg.exports, cwd));
7035
+ }
7036
+ if (pkg.bin !== void 0) {
7037
+ if (typeof pkg.bin === "string") {
7038
+ if (!checkPath(pkg.bin, cwd)) {
7039
+ errors.push({ field: "bin", path: pkg.bin });
7040
+ }
7041
+ } else if (typeof pkg.bin === "object" && pkg.bin !== null) {
7042
+ for (const [name, binPath] of Object.entries(
7043
+ pkg.bin
7044
+ )) {
7045
+ if (!checkPath(binPath, cwd)) {
7046
+ errors.push({ field: `bin.${name}`, path: binPath });
7047
+ }
7048
+ }
7049
+ }
7050
+ }
7051
+ return errors;
7052
+ }
7053
+
7054
+ // src/validate/extraneous-files.ts
7055
+ var import_micromatch2 = __toESM(require("micromatch"), 1);
7056
+ var PATTERNS = [
7057
+ {
7058
+ pattern: [".env", ".env.*"],
7059
+ reason: "potentially contains secrets",
7060
+ basename: true
7061
+ },
7062
+ {
7063
+ pattern: ["*.test.*", "*.spec.*"],
7064
+ reason: "test file",
7065
+ basename: true
7066
+ },
7067
+ {
7068
+ pattern: ["**/__tests__/**"],
7069
+ reason: "test file"
7070
+ },
7071
+ { pattern: ["*.map"], reason: "source map", basename: true },
7072
+ {
7073
+ pattern: [
7074
+ ".eslintrc*",
7075
+ ".prettierrc*",
7076
+ "tsconfig.json",
7077
+ "tsconfig.*.json",
7078
+ ".babelrc*",
7079
+ "jest.config.*",
7080
+ "vitest.config.*",
7081
+ ".editorconfig",
7082
+ "biome.json"
7083
+ ],
7084
+ reason: "development config file",
7085
+ basename: true
7086
+ }
7087
+ ];
7088
+ function detectExtraneousFiles(files) {
7089
+ const result = [];
7090
+ const seen = /* @__PURE__ */ new Set();
7091
+ for (const { pattern, reason, basename } of PATTERNS) {
7092
+ const options = basename ? { basename: true } : {};
7093
+ const matched = (0, import_micromatch2.default)(files, pattern, options);
7094
+ for (const file of matched) {
7095
+ if (!seen.has(file)) {
7096
+ seen.add(file);
7097
+ result.push({ file, reason });
7098
+ }
7099
+ }
7100
+ }
7101
+ return result;
7102
+ }
7103
+
6187
7104
  // src/index.ts
6188
7105
  async function pubm(options) {
6189
7106
  const resolvedOptions = resolveOptions({ ...options });
@@ -6191,5 +7108,29 @@ async function pubm(options) {
6191
7108
  }
6192
7109
  // Annotate the CommonJS export names for ESM import in node:
6193
7110
  0 && (module.exports = {
6194
- pubm
7111
+ applyFixedGroup,
7112
+ applyLinkedGroup,
7113
+ buildDependencyGraph,
7114
+ calculateVersionBumps,
7115
+ defineConfig,
7116
+ detectExtraneousFiles,
7117
+ detectWorkspace,
7118
+ enterPreMode,
7119
+ exitPreMode,
7120
+ generateChangelog,
7121
+ generateChangesetContent,
7122
+ generateChangesetId,
7123
+ generateSnapshotVersion,
7124
+ getStatus,
7125
+ loadConfig,
7126
+ migrateFromChangesets,
7127
+ parseChangeset,
7128
+ pubm,
7129
+ readChangesets,
7130
+ readPreState,
7131
+ resolveConfig,
7132
+ resolveGroups,
7133
+ topologicalSort,
7134
+ validateEntryPoints,
7135
+ writeChangeset
6195
7136
  });