diff --git a/terminus-plugin-manager/src/services/pluginManager.service.ts b/terminus-plugin-manager/src/services/pluginManager.service.ts index e881cf8c..916574a7 100644 --- a/terminus-plugin-manager/src/services/pluginManager.service.ts +++ b/terminus-plugin-manager/src/services/pluginManager.service.ts @@ -29,6 +29,7 @@ export class PluginManagerService { userPluginsPath: string = (window as any).userPluginsPath installedPlugins: IPluginInfo[] = (window as any).installedPlugins npmPath: string + private envPath: string constructor ( log: LogService, @@ -41,11 +42,13 @@ export class PluginManagerService { async detectPath () { this.npmPath = this.config.store.npm + this.envPath = process.env.PATH if (await fs.exists(this.npmPath)) { return } if (this.hostApp.platform !== Platform.Windows) { - let searchPaths = (await exec('$SHELL -c -i \'echo $PATH\''))[0].toString().trim().split(':') + this.envPath = (await exec('$SHELL -c -i \'echo $PATH\''))[0].toString().trim() + let searchPaths = this.envPath.split(':') for (let searchPath of searchPaths) { if (await fs.exists(path.join(searchPath, 'npm'))) { this.logger.debug('Found npm in', searchPath) @@ -59,7 +62,7 @@ export class PluginManagerService { async isNPMInstalled (): Promise { await this.detectPath() try { - await exec(`${this.npmPath} -v`) + await exec(`${this.npmPath} -v`, { env: this.getEnv() }) return true } catch (_) { return false @@ -88,13 +91,17 @@ export class PluginManagerService { } async installPlugin (plugin: IPluginInfo) { - await exec(`${this.npmPath} --prefix "${this.userPluginsPath}" install ${plugin.packageName}@${plugin.version}`) + await exec(`${this.npmPath} --prefix "${this.userPluginsPath}" install ${plugin.packageName}@${plugin.version}`, { env: this.getEnv() }) this.installedPlugins = this.installedPlugins.filter(x => x.packageName !== plugin.packageName) this.installedPlugins.push(plugin) } async uninstallPlugin (plugin: IPluginInfo) { - await exec(`${this.npmPath} --prefix "${this.userPluginsPath}" remove ${plugin.packageName}`) + await exec(`${this.npmPath} --prefix "${this.userPluginsPath}" remove ${plugin.packageName}`, { env: this.getEnv() }) this.installedPlugins = this.installedPlugins.filter(x => x.packageName !== plugin.packageName) } + + private getEnv (): any { + return Object.assign(process.env, { PATH: this.envPath }) + } }