mirror of
https://github.com/Eugeny/tabby.git
synced 2024-11-28 14:08:04 +03:00
avoid importing npm until required
This commit is contained in:
parent
6b56155ca5
commit
128aa618f0
@ -1,4 +1,3 @@
|
||||
import npm from 'npm'
|
||||
import axios from 'axios'
|
||||
import { Observable, from } from 'rxjs'
|
||||
import { map } from 'rxjs/operators'
|
||||
@ -29,22 +28,34 @@ export class PluginManagerService {
|
||||
installedPlugins: IPluginInfo[] = (window as any).installedPlugins
|
||||
|
||||
private npmReady: Promise<void>
|
||||
private npm: any
|
||||
|
||||
constructor (
|
||||
log: LogService,
|
||||
) {
|
||||
this.logger = log.create('pluginManager')
|
||||
}
|
||||
|
||||
async getNPM () {
|
||||
if (!this.npm) {
|
||||
if (!this.npmReady) {
|
||||
this.npmReady = new Promise(resolve => {
|
||||
const npm = (window as any).nodeRequire('npm')
|
||||
npm.load({
|
||||
prefix: this.userPluginsPath,
|
||||
}, err => {
|
||||
if (err) {
|
||||
this.logger.error(err)
|
||||
}
|
||||
this.npm = npm
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
await this.npmReady
|
||||
}
|
||||
return this.npm
|
||||
}
|
||||
|
||||
listAvailable (query?: string): Observable<IPluginInfo[]> {
|
||||
return from(
|
||||
@ -68,8 +79,7 @@ export class PluginManagerService {
|
||||
}
|
||||
|
||||
async installPlugin (plugin: IPluginInfo) {
|
||||
await this.npmReady
|
||||
npm.commands.install([`${plugin.packageName}@${plugin.version}`], err => {
|
||||
(await this.getNPM()).commands.install([`${plugin.packageName}@${plugin.version}`], err => {
|
||||
if (err) {
|
||||
this.logger.error(err)
|
||||
}
|
||||
@ -79,8 +89,7 @@ export class PluginManagerService {
|
||||
}
|
||||
|
||||
async uninstallPlugin (plugin: IPluginInfo) {
|
||||
await this.npmReady
|
||||
npm.commands.remove([plugin.packageName], err => {
|
||||
(await this.getNPM()).commands.remove([plugin.packageName], err => {
|
||||
if (err) {
|
||||
this.logger.error(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user