1+ import bytes from 'bytes'
12import { createHash } from 'crypto'
23import fs , { createReadStream } from 'fs'
3- import bytes from 'bytes'
44import path from 'path'
55import semver from 'semver'
66import tar from 'tar'
77import { URL } from 'url'
8+ import { promisify } from 'util'
89import { CancellationToken , CancellationTokenSource } from 'vscode-languageserver-protocol'
910import download from '../model/download'
1011import fetch , { FetchOptions } from '../model/fetch'
@@ -95,7 +96,10 @@ export function shouldRetry(error: any): boolean {
9596 return false
9697}
9798
98- export function readDependencies ( directory : string ) : { [ key : string ] : string } {
99+ /**
100+ * Production dependencies in directory
101+ */
102+ export function readDependencies ( directory : string ) : Dependencies {
99103 let jsonfile = path . join ( directory , 'package.json' )
100104 let obj = loadJson ( jsonfile ) as any
101105 let dependencies = obj . dependencies as { [ key : string ] : string }
@@ -118,8 +122,8 @@ export function getVersion(requirement: string, versions: string[], latest?: str
118122 */
119123export async function untar ( dest : string , tarfile : string , strip = 1 ) : Promise < void > {
120124 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 } )
123127 await new Promise < void > ( ( resolve , reject ) => {
124128 const input = createReadStream ( tarfile )
125129 input . on ( 'error' , reject )
0 commit comments