Skip to content

Commit 28ba71e

Browse files
minor adjustments based on copilot feedback (#171)
[Copilot found a few issues](#170) that I thought were important to address. This PR adds those fixes to merge to main before we merge to v2 and release
2 parents db51bb5 + fbbcb3d commit 28ba71e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

.github/actions/find/src/dynamicImport.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {pathToFileURL} from 'url'
2+
13
// - this exists because it looks like there's no straight-forward
24
// way to mock the dynamic import function, so mocking this instead
35
// (also, if it _is_ possible to mock the dynamic import,
@@ -17,5 +19,5 @@
1719
//
1820
// - so this looks like a reasonable approach
1921
export function dynamicImport(path: string) {
20-
return import(path)
22+
return import(pathToFileURL(path).href)
2123
}

.github/actions/find/src/pluginManager.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,20 @@ export async function loadBuiltInPlugins() {
6161
// exported for mocking/testing. not for actual use
6262
export async function loadCustomPlugins() {
6363
core.info('Loading custom plugins')
64+
const pluginsPath = path.join(process.cwd(), '.github/scanner-plugins/')
65+
66+
// - currently, the plugin manager will abort loading
67+
// all plugins if there's an error
68+
// - the problem with this is that if a scanner user doesnt
69+
// have custom plugins, they won't have a 'scanner-plugins' folder
70+
// which will cause an error and abort loading all plugins, including built-in ones
71+
// - so for custom plugins, if the path doesn't exist, we can return early
72+
// and not abort the loading of built-in plugins
73+
if (!fs.existsSync(pluginsPath)) {
74+
core.info('No custom plugins found.')
75+
return
76+
}
6477

65-
const pluginsPath = path.join(process.cwd(), '/.github/scanner-plugins/')
6678
await loadPluginsFromPath({pluginsPath})
6779
}
6880

@@ -75,7 +87,7 @@ export async function loadPluginsFromPath({pluginsPath}: {pluginsPath: string})
7587

7688
if (fs.existsSync(pluginFolderPath) && fs.lstatSync(pluginFolderPath).isDirectory()) {
7789
core.info(`Found plugin: ${pluginFolder}`)
78-
plugins.push(await dynamicImport(path.join(pluginsPath, pluginFolder, '/index.js')))
90+
plugins.push(await dynamicImport(path.join(pluginsPath, pluginFolder, 'index.js')))
7991
}
8092
}
8193
} catch (e) {

0 commit comments

Comments
 (0)