/
report.ts
151 lines (138 loc) · 3.53 KB
/
report.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import * as chalk from 'chalk';
import { appRootPath } from 'nx/src/utils/app-root';
import {
detectPackageManager,
getPackageManagerVersion,
readJsonFile,
} from '@nrwl/devkit';
import { output } from '../utilities/output';
import { join } from 'path';
import { resolve } from '../utilities/fileutils';
export const packagesWeCareAbout = [
'nx',
'@nrwl/angular',
'@nrwl/cypress',
'@nrwl/detox',
'@nrwl/devkit',
'@nrwl/eslint-plugin-nx',
'@nrwl/express',
'@nrwl/jest',
'@nrwl/js',
'@nrwl/linter',
'@nrwl/nest',
'@nrwl/next',
'@nrwl/node',
'@nrwl/nx-cloud',
'@nrwl/nx-plugin',
'@nrwl/react',
'@nrwl/react-native',
'@nrwl/schematics',
'@nrwl/storybook',
'@nrwl/web',
'@nrwl/workspace',
'typescript',
'rxjs',
];
export const patternsWeIgnoreInCommunityReport: Array<string | RegExp> = [
...packagesWeCareAbout,
'@schematics/angular',
new RegExp('@angular/*'),
'@nestjs/schematics',
];
export const report = {
command: 'report',
describe: 'Reports useful version numbers to copy into the Nx issue template',
builder: (yargs) => yargs,
handler: reportHandler,
};
/**
* Reports relevant version numbers for adding to an Nx issue report
*
* @remarks
*
* Must be run within an Nx workspace
*
*/
function reportHandler() {
const pm = detectPackageManager();
const pmVersion = getPackageManagerVersion(pm);
const bodyLines = [
`Node : ${process.versions.node}`,
`OS : ${process.platform} ${process.arch}`,
`${pm.padEnd(5)}: ${pmVersion}`,
``,
];
packagesWeCareAbout.forEach((p) => {
bodyLines.push(`${chalk.green(p)} : ${chalk.bold(readPackageVersion(p))}`);
});
bodyLines.push('---------------------------------------');
const communityPlugins = findInstalledCommunityPlugins();
bodyLines.push('Community plugins:');
communityPlugins.forEach((p) => {
bodyLines.push(`\t ${chalk.green(p.package)}: ${chalk.bold(p.version)}`);
});
output.log({
title: 'Report complete - copy this into the issue template',
bodyLines,
});
}
export function readPackageJson(p: string) {
try {
const packageJsonPath = resolve(`${p}/package.json`, {
paths: [appRootPath],
});
return readJsonFile(packageJsonPath);
} catch {
return {};
}
}
export function readPackageVersion(p: string): string {
return readPackageJson(p).version || 'Not Found';
}
export function findInstalledCommunityPlugins(): {
package: string;
version: string;
}[] {
const { dependencies, devDependencies } = readJsonFile(
join(appRootPath, 'package.json')
);
const deps = [
Object.keys(dependencies || {}),
Object.keys(devDependencies || {}),
].flat();
return deps.reduce(
(arr: any[], nextDep: string): { project: string; version: string }[] => {
if (
patternsWeIgnoreInCommunityReport.some((pattern) =>
typeof pattern === 'string'
? pattern === nextDep
: pattern.test(nextDep)
)
) {
return arr;
}
try {
const depPackageJson = readPackageJson(nextDep);
if (
[
'ng-update',
'nx-migrations',
'schematics',
'generators',
'builders',
'executors',
].some((field) => field in depPackageJson)
) {
arr.push({ package: nextDep, version: depPackageJson.version });
return arr;
} else {
return arr;
}
} catch {
console.warn(`Error parsing packageJson for ${nextDep}`);
return arr;
}
},
[]
);
}