Skip to content

Commit 3df6e16

Browse files
authored
vm_harness: access local files in plugin directory (#68)
Adds ability for vm_harness find_haraka_lib(id) to load a local .js file that is stored in the plugin directory (passed as parameter 'id'), fixes #45
1 parent 2fc8d13 commit 3df6e16

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/vm_harness.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ const vm = require('vm')
55
const dir_paths = [
66
`${__dirname}/../../../`, // for Haraka/tests/plugins
77
`${__dirname}/`, // for haraka-test-fixtures/test
8+
`${__dirname}/../../../../../`, // for files in Haraka/
89
]
910

1011
function dot_files(element) {
1112
return element.match(/^\./) == null
1213
}
1314

1415
function find_haraka_lib(id) {
16+
// For local files in the project root directory
17+
// e.g. "require('./example.js')"
18+
if (id.includes('./') && id.includes('.js')) {
19+
id = id.substring(2, (id.length - 3))
20+
}
1521
for (let i = 0; i < dir_paths.length; i++) {
1622
const dirPath = `${dir_paths[i]}${id}.js`
1723
// console.log('dirPath: ' + dirPath);

0 commit comments

Comments
 (0)