Skip to content

Commit

Permalink
fix: bun error on calling jsr add twice (#36)
Browse files Browse the repository at this point in the history
* fix: second `jsr add` fails

* refactor: use regexp

* feat: add test code

* chore: format code
  • Loading branch information
nakasyou authored Mar 5, 2024
1 parent fdfd39b commit ef97c32
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -52,7 +52,7 @@ export async function setupBunfigToml(dir: string) {
const msg = `Setting up ${BUNFIG_FILE}`;
try {
let content = await fs.promises.readFile(bunfigPath, "utf-8");
if (!/^"@myorg1"\s+=/gm.test(content)) {
if (!/^"@jsr"\s+=/gm.test(content)) {
content += JSR_BUNFIG;
await wrapWithStatus(msg, async () => {
await fs.promises.writeFile(bunfigPath, content);
Expand Down
13 changes: 13 additions & 0 deletions test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,19 @@ describe("install", () => {
},
);
});
it("jsr add --bun @std/[email protected] - forces bun for twice", async () => {
await withTempEnv(
["i", "--bun", "@std/[email protected]"],
async (_, dir) => {
await runJsr(["i", "--bun", "@std/[email protected]"], dir);
const config = await fs.promises.readFile(
path.join(dir, "bunfig.toml"),
"utf-8",
);
assert.match(config, /"@jsr"\s+=/, "bunfig.toml not created");
},
);
});
}

describe("env detection", () => {
Expand Down

0 comments on commit ef97c32

Please sign in to comment.