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

Function loadConfig

@commitlint/load/src/utils/load-config.ts:15–72  ·  view source on GitHub ↗
(
	cwd: string,
	configPath?: string,
)

Source from the content-addressed store, hash-verified

13const searchStrategy = "global";
14
15export async function loadConfig(
16 cwd: string,
17 configPath?: string,
18): Promise<LoadConfigResult | null> {
19 let tsLoaderInstance: Loader | undefined;
20 const tsLoader: Loader = (...args) => {
21 if (!tsLoaderInstance) {
22 tsLoaderInstance = TypeScriptLoader();
23 }
24 return tsLoaderInstance(...args);
25 };
26
27 const explorer = cosmiconfig(moduleName, {
28 searchStrategy,
29 searchPlaces: [
30 // cosmiconfig overrides default searchPlaces if any new search place is added (For e.g. `*.ts` files),
31 // we need to manually merge default searchPlaces from https://github.com/davidtheclark/cosmiconfig#searchplaces
32 "package.json",
33 "package.yaml",
34 `.${moduleName}rc`,
35 `.${moduleName}rc.json`,
36 `.${moduleName}rc.yaml`,
37 `.${moduleName}rc.yml`,
38 `.${moduleName}rc.js`,
39 `.${moduleName}rc.cjs`,
40 `.${moduleName}rc.mjs`,
41 `${moduleName}.config.js`,
42 `${moduleName}.config.cjs`,
43 `${moduleName}.config.mjs`,
44
45 // files supported by TypescriptLoader
46 `.${moduleName}rc.ts`,
47 `.${moduleName}rc.cts`,
48 `.${moduleName}rc.mts`,
49 `${moduleName}.config.ts`,
50 `${moduleName}.config.cts`,
51 `${moduleName}.config.mts`,
52 ],
53 loaders: {
54 ".ts": tsLoader,
55 ".cts": tsLoader,
56 ".mts": tsLoader,
57 ".cjs": defaultLoaders[".cjs"],
58 ".js": defaultLoaders[".js"],
59 },
60 });
61
62 const explicitPath = configPath ? path.resolve(cwd, configPath) : undefined;
63 const explore = explicitPath ? explorer.load : explorer.search;
64 const searchPath = explicitPath ? explicitPath : cwd;
65 const local = await explore(searchPath);
66
67 if (local) {
68 return local;
69 }
70
71 return null;
72}

Callers 1

loadFunction · 0.50

Calls 1

resolveMethod · 0.80

Tested by

no test coverage detected