pubz 0.2.6 → 0.2.9
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/cli.js +33 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -346,6 +346,10 @@ async function npmLogin(registry) {
|
|
|
346
346
|
});
|
|
347
347
|
});
|
|
348
348
|
}
|
|
349
|
+
async function reauthenticate(registry) {
|
|
350
|
+
const loginResult = await npmLogin(registry);
|
|
351
|
+
return loginResult.success;
|
|
352
|
+
}
|
|
349
353
|
|
|
350
354
|
// src/publish.ts
|
|
351
355
|
import { spawn as spawn2 } from "node:child_process";
|
|
@@ -420,18 +424,38 @@ async function verifyBuild(pkg) {
|
|
|
420
424
|
}
|
|
421
425
|
return { success: true };
|
|
422
426
|
}
|
|
423
|
-
|
|
427
|
+
function isOtpError(output) {
|
|
428
|
+
return output.includes("EOTP") || output.includes("one-time password");
|
|
429
|
+
}
|
|
430
|
+
async function publishPackage(pkg, registry, context, dryRun) {
|
|
424
431
|
if (dryRun) {
|
|
425
432
|
console.log(` [DRY RUN] Would publish ${pkg.name}@${pkg.version} to ${registry}`);
|
|
426
433
|
return { success: true };
|
|
427
434
|
}
|
|
428
435
|
console.log(`Publishing ${pkg.name}@${pkg.version}...`);
|
|
429
436
|
const args = ["publish", "--registry", registry, "--access", "public"];
|
|
430
|
-
if (otp) {
|
|
431
|
-
args.push("--otp", otp);
|
|
437
|
+
if (context.otp) {
|
|
438
|
+
args.push("--otp", context.otp);
|
|
439
|
+
}
|
|
440
|
+
let result = await run("npm", args, pkg.path);
|
|
441
|
+
if (result.code !== 0 && isOtpError(result.output) && context.onAuthRequired) {
|
|
442
|
+
console.log("");
|
|
443
|
+
console.log("2FA verification required. Opening browser for authentication...");
|
|
444
|
+
const authSuccess = await context.onAuthRequired(registry);
|
|
445
|
+
if (authSuccess) {
|
|
446
|
+
console.log("");
|
|
447
|
+
console.log(`Retrying publish...`);
|
|
448
|
+
const retryArgs = ["publish", "--registry", registry, "--access", "public"];
|
|
449
|
+
result = await run("npm", retryArgs, pkg.path);
|
|
450
|
+
}
|
|
432
451
|
}
|
|
433
|
-
const result = await run("npm", args, pkg.path);
|
|
434
452
|
if (result.code !== 0) {
|
|
453
|
+
if (isOtpError(result.output)) {
|
|
454
|
+
return {
|
|
455
|
+
success: false,
|
|
456
|
+
error: `2FA required. Use --otp flag for TOTP, or run interactively for security key auth.`
|
|
457
|
+
};
|
|
458
|
+
}
|
|
435
459
|
return { success: false, error: `Failed to publish ${pkg.name}` };
|
|
436
460
|
}
|
|
437
461
|
console.log(` ${pkg.name} published successfully`);
|
|
@@ -913,8 +937,12 @@ async function main() {
|
|
|
913
937
|
console.log("");
|
|
914
938
|
console.log(cyan("Publishing packages..."));
|
|
915
939
|
console.log("");
|
|
940
|
+
const publishContext = {
|
|
941
|
+
otp: options.otp,
|
|
942
|
+
onAuthRequired: options.ci ? undefined : reauthenticate
|
|
943
|
+
};
|
|
916
944
|
for (const pkg of packages) {
|
|
917
|
-
const result = await publishPackage(pkg, registry,
|
|
945
|
+
const result = await publishPackage(pkg, registry, publishContext, options.dryRun);
|
|
918
946
|
if (!result.success) {
|
|
919
947
|
console.error(red(bold("Failed to publish")) + ` ${cyan(pkg.name)}: ${result.error}`);
|
|
920
948
|
console.log("");
|