pubz 0.2.6 → 0.2.8

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 +31 -5
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -346,6 +346,11 @@ async function npmLogin(registry) {
346
346
  });
347
347
  });
348
348
  }
349
+ async function promptForOtp() {
350
+ console.log("");
351
+ const code = await prompt(`${cyan("?")} Enter OTP code from your authenticator: `);
352
+ return code.trim();
353
+ }
349
354
 
350
355
  // src/publish.ts
351
356
  import { spawn as spawn2 } from "node:child_process";
@@ -420,18 +425,35 @@ async function verifyBuild(pkg) {
420
425
  }
421
426
  return { success: true };
422
427
  }
423
- async function publishPackage(pkg, registry, otp, dryRun) {
428
+ function isOtpError(output) {
429
+ return output.includes("EOTP") || output.includes("one-time password");
430
+ }
431
+ async function publishPackage(pkg, registry, context, dryRun) {
424
432
  if (dryRun) {
425
433
  console.log(` [DRY RUN] Would publish ${pkg.name}@${pkg.version} to ${registry}`);
426
434
  return { success: true };
427
435
  }
428
436
  console.log(`Publishing ${pkg.name}@${pkg.version}...`);
429
437
  const args = ["publish", "--registry", registry, "--access", "public"];
430
- if (otp) {
431
- args.push("--otp", otp);
438
+ if (context.otp) {
439
+ args.push("--otp", context.otp);
440
+ }
441
+ let result = await run("npm", args, pkg.path);
442
+ if (result.code !== 0 && isOtpError(result.output) && context.onOtpRequired) {
443
+ const otpCode = await context.onOtpRequired();
444
+ if (otpCode) {
445
+ context.otp = otpCode;
446
+ const retryArgs = ["publish", "--registry", registry, "--access", "public", "--otp", otpCode];
447
+ result = await run("npm", retryArgs, pkg.path);
448
+ }
432
449
  }
433
- const result = await run("npm", args, pkg.path);
434
450
  if (result.code !== 0) {
451
+ if (isOtpError(result.output)) {
452
+ return {
453
+ success: false,
454
+ error: `2FA OTP required. Use --otp flag or run interactively.`
455
+ };
456
+ }
435
457
  return { success: false, error: `Failed to publish ${pkg.name}` };
436
458
  }
437
459
  console.log(` ${pkg.name} published successfully`);
@@ -913,8 +935,12 @@ async function main() {
913
935
  console.log("");
914
936
  console.log(cyan("Publishing packages..."));
915
937
  console.log("");
938
+ const publishContext = {
939
+ otp: options.otp,
940
+ onOtpRequired: options.ci ? undefined : promptForOtp
941
+ };
916
942
  for (const pkg of packages) {
917
- const result = await publishPackage(pkg, registry, options.otp, options.dryRun);
943
+ const result = await publishPackage(pkg, registry, publishContext, options.dryRun);
918
944
  if (!result.success) {
919
945
  console.error(red(bold("Failed to publish")) + ` ${cyan(pkg.name)}: ${result.error}`);
920
946
  console.log("");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubz",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Interactive CLI for publishing npm packages (single or monorepo)",
5
5
  "type": "module",
6
6
  "bin": {