@@ -115,6 +115,22 @@ function getProjectPackageJson() {
115115 return JSON . parse ( contents ) ;
116116}
117117
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+ 118134/**
119135 * @param {string } projectName
120136 */
@@ -124,6 +140,7 @@ async function addToExistingProject(projectName) {
124140 const gitignorePath = path . join ( projectPath , ".gitignore" ) ;
125141
126142 const s = p . spinner ( ) ;
143+ const pm = getPackageManager ( ) ;
127144
128145 try {
129146 s . start ( "Loading available versions..." ) ;
@@ -180,10 +197,10 @@ async function addToExistingProject(projectName) {
180197
181198 const packages = [ `rescript@${ rescriptVersion } ` , `@rescript/core@${ rescriptCoreVersion } ` ] ;
182199
183- await promisify ( exec ) ( "npm add " + packages . join ( " " ) ) ;
200+ await promisify ( exec ) ( ` ${ pm } add ${ packages . join ( " " ) } ` ) ;
184201
185202 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" ) ;
187204 p . outro ( `Happy hacking!` ) ;
188205 } catch ( error ) {
189206 console . warn ( error ) ;
@@ -210,6 +227,7 @@ async function createNewProject() {
210227 checkCancel ( templateName ) ;
211228
212229 const s = p . spinner ( ) ;
230+ const pm = getPackageManager ( ) ;
213231
214232 try {
215233 s . start ( "Loading available versions..." ) ;
@@ -245,7 +263,7 @@ async function createNewProject() {
245263
246264 const packages = [ `rescript@${ rescriptVersion } ` , `@rescript/core@${ rescriptCoreVersion } ` ] ;
247265
248- await promisify ( exec ) ( "npm add " + packages . join ( " " ) ) ;
266+ await promisify ( exec ) ( ` ${ pm } add ${ packages . join ( " " ) } ` ) ;
249267 await promisify ( exec ) ( "git init" ) ;
250268 s . stop ( "Project created." ) ;
251269
0 commit comments