1
+ import bytes from 'bytes'
1
2
import { createHash } from 'crypto'
2
3
import fs , { createReadStream } from 'fs'
3
- import bytes from 'bytes'
4
4
import path from 'path'
5
5
import semver from 'semver'
6
6
import tar from 'tar'
7
7
import { URL } from 'url'
8
+ import { promisify } from 'util'
8
9
import { CancellationToken , CancellationTokenSource } from 'vscode-languageserver-protocol'
9
10
import download from '../model/download'
10
11
import fetch , { FetchOptions } from '../model/fetch'
@@ -95,7 +96,10 @@ export function shouldRetry(error: any): boolean {
95
96
return false
96
97
}
97
98
98
- export function readDependencies ( directory : string ) : { [ key : string ] : string } {
99
+ /**
100
+ * Production dependencies in directory
101
+ */
102
+ export function readDependencies ( directory : string ) : Dependencies {
99
103
let jsonfile = path . join ( directory , 'package.json' )
100
104
let obj = loadJson ( jsonfile ) as any
101
105
let dependencies = obj . dependencies as { [ key : string ] : string }
@@ -118,8 +122,8 @@ export function getVersion(requirement: string, versions: string[], latest?: str
118
122
*/
119
123
export async function untar ( dest : string , tarfile : string , strip = 1 ) : Promise < void > {
120
124
if ( ! fs . existsSync ( tarfile ) ) throw new Error ( `${ tarfile } not exists` )
121
- fs . rmSync ( dest , { recursive : true , force : true } )
122
- fs . mkdirSync ( dest , { recursive : true } )
125
+ await promisify ( fs . rm ) ( dest , { recursive : true , force : true } )
126
+ await promisify ( fs . mkdir ) ( dest , { recursive : true } )
123
127
await new Promise < void > ( ( resolve , reject ) => {
124
128
const input = createReadStream ( tarfile )
125
129
input . on ( 'error' , reject )
0 commit comments