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 95f2f52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
23 changes: 19 additions & 4 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,28 @@ 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;
}

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

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

name[0] = modulePath;
return name;
}

return 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 95f2f52

Please sign in to comment.