pubz 0.2.9 → 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 -17
- 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,10 +353,6 @@ async function npmLogin(registry) {
|
|
|
346
353
|
});
|
|
347
354
|
});
|
|
348
355
|
}
|
|
349
|
-
async function reauthenticate(registry) {
|
|
350
|
-
const loginResult = await npmLogin(registry);
|
|
351
|
-
return loginResult.success;
|
|
352
|
-
}
|
|
353
356
|
|
|
354
357
|
// src/publish.ts
|
|
355
358
|
import { spawn as spawn2 } from "node:child_process";
|
|
@@ -375,6 +378,17 @@ function run(command, args, cwd) {
|
|
|
375
378
|
});
|
|
376
379
|
});
|
|
377
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
|
+
}
|
|
378
392
|
async function runBuild(cwd, dryRun) {
|
|
379
393
|
if (dryRun) {
|
|
380
394
|
console.log("[DRY RUN] Would run: bun run build");
|
|
@@ -437,23 +451,20 @@ async function publishPackage(pkg, registry, context, dryRun) {
|
|
|
437
451
|
if (context.otp) {
|
|
438
452
|
args.push("--otp", context.otp);
|
|
439
453
|
}
|
|
440
|
-
let result
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const retryArgs = ["publish", "--registry", registry, "--access", "public"];
|
|
449
|
-
result = await run("npm", retryArgs, pkg.path);
|
|
450
|
-
}
|
|
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);
|
|
451
462
|
}
|
|
452
463
|
if (result.code !== 0) {
|
|
453
464
|
if (isOtpError(result.output)) {
|
|
454
465
|
return {
|
|
455
466
|
success: false,
|
|
456
|
-
error:
|
|
467
|
+
error: "2FA required. Use --otp flag for TOTP, or run interactively."
|
|
457
468
|
};
|
|
458
469
|
}
|
|
459
470
|
return { success: false, error: `Failed to publish ${pkg.name}` };
|
|
@@ -939,7 +950,8 @@ async function main() {
|
|
|
939
950
|
console.log("");
|
|
940
951
|
const publishContext = {
|
|
941
952
|
otp: options.otp,
|
|
942
|
-
|
|
953
|
+
useBrowserAuth: !options.ci,
|
|
954
|
+
onInteractiveComplete: resetPrompt
|
|
943
955
|
};
|
|
944
956
|
for (const pkg of packages) {
|
|
945
957
|
const result = await publishPackage(pkg, registry, publishContext, options.dryRun);
|