pubm 0.1.4 → 0.1.5

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
@@ -2416,15 +2416,15 @@ var isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !is
2416
2416
  var isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
2417
2417
  var isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
2418
2418
  var replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
2419
- var clearBleed = (index, string, open3, close, replace) => index < 0 ? open3 + string + close : open3 + replaceClose(index, string, close, replace) + close;
2420
- var filterEmpty = (open3, close, replace = open3, at = open3.length + 1) => (string) => string || !(string === "" || string === void 0) ? clearBleed(
2419
+ var clearBleed = (index, string, open4, close, replace) => index < 0 ? open4 + string + close : open4 + replaceClose(index, string, close, replace) + close;
2420
+ var filterEmpty = (open4, close, replace = open4, at = open4.length + 1) => (string) => string || !(string === "" || string === void 0) ? clearBleed(
2421
2421
  ("" + string).indexOf(close, at),
2422
2422
  string,
2423
- open3,
2423
+ open4,
2424
2424
  close,
2425
2425
  replace
2426
2426
  ) : "";
2427
- var init = (open3, close, replace) => filterEmpty(`\x1B[${open3}m`, `\x1B[${close}m`, replace);
2427
+ var init = (open4, close, replace) => filterEmpty(`\x1B[${open4}m`, `\x1B[${close}m`, replace);
2428
2428
  var colors = {
2429
2429
  reset: init(0, 0),
2430
2430
  bold: init(1, 22, "\x1B[22m\x1B[1m"),
@@ -4945,7 +4945,8 @@ var Git = class {
4945
4945
  async revisionDiffsCount() {
4946
4946
  try {
4947
4947
  return Number.parseInt(
4948
- await this.git(["rev-list", "@{u}...HEAD", "--count", "--left-only"])
4948
+ await this.git(["rev-list", "@{u}...HEAD", "--count", "--left-only"]),
4949
+ 10
4949
4950
  );
4950
4951
  } catch (error) {
4951
4952
  throw new GitError(
@@ -5145,6 +5146,80 @@ var Git = class {
5145
5146
  }
5146
5147
  };
5147
5148
 
5149
+ // src/config/defaults.ts
5150
+ var defaultValidate = {
5151
+ cleanInstall: true,
5152
+ entryPoints: true,
5153
+ extraneousFiles: true
5154
+ };
5155
+ var defaultSnapshot = {
5156
+ useCalculatedVersion: false,
5157
+ prereleaseTemplate: "{tag}-{timestamp}"
5158
+ };
5159
+ var defaultConfig = {
5160
+ versioning: "independent",
5161
+ branch: "main",
5162
+ changelog: true,
5163
+ changelogFormat: "default",
5164
+ commit: false,
5165
+ access: "public",
5166
+ fixed: [],
5167
+ linked: [],
5168
+ updateInternalDependencies: "patch",
5169
+ ignore: [],
5170
+ tag: "latest",
5171
+ contents: ".",
5172
+ saveToken: true,
5173
+ releaseDraft: true,
5174
+ releaseNotes: true,
5175
+ registries: ["npm", "jsr"],
5176
+ rollbackStrategy: "individual"
5177
+ };
5178
+ function resolveConfig(config) {
5179
+ const packages = config.packages ?? [
5180
+ { path: ".", registries: ["npm", "jsr"] }
5181
+ ];
5182
+ return {
5183
+ ...defaultConfig,
5184
+ ...config,
5185
+ packages,
5186
+ validate: { ...defaultValidate, ...config.validate },
5187
+ snapshot: { ...defaultSnapshot, ...config.snapshot }
5188
+ };
5189
+ }
5190
+
5191
+ // src/config/loader.ts
5192
+ import { stat } from "node:fs/promises";
5193
+ import path6 from "node:path";
5194
+ var CONFIG_FILES = [
5195
+ "pubm.config.ts",
5196
+ "pubm.config.mts",
5197
+ "pubm.config.cts",
5198
+ "pubm.config.js",
5199
+ "pubm.config.mjs",
5200
+ "pubm.config.cjs"
5201
+ ];
5202
+ async function findConfigFile(cwd) {
5203
+ for (const file of CONFIG_FILES) {
5204
+ const filePath = path6.join(cwd, file);
5205
+ try {
5206
+ if ((await stat(filePath)).isFile()) {
5207
+ return filePath;
5208
+ }
5209
+ } catch {
5210
+ }
5211
+ }
5212
+ return null;
5213
+ }
5214
+ async function loadConfig(cwd = process.cwd()) {
5215
+ const configPath = await findConfigFile(cwd);
5216
+ if (!configPath) return null;
5217
+ const { createJiti } = await import("jiti");
5218
+ const jiti = createJiti(cwd, { interopDefault: true });
5219
+ const mod = await jiti.import(configPath);
5220
+ return mod.default ?? mod;
5221
+ }
5222
+
5148
5223
  // src/options.ts
5149
5224
  var defaultOptions = {
5150
5225
  testScript: "test",
@@ -5154,13 +5229,16 @@ var defaultOptions = {
5154
5229
  registries: ["npm", "jsr"]
5155
5230
  };
5156
5231
  function resolveOptions(options) {
5157
- const nextOptions = { ...options, ...defaultOptions };
5232
+ const defined = Object.fromEntries(
5233
+ Object.entries(options).filter(([, v]) => v !== void 0)
5234
+ );
5235
+ const nextOptions = { ...defaultOptions, ...defined };
5158
5236
  return nextOptions;
5159
5237
  }
5160
5238
 
5161
5239
  // src/tasks/runner.ts
5162
5240
  import process14 from "node:process";
5163
- import npmCli2 from "@npmcli/promise-spawn";
5241
+ import npmCli3 from "@npmcli/promise-spawn";
5164
5242
  import SemVer from "semver";
5165
5243
  import { isCI as isCI2 } from "std-env";
5166
5244
  import { exec as exec7 } from "tinyexec";
@@ -5211,8 +5289,8 @@ function createListr(...args) {
5211
5289
  }
5212
5290
 
5213
5291
  // src/utils/package.ts
5214
- import { readFile, stat, writeFile } from "node:fs/promises";
5215
- import path6 from "node:path";
5292
+ import { readFile, stat as stat2, writeFile } from "node:fs/promises";
5293
+ import path7 from "node:path";
5216
5294
  import process11 from "node:process";
5217
5295
  var cachedPackageJson = {};
5218
5296
  var cachedJsrJson = {};
@@ -5222,16 +5300,16 @@ function patchCachedJsrJson(contents, { cwd = process11.cwd() } = {}) {
5222
5300
  async function findOutFile(file, { cwd = process11.cwd() } = {}) {
5223
5301
  let directory = cwd;
5224
5302
  let filePath = "";
5225
- const { root } = path6.parse(cwd);
5303
+ const { root } = path7.parse(cwd);
5226
5304
  while (directory) {
5227
- filePath = path6.join(directory, file);
5305
+ filePath = path7.join(directory, file);
5228
5306
  try {
5229
- if ((await stat(filePath)).isFile()) {
5307
+ if ((await stat2(filePath)).isFile()) {
5230
5308
  break;
5231
5309
  }
5232
5310
  } catch {
5233
5311
  }
5234
- directory = path6.dirname(directory);
5312
+ directory = path7.dirname(directory);
5235
5313
  if (directory === root) return null;
5236
5314
  }
5237
5315
  return filePath;
@@ -5417,8 +5495,8 @@ async function getPackageManager() {
5417
5495
  }
5418
5496
 
5419
5497
  // src/ecosystem/rust.ts
5420
- import { readFile as readFile2, stat as stat2, writeFile as writeFile2 } from "node:fs/promises";
5421
- import path7 from "node:path";
5498
+ import { readFile as readFile2, stat as stat3, writeFile as writeFile2 } from "node:fs/promises";
5499
+ import path8 from "node:path";
5422
5500
  import { parse, stringify } from "smol-toml";
5423
5501
 
5424
5502
  // src/ecosystem/ecosystem.ts
@@ -5432,14 +5510,14 @@ var Ecosystem = class {
5432
5510
  var RustEcosystem = class extends Ecosystem {
5433
5511
  static async detect(packagePath) {
5434
5512
  try {
5435
- return (await stat2(path7.join(packagePath, "Cargo.toml"))).isFile();
5513
+ return (await stat3(path8.join(packagePath, "Cargo.toml"))).isFile();
5436
5514
  } catch {
5437
5515
  return false;
5438
5516
  }
5439
5517
  }
5440
5518
  async readCargoToml() {
5441
5519
  const raw = await readFile2(
5442
- path7.join(this.packagePath, "Cargo.toml"),
5520
+ path8.join(this.packagePath, "Cargo.toml"),
5443
5521
  "utf-8"
5444
5522
  );
5445
5523
  return parse(raw);
@@ -5455,7 +5533,7 @@ var RustEcosystem = class extends Ecosystem {
5455
5533
  return pkg.version;
5456
5534
  }
5457
5535
  async writeVersion(newVersion) {
5458
- const filePath = path7.join(this.packagePath, "Cargo.toml");
5536
+ const filePath = path8.join(this.packagePath, "Cargo.toml");
5459
5537
  const raw = await readFile2(filePath, "utf-8");
5460
5538
  const cargo = parse(raw);
5461
5539
  const pkg = cargo.package;
@@ -5641,6 +5719,7 @@ var cratesPublishTasks = {
5641
5719
  // src/tasks/jsr.ts
5642
5720
  import process12 from "node:process";
5643
5721
  import { ListrEnquirerPromptAdapter } from "@listr2/prompt-adapter-enquirer";
5722
+ import npmCli from "@npmcli/promise-spawn";
5644
5723
 
5645
5724
  // src/registry/jsr.ts
5646
5725
  import { exec as exec4, NonZeroExitError } from "tinyexec";
@@ -5648,7 +5727,7 @@ import { exec as exec4, NonZeroExitError } from "tinyexec";
5648
5727
  // src/utils/db.ts
5649
5728
  import { createCipheriv, createDecipheriv, createHash } from "node:crypto";
5650
5729
  import { mkdirSync as mkdirSync5, readFileSync as readFileSync3, statSync, writeFileSync as writeFileSync4 } from "node:fs";
5651
- import path8 from "node:path";
5730
+ import path9 from "node:path";
5652
5731
  var a = "aes-256-cbc";
5653
5732
  var n = statSync(import.meta.dirname);
5654
5733
  var k = `${n.rdev}${n.birthtimeMs}${n.nlink}${n.gid}`;
@@ -5663,7 +5742,7 @@ function d(g, h) {
5663
5742
  }
5664
5743
  var Db = class {
5665
5744
  constructor() {
5666
- __publicField(this, "path", path8.resolve(import.meta.dirname, ".pubm"));
5745
+ __publicField(this, "path", path9.resolve(import.meta.dirname, ".pubm"));
5667
5746
  try {
5668
5747
  if (!statSync(this.path).isDirectory()) {
5669
5748
  mkdirSync5(this.path);
@@ -5681,7 +5760,7 @@ var Db = class {
5681
5760
  set(field, value) {
5682
5761
  try {
5683
5762
  writeFileSync4(
5684
- path8.resolve(
5763
+ path9.resolve(
5685
5764
  this.path,
5686
5765
  Buffer.from(e(field, field)).toString("base64")
5687
5766
  ),
@@ -5695,7 +5774,7 @@ var Db = class {
5695
5774
  }
5696
5775
  }
5697
5776
  get(field) {
5698
- const filePath = path8.resolve(
5777
+ const filePath = path9.resolve(
5699
5778
  this.path,
5700
5779
  Buffer.from(e(field, field)).toString("base64")
5701
5780
  );
@@ -5777,6 +5856,7 @@ var JsrRegisry = class extends Registry {
5777
5856
  super(packageName, registry);
5778
5857
  __publicField(this, "registry", "https://jsr.io");
5779
5858
  __publicField(this, "client");
5859
+ __publicField(this, "packageCreationUrls");
5780
5860
  this.client = new JsrClient(getApiEndpoint(this.registry));
5781
5861
  }
5782
5862
  async jsr(args) {
@@ -5818,9 +5898,19 @@ var JsrRegisry = class extends Registry {
5818
5898
  throwOnError: true
5819
5899
  }
5820
5900
  );
5901
+ this.packageCreationUrls = void 0;
5821
5902
  return true;
5822
5903
  } catch (error) {
5823
5904
  const stderr = error instanceof NonZeroExitError ? error.output?.stderr : void 0;
5905
+ if (stderr?.includes("don't exist")) {
5906
+ const urls = [...stderr.matchAll(/https:\/\/jsr\.io\/new\S+/g)].map(
5907
+ (m) => m[0]
5908
+ );
5909
+ if (urls.length > 0) {
5910
+ this.packageCreationUrls = urls;
5911
+ return false;
5912
+ }
5913
+ }
5824
5914
  throw new JsrError(
5825
5915
  `Failed to run \`jsr publish --allow-dirty --token ***\`${stderr ? `
5826
5916
  ${stderr}` : ""}`,
@@ -6261,6 +6351,7 @@ async function npmRegistry() {
6261
6351
  }
6262
6352
 
6263
6353
  // src/tasks/jsr.ts
6354
+ var { open } = npmCli;
6264
6355
  var JsrAvailableError = class extends AbstractError {
6265
6356
  constructor(message, { cause } = {}) {
6266
6357
  super(message, { cause });
@@ -6441,7 +6532,39 @@ var jsrPublishTasks = {
6441
6532
  }
6442
6533
  JsrClient.token = jsrTokenEnv;
6443
6534
  }
6444
- await jsr.publish();
6535
+ let result = await jsr.publish();
6536
+ if (!result && jsr.packageCreationUrls) {
6537
+ if (ctx.promptEnabled) {
6538
+ task.title = "Running jsr publish (package creation needed)";
6539
+ const urls = jsr.packageCreationUrls;
6540
+ const maxAttempts = 3;
6541
+ task.output = `Package doesn't exist on jsr. Create it at:
6542
+ ${urls.map((url) => ` ${color.cyan(url)}`).join("\n")}`;
6543
+ open(urls[0]);
6544
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
6545
+ await task.prompt(ListrEnquirerPromptAdapter).run({
6546
+ type: "input",
6547
+ message: `Press ${color.bold("enter")} after creating the package on jsr.io${attempt > 1 ? ` (attempt ${attempt}/${maxAttempts})` : ""}`
6548
+ });
6549
+ result = await jsr.publish();
6550
+ if (result) break;
6551
+ if (attempt < maxAttempts) {
6552
+ task.output = "Package still doesn't exist. Please create it and try again.";
6553
+ }
6554
+ }
6555
+ if (!result) {
6556
+ throw new JsrAvailableError(
6557
+ "Package creation not completed after 3 attempts."
6558
+ );
6559
+ }
6560
+ task.title = "Running jsr publish (package created)";
6561
+ } else {
6562
+ throw new JsrAvailableError(
6563
+ `Package doesn't exist on jsr. Create it at:
6564
+ ${jsr.packageCreationUrls.join("\n")}`
6565
+ );
6566
+ }
6567
+ }
6445
6568
  }
6446
6569
  };
6447
6570
 
@@ -6449,8 +6572,8 @@ var jsrPublishTasks = {
6449
6572
  import { spawn } from "node:child_process";
6450
6573
  import process13 from "node:process";
6451
6574
  import { ListrEnquirerPromptAdapter as ListrEnquirerPromptAdapter2 } from "@listr2/prompt-adapter-enquirer";
6452
- import npmCli from "@npmcli/promise-spawn";
6453
- var { open } = npmCli;
6575
+ import npmCli2 from "@npmcli/promise-spawn";
6576
+ var { open: open2 } = npmCli2;
6454
6577
  var NpmAvailableError = class extends AbstractError {
6455
6578
  constructor(message, { cause } = {}) {
6456
6579
  super(message, { cause });
@@ -6480,7 +6603,7 @@ var npmAvailableCheckTasks = {
6480
6603
  if (urlMatch && !opened) {
6481
6604
  opened = true;
6482
6605
  task.output = `Login at: ${color.cyan(urlMatch[0])}`;
6483
- open(urlMatch[0]);
6606
+ open2(urlMatch[0]);
6484
6607
  child.stdin?.write("\n");
6485
6608
  }
6486
6609
  };
@@ -6907,8 +7030,24 @@ var requiredConditionsCheckTask = (options) => createListr({
6907
7030
  });
6908
7031
 
6909
7032
  // src/tasks/runner.ts
6910
- var { open: open2 } = npmCli2;
7033
+ var { open: open3 } = npmCli3;
6911
7034
  var { prerelease } = SemVer;
7035
+ function collectRegistries(ctx) {
7036
+ if (ctx.packages?.length) {
7037
+ const seen = /* @__PURE__ */ new Set();
7038
+ const result = [];
7039
+ for (const pkg of ctx.packages) {
7040
+ for (const reg of pkg.registries) {
7041
+ if (!seen.has(reg)) {
7042
+ seen.add(reg);
7043
+ result.push(reg);
7044
+ }
7045
+ }
7046
+ }
7047
+ return result;
7048
+ }
7049
+ return ctx.registries;
7050
+ }
6912
7051
  async function run(options) {
6913
7052
  const ctx = {
6914
7053
  ...options,
@@ -6928,7 +7067,7 @@ async function run(options) {
6928
7067
  options.publishOnly ? {
6929
7068
  title: "Publishing",
6930
7069
  task: (ctx2, parentTask) => parentTask.newListr(
6931
- ctx2.registries.map((registry) => {
7070
+ collectRegistries(ctx2).map((registry) => {
6932
7071
  switch (registry) {
6933
7072
  case "npm":
6934
7073
  return npmPublishTasks;
@@ -7026,7 +7165,7 @@ async function run(options) {
7026
7165
  skip: (ctx2) => options.skipPublish || !!ctx2.preview,
7027
7166
  title: "Publishing",
7028
7167
  task: (ctx2, parentTask) => parentTask.newListr(
7029
- ctx2.registries.map((registry) => {
7168
+ collectRegistries(ctx2).map((registry) => {
7030
7169
  switch (registry) {
7031
7170
  case "npm":
7032
7171
  return npmPublishTasks;
@@ -7079,7 +7218,7 @@ ${repositoryUrl}/compare/${lastRev}...${latestTag}`;
7079
7218
  );
7080
7219
  const linkUrl = link2("Link", releaseDraftUrl.toString());
7081
7220
  task.title += ` ${linkUrl}`;
7082
- await open2(releaseDraftUrl.toString());
7221
+ await open3(releaseDraftUrl.toString());
7083
7222
  }
7084
7223
  }
7085
7224
  ]
@@ -7103,10 +7242,6 @@ ${repositoryUrl}/compare/${lastRev}...${latestTag}`;
7103
7242
  import process15 from "node:process";
7104
7243
  import { inc } from "semver";
7105
7244
 
7106
- // src/config/loader.ts
7107
- import { stat as stat3 } from "node:fs/promises";
7108
- import path9 from "node:path";
7109
-
7110
7245
  // src/monorepo/discover.ts
7111
7246
  import { existsSync as existsSync6, readdirSync as readdirSync3, statSync as statSync2 } from "node:fs";
7112
7247
  import path10 from "node:path";
@@ -7129,7 +7264,18 @@ import micromatch3 from "micromatch";
7129
7264
 
7130
7265
  // src/index.ts
7131
7266
  async function pubm(options) {
7132
- const resolvedOptions = resolveOptions({ ...options });
7267
+ const config = await loadConfig();
7268
+ const configOptions = {};
7269
+ if (config) {
7270
+ const resolved = resolveConfig(config);
7271
+ if (resolved.packages) {
7272
+ configOptions.packages = resolved.packages;
7273
+ }
7274
+ if (!options.registries && resolved.registries) {
7275
+ configOptions.registries = resolved.registries;
7276
+ }
7277
+ }
7278
+ const resolvedOptions = resolveOptions({ ...configOptions, ...options });
7133
7279
  await run(resolvedOptions);
7134
7280
  }
7135
7281