Skip to content

Commit be5e2fb

Browse files
clydinKeen Yee Liau
authored andcommitted
fix(@angular/cli): remove redundant typescript/compiler-cli compatibility check
Angular 5.0+ has a full peer dependencies setup (with 6.0+ also having a configurable runtime error check) to ensure that an appropriate version of typescript is available for compilation. Angular CLI 8.0+ does not support Angular versions prior to these and therefore the warning is redundant. For the case where the developer wishes to use an unsupported TypeScript version, the developer would need to adjust two similar but differently name settings in two different configuration files.
1 parent bd6fe98 commit be5e2fb

File tree

10 files changed

+26
-143
lines changed

10 files changed

+26
-143
lines changed

packages/angular/cli/commands/build-impl.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ export class BuildCommand extends ArchitectCommand<BuildCommandSchema> {
1515
public readonly target = 'build';
1616

1717
public async run(options: ArchitectCommandOptions & Arguments) {
18-
// Check Angular and TypeScript versions.
18+
// Check Angular version.
1919
Version.assertCompatibleAngularVersion(this.workspace.root);
20-
Version.assertTypescriptVersion(this.workspace.root);
2120

2221
return this.runArchitectTarget(options);
2322
}

packages/angular/cli/commands/config-impl.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { Schema as ConfigCommandSchema, Value as ConfigCommandSchemaValue } from
3030

3131
const validCliPaths = new Map([
3232
['cli.warnings.versionMismatch', 'boolean'],
33-
['cli.warnings.typescriptMismatch', 'boolean'],
3433
['cli.defaultCollection', 'string'],
3534
['cli.packageManager', 'string'],
3635
]);
@@ -213,6 +212,15 @@ export class ConfigCommand extends Command<ConfigCommandSchema> {
213212
private get(config: experimental.workspace.WorkspaceSchema, options: ConfigCommandSchema) {
214213
let value;
215214
if (options.jsonPath) {
215+
if (options.jsonPath === 'cli.warnings.typescriptMismatch') {
216+
// NOTE: Remove this in 9.0.
217+
this.logger.warn('The "typescriptMismatch" warning has been removed in 8.0.');
218+
// Since there is no actual warning, this value is always false.
219+
this.logger.info('false');
220+
221+
return 0;
222+
}
223+
216224
value = getValueFromPath(config as {} as JsonObject, options.jsonPath);
217225
} else {
218226
value = config;
@@ -235,6 +243,14 @@ export class ConfigCommand extends Command<ConfigCommandSchema> {
235243
if (!options.jsonPath || !options.jsonPath.trim()) {
236244
throw new Error('Invalid Path.');
237245
}
246+
247+
if (options.jsonPath === 'cli.warnings.typescriptMismatch') {
248+
// NOTE: Remove this in 9.0.
249+
this.logger.warn('The "typescriptMismatch" warning has been removed in 8.0.');
250+
251+
return 0;
252+
}
253+
238254
if (options.global
239255
&& !options.jsonPath.startsWith('schematics.')
240256
&& !validCliPaths.has(options.jsonPath)) {

packages/angular/cli/commands/serve-impl.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ export class ServeCommand extends ArchitectCommand<ServeCommandSchema> {
1515
public readonly target = 'serve';
1616

1717
public validate(_options: ArchitectCommandOptions & Arguments) {
18-
// Check Angular and TypeScript versions.
18+
// Check Angular versions.
1919
Version.assertCompatibleAngularVersion(this.workspace.root);
20-
Version.assertTypescriptVersion(this.workspace.root);
2120

2221
return true;
2322
}

packages/angular/cli/lib/config/schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
},
6262
"typescriptMismatch": {
6363
"description": "Show a warning when the TypeScript version is incompatible.",
64-
"type": "boolean"
64+
"type": "boolean",
65+
"x-deprecated": true
6566
}
6667
}
6768
}

packages/angular/cli/upgrade/version.ts

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import { tags, terminal } from '@angular-devkit/core';
1010
import { resolve } from '@angular-devkit/core/node';
1111
import * as path from 'path';
12-
import { SemVer, satisfies } from 'semver';
13-
import { isWarningEnabled } from '../utilities/config';
12+
import { SemVer } from 'semver';
1413

1514

1615
export class Version {
@@ -110,67 +109,4 @@ export class Version {
110109
}
111110
}
112111

113-
static assertTypescriptVersion(projectRoot: string) {
114-
if (!isWarningEnabled('typescriptMismatch')) {
115-
return;
116-
}
117-
118-
let compilerVersion: string;
119-
let tsVersion: string;
120-
let compilerTypeScriptPeerVersion: string;
121-
try {
122-
const resolveOptions = {
123-
basedir: projectRoot,
124-
checkGlobal: false,
125-
checkLocal: true,
126-
};
127-
const compilerPackagePath = resolve('@angular/compiler-cli/package.json', resolveOptions);
128-
const typescriptProjectPath = resolve('typescript', resolveOptions);
129-
const compilerPackageInfo = require(compilerPackagePath);
130-
131-
compilerVersion = compilerPackageInfo['version'];
132-
compilerTypeScriptPeerVersion = compilerPackageInfo['peerDependencies']['typescript'];
133-
tsVersion = require(typescriptProjectPath).version;
134-
} catch {
135-
console.error(terminal.bold(terminal.red(tags.stripIndents`
136-
Versions of @angular/compiler-cli and typescript could not be determined.
137-
The most common reason for this is a broken npm install.
138-
139-
Please make sure your package.json contains both @angular/compiler-cli and typescript in
140-
devDependencies, then delete node_modules and package-lock.json (if you have one) and
141-
run npm install again.
142-
`)));
143-
process.exit(2);
144-
145-
return;
146-
}
147-
148-
// These versions do not have accurate typescript peer dependencies
149-
const versionCombos = [
150-
{ compiler: '>=2.3.1 <3.0.0', typescript: '>=2.0.2 <2.3.0' },
151-
{ compiler: '>=4.0.0-beta.0 <5.0.0', typescript: '>=2.1.0 <2.4.0' },
152-
{ compiler: '5.0.0-beta.0 - 5.0.0-rc.2', typescript: '>=2.4.2 <2.5.0' },
153-
];
154-
155-
let currentCombo = versionCombos.find((combo) => satisfies(compilerVersion, combo.compiler));
156-
if (!currentCombo && compilerTypeScriptPeerVersion) {
157-
currentCombo = { compiler: compilerVersion, typescript: compilerTypeScriptPeerVersion };
158-
}
159-
160-
if (currentCombo && !satisfies(tsVersion, currentCombo.typescript)) {
161-
// First line of warning looks weird being split in two, disable tslint for it.
162-
console.error((terminal.yellow('\n' + tags.stripIndent`
163-
@angular/compiler-cli@${compilerVersion} requires typescript@'${
164-
currentCombo.typescript}' but ${tsVersion} was found instead.
165-
Using this version can result in undefined behaviour and difficult to debug problems.
166-
167-
Please run the following command to install a compatible version of TypeScript.
168-
169-
npm install typescript@"${currentCombo.typescript}"
170-
171-
To disable this warning run "ng config cli.warnings.typescriptMismatch false".
172-
` + '\n')));
173-
}
174-
}
175-
176112
}

packages/angular/cli/utilities/config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ export function migrateLegacyGlobalConfig(): boolean {
221221
if (typeof legacy.warnings.versionMismatch == 'boolean') {
222222
warnings['versionMismatch'] = legacy.warnings.versionMismatch;
223223
}
224-
if (typeof legacy.warnings.typescriptMismatch == 'boolean') {
225-
warnings['typescriptMismatch'] = legacy.warnings.typescriptMismatch;
226-
}
227224

228225
if (Object.getOwnPropertyNames(warnings).length > 0) {
229226
cli['warnings'] = warnings;

packages/schematics/angular/migrations/update-6/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ function extractCliConfig(config: CliConfig): JsonObject | null {
145145
...{ versionMismatch: config.warnings.versionMismatch },
146146
};
147147
}
148-
if (config.warnings.typescriptMismatch !== undefined) {
149-
newConfig.warnings = {
150-
...((newConfig.warnings as JsonObject | null) || {}),
151-
...{ typescriptMismatch: config.warnings.typescriptMismatch },
152-
};
153-
}
154148
}
155149

156150
return Object.getOwnPropertyNames(newConfig).length == 0 ? null : newConfig;

tests/angular_devkit/core/json/schema/serializers/schema_benchmark.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,6 @@
586586
"description": "Show a warning when the global version is newer than the local one.",
587587
"type": "boolean",
588588
"default": true
589-
},
590-
"typescriptMismatch": {
591-
"description": "Show a warning when the TypeScript version is incompatible",
592-
"type": "boolean",
593-
"default": true
594589
}
595590
}
596591
}

tests/legacy-cli/e2e/tests/commands/config/config-set.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {ng} from '../../../utils/process';
2-
import {expectToFail} from '../../../utils/utils';
1+
import { ng } from '../../../utils/process';
2+
import { expectToFail } from '../../../utils/utils';
33

44
export default function() {
55
return Promise.resolve()
66
.then(() => expectToFail(() => ng('config', 'cli.warnings.zzzz')))
7-
.then(() => ng('config', 'cli.warnings.typescriptMismatch' , 'false'))
8-
.then(() => ng('config', 'cli.warnings.typescriptMismatch'))
7+
.then(() => ng('config', 'cli.warnings.versionMismatch' , 'false'))
8+
.then(() => ng('config', 'cli.warnings.versionMismatch'))
99
.then(({ stdout }) => {
1010
if (!stdout.match(/false/)) {
1111
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);

tests/legacy-cli/e2e/tests/misc/typescript-warning.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)