@@ -7,6 +7,34 @@ process.title = 'angular-cli';
7
7
const resolve = require ( 'resolve' ) ;
8
8
const packageJson = require ( '../package.json' ) ;
9
9
const Version = require ( '../upgrade/version' ) . Version ;
10
+ const yellow = require ( 'chalk' ) . yellow ;
11
+ const SemVer = require ( 'semver' ) . SemVer ;
12
+
13
+
14
+ function _fromPackageJson ( cwd ) {
15
+ cwd = cwd || process . cwd ( ) ;
16
+ // Require here so it doesn't involve cost if this function isn't used.
17
+ const { existsSync, readFileSync} = require ( 'fs' ) ;
18
+ const { join, dirname} = require ( 'path' ) ;
19
+
20
+ do {
21
+ const packageJsonPath = join ( cwd , 'node_modules/angular-cli/package.json' ) ;
22
+ if ( existsSync ( packageJsonPath ) ) {
23
+ const content = readFileSync ( packageJsonPath , 'utf-8' ) ;
24
+ if ( content ) {
25
+ const json = JSON . parse ( content ) ;
26
+ if ( json [ 'version' ] ) {
27
+ return new Version ( json [ 'version' ] ) ;
28
+ }
29
+ }
30
+ }
31
+
32
+ // Check the parent.
33
+ cwd = dirname ( cwd ) ;
34
+ } while ( cwd != dirname ( cwd ) ) ;
35
+
36
+ return null ;
37
+ }
10
38
11
39
12
40
resolve ( 'angular-cli' , { basedir : process . cwd ( ) } ,
@@ -22,6 +50,24 @@ resolve('angular-cli', { basedir: process.cwd() },
22
50
// Verify that package's version.
23
51
Version . assertPostWebpackVersion ( ) ;
24
52
53
+ // This was run from a global, check local version.
54
+ const globalVersion = new SemVer ( packageJson [ 'version' ] ) ;
55
+ let localVersion ;
56
+ let shouldWarn = false ;
57
+
58
+ try {
59
+ localVersion = _fromPackageJson ( ) ;
60
+ shouldWarn = localVersion && globalVersion . compare ( localVersion ) > - 1 ;
61
+ } catch ( e ) {
62
+ shouldWarn = true ;
63
+ }
64
+
65
+ if ( shouldWarn ) {
66
+ // eslint-disable no-console
67
+ console . log ( yellow ( `Your global Angular CLI version (${ globalVersion } ) is greater than `
68
+ + `your local version (${ localVersion } ). The local Angular CLI version is used.` ) ) ;
69
+ }
70
+
25
71
// No error implies a projectLocalCli, which will load whatever
26
72
// version of ng-cli you have installed in a local package.json
27
73
cli = require ( projectLocalCli ) ;
@@ -36,7 +82,6 @@ resolve('angular-cli', { basedir: process.cwd() },
36
82
inputStream : process . stdin ,
37
83
outputStream : process . stdout
38
84
} ) . then ( function ( result ) {
39
- var exitCode = typeof result === 'object' ? result . exitCode : result ;
40
- process . exit ( exitCode ) ;
85
+ process . exit ( typeof result === 'object' ? result . exitCode : result ) ;
41
86
} ) ;
42
87
} ) ;
0 commit comments