@@ -10,17 +10,9 @@ interface CompilationArtifact {
10
10
}
11
11
12
12
export class Cargo {
13
- rootFolder : string ;
14
- env ?: Record < string , string > ;
15
- output : OutputChannel ;
13
+ constructor ( readonly rootFolder : string , readonly output : OutputChannel ) { }
16
14
17
- public constructor ( cargoTomlFolder : string , output : OutputChannel , env : Record < string , string > | undefined = undefined ) {
18
- this . rootFolder = cargoTomlFolder ;
19
- this . output = output ;
20
- this . env = env ;
21
- }
22
-
23
- public async artifactsFromArgs ( cargoArgs : string [ ] ) : Promise < CompilationArtifact [ ] > {
15
+ private async artifactsFromArgs ( cargoArgs : string [ ] ) : Promise < CompilationArtifact [ ] > {
24
16
const artifacts : CompilationArtifact [ ] = [ ] ;
25
17
26
18
try {
@@ -37,27 +29,22 @@ export class Cargo {
37
29
isTest : message . profile . test
38
30
} ) ;
39
31
}
40
- }
41
- else if ( message . reason === 'compiler-message' ) {
32
+ } else if ( message . reason === 'compiler-message' ) {
42
33
this . output . append ( message . message . rendered ) ;
43
34
}
44
35
} ,
45
- stderr => {
46
- this . output . append ( stderr ) ;
47
- }
36
+ stderr => this . output . append ( stderr ) ,
48
37
) ;
49
- }
50
- catch ( err ) {
38
+ } catch ( err ) {
51
39
this . output . show ( true ) ;
52
40
throw new Error ( `Cargo invocation has failed: ${ err } ` ) ;
53
41
}
54
42
55
43
return artifacts ;
56
44
}
57
45
58
- public async executableFromArgs ( args : string [ ] ) : Promise < string > {
59
- const cargoArgs = [ ...args ] ; // to remain args unchanged
60
- cargoArgs . push ( "--message-format=json" ) ;
46
+ async executableFromArgs ( args : readonly string [ ] ) : Promise < string > {
47
+ const cargoArgs = [ ...args , "--message-format=json" ] ;
61
48
62
49
const artifacts = await this . artifactsFromArgs ( cargoArgs ) ;
63
50
@@ -70,24 +57,20 @@ export class Cargo {
70
57
return artifacts [ 0 ] . fileName ;
71
58
}
72
59
73
- runCargo (
60
+ private runCargo (
74
61
cargoArgs : string [ ] ,
75
62
onStdoutJson : ( obj : any ) => void ,
76
63
onStderrString : ( data : string ) => void
77
64
) : Promise < number > {
78
- return new Promise < number > ( ( resolve , reject ) => {
65
+ return new Promise ( ( resolve , reject ) => {
79
66
const cargo = cp . spawn ( 'cargo' , cargoArgs , {
80
67
stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
81
- cwd : this . rootFolder ,
82
- env : this . env ,
68
+ cwd : this . rootFolder
83
69
} ) ;
84
70
85
- cargo . on ( 'error' , err => {
86
- reject ( new Error ( `could not launch cargo: ${ err } ` ) ) ;
87
- } ) ;
88
- cargo . stderr . on ( 'data' , chunk => {
89
- onStderrString ( chunk . toString ( ) ) ;
90
- } ) ;
71
+ cargo . on ( 'error' , err => reject ( new Error ( `could not launch cargo: ${ err } ` ) ) ) ;
72
+
73
+ cargo . stderr . on ( 'data' , chunk => onStderrString ( chunk . toString ( ) ) ) ;
91
74
92
75
const rl = readline . createInterface ( { input : cargo . stdout } ) ;
93
76
rl . on ( 'line' , line => {
@@ -103,4 +86,4 @@ export class Cargo {
103
86
} ) ;
104
87
} ) ;
105
88
}
106
- }
89
+ }
0 commit comments