@@ -10,7 +10,7 @@ import type { Argv } from 'yargs';
10
10
import { CommandModule , CommandModuleImplementation } from '../../command-builder/command-module' ;
11
11
import { colors } from '../../utilities/color' ;
12
12
import { RootCommands } from '../command-config' ;
13
- import { gatherVersionInfo } from './version-info' ;
13
+ import { PackageVersionInfo , gatherVersionInfo } from './version-info' ;
14
14
15
15
/**
16
16
* The Angular CLI logo, displayed as ASCII art.
@@ -67,6 +67,7 @@ export default class VersionCommandModule
67
67
68
68
const {
69
69
cli : { version : ngCliVersion } ,
70
+ framework,
70
71
system : {
71
72
node : { version : nodeVersion , unsupported : unsupportedNodeVersion } ,
72
73
os : { platform : os , architecture : arch } ,
@@ -75,8 +76,13 @@ export default class VersionCommandModule
75
76
packages,
76
77
} = versionInfo ;
77
78
78
- const headerInfo = [
79
- { label : 'Angular CLI' , value : ngCliVersion } ,
79
+ const headerInfo = [ { label : 'Angular CLI' , value : ngCliVersion } ] ;
80
+
81
+ if ( framework . version ) {
82
+ headerInfo . push ( { label : 'Angular' , value : framework . version } ) ;
83
+ }
84
+
85
+ headerInfo . push (
80
86
{
81
87
label : 'Node.js' ,
82
88
value : `${ nodeVersion } ${ unsupportedNodeVersion ? colors . yellow ( ' (Unsupported)' ) : '' } ` ,
@@ -86,7 +92,7 @@ export default class VersionCommandModule
86
92
value : `${ packageManagerName } ${ packageManagerVersion ?? '<error>' } ` ,
87
93
} ,
88
94
{ label : 'Operating System' , value : `${ os } ${ arch } ` } ,
89
- ] ;
95
+ ) ;
90
96
91
97
const maxHeaderLabelLength = Math . max ( ...headerInfo . map ( ( l ) => l . label . length ) ) ;
92
98
@@ -113,38 +119,56 @@ export default class VersionCommandModule
113
119
* @param versions A map of package names to their versions.
114
120
* @returns A string containing the formatted package table.
115
121
*/
116
- private formatPackageTable ( versions : Record < string , string > ) : string {
122
+ private formatPackageTable ( versions : Record < string , PackageVersionInfo > ) : string {
117
123
const versionKeys = Object . keys ( versions ) ;
118
124
if ( versionKeys . length === 0 ) {
119
125
return '' ;
120
126
}
121
127
122
- const nameHeader = 'Package' ;
123
- const versionHeader = 'Version' ;
128
+ const headers = {
129
+ name : 'Package' ,
130
+ installed : 'Installed Version' ,
131
+ requested : 'Requested Version' ,
132
+ } ;
124
133
125
- const maxNameLength = Math . max ( nameHeader . length , ...versionKeys . map ( ( key ) => key . length ) ) ;
126
- const maxVersionLength = Math . max (
127
- versionHeader . length ,
128
- ...versionKeys . map ( ( key ) => versions [ key ] . length ) ,
134
+ const maxNameLength = Math . max ( headers . name . length , ...versionKeys . map ( ( key ) => key . length ) ) ;
135
+ const maxInstalledLength = Math . max (
136
+ headers . installed . length ,
137
+ ...versionKeys . map ( ( key ) => versions [ key ] . installed . length ) ,
138
+ ) ;
139
+ const maxRequestedLength = Math . max (
140
+ headers . requested . length ,
141
+ ...versionKeys . map ( ( key ) => versions [ key ] . requested . length ) ,
129
142
) ;
130
143
131
144
const tableRows = versionKeys
132
145
. map ( ( module ) => {
146
+ const { requested, installed } = versions [ module ] ;
133
147
const name = module . padEnd ( maxNameLength ) ;
134
- const version = versions [ module ] ;
135
- const coloredVersion = version === '<error>' ? colors . red ( version ) : colors . cyan ( version ) ;
136
- const padding = ' ' . repeat ( maxVersionLength - version . length ) ;
137
148
138
- return `│ ${ name } │ ${ coloredVersion } ${ padding } │` ;
149
+ const coloredInstalled =
150
+ installed === '<error>' ? colors . red ( installed ) : colors . cyan ( installed ) ;
151
+ const installedPadding = ' ' . repeat ( maxInstalledLength - installed . length ) ;
152
+
153
+ return `│ ${ name } │ ${ coloredInstalled } ${ installedPadding } │ ${ requested . padEnd (
154
+ maxRequestedLength ,
155
+ ) } │`;
139
156
} )
140
157
. sort ( ) ;
141
158
142
- const top = `┌─${ '─' . repeat ( maxNameLength ) } ─┬─${ '─' . repeat ( maxVersionLength ) } ─┐` ;
143
- const header = `│ ${ nameHeader . padEnd ( maxNameLength ) } │ ${ versionHeader . padEnd (
144
- maxVersionLength ,
145
- ) } │`;
146
- const separator = `├─${ '─' . repeat ( maxNameLength ) } ─┼─${ '─' . repeat ( maxVersionLength ) } ─┤` ;
147
- const bottom = `└─${ '─' . repeat ( maxNameLength ) } ─┴─${ '─' . repeat ( maxVersionLength ) } ─┘` ;
159
+ const top = `┌─${ '─' . repeat ( maxNameLength ) } ─┬─${ '─' . repeat (
160
+ maxInstalledLength ,
161
+ ) } ─┬─${ '─' . repeat ( maxRequestedLength ) } ─┐`;
162
+ const header =
163
+ `│ ${ headers . name . padEnd ( maxNameLength ) } │ ` +
164
+ `${ headers . installed . padEnd ( maxInstalledLength ) } │ ` +
165
+ `${ headers . requested . padEnd ( maxRequestedLength ) } │` ;
166
+ const separator = `├─${ '─' . repeat ( maxNameLength ) } ─┼─${ '─' . repeat (
167
+ maxInstalledLength ,
168
+ ) } ─┼─${ '─' . repeat ( maxRequestedLength ) } ─┤`;
169
+ const bottom = `└─${ '─' . repeat ( maxNameLength ) } ─┴─${ '─' . repeat (
170
+ maxInstalledLength ,
171
+ ) } ─┴─${ '─' . repeat ( maxRequestedLength ) } ─┘`;
148
172
149
173
return [ top , header , separator , ...tableRows , bottom ] . join ( '\n' ) ;
150
174
}
0 commit comments