@@ -84,6 +84,16 @@ export async function setupBunfigToml(dir: string) {
8484 }
8585}
8686
87+ async function bunfigExists ( dir : string ) : Promise < boolean > {
88+ const bunfigPath = path . join ( dir , BUNFIG_FILE ) ;
89+ try {
90+ await fs . promises . access ( bunfigPath ) ;
91+ return true ;
92+ } catch {
93+ return false ;
94+ }
95+ }
96+
8797export interface BaseOptions {
8898 pkgManagerName : PkgManagerName | null ;
8999}
@@ -99,11 +109,21 @@ export async function install(packages: JsrPackage[], options: InstallOptions) {
99109 ) ;
100110
101111 if ( packages . length > 0 ) {
102- if ( pkgManager instanceof Bun && ! ( await pkgManager . isNpmrcSupported ( ) ) ) {
103- // Bun v1.1.17 or lower doesn't support reading from .npmrc
104- // Bun v1.1.18+ supports npmrc
105- // https://bun.sh/blog/bun-v1.1.18#npmrc-support
106- await setupBunfigToml ( root ) ;
112+ if ( pkgManager instanceof Bun ) {
113+ // Always check if bunfig.toml exists first, regardless of Bun version
114+ if ( await bunfigExists ( root ) ) {
115+ // If bunfig.toml exists, use it
116+ await setupBunfigToml ( root ) ;
117+ } else if ( ! ( await pkgManager . isNpmrcSupported ( ) ) ) {
118+ // Bun v1.1.17 or lower doesn't support reading from .npmrc
119+ // Bun v1.1.18+ supports npmrc
120+ // https://bun.sh/blog/bun-v1.1.18#npmrc-support
121+ // Create bunfig.toml for older versions
122+ await setupBunfigToml ( root ) ;
123+ } else {
124+ // For newer Bun versions without existing bunfig.toml, use .npmrc
125+ await setupNpmRc ( root ) ;
126+ }
107127 } else if ( pkgManager instanceof YarnBerry ) {
108128 // Yarn v2+ does not read from .npmrc intentionally
109129 // https://yarnpkg.com/migration/guide#update-your-configuration-to-the-new-settings
0 commit comments