Skip to content

Commit

Permalink
fix: don't overwrite existing jsr registry mapping (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Feb 29, 2024
1 parent 5abd425 commit 49dd483
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function setupNpmRc(dir: string) {
const msg = `Setting up ${NPMRC_FILE}`;
try {
let content = await fs.promises.readFile(npmRcPath, "utf-8");
if (!content.includes(JSR_NPMRC)) {
if (!content.includes("@jsr:registry=")) {
content += JSR_NPMRC;
await wrapWithStatus(msg, async () => {
await fs.promises.writeFile(npmRcPath, content);
Expand Down
23 changes: 23 additions & 0 deletions test/unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as path from "path";
import * as fs from "fs";
import { runInTempDir } from "./test_utils";
import { setupNpmRc } from "../src/commands";
import * as assert from "assert/strict";

describe("npmrc", () => {
it("doesn't overwrite exising jsr mapping", async () => {
await runInTempDir(async (dir) => {
const npmrc = path.join(dir, ".npmrc");
await fs.promises.writeFile(
npmrc,
"@jsr:registry=https://example.com\n",
"utf-8",
);

await setupNpmRc(dir);

const content = await fs.promises.readFile(npmrc, "utf-8");
assert.equal(content.trim(), "@jsr:registry=https://example.com");
});
});
});

0 comments on commit 49dd483

Please sign in to comment.