diff --git a/src/cli/cli-core/src/package-manager.ts b/src/cli/cli-core/src/package-manager.ts index a8cabf11c..8c3438ba5 100644 --- a/src/cli/cli-core/src/package-manager.ts +++ b/src/cli/cli-core/src/package-manager.ts @@ -1,4 +1,4 @@ -import {spawn, SpawnOptions, spawnSync} from 'child_process'; +import {execSync, ExecSyncOptions, spawn, SpawnOptions, spawnSync} from 'child_process'; import {PackageManagerCommands, PackageManagers} from './api'; import {canRunCommand} from './utils'; @@ -48,10 +48,12 @@ const commands: PackageManagerCommands = { [PackageManagers.Npm]: { addDependency: 'install', installAllDependencies: 'install', + execBinary: 'npx', }, [PackageManagers.Yarn]: { addDependency: 'add', installAllDependencies: 'install', + execBinary: 'yarn', }, }; @@ -76,8 +78,8 @@ export class PackageManager { /** * Installs all the dependencies listed in package.json. */ - installAllDependencies (options?: SpawnOptions) { - return this.exec([this.commands.installAllDependencies], options); + installAllDependencies (options?: ExecSyncOptions) { + return execSync(`${this.binary} ${this.commands.installAllDependencies}`, options); } /** @@ -96,6 +98,10 @@ export class PackageManager { }); }); } + + execBinary (command: string, options?: ExecSyncOptions) { + execSync(`${this.commands.execBinary} ${command}`, options); + } } let packageManager: PackageManager; diff --git a/src/utils/start/src/index.action.ts b/src/utils/start/src/index.action.ts index d8d217ed9..29037d1a8 100644 --- a/src/utils/start/src/index.action.ts +++ b/src/utils/start/src/index.action.ts @@ -48,19 +48,19 @@ export = async (_: {}, target: Target) => { const guideUrl = guideUrls[target]; switch (target) { case Target.Android: - execSync(`${diez} compile -t android`, {stdio: 'inherit'}); + packageManager.execBinary('diez compile -t android', {stdio: 'inherit'}); Log.comment('Starting the Diez hot server...'); hotProcess = fork(diez, ['hot', '-t', 'android'], {stdio: 'inherit'}); break; case Target.Ios: - execSync(`${diez} compile -t ios --cocoapods`, {stdio: 'inherit'}); + packageManager.execBinary('diez compile -t ios --cocoapods', {stdio: 'inherit'}); Log.comment('Installing CocoaPods dependencies in example codebase...'); execSync('pod install', {cwd: targetRoot, stdio: 'inherit'}); Log.comment('Starting the Diez hot server...'); hotProcess = fork(diez, ['hot', '-t', 'ios'], {stdio: 'inherit'}); break; case Target.Web: - execSync(`${diez} compile -t web`, {stdio: 'inherit'}); + packageManager.execBinary('diez compile -t web', {stdio: 'inherit'}); Log.comment('Installing Node dependencies in example codebase...'); await packageManager.installAllDependencies({cwd: targetRoot, stdio: 'inherit'}); Log.comment('Starting the Diez hot server...');