Skip to content

Commit

Permalink
feat(config-conventional): use parser with short breaking change supp…
Browse files Browse the repository at this point in the history
…ort (#821)

* feat(load): add parser preset factory support

The latest conventional changelog parser options is loaded using a secondary promise. Load it before using the parserOpts property.

* refactor(config-conventional): use preset with short breaking change

* fix(config-conventional): define new parser as dependency
  • Loading branch information
byCedric authored Oct 16, 2019
1 parent ecac29f commit 4b5300a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions @commitlint/config-conventional/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'body-leading-blank': [1, 'always'],
'footer-leading-blank': [1, 'always'],
Expand Down
3 changes: 3 additions & 0 deletions @commitlint/config-conventional/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
"homepage": "https://github.com/conventional-changelog/commitlint#readme",
"devDependencies": {
"@commitlint/utils": "^8.2.0"
},
"dependencies": {
"conventional-changelog-conventionalcommits": "^4.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
parserOpts: {
parserPreset: './conventional-changelog-factory'
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = Promise.resolve().then(
() =>
function factory() {
return {
parserOpts: {
headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/
}
};
}
);
8 changes: 7 additions & 1 deletion @commitlint/load/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ export default async (seed = {}, options = {cwd: process.cwd()}) => {
// Resolve parserPreset key
if (typeof config.parserPreset === 'string') {
const resolvedParserPreset = resolveFrom(base, config.parserPreset);
let resolvedParserConfig = await require(resolvedParserPreset);

// Resolve loaded parser preset if its a factory
if (typeof resolvedParserConfig === 'function') {
resolvedParserConfig = await resolvedParserConfig();
}

config.parserPreset = {
name: config.parserPreset,
path: resolvedParserPreset,
parserOpts: (await require(resolvedParserPreset)).parserOpts
parserOpts: resolvedParserConfig.parserOpts
};
}

Expand Down
14 changes: 14 additions & 0 deletions @commitlint/load/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ test('uses seed with parserPreset', async t => {
});
});

test('uses seed with parserPreset factory', async t => {
const cwd = await git.bootstrap('fixtures/parser-preset-factory');
const {parserPreset: actual} = await load(
{
parserPreset: './conventional-changelog-factory'
},
{cwd}
);
t.is(actual.name, './conventional-changelog-factory');
t.deepEqual(actual.parserOpts, {
headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/
});
});

test('invalid extend should throw', async t => {
const cwd = await git.bootstrap('fixtures/extends-invalid');
await t.throws(load({}, {cwd}));
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3707,6 +3707,14 @@ conventional-changelog-angular@^5.0.3:
compare-func "^1.3.1"
q "^1.5.1"

conventional-changelog-conventionalcommits@^4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-4.1.0.tgz#eb7d47a9c5f1a6f9846a649482294e4ac50d7683"
integrity sha512-J3xolGrH8PTxpCqueHOuZtv3Cp73SQOWiBQzlsaugZAZ+hZgcJBonmC+1bQbfGs2neC2S18p2L1Gx+nTEglJTQ==
dependencies:
compare-func "^1.3.1"
q "^1.5.1"

conventional-changelog-core@^3.1.6:
version "3.1.6"
resolved "https://registry.npmjs.org/conventional-changelog-core/-/conventional-changelog-core-3.1.6.tgz#ac1731a461c50d150d29c1ad4f33143293bcd32f"
Expand Down

0 comments on commit 4b5300a

Please sign in to comment.