diff --git a/src/commands.ts b/src/commands.ts index 3007a33..b51140d 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -84,6 +84,16 @@ export async function setupBunfigToml(dir: string) { } } +async function bunfigExists(dir: string): Promise { + const bunfigPath = path.join(dir, BUNFIG_FILE); + try { + await fs.promises.access(bunfigPath); + return true; + } catch { + return false; + } +} + export interface BaseOptions { pkgManagerName: PkgManagerName | null; } @@ -99,11 +109,21 @@ export async function install(packages: JsrPackage[], options: InstallOptions) { ); if (packages.length > 0) { - if (pkgManager instanceof Bun && !(await pkgManager.isNpmrcSupported())) { - // Bun v1.1.17 or lower doesn't support reading from .npmrc - // Bun v1.1.18+ supports npmrc - // https://bun.sh/blog/bun-v1.1.18#npmrc-support - await setupBunfigToml(root); + if (pkgManager instanceof Bun) { + // Always check if bunfig.toml exists first, regardless of Bun version + if (await bunfigExists(root)) { + // If bunfig.toml exists, use it + await setupBunfigToml(root); + } else if (!(await pkgManager.isNpmrcSupported())) { + // Bun v1.1.17 or lower doesn't support reading from .npmrc + // Bun v1.1.18+ supports npmrc + // https://bun.sh/blog/bun-v1.1.18#npmrc-support + // Create bunfig.toml for older versions + await setupBunfigToml(root); + } else { + // For newer Bun versions without existing bunfig.toml, use .npmrc + await setupNpmRc(root); + } } else if (pkgManager instanceof YarnBerry) { // Yarn v2+ does not read from .npmrc intentionally // https://yarnpkg.com/migration/guide#update-your-configuration-to-the-new-settings