Skip to content

Commit 34047b1

Browse files
committedNov 8, 2021
fix(@angular/cli): avoid redirecting @angular/core in Angular migrations
Files should not redirect `@angular/core` and instead use the direct dependency of the `@schematics/angular` package. This allows old major version migrations to continue to function even though the latest major version may have breaking changes in `@angular/core`. (cherry picked from commit 4a5ca16)
1 parent facb5d8 commit 34047b1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed
 

Diff for: ‎packages/angular/cli/models/schematic-engine-host.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,21 @@ function wrap(
129129
// Provide compatibility modules for older versions of @angular/cdk
130130
return legacyModules[id];
131131
} else if (id.startsWith('@angular-devkit/') || id.startsWith('@schematics/')) {
132-
// Resolve from inside the `@angular/cli` project
133-
const packagePath = require.resolve(id);
132+
// Files should not redirect `@angular/core` and instead use the direct
133+
// dependency if available. This allows old major version migrations to continue to function
134+
// even though the latest major version may have breaking changes in `@angular/core`.
135+
if (id.startsWith('@angular-devkit/core')) {
136+
try {
137+
return schematicRequire(id);
138+
} catch (e) {
139+
if (e.code !== 'MODULE_NOT_FOUND') {
140+
throw e;
141+
}
142+
}
143+
}
134144

135-
return hostRequire(packagePath);
145+
// Resolve from inside the `@angular/cli` project
146+
return hostRequire(id);
136147
} else if (id.startsWith('.') || id.startsWith('@angular/cdk')) {
137148
// Wrap relative files inside the schematic collection
138149
// Also wrap `@angular/cdk`, it contains helper utilities that import core schematic packages

0 commit comments

Comments
 (0)
Please sign in to comment.