Skip to content

Commit 95f2f52

Browse files
committed
feat: handle complex options.require config property
1 parent 1c56764 commit 95f2f52

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/api.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,28 @@ import serializeError from './serialize-error.js';
2424

2525
function resolveModules(modules) {
2626
return arrify(modules).map(name => {
27-
const modulePath = resolveCwd.silent(name);
27+
if (typeof name === 'string') {
28+
const modulePath = resolveCwd.silent(name);
2829

29-
if (modulePath === undefined) {
30-
throw new Error(`Could not resolve required module ’${name}’`);
30+
if (modulePath === undefined) {
31+
throw new Error(`Could not resolve required module ’${name}’`);
32+
}
33+
34+
return modulePath;
35+
}
36+
37+
if (Array.isArray(name) && name.length > 0) {
38+
const modulePath = resolveCwd.silent(name[0]);
39+
40+
if (modulePath === undefined) {
41+
throw new Error(`Could not resolve required module ’${name[0]}’`);
42+
}
43+
44+
name[0] = modulePath;
45+
return name;
3146
}
3247

33-
return modulePath;
48+
return name;
3449
});
3550
}
3651

lib/worker/base.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,14 @@ const run = async options => {
176176

177177
try {
178178
for await (const ref of (options.require || [])) {
179-
await load(ref);
179+
if (typeof ref === 'string') {
180+
await load(ref);
181+
} else if (Array.isArray(ref)) {
182+
const [path, options] = ref;
183+
184+
const mod = await load(path);
185+
mod.apply(null, ...options);
186+
}
180187
}
181188

182189
// Install dependency tracker after the require configuration has been evaluated

0 commit comments

Comments
 (0)