11import path from 'node:path' ;
2- import type { RunnerConfig } from '@code-pushup/models' ;
2+ import type { AuditOutputs , RunnerFunction } from '@code-pushup/models' ;
3+ import { executeProcess , readJsonFile } from '@code-pushup/utils' ;
34import {
45 KNIP_PLUGIN_SLUG ,
56 KNIP_REPORT_NAME ,
@@ -45,7 +46,9 @@ export type KnipCliOptions = Partial<{
4546} > ;
4647export type RunnerOptions = KnipCliOptions & CustomReporterOptions ;
4748
48- export function createRunnerConfig ( options : RunnerOptions = { } ) : RunnerConfig {
49+ export function createRunnerFunction (
50+ options : RunnerOptions = { } ,
51+ ) : RunnerFunction {
4952 const {
5053 outputFile = path . join ( KNIP_PLUGIN_SLUG , KNIP_REPORT_NAME ) ,
5154 rawOutputFile,
@@ -54,24 +57,27 @@ export function createRunnerConfig(options: RunnerOptions = {}): RunnerConfig {
5457 // Resolve the reporter path from the installed package
5558 const reporterPath = '@code-pushup/knip-plugin/src/lib/reporter.js' ;
5659
57- return {
58- command : 'npx' ,
59- args : [
60- 'knip' ,
61- // off as we want to CI to pass
62- '--no-exit-code' ,
63- // off by default to guarantee execution without interference
64- '--no-progress' ,
65- // code-pushup reporter is used from the installed package
66- `--reporter=${ reporterPath } ` ,
67- // code-pushup reporter options are passed as string. Double JSON.stringify ensures proper escaping on all platforms
68- `--reporter-options=${ JSON . stringify (
69- JSON . stringify ( {
70- outputFile,
71- rawOutputFile,
72- } satisfies CustomReporterOptions ) ,
73- ) } `,
74- ] ,
75- outputFile,
60+ return async ( ) => {
61+ await executeProcess ( {
62+ command : 'npx' ,
63+ args : [
64+ 'knip' ,
65+ // off as we want to CI to pass
66+ '--no-exit-code' ,
67+ // off by default to guarantee execution without interference
68+ '--no-progress' ,
69+ // code-pushup reporter is used from the installed package
70+ `--reporter=${ reporterPath } ` ,
71+ // code-pushup reporter options are passed as string. Double JSON.stringify ensures proper escaping on all platforms
72+ `--reporter-options=${ JSON . stringify (
73+ JSON . stringify ( {
74+ outputFile,
75+ rawOutputFile,
76+ } satisfies CustomReporterOptions ) ,
77+ ) } `,
78+ ] ,
79+ } ) ;
80+
81+ return readJsonFile < AuditOutputs > ( outputFile ) ;
7682 } ;
7783}
0 commit comments