@@ -26,7 +26,7 @@ export function getExtensionPath() {
26
26
export function getUnixTempDirectory ( ) {
27
27
const envTmp = process . env . TMPDIR ;
28
28
if ( ! envTmp ) {
29
- return " /tmp/" ;
29
+ return ' /tmp/' ;
30
30
}
31
31
32
32
return envTmp ;
@@ -38,14 +38,14 @@ export function sum<T>(arr: T[], selector: (item: T) => number): number {
38
38
39
39
export async function mapAsync < T1 , T2 > (
40
40
array : T1 [ ] ,
41
- selector : ( value : T1 , index : number , array : T1 [ ] ) => Promise < T2 > ,
41
+ selector : ( value : T1 , index : number , array : T1 [ ] ) => Promise < T2 >
42
42
) : Promise < T2 [ ] > {
43
43
return Promise . all ( array . map ( selector ) ) ;
44
44
}
45
45
46
46
export async function filterAsync < T > (
47
47
array : T [ ] ,
48
- predicate : ( value : T , index : number , array : T [ ] ) => Promise < boolean > ,
48
+ predicate : ( value : T , index : number , array : T [ ] ) => Promise < boolean >
49
49
) : Promise < T [ ] > {
50
50
const filterMap = await mapAsync ( array , predicate ) ;
51
51
return array . filter ( ( _ , index ) => filterMap [ index ] ) ;
@@ -56,18 +56,22 @@ export function safeLength<T>(arr: T[] | undefined) {
56
56
return arr ? arr . length : 0 ;
57
57
}
58
58
59
- export async function execChildProcess ( command : string , workingDirectory : string = getExtensionPath ( ) , env : NodeJS . ProcessEnv = { } ) : Promise < string > {
59
+ export async function execChildProcess (
60
+ command : string ,
61
+ workingDirectory : string = getExtensionPath ( ) ,
62
+ env : NodeJS . ProcessEnv = { }
63
+ ) : Promise < string > {
60
64
return new Promise < string > ( ( resolve , reject ) => {
61
65
cp . exec ( command , { cwd : workingDirectory , maxBuffer : 500 * 1024 , env : env } , ( error , stdout , stderr ) => {
62
66
if ( error ) {
63
- reject ( new Error ( `${ error }
67
+ reject (
68
+ new Error ( `${ error }
64
69
${ stdout }
65
- ${ stderr } `) ) ;
66
- }
67
- else if ( stderr && ! stderr . includes ( " screen size is bogus" ) ) {
70
+ ${ stderr } `)
71
+ ) ;
72
+ } else if ( stderr && ! stderr . includes ( ' screen size is bogus' ) ) {
68
73
reject ( new Error ( stderr ) ) ;
69
- }
70
- else {
74
+ } else {
71
75
resolve ( stdout ) ;
72
76
}
73
77
} ) ;
@@ -81,7 +85,7 @@ export async function getUnixChildProcessIds(pid: number): Promise<number[]> {
81
85
return reject ( error ) ;
82
86
}
83
87
84
- if ( stderr && ! stderr . includes ( " screen size is bogus" ) ) {
88
+ if ( stderr && ! stderr . includes ( ' screen size is bogus' ) ) {
85
89
return reject ( new Error ( stderr ) ) ;
86
90
}
87
91
@@ -90,7 +94,7 @@ export async function getUnixChildProcessIds(pid: number): Promise<number[]> {
90
94
}
91
95
92
96
const lines = stdout . split ( os . EOL ) ;
93
- const pairs = lines . map ( line => line . trim ( ) . split ( / \s + / ) ) ;
97
+ const pairs = lines . map ( ( line ) => line . trim ( ) . split ( / \s + / ) ) ;
94
98
95
99
const children = [ ] ;
96
100
@@ -111,36 +115,34 @@ export async function fileExists(filePath: string): Promise<boolean> {
111
115
fs . stat ( filePath , ( err , stats ) => {
112
116
if ( stats && stats . isFile ( ) ) {
113
117
resolve ( true ) ;
114
- }
115
- else {
118
+ } else {
116
119
resolve ( false ) ;
117
120
}
118
121
} ) ;
119
122
} ) ;
120
123
}
121
124
122
125
export async function deleteIfExists ( filePath : string ) : Promise < void > {
123
- return fileExists ( filePath )
124
- . then ( async ( exists : boolean ) => {
125
- return new Promise < void > ( ( resolve , reject ) => {
126
- if ( ! exists ) {
127
- return resolve ( ) ;
128
- }
126
+ return fileExists ( filePath ) . then ( async ( exists : boolean ) => {
127
+ return new Promise < void > ( ( resolve , reject ) => {
128
+ if ( ! exists ) {
129
+ return resolve ( ) ;
130
+ }
129
131
130
- fs . unlink ( filePath , err => {
131
- if ( err ) {
132
- return reject ( err ) ;
133
- }
132
+ fs . unlink ( filePath , ( err ) => {
133
+ if ( err ) {
134
+ return reject ( err ) ;
135
+ }
134
136
135
- resolve ( ) ;
136
- } ) ;
137
+ resolve ( ) ;
137
138
} ) ;
138
139
} ) ;
140
+ } ) ;
139
141
}
140
142
141
143
export enum InstallFileType {
142
144
Begin ,
143
- Lock
145
+ Lock ,
144
146
}
145
147
146
148
export function getInstallFilePath ( folderPath : AbsolutePath , type : InstallFileType ) : string {
@@ -154,7 +156,7 @@ export async function installFileExists(folderPath: AbsolutePath, type: InstallF
154
156
155
157
export async function touchInstallFile ( folderPath : AbsolutePath , type : InstallFileType ) : Promise < void > {
156
158
return new Promise < void > ( ( resolve , reject ) => {
157
- fs . writeFile ( getInstallFilePath ( folderPath , type ) , '' , err => {
159
+ fs . writeFile ( getInstallFilePath ( folderPath , type ) , '' , ( err ) => {
158
160
if ( err ) {
159
161
reject ( err ) ;
160
162
return ;
@@ -167,7 +169,7 @@ export async function touchInstallFile(folderPath: AbsolutePath, type: InstallFi
167
169
168
170
export async function deleteInstallFile ( folderPath : AbsolutePath , type : InstallFileType ) : Promise < void > {
169
171
return new Promise < void > ( ( resolve , reject ) => {
170
- fs . unlink ( getInstallFilePath ( folderPath , type ) , err => {
172
+ fs . unlink ( getInstallFilePath ( folderPath , type ) , ( err ) => {
171
173
if ( err ) {
172
174
reject ( err ) ;
173
175
return ;
@@ -196,25 +198,31 @@ export function isSubfolderOf(subfolder: string, folder: string): boolean {
196
198
const folderArray : string [ ] = folder . split ( path . sep ) ;
197
199
198
200
// Check to see that every sub directory in subfolder exists in folder.
199
- return subfolderArray . length <= folderArray . length && subfolderArray . every ( ( subpath , index ) => folderArray [ index ] === subpath ) ;
201
+ return (
202
+ subfolderArray . length <= folderArray . length &&
203
+ subfolderArray . every ( ( subpath , index ) => folderArray [ index ] === subpath )
204
+ ) ;
200
205
}
201
206
202
207
/**
203
208
* Find PowerShell executable from PATH (for Windows only).
204
209
*/
205
210
export function findPowerShell ( ) : string | undefined {
206
- const dirs : string [ ] = ( process . env . PATH || '' ) . replace ( / " + / g, '' ) . split ( ';' ) . filter ( x => x ) ;
211
+ const dirs : string [ ] = ( process . env . PATH || '' )
212
+ . replace ( / " + / g, '' )
213
+ . split ( ';' )
214
+ . filter ( ( x ) => x ) ;
207
215
const names : string [ ] = [ 'pwsh.exe' , 'powershell.exe' ] ;
208
216
for ( const name of names ) {
209
- const candidates : string [ ] = dirs . reduce < string [ ] > ( ( paths , dir ) => [
210
- ...paths , path . join ( dir , name )
211
- ] , [ ] ) ;
217
+ const candidates : string [ ] = dirs . reduce < string [ ] > ( ( paths , dir ) => [ ...paths , path . join ( dir , name ) ] , [ ] ) ;
212
218
for ( const candidate of candidates ) {
213
219
try {
214
220
if ( fs . statSync ( candidate ) . isFile ( ) ) {
215
221
return name ;
216
222
}
217
- } catch ( e ) { /* empty */ }
223
+ } catch ( e ) {
224
+ /* empty */
225
+ }
218
226
}
219
227
}
220
228
}
0 commit comments