Skip to content

Commit

Permalink
feat: handle call function from loaded option.require
Browse files Browse the repository at this point in the history
- call directly
- fallback to `default`
  • Loading branch information
sculpt0r committed Mar 13, 2023
1 parent 95f2f52 commit 7000e15
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/worker/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,15 @@ const run = async options => {
} else if (Array.isArray(ref)) {
const [path, options] = ref;

const mod = await load(path);
mod.apply(null, ...options);
const loadedModule = await load(path);

if (typeof loadedModule === 'function') {
loadedModule.apply(null, ...options);
} else if (typeof loadedModule.default === 'function') {
loadedModule.default.apply(null, ...options);
} else {
channel.send({type: 'non-invokable-require-option'});
}
}
}

Expand Down

0 comments on commit 7000e15

Please sign in to comment.