@pubm/core 0.4.4 → 0.4.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/dist/index.js CHANGED
@@ -20111,6 +20111,10 @@ async function openUrl(url) {
20111
20111
  var init_open_url = () => {};
20112
20112
 
20113
20113
  // src/plugin/runner.ts
20114
+ function isDefined(value) {
20115
+ return value !== undefined;
20116
+ }
20117
+
20114
20118
  class PluginRunner {
20115
20119
  plugins;
20116
20120
  constructor(plugins) {
@@ -20148,7 +20152,7 @@ class PluginRunner {
20148
20152
  }
20149
20153
  collectAssetHooks() {
20150
20154
  const collected = {};
20151
- const resolveChain = this.plugins.map((p) => p.hooks?.resolveAssets).filter(Boolean);
20155
+ const resolveChain = this.plugins.map((p) => p.hooks?.resolveAssets).filter(isDefined);
20152
20156
  if (resolveChain.length > 0) {
20153
20157
  collected.resolveAssets = async (assets, ctx) => {
20154
20158
  let result = assets;
@@ -20158,7 +20162,7 @@ class PluginRunner {
20158
20162
  return result;
20159
20163
  };
20160
20164
  }
20161
- const transformChain = this.plugins.map((p) => p.hooks?.transformAsset).filter(Boolean);
20165
+ const transformChain = this.plugins.map((p) => p.hooks?.transformAsset).filter(isDefined);
20162
20166
  if (transformChain.length > 0) {
20163
20167
  collected.transformAsset = async (asset, ctx) => {
20164
20168
  let items = [asset];
@@ -20173,17 +20177,18 @@ class PluginRunner {
20173
20177
  return items.length === 1 ? items[0] : items;
20174
20178
  };
20175
20179
  }
20176
- const compressChain = this.plugins.map((p) => p.hooks?.compressAsset).filter(Boolean);
20180
+ const compressChain = this.plugins.map((p) => p.hooks?.compressAsset).filter(isDefined);
20177
20181
  if (compressChain.length > 0) {
20178
20182
  collected.compressAsset = async (asset, ctx) => {
20179
- let result = asset;
20180
- for (const hook of compressChain) {
20183
+ const [firstHook, ...restHooks] = compressChain;
20184
+ let result = await firstHook(asset, ctx);
20185
+ for (const hook of restHooks) {
20181
20186
  result = await hook(result, ctx);
20182
20187
  }
20183
20188
  return result;
20184
20189
  };
20185
20190
  }
20186
- const nameChain = this.plugins.map((p) => p.hooks?.nameAsset).filter(Boolean);
20191
+ const nameChain = this.plugins.map((p) => p.hooks?.nameAsset).filter(isDefined);
20187
20192
  if (nameChain.length > 0) {
20188
20193
  collected.nameAsset = (asset, ctx) => {
20189
20194
  let result = "";
@@ -20193,7 +20198,7 @@ class PluginRunner {
20193
20198
  return result;
20194
20199
  };
20195
20200
  }
20196
- const checksumChain = this.plugins.map((p) => p.hooks?.generateChecksums).filter(Boolean);
20201
+ const checksumChain = this.plugins.map((p) => p.hooks?.generateChecksums).filter(isDefined);
20197
20202
  if (checksumChain.length > 0) {
20198
20203
  collected.generateChecksums = async (assets, ctx) => {
20199
20204
  let result = assets;
@@ -20203,7 +20208,7 @@ class PluginRunner {
20203
20208
  return result;
20204
20209
  };
20205
20210
  }
20206
- const uploadHooks = this.plugins.map((p) => p.hooks?.uploadAssets).filter(Boolean);
20211
+ const uploadHooks = this.plugins.map((p) => p.hooks?.uploadAssets).filter(isDefined);
20207
20212
  if (uploadHooks.length > 0) {
20208
20213
  collected.uploadAssets = async (assets, ctx) => {
20209
20214
  const allResults = [];
@@ -20219,7 +20224,7 @@ class PluginRunner {
20219
20224
  }
20220
20225
 
20221
20226
  // src/tasks/runner.ts
20222
- import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync8, rmSync as rmSync2 } from "node:fs";
20227
+ import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync9, rmSync as rmSync2 } from "node:fs";
20223
20228
  import { tmpdir as tmpdir2 } from "node:os";
20224
20229
  import path10, { join as join9 } from "node:path";
20225
20230
  import process17 from "node:process";
@@ -22860,6 +22865,7 @@ function createKeyResolver(packages) {
22860
22865
  }
22861
22866
 
22862
22867
  // src/ecosystem/js.ts
22868
+ import { existsSync as existsSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "node:fs";
22863
22869
  import { readFile as readFile3, writeFile } from "node:fs/promises";
22864
22870
  import path5 from "node:path";
22865
22871
 
@@ -22964,7 +22970,7 @@ function isValidPackageName(packageName) {
22964
22970
  // package.json
22965
22971
  var package_default = {
22966
22972
  name: "@pubm/core",
22967
- version: "0.4.4",
22973
+ version: "0.4.5",
22968
22974
  type: "module",
22969
22975
  description: "Core SDK for pubm - publish manager for multiple registries",
22970
22976
  types: "./dist/index.d.ts",
@@ -23038,7 +23044,7 @@ var coreEngines = package_default.engines ?? {};
23038
23044
  function resolveDefine(injected, fallback) {
23039
23045
  return typeof injected === "string" ? injected : fallback;
23040
23046
  }
23041
- var PUBM_VERSION = resolveDefine("0.4.4", package_default.version);
23047
+ var PUBM_VERSION = resolveDefine("0.4.5", package_default.version);
23042
23048
  var PUBM_ENGINES = {
23043
23049
  node: resolveDefine(">=24", coreEngines.node ?? ">=18"),
23044
23050
  git: resolveDefine(">=2.11.0", coreEngines.git ?? ">=2.11.0"),
@@ -24038,6 +24044,8 @@ async function getPackageManager() {
24038
24044
  }
24039
24045
 
24040
24046
  // src/ecosystem/ecosystem.ts
24047
+ import { writeFileSync as writeFileSync3 } from "node:fs";
24048
+
24041
24049
  class Ecosystem {
24042
24050
  packagePath;
24043
24051
  constructor(packagePath) {
@@ -24081,6 +24089,14 @@ class Ecosystem {
24081
24089
  async syncLockfile() {
24082
24090
  return;
24083
24091
  }
24092
+ async resolvePublishDependencies(_workspaceVersions) {
24093
+ return new Map;
24094
+ }
24095
+ restorePublishDependencies(backups) {
24096
+ for (const [filePath, content] of backups) {
24097
+ writeFileSync3(filePath, content, "utf-8");
24098
+ }
24099
+ }
24084
24100
  }
24085
24101
 
24086
24102
  // src/ecosystem/descriptor.ts
@@ -24151,6 +24167,48 @@ class JsEcosystem extends Ecosystem {
24151
24167
  supportedRegistries() {
24152
24168
  return ["npm", "jsr"];
24153
24169
  }
24170
+ async resolvePublishDependencies(workspaceVersions) {
24171
+ const backups = new Map;
24172
+ const manifestPath = path5.join(this.packagePath, "package.json");
24173
+ if (!existsSync3(manifestPath))
24174
+ return backups;
24175
+ const original = readFileSync4(manifestPath, "utf-8");
24176
+ const pkg = JSON.parse(original);
24177
+ let modified = false;
24178
+ const WORKSPACE_PREFIX = "workspace:";
24179
+ const DEPENDENCY_FIELDS = [
24180
+ "dependencies",
24181
+ "devDependencies",
24182
+ "optionalDependencies",
24183
+ "peerDependencies"
24184
+ ];
24185
+ for (const field of DEPENDENCY_FIELDS) {
24186
+ const deps = pkg[field];
24187
+ if (!deps)
24188
+ continue;
24189
+ for (const [depName, spec] of Object.entries(deps)) {
24190
+ if (!spec.startsWith(WORKSPACE_PREFIX))
24191
+ continue;
24192
+ const range = spec.slice(WORKSPACE_PREFIX.length);
24193
+ if (range === "*" || range === "^" || range === "~") {
24194
+ const version = workspaceVersions.get(depName);
24195
+ if (!version) {
24196
+ throw new Error(`Cannot resolve "${spec}" for dependency "${depName}": package not found in workspace`);
24197
+ }
24198
+ deps[depName] = range === "*" ? version : range === "^" ? `^${version}` : `~${version}`;
24199
+ } else {
24200
+ deps[depName] = range;
24201
+ }
24202
+ modified = true;
24203
+ }
24204
+ }
24205
+ if (modified) {
24206
+ backups.set(manifestPath, original);
24207
+ writeFileSync4(manifestPath, `${JSON.stringify(pkg, null, 2)}
24208
+ `, "utf-8");
24209
+ }
24210
+ return backups;
24211
+ }
24154
24212
  async createDescriptor() {
24155
24213
  const npmReader = NpmPackageRegistry.reader;
24156
24214
  const jsrReader = JsrPackageRegistry.reader;
@@ -25600,12 +25658,12 @@ async function writeVersionsForEcosystem(ecosystems, versions) {
25600
25658
  }
25601
25659
 
25602
25660
  // src/monorepo/resolve-workspace.ts
25603
- import { existsSync as existsSync4, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "node:fs";
25661
+ import { existsSync as existsSync5, readFileSync as readFileSync6, writeFileSync as writeFileSync5 } from "node:fs";
25604
25662
  import { join as join7 } from "node:path";
25605
25663
 
25606
25664
  // src/monorepo/discover.ts
25607
25665
  var import_micromatch2 = __toESM(require_micromatch(), 1);
25608
- import { readdirSync as readdirSync3, statSync as statSync2 } from "node:fs";
25666
+ import { lstatSync, readdirSync as readdirSync3 } from "node:fs";
25609
25667
  import path8 from "node:path";
25610
25668
 
25611
25669
  // src/ecosystem/infer.ts
@@ -25681,6 +25739,9 @@ function normalizeRegistryUrl(url) {
25681
25739
  init_exec();
25682
25740
  class CustomPackageRegistry extends NpmPackageRegistry {
25683
25741
  async npm(args, cwd) {
25742
+ if (!this.registry) {
25743
+ throw new Error("Custom registry URL is required for npm operations.");
25744
+ }
25684
25745
  const { stdout } = await exec3("npm", args.concat("--registry", this.registry), {
25685
25746
  throwOnError: true,
25686
25747
  nodeOptions: cwd ? { cwd } : undefined
@@ -25785,7 +25846,7 @@ registryCatalog.register({
25785
25846
  return token.trim().length >= 32;
25786
25847
  },
25787
25848
  resolveDisplayName: async (ctx) => {
25788
- return ctx.packages?.filter((pkg) => pkg.registries?.includes("crates")).map((pkg) => pkg.path) ?? ["crate"];
25849
+ return ctx.packages?.filter((pkg) => pkg.registries?.includes("crates")).map((pkg) => pkg.name) ?? ["crate"];
25789
25850
  },
25790
25851
  concurrentPublish: false,
25791
25852
  orderPackages: (paths) => sortCratesByDependencyOrder(paths),
@@ -25837,6 +25898,12 @@ async function readJsonSafe(path8) {
25837
25898
  return null;
25838
25899
  }
25839
25900
  }
25901
+ function asRecord(value) {
25902
+ return value !== null && typeof value === "object" ? value : null;
25903
+ }
25904
+ function readString(value) {
25905
+ return typeof value === "string" ? value : undefined;
25906
+ }
25840
25907
  async function readFileSafe(path8) {
25841
25908
  try {
25842
25909
  return await readFile5(path8, "utf-8");
@@ -25886,8 +25953,8 @@ async function inferJsRegistries(packagePath, rootPath) {
25886
25953
  return [];
25887
25954
  }
25888
25955
  const packageJson = await readJsonSafe(join5(packagePath, "package.json"));
25889
- const packageName = packageJson?.name;
25890
- const publishConfigRegistry = packageJson?.publishConfig?.registry;
25956
+ const packageName = readString(packageJson?.name);
25957
+ const publishConfigRegistry = readString(asRecord(packageJson?.publishConfig)?.registry);
25891
25958
  let npmRegistryUrl = null;
25892
25959
  if (publishConfigRegistry) {
25893
25960
  npmRegistryUrl = publishConfigRegistry;
@@ -25928,7 +25995,7 @@ async function inferRegistries(packagePath, ecosystemKey, rootPath) {
25928
25995
  }
25929
25996
 
25930
25997
  // src/monorepo/workspace.ts
25931
- import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
25998
+ import { existsSync as existsSync4, readFileSync as readFileSync5 } from "node:fs";
25932
25999
  import { join as join6 } from "node:path";
25933
26000
 
25934
26001
  // ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
@@ -26740,15 +26807,15 @@ function detectWorkspace(cwd) {
26740
26807
  const root = cwd ?? process.cwd();
26741
26808
  const workspaces = [];
26742
26809
  const pnpmWorkspacePath = join6(root, "pnpm-workspace.yaml");
26743
- if (existsSync3(pnpmWorkspacePath)) {
26744
- const content = readFileSync4(pnpmWorkspacePath, "utf-8");
26810
+ if (existsSync4(pnpmWorkspacePath)) {
26811
+ const content = readFileSync5(pnpmWorkspacePath, "utf-8");
26745
26812
  const parsed = $parse(content);
26746
26813
  const packages = parsed?.packages ?? [];
26747
26814
  workspaces.push({ type: "pnpm", patterns: packages });
26748
26815
  }
26749
26816
  const cargoTomlPath = join6(root, "Cargo.toml");
26750
- if (existsSync3(cargoTomlPath)) {
26751
- const content = readFileSync4(cargoTomlPath, "utf-8");
26817
+ if (existsSync4(cargoTomlPath)) {
26818
+ const content = readFileSync5(cargoTomlPath, "utf-8");
26752
26819
  try {
26753
26820
  const parsed = parse(content);
26754
26821
  const workspace = parsed.workspace;
@@ -26763,8 +26830,8 @@ function detectWorkspace(cwd) {
26763
26830
  }
26764
26831
  for (const denoFile of ["deno.json", "deno.jsonc"]) {
26765
26832
  const denoPath = join6(root, denoFile);
26766
- if (existsSync3(denoPath)) {
26767
- const content = readFileSync4(denoPath, "utf-8");
26833
+ if (existsSync4(denoPath)) {
26834
+ const content = readFileSync5(denoPath, "utf-8");
26768
26835
  try {
26769
26836
  const parsed = denoFile.endsWith(".jsonc") ? parse3(content) : JSON.parse(content);
26770
26837
  if (Array.isArray(parsed?.workspace)) {
@@ -26777,12 +26844,12 @@ function detectWorkspace(cwd) {
26777
26844
  }
26778
26845
  if (!workspaces.some((w2) => w2.type === "pnpm")) {
26779
26846
  const packageJsonPath = join6(root, "package.json");
26780
- if (existsSync3(packageJsonPath)) {
26781
- const content = readFileSync4(packageJsonPath, "utf-8");
26847
+ if (existsSync4(packageJsonPath)) {
26848
+ const content = readFileSync5(packageJsonPath, "utf-8");
26782
26849
  const pkg = JSON.parse(content);
26783
26850
  if (pkg.workspaces) {
26784
26851
  const bunfigPath = join6(root, "bunfig.toml");
26785
- const isBun2 = existsSync3(bunfigPath);
26852
+ const isBun2 = existsSync4(bunfigPath);
26786
26853
  if (Array.isArray(pkg.workspaces)) {
26787
26854
  workspaces.push({
26788
26855
  type: isBun2 ? "bun" : "npm",
@@ -26814,16 +26881,32 @@ function matchesIgnore(pkgPath, ignorePatterns) {
26814
26881
  return regex3.test(normalized);
26815
26882
  });
26816
26883
  }
26817
- function resolvePatterns(cwd, patterns) {
26818
- const entries = readdirSync3(cwd, { recursive: true, encoding: "utf-8" });
26819
- const dirs = entries.filter((entry) => {
26820
- const fullPath = path8.join(cwd, entry);
26884
+ function readdirRecursiveNoSymlinks(dir, root) {
26885
+ const results = [];
26886
+ let entries;
26887
+ try {
26888
+ entries = readdirSync3(dir, { encoding: "utf-8" });
26889
+ } catch {
26890
+ return results;
26891
+ }
26892
+ for (const entry of entries) {
26893
+ if (entry === "node_modules" || entry === ".git")
26894
+ continue;
26895
+ const fullPath = path8.join(dir, entry);
26821
26896
  try {
26822
- return statSync2(fullPath).isDirectory();
26823
- } catch {
26824
- return false;
26825
- }
26826
- });
26897
+ const stat5 = lstatSync(fullPath);
26898
+ if (stat5.isSymbolicLink())
26899
+ continue;
26900
+ if (stat5.isDirectory()) {
26901
+ results.push(path8.relative(root, fullPath));
26902
+ results.push(...readdirRecursiveNoSymlinks(fullPath, root));
26903
+ }
26904
+ } catch {}
26905
+ }
26906
+ return results;
26907
+ }
26908
+ function resolvePatterns(cwd, patterns) {
26909
+ const dirs = readdirRecursiveNoSymlinks(cwd, cwd);
26827
26910
  const normalizedDirs = dirs.map((d3) => d3.replace(/\\/g, "/"));
26828
26911
  const matched = import_micromatch2.default(normalizedDirs, patterns);
26829
26912
  return matched.map((d3) => path8.resolve(cwd, d3));
@@ -26920,31 +27003,6 @@ async function discoverPackages(options) {
26920
27003
  }
26921
27004
 
26922
27005
  // src/monorepo/resolve-workspace.ts
26923
- var WORKSPACE_PREFIX = "workspace:";
26924
- var DEPENDENCY_FIELDS = [
26925
- "dependencies",
26926
- "devDependencies",
26927
- "optionalDependencies",
26928
- "peerDependencies"
26929
- ];
26930
- function resolveWorkspaceProtocol(spec, version) {
26931
- if (!spec.startsWith(WORKSPACE_PREFIX))
26932
- return spec;
26933
- const range = spec.slice(WORKSPACE_PREFIX.length);
26934
- switch (range) {
26935
- case "*":
26936
- return version;
26937
- case "^":
26938
- return `^${version}`;
26939
- case "~":
26940
- return `~${version}`;
26941
- default:
26942
- return range;
26943
- }
26944
- }
26945
- function isDynamicWorkspaceSpec(range) {
26946
- return range === "*" || range === "^" || range === "~";
26947
- }
26948
27006
  function collectWorkspaceVersions(cwd) {
26949
27007
  const versions = new Map;
26950
27008
  const workspaces = detectWorkspace(cwd);
@@ -26956,10 +27014,10 @@ function collectWorkspaceVersions(cwd) {
26956
27014
  const dirs = resolvePatterns(cwd, workspace.patterns);
26957
27015
  for (const dir of dirs) {
26958
27016
  const pkgJsonPath = join7(dir, "package.json");
26959
- if (!existsSync4(pkgJsonPath))
27017
+ if (!existsSync5(pkgJsonPath))
26960
27018
  continue;
26961
27019
  try {
26962
- const content = readFileSync5(pkgJsonPath, "utf-8");
27020
+ const content = readFileSync6(pkgJsonPath, "utf-8");
26963
27021
  const pkg = JSON.parse(content);
26964
27022
  if (typeof pkg.name === "string" && pkg.name && typeof pkg.version === "string" && pkg.version) {
26965
27023
  versions.set(pkg.name, pkg.version);
@@ -26969,44 +27027,9 @@ function collectWorkspaceVersions(cwd) {
26969
27027
  }
26970
27028
  return versions;
26971
27029
  }
26972
- function resolveWorkspaceProtocolsInManifests(packagePaths, workspaceVersions) {
26973
- const backups = new Map;
26974
- for (const pkgPath of packagePaths) {
26975
- const manifestPath = join7(pkgPath, "package.json");
26976
- const original = readFileSync5(manifestPath, "utf-8");
26977
- const pkg = JSON.parse(original);
26978
- let modified = false;
26979
- for (const field of DEPENDENCY_FIELDS) {
26980
- const deps = pkg[field];
26981
- if (!deps)
26982
- continue;
26983
- for (const [depName, spec] of Object.entries(deps)) {
26984
- if (!spec.startsWith(WORKSPACE_PREFIX))
26985
- continue;
26986
- const range = spec.slice(WORKSPACE_PREFIX.length);
26987
- if (isDynamicWorkspaceSpec(range)) {
26988
- const version = workspaceVersions.get(depName);
26989
- if (!version) {
26990
- throw new Error(`Cannot resolve "${spec}" for dependency "${depName}": package not found in workspace`);
26991
- }
26992
- deps[depName] = resolveWorkspaceProtocol(spec, version);
26993
- } else {
26994
- deps[depName] = range;
26995
- }
26996
- modified = true;
26997
- }
26998
- }
26999
- if (modified) {
27000
- backups.set(manifestPath, original);
27001
- writeFileSync3(manifestPath, `${JSON.stringify(pkg, null, 2)}
27002
- `, "utf-8");
27003
- }
27004
- }
27005
- return backups;
27006
- }
27007
27030
  function restoreManifests(backups) {
27008
27031
  for (const [filePath, content] of backups) {
27009
- writeFileSync3(filePath, content, "utf-8");
27032
+ writeFileSync5(filePath, content, "utf-8");
27010
27033
  }
27011
27034
  }
27012
27035
 
@@ -27310,7 +27333,8 @@ function createContext(config, options, cwd) {
27310
27333
  tag: options.tag ?? "latest",
27311
27334
  promptEnabled: false,
27312
27335
  cleanWorkingTree: false,
27313
- pluginRunner: new PluginRunner([])
27336
+ pluginRunner: new PluginRunner([]),
27337
+ tokenRetryPromises: {}
27314
27338
  };
27315
27339
  const ctx = Object.defineProperties(Object.create(null), {
27316
27340
  config: {
@@ -27397,9 +27421,10 @@ async function withTokenRetry(registryKey, ctx, task, action) {
27397
27421
  if (!descriptor)
27398
27422
  throw error2;
27399
27423
  const config = descriptor.tokenConfig;
27400
- const retryKey = `_tokenRetry_${registryKey}`;
27401
- if (!ctx.runtime[retryKey]) {
27402
- ctx.runtime[retryKey] = (async () => {
27424
+ const retryPromises = ctx.runtime.tokenRetryPromises ?? {};
27425
+ ctx.runtime.tokenRetryPromises = retryPromises;
27426
+ if (!retryPromises[registryKey]) {
27427
+ retryPromises[registryKey] = (async () => {
27403
27428
  task.output = `Auth failed. Re-enter ${config.promptLabel}`;
27404
27429
  const newToken = await task.prompt(ListrEnquirerPromptAdapter).run({
27405
27430
  type: "password",
@@ -27410,7 +27435,7 @@ async function withTokenRetry(registryKey, ctx, task, action) {
27410
27435
  return newToken;
27411
27436
  })();
27412
27437
  }
27413
- await ctx.runtime[retryKey];
27438
+ await retryPromises[registryKey];
27414
27439
  await action();
27415
27440
  }
27416
27441
  }
@@ -27467,7 +27492,11 @@ async function findUnpublishedSiblingDeps(packagePath, siblingPaths) {
27467
27492
  }));
27468
27493
  const siblingDeps = deps.filter((d3) => siblingNameToPath.has(d3));
27469
27494
  const results = await Promise.all(siblingDeps.map(async (name) => {
27470
- const registry = await cratesPackageRegistry(siblingNameToPath.get(name));
27495
+ const siblingPath = siblingNameToPath.get(name);
27496
+ if (!siblingPath) {
27497
+ throw new Error(`Missing sibling crate path for dependency: ${name}`);
27498
+ }
27499
+ const registry = await cratesPackageRegistry(siblingPath);
27471
27500
  const published = await registry.isPublished();
27472
27501
  return published ? null : name;
27473
27502
  }));
@@ -27518,7 +27547,7 @@ function createCratesDryRunPublishTask(packagePath, siblingPaths) {
27518
27547
  init_error();
27519
27548
  init_git();
27520
27549
  var import_semver2 = __toESM(require_semver2(), 1);
27521
- import { readFileSync as readFileSync6 } from "node:fs";
27550
+ import { readFileSync as readFileSync7 } from "node:fs";
27522
27551
  var { prerelease } = import_semver2.default;
27523
27552
 
27524
27553
  class GitHubReleaseError extends AbstractError {
@@ -27587,7 +27616,7 @@ async function createGitHubRelease(_ctx, options) {
27587
27616
  const uploadUrl = release.upload_url.replace(/\{[^}]*\}/, "");
27588
27617
  const releaseAssets = [];
27589
27618
  for (const asset of options.assets) {
27590
- const archiveContent = readFileSync6(asset.filePath);
27619
+ const archiveContent = readFileSync7(asset.filePath);
27591
27620
  const uploadResponse = await fetch(`${uploadUrl}?name=${encodeURIComponent(asset.name)}`, {
27592
27621
  method: "POST",
27593
27622
  headers: {
@@ -27836,7 +27865,7 @@ init_error();
27836
27865
  init_exec();
27837
27866
 
27838
27867
  // src/utils/gh-secrets-sync-state.ts
27839
- import { readFileSync as readFileSync7, writeFileSync as writeFileSync4 } from "node:fs";
27868
+ import { readFileSync as readFileSync8, writeFileSync as writeFileSync6 } from "node:fs";
27840
27869
  import path9 from "node:path";
27841
27870
  var SYNC_HASH_FILENAME = "gh-secrets-sync-hash";
27842
27871
  function syncHashFilePath() {
@@ -27844,14 +27873,14 @@ function syncHashFilePath() {
27844
27873
  }
27845
27874
  function readGhSecretsSyncHash() {
27846
27875
  try {
27847
- const value = readFileSync7(syncHashFilePath(), "utf8").trim();
27876
+ const value = readFileSync8(syncHashFilePath(), "utf8").trim();
27848
27877
  return value || null;
27849
27878
  } catch {
27850
27879
  return null;
27851
27880
  }
27852
27881
  }
27853
27882
  function writeGhSecretsSyncHash(hash) {
27854
- writeFileSync4(syncHashFilePath(), `${hash}
27883
+ writeFileSync6(syncHashFilePath(), `${hash}
27855
27884
  `, "utf8");
27856
27885
  }
27857
27886
 
@@ -28239,12 +28268,26 @@ function isReleaseExcluded(config, pkgPath) {
28239
28268
  function getPackageName(ctx, packagePath) {
28240
28269
  return ctx.config.packages.find((p2) => p2.path === packagePath)?.name ?? packagePath;
28241
28270
  }
28271
+ function requirePackageEcosystem(pkg) {
28272
+ if (!pkg.ecosystem) {
28273
+ throw new Error(`Package ${pkg.path} is missing an ecosystem.`);
28274
+ }
28275
+ return pkg.ecosystem;
28276
+ }
28277
+ function requireVersionPlan(ctx) {
28278
+ const { versionPlan } = ctx.runtime;
28279
+ if (!versionPlan) {
28280
+ throw new Error("Version plan is required before running release tasks.");
28281
+ }
28282
+ return versionPlan;
28283
+ }
28242
28284
  async function writeVersions(ctx, versions) {
28243
28285
  const ecosystems = ctx.config.packages.map((pkg) => {
28244
28286
  const absPath = path10.resolve(ctx.cwd ?? process17.cwd(), pkg.path);
28245
- const descriptor = ecosystemCatalog.get(pkg.ecosystem);
28287
+ const ecosystem = requirePackageEcosystem(pkg);
28288
+ const descriptor = ecosystemCatalog.get(ecosystem);
28246
28289
  if (!descriptor)
28247
- throw new Error(`Unknown ecosystem: ${pkg.ecosystem}`);
28290
+ throw new Error(`Unknown ecosystem: ${ecosystem}`);
28248
28291
  const eco = new descriptor.ecosystemClass(absPath);
28249
28292
  return { eco, pkg };
28250
28293
  });
@@ -28263,17 +28306,38 @@ function createPublishTaskForPath(registryKey, packagePath) {
28263
28306
  return { title: `Publish to ${registryKey}`, task: async () => {} };
28264
28307
  return factory(packagePath);
28265
28308
  }
28266
- function resolveWorkspaceProtocols(ctx) {
28309
+ async function resolveWorkspaceProtocols(ctx) {
28267
28310
  if (!ctx.cwd)
28268
28311
  return;
28269
28312
  const workspaceVersions = collectWorkspaceVersions(ctx.cwd);
28270
28313
  if (workspaceVersions.size === 0)
28271
28314
  return;
28272
- const packagePaths = ctx.config.packages.map((pkg) => path10.resolve(ctx.cwd, pkg.path));
28273
- const backups = resolveWorkspaceProtocolsInManifests(packagePaths, workspaceVersions);
28274
- if (backups.size > 0) {
28275
- ctx.runtime.workspaceBackups = backups;
28276
- addRollback(async () => restoreManifests(backups), ctx);
28315
+ const allBackups = new Map;
28316
+ for (const pkg of ctx.config.packages) {
28317
+ const absPath = path10.resolve(ctx.cwd, pkg.path);
28318
+ const ecosystem = requirePackageEcosystem(pkg);
28319
+ const descriptor = ecosystemCatalog.get(ecosystem);
28320
+ if (!descriptor)
28321
+ continue;
28322
+ const eco = new descriptor.ecosystemClass(absPath);
28323
+ const backups = await eco.resolvePublishDependencies(workspaceVersions);
28324
+ for (const [k3, v2] of backups) {
28325
+ allBackups.set(k3, v2);
28326
+ }
28327
+ }
28328
+ if (allBackups.size > 0) {
28329
+ ctx.runtime.workspaceBackups = allBackups;
28330
+ addRollback(async () => {
28331
+ for (const pkg of ctx.config.packages) {
28332
+ const absPath = path10.resolve(ctx.cwd, pkg.path);
28333
+ const ecosystem = requirePackageEcosystem(pkg);
28334
+ const descriptor = ecosystemCatalog.get(ecosystem);
28335
+ if (!descriptor)
28336
+ continue;
28337
+ const eco = new descriptor.ecosystemClass(absPath);
28338
+ eco.restorePublishDependencies(allBackups);
28339
+ }
28340
+ }, ctx);
28277
28341
  }
28278
28342
  }
28279
28343
  async function applyVersionsForDryRun(ctx) {
@@ -28393,8 +28457,8 @@ ${[...plan.packages].map(([pkgPath, ver]) => ` ${getPackageName(ctx, pkgPath)}:
28393
28457
  }
28394
28458
  return "";
28395
28459
  }
28396
- function shouldRenderLiveCommandOutput(ctx) {
28397
- return ctx.options.mode !== "ci" && !m && Boolean(process17.stdout.isTTY);
28460
+ function shouldRenderLiveCommandOutput(_ctx) {
28461
+ return !m && Boolean(process17.stdout.isTTY);
28398
28462
  }
28399
28463
  function normalizeLiveCommandOutputLine(line) {
28400
28464
  const normalized = stripVTControlCharacters2(line).trimEnd();
@@ -28475,7 +28539,7 @@ async function run(ctx) {
28475
28539
  await requiredConditionsCheckTask({
28476
28540
  skip: ctx.options.skipConditionsCheck
28477
28541
  }).run(ctx);
28478
- const pipelineListrOptions2 = mode === "ci" || m ? createCiListrOptions() : undefined;
28542
+ const pipelineListrOptions2 = m ? createCiListrOptions() : undefined;
28479
28543
  await createListr([
28480
28544
  {
28481
28545
  skip: ctx.options.skipTests,
@@ -28557,7 +28621,7 @@ async function run(ctx) {
28557
28621
  skip: () => dryRun,
28558
28622
  task: async (ctx2, task) => {
28559
28623
  const git = new Git;
28560
- const snapshotPlan = ctx2.runtime.versionPlan;
28624
+ const snapshotPlan = requireVersionPlan(ctx2);
28561
28625
  const tagName = `v${snapshotPlan.mode !== "independent" ? snapshotPlan.version : ""}`;
28562
28626
  task.output = `Creating tag ${tagName}...`;
28563
28627
  const headCommit = await git.latestCommit();
@@ -28624,7 +28688,7 @@ async function run(ctx) {
28624
28688
  skip: ctx.options.skipConditionsCheck
28625
28689
  }).run(ctx);
28626
28690
  }
28627
- const pipelineListrOptions = mode === "ci" || m ? createCiListrOptions() : undefined;
28691
+ const pipelineListrOptions = m ? createCiListrOptions() : undefined;
28628
28692
  await createListr([
28629
28693
  {
28630
28694
  skip: !hasPrepare || ctx.options.skipTests,
@@ -28690,7 +28754,7 @@ async function run(ctx) {
28690
28754
  const git = new Git;
28691
28755
  let tagCreated = false;
28692
28756
  let commited = false;
28693
- const plan = ctx2.runtime.versionPlan;
28757
+ const plan = requireVersionPlan(ctx2);
28694
28758
  task.output = formatVersionPlan(ctx2);
28695
28759
  addRollback(async () => {
28696
28760
  if (tagCreated) {
@@ -28914,7 +28978,7 @@ ${[...plan.packages].map(([pkgPath, ver]) => `- ${getPackageName(ctx2, pkgPath)}
28914
28978
  task: async (ctx2, parentTask) => {
28915
28979
  parentTask.output = "Running plugin beforePublish hooks...";
28916
28980
  await ctx2.runtime.pluginRunner.runHook("beforePublish", ctx2);
28917
- resolveWorkspaceProtocols(ctx2);
28981
+ await resolveWorkspaceProtocols(ctx2);
28918
28982
  const publishTasks = await collectPublishTasks(ctx2);
28919
28983
  parentTask.title = `Publishing (${countPublishTargets(ctx2)} targets)`;
28920
28984
  parentTask.output = formatRegistryGroupSummary("Concurrent publish tasks", ctx2, true);
@@ -28927,7 +28991,11 @@ ${[...plan.packages].map(([pkgPath, ver]) => `- ${getPackageName(ctx2, pkgPath)}
28927
28991
  skip: (ctx2) => !hasPublish || !!ctx2.options.skipPublish || dryRun || !ctx2.runtime.workspaceBackups?.size,
28928
28992
  title: "Restoring workspace protocols",
28929
28993
  task: (ctx2) => {
28930
- restoreManifests(ctx2.runtime.workspaceBackups);
28994
+ const backups = ctx2.runtime.workspaceBackups;
28995
+ if (!backups) {
28996
+ throw new Error("Workspace backups are required for restore.");
28997
+ }
28998
+ restoreManifests(backups);
28931
28999
  ctx2.runtime.workspaceBackups = undefined;
28932
29000
  }
28933
29001
  },
@@ -28944,7 +29012,7 @@ ${[...plan.packages].map(([pkgPath, ver]) => `- ${getPackageName(ctx2, pkgPath)}
28944
29012
  skip: !dryRun && !(mode === "ci" && hasPrepare),
28945
29013
  title: "Validating publish (dry-run)",
28946
29014
  task: async (ctx2, parentTask) => {
28947
- resolveWorkspaceProtocols(ctx2);
29015
+ await resolveWorkspaceProtocols(ctx2);
28948
29016
  await applyVersionsForDryRun(ctx2);
28949
29017
  const dryRunTasks = await collectDryRunPublishTasks(ctx2);
28950
29018
  parentTask.title = `Validating publish (${countRegistryTargets(collectEcosystemRegistryGroups(ctx2.config))} targets)`;
@@ -28958,7 +29026,11 @@ ${[...plan.packages].map(([pkgPath, ver]) => `- ${getPackageName(ctx2, pkgPath)}
28958
29026
  skip: (ctx2) => !dryRun && !(mode === "ci" && hasPrepare) || !ctx2.runtime.workspaceBackups?.size,
28959
29027
  title: "Restoring workspace protocols",
28960
29028
  task: (ctx2) => {
28961
- restoreManifests(ctx2.runtime.workspaceBackups);
29029
+ const backups = ctx2.runtime.workspaceBackups;
29030
+ if (!backups) {
29031
+ throw new Error("Workspace backups are required for restore.");
29032
+ }
29033
+ restoreManifests(backups);
28962
29034
  ctx2.runtime.workspaceBackups = undefined;
28963
29035
  }
28964
29036
  },
@@ -28966,7 +29038,11 @@ ${[...plan.packages].map(([pkgPath, ver]) => `- ${getPackageName(ctx2, pkgPath)}
28966
29038
  skip: (ctx2) => !dryRun || !ctx2.runtime.dryRunVersionBackup?.size,
28967
29039
  title: "Restoring original versions (dry-run)",
28968
29040
  task: async (ctx2) => {
28969
- await writeVersions(ctx2, ctx2.runtime.dryRunVersionBackup);
29041
+ const backupVersions = ctx2.runtime.dryRunVersionBackup;
29042
+ if (!backupVersions) {
29043
+ throw new Error("Dry-run version backup is required for restore.");
29044
+ }
29045
+ await writeVersions(ctx2, backupVersions);
28970
29046
  ctx2.runtime.dryRunVersionBackup = undefined;
28971
29047
  }
28972
29048
  },
@@ -28993,7 +29069,7 @@ ${[...plan.packages].map(([pkgPath, ver]) => `- ${getPackageName(ctx2, pkgPath)}
28993
29069
  skip: (ctx2) => !hasPublish || !!ctx2.options.skipReleaseDraft || dryRun,
28994
29070
  title: "Creating GitHub Release",
28995
29071
  task: async (ctx2, task) => {
28996
- const plan = ctx2.runtime.versionPlan;
29072
+ const plan = requireVersionPlan(ctx2);
28997
29073
  const tokenResult = resolveGitHubToken();
28998
29074
  let hasToken = !!tokenResult;
28999
29075
  if (tokenResult) {
@@ -29039,8 +29115,8 @@ ${[...plan.packages].map(([pkgPath, ver]) => `- ${getPackageName(ctx2, pkgPath)}
29039
29115
  const pkgConfig = ctx2.config.packages.find((p2) => p2.path === pkgPath);
29040
29116
  if (pkgConfig) {
29041
29117
  const changelogPath = join9(process17.cwd(), pkgConfig.path, "CHANGELOG.md");
29042
- if (existsSync5(changelogPath)) {
29043
- const section = parseChangelogSection(readFileSync8(changelogPath, "utf-8"), pkgVersion);
29118
+ if (existsSync6(changelogPath)) {
29119
+ const section = parseChangelogSection(readFileSync9(changelogPath, "utf-8"), pkgVersion);
29044
29120
  if (section)
29045
29121
  changelogBody = section;
29046
29122
  }
@@ -29086,8 +29162,8 @@ ${[...plan.packages].map(([pkgPath, ver]) => `- ${getPackageName(ctx2, pkgPath)}
29086
29162
  if (!pkgConfig)
29087
29163
  continue;
29088
29164
  const changelogPath = join9(process17.cwd(), pkgConfig.path, "CHANGELOG.md");
29089
- if (existsSync5(changelogPath)) {
29090
- const section = parseChangelogSection(readFileSync8(changelogPath, "utf-8"), pkgVersion);
29165
+ if (existsSync6(changelogPath)) {
29166
+ const section = parseChangelogSection(readFileSync9(changelogPath, "utf-8"), pkgVersion);
29091
29167
  if (section) {
29092
29168
  sections.push(`## ${pkgName} v${pkgVersion}
29093
29169
 
@@ -29104,8 +29180,8 @@ ${section}`);
29104
29180
  }
29105
29181
  } else {
29106
29182
  const changelogPath = join9(process17.cwd(), "CHANGELOG.md");
29107
- if (existsSync5(changelogPath)) {
29108
- const section = parseChangelogSection(readFileSync8(changelogPath, "utf-8"), version);
29183
+ if (existsSync6(changelogPath)) {
29184
+ const section = parseChangelogSection(readFileSync9(changelogPath, "utf-8"), version);
29109
29185
  if (section)
29110
29186
  changelogBody = section;
29111
29187
  }
@@ -29245,13 +29321,13 @@ function maxBump(a3, b2) {
29245
29321
  return BUMP_ORDER[a3] >= BUMP_ORDER[b2] ? a3 : b2;
29246
29322
  }
29247
29323
  // src/changeset/migrate.ts
29248
- import { copyFileSync, existsSync as existsSync6, mkdirSync as mkdirSync3, readdirSync as readdirSync4 } from "node:fs";
29324
+ import { copyFileSync, existsSync as existsSync7, mkdirSync as mkdirSync3, readdirSync as readdirSync4 } from "node:fs";
29249
29325
  import path11 from "node:path";
29250
29326
  import process18 from "node:process";
29251
29327
  var SKIPPED_FILES = new Set(["config.json", "README.md"]);
29252
29328
  function migrateFromChangesets(cwd = process18.cwd()) {
29253
29329
  const changesetDir = path11.join(cwd, ".changeset");
29254
- if (!existsSync6(changesetDir)) {
29330
+ if (!existsSync7(changesetDir)) {
29255
29331
  return {
29256
29332
  success: false,
29257
29333
  error: ".changeset/ directory not found",
@@ -29352,7 +29428,7 @@ function calculateVersionBumps(currentVersions, cwd = process20.cwd(), resolveKe
29352
29428
  return result;
29353
29429
  }
29354
29430
  // src/changeset/writer.ts
29355
- import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync5 } from "node:fs";
29431
+ import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync7 } from "node:fs";
29356
29432
  import path12 from "node:path";
29357
29433
  import process21 from "node:process";
29358
29434
  var adjectives = [
@@ -29455,7 +29531,7 @@ function writeChangeset(releases, summary, cwd = process21.cwd()) {
29455
29531
  const fileName = `${id}.md`;
29456
29532
  const filePath = path12.join(changesetsDir, fileName);
29457
29533
  const content = generateChangesetContent(releases, summary);
29458
- writeFileSync5(filePath, content, "utf-8");
29534
+ writeFileSync7(filePath, content, "utf-8");
29459
29535
  return filePath;
29460
29536
  }
29461
29537
  // src/config/defaults.ts
@@ -30217,17 +30293,32 @@ function formatStageError(stage, error2) {
30217
30293
  const message = error2 instanceof Error ? error2.stack ?? error2.message : String(error2);
30218
30294
  return `[${stage}] ${message}`;
30219
30295
  }
30220
- async function loadConfig(cwd = process.cwd()) {
30221
- const configPath = await findConfigFile(cwd);
30222
- if (!configPath)
30296
+ async function loadConfig(cwd = process.cwd(), configPath) {
30297
+ let resolvedConfigPath;
30298
+ if (configPath) {
30299
+ resolvedConfigPath = path13.resolve(cwd, configPath);
30300
+ try {
30301
+ if (!(await stat5(resolvedConfigPath)).isFile()) {
30302
+ throw new Error(`Config path is not a file: ${resolvedConfigPath}`);
30303
+ }
30304
+ } catch (e3) {
30305
+ if (e3.code === "ENOENT") {
30306
+ throw new Error(`Config file not found: ${resolvedConfigPath}`);
30307
+ }
30308
+ throw e3;
30309
+ }
30310
+ } else {
30311
+ resolvedConfigPath = await findConfigFile(cwd);
30312
+ }
30313
+ if (!resolvedConfigPath)
30223
30314
  return null;
30224
30315
  const errors2 = [];
30225
30316
  try {
30226
- return await importConfigModule(configPath);
30317
+ return await importConfigModule(resolvedConfigPath);
30227
30318
  } catch (error2) {
30228
30319
  errors2.push(formatStageError("native import", error2));
30229
30320
  }
30230
- const output = await buildConfig(configPath);
30321
+ const output = await buildConfig(resolvedConfigPath);
30231
30322
  if (!output.success) {
30232
30323
  errors2.push(formatStageError("bundled build", output.logs.map((log) => log.message).join(`
30233
30324
  `)));
@@ -30246,11 +30337,11 @@ ${errors2.join(`
30246
30337
  }
30247
30338
  const bundledSource = await entrypoint.text();
30248
30339
  try {
30249
- return await importBundledConfig(bundledSource, configPath, output.optionalDependencies);
30340
+ return await importBundledConfig(bundledSource, resolvedConfigPath, output.optionalDependencies);
30250
30341
  } catch (error2) {
30251
30342
  errors2.push(formatStageError("bundled import", error2));
30252
30343
  }
30253
- const vmOutput = await buildConfigWithFormat(configPath, "cjs");
30344
+ const vmOutput = await buildConfigWithFormat(resolvedConfigPath, "cjs");
30254
30345
  if (!vmOutput.success) {
30255
30346
  errors2.push(formatStageError("bundled vm build", vmOutput.logs.map((log) => log.message).join(`
30256
30347
  `)));
@@ -30268,7 +30359,7 @@ ${errors2.join(`
30268
30359
  `)}`);
30269
30360
  }
30270
30361
  try {
30271
- return await executeBundledConfigInVm(await vmEntrypoint.text(), configPath);
30362
+ return await executeBundledConfigInVm(await vmEntrypoint.text(), resolvedConfigPath);
30272
30363
  } catch (error2) {
30273
30364
  errors2.push(formatStageError("bundled vm", error2));
30274
30365
  throw new Error(`Failed to load config:
@@ -30688,6 +30779,9 @@ async function handleMultiPackage(ctx, task, packageInfos) {
30688
30779
  if (result === "accepted")
30689
30780
  return;
30690
30781
  if (result === "add_packages") {
30782
+ if (!bumps) {
30783
+ throw new Error("Changeset bumps are required for add_packages.");
30784
+ }
30691
30785
  await handleAddPackages(ctx, task, sortedPackageInfos, currentVersions, graph, bumps);
30692
30786
  return;
30693
30787
  }
@@ -31031,7 +31125,7 @@ import { homedir as homedir2 } from "os";
31031
31125
  import { join as join10 } from "path";
31032
31126
  import os2 from "os";
31033
31127
  import path32 from "path";
31034
- import { readFileSync as readFileSync9 } from "fs";
31128
+ import { readFileSync as readFileSync10 } from "fs";
31035
31129
  import { readFile as readFile22 } from "fs/promises";
31036
31130
  import { dirname, join as join22, resolve as resolve2, sep } from "path";
31037
31131
  import { fileURLToPath } from "url";
@@ -32611,7 +32705,7 @@ function findPackageJsonSync(startDir) {
32611
32705
  for (;; ) {
32612
32706
  const candidate = join22(current, "package.json");
32613
32707
  try {
32614
- const content = readFileSync9(candidate, "utf-8");
32708
+ const content = readFileSync10(candidate, "utf-8");
32615
32709
  const result = parsePackageJson(content, candidate);
32616
32710
  if (result)
32617
32711
  return result;
@@ -33014,11 +33108,11 @@ function isBun2() {
33014
33108
  init_ui();
33015
33109
 
33016
33110
  // src/validate/entry-points.ts
33017
- import { existsSync as existsSync7 } from "node:fs";
33111
+ import { existsSync as existsSync8 } from "node:fs";
33018
33112
  import path15 from "node:path";
33019
33113
  var SIMPLE_FIELDS = ["main", "module", "types", "typings"];
33020
33114
  function checkPath(filePath, cwd) {
33021
- return existsSync7(path15.resolve(cwd, filePath));
33115
+ return existsSync8(path15.resolve(cwd, filePath));
33022
33116
  }
33023
33117
  function validateExports(exports, cwd, prefix = "exports") {
33024
33118
  const errors2 = [];