@icebreakers/changelog-github 0.2.0 → 0.2.1

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 CHANGED
@@ -46,7 +46,7 @@ All other behaviours (tuple arguments, required `repo` option, rendered layout)
46
46
 
47
47
  Leverage the summary tags to control the metadata the formatter displays:
48
48
 
49
- ```
49
+ ```text
50
50
  pr: #42
51
51
  commit: 1234567890abcdef1234567890abcdef12345678
52
52
  author: @octocat
@@ -59,7 +59,7 @@ Add optional `tailwind-config` flag to the lint preset
59
59
 
60
60
  The rendered changelog entry becomes:
61
61
 
62
- ```
62
+ ```md
63
63
  - ✨ **Add optional `tailwind-config` flag** [#42] [`1234567`](https://github.com/org/repo/commit/1234567890abcdef1234567890abcdef12345678) by @octocat
64
64
  - accepts a relative path to `tailwind.config.ts`
65
65
  - falls back to the workspace root when unset
package/README.zh.md CHANGED
@@ -44,7 +44,7 @@ pnpm add -D @changesets/cli @icebreakers/changelog-github
44
44
 
45
45
  可以借助摘要指令精准控制展示的元数据:
46
46
 
47
- ```
47
+ ```text
48
48
  pr: #42
49
49
  commit: 1234567890abcdef1234567890abcdef12345678
50
50
  author: @octocat
@@ -57,7 +57,7 @@ author: @octocat
57
57
 
58
58
  最终 changelog 会渲染为:
59
59
 
60
- ```
60
+ ```md
61
61
  - ✨ **为 lint preset 新增可选的 `tailwind-config` 配置项** [#42] [`1234567`](https://github.com/org/repo/commit/1234567890abcdef1234567890abcdef12345678) by @octocat
62
62
  - 接受相对路径指向 `tailwind.config.ts`
63
63
  - 未设置时默认读取工作区根目录
package/dist/index.cjs CHANGED
@@ -15,7 +15,7 @@ function resolveReleaseType(type) {
15
15
  return "none";
16
16
  }
17
17
  function assertRepo(options) {
18
- if (!options || !options.repo) {
18
+ if (!options || typeof options["repo"] !== "string" || options["repo"].trim().length === 0) {
19
19
  throw new Error(
20
20
  'Please provide a repo to this changelog generator like this:\n"changelog": ["@icebreakers/changelog-github", { "repo": "org/repo" }]'
21
21
  );
@@ -69,11 +69,14 @@ function parseConventionalHeadline(raw) {
69
69
  if (!match) {
70
70
  return { breaking: false, description: raw };
71
71
  }
72
+ const type = match[1];
73
+ const scope = match[2] || void 0;
74
+ const description = (_nullishCoalesce(match[4], () => ( raw))).trim();
72
75
  return {
73
- type: match[1],
74
- scope: match[2] || void 0,
76
+ type,
77
+ scope,
75
78
  breaking: match[3] === "!",
76
- description: match[4].trim()
79
+ description
77
80
  };
78
81
  }
79
82
  function formatHeadline(raw) {
@@ -93,12 +96,12 @@ function normalizeUserMentions(users) {
93
96
  return "";
94
97
  }
95
98
  if (normalized.length === 1) {
96
- return normalized[0];
99
+ return _nullishCoalesce(normalized[0], () => ( ""));
97
100
  }
98
101
  if (normalized.length === 2) {
99
- return `${normalized[0]} and ${normalized[1]}`;
102
+ return `${_nullishCoalesce(normalized[0], () => ( ""))} and ${_nullishCoalesce(normalized[1], () => ( ""))}`;
100
103
  }
101
- return `${normalized.slice(0, -1).join(", ")}, and ${normalized.at(-1)}`;
104
+ return `${normalized.slice(0, -1).join(", ")}, and ${_nullishCoalesce(normalized.at(-1), () => ( ""))}`;
102
105
  }
103
106
  function extractSummaryMeta(summary) {
104
107
  let prNumber;
@@ -112,7 +115,7 @@ function extractSummaryMeta(summary) {
112
115
  /^(?:pr|pull|pull\s*request):\s*#?(\d+)\s*$/i
113
116
  );
114
117
  if (prMatch) {
115
- const num = Number(prMatch[1]);
118
+ const num = Number(_nullishCoalesce(prMatch[1], () => ( Number.NaN)));
116
119
  if (!Number.isNaN(num)) {
117
120
  prNumber = num;
118
121
  }
@@ -125,7 +128,10 @@ function extractSummaryMeta(summary) {
125
128
  }
126
129
  const userMatch = withoutListMarker.match(/^(?:author|user):\s*(\S+)\s*$/i);
127
130
  if (userMatch) {
128
- users.push(userMatch[1].replace(/^@/, ""));
131
+ const user = userMatch[1];
132
+ if (user) {
133
+ users.push(user.replace(/^@/, ""));
134
+ }
129
135
  return false;
130
136
  }
131
137
  if (/^BREAKING[\s-]CHANGE:/i.test(withoutListMarker)) {
@@ -134,8 +140,8 @@ function extractSummaryMeta(summary) {
134
140
  return true;
135
141
  }).map((line) => line.trimEnd());
136
142
  return {
137
- prNumber,
138
- commitRef,
143
+ ...prNumber !== void 0 ? { prNumber } : {},
144
+ ...commitRef !== void 0 ? { commitRef } : {},
139
145
  users,
140
146
  contentLines,
141
147
  breaking
@@ -154,24 +160,24 @@ function parseSummary(summary) {
154
160
  return {
155
161
  headline: "",
156
162
  detailLines: [],
157
- prNumber,
158
- commitRef,
163
+ ...prNumber !== void 0 ? { prNumber } : {},
164
+ ...commitRef !== void 0 ? { commitRef } : {},
159
165
  users,
160
166
  breaking: bodyBreaking
161
167
  };
162
168
  }
163
- const firstContentLine = contentLines[nonEmptyIndex].trim();
169
+ const firstContentLine = _nullishCoalesce(_optionalChain([contentLines, 'access', _ => _[nonEmptyIndex], 'optionalAccess', _2 => _2.trim, 'call', _3 => _3()]), () => ( ""));
164
170
  const startsWithList = /^(?:[-*+]\s+|\d+[.)]\s+)/.test(firstContentLine);
165
171
  const headline = startsWithList ? "" : firstContentLine;
166
172
  const restLines = startsWithList ? contentLines.slice(nonEmptyIndex) : contentLines.slice(nonEmptyIndex + 1);
167
173
  const detailLines = restLines;
168
174
  const headlineParsed = headline ? parseConventionalHeadline(headline) : null;
169
- const breaking = bodyBreaking || (_nullishCoalesce(_optionalChain([headlineParsed, 'optionalAccess', _ => _.breaking]), () => ( false)));
175
+ const breaking = bodyBreaking || (_nullishCoalesce(_optionalChain([headlineParsed, 'optionalAccess', _4 => _4.breaking]), () => ( false)));
170
176
  return {
171
177
  headline,
172
178
  detailLines,
173
- prNumber,
174
- commitRef,
179
+ ...prNumber !== void 0 ? { prNumber } : {},
180
+ ...commitRef !== void 0 ? { commitRef } : {},
175
181
  users,
176
182
  breaking
177
183
  };
@@ -208,7 +214,8 @@ function buildUserMentions(users, fallbackUser) {
208
214
  }
209
215
  if (fallbackUser) {
210
216
  const match = fallbackUser.match(/@([^\]]+)/);
211
- return match ? normalizeUserMentions([match[1]]) : "";
217
+ const matchedUser = _optionalChain([match, 'optionalAccess', _5 => _5[1]]);
218
+ return matchedUser ? normalizeUserMentions([matchedUser]) : "";
212
219
  }
213
220
  return "";
214
221
  }
@@ -240,7 +247,7 @@ function formatDetailBlock(detailLines) {
240
247
  var changelogFunctions = {
241
248
  async getDependencyReleaseLine(changesets, dependenciesUpdated, options) {
242
249
  assertRepo(options);
243
- const { repo } = options;
250
+ const repo = options.repo;
244
251
  if (dependenciesUpdated.length === 0) {
245
252
  return "";
246
253
  }
@@ -252,7 +259,7 @@ var changelogFunctions = {
252
259
  },
253
260
  async getReleaseLine(changeset, type, options) {
254
261
  assertRepo(options);
255
- const { repo } = options;
262
+ const repo = options.repo;
256
263
  const parsedSummary = parseSummary(changeset.summary);
257
264
  const resolvedType = resolveReleaseType(type);
258
265
  const links = await resolveLinks(
package/dist/index.d.cts CHANGED
@@ -2,8 +2,8 @@ import * as _changesets_types from '@changesets/types';
2
2
  import { ChangelogFunctions } from '@changesets/types';
3
3
 
4
4
  interface ConventionalHeadline {
5
- type?: string;
6
- scope?: string;
5
+ type?: string | undefined;
6
+ scope?: string | undefined;
7
7
  breaking: boolean;
8
8
  description: string;
9
9
  }
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import * as _changesets_types from '@changesets/types';
2
2
  import { ChangelogFunctions } from '@changesets/types';
3
3
 
4
4
  interface ConventionalHeadline {
5
- type?: string;
6
- scope?: string;
5
+ type?: string | undefined;
6
+ scope?: string | undefined;
7
7
  breaking: boolean;
8
8
  description: string;
9
9
  }
package/dist/index.mjs CHANGED
@@ -15,7 +15,7 @@ function resolveReleaseType(type) {
15
15
  return "none";
16
16
  }
17
17
  function assertRepo(options) {
18
- if (!options || !options.repo) {
18
+ if (!options || typeof options["repo"] !== "string" || options["repo"].trim().length === 0) {
19
19
  throw new Error(
20
20
  'Please provide a repo to this changelog generator like this:\n"changelog": ["@icebreakers/changelog-github", { "repo": "org/repo" }]'
21
21
  );
@@ -69,11 +69,14 @@ function parseConventionalHeadline(raw) {
69
69
  if (!match) {
70
70
  return { breaking: false, description: raw };
71
71
  }
72
+ const type = match[1];
73
+ const scope = match[2] || void 0;
74
+ const description = (match[4] ?? raw).trim();
72
75
  return {
73
- type: match[1],
74
- scope: match[2] || void 0,
76
+ type,
77
+ scope,
75
78
  breaking: match[3] === "!",
76
- description: match[4].trim()
79
+ description
77
80
  };
78
81
  }
79
82
  function formatHeadline(raw) {
@@ -93,12 +96,12 @@ function normalizeUserMentions(users) {
93
96
  return "";
94
97
  }
95
98
  if (normalized.length === 1) {
96
- return normalized[0];
99
+ return normalized[0] ?? "";
97
100
  }
98
101
  if (normalized.length === 2) {
99
- return `${normalized[0]} and ${normalized[1]}`;
102
+ return `${normalized[0] ?? ""} and ${normalized[1] ?? ""}`;
100
103
  }
101
- return `${normalized.slice(0, -1).join(", ")}, and ${normalized.at(-1)}`;
104
+ return `${normalized.slice(0, -1).join(", ")}, and ${normalized.at(-1) ?? ""}`;
102
105
  }
103
106
  function extractSummaryMeta(summary) {
104
107
  let prNumber;
@@ -112,7 +115,7 @@ function extractSummaryMeta(summary) {
112
115
  /^(?:pr|pull|pull\s*request):\s*#?(\d+)\s*$/i
113
116
  );
114
117
  if (prMatch) {
115
- const num = Number(prMatch[1]);
118
+ const num = Number(prMatch[1] ?? Number.NaN);
116
119
  if (!Number.isNaN(num)) {
117
120
  prNumber = num;
118
121
  }
@@ -125,7 +128,10 @@ function extractSummaryMeta(summary) {
125
128
  }
126
129
  const userMatch = withoutListMarker.match(/^(?:author|user):\s*(\S+)\s*$/i);
127
130
  if (userMatch) {
128
- users.push(userMatch[1].replace(/^@/, ""));
131
+ const user = userMatch[1];
132
+ if (user) {
133
+ users.push(user.replace(/^@/, ""));
134
+ }
129
135
  return false;
130
136
  }
131
137
  if (/^BREAKING[\s-]CHANGE:/i.test(withoutListMarker)) {
@@ -134,8 +140,8 @@ function extractSummaryMeta(summary) {
134
140
  return true;
135
141
  }).map((line) => line.trimEnd());
136
142
  return {
137
- prNumber,
138
- commitRef,
143
+ ...prNumber !== void 0 ? { prNumber } : {},
144
+ ...commitRef !== void 0 ? { commitRef } : {},
139
145
  users,
140
146
  contentLines,
141
147
  breaking
@@ -154,13 +160,13 @@ function parseSummary(summary) {
154
160
  return {
155
161
  headline: "",
156
162
  detailLines: [],
157
- prNumber,
158
- commitRef,
163
+ ...prNumber !== void 0 ? { prNumber } : {},
164
+ ...commitRef !== void 0 ? { commitRef } : {},
159
165
  users,
160
166
  breaking: bodyBreaking
161
167
  };
162
168
  }
163
- const firstContentLine = contentLines[nonEmptyIndex].trim();
169
+ const firstContentLine = contentLines[nonEmptyIndex]?.trim() ?? "";
164
170
  const startsWithList = /^(?:[-*+]\s+|\d+[.)]\s+)/.test(firstContentLine);
165
171
  const headline = startsWithList ? "" : firstContentLine;
166
172
  const restLines = startsWithList ? contentLines.slice(nonEmptyIndex) : contentLines.slice(nonEmptyIndex + 1);
@@ -170,8 +176,8 @@ function parseSummary(summary) {
170
176
  return {
171
177
  headline,
172
178
  detailLines,
173
- prNumber,
174
- commitRef,
179
+ ...prNumber !== void 0 ? { prNumber } : {},
180
+ ...commitRef !== void 0 ? { commitRef } : {},
175
181
  users,
176
182
  breaking
177
183
  };
@@ -208,7 +214,8 @@ function buildUserMentions(users, fallbackUser) {
208
214
  }
209
215
  if (fallbackUser) {
210
216
  const match = fallbackUser.match(/@([^\]]+)/);
211
- return match ? normalizeUserMentions([match[1]]) : "";
217
+ const matchedUser = match?.[1];
218
+ return matchedUser ? normalizeUserMentions([matchedUser]) : "";
212
219
  }
213
220
  return "";
214
221
  }
@@ -240,7 +247,7 @@ function formatDetailBlock(detailLines) {
240
247
  var changelogFunctions = {
241
248
  async getDependencyReleaseLine(changesets, dependenciesUpdated, options) {
242
249
  assertRepo(options);
243
- const { repo } = options;
250
+ const repo = options.repo;
244
251
  if (dependenciesUpdated.length === 0) {
245
252
  return "";
246
253
  }
@@ -252,7 +259,7 @@ var changelogFunctions = {
252
259
  },
253
260
  async getReleaseLine(changeset, type, options) {
254
261
  assertRepo(options);
255
- const { repo } = options;
262
+ const repo = options.repo;
256
263
  const parsedSummary = parseSummary(changeset.summary);
257
264
  const resolvedType = resolveReleaseType(type);
258
265
  const links = await resolveLinks(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@icebreakers/changelog-github",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "description": "Changesets GitHub changelog formatter for Icebreaker's dev-configs",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -34,12 +34,12 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@changesets/get-github-info": "^0.7.0",
37
+ "@changesets/get-github-info": "^0.8.0",
38
38
  "@changesets/types": "^6.1.0",
39
- "dotenv": "^17.2.4"
39
+ "dotenv": "^17.3.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@changesets/parse": "^0.4.2"
42
+ "@changesets/parse": "^0.4.3"
43
43
  },
44
44
  "scripts": {
45
45
  "stub": "unbuild --stub",
@@ -49,6 +49,7 @@
49
49
  "test:dev": "vitest",
50
50
  "release": "pnpm publish",
51
51
  "lint": "eslint .",
52
- "lint:fix": "eslint . --fix"
52
+ "lint:fix": "eslint . --fix",
53
+ "typecheck": "tsc --noEmit"
53
54
  }
54
55
  }