@@ -84,6 +84,16 @@ export async function setupBunfigToml(dir: string) {
84
84
}
85
85
}
86
86
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
+
87
97
export interface BaseOptions {
88
98
pkgManagerName : PkgManagerName | null ;
89
99
}
@@ -99,11 +109,21 @@ export async function install(packages: JsrPackage[], options: InstallOptions) {
99
109
) ;
100
110
101
111
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
+ }
107
127
} else if ( pkgManager instanceof YarnBerry ) {
108
128
// Yarn v2+ does not read from .npmrc intentionally
109
129
// https://yarnpkg.com/migration/guide#update-your-configuration-to-the-new-settings
0 commit comments