@@ -2,6 +2,7 @@ import chalk from "chalk";
22import { execSync , spawn } from "child_process" ;
33import * as path from "path" ;
44import * as fs from "fs" ;
5+ import { detectPackageManager , getInstallCommand , getExecCommand } from "../utils/common.js" ;
56interface InitOptions {
67 force ?: boolean ;
78 skipPrebuild ?: boolean ;
@@ -50,17 +51,11 @@ export async function initCommand(options: InitOptions): Promise<void> {
5051 path . join ( projectRoot , "node_modules" , "@10play" , "expo-air" ) ,
5152 ) ;
5253
54+ const pm = detectPackageManager ( projectRoot ) ;
55+
5356 if ( ! allDeps [ "@10play/expo-air" ] || ! moduleExists ) {
5457 console . log ( chalk . gray ( " Installing @10play/expo-air...\n" ) ) ;
55- const cmd =
56- fs . existsSync ( path . join ( projectRoot , "bun.lockb" ) ) ||
57- fs . existsSync ( path . join ( projectRoot , "bun.lock" ) )
58- ? "bun add @10play/expo-air"
59- : fs . existsSync ( path . join ( projectRoot , "pnpm-lock.yaml" ) )
60- ? "pnpm add @10play/expo-air"
61- : fs . existsSync ( path . join ( projectRoot , "yarn.lock" ) )
62- ? "yarn add @10play/expo-air"
63- : "npm install @10play/expo-air" ;
58+ const cmd = getInstallCommand ( pm , "@10play/expo-air" ) ;
6459
6560 try {
6661 execSync ( cmd , { cwd : projectRoot , stdio : "inherit" } ) ;
@@ -158,9 +153,12 @@ export async function initCommand(options: InitOptions): Promise<void> {
158153 ) ,
159154 ) ;
160155
156+ const exec = getExecCommand ( pm ) ;
157+ const prebuildCmd = [ ...exec . args , "expo" , "prebuild" , "--clean" ] ;
158+
161159 try {
162160 await new Promise < void > ( ( resolve , reject ) => {
163- const prebuild = spawn ( "npx" , [ "expo" , "prebuild" , "--clean" ] , {
161+ const prebuild = spawn ( exec . cmd , prebuildCmd , {
164162 cwd : projectRoot ,
165163 stdio : "inherit" ,
166164 shell : true ,
@@ -184,21 +182,23 @@ export async function initCommand(options: InitOptions): Promise<void> {
184182 const message = err instanceof Error ? err . message : String ( err ) ;
185183 console . log ( chalk . red ( `\n Prebuild failed: ${ message } ` ) ) ;
186184 console . log (
187- chalk . gray ( " You can run it manually: npx expo prebuild --clean\n" ) ,
185+ chalk . gray ( ` You can run it manually: ${ exec . cmd } ${ prebuildCmd . join ( " " ) } \n` ) ,
188186 ) ;
189187 process . exit ( 1 ) ;
190188 }
191189 } else {
190+ const exec = getExecCommand ( pm ) ;
192191 console . log ( chalk . yellow ( "\n Skipped prebuild (--skip-prebuild)" ) ) ;
193- console . log ( chalk . gray ( " Run manually: npx expo prebuild --clean\n" ) ) ;
192+ console . log ( chalk . gray ( ` Run manually: ${ exec . cmd } ${ [ ... exec . args , " expo" , " prebuild" , " --clean" ] . join ( " " ) } \n` ) ) ;
194193 }
195194
196195 // Success message
196+ const exec = getExecCommand ( pm ) ;
197197 console . log ( chalk . blue ( "\n expo-air initialized!\n" ) ) ;
198198 console . log ( chalk . gray ( " Next steps:" ) ) ;
199199 console . log (
200200 chalk . white ( " 1. Connect your iOS or Android device via cable" ) ,
201201 ) ;
202- console . log ( chalk . white ( " 2. Run: npx expo-air fly") ) ;
202+ console . log ( chalk . white ( ` 2. Run: ${ exec . cmd } ${ [ ... exec . args , " expo-air" , " fly"] . join ( " " ) } ` ) ) ;
203203 console . log ( chalk . white ( " 3. The widget will appear on your device\n" ) ) ;
204204}
0 commit comments