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
53 changes: 53 additions & 0 deletions .changeset/changelog.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const SHA_LENGTH = 8;

// NOTE: Returns `null` if the changeset has no commit yet (e.g. local)
const shortSha = (changeset) => {
return ((changeset.commit) ? changeset.commit.slice(0, SHA_LENGTH) : null);
}

module.exports = {
// Changelog line format:
// - <first line of summary> (<short SHA>)
// <continuation lines of summary>
// ...
getReleaseLine: async (changeset) => {
const summaryLines = changeset.summary.split('\n');
const trimmedLines = summaryLines.map((line) => line.trimEnd());
const [firstLine, ...continuationLines] = trimmedLines;

// Omit SHA suffix if the changeset has no commit (`null`)
const sha = shortSha(changeset);
const suffix = ((sha !== null) ? ` (${sha})` : '');

// SHA suffix is added only to first line of summary
let releaseLine = `- ${firstLine}${suffix}`;
if (continuationLines.length > 0) {
releaseLine += `\n${continuationLines.map((line) => ` ${line}`).join('\n')}`;
}
return releaseLine;
},

// Changelog dependency bump format:
// - Updated dependencies [<short SHA>, ...]
// - <dependency@version>
// - <...>
getDependencyReleaseLine: async (changesets, dependenciesUpdated) => {
if (dependenciesUpdated.length === 0) return '';

// Get one SHA per changeset
const changesetShas = changesets.map((changeset) => shortSha(changeset));
// Skip changesets with no commit (`null`)
const filteredShas = changesetShas.filter((sha) => (sha !== null));
// List each commit at most once
const shas = [...new Set(filteredShas)];
// Omit SHA suffix if there are no commits left after the above logic
const suffix = ((shas.length) > 0 ? ` [${shas.join(', ')}]` : '');

return [
`- Updated dependencies${suffix}`,
...dependenciesUpdated.map(
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`
),
].join('\n');
},
};
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://unpkg.com/@changesets/config@4.0.0/schema.json",
"baseBranch": "master",
"access": "public",
"changelog": "@changesets/cli/changelog",
"changelog": "./changelog.cjs",
"commit": false,
"ignore": [],
"fixed": [],
Expand Down