Skip to content

Commit

Permalink
vm_harness: access local files in plugin directory (#68)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nickolson authored Jan 31, 2025
1 parent 2fc8d13 commit 3df6e16
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/vm_harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ const vm = require('vm')
const dir_paths = [
`${__dirname}/../../../`, // for Haraka/tests/plugins
`${__dirname}/`, // for haraka-test-fixtures/test
`${__dirname}/../../../../../`, // for files in Haraka/
]

function dot_files(element) {
return element.match(/^\./) == null
}

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

0 comments on commit 3df6e16

Please sign in to comment.