Skip to content

Commit a342189

Browse files
alan-agius4vikerman
authored andcommitted
fix(@angular/cli): ng version should report if ivy is enabled
Closes: #14491
1 parent cd3e2f7 commit a342189

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import { JsonParseMode, isJsonObject, parseJson } from '@angular-devkit/core';
89
import * as child_process from 'child_process';
910
import * as fs from 'fs';
1011
import * as path from 'path';
@@ -21,7 +22,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {
2122
let projPkg;
2223
try {
2324
projPkg = require(path.resolve(this.workspace.root, 'package.json'));
24-
} catch (exception) {
25+
} catch {
2526
projPkg = undefined;
2627
}
2728

@@ -137,6 +138,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {
137138
Angular CLI: ${ngCliVersion}
138139
Node: ${process.versions.node}
139140
OS: ${process.platform} ${process.arch}
141+
140142
Angular: ${angularCoreVersion}
141143
... ${angularSameAsCore
142144
.reduce<string[]>((acc, name) => {
@@ -154,6 +156,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {
154156
return acc;
155157
}, [])
156158
.join('\n... ')}
159+
Ivy Workspace: ${projPkg ? this.getIvyWorkspace() : ''}
157160
158161
Package${namePad.slice(7)}Version
159162
-------${namePad.replace(/ /g, '-')}------------------
@@ -176,7 +179,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {
176179

177180
return modulePkg.version;
178181
}
179-
} catch (_) {}
182+
} catch {}
180183

181184
try {
182185
if (cliNodeModules) {
@@ -188,4 +191,22 @@ export class VersionCommand extends Command<VersionCommandSchema> {
188191

189192
return '<error>';
190193
}
194+
195+
private getIvyWorkspace(): string {
196+
try {
197+
const content = fs.readFileSync(path.resolve(this.workspace.root, 'tsconfig.json'), 'utf-8');
198+
const tsConfig = parseJson(content, JsonParseMode.Loose);
199+
if (!isJsonObject(tsConfig)) {
200+
return '<error>';
201+
}
202+
203+
const { angularCompilerOptions } = tsConfig;
204+
205+
return isJsonObject(angularCompilerOptions) && angularCompilerOptions.enableIvy === false
206+
? 'No'
207+
: 'Yes';
208+
} catch {
209+
return '<error>';
210+
}
211+
}
191212
}

tests/legacy-cli/e2e/tests/misc/version.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getGlobalVariable } from '../../utils/env';
12
import { deleteFile } from '../../utils/fs';
23
import { ng } from '../../utils/process';
34

@@ -8,6 +9,17 @@ export default async function() {
89
if (!optionOutput.includes('Angular CLI:')) {
910
throw new Error('version not displayed');
1011
}
12+
13+
const argv = getGlobalVariable('argv');
14+
const veProject = argv['ve'];
15+
16+
const ivyWorkspaceMatch = veProject
17+
? 'Ivy Workspace: No'
18+
: 'Ivy Workspace: Yes';
19+
if (!optionOutput.includes(ivyWorkspaceMatch)) {
20+
throw new Error(`Expected output to contain ${ivyWorkspaceMatch}`);
21+
}
22+
1123
if (commandOutput !== optionOutput) {
1224
throw new Error('version variants have differing output');
1325
}
@@ -17,6 +29,6 @@ export default async function() {
1729
await ng('version');
1830

1931
// Doesn't fail outside a project.
20-
await process.chdir('/');
32+
process.chdir('/');
2133
await ng('version');
2234
}

0 commit comments

Comments
 (0)