Skip to content

Commit 0d7e45d

Browse files
committed
refactor(plugin-js-packages): use runner function instead of runner config
1 parent 342ec2e commit 0d7e45d

File tree

4 files changed

+26
-113
lines changed

4 files changed

+26
-113
lines changed

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/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)