Skip to content

Commit

Permalink
feat: lazy load cosmiconfig-typescript-loader (#3694)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Oct 14, 2023
1 parent 0281f55 commit b058c7c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions @commitlint/load/src/utils/load-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {cosmiconfig} from 'cosmiconfig';
import {cosmiconfig, type Loader} from 'cosmiconfig';
import {TypeScriptLoader} from 'cosmiconfig-typescript-loader';
import path from 'path';

Expand All @@ -13,7 +13,15 @@ export async function loadConfig(
configPath?: string
): Promise<LoadConfigResult | null> {
const moduleName = 'commitlint';
const tsLoader = TypeScriptLoader();

let tsLoaderInstance: Loader | undefined;
const tsLoader: Loader = (...args) => {
if (!tsLoaderInstance) {
tsLoaderInstance = TypeScriptLoader();
}
return tsLoaderInstance(...args);
};

const explorer = cosmiconfig(moduleName, {
searchPlaces: [
// cosmiconfig overrides default searchPlaces if any new search place is added (For e.g. `*.ts` files),
Expand Down

0 comments on commit b058c7c

Please sign in to comment.