Skip to content

Commit

Permalink
refactor!: convert library to ESM (#111)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the package is now pure ESM
  • Loading branch information
sheerlox authored Nov 6, 2023
1 parent 8ab343c commit 3467a5f
Show file tree
Hide file tree
Showing 19 changed files with 963 additions and 2,247 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
root: true,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
env: {
node: true,
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ jobs:
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/coverage-final.json
fail_ci_if_error: true

# separate job to set as required status check in branch protection
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Commit types _originally_ from:

## Install

**Starting from v9, this package is a [pure ESM module](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)**, which will only work with `semantic-release@>=22`. If you cannot upgrade, you can keep using [v8](https://github.com/insurgent-lab/conventional-changelog-preset/tree/v8).

```bash
npm install --save-dev @insurgent/conventional-changelog-preset
```
Expand Down
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
'use strict';
import _ from 'lodash-es';

const _ = require('lodash');
const conventionalChangelogConventionalCommits =
require('conventional-changelog-conventionalcommits')();
const commitGroupsSort = require('./lib/commit-groups-compare');
const transform = require('./lib/commit-transform');
import conventionalChangelogConventionalCommits from 'conventional-changelog-conventionalcommits';

import commitGroupsSort from './lib/commit-groups-compare.js';
import transform from './lib/commit-transform.js';

async function createPreset() {
return conventionalChangelogConventionalCommits.then((preset) =>
return conventionalChangelogConventionalCommits().then((preset) =>
_.merge(preset, {
writerOpts: { transform, commitGroupsSort, groupBy: 'groupType' },
})
);
}

module.exports = createPreset;
export default createPreset;
10 changes: 4 additions & 6 deletions lib/commit-groups-compare.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const types = require('../types');
import { typesOrder } from '../types.js';

/**
* Comparison function to sort Commit Groups.
Expand All @@ -9,9 +7,9 @@ const types = require('../types');
* @param {Object} group2 commit group object with a `title` attribute.
* @return {integer} -1 if `group1` should be displayed before `group2`, 1 for the opposite and 0 if they are equals.
*/
module.exports = (group1, group2) => {
const idx1 = types.typesOrder.indexOf(group1.commits[0].type);
const idx2 = types.typesOrder.indexOf(group2.commits[0].type);
export default (group1, group2) => {
const idx1 = typesOrder.indexOf(group1.commits[0].type);
const idx2 = typesOrder.indexOf(group2.commits[0].type);

if (idx1 !== -1 && idx2 === -1) {
return -1;
Expand Down
15 changes: 6 additions & 9 deletions lib/commit-transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const types = require('../types');
import { types } from '../types.js';

const COMMIT_HASH_LENGTH = 7;

Expand All @@ -11,21 +9,20 @@ const COMMIT_HASH_LENGTH = 7;
* @param {Object} context `conventional-changelog` context.
* @return {Object} the transformed commit.
*/
module.exports = (commit, context) => {
export default (commit, context) => {
if (commit.notes) {
commit.notes.forEach((note) => {
note.title = 'Breaking changes';
});
}

if (
types.types[commit.type] &&
(types.types[commit.type].changelog ||
(commit.notes && commit.notes.length > 0))
types[commit.type] &&
(types[commit.type].changelog || (commit.notes && commit.notes.length > 0))
) {
commit.groupType = `${
types.types[commit.type].emoji ? `${types.types[commit.type].emoji} ` : ''
}${types.types[commit.type].title}`;
types[commit.type].emoji ? `${types[commit.type].emoji} ` : ''
}${types[commit.type].title}`;
} else {
return null;
}
Expand Down
Loading

0 comments on commit 3467a5f

Please sign in to comment.