Skip to content

Commit 52c222c

Browse files
clydinhansl
authored andcommitted
refactor(@angular/cli): use compiler-cli peer dep to check typescript
1 parent a394434 commit 52c222c

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

packages/angular/cli/upgrade/version.ts

+22-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { resolve } from '@angular-devkit/core/node';
1111
import * as path from 'path';
1212
import { SemVer, satisfies } from 'semver';
1313
import { isWarningEnabled } from '../utilities/config';
14-
import { requireProjectModule } from '../utilities/require-project-module';
1514

1615

1716
export class Version {
@@ -131,10 +130,23 @@ export class Version {
131130
if (!isWarningEnabled('typescriptMismatch')) {
132131
return;
133132
}
134-
let compilerVersion: string, tsVersion: string;
133+
134+
let compilerVersion: string;
135+
let tsVersion: string;
136+
let compilerTypeScriptPeerVersion: string;
135137
try {
136-
compilerVersion = requireProjectModule(projectRoot, '@angular/compiler-cli').VERSION.full;
137-
tsVersion = requireProjectModule(projectRoot, 'typescript').version;
138+
const resolveOptions = {
139+
basedir: projectRoot,
140+
checkGlobal: false,
141+
checkLocal: true,
142+
};
143+
const compilerPackagePath = resolve('@angular/compiler-cli/package.json', resolveOptions);
144+
const typescriptProjectPath = resolve('typescript', resolveOptions);
145+
const compilerPackageInfo = require(compilerPackagePath);
146+
147+
compilerVersion = compilerPackageInfo['version'];
148+
compilerTypeScriptPeerVersion = compilerPackageInfo['peerDependencies']['typescript'];
149+
tsVersion = require(typescriptProjectPath).version;
138150
} catch {
139151
console.error(terminal.bold(terminal.red(tags.stripIndents`
140152
Versions of @angular/compiler-cli and typescript could not be determined.
@@ -149,18 +161,17 @@ export class Version {
149161
return;
150162
}
151163

164+
// These versions do not have accurate typescript peer dependencies
152165
const versionCombos = [
153166
{ compiler: '>=2.3.1 <3.0.0', typescript: '>=2.0.2 <2.3.0' },
154167
{ compiler: '>=4.0.0-beta.0 <5.0.0', typescript: '>=2.1.0 <2.4.0' },
155-
{ compiler: '>=5.0.0-beta.0 <5.1.0', typescript: '>=2.4.2 <2.5.0' },
156-
{ compiler: '>=5.1.0-beta.0 <5.2.0', typescript: '>=2.4.2 <2.6.0' },
157-
{ compiler: '>=5.2.0-beta.0 <6.0.0', typescript: '>=2.4.2 <2.7.0' },
158-
{ compiler: '>=6.0.0-beta.0 <6.1.0-beta.0', typescript: '>=2.7.0 <2.8.0' },
159-
{ compiler: '>=6.1.0-beta.0 <6.1.0-rc.0', typescript: '>=2.7.2 <2.9.0' },
160-
{ compiler: '>=6.1.0-rc.0 <7.0.0', typescript: '>=2.7.2 <2.10.0' },
168+
{ compiler: '5.0.0-beta.0 - 5.0.0-rc.2', typescript: '>=2.4.2 <2.5.0' },
161169
];
162170

163-
const currentCombo = versionCombos.find((combo) => satisfies(compilerVersion, combo.compiler));
171+
let currentCombo = versionCombos.find((combo) => satisfies(compilerVersion, combo.compiler));
172+
if (!currentCombo && compilerTypeScriptPeerVersion) {
173+
currentCombo = { compiler: compilerVersion, typescript: compilerTypeScriptPeerVersion };
174+
}
164175

165176
if (currentCombo && !satisfies(tsVersion, currentCombo.typescript)) {
166177
// First line of warning looks weird being split in two, disable tslint for it.

packages/angular/cli/utilities/require-project-module.ts

-17
This file was deleted.

0 commit comments

Comments
 (0)