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

Update remark, unified and mdast packages #306

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 @@ -42,20 +42,19 @@
"@manypkg/get-packages": "^1.1.3",
"@octokit/plugin-throttling": "^5.2.1",
"fs-extra": "^8.1.0",
"mdast-util-to-string": "^1.0.6",
"remark-parse": "^7.0.1",
"remark-stringify": "^7.0.3",
"mdast-util-to-string": "^3.2.0",
"remark-parse": "^10.0.2",
"remark-stringify": "^10.0.3",
"resolve-from": "^5.0.0",
"semver": "^7.5.3",
"unified": "^8.3.2"
"unified": "^10.1.2"
},
"husky": {
"hooks": {}
},
"prettier": {},
"resolutions": {
"**/@octokit/core": "4.2.0",
"trim": "^0.0.3",
"y18n": "^4.0.1"
}
}
10 changes: 8 additions & 2 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ const createRelease = async (

let changelog = await fs.readFile(changelogFileName, "utf8");

let changelogEntry = getChangelogEntry(changelog, pkg.packageJson.version);
let changelogEntry = await getChangelogEntry(
changelog,
pkg.packageJson.version
);
if (!changelogEntry) {
// we can find a changelog but not the entry for this version
// if this is true, something has probably gone wrong
Expand Down Expand Up @@ -352,7 +355,10 @@ export async function runVersion({
"utf8"
);

let entry = getChangelogEntry(changelogContents, pkg.packageJson.version);
let entry = await getChangelogEntry(
changelogContents,
pkg.packageJson.version
);
return {
highestLevel: entry.highestLevel,
private: !!pkg.packageJson.private,
Expand Down
8 changes: 4 additions & 4 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ let changelog = `# @keystone-alpha/email
- Update mjml-dependency
`;

test("it works", () => {
let entry = getChangelogEntry(changelog, "3.0.0");
test("it works", async () => {
let entry = await getChangelogEntry(changelog, "3.0.0");
expect(entry.content).toMatchSnapshot();
expect(entry.highestLevel).toBe(BumpLevels.major);
});

test("it works", () => {
let entry = getChangelogEntry(changelog, "3.0.1");
test("it works", async () => {
let entry = await getChangelogEntry(changelog, "3.0.1");
expect(entry.content).toMatchSnapshot();
expect(entry.highestLevel).toBe(BumpLevels.patch);
});
Expand Down
14 changes: 7 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import unified from "unified";
import remarkParse from "remark-parse";
import remarkStringify from "remark-stringify";
// @ts-ignore
import mdastToString from "mdast-util-to-string";
import { getPackages, Package } from "@manypkg/get-packages";

export const BumpLevels = {
Expand Down Expand Up @@ -34,7 +29,12 @@ export async function getChangedPackages(
return [...changedPackages];
}

export function getChangelogEntry(changelog: string, version: string) {
export async function getChangelogEntry(changelog: string, version: string) {
const { unified } = await import("unified");
const remarkParse = (await import("remark-parse")).default;
const remarkStringify = (await import("remark-stringify")).default;
const mdast = await import("mdast-util-to-string");

let ast = unified().use(remarkParse).parse(changelog);

let highestLevel: number = BumpLevels.dep;
Expand All @@ -51,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 = mdast.toString(node);
let match = stringified.toLowerCase().match(/(major|minor|patch)/);
if (match !== null) {
let level = BumpLevels[match[0] as "major" | "minor" | "patch"];
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
Expand Down Expand Up @@ -39,7 +39,7 @@
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"moduleResolution": "bundler" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
Expand Down
Loading