@@ -4,6 +4,7 @@ import {fileURLToPath} from 'url'
44import { dynamicImport } from './dynamicImport.js'
55import type { Finding } from './types.d.js'
66import playwright from 'playwright'
7+ import core from '@actions/core'
78
89// Helper to get __dirname equivalent in ES Modules
910const __filename = fileURLToPath ( import . meta. url )
@@ -18,7 +19,7 @@ const plugins: Plugin[] = []
1819let pluginsLoaded = false
1920
2021export async function loadPlugins ( ) {
21- console . log ( 'loading plugins' )
22+ core . info ( 'loading plugins' )
2223
2324 try {
2425 if ( ! pluginsLoaded ) {
@@ -27,7 +28,7 @@ export async function loadPlugins() {
2728 }
2829 } catch {
2930 plugins . length = 0
30- console . log ( abortError )
31+ core . error ( abortError )
3132 } finally {
3233 pluginsLoaded = true
3334 return plugins
@@ -47,7 +48,7 @@ export function clearCache() {
4748
4849// exported for mocking/testing. not for actual use
4950export async function loadBuiltInPlugins ( ) {
50- console . log ( 'Loading built-in plugins' )
51+ core . info ( 'Loading built-in plugins' )
5152
5253 const pluginsPath = '../../../scanner-plugins/'
5354 await loadPluginsFromPath ( {
@@ -58,7 +59,7 @@ export async function loadBuiltInPlugins() {
5859
5960// exported for mocking/testing. not for actual use
6061export async function loadCustomPlugins ( ) {
61- console . log ( 'Loading custom plugins' )
62+ core . info ( 'Loading custom plugins' )
6263
6364 const pluginsPath = process . cwd ( ) + '/.github/scanner-plugins/'
6465 await loadPluginsFromPath ( {
@@ -74,15 +75,26 @@ export async function loadPluginsFromPath({readPath, importPath}: {readPath: str
7475 for ( const pluginFolder of res ) {
7576 const pluginFolderPath = path . join ( importPath , pluginFolder )
7677 if ( fs . lstatSync ( pluginFolderPath ) . isDirectory ( ) ) {
77- console . log ( ' Found plugin: ' , pluginFolder )
78+ core . info ( ` Found plugin: ${ pluginFolder } ` )
7879 plugins . push ( await dynamicImport ( path . join ( importPath , pluginFolder , '/index.js' ) ) )
7980 }
8081 }
8182 } catch ( e ) {
8283 // - log errors here for granular info
83- console . log ( 'error: ' )
84- console . log ( e )
84+ core . error ( 'error: ' )
85+ core . error ( e as Error )
8586 // - throw error to handle aborting the plugin scans
8687 throw e
8788 }
8889}
90+
91+
92+ type InvokePluginParams = {
93+ plugin : Plugin ,
94+ page : playwright . Page ,
95+ addFinding : ( findingData : Finding ) => void ,
96+ url : string
97+ }
98+ export function invokePlugin ( { plugin, page, addFinding, url } : InvokePluginParams ) {
99+ return plugin . default ( { page, addFinding, url} )
100+ }
0 commit comments