1
- import { any , isEmpty , replace , split } from 'ramda' ;
1
+ import { any , isEmpty , replace } from 'ramda' ;
2
2
3
3
import { JSONObject } from '../types' ;
4
4
import { SpawnError , spawnProcess } from '../utils' ;
@@ -20,6 +20,18 @@ export class NPM implements Packager {
20
20
return true ;
21
21
}
22
22
23
+ isManagerInstalled ( cwd : string ) {
24
+ const command = / ^ w i n / . test ( process . platform ) ? 'npm.cmd' : 'npm' ;
25
+ const args = [ '--version' ] ;
26
+
27
+ try {
28
+ spawnProcess ( command , args , { cwd } ) ;
29
+ return true ;
30
+ } catch ( _e ) {
31
+ return false ;
32
+ }
33
+ }
34
+
23
35
getProdDependencies ( cwd : string , depth : number ) {
24
36
// Get first level dependency graph
25
37
const command = / ^ w i n / . test ( process . platform ) ? 'npm.cmd' : 'npm' ;
@@ -44,7 +56,7 @@ export class NPM implements Packager {
44
56
} catch ( err ) {
45
57
if ( err instanceof SpawnError ) {
46
58
// Only exit with an error if we have critical npm errors for 2nd level inside
47
- const errors = split ( '\n' , err . stderr ) ;
59
+ const errors = err . stderr ?. split ( '\n' ) ?? [ ] ;
48
60
const failed = errors . reduce ( ( f , error ) => {
49
61
if ( f ) {
50
62
return true ;
@@ -64,15 +76,6 @@ export class NPM implements Packager {
64
76
}
65
77
}
66
78
67
- _rebaseFileReferences ( pathToPackageRoot : string , moduleVersion : string ) {
68
- if ( / ^ f i l e : [ ^ / ] { 2 } / . test ( moduleVersion ) ) {
69
- const filePath = replace ( / ^ f i l e : / , '' , moduleVersion ) ;
70
- return replace ( / \\ / g, '/' , `file:${ pathToPackageRoot } /${ filePath } ` ) ;
71
- }
72
-
73
- return moduleVersion ;
74
- }
75
-
76
79
/**
77
80
* We should not be modifying 'package-lock.json'
78
81
* because this file should be treated as internal to npm.
@@ -82,7 +85,7 @@ export class NPM implements Packager {
82
85
*/
83
86
rebaseLockfile ( pathToPackageRoot : string , lockfile : JSONObject ) {
84
87
if ( lockfile . version ) {
85
- lockfile . version = this . _rebaseFileReferences ( pathToPackageRoot , lockfile . version ) ;
88
+ lockfile . version = this . rebaseFileReferences ( pathToPackageRoot , lockfile . version ) ;
86
89
}
87
90
88
91
if ( lockfile . dependencies ) {
@@ -117,4 +120,13 @@ export class NPM implements Packager {
117
120
spawnProcess ( command , args , { cwd } ) ;
118
121
} ) ;
119
122
}
123
+
124
+ private rebaseFileReferences ( pathToPackageRoot : string , moduleVersion : string ) {
125
+ if ( / ^ f i l e : [ ^ / ] { 2 } / . test ( moduleVersion ) ) {
126
+ const filePath = replace ( / ^ f i l e : / , '' , moduleVersion ) ;
127
+ return replace ( / \\ / g, '/' , `file:${ pathToPackageRoot } /${ filePath } ` ) ;
128
+ }
129
+
130
+ return moduleVersion ;
131
+ }
120
132
}
0 commit comments