1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.cosmiconfig = cosmiconfig;
|
7 | exports.cosmiconfigSync = cosmiconfigSync;
|
8 | exports.defaultLoaders = void 0;
|
9 |
|
10 | var _os = _interopRequireDefault(require("os"));
|
11 |
|
12 | var _Explorer = require("./Explorer");
|
13 |
|
14 | var _ExplorerSync = require("./ExplorerSync");
|
15 |
|
16 | var _loaders = require("./loaders");
|
17 |
|
18 | var _types = require("./types");
|
19 |
|
20 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21 |
|
22 |
|
23 |
|
24 | function cosmiconfig(moduleName, options = {}) {
|
25 | const normalizedOptions = normalizeOptions(moduleName, options);
|
26 | const explorer = new _Explorer.Explorer(normalizedOptions);
|
27 | return {
|
28 | search: explorer.search.bind(explorer),
|
29 | load: explorer.load.bind(explorer),
|
30 | clearLoadCache: explorer.clearLoadCache.bind(explorer),
|
31 | clearSearchCache: explorer.clearSearchCache.bind(explorer),
|
32 | clearCaches: explorer.clearCaches.bind(explorer)
|
33 | };
|
34 | }
|
35 |
|
36 |
|
37 | function cosmiconfigSync(moduleName, options = {}) {
|
38 | const normalizedOptions = normalizeOptions(moduleName, options);
|
39 | const explorerSync = new _ExplorerSync.ExplorerSync(normalizedOptions);
|
40 | return {
|
41 | search: explorerSync.searchSync.bind(explorerSync),
|
42 | load: explorerSync.loadSync.bind(explorerSync),
|
43 | clearLoadCache: explorerSync.clearLoadCache.bind(explorerSync),
|
44 | clearSearchCache: explorerSync.clearSearchCache.bind(explorerSync),
|
45 | clearCaches: explorerSync.clearCaches.bind(explorerSync)
|
46 | };
|
47 | }
|
48 |
|
49 |
|
50 | const defaultLoaders = Object.freeze({
|
51 | '.cjs': _loaders.loaders.loadJs,
|
52 | '.js': _loaders.loaders.loadJs,
|
53 | '.json': _loaders.loaders.loadJson,
|
54 | '.yaml': _loaders.loaders.loadYaml,
|
55 | '.yml': _loaders.loaders.loadYaml,
|
56 | noExt: _loaders.loaders.loadYaml
|
57 | });
|
58 | exports.defaultLoaders = defaultLoaders;
|
59 |
|
60 | const identity = function identity(x) {
|
61 | return x;
|
62 | };
|
63 |
|
64 | function normalizeOptions(moduleName, options) {
|
65 | const defaults = {
|
66 | packageProp: moduleName,
|
67 | searchPlaces: ['package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `.${moduleName}rc.cjs`, `${moduleName}.config.js`, `${moduleName}.config.cjs`],
|
68 | ignoreEmptySearchPlaces: true,
|
69 | stopDir: _os.default.homedir(),
|
70 | cache: true,
|
71 | transform: identity,
|
72 | loaders: defaultLoaders
|
73 | };
|
74 | const normalizedOptions = { ...defaults,
|
75 | ...options,
|
76 | loaders: { ...defaults.loaders,
|
77 | ...options.loaders
|
78 | }
|
79 | };
|
80 | return normalizedOptions;
|
81 | }
|
82 |
|
\ | No newline at end of file |