@@ -2,23 +2,59 @@ const Task = require('ember-cli/lib/models/task');
2
2
import * as chalk from 'chalk' ;
3
3
import { exec } from 'child_process' ;
4
4
5
+ function removeFromArray ( array : any [ ] , item : any ) {
6
+ const itemIndex = array . indexOf ( item ) ;
7
+ if ( itemIndex !== - 1 ) {
8
+ array . splice ( itemIndex , 1 ) ;
9
+ }
10
+ }
5
11
6
12
export default Task . extend ( {
7
13
run : function ( ) {
8
14
const ui = this . ui ;
15
+ let PATH : string ;
9
16
10
17
return new Promise ( function ( resolve , reject ) {
11
18
ui . writeLine ( chalk . green ( 'Installing packages for tooling via npm.' ) ) ;
12
- exec ( 'npm install' ,
13
- ( err : NodeJS . ErrnoException , stdout : string , stderr : string ) => {
14
- if ( err ) {
15
- ui . writeLine ( stderr ) ;
16
- ui . writeLine ( chalk . red ( 'Package install failed, see above.' ) ) ;
17
- reject ( ) ;
18
- } else {
19
- ui . writeLine ( chalk . green ( 'Installed packages for tooling via npm.' ) ) ;
20
- resolve ( ) ;
21
- }
19
+ // remove from PATH:
20
+ // - absolute path to projet's node_modules
21
+ // - relative path to projet's node_modules (linux and windows)
22
+ exec ( 'npm bin' , ( err : NodeJS . ErrnoException , stdout : string , stderr : string ) => {
23
+ if ( err ) {
24
+ ui . writeLine ( stderr ) ;
25
+ ui . writeLine ( chalk . red ( 'Package install failed, see above.' ) ) ;
26
+ reject ( ) ;
27
+ } else {
28
+ const absoluteProjectNodeModulesPath = stdout . replace ( / ( \r | \n ) / , '' ) ;
29
+ const pathArr = process . env . PATH . split ( ':' ) ;
30
+ removeFromArray ( pathArr , absoluteProjectNodeModulesPath ) ;
31
+ removeFromArray ( pathArr , 'node_modules/.bin' ) ;
32
+ removeFromArray ( pathArr , 'node_modules\.bin' ) ;
33
+ PATH = pathArr . join ( ':' ) ;
34
+ resolve ( ) ;
35
+ }
36
+ } ) ;
37
+ } )
38
+ . then ( ( ) => {
39
+ return new Promise ( function ( resolve , reject ) {
40
+ const options = {
41
+ env : {
42
+ PATH : PATH
43
+ }
44
+ } ;
45
+ exec (
46
+ 'npm install' ,
47
+ options ,
48
+ ( err : NodeJS . ErrnoException , stdout : string , stderr : string ) => {
49
+ if ( err ) {
50
+ ui . writeLine ( stderr ) ;
51
+ ui . writeLine ( chalk . red ( 'Package install failed, see above.' ) ) ;
52
+ reject ( ) ;
53
+ } else {
54
+ ui . writeLine ( chalk . green ( 'Installed packages for tooling via npm.' ) ) ;
55
+ resolve ( ) ;
56
+ }
57
+ } ) ;
22
58
} ) ;
23
59
} ) ;
24
60
}
0 commit comments