@code-pushup/js-packages-plugin 0.30.0-alpha → 0.34.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/bin.js +104 -36
- package/index.js +1 -1
- package/package.json +3 -3
- package/src/lib/runner/audit/constants.d.ts +1 -0
- package/src/lib/runner/audit/types.d.ts +18 -0
- package/src/lib/runner/audit/unify-type.d.ts +2 -0
- package/src/lib/runner/outdated/constants.d.ts +1 -1
- package/src/lib/runner/outdated/types.d.ts +6 -0
- package/src/lib/runner/outdated/unify-type.d.ts +1 -0
package/bin.js
CHANGED
|
@@ -1034,12 +1034,57 @@ function yarnv2ToAuditResult(output) {
|
|
|
1034
1034
|
};
|
|
1035
1035
|
}
|
|
1036
1036
|
);
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1037
|
+
return {
|
|
1038
|
+
vulnerabilities,
|
|
1039
|
+
summary: {
|
|
1040
|
+
...yarnv2Audit.metadata.vulnerabilities,
|
|
1041
|
+
total: getVulnerabilitiesTotal(yarnv2Audit.metadata.vulnerabilities)
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
function pnpmToAuditResult(output) {
|
|
1046
|
+
const pnpmResult = JSON.parse(output);
|
|
1047
|
+
const vulnerabilities = Object.values(pnpmResult.advisories).map(
|
|
1048
|
+
({
|
|
1049
|
+
module_name: name,
|
|
1050
|
+
id,
|
|
1051
|
+
title,
|
|
1052
|
+
url,
|
|
1053
|
+
severity,
|
|
1054
|
+
vulnerable_versions: versionRange,
|
|
1055
|
+
recommendation: fixInformation,
|
|
1056
|
+
findings
|
|
1057
|
+
}) => {
|
|
1058
|
+
const path = findings[0]?.paths[0];
|
|
1059
|
+
return {
|
|
1060
|
+
name,
|
|
1061
|
+
id,
|
|
1062
|
+
title,
|
|
1063
|
+
url,
|
|
1064
|
+
severity,
|
|
1065
|
+
versionRange,
|
|
1066
|
+
directDependency: path == null ? true : pnpmToDirectDependency(path),
|
|
1067
|
+
fixInformation
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1040
1070
|
);
|
|
1041
|
-
|
|
1042
|
-
|
|
1071
|
+
return {
|
|
1072
|
+
vulnerabilities,
|
|
1073
|
+
summary: {
|
|
1074
|
+
...pnpmResult.metadata.vulnerabilities,
|
|
1075
|
+
total: getVulnerabilitiesTotal(pnpmResult.metadata.vulnerabilities)
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
function pnpmToDirectDependency(path) {
|
|
1080
|
+
const deps = path.split(" > ").slice(1);
|
|
1081
|
+
if (deps.length <= 1) {
|
|
1082
|
+
return true;
|
|
1083
|
+
}
|
|
1084
|
+
return deps[0]?.split("@")[0] ?? true;
|
|
1085
|
+
}
|
|
1086
|
+
function getVulnerabilitiesTotal(summary) {
|
|
1087
|
+
return Object.values(summary).reduce((acc, value) => acc + value, 0);
|
|
1043
1088
|
}
|
|
1044
1089
|
|
|
1045
1090
|
// packages/plugin-js-packages/src/lib/runner/audit/constants.ts
|
|
@@ -1054,9 +1099,27 @@ var normalizeAuditMapper = {
|
|
|
1054
1099
|
npm: npmToAuditResult,
|
|
1055
1100
|
"yarn-classic": yarnv1ToAuditResult,
|
|
1056
1101
|
"yarn-modern": yarnv2ToAuditResult,
|
|
1057
|
-
pnpm:
|
|
1058
|
-
|
|
1059
|
-
|
|
1102
|
+
pnpm: pnpmToAuditResult
|
|
1103
|
+
};
|
|
1104
|
+
var filterNpmAuditResults = (results) => ({
|
|
1105
|
+
prod: results.prod,
|
|
1106
|
+
dev: filterAuditResult(results.dev, "name", results.prod),
|
|
1107
|
+
optional: filterAuditResult(results.optional, "name", results.prod)
|
|
1108
|
+
});
|
|
1109
|
+
var filterPnpmAuditResults = (results) => ({
|
|
1110
|
+
prod: results.prod,
|
|
1111
|
+
dev: results.dev,
|
|
1112
|
+
optional: filterAuditResult(
|
|
1113
|
+
filterAuditResult(results.optional, "id", results.prod),
|
|
1114
|
+
"id",
|
|
1115
|
+
results.dev
|
|
1116
|
+
)
|
|
1117
|
+
});
|
|
1118
|
+
var postProcessingAuditMapper = {
|
|
1119
|
+
npm: filterNpmAuditResults,
|
|
1120
|
+
// prod dependencies need to be filtered out manually since v10
|
|
1121
|
+
pnpm: filterPnpmAuditResults
|
|
1122
|
+
// optional dependencies don't have an exclusive option so they need duplicates filtered out
|
|
1060
1123
|
};
|
|
1061
1124
|
var npmDependencyOptions = {
|
|
1062
1125
|
prod: ["--omit=dev", "--omit=optional"],
|
|
@@ -1068,16 +1131,16 @@ var yarnv2EnvironmentOptions = {
|
|
|
1068
1131
|
dev: "development",
|
|
1069
1132
|
optional: ""
|
|
1070
1133
|
};
|
|
1134
|
+
var pnpmDependencyOptions = {
|
|
1135
|
+
prod: ["--prod", "--no-optional"],
|
|
1136
|
+
dev: ["--dev", "--no-optional"],
|
|
1137
|
+
optional: []
|
|
1138
|
+
};
|
|
1071
1139
|
var auditArgs = (groupDep) => ({
|
|
1072
|
-
npm: [...npmDependencyOptions[groupDep], "--
|
|
1073
|
-
"yarn-classic": ["--
|
|
1074
|
-
"yarn-modern": [
|
|
1075
|
-
|
|
1076
|
-
"--environment",
|
|
1077
|
-
yarnv2EnvironmentOptions[groupDep]
|
|
1078
|
-
],
|
|
1079
|
-
// TODO: Add once PNPM is supported.
|
|
1080
|
-
pnpm: []
|
|
1140
|
+
npm: [...npmDependencyOptions[groupDep], "--audit-level=none"],
|
|
1141
|
+
"yarn-classic": ["--groups", dependencyGroupToLong[groupDep]],
|
|
1142
|
+
"yarn-modern": ["--environment", yarnv2EnvironmentOptions[groupDep]],
|
|
1143
|
+
pnpm: [...pnpmDependencyOptions[groupDep]]
|
|
1081
1144
|
});
|
|
1082
1145
|
|
|
1083
1146
|
// packages/plugin-js-packages/src/lib/runner/audit/transform.ts
|
|
@@ -1177,6 +1240,17 @@ function yarnv2ToOutdatedResult(output) {
|
|
|
1177
1240
|
type
|
|
1178
1241
|
}));
|
|
1179
1242
|
}
|
|
1243
|
+
function pnpmToOutdatedResult(output) {
|
|
1244
|
+
const pnpmOutdated = JSON.parse(output);
|
|
1245
|
+
return objectToEntries(pnpmOutdated).map(
|
|
1246
|
+
([name, { current, latest, dependencyType: type }]) => ({
|
|
1247
|
+
name,
|
|
1248
|
+
current,
|
|
1249
|
+
latest,
|
|
1250
|
+
type
|
|
1251
|
+
})
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1180
1254
|
|
|
1181
1255
|
// packages/plugin-js-packages/src/lib/runner/outdated/constants.ts
|
|
1182
1256
|
var outdatedSeverity = {
|
|
@@ -1184,17 +1258,17 @@ var outdatedSeverity = {
|
|
|
1184
1258
|
minor: "warning",
|
|
1185
1259
|
patch: "info"
|
|
1186
1260
|
};
|
|
1187
|
-
var outdatedArgs = {
|
|
1188
|
-
npm: ["--json", "--long"],
|
|
1189
|
-
"yarn-classic": ["--json"],
|
|
1190
|
-
"yarn-modern": ["--json"],
|
|
1191
|
-
pnpm: []
|
|
1192
|
-
};
|
|
1193
1261
|
var normalizeOutdatedMapper = {
|
|
1194
1262
|
npm: npmToOutdatedResult,
|
|
1195
1263
|
"yarn-classic": yarnv1ToOutdatedResult,
|
|
1196
1264
|
"yarn-modern": yarnv2ToOutdatedResult,
|
|
1197
|
-
pnpm:
|
|
1265
|
+
pnpm: pnpmToOutdatedResult
|
|
1266
|
+
};
|
|
1267
|
+
var outdatedArgs = {
|
|
1268
|
+
npm: ["--long"],
|
|
1269
|
+
"yarn-classic": [],
|
|
1270
|
+
"yarn-modern": [],
|
|
1271
|
+
pnpm: []
|
|
1198
1272
|
};
|
|
1199
1273
|
|
|
1200
1274
|
// packages/plugin-js-packages/src/lib/runner/outdated/types.ts
|
|
@@ -1291,10 +1365,10 @@ async function executeRunner() {
|
|
|
1291
1365
|
async function processOutdated(packageManager) {
|
|
1292
1366
|
const { stdout } = await executeProcess({
|
|
1293
1367
|
command: pkgManagerCommands[packageManager],
|
|
1294
|
-
args: ["outdated", ...outdatedArgs[packageManager]],
|
|
1368
|
+
args: ["outdated", "--json", ...outdatedArgs[packageManager]],
|
|
1295
1369
|
cwd: process.cwd(),
|
|
1296
1370
|
ignoreExitCode: true
|
|
1297
|
-
//
|
|
1371
|
+
// outdated returns exit code 1 when outdated dependencies are found
|
|
1298
1372
|
});
|
|
1299
1373
|
const normalizedResult = normalizeOutdatedMapper[packageManager](stdout);
|
|
1300
1374
|
return dependencyGroups.map(
|
|
@@ -1310,8 +1384,8 @@ async function processAudit(packageManager, auditLevelMapping) {
|
|
|
1310
1384
|
command: pkgManagerCommands[packageManager],
|
|
1311
1385
|
args: getAuditCommandArgs(packageManager, dep),
|
|
1312
1386
|
cwd: process.cwd(),
|
|
1313
|
-
ignoreExitCode: packageManager === "yarn-classic"
|
|
1314
|
-
// yarn v1
|
|
1387
|
+
ignoreExitCode: packageManager === "yarn-classic" || packageManager === "pnpm"
|
|
1388
|
+
// yarn v1 and PNPM do not have exit code configuration
|
|
1315
1389
|
});
|
|
1316
1390
|
return [dep, normalizeAuditMapper[packageManager](stdout)];
|
|
1317
1391
|
}
|
|
@@ -1329,7 +1403,7 @@ async function processAudit(packageManager, auditLevelMapping) {
|
|
|
1329
1403
|
const fulfilled = objectFromEntries(
|
|
1330
1404
|
auditResults.filter(isPromiseFulfilledResult).map((x) => x.value)
|
|
1331
1405
|
);
|
|
1332
|
-
const uniqueResults = packageManager
|
|
1406
|
+
const uniqueResults = postProcessingAuditMapper[packageManager]?.(fulfilled) ?? fulfilled;
|
|
1333
1407
|
return supportedDepGroups.map(
|
|
1334
1408
|
(group) => auditResultToAuditOutput(
|
|
1335
1409
|
uniqueResults[group],
|
|
@@ -1343,16 +1417,10 @@ function getAuditCommandArgs(packageManager, group) {
|
|
|
1343
1417
|
return [
|
|
1344
1418
|
...packageManager === "yarn-modern" ? ["npm"] : [],
|
|
1345
1419
|
"audit",
|
|
1420
|
+
"--json",
|
|
1346
1421
|
...auditArgs(group)[packageManager]
|
|
1347
1422
|
];
|
|
1348
1423
|
}
|
|
1349
|
-
function filterNpmAuditResults(results) {
|
|
1350
|
-
return {
|
|
1351
|
-
prod: results.prod,
|
|
1352
|
-
dev: filterAuditResult(results.dev, "name", results.prod),
|
|
1353
|
-
optional: filterAuditResult(results.optional, "name", results.prod)
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
1424
|
|
|
1357
1425
|
// packages/plugin-js-packages/src/bin.ts
|
|
1358
1426
|
await executeRunner();
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
|
|
5
5
|
// packages/plugin-js-packages/package.json
|
|
6
6
|
var name = "@code-pushup/js-packages-plugin";
|
|
7
|
-
var version = "0.
|
|
7
|
+
var version = "0.34.0";
|
|
8
8
|
|
|
9
9
|
// packages/plugin-js-packages/src/lib/config.ts
|
|
10
10
|
import { z as z15 } from "zod";
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/js-packages-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@code-pushup/models": "
|
|
6
|
-
"@code-pushup/utils": "
|
|
5
|
+
"@code-pushup/models": "0.34.0",
|
|
6
|
+
"@code-pushup/utils": "0.34.0",
|
|
7
7
|
"zod": "^3.22.4"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
@@ -2,4 +2,5 @@ import { DependencyGroup, PackageAuditLevel, PackageManager } from '../../config
|
|
|
2
2
|
import { AuditResult } from './types';
|
|
3
3
|
export declare const auditScoreModifiers: Record<PackageAuditLevel, number>;
|
|
4
4
|
export declare const normalizeAuditMapper: Record<PackageManager, (output: string) => AuditResult>;
|
|
5
|
+
export declare const postProcessingAuditMapper: Partial<Record<PackageManager, (result: Record<DependencyGroup, AuditResult>) => Record<DependencyGroup, AuditResult>>>;
|
|
5
6
|
export declare const auditArgs: (groupDep: DependencyGroup) => Record<PackageManager, string[]>;
|
|
@@ -83,3 +83,21 @@ export type Yarnv2AuditResultJson = {
|
|
|
83
83
|
vulnerabilities: Record<PackageAuditLevel, number>;
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
|
+
export type PnpmAuditAdvisory = {
|
|
87
|
+
module_name: string;
|
|
88
|
+
id: number;
|
|
89
|
+
severity: PackageAuditLevel;
|
|
90
|
+
vulnerable_versions: string;
|
|
91
|
+
recommendation: string;
|
|
92
|
+
title: string;
|
|
93
|
+
url: string;
|
|
94
|
+
findings: {
|
|
95
|
+
paths: string[];
|
|
96
|
+
}[];
|
|
97
|
+
};
|
|
98
|
+
export type PnpmAuditResultJson = {
|
|
99
|
+
advisories: Record<string, PnpmAuditAdvisory>;
|
|
100
|
+
metadata: {
|
|
101
|
+
vulnerabilities: Record<PackageAuditLevel, number>;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
@@ -4,3 +4,5 @@ export declare function npmToFixInformation(fixAvailable: boolean | NpmFixInform
|
|
|
4
4
|
export declare function npmToAdvisory(name: string, vulnerabilities: NpmVulnerabilities, prevNodes?: Set<string>): NpmAdvisory | null;
|
|
5
5
|
export declare function yarnv1ToAuditResult(output: string): AuditResult;
|
|
6
6
|
export declare function yarnv2ToAuditResult(output: string): AuditResult;
|
|
7
|
+
export declare function pnpmToAuditResult(output: string): AuditResult;
|
|
8
|
+
export declare function pnpmToDirectDependency(path: string): string | true;
|
|
@@ -2,5 +2,5 @@ import { IssueSeverity } from '@code-pushup/models';
|
|
|
2
2
|
import { PackageManager } from '../../config';
|
|
3
3
|
import { OutdatedResult, VersionType } from './types';
|
|
4
4
|
export declare const outdatedSeverity: Record<VersionType, IssueSeverity>;
|
|
5
|
-
export declare const outdatedArgs: Record<PackageManager, string[]>;
|
|
6
5
|
export declare const normalizeOutdatedMapper: Record<PackageManager, (output: string) => OutdatedResult>;
|
|
6
|
+
export declare const outdatedArgs: Record<PackageManager, string[]>;
|
|
@@ -45,4 +45,10 @@ export type Yarnv2VersionOverview = {
|
|
|
45
45
|
type: DependencyGroupLong;
|
|
46
46
|
};
|
|
47
47
|
export type Yarnv2OutdatedResultJson = Yarnv2VersionOverview[];
|
|
48
|
+
export type PnpmVersionOverview = {
|
|
49
|
+
current: string;
|
|
50
|
+
latest: string;
|
|
51
|
+
dependencyType: DependencyGroupLong;
|
|
52
|
+
};
|
|
53
|
+
export type PnpmOutdatedResultJson = Record<string, PnpmVersionOverview>;
|
|
48
54
|
export {};
|
|
@@ -2,3 +2,4 @@ import { OutdatedResult } from './types';
|
|
|
2
2
|
export declare function npmToOutdatedResult(output: string): OutdatedResult;
|
|
3
3
|
export declare function yarnv1ToOutdatedResult(output: string): OutdatedResult;
|
|
4
4
|
export declare function yarnv2ToOutdatedResult(output: string): OutdatedResult;
|
|
5
|
+
export declare function pnpmToOutdatedResult(output: string): OutdatedResult;
|