1
1
import * as path from 'path' ;
2
2
import * as fs from 'fs' ;
3
3
import * as cp from 'child_process' ;
4
- import * as parseSemver from 'parse-semver' ;
5
- import { CancellationToken , log } from './util' ;
4
+ import parseSemver from 'parse-semver' ;
5
+ import { CancellationToken , log , nonnull } from './util' ;
6
6
7
7
const exists = ( file : string ) =>
8
8
fs . promises . stat ( file ) . then (
@@ -30,7 +30,7 @@ function exec(
30
30
cancellationToken ?: CancellationToken
31
31
) : Promise < { stdout : string ; stderr : string } > {
32
32
return new Promise ( ( c , e ) => {
33
- let disposeCancellationListener : Function = null ;
33
+ let disposeCancellationListener : Function | null = null ;
34
34
35
35
const child = cp . exec ( command , { ...options , encoding : 'utf8' } as any , ( err , stdout : string , stderr : string ) => {
36
36
if ( disposeCancellationListener ) {
@@ -45,22 +45,21 @@ function exec(
45
45
} ) ;
46
46
47
47
if ( cancellationToken ) {
48
- disposeCancellationListener = cancellationToken . subscribe ( err => {
48
+ disposeCancellationListener = cancellationToken . subscribe ( ( err : any ) => {
49
49
child . kill ( ) ;
50
50
e ( err ) ;
51
51
} ) ;
52
52
}
53
53
} ) ;
54
54
}
55
55
56
- function checkNPM ( cancellationToken ?: CancellationToken ) : Promise < void > {
57
- return exec ( 'npm -v' , { } , cancellationToken ) . then ( ( { stdout } ) => {
58
- const version = stdout . trim ( ) ;
56
+ async function checkNPM ( cancellationToken ?: CancellationToken ) : Promise < void > {
57
+ const { stdout } = await exec ( 'npm -v' , { } , cancellationToken ) ;
58
+ const version = stdout . trim ( ) ;
59
59
60
- if ( / ^ 3 \. 7 \. [ 0 1 2 3 ] $ / . test ( version ) ) {
61
- return Promise . reject ( `npm@${ version } doesn't work with vsce. Please update npm: npm install -g npm` ) ;
62
- }
63
- } ) ;
60
+ if ( / ^ 3 \. 7 \. [ 0 1 2 3 ] $ / . test ( version ) ) {
61
+ throw new Error ( `npm@${ version } doesn't work with vsce. Please update npm: npm install -g npm` ) ;
62
+ }
64
63
}
65
64
66
65
function getNpmDependencies ( cwd : string ) : Promise < string [ ] > {
@@ -174,10 +173,10 @@ async function getYarnProductionDependencies(cwd: string, packagedDependencies?:
174
173
175
174
let result = trees
176
175
. map ( tree => asYarnDependency ( path . join ( cwd , 'node_modules' ) , tree , ! usingPackagedDependencies ) )
177
- . filter ( dep => ! ! dep ) ;
176
+ . filter ( nonnull ) ;
178
177
179
178
if ( usingPackagedDependencies ) {
180
- result = selectYarnDependencies ( result , packagedDependencies ) ;
179
+ result = selectYarnDependencies ( result , packagedDependencies ! ) ;
181
180
}
182
181
183
182
return result ;
0 commit comments