1- import { writeFile } from 'node:fs/promises' ;
21import path from 'node:path' ;
3- import type { RunnerConfig , RunnerFilesPaths } from '@code-pushup/models' ;
2+ import type { RunnerFunction } from '@code-pushup/models' ;
43import {
54 asyncSequential ,
6- createRunnerFiles ,
7- ensureDirectoryExists ,
85 executeProcess ,
9- filePathToCliArg ,
106 objectFromEntries ,
11- objectToCliArgs ,
12- readJsonFile ,
137} from '@code-pushup/utils' ;
148import {
159 type AuditSeverity ,
@@ -26,54 +20,33 @@ import type { AuditResult } from './audit/types.js';
2620import { outdatedResultToAuditOutput } from './outdated/transform.js' ;
2721import { 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
7952async function processOutdated (
0 commit comments