#!/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");