6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
import 'symbol-observable' ;
9
- const isWarningEnabled = require ( '../utilities/config' ) . isWarningEnabled ;
9
+ // symbol polyfill must go first
10
+ // tslint:disable-next-line:ordered-imports import-groups
11
+ import { tags , terminal } from '@angular-devkit/core' ;
12
+ import { resolve } from '@angular-devkit/core/node' ;
13
+ import * as fs from 'fs' ;
14
+ import * as path from 'path' ;
15
+ import { SemVer } from 'semver' ;
16
+ import { isWarningEnabled } from '../utilities/config' ;
10
17
11
- const fs = require ( 'fs' ) ;
12
18
const packageJson = require ( '../package.json' ) ;
13
- const path = require ( 'path' ) ;
14
- const stripIndents = require ( '@angular-devkit/core' ) . tags . stripIndents ;
15
- const yellow = require ( '@angular-devkit/core' ) . terminal . yellow ;
16
- const SemVer = require ( 'semver' ) . SemVer ;
17
19
18
20
function _fromPackageJson ( cwd ?: string ) {
19
21
cwd = cwd || process . cwd ( ) ;
@@ -45,8 +47,10 @@ if (process.env['NG_CLI_PROFILING']) {
45
47
const exitHandler = ( options : { cleanup ?: boolean , exit ?: boolean } ) => {
46
48
if ( options . cleanup ) {
47
49
const cpuProfile = profiler . stopProfiling ( ) ;
48
- fs . writeFileSync ( path . resolve ( process . cwd ( ) , process . env . NG_CLI_PROFILING ) + '.cpuprofile' ,
49
- JSON . stringify ( cpuProfile ) ) ;
50
+ fs . writeFileSync (
51
+ path . resolve ( process . cwd ( ) , process . env . NG_CLI_PROFILING || '' ) + '.cpuprofile' ,
52
+ JSON . stringify ( cpuProfile ) ,
53
+ ) ;
50
54
}
51
55
52
56
if ( options . exit ) {
@@ -59,45 +63,33 @@ if (process.env['NG_CLI_PROFILING']) {
59
63
process . on ( 'uncaughtException' , ( ) => exitHandler ( { exit : true } ) ) ;
60
64
}
61
65
62
- const isInside = ( base : string , potential : string ) : boolean => {
63
- const absoluteBase = path . resolve ( base ) ;
64
- const absolutePotential = path . resolve ( potential ) ;
65
- const relativePotential = path . relative ( absoluteBase , absolutePotential ) ;
66
- if ( ! relativePotential . startsWith ( '..' ) && ! path . isAbsolute ( relativePotential ) ) {
67
- return true ;
68
- }
69
-
70
- return false ;
71
- } ;
72
-
73
66
let cli ;
74
67
try {
75
- const projectLocalCli = require . resolve (
68
+ const projectLocalCli = resolve (
76
69
'@angular/cli' ,
77
- { paths : [ path . join ( process . cwd ( ) , 'node_modules' ) , process . cwd ( ) ] } ,
70
+ {
71
+ checkGlobal : false ,
72
+ basedir : process . cwd ( ) ,
73
+ preserveSymlinks : true ,
74
+ } ,
78
75
) ;
79
76
80
- const isGlobal = isInside ( path . join ( __dirname , '..' ) , projectLocalCli ) ;
81
- if ( isGlobal ) {
82
- throw new Error ( ) ;
83
- }
84
-
85
77
// This was run from a global, check local version.
86
78
const globalVersion = new SemVer ( packageJson [ 'version' ] ) ;
87
79
let localVersion ;
88
80
let shouldWarn = false ;
89
81
90
82
try {
91
83
localVersion = _fromPackageJson ( ) ;
92
- shouldWarn = localVersion && globalVersion . compare ( localVersion ) > 0 ;
84
+ shouldWarn = localVersion != null && globalVersion . compare ( localVersion ) > 0 ;
93
85
} catch ( e ) {
94
86
// eslint-disable-next-line no-console
95
87
console . error ( e ) ;
96
88
shouldWarn = true ;
97
89
}
98
90
99
91
if ( shouldWarn && isWarningEnabled ( 'versionMismatch' ) ) {
100
- const warning = yellow ( stripIndents `
92
+ const warning = terminal . yellow ( tags . stripIndents `
101
93
Your global Angular CLI version (${ globalVersion } ) is greater than your local
102
94
version (${ localVersion } ). The local Angular CLI version is used.
103
95
0 commit comments