@code-pushup/js-packages-plugin 0.30.0-alpha → 0.35.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/CONTRIBUTING.md +15 -5
- package/bin.js +288 -131
- package/index.js +490 -94
- package/package.json +3 -3
- package/src/lib/config.d.ts +2 -2
- package/src/lib/constants.d.ts +3 -8
- package/src/lib/package-managers/constants.d.ts +2 -0
- package/src/lib/package-managers/index.d.ts +2 -0
- package/src/lib/{runner/audit/unify-type.d.ts → package-managers/npm/audit-result.d.ts} +2 -3
- package/src/lib/package-managers/npm/npm.d.ts +2 -0
- package/src/lib/package-managers/npm/outdated-result.d.ts +2 -0
- package/src/lib/package-managers/npm/types.d.ts +38 -0
- package/src/lib/package-managers/package-managers.d.ts +3 -0
- package/src/lib/package-managers/pnpm/audit-result.d.ts +3 -0
- package/src/lib/package-managers/pnpm/outdated-result.d.ts +2 -0
- package/src/lib/package-managers/pnpm/pnpm.d.ts +2 -0
- package/src/lib/package-managers/pnpm/types.d.ts +26 -0
- package/src/lib/package-managers/types.d.ts +26 -0
- package/src/lib/package-managers/yarn-classic/audit-result.d.ts +2 -0
- package/src/lib/package-managers/yarn-classic/outdated-result.d.ts +2 -0
- package/src/lib/package-managers/yarn-classic/types.d.ts +49 -0
- package/src/lib/package-managers/yarn-classic/yarn-classic.d.ts +2 -0
- package/src/lib/package-managers/yarn-modern/audit-result.d.ts +2 -0
- package/src/lib/package-managers/yarn-modern/outdated-result.d.ts +2 -0
- package/src/lib/package-managers/yarn-modern/types.d.ts +26 -0
- package/src/lib/package-managers/yarn-modern/yarn-modern.d.ts +2 -0
- package/src/lib/runner/audit/constants.d.ts +1 -4
- package/src/lib/runner/audit/transform.d.ts +2 -2
- package/src/lib/runner/audit/types.d.ts +0 -69
- package/src/lib/runner/audit/utils.d.ts +2 -0
- package/src/lib/runner/outdated/constants.d.ts +2 -5
- package/src/lib/runner/outdated/transform.d.ts +2 -2
- package/src/lib/runner/outdated/types.d.ts +0 -37
- package/src/lib/runner/outdated/unify-type.d.ts +0 -4
package/CONTRIBUTING.md
CHANGED
|
@@ -2,9 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
## Adding new package managers
|
|
4
4
|
|
|
5
|
-
In order to add a support for a new package manager, one needs to do the following
|
|
5
|
+
In order to add a support for a new package manager, one needs to do the following:
|
|
6
6
|
|
|
7
|
-
1. Expand `
|
|
8
|
-
2.
|
|
9
|
-
3.
|
|
10
|
-
|
|
7
|
+
1. Expand `packageManagerIdSchema` in `config.ts`.
|
|
8
|
+
2. Create a new object of `PackageManager` type in `package-managers/<name>/<name>.ts` and fill it in with all relevant data. Following the current pattern of separate files for audit and outdated result and types is recommended.
|
|
9
|
+
3. Extend `package-managers/package-managers.ts` record with the new package manager.
|
|
10
|
+
|
|
11
|
+
> [!NOTE]
|
|
12
|
+
> Should your package manager require specific behaviour, feel free to request a property addition or change.
|
|
13
|
+
|
|
14
|
+
### Notable properties
|
|
15
|
+
|
|
16
|
+
- `(audit|check).unifyResult()`: In order to process the results in a unified way, the expected type needs to be defined in `runner/(audit|check)/types.ts` and its transformation to normalised result implemented in `runner/(audit|check)/unify-type.ts`. This function is then referenced in the object to be called accordingly.
|
|
17
|
+
- `audit.getCommandArgs(depGroup)`: The `audit` command is run for one dependency group. In order to filter out the other dependencies, the arguments are provided dynamically based on this function. One may include frequently used arguments from `COMMON_AUDIT_ARGS`.
|
|
18
|
+
- `audit.ignoreExitCode`: Some package managers do not allow non-zero exit code override. To ignore non-zero exit code, set this property to `true`.
|
|
19
|
+
- `audit.supportedDepGroups`: Some package managers do not support `audit` check for all types of dependencies (e.g. optional). In that case, please list a supported subset of dependencies in this property. By default, all dependency groups are considered supported.
|
|
20
|
+
- `audit.postProcessResult()`: The `audit` check often does not offer exclusive result for all dependency groups. In order to filter out duplicates after the results are normalised, add a post-processing function here.
|
package/bin.js
CHANGED
|
@@ -832,17 +832,11 @@ var dependencyGroupToLong = {
|
|
|
832
832
|
dev: "devDependencies",
|
|
833
833
|
optional: "optionalDependencies"
|
|
834
834
|
};
|
|
835
|
-
var pkgManagerCommands = {
|
|
836
|
-
npm: "npm",
|
|
837
|
-
"yarn-classic": "yarn",
|
|
838
|
-
"yarn-modern": "yarn",
|
|
839
|
-
pnpm: "pnpm"
|
|
840
|
-
};
|
|
841
835
|
|
|
842
836
|
// packages/plugin-js-packages/src/lib/config.ts
|
|
843
837
|
var dependencyGroups = ["prod", "dev", "optional"];
|
|
844
838
|
var packageCommandSchema = z15.enum(["audit", "outdated"]);
|
|
845
|
-
var
|
|
839
|
+
var packageManagerIdSchema = z15.enum([
|
|
846
840
|
"npm",
|
|
847
841
|
"yarn-classic",
|
|
848
842
|
"yarn-modern",
|
|
@@ -869,7 +863,9 @@ var jsPackagesPluginConfigSchema = z15.object({
|
|
|
869
863
|
checks: z15.array(packageCommandSchema, {
|
|
870
864
|
description: "Package manager commands to be run. Defaults to both audit and outdated."
|
|
871
865
|
}).min(1).default(["audit", "outdated"]),
|
|
872
|
-
packageManager:
|
|
866
|
+
packageManager: packageManagerIdSchema.describe(
|
|
867
|
+
"Package manager to be used."
|
|
868
|
+
),
|
|
873
869
|
auditLevelMapping: z15.record(packageAuditLevelSchema, issueSeveritySchema, {
|
|
874
870
|
description: "Mapping of audit levels to issue severity. Custom mapping or overrides may be entered manually, otherwise has a default preset."
|
|
875
871
|
}).default(defaultAuditLevelMapping).transform(fillAuditLevelMapping)
|
|
@@ -907,7 +903,11 @@ function filterAuditResult(result, key, referenceResult) {
|
|
|
907
903
|
};
|
|
908
904
|
}
|
|
909
905
|
|
|
910
|
-
// packages/plugin-js-packages/src/lib/
|
|
906
|
+
// packages/plugin-js-packages/src/lib/package-managers/constants.ts
|
|
907
|
+
var COMMON_AUDIT_ARGS = ["audit", "--json"];
|
|
908
|
+
var COMMON_OUTDATED_ARGS = ["outdated", "--json"];
|
|
909
|
+
|
|
910
|
+
// packages/plugin-js-packages/src/lib/package-managers/npm/audit-result.ts
|
|
911
911
|
function npmToAuditResult(output) {
|
|
912
912
|
const npmAudit = JSON.parse(output);
|
|
913
913
|
const vulnerabilities = objectToEntries(npmAudit.vulnerabilities).map(
|
|
@@ -964,6 +964,159 @@ function npmToAdvisory(name, vulnerabilities, prevNodes = /* @__PURE__ */ new Se
|
|
|
964
964
|
}
|
|
965
965
|
return null;
|
|
966
966
|
}
|
|
967
|
+
|
|
968
|
+
// packages/plugin-js-packages/src/lib/package-managers/npm/outdated-result.ts
|
|
969
|
+
function npmToOutdatedResult(output) {
|
|
970
|
+
const npmOutdated = JSON.parse(output);
|
|
971
|
+
return objectToEntries(npmOutdated).filter(
|
|
972
|
+
(entry) => entry[1].current != null
|
|
973
|
+
).map(([name, overview]) => ({
|
|
974
|
+
name,
|
|
975
|
+
current: overview.current,
|
|
976
|
+
latest: overview.latest,
|
|
977
|
+
type: overview.type,
|
|
978
|
+
...overview.homepage != null && { url: overview.homepage }
|
|
979
|
+
}));
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// packages/plugin-js-packages/src/lib/package-managers/npm/npm.ts
|
|
983
|
+
var npmDependencyOptions = {
|
|
984
|
+
prod: ["--omit=dev", "--omit=optional"],
|
|
985
|
+
dev: ["--include=dev", "--omit=optional"],
|
|
986
|
+
optional: ["--include=optional", "--omit=dev"]
|
|
987
|
+
};
|
|
988
|
+
var npmPackageManager = {
|
|
989
|
+
slug: "npm",
|
|
990
|
+
name: "NPM",
|
|
991
|
+
command: "npm",
|
|
992
|
+
icon: "npm",
|
|
993
|
+
docs: {
|
|
994
|
+
homepage: "https://docs.npmjs.com/",
|
|
995
|
+
audit: "https://docs.npmjs.com/cli/commands/npm-audit",
|
|
996
|
+
outdated: "https://docs.npmjs.com/cli/commands/npm-outdated"
|
|
997
|
+
},
|
|
998
|
+
audit: {
|
|
999
|
+
getCommandArgs: (groupDep) => [
|
|
1000
|
+
...COMMON_AUDIT_ARGS,
|
|
1001
|
+
...npmDependencyOptions[groupDep],
|
|
1002
|
+
"--audit-level=none"
|
|
1003
|
+
],
|
|
1004
|
+
unifyResult: npmToAuditResult,
|
|
1005
|
+
// prod dependencies need to be filtered out manually since v10
|
|
1006
|
+
postProcessResult: (results) => ({
|
|
1007
|
+
prod: results.prod,
|
|
1008
|
+
dev: filterAuditResult(results.dev, "name", results.prod),
|
|
1009
|
+
optional: filterAuditResult(results.optional, "name", results.prod)
|
|
1010
|
+
})
|
|
1011
|
+
},
|
|
1012
|
+
outdated: {
|
|
1013
|
+
commandArgs: [...COMMON_OUTDATED_ARGS, "--long"],
|
|
1014
|
+
unifyResult: npmToOutdatedResult
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
// packages/plugin-js-packages/src/lib/runner/audit/utils.ts
|
|
1019
|
+
function getVulnerabilitiesTotal(summary) {
|
|
1020
|
+
return Object.values(summary).reduce((acc, value) => acc + value, 0);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// packages/plugin-js-packages/src/lib/package-managers/pnpm/audit-result.ts
|
|
1024
|
+
function pnpmToAuditResult(output) {
|
|
1025
|
+
const pnpmResult = JSON.parse(output);
|
|
1026
|
+
const vulnerabilities = Object.values(pnpmResult.advisories).map(
|
|
1027
|
+
({
|
|
1028
|
+
module_name: name,
|
|
1029
|
+
id,
|
|
1030
|
+
title,
|
|
1031
|
+
url,
|
|
1032
|
+
severity,
|
|
1033
|
+
vulnerable_versions: versionRange,
|
|
1034
|
+
recommendation: fixInformation,
|
|
1035
|
+
findings
|
|
1036
|
+
}) => {
|
|
1037
|
+
const path = findings[0]?.paths[0];
|
|
1038
|
+
return {
|
|
1039
|
+
name,
|
|
1040
|
+
id,
|
|
1041
|
+
title,
|
|
1042
|
+
url,
|
|
1043
|
+
severity,
|
|
1044
|
+
versionRange,
|
|
1045
|
+
directDependency: path == null ? true : pnpmToDirectDependency(path),
|
|
1046
|
+
fixInformation
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
);
|
|
1050
|
+
return {
|
|
1051
|
+
vulnerabilities,
|
|
1052
|
+
summary: {
|
|
1053
|
+
...pnpmResult.metadata.vulnerabilities,
|
|
1054
|
+
total: getVulnerabilitiesTotal(pnpmResult.metadata.vulnerabilities)
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
function pnpmToDirectDependency(path) {
|
|
1059
|
+
const deps = path.split(" > ").slice(1);
|
|
1060
|
+
if (deps.length <= 1) {
|
|
1061
|
+
return true;
|
|
1062
|
+
}
|
|
1063
|
+
return deps[0]?.split("@")[0] ?? true;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// packages/plugin-js-packages/src/lib/package-managers/pnpm/outdated-result.ts
|
|
1067
|
+
function pnpmToOutdatedResult(output) {
|
|
1068
|
+
const pnpmOutdated = JSON.parse(output);
|
|
1069
|
+
return objectToEntries(pnpmOutdated).map(
|
|
1070
|
+
([name, { current, latest, dependencyType: type }]) => ({
|
|
1071
|
+
name,
|
|
1072
|
+
current,
|
|
1073
|
+
latest,
|
|
1074
|
+
type
|
|
1075
|
+
})
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// packages/plugin-js-packages/src/lib/package-managers/pnpm/pnpm.ts
|
|
1080
|
+
var pnpmDependencyOptions = {
|
|
1081
|
+
prod: ["--prod", "--no-optional"],
|
|
1082
|
+
dev: ["--dev", "--no-optional"],
|
|
1083
|
+
optional: []
|
|
1084
|
+
};
|
|
1085
|
+
var pnpmPackageManager = {
|
|
1086
|
+
slug: "pnpm",
|
|
1087
|
+
name: "pnpm",
|
|
1088
|
+
command: "pnpm",
|
|
1089
|
+
icon: "pnpm",
|
|
1090
|
+
docs: {
|
|
1091
|
+
homepage: "https://pnpm.io/pnpm-cli",
|
|
1092
|
+
audit: "https://pnpm.io/cli/audit/",
|
|
1093
|
+
outdated: "https://pnpm.io/cli/outdated"
|
|
1094
|
+
},
|
|
1095
|
+
audit: {
|
|
1096
|
+
getCommandArgs: (groupDep) => [
|
|
1097
|
+
...COMMON_AUDIT_ARGS,
|
|
1098
|
+
...pnpmDependencyOptions[groupDep]
|
|
1099
|
+
],
|
|
1100
|
+
ignoreExitCode: true,
|
|
1101
|
+
unifyResult: pnpmToAuditResult,
|
|
1102
|
+
// optional dependencies don't have an exclusive option so they need duplicates filtered out
|
|
1103
|
+
postProcessResult: (results) => ({
|
|
1104
|
+
prod: results.prod,
|
|
1105
|
+
dev: results.dev,
|
|
1106
|
+
optional: filterAuditResult(
|
|
1107
|
+
filterAuditResult(results.optional, "id", results.prod),
|
|
1108
|
+
"id",
|
|
1109
|
+
results.dev
|
|
1110
|
+
)
|
|
1111
|
+
})
|
|
1112
|
+
},
|
|
1113
|
+
outdated: {
|
|
1114
|
+
commandArgs: COMMON_OUTDATED_ARGS,
|
|
1115
|
+
unifyResult: pnpmToOutdatedResult
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
// packages/plugin-js-packages/src/lib/package-managers/yarn-classic/audit-result.ts
|
|
967
1120
|
function yarnv1ToAuditResult(output) {
|
|
968
1121
|
const yarnv1Result = fromJsonLines(output);
|
|
969
1122
|
const [yarnv1Advisory, yarnv1Summary] = validateYarnv1Result(yarnv1Result);
|
|
@@ -1010,6 +1163,47 @@ function validateYarnv1Result(result) {
|
|
|
1010
1163
|
);
|
|
1011
1164
|
return [vulnerabilities, summary];
|
|
1012
1165
|
}
|
|
1166
|
+
|
|
1167
|
+
// packages/plugin-js-packages/src/lib/package-managers/yarn-classic/outdated-result.ts
|
|
1168
|
+
function yarnv1ToOutdatedResult(output) {
|
|
1169
|
+
const yarnv1Outdated = fromJsonLines(output);
|
|
1170
|
+
const dependencies = yarnv1Outdated[1].data.body;
|
|
1171
|
+
return dependencies.map(([name, current, _, latest, __, type, url]) => ({
|
|
1172
|
+
name,
|
|
1173
|
+
current,
|
|
1174
|
+
latest,
|
|
1175
|
+
type,
|
|
1176
|
+
url
|
|
1177
|
+
}));
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// packages/plugin-js-packages/src/lib/package-managers/yarn-classic/yarn-classic.ts
|
|
1181
|
+
var yarnv1PackageManager = {
|
|
1182
|
+
slug: "yarn-classic",
|
|
1183
|
+
name: "Yarn v1",
|
|
1184
|
+
command: "yarn",
|
|
1185
|
+
icon: "yarn",
|
|
1186
|
+
docs: {
|
|
1187
|
+
homepage: "https://classic.yarnpkg.com/docs/",
|
|
1188
|
+
audit: "https://classic.yarnpkg.com/docs/cli/audit",
|
|
1189
|
+
outdated: "https://classic.yarnpkg.com/docs/cli/outdated/"
|
|
1190
|
+
},
|
|
1191
|
+
audit: {
|
|
1192
|
+
getCommandArgs: (groupDep) => [
|
|
1193
|
+
...COMMON_AUDIT_ARGS,
|
|
1194
|
+
"--groups",
|
|
1195
|
+
dependencyGroupToLong[groupDep]
|
|
1196
|
+
],
|
|
1197
|
+
ignoreExitCode: true,
|
|
1198
|
+
unifyResult: yarnv1ToAuditResult
|
|
1199
|
+
},
|
|
1200
|
+
outdated: {
|
|
1201
|
+
commandArgs: COMMON_OUTDATED_ARGS,
|
|
1202
|
+
unifyResult: yarnv1ToOutdatedResult
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
|
|
1206
|
+
// packages/plugin-js-packages/src/lib/package-managers/yarn-modern/audit-result.ts
|
|
1013
1207
|
function yarnv2ToAuditResult(output) {
|
|
1014
1208
|
const yarnv2Audit = JSON.parse(output);
|
|
1015
1209
|
const vulnerabilities = Object.values(yarnv2Audit.advisories).map(
|
|
@@ -1034,14 +1228,67 @@ function yarnv2ToAuditResult(output) {
|
|
|
1034
1228
|
};
|
|
1035
1229
|
}
|
|
1036
1230
|
);
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1231
|
+
return {
|
|
1232
|
+
vulnerabilities,
|
|
1233
|
+
summary: {
|
|
1234
|
+
...yarnv2Audit.metadata.vulnerabilities,
|
|
1235
|
+
total: getVulnerabilitiesTotal(yarnv2Audit.metadata.vulnerabilities)
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1043
1238
|
}
|
|
1044
1239
|
|
|
1240
|
+
// packages/plugin-js-packages/src/lib/package-managers/yarn-modern/outdated-result.ts
|
|
1241
|
+
function yarnv2ToOutdatedResult(output) {
|
|
1242
|
+
const npmOutdated = JSON.parse(output);
|
|
1243
|
+
return npmOutdated.map(({ name, current, latest, type }) => ({
|
|
1244
|
+
name,
|
|
1245
|
+
current,
|
|
1246
|
+
latest,
|
|
1247
|
+
type
|
|
1248
|
+
}));
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
// packages/plugin-js-packages/src/lib/package-managers/yarn-modern/yarn-modern.ts
|
|
1252
|
+
var yarnv2EnvironmentOptions = {
|
|
1253
|
+
prod: "production",
|
|
1254
|
+
dev: "development",
|
|
1255
|
+
optional: ""
|
|
1256
|
+
};
|
|
1257
|
+
var yarnv2PackageManager = {
|
|
1258
|
+
slug: "yarn-modern",
|
|
1259
|
+
name: "yarn-modern",
|
|
1260
|
+
command: "yarn",
|
|
1261
|
+
icon: "yarn",
|
|
1262
|
+
docs: {
|
|
1263
|
+
homepage: "https://yarnpkg.com/getting-started",
|
|
1264
|
+
audit: "https://yarnpkg.com/cli/npm/audit",
|
|
1265
|
+
outdated: "https://github.com/mskelton/yarn-plugin-outdated"
|
|
1266
|
+
},
|
|
1267
|
+
audit: {
|
|
1268
|
+
getCommandArgs: (groupDep) => [
|
|
1269
|
+
"npm",
|
|
1270
|
+
...COMMON_AUDIT_ARGS,
|
|
1271
|
+
"--environment",
|
|
1272
|
+
yarnv2EnvironmentOptions[groupDep]
|
|
1273
|
+
],
|
|
1274
|
+
supportedDepGroups: ["prod", "dev"],
|
|
1275
|
+
// Yarn v2 does not support audit for optional dependencies
|
|
1276
|
+
unifyResult: yarnv2ToAuditResult
|
|
1277
|
+
},
|
|
1278
|
+
outdated: {
|
|
1279
|
+
commandArgs: COMMON_OUTDATED_ARGS,
|
|
1280
|
+
unifyResult: yarnv2ToOutdatedResult
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
|
|
1284
|
+
// packages/plugin-js-packages/src/lib/package-managers/package-managers.ts
|
|
1285
|
+
var packageManagers = {
|
|
1286
|
+
npm: npmPackageManager,
|
|
1287
|
+
"yarn-classic": yarnv1PackageManager,
|
|
1288
|
+
"yarn-modern": yarnv2PackageManager,
|
|
1289
|
+
pnpm: pnpmPackageManager
|
|
1290
|
+
};
|
|
1291
|
+
|
|
1045
1292
|
// packages/plugin-js-packages/src/lib/runner/audit/constants.ts
|
|
1046
1293
|
var auditScoreModifiers = {
|
|
1047
1294
|
critical: 1,
|
|
@@ -1050,44 +1297,15 @@ var auditScoreModifiers = {
|
|
|
1050
1297
|
low: 0.02,
|
|
1051
1298
|
info: 0.01
|
|
1052
1299
|
};
|
|
1053
|
-
var normalizeAuditMapper = {
|
|
1054
|
-
npm: npmToAuditResult,
|
|
1055
|
-
"yarn-classic": yarnv1ToAuditResult,
|
|
1056
|
-
"yarn-modern": yarnv2ToAuditResult,
|
|
1057
|
-
pnpm: () => {
|
|
1058
|
-
throw new Error("PNPM audit is not supported yet.");
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
1061
|
-
var npmDependencyOptions = {
|
|
1062
|
-
prod: ["--omit=dev", "--omit=optional"],
|
|
1063
|
-
dev: ["--include=dev", "--omit=optional"],
|
|
1064
|
-
optional: ["--include=optional", "--omit=dev"]
|
|
1065
|
-
};
|
|
1066
|
-
var yarnv2EnvironmentOptions = {
|
|
1067
|
-
prod: "production",
|
|
1068
|
-
dev: "development",
|
|
1069
|
-
optional: ""
|
|
1070
|
-
};
|
|
1071
|
-
var auditArgs = (groupDep) => ({
|
|
1072
|
-
npm: [...npmDependencyOptions[groupDep], "--json", "--audit-level=none"],
|
|
1073
|
-
"yarn-classic": ["--json", "--groups", dependencyGroupToLong[groupDep]],
|
|
1074
|
-
"yarn-modern": [
|
|
1075
|
-
"--json",
|
|
1076
|
-
"--environment",
|
|
1077
|
-
yarnv2EnvironmentOptions[groupDep]
|
|
1078
|
-
],
|
|
1079
|
-
// TODO: Add once PNPM is supported.
|
|
1080
|
-
pnpm: []
|
|
1081
|
-
});
|
|
1082
1300
|
|
|
1083
1301
|
// packages/plugin-js-packages/src/lib/runner/audit/transform.ts
|
|
1084
|
-
function auditResultToAuditOutput(result,
|
|
1302
|
+
function auditResultToAuditOutput(result, id, depGroup, auditLevelMapping) {
|
|
1085
1303
|
const issues = vulnerabilitiesToIssues(
|
|
1086
1304
|
result.vulnerabilities,
|
|
1087
1305
|
auditLevelMapping
|
|
1088
1306
|
);
|
|
1089
1307
|
return {
|
|
1090
|
-
slug: `${
|
|
1308
|
+
slug: `${id}-audit-${depGroup}`,
|
|
1091
1309
|
score: calculateAuditScore(result.summary),
|
|
1092
1310
|
value: result.summary.total,
|
|
1093
1311
|
displayValue: summaryToDisplayValue(result.summary),
|
|
@@ -1144,66 +1362,20 @@ var PLUGIN_CONFIG_PATH = join2(
|
|
|
1144
1362
|
"plugin-config.json"
|
|
1145
1363
|
);
|
|
1146
1364
|
|
|
1147
|
-
// packages/plugin-js-packages/src/lib/runner/outdated/unify-type.ts
|
|
1148
|
-
function npmToOutdatedResult(output) {
|
|
1149
|
-
const npmOutdated = JSON.parse(output);
|
|
1150
|
-
return objectToEntries(npmOutdated).filter(
|
|
1151
|
-
(entry) => entry[1].current != null
|
|
1152
|
-
).map(([name, overview]) => ({
|
|
1153
|
-
name,
|
|
1154
|
-
current: overview.current,
|
|
1155
|
-
latest: overview.latest,
|
|
1156
|
-
type: overview.type,
|
|
1157
|
-
...overview.homepage != null && { url: overview.homepage }
|
|
1158
|
-
}));
|
|
1159
|
-
}
|
|
1160
|
-
function yarnv1ToOutdatedResult(output) {
|
|
1161
|
-
const yarnv1Outdated = fromJsonLines(output);
|
|
1162
|
-
const dependencies = yarnv1Outdated[1].data.body;
|
|
1163
|
-
return dependencies.map(([name, current, _, latest, __, type, url]) => ({
|
|
1164
|
-
name,
|
|
1165
|
-
current,
|
|
1166
|
-
latest,
|
|
1167
|
-
type,
|
|
1168
|
-
url
|
|
1169
|
-
}));
|
|
1170
|
-
}
|
|
1171
|
-
function yarnv2ToOutdatedResult(output) {
|
|
1172
|
-
const npmOutdated = JSON.parse(output);
|
|
1173
|
-
return npmOutdated.map(({ name, current, latest, type }) => ({
|
|
1174
|
-
name,
|
|
1175
|
-
current,
|
|
1176
|
-
latest,
|
|
1177
|
-
type
|
|
1178
|
-
}));
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
1365
|
// packages/plugin-js-packages/src/lib/runner/outdated/constants.ts
|
|
1182
1366
|
var outdatedSeverity = {
|
|
1183
1367
|
major: "error",
|
|
1184
1368
|
minor: "warning",
|
|
1185
1369
|
patch: "info"
|
|
1186
1370
|
};
|
|
1187
|
-
var outdatedArgs = {
|
|
1188
|
-
npm: ["--json", "--long"],
|
|
1189
|
-
"yarn-classic": ["--json"],
|
|
1190
|
-
"yarn-modern": ["--json"],
|
|
1191
|
-
pnpm: []
|
|
1192
|
-
};
|
|
1193
|
-
var normalizeOutdatedMapper = {
|
|
1194
|
-
npm: npmToOutdatedResult,
|
|
1195
|
-
"yarn-classic": yarnv1ToOutdatedResult,
|
|
1196
|
-
"yarn-modern": yarnv2ToOutdatedResult,
|
|
1197
|
-
pnpm: (_) => []
|
|
1198
|
-
};
|
|
1199
1371
|
|
|
1200
1372
|
// packages/plugin-js-packages/src/lib/runner/outdated/types.ts
|
|
1201
1373
|
var versionType = ["major", "minor", "patch"];
|
|
1202
1374
|
|
|
1203
1375
|
// packages/plugin-js-packages/src/lib/runner/outdated/transform.ts
|
|
1204
|
-
function outdatedResultToAuditOutput(result, packageManager,
|
|
1376
|
+
function outdatedResultToAuditOutput(result, packageManager, depGroup) {
|
|
1205
1377
|
const relevantDependencies = result.filter(
|
|
1206
|
-
(dep) => dep.type === dependencyGroupToLong[
|
|
1378
|
+
(dep) => dep.type === dependencyGroupToLong[depGroup]
|
|
1207
1379
|
);
|
|
1208
1380
|
const outdatedDependencies = relevantDependencies.filter(
|
|
1209
1381
|
(dep) => dep.current !== dep.latest
|
|
@@ -1217,7 +1389,7 @@ function outdatedResultToAuditOutput(result, packageManager, dependencyGroup) {
|
|
|
1217
1389
|
);
|
|
1218
1390
|
const issues = outdatedDependencies.length === 0 ? [] : outdatedToIssues(outdatedDependencies);
|
|
1219
1391
|
return {
|
|
1220
|
-
slug: `${packageManager}-outdated-${
|
|
1392
|
+
slug: `${packageManager}-outdated-${depGroup}`,
|
|
1221
1393
|
score: calculateOutdatedScore(
|
|
1222
1394
|
outdatedStats.major,
|
|
1223
1395
|
relevantDependencies.length
|
|
@@ -1288,32 +1460,33 @@ async function executeRunner() {
|
|
|
1288
1460
|
await ensureDirectoryExists(dirname(RUNNER_OUTPUT_PATH));
|
|
1289
1461
|
await writeFile(RUNNER_OUTPUT_PATH, JSON.stringify(checkResults));
|
|
1290
1462
|
}
|
|
1291
|
-
async function processOutdated(
|
|
1463
|
+
async function processOutdated(id) {
|
|
1464
|
+
const pm = packageManagers[id];
|
|
1292
1465
|
const { stdout } = await executeProcess({
|
|
1293
|
-
command:
|
|
1294
|
-
args:
|
|
1466
|
+
command: pm.command,
|
|
1467
|
+
args: pm.outdated.commandArgs,
|
|
1295
1468
|
cwd: process.cwd(),
|
|
1296
1469
|
ignoreExitCode: true
|
|
1297
|
-
//
|
|
1470
|
+
// outdated returns exit code 1 when outdated dependencies are found
|
|
1298
1471
|
});
|
|
1299
|
-
const normalizedResult =
|
|
1472
|
+
const normalizedResult = pm.outdated.unifyResult(stdout);
|
|
1300
1473
|
return dependencyGroups.map(
|
|
1301
|
-
(
|
|
1474
|
+
(depGroup) => outdatedResultToAuditOutput(normalizedResult, id, depGroup)
|
|
1302
1475
|
);
|
|
1303
1476
|
}
|
|
1304
|
-
async function processAudit(
|
|
1305
|
-
const
|
|
1477
|
+
async function processAudit(id, auditLevelMapping) {
|
|
1478
|
+
const pm = packageManagers[id];
|
|
1479
|
+
const supportedDepGroups = pm.audit.supportedDepGroups ?? dependencyGroups;
|
|
1306
1480
|
const auditResults = await Promise.allSettled(
|
|
1307
1481
|
supportedDepGroups.map(
|
|
1308
|
-
async (
|
|
1482
|
+
async (depGroup) => {
|
|
1309
1483
|
const { stdout } = await executeProcess({
|
|
1310
|
-
command:
|
|
1311
|
-
args:
|
|
1484
|
+
command: pm.command,
|
|
1485
|
+
args: pm.audit.getCommandArgs(depGroup),
|
|
1312
1486
|
cwd: process.cwd(),
|
|
1313
|
-
ignoreExitCode:
|
|
1314
|
-
// yarn v1 does not have exit code configuration
|
|
1487
|
+
ignoreExitCode: pm.audit.ignoreExitCode
|
|
1315
1488
|
});
|
|
1316
|
-
return [
|
|
1489
|
+
return [depGroup, pm.audit.unifyResult(stdout)];
|
|
1317
1490
|
}
|
|
1318
1491
|
)
|
|
1319
1492
|
);
|
|
@@ -1322,37 +1495,21 @@ async function processAudit(packageManager, auditLevelMapping) {
|
|
|
1322
1495
|
rejected.map((result) => {
|
|
1323
1496
|
console.error(result.reason);
|
|
1324
1497
|
});
|
|
1325
|
-
throw new Error(
|
|
1326
|
-
`JS Packages plugin: Running ${pkgManagerCommands[packageManager]} audit failed.`
|
|
1327
|
-
);
|
|
1498
|
+
throw new Error(`JS Packages plugin: Running ${pm.name} audit failed.`);
|
|
1328
1499
|
}
|
|
1329
1500
|
const fulfilled = objectFromEntries(
|
|
1330
1501
|
auditResults.filter(isPromiseFulfilledResult).map((x) => x.value)
|
|
1331
1502
|
);
|
|
1332
|
-
const uniqueResults =
|
|
1503
|
+
const uniqueResults = pm.audit.postProcessResult?.(fulfilled) ?? fulfilled;
|
|
1333
1504
|
return supportedDepGroups.map(
|
|
1334
|
-
(
|
|
1335
|
-
uniqueResults[
|
|
1336
|
-
|
|
1337
|
-
|
|
1505
|
+
(depGroup) => auditResultToAuditOutput(
|
|
1506
|
+
uniqueResults[depGroup],
|
|
1507
|
+
id,
|
|
1508
|
+
depGroup,
|
|
1338
1509
|
auditLevelMapping
|
|
1339
1510
|
)
|
|
1340
1511
|
);
|
|
1341
1512
|
}
|
|
1342
|
-
function getAuditCommandArgs(packageManager, group) {
|
|
1343
|
-
return [
|
|
1344
|
-
...packageManager === "yarn-modern" ? ["npm"] : [],
|
|
1345
|
-
"audit",
|
|
1346
|
-
...auditArgs(group)[packageManager]
|
|
1347
|
-
];
|
|
1348
|
-
}
|
|
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
1513
|
|
|
1357
1514
|
// packages/plugin-js-packages/src/bin.ts
|
|
1358
1515
|
await executeRunner();
|