Skip to content

Commit

Permalink
fix(@angular/cli): allow flat modules from Angular RC (#4969)
Browse files Browse the repository at this point in the history
The resource of context modules is in a different path.
  • Loading branch information
hansl authored Feb 23, 2017
1 parent b6893d0 commit a537dce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/@angular/cli/upgrade/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export class Version {
if (v.isLocal()) {
console.warn(yellow('Using a local version of angular. Proceeding with care...'));
} else {
if (!v.isGreaterThanOrEqualTo(new SemVer('2.3.1'))) {
// Check if major is not 0, so that we stay compatible with local compiled versions
// of angular.
if (!v.isGreaterThanOrEqualTo(new SemVer('2.3.1')) && v.major != 0) {
console.error(bold(red(stripIndents`
This version of CLI is only compatible with angular version 2.3.1 or better. Please
upgrade your angular version, e.g. by running:
Expand Down
17 changes: 15 additions & 2 deletions packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,26 @@ export class AotPlugin implements Tapable {

// Add lazy modules to the context module for @angular/core/src/linker
compiler.plugin('context-module-factory', (cmf: any) => {
const angularCorePackagePath = require.resolve('@angular/core/package.json');
const angularCorePackageJson = require(angularCorePackagePath);
const angularCoreModulePath = path.resolve(path.dirname(angularCorePackagePath),
angularCorePackageJson['module']);
// Pick the last part after the last node_modules instance. We do this to let people have
// a linked @angular/core or cli which would not be under the same path as the project
// being built.
const angularCoreModuleDir = path.dirname(angularCoreModulePath).split(/node_modules/).pop();

cmf.plugin('after-resolve', (result: any, callback: (err?: any, request?: any) => void) => {
if (!result) {
return callback();
}

// alter only request from @angular/core/src/linker
if (!result.resource.endsWith(path.join('@angular/core/src/linker'))) {
// Alter only request from Angular;
// @angular/core/src/linker matches for 2.*.*,
// The other logic is for flat modules and requires reading the package.json of angular
// (see above).
if (!result.resource.endsWith(path.join('@angular/core/src/linker'))
&& (angularCoreModuleDir && !result.resource.endsWith(angularCoreModuleDir))) {
return callback(null, result);
}

Expand Down

0 comments on commit a537dce

Please sign in to comment.