diff --git a/packages/angular/cli/commands/version-impl.ts b/packages/angular/cli/commands/version-impl.ts index acf6d0d5bdb0..a840cd3955a1 100644 --- a/packages/angular/cli/commands/version-impl.ts +++ b/packages/angular/cli/commands/version-impl.ts @@ -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'; @@ -21,7 +22,7 @@ export class VersionCommand extends Command { let projPkg; try { projPkg = require(path.resolve(this.workspace.root, 'package.json')); - } catch (exception) { + } catch { projPkg = undefined; } @@ -137,6 +138,7 @@ export class VersionCommand extends Command { Angular CLI: ${ngCliVersion} Node: ${process.versions.node} OS: ${process.platform} ${process.arch} + Angular: ${angularCoreVersion} ... ${angularSameAsCore .reduce((acc, name) => { @@ -154,6 +156,7 @@ export class VersionCommand extends Command { return acc; }, []) .join('\n... ')} + Ivy Workspace: ${projPkg ? this.getIvyWorkspace() : ''} Package${namePad.slice(7)}Version -------${namePad.replace(/ /g, '-')}------------------ @@ -176,7 +179,7 @@ export class VersionCommand extends Command { return modulePkg.version; } - } catch (_) {} + } catch {} try { if (cliNodeModules) { @@ -188,4 +191,22 @@ export class VersionCommand extends Command { return ''; } + + 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 ''; + } + + const { angularCompilerOptions } = tsConfig; + + return isJsonObject(angularCompilerOptions) && angularCompilerOptions.enableIvy === false + ? 'No' + : 'Yes'; + } catch { + return ''; + } + } } diff --git a/tests/legacy-cli/e2e/tests/misc/version.ts b/tests/legacy-cli/e2e/tests/misc/version.ts index 121d1aa123e1..09eff96fec9c 100644 --- a/tests/legacy-cli/e2e/tests/misc/version.ts +++ b/tests/legacy-cli/e2e/tests/misc/version.ts @@ -1,3 +1,4 @@ +import { getGlobalVariable } from '../../utils/env'; import { deleteFile } from '../../utils/fs'; import { ng } from '../../utils/process'; @@ -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'); } @@ -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'); }