Skip to content

Commit a537dce

Browse files
authored
fix(@angular/cli): allow flat modules from Angular RC (#4969)
The resource of context modules is in a different path.
1 parent b6893d0 commit a537dce

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/@angular/cli/upgrade/version.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export class Version {
9494
if (v.isLocal()) {
9595
console.warn(yellow('Using a local version of angular. Proceeding with care...'));
9696
} else {
97-
if (!v.isGreaterThanOrEqualTo(new SemVer('2.3.1'))) {
97+
// Check if major is not 0, so that we stay compatible with local compiled versions
98+
// of angular.
99+
if (!v.isGreaterThanOrEqualTo(new SemVer('2.3.1')) && v.major != 0) {
98100
console.error(bold(red(stripIndents`
99101
This version of CLI is only compatible with angular version 2.3.1 or better. Please
100102
upgrade your angular version, e.g. by running:

packages/@ngtools/webpack/src/plugin.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,26 @@ export class AotPlugin implements Tapable {
269269

270270
// Add lazy modules to the context module for @angular/core/src/linker
271271
compiler.plugin('context-module-factory', (cmf: any) => {
272+
const angularCorePackagePath = require.resolve('@angular/core/package.json');
273+
const angularCorePackageJson = require(angularCorePackagePath);
274+
const angularCoreModulePath = path.resolve(path.dirname(angularCorePackagePath),
275+
angularCorePackageJson['module']);
276+
// Pick the last part after the last node_modules instance. We do this to let people have
277+
// a linked @angular/core or cli which would not be under the same path as the project
278+
// being built.
279+
const angularCoreModuleDir = path.dirname(angularCoreModulePath).split(/node_modules/).pop();
280+
272281
cmf.plugin('after-resolve', (result: any, callback: (err?: any, request?: any) => void) => {
273282
if (!result) {
274283
return callback();
275284
}
276285

277-
// alter only request from @angular/core/src/linker
278-
if (!result.resource.endsWith(path.join('@angular/core/src/linker'))) {
286+
// Alter only request from Angular;
287+
// @angular/core/src/linker matches for 2.*.*,
288+
// The other logic is for flat modules and requires reading the package.json of angular
289+
// (see above).
290+
if (!result.resource.endsWith(path.join('@angular/core/src/linker'))
291+
&& (angularCoreModuleDir && !result.resource.endsWith(angularCoreModuleDir))) {
279292
return callback(null, result);
280293
}
281294

0 commit comments

Comments
 (0)