MCPcopy Create free account
hub / github.com/conventional-changelog/commitlint / load

Function load

@commitlint/load/src/load.ts:42–139  ·  view source on GitHub ↗
(
	seed: UserConfig = {},
	options: LoadOptions = {},
)

Source from the content-addressed store, hash-verified

40};
41
42export 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;

Callers 4

inputFunction · 0.85
loadConfigFunction · 0.85
prompterFunction · 0.85
load.test.tsFile · 0.85

Calls 8

validateConfigFunction · 0.90
resolveFromFunction · 0.90
loadParserPresetFunction · 0.90
resolveExtendsFunction · 0.85
loadPluginFunction · 0.85
resolveFormatterFunction · 0.85
loadParserOptsFunction · 0.85
loadConfigFunction · 0.50

Tested by

no test coverage detected