@ovh-ux/manager-static-analysis-kit 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +166 -24
- package/bin/cli-path-config.js +41 -2
- package/bin/code-duplication-cli.js +14 -16
- package/bin/code-duplication-tests-cli.js +43 -6
- package/bin/perf-budgets-cli.js +15 -15
- package/bin/perf-budgets-tests-cli.js +36 -3
- package/bin/static-dynamic-quality-checks.js +2 -2
- package/bin/tests-coverage-cli-tests.js +44 -6
- package/bin/tests-coverage-cli.js +35 -27
- package/bin/types-coverage-cli.js +8 -11
- package/bin/types-coverage-tests-cli.js +44 -7
- package/bin/utils/args-parse-utils.js +69 -106
- package/bin/utils/module-utils.js +121 -0
- package/bin/utils/runner-utils.js +117 -22
- package/bin/utils/turbo-utils.js +1 -71
- package/dist/adapters/perf-budgets/helpers/perfs-bundle-analysis-helper.d.ts.map +1 -1
- package/dist/adapters/perf-budgets/helpers/perfs-bundle-analysis-helper.js +8 -4
- package/dist/configs/shared-exclusion-patterns.d.ts.map +1 -1
- package/dist/configs/shared-exclusion-patterns.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/bin/utils/apps-utils.js +0 -64
|
@@ -3,12 +3,23 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import process from 'node:process';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import { generateCombinedReports } from './file-utils.js';
|
|
6
|
+
import { generateCombinedReports, readJsonSafe } from './file-utils.js';
|
|
8
7
|
import { logError, logInfo } from './log-utils.js';
|
|
8
|
+
import { isReactModule } from './module-utils.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Ensure
|
|
11
|
+
* Ensure that a required binary exists before running an analysis command.
|
|
12
|
+
*
|
|
13
|
+
* This function verifies that a binary file exists at the given path.
|
|
14
|
+
* If not found, it logs an error message and terminates the process
|
|
15
|
+
* with exit code `1`.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} binPath - Absolute path to the binary executable.
|
|
18
|
+
* @param {string} label - Human-readable label for the binary (used in error logs).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ensureBinExists('/usr/local/bin/jscpd', 'JSCPD');
|
|
22
|
+
* // → Exits process if binary is missing
|
|
12
23
|
*/
|
|
13
24
|
export function ensureBinExists(binPath, label) {
|
|
14
25
|
if (!fs.existsSync(binPath)) {
|
|
@@ -18,7 +29,20 @@ export function ensureBinExists(binPath, label) {
|
|
|
18
29
|
}
|
|
19
30
|
|
|
20
31
|
/**
|
|
21
|
-
*
|
|
32
|
+
* Execute a command synchronously using the system shell.
|
|
33
|
+
*
|
|
34
|
+
* This function spawns a child process that runs a binary or command
|
|
35
|
+
* with the provided arguments, inheriting the parent process's stdio streams.
|
|
36
|
+
* It returns `true` if the command completed successfully (exit code `0`).
|
|
37
|
+
*
|
|
38
|
+
* @param {string} bin - Executable name or absolute path to run.
|
|
39
|
+
* @param {string[]} args - Command-line arguments for the executable.
|
|
40
|
+
* @param {string} cwd - Working directory where the command will be executed.
|
|
41
|
+
* @returns {boolean} `true` if the process exits with status `0`, otherwise `false`.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* runCommand('eslint', ['--fix', '.'], process.cwd());
|
|
45
|
+
* // → Runs ESLint and returns true if successful
|
|
22
46
|
*/
|
|
23
47
|
export function runCommand(bin, args, cwd) {
|
|
24
48
|
const result = spawnSync(bin, args, {
|
|
@@ -30,14 +54,90 @@ export function runCommand(bin, args, cwd) {
|
|
|
30
54
|
}
|
|
31
55
|
|
|
32
56
|
/**
|
|
33
|
-
*
|
|
57
|
+
* Execute analysis for a single module.
|
|
58
|
+
*
|
|
59
|
+
* This internal helper encapsulates:
|
|
60
|
+
* - Module validation (`fullPath`, `package.json`, React module check)
|
|
61
|
+
* - Error handling for analysis execution
|
|
62
|
+
* - Delegation to a provided analysis runner
|
|
63
|
+
*
|
|
64
|
+
* @param {Object} options - Analysis parameters.
|
|
65
|
+
* @param {Object} options.module - Module descriptor with metadata.
|
|
66
|
+
* @param {Function} options.analysisRunner - Function `(fullPath, shortPath, context) => boolean`
|
|
67
|
+
* that performs the analysis for this module.
|
|
68
|
+
* @returns {boolean} `true` if analysis succeeded for the module, otherwise `false`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* runModuleAnalysis({
|
|
72
|
+
* module: { fullPath: '/apps/zimbra', shortPath: 'zimbra', packageName: '@ovh-ux/manager-zimbra-app' },
|
|
73
|
+
* analysisRunner: runCoverageAnalysis,
|
|
74
|
+
* });
|
|
34
75
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
76
|
+
function runModuleAnalysis({ module, analysisRunner }) {
|
|
77
|
+
const { fullPath, shortPath, packageName } = module || {};
|
|
78
|
+
const pkgPath = path.join(fullPath, 'package.json');
|
|
79
|
+
let isAnalysisComplete = false;
|
|
80
|
+
|
|
81
|
+
if (!fs.existsSync(fullPath) || !fs.existsSync(pkgPath) || !isReactModule(pkgPath)) {
|
|
82
|
+
logError(`❌ Module folder not found: ${module} → skipping`);
|
|
83
|
+
return isAnalysisComplete;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
isAnalysisComplete = analysisRunner(fullPath, shortPath, {
|
|
88
|
+
pkgPath,
|
|
89
|
+
moduleDir: fullPath,
|
|
90
|
+
moduleFolder: shortPath,
|
|
91
|
+
moduleShortName: packageName,
|
|
92
|
+
pkg: readJsonSafe(pkgPath),
|
|
93
|
+
});
|
|
94
|
+
} catch (err) {
|
|
95
|
+
logError(`❌ Fatal error while analyzing ${shortPath}: ${err.stack || err.message}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return isAnalysisComplete;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Run a complete analysis across multiple modules and generate combined reports.
|
|
103
|
+
*
|
|
104
|
+
* This function orchestrates:
|
|
105
|
+
* 1. Iterating over provided modules.
|
|
106
|
+
* 2. Running analysis for each module (via `runModuleAnalysis`).
|
|
107
|
+
* 3. Aggregating successful results.
|
|
108
|
+
* 4. Generating combined JSON and HTML reports.
|
|
109
|
+
*
|
|
110
|
+
* If no modules are successfully analyzed, the process terminates with exit code `1`.
|
|
111
|
+
*
|
|
112
|
+
* @param {Object} options - Analysis configuration.
|
|
113
|
+
* @param {Object[]} options.modules - Array of module descriptors (`{ fullPath, shortPath, packageName }`).
|
|
114
|
+
* @param {string} options.binaryLabel - Label for the analysis type (e.g. "Type Coverage").
|
|
115
|
+
* @param {Function} options.analysisRunner - Function executed per module to run analysis logic.
|
|
116
|
+
* @param {string} options.reportsRootDirName - Directory under the output root to store reports.
|
|
117
|
+
* @param {string} options.combinedJson - Filename for the combined JSON report.
|
|
118
|
+
* @param {string} options.combinedHtml - Filename for the combined HTML report.
|
|
119
|
+
* @param {Function} options.collectFn - Function used to aggregate individual module data.
|
|
120
|
+
* @param {Function} options.generateHtmlFn - Function used to generate the combined HTML output.
|
|
121
|
+
* @param {string} options.outputRootDir - Base path where reports should be written.
|
|
122
|
+
* @returns {string[]} Array of successfully analyzed module short names.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* runModulesAnalysis({
|
|
126
|
+
* modules,
|
|
127
|
+
* binaryLabel: 'Type Coverage',
|
|
128
|
+
* analysisRunner: runTypeCoverage,
|
|
129
|
+
* reportsRootDirName: 'types-coverage-reports',
|
|
130
|
+
* combinedJson: 'types-coverage-combined-report.json',
|
|
131
|
+
* combinedHtml: 'types-coverage-combined-report.html',
|
|
132
|
+
* collectFn: collectTypeCoverage,
|
|
133
|
+
* generateHtmlFn: generateTypeCoverageHtml,
|
|
134
|
+
* outputRootDir: './reports',
|
|
135
|
+
* });
|
|
136
|
+
*/
|
|
137
|
+
export function runModulesAnalysis({
|
|
138
|
+
modules,
|
|
39
139
|
binaryLabel,
|
|
40
|
-
|
|
140
|
+
analysisRunner,
|
|
41
141
|
reportsRootDirName,
|
|
42
142
|
combinedJson,
|
|
43
143
|
combinedHtml,
|
|
@@ -45,21 +145,16 @@ export function runAppsAnalysis({
|
|
|
45
145
|
generateHtmlFn,
|
|
46
146
|
outputRootDir,
|
|
47
147
|
}) {
|
|
148
|
+
/** @type {string[]} */
|
|
48
149
|
const analyzed = [];
|
|
49
150
|
|
|
50
|
-
for (const
|
|
51
|
-
const
|
|
52
|
-
|
|
151
|
+
for (const module of modules) {
|
|
152
|
+
const isAnalysisComplete = runModuleAnalysis({
|
|
153
|
+
module,
|
|
154
|
+
analysisRunner,
|
|
155
|
+
});
|
|
53
156
|
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
ok = appRunner(appInfo.appDir, appInfo.appShortName, appInfo);
|
|
57
|
-
} catch (err) {
|
|
58
|
-
logError(
|
|
59
|
-
`❌ Fatal error while analyzing ${appInfo.appShortName}: ${err.stack || err.message}`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
if (ok) analyzed.push(appInfo.appShortName);
|
|
157
|
+
if (isAnalysisComplete) analyzed.push(module.shortPath);
|
|
63
158
|
}
|
|
64
159
|
|
|
65
160
|
if (analyzed.length > 0) {
|
package/bin/utils/turbo-utils.js
CHANGED
|
@@ -1,76 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
2
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Convert app folder names into Turbo filters by resolving their package.json names.
|
|
9
|
-
*
|
|
10
|
-
* Each app folder must contain a valid `package.json`. If not found, the app is skipped.
|
|
11
|
-
*
|
|
12
|
-
* @param {string} appsDir - Absolute path to the apps root directory.
|
|
13
|
-
* @param {string[]} appFolders - List of app folder names inside the apps directory.
|
|
14
|
-
* @returns {string[]} Array of package names to be used as Turbo filters.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* // appsDir = "/workspace/manager/apps"
|
|
18
|
-
* // appFolders = ["zimbra", "web"]
|
|
19
|
-
* // Returns: ["@ovh-ux/manager-zimbra-app", "@ovh-ux/manager-web-app"]
|
|
20
|
-
*/
|
|
21
|
-
function resolveTurboFiltersFromAppFolders(appsDir, appFolders) {
|
|
22
|
-
return appFolders
|
|
23
|
-
.map((appFolder) => {
|
|
24
|
-
const pkgPath = path.join(appsDir, appFolder, 'package.json');
|
|
25
|
-
if (!fs.existsSync(pkgPath)) {
|
|
26
|
-
logError(`❌ No package.json for app folder ${appFolder}, skipping`);
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
30
|
-
return pkg.name;
|
|
31
|
-
})
|
|
32
|
-
.filter(Boolean);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Resolve Turbo filters (package names) based on input mode.
|
|
37
|
-
*
|
|
38
|
-
* - If only `appFolders` are provided, resolves their corresponding package names.
|
|
39
|
-
* - If `packageNames` are provided, they are used directly as filters.
|
|
40
|
-
*
|
|
41
|
-
* @param {Object} options
|
|
42
|
-
* @param {string} options.appsDir - Absolute path to the apps root directory.
|
|
43
|
-
* @param {string[]} options.appFolders - List of app folders to analyze.
|
|
44
|
-
* @param {string[]} options.packageNames - List of package names (overrides appFolders).
|
|
45
|
-
* @returns {string[]} List of resolved Turbo filters (package names).
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* resolveTurboFilters({
|
|
49
|
-
* appsDir: "/workspace/manager/apps",
|
|
50
|
-
* appFolders: ["zimbra"],
|
|
51
|
-
* packageNames: []
|
|
52
|
-
* });
|
|
53
|
-
* // → ["@ovh-ux/manager-zimbra-app"]
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* resolveTurboFilters({
|
|
57
|
-
* appsDir: "/workspace/manager/apps",
|
|
58
|
-
* appFolders: [],
|
|
59
|
-
* packageNames: ["@ovh-ux/manager-web-app"]
|
|
60
|
-
* });
|
|
61
|
-
* // → ["@ovh-ux/manager-web-app"]
|
|
62
|
-
*/
|
|
63
|
-
export function resolveTurboFilters({ appsDir, appFolders, packageNames }) {
|
|
64
|
-
let filters = [];
|
|
65
|
-
|
|
66
|
-
if (appFolders.length > 0 && packageNames.length === 0) {
|
|
67
|
-
filters = resolveTurboFiltersFromAppFolders(appsDir, appFolders);
|
|
68
|
-
} else if (packageNames.length > 0) {
|
|
69
|
-
filters = packageNames;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return filters;
|
|
73
|
-
}
|
|
3
|
+
import { logInfo, logWarn } from './log-utils.js';
|
|
74
4
|
|
|
75
5
|
/**
|
|
76
6
|
* Run a Turbo build for the provided filters.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perfs-bundle-analysis-helper.d.ts","sourceRoot":"","sources":["../../../../src/adapters/perf-budgets/helpers/perfs-bundle-analysis-helper.ts"],"names":[],"mappings":"AAMA,OAAO,EAAoB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAKtE,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C;
|
|
1
|
+
{"version":3,"file":"perfs-bundle-analysis-helper.d.ts","sourceRoot":"","sources":["../../../../src/adapters/perf-budgets/helpers/perfs-bundle-analysis-helper.ts"],"names":[],"mappings":"AAMA,OAAO,EAAoB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAKtE,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C;AAyCD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,YAAY,CAgBlE;AASD,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,MAAM,GAAG,kBAAkB,CAmC9E;AASD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAwJ3E"}
|
|
@@ -15,14 +15,18 @@ const buildAssetsInfos = (data) => data.map((entry) => {
|
|
|
15
15
|
const filename = entry?.filename ?? 'unknown';
|
|
16
16
|
const sizeKb = typeof entry?.parsedSize === 'number' ? entry.parsedSize / 1024 : 0;
|
|
17
17
|
let type = 'other';
|
|
18
|
-
if (/\.js$/i.test(filename))
|
|
18
|
+
if (/\.(js|mjs|cjs|ts|tsx)$/i.test(filename)) {
|
|
19
19
|
type = 'js';
|
|
20
|
-
|
|
20
|
+
}
|
|
21
|
+
else if (/\.css$/i.test(filename)) {
|
|
21
22
|
type = 'css';
|
|
22
|
-
|
|
23
|
+
}
|
|
24
|
+
else if (/\.html?$/i.test(filename)) {
|
|
23
25
|
type = 'html';
|
|
24
|
-
|
|
26
|
+
}
|
|
27
|
+
else if (/\.(png|jpe?g|gif|svg|webp)$/i.test(filename)) {
|
|
25
28
|
type = 'img';
|
|
29
|
+
}
|
|
26
30
|
return { filename, type, sizeKb };
|
|
27
31
|
});
|
|
28
32
|
export function parseAnalyzerJson(raw) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-exclusion-patterns.d.ts","sourceRoot":"","sources":["../../src/configs/shared-exclusion-patterns.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,UAuCnC,CAAC;AAyBF,eAAO,MAAM,4BAA4B,
|
|
1
|
+
{"version":3,"file":"shared-exclusion-patterns.d.ts","sourceRoot":"","sources":["../../src/configs/shared-exclusion-patterns.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,UAuCnC,CAAC;AAyBF,eAAO,MAAM,4BAA4B,UAwBxC,CAAC"}
|