Skip to content

Commit 8d6f0ce

Browse files
committed
update pluginManager file paths
- add type keyword to type imports - add comment clarifying test scanner plugin
1 parent aefd2f4 commit 8d6f0ce

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

.github/actions/find/src/findForUrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {AxeBuilder} from '@axe-core/playwright'
33
import playwright from 'playwright'
44
import {AuthContext} from './AuthContext.js'
55
import {generateScreenshots} from './generateScreenshots.js'
6-
import {loadPlugins, invokePlugin} from './pluginManager'
6+
import {loadPlugins, invokePlugin} from './pluginManager/index.js'
77
import {getScansContext} from './scansContextProvider.js'
88
import * as core from '@actions/core'
99

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
loadPluginViaJsFile,
77
loadPluginViaTsFile,
88
} from './pluginFileLoaders.js'
9-
import {
9+
import type {
1010
Plugin,
1111
PluginDefaultParams
1212
} from './types.d.js'

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path'
33
import * as esbuild from 'esbuild'
44
import {dynamicImport} from '../dynamicImport.js'
55
import * as core from '@actions/core'
6-
import { Plugin } from './types.js'
6+
import type { Plugin } from './types.js'
77

88
// - these functions had to be moved into a separate file
99
// because vitest will not mock the implementation of functions
@@ -16,25 +16,29 @@ export async function loadPluginViaTsFile(pluginFolderPath: string): Promise<Plu
1616
return
1717
}
1818

19-
core.info(`index.ts found for plugin at path: ${pluginFolderPath}`)
20-
const esbuildResult = await esbuild.build({
21-
entryPoints: [pluginEntryPath],
22-
write: false,
23-
bundle: true,
24-
format: 'esm',
25-
platform: 'node',
26-
target: 'node24',
27-
sourcemap: 'inline',
28-
})
19+
try {
20+
core.info(`index.ts found for plugin at path: ${pluginFolderPath}`)
21+
const esbuildResult = await esbuild.build({
22+
entryPoints: [pluginEntryPath],
23+
write: false,
24+
bundle: true,
25+
format: 'esm',
26+
platform: 'node',
27+
target: 'node24',
28+
sourcemap: 'inline',
29+
})
2930

30-
const outputFileContents = esbuildResult.outputFiles[0]?.text
31-
if (!outputFileContents) {
32-
core.info(`esbuild produced no output for plugin: ${pluginEntryPath}`)
33-
return
34-
}
31+
const outputFileContents = esbuildResult.outputFiles[0]?.text
32+
if (!outputFileContents) {
33+
core.info(`esbuild produced no output for plugin: ${pluginEntryPath}`)
34+
return
35+
}
3536

36-
const base64CompiledPlugin = Buffer.from(outputFileContents).toString('base64')
37-
return dynamicImport(`data:text/javascript;base64,${base64CompiledPlugin}`)
37+
const base64CompiledPlugin = Buffer.from(outputFileContents).toString('base64')
38+
return dynamicImport(`data:text/javascript;base64,${base64CompiledPlugin}`)
39+
} catch (e) {
40+
core.warning(`Error loading plugin at path: ${pluginEntryPath}`)
41+
}
3842
}
3943

4044
export async function loadPluginViaJsFile(pluginFolderPath: string): Promise<Plugin | undefined> {

.github/actions/find/tests/findForUrl.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import * as core from '@actions/core'
33
import {findForUrl} from '../src/findForUrl.js'
44
import {AxeBuilder} from '@axe-core/playwright'
55
import axe from 'axe-core'
6-
import * as pluginManager from '../src/pluginManager'
7-
import { Plugin } from '../src/pluginManager/types.js'
6+
import * as pluginManager from '../src/pluginManager/index.js'
7+
import type { Plugin } from '../src/pluginManager/types.js'
88
import {clearCache} from '../src/scansContextProvider.js'
99

1010
vi.mock('@actions/core', {spy: true})

.github/actions/find/tests/pluginManager.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import {describe, it, expect, vi, beforeEach} from 'vitest'
33
import * as fs from 'fs'
44
import * as esbuild from 'esbuild'
55
import * as dynamicImportModule from '../src/dynamicImport.js'
6-
import * as pluginManager from '../src/pluginManager'
6+
import * as pluginManager from '../src/pluginManager/index.js'
77
import * as core from '@actions/core'
88
import * as pluginLoaders from '../src/pluginManager/pluginFileLoaders.js'
99

1010
// - enable spying on fs
1111
// https://vitest.dev/guide/browser/#limitations
1212
vi.mock('fs', {spy: true})
1313
vi.mock('esbuild', {spy: true})
14-
vi.mock('../src/pluginManager', {spy: true})
14+
vi.mock('../src/pluginManager/index.js', {spy: true})
1515
vi.mock('@actions/core', {spy: true})
1616

1717
describe('pluginManager', () => {
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
export default async function reflowScan({ page, addFinding } = {}) {
2-
console.log('testing js file import')
1+
2+
// - this exist as a test to verify that loading plugins
3+
// via js files still works and there are no regressions
4+
5+
export default async function JSFilePluginLoadTest({ page, addFinding } = {}) {
6+
console.log('testing loading plugin using js file')
37
}
48

5-
export const name = 'temp-test-scan'
9+
export const name = 'js-file-plugin-load-test'

0 commit comments

Comments
 (0)