Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>';
}
}
}
28 changes: 13 additions & 15 deletions packages/angular/cli/utilities/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
JsonObject,
JsonParseMode,
experimental,
isJsonObject,
normalize,
parseJson,
parseJsonAst,
Expand Down Expand Up @@ -213,7 +214,7 @@ export function migrateLegacyGlobalConfig(): boolean {
if (existsSync(legacyGlobalConfigPath)) {
const content = readFileSync(legacyGlobalConfigPath, 'utf-8');
const legacy = parseJson(content, JsonParseMode.Loose);
if (!legacy || typeof legacy != 'object' || Array.isArray(legacy)) {
if (!isJsonObject(legacy)) {
return false;
}

Expand All @@ -224,16 +225,13 @@ export function migrateLegacyGlobalConfig(): boolean {
cli['packageManager'] = legacy.packageManager;
}

if (legacy.defaults && typeof legacy.defaults == 'object' && !Array.isArray(legacy.defaults)
&& legacy.defaults.schematics && typeof legacy.defaults.schematics == 'object'
&& !Array.isArray(legacy.defaults.schematics)
&& typeof legacy.defaults.schematics.collection == 'string') {
if (isJsonObject(legacy.defaults)
&& isJsonObject(legacy.defaults.schematics)
&& typeof legacy.defaults.schematics.collection == 'string') {
cli['defaultCollection'] = legacy.defaults.schematics.collection;
}

if (legacy.warnings && typeof legacy.warnings == 'object'
&& !Array.isArray(legacy.warnings)) {

if (isJsonObject(legacy.warnings)) {
const warnings: JsonObject = {};
if (typeof legacy.warnings.versionMismatch == 'boolean') {
warnings['versionMismatch'] = legacy.warnings.versionMismatch;
Expand Down Expand Up @@ -265,7 +263,7 @@ function getLegacyPackageManager(): string | null {
const content = readFileSync(legacyGlobalConfigPath, 'utf-8');

const legacy = parseJson(content, JsonParseMode.Loose);
if (!legacy || typeof legacy != 'object' || Array.isArray(legacy)) {
if (!isJsonObject(legacy)) {
return null;
}

Expand Down Expand Up @@ -294,7 +292,7 @@ export async function getSchematicDefaults(
result = { ...result, ...(schematicObject as {}) };
}
const collectionObject = workspace.getSchematics()[collection];
if (typeof collectionObject == 'object' && !Array.isArray(collectionObject)) {
if (isJsonObject(collectionObject)) {
result = { ...result, ...(collectionObject[schematic] as {}) };
}

Expand All @@ -309,7 +307,7 @@ export async function getSchematicDefaults(
result = { ...result, ...(schematicObject as {}) };
}
const collectionObject = workspace.getSchematics()[collection];
if (typeof collectionObject == 'object' && !Array.isArray(collectionObject)) {
if (isJsonObject(collectionObject)) {
result = { ...result, ...(collectionObject[schematic] as {}) };
}
}
Expand All @@ -321,7 +319,7 @@ export async function getSchematicDefaults(
result = { ...result, ...(schematicObject as {}) };
}
const collectionObject = workspace.getProjectSchematics(project)[collection];
if (typeof collectionObject == 'object' && !Array.isArray(collectionObject)) {
if (isJsonObject(collectionObject)) {
result = { ...result, ...(collectionObject[schematic] as {}) };
}
}
Expand All @@ -337,7 +335,7 @@ export async function isWarningEnabled(warning: string): Promise<boolean> {
const project = getProjectByCwd(workspace);
if (project && workspace.getProjectCli(project)) {
const warnings = workspace.getProjectCli(project)['warnings'];
if (typeof warnings == 'object' && !Array.isArray(warnings)) {
if (isJsonObject(warnings)) {
const value = warnings[warning];
if (typeof value == 'boolean') {
return value;
Expand All @@ -346,7 +344,7 @@ export async function isWarningEnabled(warning: string): Promise<boolean> {
}
if (workspace.getCli()) {
const warnings = workspace.getCli()['warnings'];
if (typeof warnings == 'object' && !Array.isArray(warnings)) {
if (isJsonObject(warnings)) {
const value = warnings[warning];
if (typeof value == 'boolean') {
return value;
Expand All @@ -358,7 +356,7 @@ export async function isWarningEnabled(warning: string): Promise<boolean> {
workspace = await getWorkspace('global');
if (workspace && workspace.getCli()) {
const warnings = workspace.getCli()['warnings'];
if (typeof warnings == 'object' && !Array.isArray(warnings)) {
if (isJsonObject(warnings)) {
const value = warnings[warning];
if (typeof value == 'boolean') {
return value;
Expand Down
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');
}