Skip to content

Commit

Permalink
fix(@angular/cli): ng version should report if ivy is enabled
Browse files Browse the repository at this point in the history
Closes: #14491
  • Loading branch information
alan-agius4 authored and vikerman committed Nov 27, 2019
1 parent cd3e2f7 commit a342189
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
25 changes: 23 additions & 2 deletions packages/angular/cli/commands/version-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { JsonParseMode, isJsonObject, parseJson } from '@angular-devkit/core';
import * as child_process from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
Expand All @@ -21,7 +22,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {
let projPkg;
try {
projPkg = require(path.resolve(this.workspace.root, 'package.json'));
} catch (exception) {
} catch {
projPkg = undefined;
}

Expand Down Expand Up @@ -137,6 +138,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {
Angular CLI: ${ngCliVersion}
Node: ${process.versions.node}
OS: ${process.platform} ${process.arch}
Angular: ${angularCoreVersion}
... ${angularSameAsCore
.reduce<string[]>((acc, name) => {
Expand All @@ -154,6 +156,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {
return acc;
}, [])
.join('\n... ')}
Ivy Workspace: ${projPkg ? this.getIvyWorkspace() : ''}
Package${namePad.slice(7)}Version
-------${namePad.replace(/ /g, '-')}------------------
Expand All @@ -176,7 +179,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {

return modulePkg.version;
}
} catch (_) {}
} catch {}

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

return '<error>';
}

private getIvyWorkspace(): string {
try {
const content = fs.readFileSync(path.resolve(this.workspace.root, 'tsconfig.json'), 'utf-8');
const tsConfig = parseJson(content, JsonParseMode.Loose);
if (!isJsonObject(tsConfig)) {
return '<error>';
}

const { angularCompilerOptions } = tsConfig;

return isJsonObject(angularCompilerOptions) && angularCompilerOptions.enableIvy === false
? 'No'
: 'Yes';
} catch {
return '<error>';
}
}
}
14 changes: 13 additions & 1 deletion tests/legacy-cli/e2e/tests/misc/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getGlobalVariable } from '../../utils/env';
import { deleteFile } from '../../utils/fs';
import { ng } from '../../utils/process';

Expand All @@ -8,6 +9,17 @@ export default async function() {
if (!optionOutput.includes('Angular CLI:')) {
throw new Error('version not displayed');
}

const argv = getGlobalVariable('argv');
const veProject = argv['ve'];

const ivyWorkspaceMatch = veProject
? 'Ivy Workspace: No'
: 'Ivy Workspace: Yes';
if (!optionOutput.includes(ivyWorkspaceMatch)) {
throw new Error(`Expected output to contain ${ivyWorkspaceMatch}`);
}

if (commandOutput !== optionOutput) {
throw new Error('version variants have differing output');
}
Expand All @@ -17,6 +29,6 @@ export default async function() {
await ng('version');

// Doesn't fail outside a project.
await process.chdir('/');
process.chdir('/');
await ng('version');
}

0 comments on commit a342189

Please sign in to comment.