Skip to content

Commit 0a736b6

Browse files
authored
BREAKING: Bump prettier to ^3.3.3 (#202)
* Bump `prettier` to `^3.3.3` * Update APIs to support Prettier 3 * Fix engines field * Set Prettier peer dependency range to `>=3.0.0`
1 parent b07f539 commit 0a736b6

File tree

12 files changed

+1347
-2703
lines changed

12 files changed

+1347
-2703
lines changed

.prettierrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ module.exports = {
55
singleQuote: true,
66
tabWidth: 2,
77
trailingComma: 'all',
8+
plugins: ['prettier-plugin-packagejson'],
89
};

package.json

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22
"name": "@metamask/auto-changelog",
33
"version": "3.4.4",
44
"description": "Utilities for validating and updating \"Keep a Changelog\" formatted changelogs",
5-
"publishConfig": {
6-
"registry": "https://registry.npmjs.org/",
7-
"access": "public"
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/MetaMask/auto-changelog.git"
88
},
9+
"license": "(MIT OR Apache-2.0)",
910
"main": "dist/index.js",
1011
"bin": "dist/cli.js",
11-
"engines": {
12-
"node": "^18.18 || >=20"
13-
},
1412
"files": [
1513
"dist/"
1614
],
17-
"repository": {
18-
"type": "git",
19-
"url": "https://github.com/MetaMask/auto-changelog.git"
20-
},
21-
"license": "(MIT OR Apache-2.0)",
2215
"scripts": {
23-
"test": "jest",
24-
"test:watch": "jest --watch",
25-
"prepack": "./scripts/prepack.sh",
26-
"lint:eslint": "eslint . --cache --ext js,ts",
27-
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore",
16+
"build": "tsc --project tsconfig.build.json",
17+
"build:clean": "rimraf dist && yarn build",
18+
"changelog": "node dist/cli.js",
2819
"lint": "yarn lint:eslint && yarn lint:misc --check",
20+
"lint:eslint": "eslint . --cache --ext js,ts",
2921
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
30-
"build:clean": "rimraf dist && yarn build",
31-
"build": "tsc --project tsconfig.build.json",
32-
"changelog": "node dist/cli.js"
22+
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore",
23+
"prepack": "./scripts/prepack.sh",
24+
"test": "jest",
25+
"test:watch": "jest --watch"
3326
},
3427
"dependencies": {
3528
"diff": "^5.0.0",
3629
"execa": "^5.1.1",
37-
"prettier": "^2.8.8",
3830
"semver": "^7.3.5",
3931
"yargs": "^17.0.1"
4032
},
@@ -52,22 +44,34 @@
5244
"@typescript-eslint/eslint-plugin": "^5.42.1",
5345
"@typescript-eslint/parser": "^5.42.1",
5446
"eslint": "^8.40.0",
55-
"eslint-config-prettier": "^8.5.0",
47+
"eslint-config-prettier": "^9.1.0",
5648
"eslint-plugin-import": "^2.26.0",
5749
"eslint-plugin-jest": "^27.1.5",
5850
"eslint-plugin-jsdoc": "^39.6.2",
5951
"eslint-plugin-node": "^11.1.0",
60-
"eslint-plugin-prettier": "^4.2.1",
61-
"jest": "^26.4.2",
52+
"eslint-plugin-prettier": "^5.2.1",
53+
"jest": "^29.7.0",
6254
"outdent": "^0.8.0",
55+
"prettier": "^3.3.3",
56+
"prettier-plugin-packagejson": "^2.5.2",
6357
"rimraf": "^3.0.2",
64-
"ts-jest": "^26.5.6",
58+
"ts-jest": "^29.2.5",
6559
"typescript": "~4.8.4"
6660
},
61+
"peerDependencies": {
62+
"prettier": ">=3.0.0"
63+
},
64+
"packageManager": "yarn@3.2.4",
65+
"engines": {
66+
"node": "^18.18 || >=20"
67+
},
68+
"publishConfig": {
69+
"access": "public",
70+
"registry": "https://registry.npmjs.org/"
71+
},
6772
"lavamoat": {
6873
"allowScripts": {
6974
"@lavamoat/preinstall-always-fail": false
7075
}
71-
},
72-
"packageManager": "yarn@3.2.4"
76+
}
7377
}

src/changelog.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
`;
1313

1414
describe('Changelog', () => {
15-
it('should allow creating an empty changelog', () => {
15+
it('should allow creating an empty changelog', async () => {
1616
const changelog = new Changelog({
1717
repoUrl: 'fake://metamask.io',
1818
});
19-
expect(changelog.toString()).toStrictEqual(emptyChangelog);
19+
20+
expect(await changelog.toString()).toStrictEqual(emptyChangelog);
2021
});
2122

22-
it('should allow creating an empty changelog with a custom tag prefix', () => {
23+
it('should allow creating an empty changelog with a custom tag prefix', async () => {
2324
const changelog = new Changelog({
2425
repoUrl: 'fake://metamask.io',
2526
tagPrefix: 'example@v',
2627
});
27-
expect(changelog.toString()).toStrictEqual(emptyChangelog);
28+
29+
expect(await changelog.toString()).toStrictEqual(emptyChangelog);
2830
});
2931
});

src/changelog.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as markdown from 'prettier/plugins/markdown';
2+
import { format as formatWithPrettier } from 'prettier/standalone';
13
import semver from 'semver';
24

35
import {
@@ -8,6 +10,19 @@ import {
810
} from './constants';
911
import { PackageRename } from './shared-types';
1012

13+
/**
14+
* Format a Markdown changelog string.
15+
*
16+
* @param changelog - The changelog string to format.
17+
* @returns The formatted changelog string.
18+
*/
19+
export async function format(changelog: string): Promise<string> {
20+
return formatWithPrettier(changelog, {
21+
parser: 'markdown',
22+
plugins: [markdown],
23+
});
24+
}
25+
1126
/**
1227
* `Object.getOwnPropertyNames()` is intentionally generic: it returns the
1328
* immediate property names of an object, but it cannot make guarantees about
@@ -37,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3752
/**
3853
* Formatter function that formats a Markdown changelog string.
3954
*/
40-
export type Formatter = (changelog: string) => string;
55+
export type Formatter = (changelog: string) => string | Promise<string>;
4156

4257
type ReleaseMetadata = {
4358
/**
@@ -571,7 +586,7 @@ export default class Changelog {
571586
*
572587
* @returns The stringified changelog.
573588
*/
574-
toString(): string {
589+
async toString(): Promise<string> {
575590
const changelog = `${changelogTitle}
576591
${changelogDescription}
577592
@@ -584,6 +599,6 @@ ${stringifyLinkReferenceDefinitions(
584599
this.#packageRename,
585600
)}`;
586601

587-
return this.#formatter(changelog);
602+
return await this.#formatter(changelog);
588603
}
589604
}

src/cli.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import { promises as fs, constants as fsConstants } from 'fs';
44
import path from 'path';
5-
import prettier from 'prettier';
65
import semver from 'semver';
76
import type { Argv } from 'yargs';
87
import { hideBin } from 'yargs/helpers';
98
import yargs from 'yargs/yargs';
109

11-
import { Formatter } from './changelog';
10+
import { format, Formatter } from './changelog';
1211
import { unreleased, Version } from './constants';
1312
import { generateDiff } from './generate-diff';
1413
import { createEmptyChangelog } from './init';
@@ -184,7 +183,7 @@ async function validate({
184183
const changelogContent = await readChangelog(changelogPath);
185184

186185
try {
187-
validateChangelog({
186+
await validateChangelog({
188187
changelogContent,
189188
currentVersion,
190189
repoUrl,
@@ -239,7 +238,7 @@ type InitOptions = {
239238
* @param options.tagPrefix - The prefix used in tags before the version number.
240239
*/
241240
async function init({ changelogPath, repoUrl, tagPrefix }: InitOptions) {
242-
const changelogContent = createEmptyChangelog({ repoUrl, tagPrefix });
241+
const changelogContent = await createEmptyChangelog({ repoUrl, tagPrefix });
243242
await saveChangelog(changelogPath, changelogContent);
244243
}
245244

@@ -466,10 +465,8 @@ async function main() {
466465
}
467466
}
468467

469-
const formatter = (changelog: string) => {
470-
return usePrettier
471-
? prettier.format(changelog, { parser: 'markdown' })
472-
: changelog;
468+
const formatter = async (changelog: string) => {
469+
return usePrettier ? await format(changelog) : changelog;
473470
};
474471

475472
if (command === 'update') {

src/generate-diff.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ const testCases = [
318318

319319
describe('generateDiff', () => {
320320
for (const { description, before, after, expected } of testCases) {
321-
it(`${description}`, () => {
321+
it(`${description}`, async () => {
322322
const diff = generateDiff(before, after);
323323
expect(diff).toStrictEqual(expected);
324324
});

src/init.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createEmptyChangelog } from './init';
22

33
const exampleRepoUrl =
44
'https://github.com/ExampleUsernameOrOrganization/ExampleRepository/';
5+
56
const emptyChangelog = `# Changelog
67
All notable changes to this project will be documented in this file.
78
@@ -14,15 +15,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1415
`;
1516

1617
describe('createEmptyChangelog', () => {
17-
it('creates an empty changelog', () => {
18-
expect(createEmptyChangelog({ repoUrl: exampleRepoUrl })).toStrictEqual(
19-
emptyChangelog,
20-
);
18+
it('creates an empty changelog', async () => {
19+
expect(
20+
await createEmptyChangelog({ repoUrl: exampleRepoUrl }),
21+
).toStrictEqual(emptyChangelog);
2122
});
2223

23-
it('creates an empty changelog with a custom tag prefix', () => {
24+
it('creates an empty changelog with a custom tag prefix', async () => {
2425
expect(
25-
createEmptyChangelog({ repoUrl: exampleRepoUrl, tagPrefix: 'foo' }),
26+
await createEmptyChangelog({ repoUrl: exampleRepoUrl, tagPrefix: 'foo' }),
2627
).toStrictEqual(emptyChangelog);
2728
});
2829
});

src/init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import Changelog from './changelog';
88
* @param options.tagPrefix - The prefix used in tags before the version number.
99
* @returns The initial changelog text.
1010
*/
11-
export function createEmptyChangelog({
11+
export async function createEmptyChangelog({
1212
repoUrl,
1313
tagPrefix = 'v',
1414
}: {
1515
repoUrl: string;
1616
tagPrefix?: string;
1717
}) {
1818
const changelog = new Changelog({ repoUrl, tagPrefix });
19-
return changelog.toString();
19+
return await changelog.toString();
2020
}

src/update-changelog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export async function updateChangelog({
310310
});
311311
}
312312

313-
const newChangelogContent = changelog.toString();
313+
const newChangelogContent = await changelog.toString();
314314
const isChangelogUpdated = changelogContent !== newChangelogContent;
315315
return isChangelogUpdated ? newChangelogContent : undefined;
316316
}

0 commit comments

Comments
 (0)