Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config-conventional): use parser with short breaking change support #821

Merged
merged 3 commits into from Oct 16, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions @commitlint/config-conventional/index.js
@@ -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
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"
}
}
@@ -0,0 +1,5 @@
module.exports = {
parserOpts: {
parserPreset: './conventional-changelog-factory'
}
};
@@ -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
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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added await here, just to make sure it works for async "factories". With the conventional parser, this is not necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marionebl @escapedcat I'm going to merge this for now, but feel free to ping me or respond here if this is not how you think it should be 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so yeah, I think I've answered my question here #830. Let me update and write a fix for this part, we need to update the code below // Await parser-preset if applicable. Luckily, I pushed this as a next release, so it won't affect users and it also doesn't crash 😄

}

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
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
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