Skip to content

Commit 49dd483

Browse files
fix: don't overwrite existing jsr registry mapping (#26)
1 parent 5abd425 commit 49dd483

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/commands.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function setupNpmRc(dir: string) {
2828
const msg = `Setting up ${NPMRC_FILE}`;
2929
try {
3030
let content = await fs.promises.readFile(npmRcPath, "utf-8");
31-
if (!content.includes(JSR_NPMRC)) {
31+
if (!content.includes("@jsr:registry=")) {
3232
content += JSR_NPMRC;
3333
await wrapWithStatus(msg, async () => {
3434
await fs.promises.writeFile(npmRcPath, content);

test/unit.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as path from "path";
2+
import * as fs from "fs";
3+
import { runInTempDir } from "./test_utils";
4+
import { setupNpmRc } from "../src/commands";
5+
import * as assert from "assert/strict";
6+
7+
describe("npmrc", () => {
8+
it("doesn't overwrite exising jsr mapping", async () => {
9+
await runInTempDir(async (dir) => {
10+
const npmrc = path.join(dir, ".npmrc");
11+
await fs.promises.writeFile(
12+
npmrc,
13+
"@jsr:registry=https://example.com\n",
14+
"utf-8",
15+
);
16+
17+
await setupNpmRc(dir);
18+
19+
const content = await fs.promises.readFile(npmrc, "utf-8");
20+
assert.equal(content.trim(), "@jsr:registry=https://example.com");
21+
});
22+
});
23+
});

0 commit comments

Comments
 (0)