Skip to content

Commit f186bdb

Browse files
committed
feat(version): display verions of @angular/* and @ngtools/*
Fixes #3589
1 parent 0954788 commit f186bdb

File tree

2 files changed

+6046
-3
lines changed

2 files changed

+6046
-3
lines changed

packages/angular-cli/commands/version.ts

Lines changed: 49 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,54 @@ 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.getModules(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+
let isRoot = false;
52+
roots.forEach(root => {
53+
if (module.startsWith(root)) {
54+
isRoot = true;
55+
}
56+
});
57+
if (options.verbose || alwaysPrint.indexOf(module) > -1 || isRoot) {
4058
this.printVersion(module, versions[module]);
4159
}
4260
}
4361
},
4462

63+
getModules: function(pkg: any, prefix: string): any {
64+
const modules: any = {};
65+
if (pkg.dependencies) {
66+
for (let key of Object.keys(pkg.dependencies)) {
67+
if (key && key.startsWith(prefix)) {
68+
modules[key] = this.getVersion(key);
69+
}
70+
}
71+
}
72+
if (pkg.devDependencies) {
73+
for (let key of Object.keys(pkg.devDependencies)) {
74+
if (key && key.startsWith(prefix)) {
75+
modules[key] = this.getVersion(key);
76+
}
77+
}
78+
}
79+
return modules;
80+
},
81+
82+
getVersion: function(moduleName: string): string {
83+
const modulePkg = require(path.resolve(
84+
this.project.root,
85+
'node_modules',
86+
moduleName,
87+
'package.json'));
88+
return modulePkg.version;
89+
},
90+
4591
printVersion: function (module: string, version: string) {
4692
this.ui.writeLine(module + ': ' + version);
4793
}

0 commit comments

Comments
 (0)