Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add more debug logs for npmrc #8

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import * as path from "node:path";
import * as fs from "node:fs";
import * as kl from "kolorist";
import { JsrPackage } from "./utils";
import { JsrPackage, logDebug } from "./utils";
import { getPkgManager } from "./pkg_manager";

const JSR_NPMRC = `@jsr:registry=https://npm.jsr.io\n`;

export async function setupNpmRc(dir: string) {
const npmRcPath = path.join(dir, ".npmrc");
logDebug(`Checking for .npmrc at: ${npmRcPath}`);
try {
let content = await fs.promises.readFile(npmRcPath, "utf-8");
if (!content.includes(JSR_NPMRC)) {
content += JSR_NPMRC;
await fs.promises.writeFile(npmRcPath, content);
logDebug(`Added @jsr registry to .npmrc`);
} else {
logDebug(`Added @jsr registry already mapped in .npmrc, skipping`);
}
} catch (err) {
if (err instanceof Error && (err as any).code === "ENOENT") {
await fs.promises.writeFile(npmRcPath, JSR_NPMRC);
logDebug(`Create new .npmrc file with @jsr registry mapping`);
} else {
throw err;
}
Expand Down
Loading