Skip to content

Commit c44950f

Browse files
committed
refactor(load): remove custom parser preset factory code
1 parent fbf2389 commit c44950f

File tree

8 files changed

+4
-74
lines changed

8 files changed

+4
-74
lines changed

@commitlint/load/fixtures/parser-preset-factory/commitlint.config.js

-5
This file was deleted.

@commitlint/load/fixtures/parser-preset-factory/conventional-changelog-factory.js

-10
This file was deleted.

@commitlint/load/fixtures/recursive-parser-preset-factory/commitlint.config.js

-3
This file was deleted.

@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/index.js

-3
This file was deleted.

@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/second-extended/conventional-changelog-factory.js

-10
This file was deleted.

@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/second-extended/index.js

-3
This file was deleted.

@commitlint/load/src/index.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,14 @@ export default async (seed = {}, options = {cwd: process.cwd()}) => {
3030
pick(config, 'extends', 'plugins', 'ignores', 'defaultIgnores')
3131
);
3232

33-
// Resolve parserPreset key from flat-non-extended config
33+
// Resolve parserPreset key
3434
if (typeof config.parserPreset === 'string') {
3535
const resolvedParserPreset = resolveFrom(base, config.parserPreset);
36-
let resolvedParserConfig = await require(resolvedParserPreset);
37-
38-
// Resolve loaded parser preset factory
39-
if (typeof resolvedParserConfig === 'function') {
40-
resolvedParserConfig = await resolvedParserConfig();
41-
}
4236

4337
config.parserPreset = {
4438
name: config.parserPreset,
4539
path: resolvedParserPreset,
46-
parserOpts: resolvedParserConfig.parserOpts
40+
parserOpts: (await require(resolvedParserPreset)).parserOpts
4741
};
4842
}
4943

@@ -61,14 +55,8 @@ export default async (seed = {}, options = {cwd: process.cwd()}) => {
6155
typeof preset.parserPreset.parserOpts === 'object' &&
6256
typeof preset.parserPreset.parserOpts.then === 'function'
6357
) {
64-
let parserPreset = await preset.parserPreset.parserOpts;
65-
66-
// Resolve loaded parser preset factory from extended config
67-
if (typeof parserPreset === 'function') {
68-
parserPreset = await parserPreset();
69-
}
70-
71-
preset.parserPreset.parserOpts = parserPreset.parserOpts;
58+
preset.parserPreset.parserOpts = (await preset.parserPreset
59+
.parserOpts).parserOpts;
7260
}
7361

7462
// Resolve config-relative formatter module

@commitlint/load/src/index.test.js

-24
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,6 @@ test('uses seed with parserPreset', async t => {
8484
});
8585
});
8686

87-
test('uses seed with parserPreset factory', async t => {
88-
const cwd = await git.bootstrap('fixtures/parser-preset-factory');
89-
const {parserPreset: actual} = await load(
90-
{
91-
parserPreset: './conventional-changelog-factory'
92-
},
93-
{cwd}
94-
);
95-
t.is(actual.name, './conventional-changelog-factory');
96-
t.deepEqual(actual.parserOpts, {
97-
headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/
98-
});
99-
});
100-
10187
test('invalid extend should throw', async t => {
10288
const cwd = await git.bootstrap('fixtures/extends-invalid');
10389
await t.throws(load({}, {cwd}));
@@ -228,16 +214,6 @@ test('recursive extends with parserPreset', async t => {
228214
);
229215
});
230216

231-
test('recursive extends with parserPreset factory', async t => {
232-
const cwd = await git.bootstrap('fixtures/recursive-parser-preset-factory');
233-
const actual = await load({}, {cwd});
234-
235-
t.is(actual.parserPreset.name, './conventional-changelog-factory');
236-
t.deepEqual(actual.parserPreset.parserOpts, {
237-
headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/
238-
});
239-
});
240-
241217
test('ignores unknow keys', async t => {
242218
const cwd = await git.bootstrap('fixtures/trash-file');
243219
const actual = await load({}, {cwd});

0 commit comments

Comments
 (0)