@@ -115,6 +115,22 @@ function getProjectPackageJson() {
115
115
return JSON . parse ( contents ) ;
116
116
}
117
117
118
+ let packageManagers = [ "npm" , "pnpm" , "yarn" , "bun" ] ;
119
+
120
+ function getPackageManager ( ) {
121
+ const executablePath = process . env . npm_execpath ?? "" ;
122
+ let executableBasename = path . basename ( executablePath ) ;
123
+ let manager = "npm" ;
124
+
125
+ packageManagers . forEach ( pm => {
126
+ if ( executableBasename ?. includes ( pm ) ) {
127
+ manager = pm ;
128
+ }
129
+ } ) ;
130
+
131
+ return manager ;
132
+ }
133
+
118
134
/**
119
135
* @param {string } projectName
120
136
*/
@@ -124,6 +140,7 @@ async function addToExistingProject(projectName) {
124
140
const gitignorePath = path . join ( projectPath , ".gitignore" ) ;
125
141
126
142
const s = p . spinner ( ) ;
143
+ const pm = getPackageManager ( ) ;
127
144
128
145
try {
129
146
s . start ( "Loading available versions..." ) ;
@@ -180,10 +197,10 @@ async function addToExistingProject(projectName) {
180
197
181
198
const packages = [ `rescript@${ rescriptVersion } ` , `@rescript/core@${ rescriptCoreVersion } ` ] ;
182
199
183
- await promisify ( exec ) ( "npm add " + packages . join ( " " ) ) ;
200
+ await promisify ( exec ) ( ` ${ pm } add ${ packages . join ( " " ) } ` ) ;
184
201
185
202
s . stop ( "Added ReScript to your project." ) ;
186
- p . note ( `npm run res:dev` , "Next steps" ) ;
203
+ p . note ( `${ pm } run res:dev` , "Next steps" ) ;
187
204
p . outro ( `Happy hacking!` ) ;
188
205
} catch ( error ) {
189
206
console . warn ( error ) ;
@@ -210,6 +227,7 @@ async function createNewProject() {
210
227
checkCancel ( templateName ) ;
211
228
212
229
const s = p . spinner ( ) ;
230
+ const pm = getPackageManager ( ) ;
213
231
214
232
try {
215
233
s . start ( "Loading available versions..." ) ;
@@ -245,7 +263,7 @@ async function createNewProject() {
245
263
246
264
const packages = [ `rescript@${ rescriptVersion } ` , `@rescript/core@${ rescriptCoreVersion } ` ] ;
247
265
248
- await promisify ( exec ) ( "npm add " + packages . join ( " " ) ) ;
266
+ await promisify ( exec ) ( ` ${ pm } add ${ packages . join ( " " ) } ` ) ;
249
267
await promisify ( exec ) ( "git init" ) ;
250
268
s . stop ( "Project created." ) ;
251
269
0 commit comments