1
1
import PicGo from '../core/PicGo'
2
2
import spawn from 'cross-spawn'
3
- import { Result } from '../utils/interfaces'
3
+ import { Result , ProcessEnv } from '../utils/interfaces'
4
4
5
5
class PluginHandler {
6
6
// Thanks to feflow -> https://github.com/feflow/feflow/blob/master/lib/internal/install/plugin.js
@@ -9,9 +9,9 @@ class PluginHandler {
9
9
this . ctx = ctx
10
10
}
11
11
12
- async install ( plugins : string [ ] , proxy : string = '' ) : Promise < void > {
12
+ async install ( plugins : string [ ] , proxy : string = '' , env : ProcessEnv ) : Promise < void > {
13
13
plugins = plugins . map ( ( item : string ) => 'picgo-plugin-' + item )
14
- const result = await this . execCommand ( 'install' , plugins , this . ctx . baseDir , proxy )
14
+ const result = await this . execCommand ( 'install' , plugins , this . ctx . baseDir , proxy , env )
15
15
if ( ! result . code ) {
16
16
plugins . forEach ( ( plugin : string ) => {
17
17
this . ctx . pluginLoader . registerPlugin ( plugin )
@@ -51,9 +51,9 @@ class PluginHandler {
51
51
} )
52
52
}
53
53
}
54
- async update ( plugins : string [ ] , proxy : string = '' ) : Promise < void > {
54
+ async update ( plugins : string [ ] , proxy : string = '' , env : ProcessEnv ) : Promise < void > {
55
55
plugins = plugins . map ( ( item : string ) => 'picgo-plugin-' + item )
56
- const result = await this . execCommand ( 'update' , plugins , this . ctx . baseDir , proxy )
56
+ const result = await this . execCommand ( 'update' , plugins , this . ctx . baseDir , proxy , env )
57
57
if ( ! result . code ) {
58
58
this . ctx . log . success ( '插件更新成功' )
59
59
this . ctx . emit ( 'updateSuccess' , {
@@ -69,7 +69,7 @@ class PluginHandler {
69
69
} )
70
70
}
71
71
}
72
- execCommand ( cmd : string , modules : string [ ] , where : string , proxy : string = '' ) : Promise < Result > {
72
+ execCommand ( cmd : string , modules : string [ ] , where : string , proxy : string = '' , env : ProcessEnv = { } ) : Promise < Result > {
73
73
const registry = this . ctx . getConfig ( 'registry' )
74
74
return new Promise ( ( resolve : any , reject : any ) : void => {
75
75
let args = [ cmd ] . concat ( modules ) . concat ( '--color=always' ) . concat ( '--save' )
@@ -80,7 +80,7 @@ class PluginHandler {
80
80
args = args . concat ( `--proxy=${ proxy } ` )
81
81
}
82
82
try {
83
- const npm = spawn ( 'npm' , args , { cwd : where } )
83
+ const npm = spawn ( 'npm' , args , { cwd : where , env : Object . assign ( { } , process . env , env ) } )
84
84
85
85
let output = ''
86
86
npm . stdout . on ( 'data' , ( data : string ) => {
0 commit comments