Skip to content

Commit d749c90

Browse files
committed
refactor(plugin-js-packages): simplify command args definition
1 parent 3451929 commit d749c90

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

packages/plugin-js-packages/src/lib/package-managers/constants.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/plugin-js-packages/src/lib/package-managers/npm/npm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { objectToKeys } from '@code-pushup/utils';
22
import type { DependencyGroup } from '../../config.js';
33
import { filterAuditResult } from '../../runner/utils.js';
4-
import { COMMON_AUDIT_ARGS, COMMON_OUTDATED_ARGS } from '../constants.js';
54
import type { AuditResults, PackageManager } from '../types.js';
65
import { npmToAuditResult } from './audit-result.js';
76
import { npmToOutdatedResult } from './outdated-result.js';
@@ -24,9 +23,10 @@ export const npmPackageManager: PackageManager = {
2423
},
2524
audit: {
2625
getCommandArgs: groupDep => [
27-
...COMMON_AUDIT_ARGS,
26+
'audit',
2827
...npmDependencyOptions[groupDep],
2928
'--audit-level=none',
29+
'--json',
3030
],
3131
unifyResult: npmToAuditResult,
3232
// prod dependencies need to be filtered out manually since v10
@@ -49,7 +49,7 @@ export const npmPackageManager: PackageManager = {
4949
},
5050
},
5151
outdated: {
52-
commandArgs: [...COMMON_OUTDATED_ARGS, '--long'],
52+
commandArgs: ['outdated', '--long', '--json'],
5353
unifyResult: npmToOutdatedResult,
5454
},
5555
};

packages/plugin-js-packages/src/lib/package-managers/pnpm/pnpm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { objectToKeys } from '@code-pushup/utils';
22
import type { DependencyGroup } from '../../config.js';
33
import { filterAuditResult } from '../../runner/utils.js';
4-
import { COMMON_AUDIT_ARGS, COMMON_OUTDATED_ARGS } from '../constants.js';
54
import type { AuditResults, PackageManager } from '../types.js';
65
import { pnpmToAuditResult } from './audit-result.js';
76
import { pnpmToOutdatedResult } from './outdated-result.js';
@@ -24,8 +23,9 @@ export const pnpmPackageManager: PackageManager = {
2423
},
2524
audit: {
2625
getCommandArgs: groupDep => [
27-
...COMMON_AUDIT_ARGS,
26+
'audit',
2827
...pnpmDependencyOptions[groupDep],
28+
'--json',
2929
],
3030
ignoreExitCode: true,
3131
unifyResult: pnpmToAuditResult,
@@ -49,7 +49,7 @@ export const pnpmPackageManager: PackageManager = {
4949
},
5050
},
5151
outdated: {
52-
commandArgs: COMMON_OUTDATED_ARGS,
52+
commandArgs: ['outdated', '--json'],
5353
unifyResult: pnpmToOutdatedResult,
5454
},
5555
};

packages/plugin-js-packages/src/lib/package-managers/yarn-classic/yarn-classic.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { dependencyGroupToLong } from '../../constants.js';
2-
import { COMMON_AUDIT_ARGS, COMMON_OUTDATED_ARGS } from '../constants.js';
32
import type { PackageManager } from '../types.js';
43
import { yarnClassicToAuditResult } from './audit-result.js';
54
import { yarnClassicToOutdatedResult } from './outdated-result.js';
@@ -16,15 +15,15 @@ export const yarnClassicPackageManager: PackageManager = {
1615
},
1716
audit: {
1817
getCommandArgs: groupDep => [
19-
...COMMON_AUDIT_ARGS,
20-
'--groups',
21-
dependencyGroupToLong[groupDep],
18+
'audit',
19+
`--groups=${dependencyGroupToLong[groupDep]}`,
20+
'--json',
2221
],
2322
ignoreExitCode: true,
2423
unifyResult: yarnClassicToAuditResult,
2524
},
2625
outdated: {
27-
commandArgs: COMMON_OUTDATED_ARGS,
26+
commandArgs: ['outdated', '--json'],
2827
unifyResult: yarnClassicToOutdatedResult,
2928
},
3029
};

packages/plugin-js-packages/src/lib/package-managers/yarn-modern/yarn-modern.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Yarn v2 does not currently audit optional dependencies
22
import type { DependencyGroup } from '../../config.js';
3-
import { COMMON_AUDIT_ARGS, COMMON_OUTDATED_ARGS } from '../constants.js';
43
import type { PackageManager } from '../types.js';
54
import { yarnBerryToAuditResult } from './audit-result.js';
65
import { yarnBerryToOutdatedResult } from './outdated-result.js';
@@ -23,18 +22,25 @@ export const yarnModernPackageManager: PackageManager = {
2322
outdated: 'https://github.com/mskelton/yarn-plugin-outdated',
2423
},
2524
audit: {
26-
getCommandArgs: groupDep => [
27-
'npm',
28-
...COMMON_AUDIT_ARGS,
29-
'--environment',
30-
yarnModernEnvironmentOptions[groupDep],
31-
],
25+
getCommandArgs: groupDep => {
26+
const environment = yarnModernEnvironmentOptions[groupDep];
27+
return [
28+
'npm',
29+
'audit',
30+
...(environment ? [`--environment=${environment}`] : []),
31+
'--json',
32+
];
33+
},
3234
supportedDepGroups: ['prod', 'dev'], // Yarn v2 does not support audit for optional dependencies
3335
unifyResult: yarnBerryToAuditResult,
3436
ignoreExitCode: true,
3537
},
3638
outdated: {
37-
commandArgs: [...COMMON_OUTDATED_ARGS, '--workspace=.'], // filter out other packages in case of Yarn workspaces
39+
commandArgs: [
40+
'outdated',
41+
'--workspace=.', // filter out other packages in case of Yarn workspaces
42+
'--json',
43+
],
3844
unifyResult: yarnBerryToOutdatedResult,
3945
},
4046
};

0 commit comments

Comments
 (0)