From 352b43e0aa5c455dd081eb5888103e486334f897 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Tue, 5 Sep 2017 16:06:03 +0100 Subject: [PATCH] fix(@angular/cli): use require for @angular/core check This should help with linked node_module scenarios. --- packages/@angular/cli/upgrade/version.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/@angular/cli/upgrade/version.ts b/packages/@angular/cli/upgrade/version.ts index a25a838120e0..15b4a20c4367 100644 --- a/packages/@angular/cli/upgrade/version.ts +++ b/packages/@angular/cli/upgrade/version.ts @@ -6,6 +6,7 @@ import * as path from 'path'; import {CliConfig} from '../models/config'; import {findUp} from '../utilities/find-up'; +import {requireProjectModule} from '../utilities/require-project-module'; const resolve = require('resolve'); @@ -83,10 +84,15 @@ export class Version { } static assertAngularVersionIs2_3_1OrHigher(projectRoot: string) { - const angularCorePath = path.join(projectRoot, 'node_modules/@angular/core'); - const pkgJson = existsSync(angularCorePath) - ? JSON.parse(readFileSync(path.join(angularCorePath, 'package.json'), 'utf8')) - : null; + let pkgJson; + try { + pkgJson = requireProjectModule(projectRoot, '@angular/core/package.json'); + } catch (_) { + console.error(bold(red(stripIndents` + You seem to not be depending on "@angular/core". This is an error. + `))); + process.exit(2); + } // Just check @angular/core. if (pkgJson && pkgJson['version']) {