pubz 0.2.11 → 0.3.0

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.
Files changed (2) hide show
  1. package/dist/cli.js +125 -33
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -441,6 +441,7 @@ async function verifyBuild(pkg) {
441
441
  function isOtpError(output) {
442
442
  return output.includes("EOTP") || output.includes("one-time password");
443
443
  }
444
+ var NPM_COMMAND = process.env.PUBZ_NPM_COMMAND ?? "npm";
444
445
  async function publishPackage(pkg, registry, context, dryRun) {
445
446
  if (dryRun) {
446
447
  console.log(` [DRY RUN] Would publish ${pkg.name}@${pkg.version} to ${registry}`);
@@ -454,11 +455,11 @@ async function publishPackage(pkg, registry, context, dryRun) {
454
455
  let result;
455
456
  if (context.useBrowserAuth) {
456
457
  args.push("--auth-type", "web");
457
- const interactiveResult = await runInteractive("npm", args, pkg.path);
458
+ const interactiveResult = await runInteractive(NPM_COMMAND, args, pkg.path);
458
459
  result = { code: interactiveResult.code, output: "" };
459
460
  context.onInteractiveComplete?.();
460
461
  } else {
461
- result = await run("npm", args, pkg.path);
462
+ result = await run(NPM_COMMAND, args, pkg.path);
462
463
  }
463
464
  if (result.code !== 0) {
464
465
  if (isOtpError(result.output)) {
@@ -536,6 +537,74 @@ async function pushGitTag(version, cwd, dryRun) {
536
537
 
537
538
  // src/version.ts
538
539
  import { readFile as readFile3, writeFile } from "node:fs/promises";
540
+ async function transformWorkspaceProtocolForPublish(packages, newVersion, dryRun) {
541
+ const packageNames = new Set(packages.map((p) => p.name));
542
+ const transforms = [];
543
+ for (const pkg of packages) {
544
+ const content = await readFile3(pkg.packageJsonPath, "utf-8");
545
+ const packageJson = JSON.parse(content);
546
+ let modified = false;
547
+ for (const depType of [
548
+ "dependencies",
549
+ "devDependencies",
550
+ "peerDependencies"
551
+ ]) {
552
+ const deps = packageJson[depType];
553
+ if (!deps)
554
+ continue;
555
+ for (const depName of Object.keys(deps)) {
556
+ if (packageNames.has(depName)) {
557
+ const oldVersion = deps[depName];
558
+ if (oldVersion.startsWith("workspace:")) {
559
+ const modifier = oldVersion.replace("workspace:", "");
560
+ const newVersionSpec = modifier === "*" || modifier === "" ? newVersion : `${modifier}${newVersion}`;
561
+ if (dryRun) {
562
+ console.log(` [DRY RUN] Would temporarily transform ${pkg.name} ${depType}.${depName}: ${oldVersion} -> ${newVersionSpec}`);
563
+ } else {
564
+ transforms.push({
565
+ packageJsonPath: pkg.packageJsonPath,
566
+ depType,
567
+ depName,
568
+ originalValue: oldVersion
569
+ });
570
+ deps[depName] = newVersionSpec;
571
+ modified = true;
572
+ }
573
+ }
574
+ }
575
+ }
576
+ }
577
+ if (modified && !dryRun) {
578
+ await writeFile(pkg.packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
579
+ `);
580
+ console.log(` Transformed workspace references in ${pkg.name}`);
581
+ }
582
+ }
583
+ return transforms;
584
+ }
585
+ async function restoreWorkspaceProtocol(transforms) {
586
+ const byPath = new Map;
587
+ for (const transform of transforms) {
588
+ const existing = byPath.get(transform.packageJsonPath) ?? [];
589
+ existing.push(transform);
590
+ byPath.set(transform.packageJsonPath, existing);
591
+ }
592
+ for (const [packageJsonPath, pathTransforms] of byPath) {
593
+ const content = await readFile3(packageJsonPath, "utf-8");
594
+ const packageJson = JSON.parse(content);
595
+ for (const transform of pathTransforms) {
596
+ const deps = packageJson[transform.depType];
597
+ if (deps) {
598
+ deps[transform.depName] = transform.originalValue;
599
+ }
600
+ }
601
+ await writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
602
+ `);
603
+ }
604
+ if (transforms.length > 0) {
605
+ console.log(` Restored workspace references in ${byPath.size} package(s)`);
606
+ }
607
+ }
539
608
  function bumpVersion(version, type) {
540
609
  if (type === "none")
541
610
  return version;
@@ -582,6 +651,9 @@ async function updateLocalDependencyVersions(packages, newVersion, dryRun) {
582
651
  for (const depName of Object.keys(deps)) {
583
652
  if (packageNames.has(depName)) {
584
653
  const oldVersion = deps[depName];
654
+ if (oldVersion.startsWith("workspace:")) {
655
+ continue;
656
+ }
585
657
  const newVersionSpec = oldVersion.startsWith("^") ? `^${newVersion}` : oldVersion.startsWith("~") ? `~${newVersion}` : newVersion;
586
658
  if (deps[depName] !== newVersionSpec) {
587
659
  if (dryRun) {
@@ -912,47 +984,67 @@ async function main() {
912
984
  console.log("");
913
985
  if (options.dryRun) {
914
986
  console.log(yellow("[DRY RUN]") + ` Would publish the following packages to ${cyan(registry)}:`);
915
- console.log("");
916
- for (const pkg of packages) {
917
- console.log(` ${dim("•")} ${cyan(pkg.name)}${dim("@")}${yellow(newVersion)}`);
918
- }
919
- console.log("");
920
- console.log(muted("Run without --dry-run to actually publish."));
921
987
  } else {
922
988
  console.log("About to publish the following packages:");
923
- console.log("");
924
- for (const pkg of packages) {
925
- console.log(` ${dim("•")} ${cyan(pkg.name)}${dim("@")}${yellow(newVersion)}`);
926
- }
927
- console.log("");
928
- console.log(`Registry: ${cyan(registry)}`);
929
- console.log("");
930
- if (!skipConfirms) {
931
- const shouldContinue = await confirm("Continue?");
932
- if (!shouldContinue) {
933
- console.log(yellow("Publish cancelled."));
934
- closePrompt();
935
- process.exit(0);
936
- }
989
+ }
990
+ console.log("");
991
+ for (const pkg of packages) {
992
+ console.log(` ${dim("•")} ${cyan(pkg.name)}${dim("@")}${yellow(newVersion)}`);
993
+ }
994
+ console.log("");
995
+ console.log(`Registry: ${cyan(registry)}`);
996
+ console.log("");
997
+ if (!options.dryRun && !skipConfirms) {
998
+ const shouldContinue = await confirm("Continue?");
999
+ if (!shouldContinue) {
1000
+ console.log(yellow("Publish cancelled."));
1001
+ closePrompt();
1002
+ process.exit(0);
937
1003
  }
938
1004
  console.log("");
939
- console.log(cyan("Publishing packages..."));
1005
+ }
1006
+ console.log(cyan("Preparing packages for publish..."));
1007
+ console.log("");
1008
+ const workspaceTransforms = await transformWorkspaceProtocolForPublish(packages, newVersion, options.dryRun);
1009
+ if (workspaceTransforms.length > 0 || options.dryRun) {
940
1010
  console.log("");
941
- const publishContext = {
942
- otp: options.otp,
943
- useBrowserAuth: !options.ci,
944
- onInteractiveComplete: resetPrompt
945
- };
1011
+ }
1012
+ console.log(cyan("Publishing packages..."));
1013
+ console.log("");
1014
+ const publishContext = {
1015
+ otp: options.otp,
1016
+ useBrowserAuth: !options.ci,
1017
+ onInteractiveComplete: resetPrompt
1018
+ };
1019
+ let publishFailed = false;
1020
+ let failedPackageName = "";
1021
+ let failedError = "";
1022
+ try {
946
1023
  for (const pkg of packages) {
947
1024
  const result = await publishPackage(pkg, registry, publishContext, options.dryRun);
948
1025
  if (!result.success) {
949
- console.error(red(bold("Failed to publish")) + ` ${cyan(pkg.name)}: ${result.error}`);
950
- console.log("");
951
- console.log(red("Stopping publish process."));
952
- closePrompt();
953
- process.exit(1);
1026
+ publishFailed = true;
1027
+ failedPackageName = pkg.name;
1028
+ failedError = result.error ?? "Unknown error";
1029
+ break;
954
1030
  }
955
1031
  }
1032
+ } finally {
1033
+ if (workspaceTransforms.length > 0) {
1034
+ console.log("");
1035
+ await restoreWorkspaceProtocol(workspaceTransforms);
1036
+ }
1037
+ }
1038
+ if (publishFailed) {
1039
+ console.error(red(bold("Failed to publish")) + ` ${cyan(failedPackageName)}: ${failedError}`);
1040
+ console.log("");
1041
+ console.log(red("Stopping publish process."));
1042
+ closePrompt();
1043
+ process.exit(1);
1044
+ }
1045
+ if (options.dryRun) {
1046
+ console.log("");
1047
+ console.log(muted("Run without --dry-run to actually publish."));
956
1048
  }
957
1049
  console.log("");
958
1050
  console.log(dim("═".repeat(30)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubz",
3
- "version": "0.2.11",
3
+ "version": "0.3.0",
4
4
  "description": "Interactive CLI for publishing npm packages (single or monorepo)",
5
5
  "type": "module",
6
6
  "bin": {