Skip to content

Commit 238d775

Browse files
alan-agius4josephperrott
authored andcommitted
build: update dependency conventional-commits-parser to v6 (#3039)
See associated pull request for more information. Closes #2994 as a pr takeover PR Close #3039
1 parent e6e1124 commit 238d775

File tree

8 files changed

+906
-945
lines changed

8 files changed

+906
-945
lines changed

.github/local-actions/branch-manager/main.js

Lines changed: 441 additions & 437 deletions
Large diffs are not rendered by default.

github-actions/pull-request-labeling/main.js

Lines changed: 421 additions & 417 deletions
Large diffs are not rendered by default.

ng-dev/commit-message/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ ts_project(
1111
"//ng-dev:__subpackages__",
1212
],
1313
deps = [
14-
"//ng-dev:node_modules/@types/conventional-commits-parser",
1514
"//ng-dev:node_modules/@types/git-raw-commits",
1615
"//ng-dev:node_modules/@types/node",
1716
"//ng-dev:node_modules/@types/yargs",

ng-dev/commit-message/parse.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Commit as ParsedCommit, Options, sync as parse} from 'conventional-commits-parser';
9+
import {
10+
CommitReference,
11+
CommitNote,
12+
ParserOptions,
13+
CommitParser,
14+
} from 'conventional-commits-parser';
1015

1116
/** A parsed commit, containing the information needed to validate the commit. */
1217
export interface Commit {
@@ -19,17 +24,17 @@ export interface Commit {
1924
/** The footer of the commit, containing issue references and note sections. */
2025
footer: string;
2126
/** A list of the references to other issues made throughout the commit message. */
22-
references: ParsedCommit.Reference[];
27+
references: CommitReference[];
2328
/** The type of the commit message. */
2429
type: string;
2530
/** The scope of the commit message. */
2631
scope: string;
2732
/** The subject of the commit message. */
2833
subject: string;
2934
/** A list of breaking change notes in the commit message. */
30-
breakingChanges: ParsedCommit.Note[];
35+
breakingChanges: CommitNote[];
3136
/** A list of deprecation notes in the commit message. */
32-
deprecations: ParsedCommit.Note[];
37+
deprecations: CommitNote[];
3338
/** Whether the commit is a fixup commit. */
3439
isFixup: boolean;
3540
/** Whether the commit is a squash commit. */
@@ -101,18 +106,17 @@ const headerPattern = /^(\w+)(?:\(([^)]+)\))?: (.*)$/;
101106
const headerCorrespondence = ['type', 'scope', 'subject'];
102107
/**
103108
* Configuration options for the commit parser.
104-
*
105-
* NOTE: An extended type from `Options` must be used because the current
106-
* @types/conventional-commits-parser version does not include the `notesPattern` field.
107109
*/
108-
const parseOptions: Options & {notesPattern: (keywords: string) => RegExp} = {
110+
const parseOptions: ParserOptions = {
109111
commentChar: '#',
110112
headerPattern,
111113
headerCorrespondence,
112114
noteKeywords: [NoteSections.BREAKING_CHANGE, NoteSections.DEPRECATED],
113115
notesPattern: (keywords: string) => new RegExp(`^\\s*(${keywords}): ?(.*)`),
114116
};
115117

118+
let commitParser: CommitParser | undefined;
119+
116120
/** Parse a commit message into its composite parts. */
117121
export const parseCommitMessage: (fullText: string) => Commit = parseInternal;
118122

@@ -130,21 +134,27 @@ function parseInternal(fullText: string | Buffer): CommitFromGitLog | Commit {
130134
.replace(FIXUP_PREFIX_RE, '')
131135
.replace(SQUASH_PREFIX_RE, '')
132136
.replace(REVERT_PREFIX_RE, '');
137+
138+
commitParser ??= new CommitParser(parseOptions);
139+
133140
/** The initially parsed commit. */
134-
const commit = parse(strippedCommitMsg, parseOptions);
141+
const commit = commitParser.parse(strippedCommitMsg);
135142
/** A list of breaking change notes from the commit. */
136-
const breakingChanges: ParsedCommit.Note[] = [];
143+
const breakingChanges: CommitNote[] = [];
137144
/** A list of deprecation notes from the commit. */
138-
const deprecations: ParsedCommit.Note[] = [];
145+
const deprecations: CommitNote[] = [];
139146

140147
// Extract the commit message notes by marked types into their respective lists.
141-
commit.notes.forEach((note: ParsedCommit.Note) => {
142-
if (note.title === NoteSections.BREAKING_CHANGE) {
143-
breakingChanges.push(note);
144-
} else if (note.title === NoteSections.DEPRECATED) {
145-
deprecations.push(note);
148+
for (const note of commit.notes) {
149+
switch (note.title) {
150+
case NoteSections.BREAKING_CHANGE:
151+
breakingChanges.push(note);
152+
break;
153+
case NoteSections.DEPRECATED:
154+
deprecations.push(note);
155+
break;
146156
}
147-
});
157+
}
148158

149159
return {
150160
fullText,
@@ -154,9 +164,9 @@ function parseInternal(fullText: string | Buffer): CommitFromGitLog | Commit {
154164
footer: commit.footer || '',
155165
header: commit.header || '',
156166
references: commit.references,
157-
scope: commit.scope || '',
158-
subject: commit.subject || '',
159-
type: commit.type || '',
167+
scope: commit['scope'] || '',
168+
subject: commit['subject'] || '',
169+
type: commit['type'] || '',
160170
isFixup: FIXUP_PREFIX_RE.test(fullText),
161171
isSquash: SQUASH_PREFIX_RE.test(fullText),
162172
isRevert: REVERT_PREFIX_RE.test(fullText),

ng-dev/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"@octokit/types": "14.1.0",
3333
"@pnpm/dependency-path": "1001.1.0",
3434
"@types/cli-progress": "3.11.6",
35-
"@types/conventional-commits-parser": "5.0.1",
3635
"@types/ejs": "3.1.5",
3736
"@types/events": "3.0.3",
3837
"@types/folder-hash": "4.0.4",
@@ -50,7 +49,7 @@
5049
"chalk": "5.6.2",
5150
"cli-progress": "3.12.0",
5251
"conventional-commits-filter": "5.0.0",
53-
"conventional-commits-parser": "5.0.0",
52+
"conventional-commits-parser": "6.2.0",
5453
"ejs": "3.1.10",
5554
"encoding": "0.1.13",
5655
"fast-glob": "3.3.3",

ng-dev/pr/rebase/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ ts_project(
1111
"//ng-dev:__subpackages__",
1212
],
1313
deps = [
14-
"//ng-dev:node_modules/@types/conventional-commits-parser",
1514
"//ng-dev:node_modules/@types/node",
1615
"//ng-dev:node_modules/@types/yargs",
1716
"//ng-dev:node_modules/conventional-commits-parser",

ng-dev/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"esModuleInterop": true,
1212
"strict": true,
1313
"noFallthroughCasesInSwitch": true,
14-
"moduleResolution": "node",
14+
"moduleResolution": "bundler",
1515
"module": "esnext",
1616
"target": "es2020",
1717
"lib": ["es2021", "dom"],

pnpm-lock.yaml

Lines changed: 12 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)