1 | module.exports = file => {
|
2 | let mod
|
3 |
|
4 | try {
|
5 | // eslint-disable-next-line import/no-dynamic-require
|
6 | mod = require(file)
|
7 |
|
8 | if (mod && typeof mod === 'object') {
|
9 | mod = mod.default
|
10 | }
|
11 | } catch (err) {
|
12 | console.error(`micro: Error when importing ${file}: ${err.stack}`)
|
13 | process.exit(1)
|
14 | }
|
15 |
|
16 | if (typeof mod !== 'function') {
|
17 | console.error(`micro: "${file}" does not export a function.`)
|
18 | process.exit(1)
|
19 | }
|
20 |
|
21 | return mod
|
22 | }
|