1 | const fs = require('fs')
|
2 | const path = require('path')
|
3 | const JoyCon = require('joycon').default
|
4 |
|
5 | const rcLoader = {
|
6 | name: 'rc',
|
7 | test: /\.[a-z]+rc$/,
|
8 | loadSync(filePath) {
|
9 | return JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
10 | }
|
11 | }
|
12 |
|
13 | module.exports = cwd => {
|
14 | const configLoader = new JoyCon({ cwd, stopDir: path.dirname(process.cwd()) })
|
15 |
|
16 | configLoader.addLoader(rcLoader)
|
17 |
|
18 | return {
|
19 | load(opts, noCache) {
|
20 | if (noCache) {
|
21 | configLoader.clearCache()
|
22 | }
|
23 | return configLoader.loadSync(opts)
|
24 | },
|
25 | resolve(opts, noCache) {
|
26 | if (noCache) {
|
27 | configLoader.clearCache()
|
28 | }
|
29 | return configLoader.resolveSync(opts)
|
30 | }
|
31 | }
|
32 | }
|