UNPKG

1.52 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const file_resolver_1 = require("@markuplint/file-resolver");
4async function resolveConfigs(files, options) {
5 var _a;
6 const workspace = (_a = options.workspace) !== null && _a !== void 0 ? _a : process.cwd();
7 const configs = new Map();
8 if (options.config) {
9 let configSet;
10 if (typeof options.config === 'string') {
11 configSet = await file_resolver_1.loadConfigFile(options.config);
12 }
13 else {
14 const filePath = `${workspace}/__NO_FILE__`;
15 const _files = new Set([filePath]);
16 configSet = await file_resolver_1.recursiveLoad(options.config, filePath, _files, true);
17 }
18 if (configSet) {
19 for (const file of files) {
20 configs.set(file, configSet);
21 }
22 }
23 }
24 else {
25 let configSetNearbyCWD;
26 for (const file of files) {
27 const configSet = await file_resolver_1.searchConfigFile(file.path);
28 if (configSet) {
29 configs.set(file, configSet);
30 }
31 else {
32 if (!configSetNearbyCWD) {
33 configSetNearbyCWD = await file_resolver_1.searchConfigFile(workspace);
34 }
35 if (configSetNearbyCWD) {
36 configs.set(file, configSetNearbyCWD);
37 }
38 }
39 }
40 }
41 return configs;
42}
43exports.resolveConfigs = resolveConfigs;