pubz 0.2.5 → 0.2.6

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 +77 -2
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -308,13 +308,52 @@ async function multiSelect(message, options, allSelectedByDefault = true) {
308
308
  });
309
309
  }
310
310
 
311
- // src/publish.ts
311
+ // src/auth.ts
312
312
  import { spawn } from "node:child_process";
313
+ async function checkNpmAuth(registry) {
314
+ return new Promise((resolve2) => {
315
+ const proc = spawn("npm", ["whoami", "--registry", registry], {
316
+ stdio: ["inherit", "pipe", "pipe"]
317
+ });
318
+ let stdout = "";
319
+ let stderr = "";
320
+ proc.stdout?.on("data", (data) => {
321
+ stdout += data.toString();
322
+ });
323
+ proc.stderr?.on("data", (data) => {
324
+ stderr += data.toString();
325
+ });
326
+ proc.on("close", (code) => {
327
+ if (code === 0 && stdout.trim()) {
328
+ resolve2({ authenticated: true, username: stdout.trim() });
329
+ } else {
330
+ resolve2({ authenticated: false });
331
+ }
332
+ });
333
+ });
334
+ }
335
+ async function npmLogin(registry) {
336
+ return new Promise((resolve2) => {
337
+ const proc = spawn("npm", ["login", "--registry", registry], {
338
+ stdio: "inherit"
339
+ });
340
+ proc.on("close", (code) => {
341
+ if (code === 0) {
342
+ resolve2({ success: true });
343
+ } else {
344
+ resolve2({ success: false, error: "Login failed or was cancelled" });
345
+ }
346
+ });
347
+ });
348
+ }
349
+
350
+ // src/publish.ts
351
+ import { spawn as spawn2 } from "node:child_process";
313
352
  import { readFile as readFile2, stat as stat3 } from "node:fs/promises";
314
353
  import { join as join3 } from "node:path";
315
354
  function run(command, args, cwd) {
316
355
  return new Promise((resolve2) => {
317
- const proc = spawn(command, args, {
356
+ const proc = spawn2(command, args, {
318
357
  cwd,
319
358
  stdio: ["inherit", "pipe", "pipe"]
320
359
  });
@@ -777,6 +816,42 @@ async function main() {
777
816
  console.log("");
778
817
  console.log(`Publishing to: ${cyan(registry)}`);
779
818
  console.log("");
819
+ if (!options.dryRun) {
820
+ console.log(cyan("Verifying npm authentication..."));
821
+ const authResult = await checkNpmAuth(registry);
822
+ if (!authResult.authenticated) {
823
+ if (options.ci) {
824
+ console.error(red(bold("Error:")) + " Not authenticated to npm.");
825
+ console.log("");
826
+ console.log(muted("In CI mode, you need to configure authentication:"));
827
+ console.log(muted(" - Set NPM_TOKEN environment variable"));
828
+ console.log(muted(" - Or configure .npmrc with auth token"));
829
+ console.log(muted(" - Or use OIDC Trusted Publishing"));
830
+ closePrompt();
831
+ process.exit(1);
832
+ }
833
+ console.log("");
834
+ console.log(yellow("Not logged in to npm.") + " Starting login...");
835
+ console.log("");
836
+ const loginResult = await npmLogin(registry);
837
+ if (!loginResult.success) {
838
+ console.error(red(bold("Login failed:")) + ` ${loginResult.error}`);
839
+ closePrompt();
840
+ process.exit(1);
841
+ }
842
+ const verifyAuth = await checkNpmAuth(registry);
843
+ if (!verifyAuth.authenticated) {
844
+ console.error(red(bold("Error:")) + " Login did not complete successfully.");
845
+ closePrompt();
846
+ process.exit(1);
847
+ }
848
+ console.log("");
849
+ console.log(green("Logged in as") + ` ${cyan(verifyAuth.username ?? "unknown")}`);
850
+ } else {
851
+ console.log(green("Authenticated as") + ` ${cyan(authResult.username ?? "unknown")}`);
852
+ }
853
+ console.log("");
854
+ }
780
855
  if (!options.skipBuild) {
781
856
  console.log(bold(cyan("Step 2:")) + " Building Packages");
782
857
  console.log(dim("─".repeat(30)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubz",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Interactive CLI for publishing npm packages (single or monorepo)",
5
5
  "type": "module",
6
6
  "bin": {