Skip to content
Open
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
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@
"@manypkg/get-packages": "^1.1.3",
"@octokit/core": "^5.2.1",
"@octokit/plugin-throttling": "^8.0.0",
"@types/mdast": "^3.0.0",
"mdast-util-to-string": "^1.0.6",
"remark-parse": "^7.0.1",
"remark-stringify": "^7.0.3",
"mdast-util-to-string": "^4.0.0",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"semver": "^7.5.3",
"unified": "^8.3.2"
"unified": "^11.0.5"
},
"husky": {
"hooks": {}
Expand Down
12 changes: 6 additions & 6 deletions src/__snapshots__/run.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ exports[`version > creates simple PR 1`] = `

### Minor Changes

- Awesome feature
* Awesome feature

### Patch Changes

- Updated dependencies
- [email protected]
* Updated dependencies
* [email protected]

## [email protected]

### Minor Changes

- Awesome feature
* Awesome feature
",
"head": "changeset-release/some-branch",
"owner": "changesets",
Expand Down Expand Up @@ -85,7 +85,7 @@ exports[`version > doesn't include ignored package that got a dependency update

### Minor Changes

- Awesome feature
* Awesome feature
",
"head": "changeset-release/some-branch",
"owner": "changesets",
Expand All @@ -107,7 +107,7 @@ exports[`version > only includes bumped packages in the PR body 1`] = `

### Minor Changes

- Awesome feature
* Awesome feature
",
"head": "changeset-release/some-branch",
"owner": "changesets",
Expand Down
12 changes: 6 additions & 6 deletions src/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ exports[`it sorts the things right 1`] = `
exports[`it works 1`] = `
"### Major Changes

- [2164a779](https://github.com/keystonejs/keystone-5/commit/2164a779):
* [2164a779](https://github.com/keystonejs/keystone-5/commit/2164a779):

- Replace jade with pug because Jade was renamed to Pug, and \`jade\` package is outdated
* Replace jade with pug because Jade was renamed to Pug, and \`jade\` package is outdated

### Patch Changes

- [81dc0be5](https://github.com/keystonejs/keystone-5/commit/81dc0be5):
* [81dc0be5](https://github.com/keystonejs/keystone-5/commit/81dc0be5):

- Update dependencies
* Update dependencies
"
`;

exports[`it works 2`] = `
"### Patch Changes

- [19fe6c1b](https://github.com/keystonejs/keystone-5/commit/19fe6c1b):
* [19fe6c1b](https://github.com/keystonejs/keystone-5/commit/19fe6c1b):

Move frontmatter in docs into comments
Move frontmatter in docs into comments
"
`;
10 changes: 4 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import unified from "unified";
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkStringify from "remark-stringify";
import fs from "node:fs/promises";
import type { Root } from "mdast";
// @ts-ignore
import mdastToString from "mdast-util-to-string";
import { toString as mdastToString } from "mdast-util-to-string";
import { getPackages, type Package } from "@manypkg/get-packages";

export const BumpLevels = {
Expand Down Expand Up @@ -37,7 +35,7 @@ export async function getChangedPackages(
}

export function getChangelogEntry(changelog: string, version: string) {
let ast = unified().use(remarkParse).parse(changelog) as Root;
let ast = unified().use(remarkParse).parse(changelog);

Choose a reason for hiding this comment

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

Should you support GFM and/or frontmatter here? Is so, you should use remark-gfm / remark-frontmatter.

Unless you need options passed into the function, I recommend to define the processor once outside of the function. This way plugins can cache some of the heavy lifting. This isn’t really applicable to your case, but IMO it’s a good practice. If you use GFM/frontmatter, this also allows you to keep the processor in sync with the stringify processor you use below.

const processor = unified()
  .use(remarkParse)
  .use(remarkFrontmatter)
  .use(remarkGfm)
  .use(remarkStringify)

// …

let ast = processor.parse(changelog)

If you don’t want any of that, the remark abstractions don’t really offer much. You might as well use the slightly lower level mdast-util-from-markdown and mdast-util-to-markdown.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review! ❤️


let highestLevel: number = BumpLevels.dep;

Expand All @@ -53,7 +51,7 @@ export function getChangelogEntry(changelog: string, version: string) {
for (let i = 0; i < nodes.length; i++) {
let node = nodes[i];
if (node.type === "heading") {
let stringified: string = mdastToString(node);
let stringified = mdastToString(node);
let match = stringified.toLowerCase().match(/(major|minor|patch)/);
if (match !== null) {
let level = BumpLevels[match[0] as "major" | "minor" | "patch"];
Expand Down
Loading