@mui/internal-code-infra 0.1.1-canary.4 → 0.1.1-canary.41
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/README.md +36 -4
- package/build/babel-config.d.mts +7 -1
- package/build/changelog/changelogChanges.d.mts +42 -0
- package/build/changelog/changelogGrouping.d.mts +52 -0
- package/build/changelog/changelogMarkdown.d.mts +69 -0
- package/build/changelog/changelogTags.d.mts +15 -0
- package/build/changelog/changelogTitle.d.mts +28 -0
- package/build/changelog/fetchChangelogData.d.mts +16 -0
- package/build/changelog/fetchChangelogs.d.mts +11 -12
- package/build/changelog/index.d.mts +25 -0
- package/build/changelog/octokit.d.mts +7 -0
- package/build/changelog/types.d.ts +174 -0
- package/build/eslint/baseConfig.d.mts +1 -1
- package/build/eslint/index.d.mts +1 -0
- package/build/eslint/mui/rules/no-constructor-assigned-field.d.mts +50 -0
- package/build/eslint/nodeSupportConfig.d.mts +11 -0
- package/build/eslint/packageJsonConfig.d.mts +7 -0
- package/build/remark/config.d.mts +5 -14
- package/build/utils/babelPlugin.d.mts +8 -0
- package/build/utils/build.d.mts +22 -0
- package/build/utils/cjsSourcesPlugin.d.mts +11 -0
- package/build/utils/credentials.d.mts +2 -2
- package/build/utils/dtsExportsPlugin.d.mts +8 -0
- package/build/utils/dtsNamespacesPlugin.d.mts +19 -0
- package/build/utils/fileUrlEntriesPlugin.d.mts +9 -0
- package/build/utils/getPublishedPkgJson.d.mts +20 -0
- package/build/utils/git.d.mts +30 -9
- package/build/utils/github.d.mts +8 -0
- package/build/utils/jsNamespacesPlugin.d.mts +13 -0
- package/build/utils/pnpm.d.mts +67 -3
- package/build/utils/publint.d.mts +6 -0
- package/build/utils/rolldownOutput.d.mts +38 -0
- package/build/utils/testUtils.d.mts +8 -0
- package/build/utils/typescript.d.mts +17 -0
- package/package.json +61 -49
- package/src/babel-config.mjs +35 -1
- package/src/brokenLinksChecker/index.mjs +8 -1
- package/src/changelog/changelogChanges.mjs +479 -0
- package/src/changelog/changelogGrouping.mjs +148 -0
- package/src/changelog/changelogMarkdown.mjs +110 -0
- package/src/changelog/changelogTags.mjs +34 -0
- package/src/changelog/changelogTitle.mjs +56 -0
- package/src/changelog/fetchChangelogData.mjs +172 -0
- package/src/changelog/fetchChangelogs.mjs +47 -34
- package/src/changelog/index.mjs +34 -0
- package/src/changelog/octokit.mjs +35 -0
- package/src/changelog/types.ts +187 -0
- package/src/cli/cmdBaseline.mjs +31 -0
- package/src/cli/cmdBuild.mjs +20 -89
- package/src/cli/cmdBuildNew.mjs +474 -0
- package/src/cli/cmdNetlifyIgnore.mjs +14 -7
- package/src/cli/cmdPublish.mjs +17 -3
- package/src/cli/cmdPublishNewPackage.mjs +11 -4
- package/src/cli/cmdValidateBuiltTypes.mjs +447 -32
- package/src/cli/index.mjs +4 -0
- package/src/eslint/baseConfig.mjs +10 -2
- package/src/eslint/docsConfig.mjs +28 -10
- package/src/eslint/index.mjs +1 -0
- package/src/eslint/jsonConfig.mjs +2 -1
- package/src/eslint/mui/config.mjs +16 -1
- package/src/eslint/mui/index.mjs +2 -0
- package/src/eslint/mui/rules/disallow-react-api-in-server-components.mjs +4 -1
- package/src/eslint/mui/rules/no-constructor-assigned-field.mjs +183 -0
- package/src/eslint/nodeSupportConfig.mjs +70 -0
- package/src/eslint/packageJsonConfig.mjs +50 -0
- package/src/eslint/testConfig.mjs +4 -2
- package/src/remark/config.mjs +60 -13
- package/src/utils/babelPlugin.mjs +52 -0
- package/src/utils/build.mjs +81 -0
- package/src/utils/cjsSourcesPlugin.mjs +92 -0
- package/src/utils/credentials.mjs +4 -3
- package/src/utils/dtsExportsPlugin.mjs +103 -0
- package/src/utils/dtsNamespacesPlugin.mjs +226 -0
- package/src/utils/extractErrorCodes.mjs +1 -3
- package/src/utils/fileUrlEntriesPlugin.mjs +84 -0
- package/src/utils/getPublishedPkgJson.mjs +86 -0
- package/src/utils/git.mjs +107 -46
- package/src/utils/github.mjs +27 -0
- package/src/utils/jsNamespacesPlugin.mjs +505 -0
- package/src/utils/pnpm.mjs +126 -25
- package/src/utils/publint.mjs +34 -0
- package/src/utils/rolldownOutput.mjs +70 -0
- package/src/utils/testUtils.mjs +26 -0
- package/src/utils/typescript.mjs +23 -13
- package/vale/styles/MUI/GoogleLatin.yml +5 -2
- package/build/cli/cmdArgosPush.d.mts +0 -18
- package/build/cli/cmdBuild.d.mts +0 -64
- package/build/cli/cmdCopyFiles.d.mts +0 -20
- package/build/cli/cmdExtractErrorCodes.d.mts +0 -6
- package/build/cli/cmdGenerateChangelog.d.mts +0 -32
- package/build/cli/cmdGithubAuth.d.mts +0 -11
- package/build/cli/cmdListWorkspaces.d.mts +0 -29
- package/build/cli/cmdNetlifyIgnore.d.mts +0 -17
- package/build/cli/cmdPublish.d.mts +0 -32
- package/build/cli/cmdPublishCanary.d.mts +0 -34
- package/build/cli/cmdPublishNewPackage.d.mts +0 -17
- package/build/cli/cmdRenameScope.d.mts +0 -18
- package/build/cli/cmdSetVersionOverrides.d.mts +0 -9
- package/build/cli/cmdVale.d.mts +0 -46
- package/build/cli/cmdValidateBuiltTypes.d.mts +0 -2
- package/build/cli/index.d.mts +0 -1
- package/vale/styles/MUI/CorrectRererenceCased.yml +0 -14
|
@@ -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,34 @@
|
|
|
1
|
+
import { $ } from 'execa';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The closest version tag behind a commit. Tags on the commit itself are the release being made, not
|
|
5
|
+
* the one before it.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} options
|
|
8
|
+
* @param {string} options.cwd
|
|
9
|
+
* @param {string | null} options.remote - Remote to fetch the tags and the commit from
|
|
10
|
+
* @param {string} options.sha
|
|
11
|
+
* @returns {Promise<string>}
|
|
12
|
+
*/
|
|
13
|
+
export async function findPreviousVersionTag({ cwd, remote, sha }) {
|
|
14
|
+
const $$ = $({ cwd });
|
|
15
|
+
if (remote) {
|
|
16
|
+
// --force to update any existing tags that may have changed to avoid the clobering error.
|
|
17
|
+
const { exitCode } = await $$({ reject: false })`git cat-file -e ${sha}^{commit}`;
|
|
18
|
+
const missing = exitCode === 0 ? [] : [sha];
|
|
19
|
+
await $$`git fetch --tags --force ${remote} ${missing}`;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const { stdout: ownTags } = await $$`git tag --points-at ${sha}`;
|
|
23
|
+
const excludes = ownTags.split('\n').flatMap((tag) => (tag ? ['--exclude', tag] : []));
|
|
24
|
+
const { stdout } =
|
|
25
|
+
await $$`git describe --tags --abbrev=0 --match ${'v[0-9]*'} ${excludes} ${sha}`;
|
|
26
|
+
return stdout.trim();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`No version tag found behind ${sha}. A shallow clone is the usual cause: fetch the full ` +
|
|
30
|
+
'history, or pass the `lastRelease` ref.',
|
|
31
|
+
{ cause: error },
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
|
4
|
+
import { mapAsync } from 'es-toolkit/array';
|
|
5
|
+
import { $ } from 'execa';
|
|
6
|
+
import * as semver from 'semver';
|
|
7
|
+
|
|
8
|
+
import { getCurrentGitSha, getRepositoryInfo } from '../utils/git.mjs';
|
|
9
|
+
import { getWorkspacePackages } from '../utils/pnpm.mjs';
|
|
10
|
+
import { createOctokit } from './octokit.mjs';
|
|
11
|
+
import { fetchChangelogChanges } from './changelogChanges.mjs';
|
|
12
|
+
import { findPreviousVersionTag } from './changelogTags.mjs';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {import('./types.ts').FetchChangelogDataOptions} FetchChangelogDataOptions
|
|
16
|
+
* @typedef {import('./types.ts').GitHubRepository} GitHubRepository
|
|
17
|
+
* @typedef {import('./types.ts').ChangelogData} ChangelogData
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Collects what happened in a release: its changes and its packages. Run inside a checkout of the
|
|
22
|
+
* repository, every option is optional.
|
|
23
|
+
*
|
|
24
|
+
* @param {FetchChangelogDataOptions} [options]
|
|
25
|
+
* @returns {Promise<ChangelogData>}
|
|
26
|
+
*/
|
|
27
|
+
export async function fetchChangelogData(options = {}) {
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
try {
|
|
30
|
+
return await collectData(options, controller);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
// Cancels what is still in flight. The first failure is the reason, not the cancellations
|
|
33
|
+
// that follow from it.
|
|
34
|
+
controller.abort(error);
|
|
35
|
+
throw controller.signal.reason;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {FetchChangelogDataOptions} options
|
|
41
|
+
* @param {AbortController} controller
|
|
42
|
+
* @returns {Promise<ChangelogData>}
|
|
43
|
+
*/
|
|
44
|
+
async function collectData(options, controller) {
|
|
45
|
+
const cwd = await fs.realpath(options.cwd ?? process.cwd());
|
|
46
|
+
const octokit = options.octokit ?? createOctokit();
|
|
47
|
+
const { signal } = controller;
|
|
48
|
+
|
|
49
|
+
const { repository, remote } = await resolveRepository(cwd, options);
|
|
50
|
+
const isLocalHead = (options.release ?? 'HEAD') === 'HEAD';
|
|
51
|
+
const releaseRef = isLocalHead
|
|
52
|
+
? await getCurrentGitSha(cwd)
|
|
53
|
+
: /** @type {string} */ (options.release);
|
|
54
|
+
const releaseCommit = await getCommit(octokit, repository, releaseRef, signal).catch((error) => {
|
|
55
|
+
if (isLocalHead && error.status === 422) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`HEAD (${releaseRef}) is not on GitHub in ${repository.owner}/${repository.repo}. ` +
|
|
58
|
+
'Push it, or pass a `release` ref that is already pushed.',
|
|
59
|
+
{ cause: error },
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
});
|
|
64
|
+
const releaseSha = releaseCommit.sha;
|
|
65
|
+
|
|
66
|
+
const previousRef =
|
|
67
|
+
options.lastRelease ?? (await findPreviousVersionTag({ cwd, remote, sha: releaseSha }));
|
|
68
|
+
const previousSha = (await getCommit(octokit, repository, previousRef, signal)).sha;
|
|
69
|
+
|
|
70
|
+
const changes = await fetchChangelogChanges({
|
|
71
|
+
octokit,
|
|
72
|
+
repository,
|
|
73
|
+
previousSha,
|
|
74
|
+
releaseSha,
|
|
75
|
+
includeDirectCommits: options.includeDirectCommits ?? false,
|
|
76
|
+
excludeBots: options.excludeBots,
|
|
77
|
+
controller,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const packages = await readPackages(cwd, previousSha);
|
|
81
|
+
const taggedVersion = isLocalHead ? null : semver.valid(releaseRef);
|
|
82
|
+
const version =
|
|
83
|
+
options.version ?? taggedVersion ?? packages.find((pkg) => pkg.path === '.')?.version;
|
|
84
|
+
if (!version) {
|
|
85
|
+
throw new Error('The root package.json has no version. Pass the `version` of the release.');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const date =
|
|
89
|
+
options.date ?? (taggedVersion && releaseCommit.commit.committer?.date) ?? new Date();
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
repository,
|
|
93
|
+
previous: { ref: previousRef, sha: previousSha },
|
|
94
|
+
release: { ref: releaseRef, sha: releaseSha },
|
|
95
|
+
version,
|
|
96
|
+
date: new Date(date).toISOString(),
|
|
97
|
+
changes,
|
|
98
|
+
packages: packages.flatMap(({ name, ...pkg }) => (name === null ? [] : [{ name, ...pkg }])),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The packages as they are in the working tree, named or not, sorted by path.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} cwd
|
|
106
|
+
* @param {string} previousSha
|
|
107
|
+
*/
|
|
108
|
+
async function readPackages(cwd, previousSha) {
|
|
109
|
+
const workspaceDir = await findWorkspaceDir(cwd);
|
|
110
|
+
const root = workspaceDir ?? cwd;
|
|
111
|
+
const packages = await getWorkspacePackages({ cwd: root });
|
|
112
|
+
const $$ = $({ cwd: root, reject: false });
|
|
113
|
+
const { exitCode } = await $$`git cat-file -e ${previousSha}^{commit}`;
|
|
114
|
+
|
|
115
|
+
const described = await mapAsync(
|
|
116
|
+
// Without a workspace, pnpm lists the packages of all subdirectories.
|
|
117
|
+
packages.filter((pkg) => workspaceDir || pkg.path === root),
|
|
118
|
+
async (pkg) => {
|
|
119
|
+
const directory = path.relative(root, pkg.path).split(path.sep).join('/') || '.';
|
|
120
|
+
const version = pkg.version ?? null;
|
|
121
|
+
let changed = null;
|
|
122
|
+
if (exitCode === 0) {
|
|
123
|
+
const previous =
|
|
124
|
+
await $$`git show ${previousSha}:./${path.posix.join(directory, 'package.json')}`;
|
|
125
|
+
changed =
|
|
126
|
+
previous.exitCode !== 0 || (JSON.parse(previous.stdout).version ?? null) !== version;
|
|
127
|
+
}
|
|
128
|
+
return { name: pkg.name ?? null, version, private: pkg.isPrivate, path: directory, changed };
|
|
129
|
+
},
|
|
130
|
+
{ concurrency: 10 },
|
|
131
|
+
);
|
|
132
|
+
return described.sort((a, b) => (a.path < b.path ? -1 : 1));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The repository, and the remote of the checkout that points at it, if any.
|
|
137
|
+
*
|
|
138
|
+
* @param {string} cwd
|
|
139
|
+
* @param {FetchChangelogDataOptions} options
|
|
140
|
+
* @returns {Promise<{ repository: GitHubRepository, remote: string | null }>}
|
|
141
|
+
*/
|
|
142
|
+
async function resolveRepository(cwd, options) {
|
|
143
|
+
const info = await getRepositoryInfo(cwd).catch((error) => {
|
|
144
|
+
if (options.repo) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
throw error;
|
|
148
|
+
});
|
|
149
|
+
const owner = options.org ?? 'mui';
|
|
150
|
+
const repo = options.repo ?? /** @type {NonNullable<typeof info>} */ (info).repo;
|
|
151
|
+
const isCheckout = info?.owner === owner && info.repo === repo;
|
|
152
|
+
return { repository: { owner, repo }, remote: isCheckout ? info.remoteName : null };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Resolving refs up front keeps a moving branch from shifting the range while it is paginated.
|
|
157
|
+
*
|
|
158
|
+
* @param {import('@octokit/rest').Octokit} octokit
|
|
159
|
+
* @param {GitHubRepository} repository
|
|
160
|
+
* @param {string} ref
|
|
161
|
+
* @param {AbortSignal} signal
|
|
162
|
+
*/
|
|
163
|
+
async function getCommit(octokit, repository, ref, signal) {
|
|
164
|
+
const { data } = await octokit.repos.getCommit({
|
|
165
|
+
...repository,
|
|
166
|
+
ref,
|
|
167
|
+
// Limits the file list, which can be large and isn't needed.
|
|
168
|
+
per_page: 1,
|
|
169
|
+
request: { signal },
|
|
170
|
+
});
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ } from 'execa';
|
|
1
|
+
import { mapAsync } from 'es-toolkit/array';
|
|
3
2
|
|
|
4
|
-
import {
|
|
5
|
-
import { persistentAuthStrategy } from '../utils/github.mjs';
|
|
3
|
+
import { createOctokit } from './octokit.mjs';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* @typedef {import('@octokit/rest').Octokit} OctokitType
|
|
9
7
|
*/
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
|
-
* @typedef {import('./types').FetchedCommitDetails} FetchedCommitDetails
|
|
10
|
+
* @typedef {import('./types.js').FetchedCommitDetails} FetchedCommitDetails
|
|
13
11
|
*/
|
|
14
12
|
|
|
15
13
|
/**
|
|
@@ -18,27 +16,9 @@ import { persistentAuthStrategy } from '../utils/github.mjs';
|
|
|
18
16
|
* @property {string} lastRelease
|
|
19
17
|
* @property {string} release
|
|
20
18
|
* @property {string} [org='mui'] - GitHub organization name, defaults to 'mui'
|
|
19
|
+
* @property {(progress: { phase: string; count: number; total: number }) => void} [onProgress] - Called as commits are listed and their pull request details are fetched
|
|
21
20
|
*/
|
|
22
21
|
|
|
23
|
-
/**
|
|
24
|
-
* @param {Object} opts
|
|
25
|
-
* @param {string} opts.cwd
|
|
26
|
-
* @param {boolean} [opts.fetchAll=true] Whether to fetch all tags from all remotes before finding the latest tag.
|
|
27
|
-
* @returns {Promise<string>}
|
|
28
|
-
*/
|
|
29
|
-
export async function findLatestTaggedVersion(opts) {
|
|
30
|
-
const $$ = $({ cwd: opts.cwd });
|
|
31
|
-
const fetchAll = opts.fetchAll ?? true;
|
|
32
|
-
if (fetchAll) {
|
|
33
|
-
const { remoteName } = await getRepositoryInfo();
|
|
34
|
-
// Fetch all tags from the mui remote to ensure we have the latest tags.
|
|
35
|
-
// --force to update any existing tags that may have changed to avoid the clobering error.
|
|
36
|
-
await $$`git fetch --tags --force ${remoteName}`;
|
|
37
|
-
}
|
|
38
|
-
const { stdout } = await $$`git describe --tags --abbrev=0 --match ${'v*'}`; // only include "version-tags"
|
|
39
|
-
return stdout.trim();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
22
|
/**
|
|
43
23
|
* Fetches commits between two refs (lastRelease..release) including PR details.
|
|
44
24
|
* Automatically handles GitHub OAuth authentication if none provided.
|
|
@@ -47,10 +27,7 @@ export async function findLatestTaggedVersion(opts) {
|
|
|
47
27
|
* @returns {Promise<FetchedCommitDetails[]>}
|
|
48
28
|
*/
|
|
49
29
|
export async function fetchCommitsBetweenRefs(opts) {
|
|
50
|
-
const octokit =
|
|
51
|
-
'octokit' in opts && opts.octokit
|
|
52
|
-
? opts.octokit
|
|
53
|
-
: new Octokit({ authStrategy: persistentAuthStrategy });
|
|
30
|
+
const octokit = 'octokit' in opts && opts.octokit ? opts.octokit : createOctokit();
|
|
54
31
|
|
|
55
32
|
return fetchCommitsRest({
|
|
56
33
|
octokit,
|
|
@@ -58,6 +35,7 @@ export async function fetchCommitsBetweenRefs(opts) {
|
|
|
58
35
|
lastRelease: opts.lastRelease,
|
|
59
36
|
release: opts.release,
|
|
60
37
|
org: opts.org ?? 'mui',
|
|
38
|
+
onProgress: opts.onProgress,
|
|
61
39
|
});
|
|
62
40
|
}
|
|
63
41
|
|
|
@@ -70,9 +48,9 @@ export async function fetchCommitsBetweenRefs(opts) {
|
|
|
70
48
|
*
|
|
71
49
|
* @returns {Promise<FetchedCommitDetails[]>}
|
|
72
50
|
*/
|
|
73
|
-
async function fetchCommitsRest({ octokit, repo, lastRelease, release, org = 'mui' }) {
|
|
51
|
+
async function fetchCommitsRest({ octokit, repo, lastRelease, release, org = 'mui', onProgress }) {
|
|
74
52
|
/**
|
|
75
|
-
* @typedef {Awaited<ReturnType<
|
|
53
|
+
* @typedef {Awaited<ReturnType<OctokitType['repos']['compareCommits']>>['data']['commits']} Commits
|
|
76
54
|
*/
|
|
77
55
|
/**
|
|
78
56
|
* @type {Commits}
|
|
@@ -90,9 +68,19 @@ async function fetchCommitsRest({ octokit, repo, lastRelease, release, org = 'mu
|
|
|
90
68
|
);
|
|
91
69
|
for await (const response of timeline) {
|
|
92
70
|
results.push(...response.data.commits);
|
|
71
|
+
onProgress?.({
|
|
72
|
+
phase: 'Listing commits',
|
|
73
|
+
count: results.length,
|
|
74
|
+
total: response.data.total_commits,
|
|
75
|
+
});
|
|
93
76
|
}
|
|
94
77
|
|
|
95
|
-
|
|
78
|
+
/**
|
|
79
|
+
* @param {Commits[number]} commit
|
|
80
|
+
* @param {AbortSignal} signal
|
|
81
|
+
* @returns {Promise<FetchedCommitDetails | null>}
|
|
82
|
+
*/
|
|
83
|
+
const fetchCommitDetails = async (commit, signal) => {
|
|
96
84
|
const matches = [...commit.commit.message.matchAll(/#(\d+)/g)];
|
|
97
85
|
// The PR number is always the last match.
|
|
98
86
|
// Sometimes the PR titles include an issue number like this:
|
|
@@ -111,6 +99,7 @@ async function fetchCommitsRest({ octokit, repo, lastRelease, release, org = 'mu
|
|
|
111
99
|
headers: {
|
|
112
100
|
Accept: 'application/vnd.github.text+json',
|
|
113
101
|
},
|
|
102
|
+
request: { signal },
|
|
114
103
|
});
|
|
115
104
|
|
|
116
105
|
const labels = pr.data.labels.map((label) => label.name);
|
|
@@ -132,15 +121,39 @@ async function fetchCommitsRest({ octokit, repo, lastRelease, release, org = 'mu
|
|
|
132
121
|
prTitle: pr.data.title,
|
|
133
122
|
prBody: pr.data.body,
|
|
134
123
|
});
|
|
135
|
-
}
|
|
124
|
+
};
|
|
136
125
|
|
|
137
|
-
|
|
126
|
+
// `mapAsync` rejects on the first error but still runs every queued callback.
|
|
127
|
+
// Aborted once it settles, which cancels requests in flight and skips the ones not started yet.
|
|
128
|
+
const controller = new AbortController();
|
|
129
|
+
|
|
130
|
+
let fetched = 0;
|
|
131
|
+
try {
|
|
132
|
+
const commits = await mapAsync(
|
|
133
|
+
results,
|
|
134
|
+
async (commit) => {
|
|
135
|
+
if (controller.signal.aborted) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const details = await fetchCommitDetails(commit, controller.signal);
|
|
139
|
+
if (!controller.signal.aborted) {
|
|
140
|
+
fetched += 1;
|
|
141
|
+
onProgress?.({ phase: 'Fetching pull requests', count: fetched, total: results.length });
|
|
142
|
+
}
|
|
143
|
+
return details;
|
|
144
|
+
},
|
|
145
|
+
{ concurrency: 10 },
|
|
146
|
+
);
|
|
147
|
+
return commits.filter((entry) => entry !== null);
|
|
148
|
+
} finally {
|
|
149
|
+
controller.abort();
|
|
150
|
+
}
|
|
138
151
|
}
|
|
139
152
|
|
|
140
153
|
/**
|
|
141
154
|
*
|
|
142
155
|
* @param {import('@octokit/rest').RestEndpointMethodTypes["pulls"]["get"]["response"]["data"]["author_association"]} input
|
|
143
|
-
* @returns {Exclude<import('./types').FetchedCommitDetails["author"], null>["association"]}
|
|
156
|
+
* @returns {Exclude<import('./types.js').FetchedCommitDetails["author"], null>["association"]}
|
|
144
157
|
*/
|
|
145
158
|
function getAuthorAssociation(input) {
|
|
146
159
|
switch (input) {
|