66 * found in the LICENSE file at https://angular.io/license
77 */
88import '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' ;
1017
11- const fs = require ( 'fs' ) ;
1218const 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 ;
1719
1820function _fromPackageJson ( cwd ?: string ) {
1921 cwd = cwd || process . cwd ( ) ;
@@ -45,8 +47,10 @@ if (process.env['NG_CLI_PROFILING']) {
4547 const exitHandler = ( options : { cleanup ?: boolean , exit ?: boolean } ) => {
4648 if ( options . cleanup ) {
4749 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+ ) ;
5054 }
5155
5256 if ( options . exit ) {
@@ -59,45 +63,33 @@ if (process.env['NG_CLI_PROFILING']) {
5963 process . on ( 'uncaughtException' , ( ) => exitHandler ( { exit : true } ) ) ;
6064}
6165
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-
7366let cli ;
7467try {
75- const projectLocalCli = require . resolve (
68+ const projectLocalCli = resolve (
7669 '@angular/cli' ,
77- { paths : [ path . join ( process . cwd ( ) , 'node_modules' ) , process . cwd ( ) ] } ,
70+ {
71+ checkGlobal : false ,
72+ basedir : process . cwd ( ) ,
73+ preserveSymlinks : true ,
74+ } ,
7875 ) ;
7976
80- const isGlobal = isInside ( path . join ( __dirname , '..' ) , projectLocalCli ) ;
81- if ( isGlobal ) {
82- throw new Error ( ) ;
83- }
84-
8577 // This was run from a global, check local version.
8678 const globalVersion = new SemVer ( packageJson [ 'version' ] ) ;
8779 let localVersion ;
8880 let shouldWarn = false ;
8981
9082 try {
9183 localVersion = _fromPackageJson ( ) ;
92- shouldWarn = localVersion && globalVersion . compare ( localVersion ) > 0 ;
84+ shouldWarn = localVersion != null && globalVersion . compare ( localVersion ) > 0 ;
9385 } catch ( e ) {
9486 // eslint-disable-next-line no-console
9587 console . error ( e ) ;
9688 shouldWarn = true ;
9789 }
9890
9991 if ( shouldWarn && isWarningEnabled ( 'versionMismatch' ) ) {
100- const warning = yellow ( stripIndents `
92+ const warning = terminal . yellow ( tags . stripIndents `
10193 Your global Angular CLI version (${ globalVersion } ) is greater than your local
10294 version (${ localVersion } ). The local Angular CLI version is used.
10395
0 commit comments