@@ -9,6 +9,7 @@ interface INpmOpts {
99
1010export class NodePackageManager implements INodePackageManager {
1111 constructor ( private $childProcess : IChildProcess ,
12+ private $logger : ILogger ,
1213 private $options : IOptions ) { }
1314
1415 public getCache ( ) : string {
@@ -37,15 +38,46 @@ export class NodePackageManager implements INodePackageManager {
3738 }
3839
3940 public install ( packageName : string , pathToSave : string , config ?: any ) : IFuture < any > {
40- if ( this . $options . disableNpmInstall ) {
41- return Future . fromResult ( ) ;
42- }
43- if ( this . $options . ignoreScripts ) {
44- config = config || { } ;
45- config [ "ignore-scripts" ] = true ;
46- }
41+ return ( ( ) => {
42+ if ( this . $options . disableNpmInstall ) {
43+ return ;
44+ }
45+ if ( this . $options . ignoreScripts ) {
46+ config = config || { } ;
47+ config [ "ignore-scripts" ] = true ;
48+ }
4749
48- return this . loadAndExecute ( "install" , [ pathToSave , packageName ] , { config : config } ) ;
50+ try {
51+ return this . loadAndExecute ( "install" , [ pathToSave , packageName ] , { config : config } ) . wait ( ) ;
52+ } catch ( err ) {
53+ if ( err . code === "EPEERINVALID" ) {
54+ // Not installed peer dependencies are treated by npm 2 as errors, but npm 3 treats them as warnings.
55+ // We'll show them as warnings and let the user install them in case they are needed.
56+ // The strucutre of the error object in such case is:
57+ // { [Error: The package @angular /core@2.1.0-beta.0 does not satisfy its siblings' peerDependencies requirements!]
58+ // code: 'EPEERINVALID',
59+ // packageName: '@angular/core',
60+ // packageVersion: '2.1.0-beta.0',
61+ // peersDepending:
62+ // { '@angular /common@2.1.0-beta.0': '2.1.0-beta.0',
63+ // '@angular/compiler@2.1.0-beta.0': '2.1.0-beta.0',
64+ // '@angular/forms@2.1.0-beta.0': '2.1.0-beta.0',
65+ // '@angular/http@2.1.0-beta.0': '2.1.0-beta.0',
66+ // '@angular/platform-browser@2.1.0-beta.0': '2.1.0-beta.0',
67+ // '@angular/platform-browser-dynamic@2.1.0-beta.0': '2.1.0-beta.0',
68+ // '@angular/platform-server@2.1.0-beta.0': '2.1.0-beta.0',
69+ // '@angular/router@3.1.0-beta.0': '2.1.0-beta.0',
70+ // '@ngrx/effects@2.0.0': '^2.0.0',
71+ // '@ngrx/store@2.2.1': '^2.0.0',
72+ // 'ng2-translate@2.5.0': '~2.0.0' } }
73+ this . $logger . warn ( err . message ) ;
74+ this . $logger . trace ( "Required peerDependencies are: " , err . peersDepending ) ;
75+ } else {
76+ // All other errors should be handled by the caller code.
77+ throw err ;
78+ }
79+ }
80+ } ) . future < any > ( ) ( ) ;
4981 }
5082
5183 public uninstall ( packageName : string , config ?: any , path ?: string ) : IFuture < any > {
0 commit comments