Skip to content

Commit

Permalink
feat: handle complex options.require config property
Browse files Browse the repository at this point in the history
  • Loading branch information
sculpt0r committed Mar 9, 2023
1 parent 1c56764 commit 51f8c95
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
21 changes: 16 additions & 5 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,24 @@ import serializeError from './serialize-error.js';

function resolveModules(modules) {
return arrify(modules).map(name => {
const modulePath = resolveCwd.silent(name);
if (typeof name === 'string') {
const modulePath = resolveCwd.silent(name);

if (modulePath === undefined) {
throw new Error(`Could not resolve required module ’${name}’`);
}
if (modulePath === undefined) {
throw new Error(`Could not resolve required module ’${name}’`);
}

return modulePath;
} else if (Array.isArray(name) && name.length > 0) {
const modulePath = resolveCwd.silent(name[0]);

return modulePath;
if (modulePath === undefined) {
throw new Error(`Could not resolve required module ’${name[0]}’`);
}

name[0] = modulePath;
return name;
}
});
}

Expand Down
9 changes: 8 additions & 1 deletion lib/worker/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@ const run = async options => {

try {
for await (const ref of (options.require || [])) {
await load(ref);
if (typeof ref === 'string') {
await load(ref);
} else if (Array.isArray(ref)) {
const [path, options] = ref;

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

// Install dependency tracker after the require configuration has been evaluated
Expand Down

0 comments on commit 51f8c95

Please sign in to comment.