@code-pushup/js-packages-plugin 0.34.0 → 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 +278 -189
- 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/package-managers/npm/audit-result.d.ts +5 -0
- 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 -5
- package/src/lib/runner/audit/transform.d.ts +2 -2
- package/src/lib/runner/audit/types.d.ts +0 -87
- 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 -43
- package/src/lib/runner/audit/unify-type.d.ts +0 -8
- package/src/lib/runner/outdated/unify-type.d.ts +0 -5
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(
|
|
@@ -1042,50 +1236,58 @@ function yarnv2ToAuditResult(output) {
|
|
|
1042
1236
|
}
|
|
1043
1237
|
};
|
|
1044
1238
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
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
|
-
}
|
|
1070
|
-
);
|
|
1071
|
-
return {
|
|
1072
|
-
vulnerabilities,
|
|
1073
|
-
summary: {
|
|
1074
|
-
...pnpmResult.metadata.vulnerabilities,
|
|
1075
|
-
total: getVulnerabilitiesTotal(pnpmResult.metadata.vulnerabilities)
|
|
1076
|
-
}
|
|
1077
|
-
};
|
|
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
|
+
}));
|
|
1078
1249
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
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
|
|
1083
1281
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
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
|
+
};
|
|
1089
1291
|
|
|
1090
1292
|
// packages/plugin-js-packages/src/lib/runner/audit/constants.ts
|
|
1091
1293
|
var auditScoreModifiers = {
|
|
@@ -1095,62 +1297,15 @@ var auditScoreModifiers = {
|
|
|
1095
1297
|
low: 0.02,
|
|
1096
1298
|
info: 0.01
|
|
1097
1299
|
};
|
|
1098
|
-
var normalizeAuditMapper = {
|
|
1099
|
-
npm: npmToAuditResult,
|
|
1100
|
-
"yarn-classic": yarnv1ToAuditResult,
|
|
1101
|
-
"yarn-modern": yarnv2ToAuditResult,
|
|
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
|
|
1123
|
-
};
|
|
1124
|
-
var npmDependencyOptions = {
|
|
1125
|
-
prod: ["--omit=dev", "--omit=optional"],
|
|
1126
|
-
dev: ["--include=dev", "--omit=optional"],
|
|
1127
|
-
optional: ["--include=optional", "--omit=dev"]
|
|
1128
|
-
};
|
|
1129
|
-
var yarnv2EnvironmentOptions = {
|
|
1130
|
-
prod: "production",
|
|
1131
|
-
dev: "development",
|
|
1132
|
-
optional: ""
|
|
1133
|
-
};
|
|
1134
|
-
var pnpmDependencyOptions = {
|
|
1135
|
-
prod: ["--prod", "--no-optional"],
|
|
1136
|
-
dev: ["--dev", "--no-optional"],
|
|
1137
|
-
optional: []
|
|
1138
|
-
};
|
|
1139
|
-
var auditArgs = (groupDep) => ({
|
|
1140
|
-
npm: [...npmDependencyOptions[groupDep], "--audit-level=none"],
|
|
1141
|
-
"yarn-classic": ["--groups", dependencyGroupToLong[groupDep]],
|
|
1142
|
-
"yarn-modern": ["--environment", yarnv2EnvironmentOptions[groupDep]],
|
|
1143
|
-
pnpm: [...pnpmDependencyOptions[groupDep]]
|
|
1144
|
-
});
|
|
1145
1300
|
|
|
1146
1301
|
// packages/plugin-js-packages/src/lib/runner/audit/transform.ts
|
|
1147
|
-
function auditResultToAuditOutput(result,
|
|
1302
|
+
function auditResultToAuditOutput(result, id, depGroup, auditLevelMapping) {
|
|
1148
1303
|
const issues = vulnerabilitiesToIssues(
|
|
1149
1304
|
result.vulnerabilities,
|
|
1150
1305
|
auditLevelMapping
|
|
1151
1306
|
);
|
|
1152
1307
|
return {
|
|
1153
|
-
slug: `${
|
|
1308
|
+
slug: `${id}-audit-${depGroup}`,
|
|
1154
1309
|
score: calculateAuditScore(result.summary),
|
|
1155
1310
|
value: result.summary.total,
|
|
1156
1311
|
displayValue: summaryToDisplayValue(result.summary),
|
|
@@ -1207,77 +1362,20 @@ var PLUGIN_CONFIG_PATH = join2(
|
|
|
1207
1362
|
"plugin-config.json"
|
|
1208
1363
|
);
|
|
1209
1364
|
|
|
1210
|
-
// packages/plugin-js-packages/src/lib/runner/outdated/unify-type.ts
|
|
1211
|
-
function npmToOutdatedResult(output) {
|
|
1212
|
-
const npmOutdated = JSON.parse(output);
|
|
1213
|
-
return objectToEntries(npmOutdated).filter(
|
|
1214
|
-
(entry) => entry[1].current != null
|
|
1215
|
-
).map(([name, overview]) => ({
|
|
1216
|
-
name,
|
|
1217
|
-
current: overview.current,
|
|
1218
|
-
latest: overview.latest,
|
|
1219
|
-
type: overview.type,
|
|
1220
|
-
...overview.homepage != null && { url: overview.homepage }
|
|
1221
|
-
}));
|
|
1222
|
-
}
|
|
1223
|
-
function yarnv1ToOutdatedResult(output) {
|
|
1224
|
-
const yarnv1Outdated = fromJsonLines(output);
|
|
1225
|
-
const dependencies = yarnv1Outdated[1].data.body;
|
|
1226
|
-
return dependencies.map(([name, current, _, latest, __, type, url]) => ({
|
|
1227
|
-
name,
|
|
1228
|
-
current,
|
|
1229
|
-
latest,
|
|
1230
|
-
type,
|
|
1231
|
-
url
|
|
1232
|
-
}));
|
|
1233
|
-
}
|
|
1234
|
-
function yarnv2ToOutdatedResult(output) {
|
|
1235
|
-
const npmOutdated = JSON.parse(output);
|
|
1236
|
-
return npmOutdated.map(({ name, current, latest, type }) => ({
|
|
1237
|
-
name,
|
|
1238
|
-
current,
|
|
1239
|
-
latest,
|
|
1240
|
-
type
|
|
1241
|
-
}));
|
|
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
|
-
}
|
|
1254
|
-
|
|
1255
1365
|
// packages/plugin-js-packages/src/lib/runner/outdated/constants.ts
|
|
1256
1366
|
var outdatedSeverity = {
|
|
1257
1367
|
major: "error",
|
|
1258
1368
|
minor: "warning",
|
|
1259
1369
|
patch: "info"
|
|
1260
1370
|
};
|
|
1261
|
-
var normalizeOutdatedMapper = {
|
|
1262
|
-
npm: npmToOutdatedResult,
|
|
1263
|
-
"yarn-classic": yarnv1ToOutdatedResult,
|
|
1264
|
-
"yarn-modern": yarnv2ToOutdatedResult,
|
|
1265
|
-
pnpm: pnpmToOutdatedResult
|
|
1266
|
-
};
|
|
1267
|
-
var outdatedArgs = {
|
|
1268
|
-
npm: ["--long"],
|
|
1269
|
-
"yarn-classic": [],
|
|
1270
|
-
"yarn-modern": [],
|
|
1271
|
-
pnpm: []
|
|
1272
|
-
};
|
|
1273
1371
|
|
|
1274
1372
|
// packages/plugin-js-packages/src/lib/runner/outdated/types.ts
|
|
1275
1373
|
var versionType = ["major", "minor", "patch"];
|
|
1276
1374
|
|
|
1277
1375
|
// packages/plugin-js-packages/src/lib/runner/outdated/transform.ts
|
|
1278
|
-
function outdatedResultToAuditOutput(result, packageManager,
|
|
1376
|
+
function outdatedResultToAuditOutput(result, packageManager, depGroup) {
|
|
1279
1377
|
const relevantDependencies = result.filter(
|
|
1280
|
-
(dep) => dep.type === dependencyGroupToLong[
|
|
1378
|
+
(dep) => dep.type === dependencyGroupToLong[depGroup]
|
|
1281
1379
|
);
|
|
1282
1380
|
const outdatedDependencies = relevantDependencies.filter(
|
|
1283
1381
|
(dep) => dep.current !== dep.latest
|
|
@@ -1291,7 +1389,7 @@ function outdatedResultToAuditOutput(result, packageManager, dependencyGroup) {
|
|
|
1291
1389
|
);
|
|
1292
1390
|
const issues = outdatedDependencies.length === 0 ? [] : outdatedToIssues(outdatedDependencies);
|
|
1293
1391
|
return {
|
|
1294
|
-
slug: `${packageManager}-outdated-${
|
|
1392
|
+
slug: `${packageManager}-outdated-${depGroup}`,
|
|
1295
1393
|
score: calculateOutdatedScore(
|
|
1296
1394
|
outdatedStats.major,
|
|
1297
1395
|
relevantDependencies.length
|
|
@@ -1362,32 +1460,33 @@ async function executeRunner() {
|
|
|
1362
1460
|
await ensureDirectoryExists(dirname(RUNNER_OUTPUT_PATH));
|
|
1363
1461
|
await writeFile(RUNNER_OUTPUT_PATH, JSON.stringify(checkResults));
|
|
1364
1462
|
}
|
|
1365
|
-
async function processOutdated(
|
|
1463
|
+
async function processOutdated(id) {
|
|
1464
|
+
const pm = packageManagers[id];
|
|
1366
1465
|
const { stdout } = await executeProcess({
|
|
1367
|
-
command:
|
|
1368
|
-
args:
|
|
1466
|
+
command: pm.command,
|
|
1467
|
+
args: pm.outdated.commandArgs,
|
|
1369
1468
|
cwd: process.cwd(),
|
|
1370
1469
|
ignoreExitCode: true
|
|
1371
1470
|
// outdated returns exit code 1 when outdated dependencies are found
|
|
1372
1471
|
});
|
|
1373
|
-
const normalizedResult =
|
|
1472
|
+
const normalizedResult = pm.outdated.unifyResult(stdout);
|
|
1374
1473
|
return dependencyGroups.map(
|
|
1375
|
-
(
|
|
1474
|
+
(depGroup) => outdatedResultToAuditOutput(normalizedResult, id, depGroup)
|
|
1376
1475
|
);
|
|
1377
1476
|
}
|
|
1378
|
-
async function processAudit(
|
|
1379
|
-
const
|
|
1477
|
+
async function processAudit(id, auditLevelMapping) {
|
|
1478
|
+
const pm = packageManagers[id];
|
|
1479
|
+
const supportedDepGroups = pm.audit.supportedDepGroups ?? dependencyGroups;
|
|
1380
1480
|
const auditResults = await Promise.allSettled(
|
|
1381
1481
|
supportedDepGroups.map(
|
|
1382
|
-
async (
|
|
1482
|
+
async (depGroup) => {
|
|
1383
1483
|
const { stdout } = await executeProcess({
|
|
1384
|
-
command:
|
|
1385
|
-
args:
|
|
1484
|
+
command: pm.command,
|
|
1485
|
+
args: pm.audit.getCommandArgs(depGroup),
|
|
1386
1486
|
cwd: process.cwd(),
|
|
1387
|
-
ignoreExitCode:
|
|
1388
|
-
// yarn v1 and PNPM do not have exit code configuration
|
|
1487
|
+
ignoreExitCode: pm.audit.ignoreExitCode
|
|
1389
1488
|
});
|
|
1390
|
-
return [
|
|
1489
|
+
return [depGroup, pm.audit.unifyResult(stdout)];
|
|
1391
1490
|
}
|
|
1392
1491
|
)
|
|
1393
1492
|
);
|
|
@@ -1396,31 +1495,21 @@ async function processAudit(packageManager, auditLevelMapping) {
|
|
|
1396
1495
|
rejected.map((result) => {
|
|
1397
1496
|
console.error(result.reason);
|
|
1398
1497
|
});
|
|
1399
|
-
throw new Error(
|
|
1400
|
-
`JS Packages plugin: Running ${pkgManagerCommands[packageManager]} audit failed.`
|
|
1401
|
-
);
|
|
1498
|
+
throw new Error(`JS Packages plugin: Running ${pm.name} audit failed.`);
|
|
1402
1499
|
}
|
|
1403
1500
|
const fulfilled = objectFromEntries(
|
|
1404
1501
|
auditResults.filter(isPromiseFulfilledResult).map((x) => x.value)
|
|
1405
1502
|
);
|
|
1406
|
-
const uniqueResults =
|
|
1503
|
+
const uniqueResults = pm.audit.postProcessResult?.(fulfilled) ?? fulfilled;
|
|
1407
1504
|
return supportedDepGroups.map(
|
|
1408
|
-
(
|
|
1409
|
-
uniqueResults[
|
|
1410
|
-
|
|
1411
|
-
|
|
1505
|
+
(depGroup) => auditResultToAuditOutput(
|
|
1506
|
+
uniqueResults[depGroup],
|
|
1507
|
+
id,
|
|
1508
|
+
depGroup,
|
|
1412
1509
|
auditLevelMapping
|
|
1413
1510
|
)
|
|
1414
1511
|
);
|
|
1415
1512
|
}
|
|
1416
|
-
function getAuditCommandArgs(packageManager, group) {
|
|
1417
|
-
return [
|
|
1418
|
-
...packageManager === "yarn-modern" ? ["npm"] : [],
|
|
1419
|
-
"audit",
|
|
1420
|
-
"--json",
|
|
1421
|
-
...auditArgs(group)[packageManager]
|
|
1422
|
-
];
|
|
1423
|
-
}
|
|
1424
1513
|
|
|
1425
1514
|
// packages/plugin-js-packages/src/bin.ts
|
|
1426
1515
|
await executeRunner();
|