(
seed: UserConfig = {},
options: LoadOptions = {},
)
| 40 | }; |
| 41 | |
| 42 | export default async function load( |
| 43 | seed: UserConfig = {}, |
| 44 | options: LoadOptions = {}, |
| 45 | ): Promise<QualifiedConfig> { |
| 46 | const cwd = typeof options.cwd === "undefined" ? process.cwd() : options.cwd; |
| 47 | const loaded = await loadConfig(cwd, options.file); |
| 48 | const baseDirectory = loaded?.filepath ? path.dirname(loaded.filepath) : cwd; |
| 49 | const configFilePath = loaded?.filepath; |
| 50 | let config: UserConfig = {}; |
| 51 | if (loaded) { |
| 52 | const resolvedConfig = |
| 53 | typeof loaded.config === "function" ? await loaded.config() : await loaded.config; |
| 54 | validateConfig(loaded.filepath || "", resolvedConfig); |
| 55 | config = resolvedConfig; |
| 56 | } |
| 57 | |
| 58 | // Merge passed config with file based options |
| 59 | config = merge( |
| 60 | { |
| 61 | extends: [], |
| 62 | plugins: [], |
| 63 | rules: {}, |
| 64 | }, |
| 65 | config, |
| 66 | seed, |
| 67 | ); |
| 68 | |
| 69 | // Resolve parserPreset key |
| 70 | if (typeof config.parserPreset === "string") { |
| 71 | const resolvedParserPreset = resolveFrom(config.parserPreset, configFilePath); |
| 72 | |
| 73 | config.parserPreset = { |
| 74 | name: config.parserPreset, |
| 75 | ...(await loadParserPreset(resolvedParserPreset)), |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | // Resolve extends key |
| 80 | const extended = await resolveExtends(config, { |
| 81 | prefix: "commitlint-config", |
| 82 | cwd: baseDirectory, |
| 83 | parserPreset: await config.parserPreset, |
| 84 | }); |
| 85 | |
| 86 | if (!extended.formatter || typeof extended.formatter !== "string") { |
| 87 | extended.formatter = "@commitlint/format"; |
| 88 | } |
| 89 | |
| 90 | let plugins: PluginRecords = {}; |
| 91 | if (Array.isArray(extended.plugins)) { |
| 92 | const deduplicatedPlugins = [...new Set(extended.plugins)]; |
| 93 | for (const plugin of deduplicatedPlugins) { |
| 94 | if (typeof plugin === "string") { |
| 95 | plugins = await loadPlugin(plugins, plugin, { |
| 96 | debug: process.env.DEBUG === "true", |
| 97 | }); |
| 98 | } else { |
| 99 | plugins.local = plugin; |
no test coverage detected