1
1
import {
2
2
PluginConfig ,
3
- PluginOutput ,
3
+ PluginReport ,
4
4
auditOutputsSchema ,
5
5
} from '@code-pushup/models' ;
6
6
import { ProcessObserver , executeProcess } from '@code-pushup/utils' ;
@@ -13,7 +13,7 @@ import { join } from 'path';
13
13
export class PluginOutputError extends Error {
14
14
constructor ( pluginSlug : string , error ?: Error ) {
15
15
super (
16
- `Plugin output of plugin with slug ${ pluginSlug } is invalid. \n Zod Error: ${ error ?. message } ` ,
16
+ `Plugin output of plugin with slug ${ pluginSlug } is invalid. \n Error: ${ error ?. message } ` ,
17
17
) ;
18
18
if ( error ) {
19
19
this . name = error . name ;
@@ -47,7 +47,7 @@ export class PluginOutputError extends Error {
47
47
export async function executePlugin (
48
48
pluginConfig : PluginConfig ,
49
49
observer ?: ProcessObserver ,
50
- ) : Promise < PluginOutput > {
50
+ ) : Promise < PluginReport > {
51
51
const { slug, title, icon, description, docsUrl, version, packageName } =
52
52
pluginConfig ;
53
53
const { args, command } = pluginConfig . runner ;
@@ -64,10 +64,28 @@ export async function executePlugin(
64
64
pluginConfig . runner . outputPath ,
65
65
) ;
66
66
// read process output from file system and parse it
67
- const audits = auditOutputsSchema . parse (
67
+ const auditOutputs = auditOutputsSchema . parse (
68
68
JSON . parse ( ( await readFile ( processOutputPath ) ) . toString ( ) ) ,
69
69
) ;
70
70
71
+ const audits = auditOutputs . map ( auditOutput => {
72
+ const auditMetadata = pluginConfig . audits . find (
73
+ audit => audit . slug === auditOutput . slug ,
74
+ ) ;
75
+ if ( ! auditMetadata ) {
76
+ throw new PluginOutputError (
77
+ slug ,
78
+ new Error (
79
+ `Audit metadata not found for slug ${ auditOutput . slug } from runner output` ,
80
+ ) ,
81
+ ) ;
82
+ }
83
+ return {
84
+ ...auditOutput ,
85
+ ...auditMetadata ,
86
+ } ;
87
+ } ) ;
88
+
71
89
return {
72
90
version,
73
91
packageName,
@@ -89,8 +107,8 @@ export async function executePlugin(
89
107
/**
90
108
* Execute multiple plugins and aggregates their output.
91
109
* @public
92
- * @param plugins - array of {@link PluginConfig} objects
93
- * @returns {Promise<AuditOutput []> } - runner output
110
+ * @param plugins array of {@link PluginConfig} objects
111
+ * @returns {Promise<PluginReport []> } plugin report
94
112
*
95
113
* @example
96
114
* // plugin execution
@@ -107,10 +125,10 @@ export async function executePlugin(
107
125
*/
108
126
export async function executePlugins (
109
127
plugins : PluginConfig [ ] ,
110
- ) : Promise < PluginOutput [ ] > {
128
+ ) : Promise < PluginReport [ ] > {
111
129
return await plugins . reduce ( async ( acc , pluginCfg ) => {
112
130
const outputs = await acc ;
113
- const pluginOutput = await executePlugin ( pluginCfg ) ;
114
- return outputs . concat ( pluginOutput ) ;
115
- } , Promise . resolve ( [ ] as PluginOutput [ ] ) ) ;
131
+ const pluginReport = await executePlugin ( pluginCfg ) ;
132
+ return outputs . concat ( pluginReport ) ;
133
+ } , Promise . resolve ( [ ] as PluginReport [ ] ) ) ;
116
134
}
0 commit comments