1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-23 13:13:49 +03:00

fixed NPM detection in cases when node is not on PATH

This commit is contained in:
Eugene Pankov 2018-04-03 13:31:56 +02:00
parent 30f221d05e
commit 128fe24003

View File

@ -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<boolean> {
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 })
}
}