#!/usr/bin/env node
/**
* Test NPM configuration and authentication
*/
import { execSync } from "child_process";
import { readFileSync } from "fs";
console.log("š Testing NPM Configuration...\n");
// Check if .npmrc exists
try {
const npmrc = readFileSync(".npmrc", "utf8");
console.log("ā
.npmrc file exists");
console.log("š Contents:");
console.log(
npmrc
.split("\n")
.map((line) => " " + line)
.join("\n"),
);
} catch (error) {
console.log("ā .npmrc file not found");
process.exit(1);
}
// Check NPM_TOKEN environment variable
console.log("\nš Environment Variable Check:");
if (process.env.NPM_TOKEN) {
console.log("ā
NPM_TOKEN is set");
console.log(`š Token length: ${process.env.NPM_TOKEN.length} characters`);
} else {
console.log("ā ļø NPM_TOKEN environment variable not set");
console.log('š” Set it with: export NPM_TOKEN="your_token_here"');
}
// Test npm whoami (only if token is set)
console.log("\nš¤ Authentication Test:");
if (process.env.NPM_TOKEN) {
try {
const whoami = execSync("npm whoami", { encoding: "utf8" }).trim();
console.log(`ā
Authenticated as: ${whoami}`);
} catch (error) {
console.log("ā Authentication failed");
console.log("š” Make sure your NPM_TOKEN is valid");
}
} else {
console.log("āļø Skipping authentication test (no token set)");
}
// Test publish dry run
console.log("\nš¦ Package Test:");
try {
const dryRun = execSync("npm publish --dry-run", { encoding: "utf8" });
console.log("ā
Package is ready for publishing");
// Extract package size info
const sizeMatch = dryRun.match(/package size:\s*([^\n]+)/i);
const filesMatch = dryRun.match(/([0-9]+) files/);
if (sizeMatch) console.log(`š Package size: ${sizeMatch[1]}`);
if (filesMatch) console.log(`š File count: ${filesMatch[1]} files`);
} catch (error) {
console.log("ā Package test failed");
if (error.message.includes("ENEEDAUTH")) {
console.log("š Authentication required for publishing");
} else {
console.log("š Error:", error.message.split("\n")[0]);
}
}
console.log("\nš Summary:");
console.log(" ā
.npmrc configured with environment variable");
console.log(" š Token safely stored in environment (not in file)");
console.log(" š¦ Package configuration validated");
console.log(" š Ready for publishing when authenticated");
console.log("\nš” Next steps:");
console.log(' 1. Set NPM_TOKEN: export NPM_TOKEN="your_token_here"');
console.log(" 2. Verify auth: npm whoami");
console.log(" 3. Publish: npm publish");