Skip to content

fix(@angular/cli): allow flat modules from Angular RC #4969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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