Skip to content

Commit 5ee7d22

Browse files
committed
fix: simplify parserOpts resolution
1 parent 4ac0c5e commit 5ee7d22

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

@commitlint/load/src/utils/load-parser-opts.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ function isObjectLike(obj: unknown): obj is Record<string, unknown> {
44
return Boolean(obj) && typeof obj === 'object'; // typeof null === 'object'
55
}
66

7-
function isPromiseLike(obj: unknown): obj is Promise<unknown> {
8-
return isObjectLike(obj) && typeof (obj as any).then === 'function';
9-
}
10-
117
function isParserOptsFunction<T extends ParserPreset>(
128
obj: T
139
): obj is T & {
@@ -27,9 +23,19 @@ export async function loadParserOpts(
2723
// Await for the module, loaded with require
2824
const parser = await pendingParser;
2925

30-
// Await parser opts if applicable
31-
if (isPromiseLike(parser.parserOpts)) {
32-
parser.parserOpts = ((await parser.parserOpts) as any).parserOpts;
26+
// exit early if there is no opts
27+
if (!parser.parserOpts) {
28+
return parser;
29+
}
30+
31+
// Pull nested parserOpts, might happen if overwritten with a module in main config
32+
if (typeof parser.parserOpts === 'object') {
33+
// Await parser opts if applicable
34+
const opts = await parser.parserOpts;
35+
parser.parserOpts =
36+
isObjectLike(opts) && isObjectLike(opts.parserOpts)
37+
? opts.parserOpts
38+
: undefined;
3339
return parser;
3440
}
3541

@@ -61,12 +67,5 @@ export async function loadParserOpts(
6167
});
6268
}
6369

64-
// Pull nested parserOpts, might happen if overwritten with a module in main config
65-
if (
66-
isObjectLike(parser.parserOpts) &&
67-
typeof parser.parserOpts.parserOpts === 'object'
68-
) {
69-
parser.parserOpts = parser.parserOpts.parserOpts;
70-
}
7170
return parser;
7271
}

0 commit comments

Comments
 (0)