File tree Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -59,9 +59,28 @@ if (process.env['NG_CLI_PROFILING']) {
59
59
process . on ( 'uncaughtException' , ( ) => exitHandler ( { exit : true } ) ) ;
60
60
}
61
61
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
+
62
73
let cli ;
63
74
try {
64
- const projectLocalCli = require . resolve ( '@angular/cli' , { paths : [ process . cwd ( ) ] } ) ;
75
+ const projectLocalCli = require . resolve (
76
+ '@angular/cli' ,
77
+ { paths : [ path . join ( process . cwd ( ) , 'node_modules' ) , process . cwd ( ) ] } ,
78
+ ) ;
79
+
80
+ const isGlobal = isInside ( path . join ( __dirname , '..' ) , projectLocalCli ) ;
81
+ if ( isGlobal ) {
82
+ throw new Error ( ) ;
83
+ }
65
84
66
85
// This was run from a global, check local version.
67
86
const globalVersion = new SemVer ( packageJson [ 'version' ] ) ;
Original file line number Diff line number Diff line change @@ -33,9 +33,30 @@ export class Version {
33
33
static assertCompatibleAngularVersion ( projectRoot : string ) {
34
34
let angularPkgJson ;
35
35
let rxjsPkgJson ;
36
+
37
+ const isInside = ( base : string , potential : string ) : boolean => {
38
+ const absoluteBase = path . resolve ( base ) ;
39
+ const absolutePotential = path . resolve ( potential ) ;
40
+ const relativePotential = path . relative ( absoluteBase , absolutePotential ) ;
41
+ if ( ! relativePotential . startsWith ( '..' ) && ! path . isAbsolute ( relativePotential ) ) {
42
+ return true ;
43
+ }
44
+
45
+ return false ;
46
+ } ;
47
+
36
48
try {
37
- angularPkgJson = requireProjectModule ( projectRoot , '@angular/core/package.json' ) ;
38
- rxjsPkgJson = requireProjectModule ( projectRoot , 'rxjs/package.json' ) ;
49
+ const resolveOptions = { paths : [ path . join ( projectRoot , 'node_modules' ) , projectRoot ] } ;
50
+ const angularPackagePath = require . resolve ( '@angular/core/package.json' , resolveOptions ) ;
51
+ const rxjsPackagePath = require . resolve ( 'rxjs/package.json' , resolveOptions ) ;
52
+
53
+ if ( ! isInside ( projectRoot , angularPackagePath )
54
+ || ! isInside ( projectRoot , rxjsPackagePath ) ) {
55
+ throw new Error ( ) ;
56
+ }
57
+
58
+ angularPkgJson = require ( angularPackagePath ) ;
59
+ rxjsPkgJson = require ( rxjsPackagePath ) ;
39
60
} catch {
40
61
console . error ( terminal . bold ( terminal . red ( tags . stripIndents `
41
62
You seem to not be depending on "@angular/core" and/or "rxjs". This is an error.
You can’t perform that action at this time.
0 commit comments