Skip to content

Commit

Permalink
fix(version): should not throw when changelog.md is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Jan 30, 2022
1 parent d0e94e3 commit eca9816
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/core/src/conventional-commits/read-existing-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ import { BLANK_LINE, COMMIT_GUIDELINE } from './constants';
export async function readExistingChangelog(pkg) {
const changelogFileLoc = path.join(pkg.location, 'CHANGELOG.md');

let chain: Promise<any> = Promise.resolve();

// catch allows missing file to pass without breaking chain
let changelogContents = await fs.readFile(changelogFileLoc, 'utf8');
chain = chain.then(() => fs.readFile(changelogFileLoc, 'utf8').catch(() => ''));

chain = chain.then((changelogContents) => {
// Remove the header if it exists, thus starting at the first entry.
const headerIndex = changelogContents.indexOf(COMMIT_GUIDELINE);

if (headerIndex !== -1) {
return changelogContents.substring(headerIndex + COMMIT_GUIDELINE.length + BLANK_LINE.length);
}

// Remove the header if it exists, thus starting at the first entry.
const headerIndex = changelogContents.indexOf(COMMIT_GUIDELINE);
return changelogContents;
});

if (headerIndex !== -1) {
changelogContents = changelogContents.substring(headerIndex + COMMIT_GUIDELINE.length + BLANK_LINE.length);
}
// consumer expects resolved tuple
chain = chain.then((changelogContents) => [changelogFileLoc, changelogContents]);

return [changelogFileLoc, changelogContents];
return chain;
}

0 comments on commit eca9816

Please sign in to comment.