Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = async () => ({
rules: {
'body-case': [2, 'never', 'upper-case'],
},
});
3 changes: 3 additions & 0 deletions @commitlint/load/fixtures/async-config-function/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "async-config-function-test"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = Promise.resolve({
rules: {
'body-case': [2, 'never', 'upper-case'],
},
});
3 changes: 3 additions & 0 deletions @commitlint/load/fixtures/async-config-promise/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "async-config-promise-test"
}
22 changes: 22 additions & 0 deletions @commitlint/load/src/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,25 @@ test("default helpUrl should be loaded if not provided in shareable configs", as
"https://github.com/conventional-changelog/commitlint/#what-is-commitlint",
);
});

test("should resolve config exported as a Promise", async () => {
const cwd = await gitBootstrap("fixtures/async-config-promise");
const actual = await load({}, { cwd });

expect(actual.rules["body-case"]).toStrictEqual([
RuleConfigSeverity.Error,
"never",
"upper-case",
]);
});

test("should resolve config exported as an async function", async () => {
const cwd = await gitBootstrap("fixtures/async-config-function");
const actual = await load({}, { cwd });

expect(actual.rules["body-case"]).toStrictEqual([
RuleConfigSeverity.Error,
"never",
"upper-case",
]);
});
8 changes: 6 additions & 2 deletions @commitlint/load/src/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ export default async function load(
const configFilePath = loaded?.filepath;
let config: UserConfig = {};
if (loaded) {
validateConfig(loaded.filepath || "", loaded.config);
config = loaded.config;
const resolvedConfig =
typeof loaded.config === "function"
? await loaded.config()
: await loaded.config;
validateConfig(loaded.filepath || "", resolvedConfig);
config = resolvedConfig;
Comment thread
omar-y-abdi marked this conversation as resolved.
}

// Merge passed config with file based options
Expand Down
Loading