From bf7016caa34b1bb8c76018f35edd31a6d6c3b33c Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura Date: Sat, 2 Mar 2024 02:20:41 +0000 Subject: [PATCH 1/4] fix: second `jsr add` fails --- src/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands.ts b/src/commands.ts index ff80a52..9f5749c 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -50,7 +50,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 (!/^"@myorg1"\s+=/gm.test(content) && !content.includes(JSR_BUNFIG)) { content += JSR_BUNFIG; await wrapWithStatus(msg, async () => { await fs.promises.writeFile(bunfigPath, content); From 02c14cbb6e01c14a66fed009b1d33fd5f2f0eca0 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura Date: Sat, 2 Mar 2024 07:16:11 +0000 Subject: [PATCH 2/4] refactor: use regexp --- src/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands.ts b/src/commands.ts index 9f5749c..e03b722 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -50,7 +50,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) && !content.includes(JSR_BUNFIG)) { + if (!/^"@jsr"\s+=/gm.test(content)) { content += JSR_BUNFIG; await wrapWithStatus(msg, async () => { await fs.promises.writeFile(bunfigPath, content); From 31dba322b57de7789fbb8fc895318d5c89fefa7f Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura Date: Tue, 5 Mar 2024 11:02:42 +0000 Subject: [PATCH 3/4] feat: add test code --- test/commands.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/commands.test.ts b/test/commands.test.ts index 208d7f7..15329b5 100644 --- a/test/commands.test.ts +++ b/test/commands.test.ts @@ -164,6 +164,19 @@ describe("install", () => { }, ); }); + it("jsr add --bun @std/encoding@0.216.0 - forces bun for twice", async () => { + await withTempEnv( + ["i", "--bun", "@std/encoding@0.216.0"], + async (_, dir) => { + await runJsr(["i", "--bun", "@std/encoding@0.216.0"], 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", () => { From 3db3fed06e1b17512788ed623b514ce925987e7f Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura Date: Tue, 5 Mar 2024 11:43:54 +0000 Subject: [PATCH 4/4] chore: format code --- test/commands.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/commands.test.ts b/test/commands.test.ts index 15329b5..a232fc6 100644 --- a/test/commands.test.ts +++ b/test/commands.test.ts @@ -168,15 +168,15 @@ describe("install", () => { await withTempEnv( ["i", "--bun", "@std/encoding@0.216.0"], async (_, dir) => { - await runJsr(["i", "--bun", "@std/encoding@0.216.0"], dir) + await runJsr(["i", "--bun", "@std/encoding@0.216.0"], 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", () => {