Skip to content

Commit 6275b49

Browse files
devversionjelbourn
authored andcommitted
fix(schematics): module imports not generated for schematics (#16787)
Currently in some scenarios the CLI project has a different TypeScript version than the `typescript` version used in the `@schematics/angular` package. This causes AST parsing & transformations to be broken due to the shifted values (e.g. in the `SyntaxKind` enum). Previously we solved this by always using the `typescript` version brought in by the `@schematics/angular` package, but this no longer works as of v8.0.0 CLI because the `@schematics/angular` package now vendors `typescript` instead of having an explicit version as dependency. angular/angular-cli@bf1c069
1 parent 3205b31 commit 6275b49

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/cdk/schematics/utils/version-agnostic-typescript.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,21 @@ import {SchematicsException} from '@angular-devkit/schematics';
2626
let ts: typeof typescript;
2727

2828
try {
29-
ts = require('@schematics/angular/node_modules/typescript');
29+
ts = require('@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript');
3030
} catch {
31+
// Fallback for CLI versions before v8.0.0. The TypeScript dependency has been dropped in
32+
// CLI version v8.0.0 but older CLI versions can still run the latest generation schematics.
33+
// See: https://github.com/angular/angular-cli/commit/bf1c069f73c8e3d4f0e8d584cbfb47c408c1730b
3134
try {
32-
ts = require('typescript');
35+
ts = require('@schematics/angular/node_modules/typescript');
3336
} catch {
34-
throw new SchematicsException('Error: Could not find a TypeScript version for the ' +
35-
'schematics. Please report an issue on the Angular Material repository.');
37+
try {
38+
ts = require('typescript');
39+
} catch {
40+
throw new SchematicsException(
41+
'Error: Could not find a TypeScript version for the ' +
42+
'schematics. Please report an issue on the Angular Material repository.');
43+
}
3644
}
3745
}
3846

0 commit comments

Comments
 (0)