Skip to content
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