Skip to content

Commit 11deecf

Browse files
committed
refactor(plugin-js-packages): use runner function instead of runner config
1 parent c88beaf commit 11deecf

File tree

7 files changed

+27
-124
lines changed

7 files changed

+27
-124
lines changed

packages/plugin-js-packages/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"@code-pushup/utils": "0.96.1",
4242
"build-md": "^0.4.1",
4343
"semver": "^7.6.0",
44-
"yargs": "^17.7.2",
4544
"zod": "^4.0.5"
4645
},
4746
"files": [

packages/plugin-js-packages/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"build": {},
88
"lint": {},
99
"unit-test": {},
10-
"int-test": {},
1110
"code-pushup": {},
1211
"code-pushup-eslint": {},
1312
"code-pushup-coverage": {},

packages/plugin-js-packages/src/bin.ts

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

packages/plugin-js-packages/src/lib/js-packages-plugin.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { createRequire } from 'node:module';
2-
import path from 'node:path';
3-
import { fileURLToPath } from 'node:url';
42
import type { Audit, Group, PluginConfig } from '@code-pushup/models';
53
import {
64
type DependencyGroup,
@@ -11,7 +9,7 @@ import {
119
} from './config.js';
1210
import { dependencyDocs, dependencyGroupWeights } from './constants.js';
1311
import { packageManagers } from './package-managers/package-managers.js';
14-
import { createRunnerConfig } from './runner/index.js';
12+
import { createRunnerFunction } from './runner/index.js';
1513
import { normalizeConfig } from './utils.js';
1614

1715
/**
@@ -42,12 +40,6 @@ export async function jsPackagesPlugin(
4240
...jsPackagesPluginConfigRest
4341
} = await normalizeConfig(config);
4442

45-
const runnerScriptPath = path.join(
46-
fileURLToPath(path.dirname(import.meta.url)),
47-
'..',
48-
'bin.js',
49-
);
50-
5143
const packageJson = createRequire(import.meta.url)(
5244
'../../package.json',
5345
) as typeof import('../../package.json');
@@ -63,7 +55,7 @@ export async function jsPackagesPlugin(
6355
version: packageJson.version,
6456
audits: createAudits(packageManager.slug, checks, depGroups),
6557
groups: createGroups(packageManager.slug, checks, depGroups),
66-
runner: await createRunnerConfig(runnerScriptPath, {
58+
runner: createRunnerFunction({
6759
...jsPackagesPluginConfigRest,
6860
checks,
6961
packageManager: packageManager.slug,

packages/plugin-js-packages/src/lib/js-packages-plugin.unit.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,11 @@ import { describe, expect, it } from 'vitest';
33
import {
44
type Group,
55
type PluginConfig,
6-
type RunnerConfig,
76
pluginConfigSchema,
87
} from '@code-pushup/models';
98
import { MEMFS_VOLUME } from '@code-pushup/test-utils';
109
import { jsPackagesPlugin } from './js-packages-plugin.js';
1110

12-
vi.mock('./runner/index.ts', () => ({
13-
createRunnerConfig: vi.fn().mockReturnValue({
14-
command: 'node',
15-
outputFile: 'runner-output.json',
16-
} satisfies RunnerConfig),
17-
}));
18-
1911
describe('jsPackagesPlugin', () => {
2012
it('should initialise the plugin without a given config for NPM', async () => {
2113
vol.fromJSON(
@@ -60,7 +52,7 @@ describe('jsPackagesPlugin', () => {
6052
title: 'JS Packages',
6153
audits: expect.any(Array),
6254
groups: expect.any(Array),
63-
runner: expect.any(Object),
55+
runner: expect.any(Function),
6456
}),
6557
);
6658
});

packages/plugin-js-packages/src/lib/runner/index.ts

Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import { writeFile } from 'node:fs/promises';
21
import path from 'node:path';
3-
import type { RunnerConfig, RunnerFilesPaths } from '@code-pushup/models';
2+
import type { RunnerFunction } from '@code-pushup/models';
43
import {
54
asyncSequential,
6-
createRunnerFiles,
7-
ensureDirectoryExists,
85
executeProcess,
9-
filePathToCliArg,
106
objectFromEntries,
11-
objectToCliArgs,
12-
readJsonFile,
137
} from '@code-pushup/utils';
148
import {
159
type AuditSeverity,
@@ -26,54 +20,33 @@ import type { AuditResult } from './audit/types.js';
2620
import { outdatedResultToAuditOutput } from './outdated/transform.js';
2721
import { getTotalDependencies } from './utils.js';
2822

29-
export async function createRunnerConfig(
30-
scriptPath: string,
23+
export function createRunnerFunction(
3124
config: FinalJSPackagesPluginConfig,
32-
): Promise<RunnerConfig> {
33-
const { runnerConfigPath, runnerOutputPath } = await createRunnerFiles(
34-
'js-packages',
35-
JSON.stringify(config),
36-
);
37-
38-
return {
39-
command: 'node',
40-
args: [
41-
filePathToCliArg(scriptPath),
42-
...objectToCliArgs({ runnerConfigPath, runnerOutputPath }),
43-
],
44-
configFile: runnerConfigPath,
45-
outputFile: runnerOutputPath,
46-
};
47-
}
48-
49-
export async function executeRunner({
50-
runnerConfigPath,
51-
runnerOutputPath,
52-
}: RunnerFilesPaths): Promise<void> {
53-
const {
54-
packageManager,
55-
checks,
56-
auditLevelMapping,
57-
packageJsonPath,
58-
dependencyGroups: depGroups,
59-
} = await readJsonFile<FinalJSPackagesPluginConfig>(runnerConfigPath);
25+
): RunnerFunction {
26+
return async () => {
27+
const {
28+
packageManager,
29+
checks,
30+
auditLevelMapping,
31+
packageJsonPath,
32+
dependencyGroups: depGroups,
33+
} = config;
6034

61-
const auditResults = checks.includes('audit')
62-
? await processAudit(
63-
packageManager,
64-
depGroups,
65-
auditLevelMapping,
66-
packageJsonPath,
67-
)
68-
: [];
35+
const auditResults = checks.includes('audit')
36+
? await processAudit(
37+
packageManager,
38+
depGroups,
39+
auditLevelMapping,
40+
packageJsonPath,
41+
)
42+
: [];
6943

70-
const outdatedResults = checks.includes('outdated')
71-
? await processOutdated(packageManager, depGroups, packageJsonPath)
72-
: [];
73-
const checkResults = [...auditResults, ...outdatedResults];
44+
const outdatedResults = checks.includes('outdated')
45+
? await processOutdated(packageManager, depGroups, packageJsonPath)
46+
: [];
7447

75-
await ensureDirectoryExists(path.dirname(runnerOutputPath));
76-
await writeFile(runnerOutputPath, JSON.stringify(checkResults));
48+
return [...auditResults, ...outdatedResults];
49+
};
7750
}
7851

7952
async function processOutdated(

packages/plugin-js-packages/src/lib/runner/runner.int.test.ts

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

0 commit comments

Comments
 (0)