Skip to content
Open
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
30 changes: 25 additions & 5 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ export async function setupBunfigToml(dir: string) {
}
}

async function bunfigExists(dir: string): Promise<boolean> {
const bunfigPath = path.join(dir, BUNFIG_FILE);
try {
await fs.promises.access(bunfigPath);
return true;
} catch {
return false;
}
}

export interface BaseOptions {
pkgManagerName: PkgManagerName | null;
}
Expand All @@ -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
Expand Down
Loading