Skip to content

Commit 123f74d

Browse files
Broccohansl
authored andcommitted
feat(version): display verions of @angular/* and @ngtools/* (angular#3592)
Fixes angular#3589
1 parent 8e9abf9 commit 123f74d

File tree

2 files changed

+6207
-3
lines changed

2 files changed

+6207
-3
lines changed

packages/angular-cli/commands/version.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ const VersionCommand = Command.extend({
1414
}],
1515

1616
run: function (options: any) {
17-
const versions: any = process.versions;
17+
let versions: any = process.versions;
1818
const pkg = require(path.resolve(__dirname, '..', 'package.json'));
19+
let projPkg: any;
20+
try {
21+
projPkg = require(path.resolve(this.project.root, 'package.json'));
22+
} catch (exception) {
23+
projPkg = undefined;
24+
}
1925

20-
versions['os'] = process.platform + ' ' + process.arch;
26+
versions.os = process.platform + ' ' + process.arch;
2127

2228
const alwaysPrint = ['node', 'os'];
29+
const roots = ['@angular/', '@ngtools/'];
2330

2431
let ngCliVersion = pkg.version;
2532
if (!__dirname.match(/node_modules/)) {
@@ -33,15 +40,41 @@ const VersionCommand = Command.extend({
3340
ngCliVersion = `local (v${pkg.version}, branch: ${gitBranch})`;
3441
}
3542

43+
if (projPkg) {
44+
roots.forEach(root => {
45+
versions = Object.assign(versions, this.getDependencyVersions(projPkg, root));
46+
});
47+
}
3648
this.printVersion('angular-cli', ngCliVersion);
3749

3850
for (const module of Object.keys(versions)) {
39-
if (options.verbose || alwaysPrint.indexOf(module) > -1) {
51+
const isRoot = roots.some(root => module.startsWith(root));
52+
if (options.verbose || alwaysPrint.indexOf(module) > -1 || isRoot) {
4053
this.printVersion(module, versions[module]);
4154
}
4255
}
4356
},
4457

58+
getDependencyVersions: function(pkg: any, prefix: string): any {
59+
const modules: any = {};
60+
61+
Object.keys(pkg.dependencies || {})
62+
.concat(Object.keys(pkg.devDependencies || {}))
63+
.filter(depName => depName && depName.startsWith(prefix))
64+
.forEach(key => modules[key] = this.getVersion(key));
65+
66+
return modules;
67+
},
68+
69+
getVersion: function(moduleName: string): string {
70+
const modulePkg = require(path.resolve(
71+
this.project.root,
72+
'node_modules',
73+
moduleName,
74+
'package.json'));
75+
return modulePkg.version;
76+
},
77+
4578
printVersion: function (module: string, version: string) {
4679
this.ui.writeLine(module + ': ' + version);
4780
}

0 commit comments

Comments
 (0)