1- import { any , isEmpty , replace , split } from 'ramda' ;
1+ import { any , isEmpty , replace } from 'ramda' ;
22
33import { JSONObject } from '../types' ;
44import { SpawnError , spawnProcess } from '../utils' ;
@@ -20,6 +20,18 @@ export class NPM implements Packager {
2020 return true ;
2121 }
2222
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+
2335 getProdDependencies ( cwd : string , depth : number ) {
2436 // Get first level dependency graph
2537 const command = / ^ w i n / . test ( process . platform ) ? 'npm.cmd' : 'npm' ;
@@ -44,7 +56,7 @@ export class NPM implements Packager {
4456 } catch ( err ) {
4557 if ( err instanceof SpawnError ) {
4658 // 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' ) ?? [ ] ;
4860 const failed = errors . reduce ( ( f , error ) => {
4961 if ( f ) {
5062 return true ;
@@ -64,15 +76,6 @@ export class NPM implements Packager {
6476 }
6577 }
6678
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-
7679 /**
7780 * We should not be modifying 'package-lock.json'
7881 * because this file should be treated as internal to npm.
@@ -82,7 +85,7 @@ export class NPM implements Packager {
8285 */
8386 rebaseLockfile ( pathToPackageRoot : string , lockfile : JSONObject ) {
8487 if ( lockfile . version ) {
85- lockfile . version = this . _rebaseFileReferences ( pathToPackageRoot , lockfile . version ) ;
88+ lockfile . version = this . rebaseFileReferences ( pathToPackageRoot , lockfile . version ) ;
8689 }
8790
8891 if ( lockfile . dependencies ) {
@@ -117,4 +120,13 @@ export class NPM implements Packager {
117120 spawnProcess ( command , args , { cwd } ) ;
118121 } ) ;
119122 }
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+ }
120132}
0 commit comments