pubz 0.2.8 → 0.2.10
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 +29 -15
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -195,6 +195,13 @@ function prompt(question) {
|
|
|
195
195
|
function closePrompt() {
|
|
196
196
|
rl.close();
|
|
197
197
|
}
|
|
198
|
+
function resetPrompt() {
|
|
199
|
+
rl.close();
|
|
200
|
+
rl = readline.createInterface({
|
|
201
|
+
input: process.stdin,
|
|
202
|
+
output: process.stdout
|
|
203
|
+
});
|
|
204
|
+
}
|
|
198
205
|
async function confirm(message, defaultYes = true) {
|
|
199
206
|
const hint = defaultYes ? `[${bold("Y")}/n]` : `[y/${bold("N")}]`;
|
|
200
207
|
const answer = await prompt(`${cyan("?")} ${message} ${hint} `);
|
|
@@ -346,11 +353,6 @@ async function npmLogin(registry) {
|
|
|
346
353
|
});
|
|
347
354
|
});
|
|
348
355
|
}
|
|
349
|
-
async function promptForOtp() {
|
|
350
|
-
console.log("");
|
|
351
|
-
const code = await prompt(`${cyan("?")} Enter OTP code from your authenticator: `);
|
|
352
|
-
return code.trim();
|
|
353
|
-
}
|
|
354
356
|
|
|
355
357
|
// src/publish.ts
|
|
356
358
|
import { spawn as spawn2 } from "node:child_process";
|
|
@@ -376,6 +378,17 @@ function run(command, args, cwd) {
|
|
|
376
378
|
});
|
|
377
379
|
});
|
|
378
380
|
}
|
|
381
|
+
function runInteractive(command, args, cwd) {
|
|
382
|
+
return new Promise((resolve2) => {
|
|
383
|
+
const proc = spawn2(command, args, {
|
|
384
|
+
cwd,
|
|
385
|
+
stdio: "inherit"
|
|
386
|
+
});
|
|
387
|
+
proc.on("close", (code) => {
|
|
388
|
+
resolve2({ code: code ?? 1 });
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
}
|
|
379
392
|
async function runBuild(cwd, dryRun) {
|
|
380
393
|
if (dryRun) {
|
|
381
394
|
console.log("[DRY RUN] Would run: bun run build");
|
|
@@ -438,20 +451,20 @@ async function publishPackage(pkg, registry, context, dryRun) {
|
|
|
438
451
|
if (context.otp) {
|
|
439
452
|
args.push("--otp", context.otp);
|
|
440
453
|
}
|
|
441
|
-
let result
|
|
442
|
-
if (
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
454
|
+
let result;
|
|
455
|
+
if (context.useBrowserAuth) {
|
|
456
|
+
args.push("--auth-type", "web");
|
|
457
|
+
const interactiveResult = await runInteractive("npm", args, pkg.path);
|
|
458
|
+
result = { code: interactiveResult.code, output: "" };
|
|
459
|
+
context.onInteractiveComplete?.();
|
|
460
|
+
} else {
|
|
461
|
+
result = await run("npm", args, pkg.path);
|
|
449
462
|
}
|
|
450
463
|
if (result.code !== 0) {
|
|
451
464
|
if (isOtpError(result.output)) {
|
|
452
465
|
return {
|
|
453
466
|
success: false,
|
|
454
|
-
error:
|
|
467
|
+
error: "2FA required. Use --otp flag for TOTP, or run interactively."
|
|
455
468
|
};
|
|
456
469
|
}
|
|
457
470
|
return { success: false, error: `Failed to publish ${pkg.name}` };
|
|
@@ -937,7 +950,8 @@ async function main() {
|
|
|
937
950
|
console.log("");
|
|
938
951
|
const publishContext = {
|
|
939
952
|
otp: options.otp,
|
|
940
|
-
|
|
953
|
+
useBrowserAuth: !options.ci,
|
|
954
|
+
onInteractiveComplete: resetPrompt
|
|
941
955
|
};
|
|
942
956
|
for (const pkg of packages) {
|
|
943
957
|
const result = await publishPackage(pkg, registry, publishContext, options.dryRun);
|