1 | //
|
2 | ;
|
3 |
|
4 | const requireFromString = require('require-from-string');
|
5 | const readFile = require('./readFile');
|
6 |
|
7 | module.exports = function loadJs(
|
8 | filepath ,
|
9 | options
|
10 | ) {
|
11 | function parseJsFile(content ) {
|
12 | if (!content) return null;
|
13 |
|
14 | return {
|
15 | config: requireFromString(content, filepath),
|
16 | filepath,
|
17 | };
|
18 | }
|
19 |
|
20 | return !options.sync
|
21 | ? readFile(filepath).then(parseJsFile)
|
22 | : parseJsFile(readFile.sync(filepath));
|
23 | };
|