@mui/internal-code-infra 0.1.1-canary.38 → 0.1.1-canary.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/changelog/changelogGrouping.d.mts +52 -0
- package/build/changelog/changelogMarkdown.d.mts +69 -0
- package/build/changelog/changelogTitle.d.mts +28 -0
- package/build/changelog/index.d.mts +11 -0
- package/build/changelog/types.d.ts +21 -0
- package/package.json +19 -19
- package/src/changelog/changelogChanges.mjs +3 -0
- package/src/changelog/changelogGrouping.mjs +148 -0
- package/src/changelog/changelogMarkdown.mjs +110 -0
- package/src/changelog/changelogTitle.mjs +56 -0
- package/src/changelog/index.mjs +22 -0
- package/src/changelog/types.ts +25 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export type ChangelogChange = import('./types.ts').ChangelogChange;
|
|
2
|
+
export type ChangelogAuthor = import('./types.ts').ChangelogAuthor;
|
|
3
|
+
export type ChangelogCredits = import('./types.ts').ChangelogCredits;
|
|
4
|
+
/**
|
|
5
|
+
* The labels of a change, and the ones its title prefixes stand for. A label wins over the prefixes
|
|
6
|
+
* for its kind, the part before the colon: `scope: charts` leaves the scopes of the title out.
|
|
7
|
+
*
|
|
8
|
+
* @param {Pick<ChangelogChange, 'labels' | 'title'>} change
|
|
9
|
+
* @param {Record<string, readonly string[]>} [prefixes] - Labels that a prefix stands for, with the
|
|
10
|
+
* prefix spelled in any way
|
|
11
|
+
* @returns {string[]}
|
|
12
|
+
*/
|
|
13
|
+
export declare function readLabels(change: Pick<ChangelogChange, 'labels' | 'title'>, prefixes?: Record<string, readonly string[]>): string[];
|
|
14
|
+
/**
|
|
15
|
+
* The values of one kind of label: `labelValues(['scope: charts', 'docs'], 'scope')` is `['charts']`.
|
|
16
|
+
*
|
|
17
|
+
* @param {readonly string[]} labels
|
|
18
|
+
* @param {string} kind
|
|
19
|
+
* @returns {string[]}
|
|
20
|
+
*/
|
|
21
|
+
export declare function labelValues(labels: readonly string[], kind: string): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Groups items that can be in several groups, or in none. Items keep their order.
|
|
24
|
+
*
|
|
25
|
+
* @template Item
|
|
26
|
+
* @template {string} Group
|
|
27
|
+
* @param {Iterable<Item>} items
|
|
28
|
+
* @param {(item: Item) => Group | readonly Group[] | null | undefined} getGroups
|
|
29
|
+
* @returns {Map<Group, Item[]>}
|
|
30
|
+
*/
|
|
31
|
+
export declare function groupBy<Item, Group extends string>(items: Iterable<Item>, getGroups: (item: Item) => Group | readonly Group[] | null | undefined): Map<Group, Item[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Sorts by prefixes, then by the rest of the title. Changes of the same title are sorted by pull
|
|
34
|
+
* request, so that the order never depends on the order they are given in.
|
|
35
|
+
*
|
|
36
|
+
* @template {Pick<ChangelogChange, 'title' | 'pullRequest' | 'sha'>} Change
|
|
37
|
+
* @param {Iterable<Change>} changes
|
|
38
|
+
* @returns {Change[]}
|
|
39
|
+
*/
|
|
40
|
+
export declare function sortByTitle<Change extends Pick<ChangelogChange, 'title' | 'pullRequest' | 'sha'>>(changes: Iterable<Change>): Change[];
|
|
41
|
+
/**
|
|
42
|
+
* The authors of changes, once each and in alphabetical order. Someone who joined the team during
|
|
43
|
+
* the release is credited as team.
|
|
44
|
+
*
|
|
45
|
+
* @param {Iterable<Pick<ChangelogChange, 'author'>>} changes
|
|
46
|
+
* @param {Object} [options]
|
|
47
|
+
* @param {readonly string[]} [options.exclude] - Logins
|
|
48
|
+
* @returns {ChangelogCredits}
|
|
49
|
+
*/
|
|
50
|
+
export declare function creditAuthors(changes: Iterable<Pick<ChangelogChange, 'author'>>, { exclude }?: {
|
|
51
|
+
exclude?: readonly string[];
|
|
52
|
+
}): ChangelogCredits;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
|
|
3
|
+
* @typedef {import('./types.ts').ChangelogChange} ChangelogChange
|
|
4
|
+
* @typedef {import('./types.ts').ChangelogData} ChangelogData
|
|
5
|
+
* @typedef {import('./types.ts').MarkdownBlock} MarkdownBlock
|
|
6
|
+
* @typedef {import('./types.ts').MarkdownInline} MarkdownInline
|
|
7
|
+
*/
|
|
8
|
+
export type ChangelogAuthor = import('./types.ts').ChangelogAuthor;
|
|
9
|
+
export type ChangelogChange = import('./types.ts').ChangelogChange;
|
|
10
|
+
export type ChangelogData = import('./types.ts').ChangelogData;
|
|
11
|
+
export type MarkdownBlock = import('./types.ts').MarkdownBlock;
|
|
12
|
+
export type MarkdownInline = import('./types.ts').MarkdownInline;
|
|
13
|
+
/**
|
|
14
|
+
* Joins blocks with a blank line in between. Empty ones are left out. Blank lines inside a block,
|
|
15
|
+
* such as the ones of a code block, stay as they are.
|
|
16
|
+
*
|
|
17
|
+
* @param {...MarkdownBlock} blocks
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
export declare function joinBlocks(...blocks: MarkdownBlock[]): string;
|
|
21
|
+
/**
|
|
22
|
+
* A heading and what is below it, or nothing when there is nothing below it.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} heading
|
|
25
|
+
* @param {...MarkdownBlock} blocks
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
export declare function section(heading: string, ...blocks: MarkdownBlock[]): string;
|
|
29
|
+
/**
|
|
30
|
+
* @param {Iterable<MarkdownInline>} items
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
export declare function bulletList(items: Iterable<MarkdownInline>): string;
|
|
34
|
+
/**
|
|
35
|
+
* Joins the parts of a line with a space. Empty ones are left out.
|
|
36
|
+
*
|
|
37
|
+
* @param {...MarkdownInline} parts
|
|
38
|
+
* @returns {string}
|
|
39
|
+
*/
|
|
40
|
+
export declare function joinWords(...parts: MarkdownInline[]): string;
|
|
41
|
+
/**
|
|
42
|
+
* `#123`, or the short SHA of a change without a pull request.
|
|
43
|
+
*
|
|
44
|
+
* @param {Pick<ChangelogChange, 'pullRequest' | 'sha'>} change
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
export declare function formatReference({ pullRequest, sha }: Pick<ChangelogChange, 'pullRequest' | 'sha'>): string;
|
|
48
|
+
/**
|
|
49
|
+
* `@login`, or the name of an author without a GitHub account. Empty when neither is known.
|
|
50
|
+
*
|
|
51
|
+
* @param {Pick<ChangelogAuthor, 'login' | 'name'> | null} author
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatAuthor(author: Pick<ChangelogAuthor, 'login' | 'name'> | null): string;
|
|
55
|
+
/**
|
|
56
|
+
* `Jan 2, 2026`, in UTC like the date of a release.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} date - ISO 8601
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
export declare function formatDate(date: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* What is below the heading of a release: a comment with the range it was generated from, and its
|
|
64
|
+
* date.
|
|
65
|
+
*
|
|
66
|
+
* @param {Pick<ChangelogData, 'previous' | 'release' | 'date'>} data
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
export declare function formatSubHeader({ previous, release, date }: Pick<ChangelogData, 'previous' | 'release' | 'date'>): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./types.ts').ChangelogTitle} ChangelogTitle
|
|
3
|
+
*/
|
|
4
|
+
export type ChangelogTitle = import('./types.ts').ChangelogTitle;
|
|
5
|
+
/**
|
|
6
|
+
* Splits the leading `[prefixes]` off a title.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} title
|
|
9
|
+
* @returns {ChangelogTitle}
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseTitle(title: string): ChangelogTitle;
|
|
12
|
+
/**
|
|
13
|
+
* The candidate that a prefix is a spelling of: case, spaces, hyphens and underscores don't matter.
|
|
14
|
+
*
|
|
15
|
+
* @template {string} Candidate
|
|
16
|
+
* @param {string} prefix
|
|
17
|
+
* @param {Iterable<Candidate>} candidates
|
|
18
|
+
* @returns {Candidate | undefined}
|
|
19
|
+
*/
|
|
20
|
+
export declare function matchPrefix<Candidate extends string>(prefix: string, candidates: Iterable<Candidate>): Candidate | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Rewrites the prefixes of a title. Duplicates and prefixes that become empty are left out.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} title
|
|
25
|
+
* @param {(prefix: string) => string} rewrite
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
export declare function mapPrefixes(title: string, rewrite: (prefix: string) => string): string;
|
|
@@ -6,15 +6,26 @@ export type ChangelogData = import('./types.ts').ChangelogData;
|
|
|
6
6
|
export type ChangelogChange = import('./types.ts').ChangelogChange;
|
|
7
7
|
export type ChangelogAuthor = import('./types.ts').ChangelogAuthor;
|
|
8
8
|
export type ChangelogPackage = import('./types.ts').ChangelogPackage;
|
|
9
|
+
export type ChangelogTitle = import('./types.ts').ChangelogTitle;
|
|
10
|
+
export type ChangelogCredits = import('./types.ts').ChangelogCredits;
|
|
11
|
+
export type MarkdownBlock = import('./types.ts').MarkdownBlock;
|
|
12
|
+
export type MarkdownInline = import('./types.ts').MarkdownInline;
|
|
9
13
|
/**
|
|
10
14
|
* @typedef {import('./types.ts').FetchChangelogDataOptions} FetchChangelogDataOptions
|
|
11
15
|
* @typedef {import('./types.ts').ChangelogData} ChangelogData
|
|
12
16
|
* @typedef {import('./types.ts').ChangelogChange} ChangelogChange
|
|
13
17
|
* @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
|
|
14
18
|
* @typedef {import('./types.ts').ChangelogPackage} ChangelogPackage
|
|
19
|
+
* @typedef {import('./types.ts').ChangelogTitle} ChangelogTitle
|
|
20
|
+
* @typedef {import('./types.ts').ChangelogCredits} ChangelogCredits
|
|
21
|
+
* @typedef {import('./types.ts').MarkdownBlock} MarkdownBlock
|
|
22
|
+
* @typedef {import('./types.ts').MarkdownInline} MarkdownInline
|
|
15
23
|
*/
|
|
16
24
|
export { generateChangelog } from './generateChangelog.mjs';
|
|
17
25
|
export * from './loadChangelogConfig.mjs';
|
|
18
26
|
export * from './fetchChangelogs.mjs';
|
|
19
27
|
export { fetchChangelogData } from './fetchChangelogData.mjs';
|
|
28
|
+
export { creditAuthors, groupBy, labelValues, readLabels, sortByTitle, } from './changelogGrouping.mjs';
|
|
29
|
+
export { bulletList, formatAuthor, formatDate, formatReference, formatSubHeader, joinBlocks, joinWords, section, } from './changelogMarkdown.mjs';
|
|
30
|
+
export { mapPrefixes, matchPrefix, parseTitle } from './changelogTitle.mjs';
|
|
20
31
|
export { findLatestTaggedVersion } from '../utils/git.mjs';
|
|
@@ -430,6 +430,10 @@ export interface ChangelogChange {
|
|
|
430
430
|
*/
|
|
431
431
|
url: string;
|
|
432
432
|
labels: string[];
|
|
433
|
+
/**
|
|
434
|
+
* Whether the pull request has the `breaking` or the `breaking change` label.
|
|
435
|
+
*/
|
|
436
|
+
isBreakingChange: boolean;
|
|
433
437
|
pullRequest: {
|
|
434
438
|
number: number;
|
|
435
439
|
title: string;
|
|
@@ -527,3 +531,20 @@ export interface FetchChangelogDataOptions {
|
|
|
527
531
|
*/
|
|
528
532
|
octokit?: Octokit;
|
|
529
533
|
}
|
|
534
|
+
/**
|
|
535
|
+
* Title of a change, split into its leading `[prefixes]` and the rest.
|
|
536
|
+
*/
|
|
537
|
+
export interface ChangelogTitle {
|
|
538
|
+
prefixes: string[];
|
|
539
|
+
text: string;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Authors to credit, once each.
|
|
543
|
+
*/
|
|
544
|
+
export interface ChangelogCredits {
|
|
545
|
+
all: ChangelogAuthor[];
|
|
546
|
+
team: ChangelogAuthor[];
|
|
547
|
+
community: ChangelogAuthor[];
|
|
548
|
+
}
|
|
549
|
+
export type MarkdownInline = string | false | null | undefined;
|
|
550
|
+
export type MarkdownBlock = MarkdownInline | readonly MarkdownBlock[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-code-infra",
|
|
3
|
-
"version": "0.1.1-canary.
|
|
3
|
+
"version": "0.1.1-canary.39",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "Infra scripts and configs to be used across MUI repos.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"code-infra": "./bin/code-infra.mjs"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@argos-ci/core": "6.
|
|
56
|
+
"@argos-ci/core": "6.9.2",
|
|
57
57
|
"@babel/cli": "^8.1.0",
|
|
58
|
-
"@babel/core": "^8.1.
|
|
58
|
+
"@babel/core": "^8.1.3",
|
|
59
59
|
"@babel/helper-compilation-targets": "^8.0.7",
|
|
60
60
|
"@babel/plugin-syntax-jsx": "^8.0.1",
|
|
61
61
|
"@babel/plugin-syntax-typescript": "^8.0.3",
|
|
@@ -67,11 +67,11 @@
|
|
|
67
67
|
"@eslint/compat": "^2.1.1",
|
|
68
68
|
"@eslint/js": "^10.0.1",
|
|
69
69
|
"@eslint/json": "^2.1.1",
|
|
70
|
-
"@inquirer/confirm": "^6.4.
|
|
71
|
-
"@inquirer/select": "^5.3.
|
|
72
|
-
"@mui/internal-babel-plugin-display-name": "2.0.1-canary.
|
|
73
|
-
"@mui/internal-babel-plugin-minify-errors": "3.0.1-canary.
|
|
74
|
-
"@mui/internal-babel-plugin-resolve-imports": "3.0.1-canary.
|
|
70
|
+
"@inquirer/confirm": "^6.4.1",
|
|
71
|
+
"@inquirer/select": "^5.3.1",
|
|
72
|
+
"@mui/internal-babel-plugin-display-name": "2.0.1-canary.5",
|
|
73
|
+
"@mui/internal-babel-plugin-minify-errors": "3.0.1-canary.5",
|
|
74
|
+
"@mui/internal-babel-plugin-resolve-imports": "3.0.1-canary.6",
|
|
75
75
|
"@napi-rs/keyring": "^2.1.2",
|
|
76
76
|
"@octokit/auth-action": "^6.0.3",
|
|
77
77
|
"@octokit/oauth-methods": "^6.0.5",
|
|
@@ -79,20 +79,20 @@
|
|
|
79
79
|
"@octokit/plugin-throttling": "^11.0.5",
|
|
80
80
|
"@octokit/rest": "^22.0.1",
|
|
81
81
|
"@octokit/types": "^18.0.0",
|
|
82
|
-
"@pnpm/config.version-policy": "^1100.2.
|
|
82
|
+
"@pnpm/config.version-policy": "^1100.2.11",
|
|
83
83
|
"@pnpm/find-workspace-dir": "^1000.1.5",
|
|
84
84
|
"@pnpm/parse-wanted-dependency": "^1001.0.0",
|
|
85
85
|
"@types/babel__core": "^7.20.5",
|
|
86
86
|
"@types/estree": "^1.0.10",
|
|
87
87
|
"@types/mdast": "^4.0.4",
|
|
88
|
-
"@typescript-eslint/types": "^8.
|
|
89
|
-
"@typescript-eslint/utils": "^8.
|
|
88
|
+
"@typescript-eslint/types": "^8.73.0",
|
|
89
|
+
"@typescript-eslint/utils": "^8.73.0",
|
|
90
90
|
"@vitest/eslint-plugin": "^1.6.28",
|
|
91
91
|
"babel-plugin-optimize-clsx": "^2.6.2",
|
|
92
92
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
93
93
|
"babel-plugin-transform-import-meta": "^3.1.0",
|
|
94
94
|
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
|
|
95
|
-
"babel-plugin-transform-remove-imports": "^1.8.
|
|
95
|
+
"babel-plugin-transform-remove-imports": "^1.8.3",
|
|
96
96
|
"chalk": "^6.0.1",
|
|
97
97
|
"clipboardy": "^5.3.2",
|
|
98
98
|
"content-type": "^3.1.1",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"globals": "^17.14.0",
|
|
117
117
|
"globby": "^16.2.4",
|
|
118
118
|
"html-validate": "^11.21.1",
|
|
119
|
-
"minimatch": "^11.0.
|
|
119
|
+
"minimatch": "^11.0.9",
|
|
120
120
|
"node-html-parser": "^9.0.7",
|
|
121
121
|
"open": "^11.0.4",
|
|
122
122
|
"postcss-styled-syntax": "^0.7.4",
|
|
@@ -143,9 +143,9 @@
|
|
|
143
143
|
"resolve-pkg-maps": "^1.0.0",
|
|
144
144
|
"rolldown": "1.2.16",
|
|
145
145
|
"semver": "^7.8.6",
|
|
146
|
-
"stylelint-config-standard": "^41.
|
|
146
|
+
"stylelint-config-standard": "^41.1.0",
|
|
147
147
|
"tsdown": "0.23.4",
|
|
148
|
-
"typescript-eslint": "^8.
|
|
148
|
+
"typescript-eslint": "^8.73.0",
|
|
149
149
|
"unified": "^11.0.5",
|
|
150
150
|
"unified-lint-rule": "^3.0.1",
|
|
151
151
|
"unist-util-visit": "^5.2.0",
|
|
@@ -174,8 +174,8 @@
|
|
|
174
174
|
"@types/estree-jsx": "1.0.5",
|
|
175
175
|
"@types/regexp.escape": "2.0.0",
|
|
176
176
|
"@types/yargs": "17.0.35",
|
|
177
|
-
"@typescript-eslint/parser": "8.
|
|
178
|
-
"@typescript-eslint/rule-tester": "8.
|
|
177
|
+
"@typescript-eslint/parser": "8.73.0",
|
|
178
|
+
"@typescript-eslint/rule-tester": "8.73.0",
|
|
179
179
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
180
180
|
"eslint": "10.15.0",
|
|
181
181
|
"get-port": "7.2.0",
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
"remark": "15.0.1",
|
|
184
184
|
"remark-mdx": "3.1.1",
|
|
185
185
|
"serve": "14.2.8",
|
|
186
|
-
"stylelint": "18.
|
|
186
|
+
"stylelint": "18.1.0",
|
|
187
187
|
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
188
188
|
},
|
|
189
189
|
"files": [
|
|
@@ -199,7 +199,7 @@
|
|
|
199
199
|
"publishConfig": {
|
|
200
200
|
"access": "public"
|
|
201
201
|
},
|
|
202
|
-
"gitSha": "
|
|
202
|
+
"gitSha": "071c04a35c3e2f5b1fd74619781f7f58f85bd23b",
|
|
203
203
|
"scripts": {
|
|
204
204
|
"build": "tsc -p tsconfig.build.json",
|
|
205
205
|
"typescript": "tsc -noEmit",
|
|
@@ -34,6 +34,7 @@ const ASSOCIATIONS = {
|
|
|
34
34
|
NONE: 'first-timer',
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
const BREAKING_CHANGE_LABELS = ['breaking', 'breaking change'];
|
|
37
38
|
const CHERRY_PICK_LABEL = 'cherry-pick';
|
|
38
39
|
const PULL_REFERENCE =
|
|
39
40
|
/(?:https:\/\/github\.com\/(?<urlOwner>[\w.-]+)\/(?<urlRepo>[\w.-]+)\/pull\/|(?:(?<owner>[\w.-]+)\/(?<repo>[\w.-]+))?#)(?<number>\d+)/;
|
|
@@ -377,6 +378,7 @@ export async function fetchChangelogChanges({
|
|
|
377
378
|
sha,
|
|
378
379
|
url: pull.html_url,
|
|
379
380
|
labels: pull.labels.map((label) => label.name),
|
|
381
|
+
isBreakingChange: pull.labels.some((label) => BREAKING_CHANGE_LABELS.includes(label.name)),
|
|
380
382
|
pullRequest: { number: pull.number, title: pull.title, body: pull.body ?? '' },
|
|
381
383
|
author,
|
|
382
384
|
createdAt: pull.created_at,
|
|
@@ -393,6 +395,7 @@ export async function fetchChangelogChanges({
|
|
|
393
395
|
sha,
|
|
394
396
|
url: commit.html_url,
|
|
395
397
|
labels: [],
|
|
398
|
+
isBreakingChange: false,
|
|
396
399
|
pullRequest: null,
|
|
397
400
|
author: await authors.fromCommit(commit),
|
|
398
401
|
createdAt: commit.commit.author?.date ?? null,
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { matchPrefix, parseTitle } from './changelogTitle.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('./types.ts').ChangelogChange} ChangelogChange
|
|
5
|
+
* @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
|
|
6
|
+
* @typedef {import('./types.ts').ChangelogCredits} ChangelogCredits
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const COLLATOR = new Intl.Collator('en', { numeric: true });
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Ends in a comparison by code unit, so that only equal strings are equal.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} a
|
|
15
|
+
* @param {string} b
|
|
16
|
+
*/
|
|
17
|
+
function compareText(a, b) {
|
|
18
|
+
if (a === b) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
return COLLATOR.compare(a, b) || (a < b ? -1 : 1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} label
|
|
26
|
+
*/
|
|
27
|
+
function getKind(label) {
|
|
28
|
+
return /^([^:]+):/.exec(label)?.[1];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The labels of a change, and the ones its title prefixes stand for. A label wins over the prefixes
|
|
33
|
+
* for its kind, the part before the colon: `scope: charts` leaves the scopes of the title out.
|
|
34
|
+
*
|
|
35
|
+
* @param {Pick<ChangelogChange, 'labels' | 'title'>} change
|
|
36
|
+
* @param {Record<string, readonly string[]>} [prefixes] - Labels that a prefix stands for, with the
|
|
37
|
+
* prefix spelled in any way
|
|
38
|
+
* @returns {string[]}
|
|
39
|
+
*/
|
|
40
|
+
export function readLabels(change, prefixes = {}) {
|
|
41
|
+
const kinds = new Set(change.labels.map(getKind));
|
|
42
|
+
const titleLabels = parseTitle(change.title).prefixes.flatMap((prefix) => {
|
|
43
|
+
const match = matchPrefix(prefix, Object.keys(prefixes));
|
|
44
|
+
return match === undefined ? [] : prefixes[match];
|
|
45
|
+
});
|
|
46
|
+
return [
|
|
47
|
+
...new Set([
|
|
48
|
+
...change.labels,
|
|
49
|
+
...titleLabels.filter((label) => {
|
|
50
|
+
const kind = getKind(label);
|
|
51
|
+
return kind === undefined || !kinds.has(kind);
|
|
52
|
+
}),
|
|
53
|
+
]),
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The values of one kind of label: `labelValues(['scope: charts', 'docs'], 'scope')` is `['charts']`.
|
|
59
|
+
*
|
|
60
|
+
* @param {readonly string[]} labels
|
|
61
|
+
* @param {string} kind
|
|
62
|
+
* @returns {string[]}
|
|
63
|
+
*/
|
|
64
|
+
export function labelValues(labels, kind) {
|
|
65
|
+
return labels
|
|
66
|
+
.filter((label) => getKind(label) === kind)
|
|
67
|
+
.map((label) => label.slice(kind.length + 1).trim());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Groups items that can be in several groups, or in none. Items keep their order.
|
|
72
|
+
*
|
|
73
|
+
* @template Item
|
|
74
|
+
* @template {string} Group
|
|
75
|
+
* @param {Iterable<Item>} items
|
|
76
|
+
* @param {(item: Item) => Group | readonly Group[] | null | undefined} getGroups
|
|
77
|
+
* @returns {Map<Group, Item[]>}
|
|
78
|
+
*/
|
|
79
|
+
export function groupBy(items, getGroups) {
|
|
80
|
+
/** @type {Map<Group, Item[]>} */
|
|
81
|
+
const groups = new Map();
|
|
82
|
+
for (const item of items) {
|
|
83
|
+
for (const group of new Set([getGroups(item) ?? []].flat())) {
|
|
84
|
+
const members = groups.get(/** @type {Group} */ (group)) ?? [];
|
|
85
|
+
members.push(item);
|
|
86
|
+
groups.set(/** @type {Group} */ (group), members);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return groups;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sorts by prefixes, then by the rest of the title. Changes of the same title are sorted by pull
|
|
94
|
+
* request, so that the order never depends on the order they are given in.
|
|
95
|
+
*
|
|
96
|
+
* @template {Pick<ChangelogChange, 'title' | 'pullRequest' | 'sha'>} Change
|
|
97
|
+
* @param {Iterable<Change>} changes
|
|
98
|
+
* @returns {Change[]}
|
|
99
|
+
*/
|
|
100
|
+
export function sortByTitle(changes) {
|
|
101
|
+
return Array.from(changes, (change) => {
|
|
102
|
+
const { prefixes, text } = parseTitle(change.title);
|
|
103
|
+
return { change, prefixes: prefixes.join(','), text };
|
|
104
|
+
})
|
|
105
|
+
.sort(
|
|
106
|
+
(a, b) =>
|
|
107
|
+
compareText(a.prefixes, b.prefixes) ||
|
|
108
|
+
compareText(a.text, b.text) ||
|
|
109
|
+
(a.change.pullRequest?.number ?? 0) - (b.change.pullRequest?.number ?? 0) ||
|
|
110
|
+
compareText(a.change.sha, b.change.sha),
|
|
111
|
+
)
|
|
112
|
+
.map(({ change }) => change);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The authors of changes, once each and in alphabetical order. Someone who joined the team during
|
|
117
|
+
* the release is credited as team.
|
|
118
|
+
*
|
|
119
|
+
* @param {Iterable<Pick<ChangelogChange, 'author'>>} changes
|
|
120
|
+
* @param {Object} [options]
|
|
121
|
+
* @param {readonly string[]} [options.exclude] - Logins
|
|
122
|
+
* @returns {ChangelogCredits}
|
|
123
|
+
*/
|
|
124
|
+
export function creditAuthors(changes, { exclude = [] } = {}) {
|
|
125
|
+
const excluded = new Set(exclude.map((login) => login.toLowerCase()));
|
|
126
|
+
/** @type {Map<string, ChangelogAuthor>} */
|
|
127
|
+
const authors = new Map();
|
|
128
|
+
for (const { author } of changes) {
|
|
129
|
+
const name = author?.login ?? author?.name;
|
|
130
|
+
if (!author || !name || (author.login && excluded.has(author.login.toLowerCase()))) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
// A name can equal the login of someone else.
|
|
134
|
+
const key = author.login ? `@${author.login.toLowerCase()}` : name;
|
|
135
|
+
if (!authors.has(key) || author.association === 'team') {
|
|
136
|
+
authors.set(key, author);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const all = [...authors.values()].sort((a, b) =>
|
|
141
|
+
compareText(a.login ?? a.name ?? '', b.login ?? b.name ?? ''),
|
|
142
|
+
);
|
|
143
|
+
return {
|
|
144
|
+
all,
|
|
145
|
+
team: all.filter((author) => author.association === 'team'),
|
|
146
|
+
community: all.filter((author) => author.association !== 'team'),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
|
|
3
|
+
* @typedef {import('./types.ts').ChangelogChange} ChangelogChange
|
|
4
|
+
* @typedef {import('./types.ts').ChangelogData} ChangelogData
|
|
5
|
+
* @typedef {import('./types.ts').MarkdownBlock} MarkdownBlock
|
|
6
|
+
* @typedef {import('./types.ts').MarkdownInline} MarkdownInline
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const DATE_FORMAT = new Intl.DateTimeFormat('en-US', {
|
|
10
|
+
month: 'short',
|
|
11
|
+
day: 'numeric',
|
|
12
|
+
year: 'numeric',
|
|
13
|
+
timeZone: 'UTC',
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Joins blocks with a blank line in between. Empty ones are left out. Blank lines inside a block,
|
|
18
|
+
* such as the ones of a code block, stay as they are.
|
|
19
|
+
*
|
|
20
|
+
* @param {...MarkdownBlock} blocks
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
export function joinBlocks(...blocks) {
|
|
24
|
+
return blocks
|
|
25
|
+
.map((block) => {
|
|
26
|
+
const markdown = typeof block === 'string' ? block : joinBlocks(...(block || []));
|
|
27
|
+
return markdown.replace(/^(?:[ \t]*\n)+/, '').trimEnd();
|
|
28
|
+
})
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.join('\n\n');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A heading and what is below it, or nothing when there is nothing below it.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} heading
|
|
37
|
+
* @param {...MarkdownBlock} blocks
|
|
38
|
+
* @returns {string}
|
|
39
|
+
*/
|
|
40
|
+
export function section(heading, ...blocks) {
|
|
41
|
+
const content = joinBlocks(...blocks);
|
|
42
|
+
return content && joinBlocks(heading, content);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {Iterable<MarkdownInline>} items
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
export function bulletList(items) {
|
|
50
|
+
return Array.from(items)
|
|
51
|
+
.flatMap((item) => (item ? [`- ${item.trim().replace(/\n(?=.)/g, '\n ')}`] : []))
|
|
52
|
+
.join('\n');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Joins the parts of a line with a space. Empty ones are left out.
|
|
57
|
+
*
|
|
58
|
+
* @param {...MarkdownInline} parts
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
export function joinWords(...parts) {
|
|
62
|
+
return parts.filter(Boolean).join(' ');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* `#123`, or the short SHA of a change without a pull request.
|
|
67
|
+
*
|
|
68
|
+
* @param {Pick<ChangelogChange, 'pullRequest' | 'sha'>} change
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
export function formatReference({ pullRequest, sha }) {
|
|
72
|
+
return pullRequest ? `#${pullRequest.number}` : sha.slice(0, 7);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* `@login`, or the name of an author without a GitHub account. Empty when neither is known.
|
|
77
|
+
*
|
|
78
|
+
* @param {Pick<ChangelogAuthor, 'login' | 'name'> | null} author
|
|
79
|
+
* @returns {string}
|
|
80
|
+
*/
|
|
81
|
+
export function formatAuthor(author) {
|
|
82
|
+
if (author?.login) {
|
|
83
|
+
return `@${author.login}`;
|
|
84
|
+
}
|
|
85
|
+
return (author?.name ?? '').replace(/[\\`*_[\]<>]/g, '\\$&');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* `Jan 2, 2026`, in UTC like the date of a release.
|
|
90
|
+
*
|
|
91
|
+
* @param {string} date - ISO 8601
|
|
92
|
+
* @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
export function formatDate(date) {
|
|
95
|
+
return DATE_FORMAT.format(new Date(date));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* What is below the heading of a release: a comment with the range it was generated from, and its
|
|
100
|
+
* date.
|
|
101
|
+
*
|
|
102
|
+
* @param {Pick<ChangelogData, 'previous' | 'release' | 'date'>} data
|
|
103
|
+
* @returns {string}
|
|
104
|
+
*/
|
|
105
|
+
export function formatSubHeader({ previous, release, date }) {
|
|
106
|
+
return joinBlocks(
|
|
107
|
+
`<!-- generated comparing ${previous.ref}...${release.ref} -->`,
|
|
108
|
+
`_${formatDate(date)}_`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./types.ts').ChangelogTitle} ChangelogTitle
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const PREFIX = /^\[([^[\]]+)\]\s*/;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Splits the leading `[prefixes]` off a title.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} title
|
|
11
|
+
* @returns {ChangelogTitle}
|
|
12
|
+
*/
|
|
13
|
+
export function parseTitle(title) {
|
|
14
|
+
const prefixes = [];
|
|
15
|
+
let text = title.trim();
|
|
16
|
+
for (let match = PREFIX.exec(text); match; match = PREFIX.exec(text)) {
|
|
17
|
+
prefixes.push(match[1].trim());
|
|
18
|
+
text = text.slice(match[0].length);
|
|
19
|
+
}
|
|
20
|
+
return { prefixes, text };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} prefix
|
|
25
|
+
*/
|
|
26
|
+
function normalizePrefix(prefix) {
|
|
27
|
+
return prefix.toLowerCase().replace(/[\s_-]/g, '');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The candidate that a prefix is a spelling of: case, spaces, hyphens and underscores don't matter.
|
|
32
|
+
*
|
|
33
|
+
* @template {string} Candidate
|
|
34
|
+
* @param {string} prefix
|
|
35
|
+
* @param {Iterable<Candidate>} candidates
|
|
36
|
+
* @returns {Candidate | undefined}
|
|
37
|
+
*/
|
|
38
|
+
export function matchPrefix(prefix, candidates) {
|
|
39
|
+
const normalized = normalizePrefix(prefix);
|
|
40
|
+
return Array.from(candidates).find((candidate) => normalizePrefix(candidate) === normalized);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Rewrites the prefixes of a title. Duplicates and prefixes that become empty are left out.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} title
|
|
47
|
+
* @param {(prefix: string) => string} rewrite
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
export function mapPrefixes(title, rewrite) {
|
|
51
|
+
const { prefixes, text } = parseTitle(title);
|
|
52
|
+
const rewritten = new Set(prefixes.map((prefix) => rewrite(prefix)).filter(Boolean));
|
|
53
|
+
return [Array.from(rewritten, (prefix) => `[${prefix}]`).join(''), text]
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
.join(' ');
|
|
56
|
+
}
|
package/src/changelog/index.mjs
CHANGED
|
@@ -8,12 +8,34 @@
|
|
|
8
8
|
* @typedef {import('./types.ts').ChangelogChange} ChangelogChange
|
|
9
9
|
* @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
|
|
10
10
|
* @typedef {import('./types.ts').ChangelogPackage} ChangelogPackage
|
|
11
|
+
* @typedef {import('./types.ts').ChangelogTitle} ChangelogTitle
|
|
12
|
+
* @typedef {import('./types.ts').ChangelogCredits} ChangelogCredits
|
|
13
|
+
* @typedef {import('./types.ts').MarkdownBlock} MarkdownBlock
|
|
14
|
+
* @typedef {import('./types.ts').MarkdownInline} MarkdownInline
|
|
11
15
|
*/
|
|
12
16
|
|
|
13
17
|
export { generateChangelog } from './generateChangelog.mjs';
|
|
14
18
|
export * from './loadChangelogConfig.mjs';
|
|
15
19
|
export * from './fetchChangelogs.mjs';
|
|
16
20
|
export { fetchChangelogData } from './fetchChangelogData.mjs';
|
|
21
|
+
export {
|
|
22
|
+
creditAuthors,
|
|
23
|
+
groupBy,
|
|
24
|
+
labelValues,
|
|
25
|
+
readLabels,
|
|
26
|
+
sortByTitle,
|
|
27
|
+
} from './changelogGrouping.mjs';
|
|
28
|
+
export {
|
|
29
|
+
bulletList,
|
|
30
|
+
formatAuthor,
|
|
31
|
+
formatDate,
|
|
32
|
+
formatReference,
|
|
33
|
+
formatSubHeader,
|
|
34
|
+
joinBlocks,
|
|
35
|
+
joinWords,
|
|
36
|
+
section,
|
|
37
|
+
} from './changelogMarkdown.mjs';
|
|
38
|
+
export { mapPrefixes, matchPrefix, parseTitle } from './changelogTitle.mjs';
|
|
17
39
|
// Moved to the git utilities, where the rest of the local git plumbing lives. Re-exported because
|
|
18
40
|
// `@mui/internal-code-infra/changelog` is a published entry point and this was part of it.
|
|
19
41
|
export { findLatestTaggedVersion } from '../utils/git.mjs';
|
package/src/changelog/types.ts
CHANGED
|
@@ -484,6 +484,10 @@ export interface ChangelogChange {
|
|
|
484
484
|
*/
|
|
485
485
|
url: string;
|
|
486
486
|
labels: string[];
|
|
487
|
+
/**
|
|
488
|
+
* Whether the pull request has the `breaking` or the `breaking change` label.
|
|
489
|
+
*/
|
|
490
|
+
isBreakingChange: boolean;
|
|
487
491
|
pullRequest: { number: number; title: string; body: string } | null;
|
|
488
492
|
/**
|
|
489
493
|
* `null` when the GitHub account was deleted.
|
|
@@ -580,3 +584,24 @@ export interface FetchChangelogDataOptions {
|
|
|
580
584
|
*/
|
|
581
585
|
octokit?: Octokit;
|
|
582
586
|
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Title of a change, split into its leading `[prefixes]` and the rest.
|
|
590
|
+
*/
|
|
591
|
+
export interface ChangelogTitle {
|
|
592
|
+
prefixes: string[];
|
|
593
|
+
text: string;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Authors to credit, once each.
|
|
598
|
+
*/
|
|
599
|
+
export interface ChangelogCredits {
|
|
600
|
+
all: ChangelogAuthor[];
|
|
601
|
+
team: ChangelogAuthor[];
|
|
602
|
+
community: ChangelogAuthor[];
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export type MarkdownInline = string | false | null | undefined;
|
|
606
|
+
|
|
607
|
+
export type MarkdownBlock = MarkdownInline | readonly MarkdownBlock[];
|