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

fix: don't overwrite existing jsr registry mapping #26

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
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
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");
});
});
});
Loading