@soybeanjs/changelog 0.3.15 → 0.3.17

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/dist/index.cjs CHANGED
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // node_modules/.pnpm/tsup@8.0.2_typescript@5.3.3/node_modules/tsup/assets/cjs_shims.js
33
+ // node_modules/.pnpm/tsup@8.0.2_typescript@5.4.5/node_modules/tsup/assets/cjs_shims.js
34
34
  var init_cjs_shims = __esm({
35
- "node_modules/.pnpm/tsup@8.0.2_typescript@5.3.3/node_modules/tsup/assets/cjs_shims.js"() {
35
+ "node_modules/.pnpm/tsup@8.0.2_typescript@5.4.5/node_modules/tsup/assets/cjs_shims.js"() {
36
36
  "use strict";
37
37
  }
38
38
  });
@@ -2004,7 +2004,7 @@ var VERSION_WITH_RELEASE = /release\sv\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?/;
2004
2004
  async function getTotalGitTags() {
2005
2005
  const tagStr = await execCommand("git", ["--no-pager", "tag", "-l", "--sort=creatordate"]);
2006
2006
  const tags = tagStr.split("\n");
2007
- return tags;
2007
+ return tags.filter((tag) => VERSION_REG.test(tag));
2008
2008
  }
2009
2009
  async function getTagDateMap() {
2010
2010
  const tagDateStr = await execCommand("git", [
@@ -2030,16 +2030,23 @@ async function getTagDateMap() {
2030
2030
  }
2031
2031
  function getFromToTags(tags) {
2032
2032
  const result = [];
2033
- tags.forEach((tag, index) => {
2034
- if (index < tags.length - 1) {
2035
- result.push({ from: tag, to: tags[index + 1] });
2033
+ if (tags.length < 2) {
2034
+ return result;
2035
+ }
2036
+ const releaseTags = tags.filter((tag) => !isPrerelease(tag));
2037
+ const reversedTags = [...tags].reverse();
2038
+ reversedTags.forEach((tag, index) => {
2039
+ if (index < reversedTags.length - 1) {
2040
+ const to = tag;
2041
+ let from = reversedTags[index + 1];
2042
+ if (!isPrerelease(to)) {
2043
+ const toIndex = releaseTags.indexOf(to);
2044
+ from = releaseTags[toIndex - 1];
2045
+ }
2046
+ result.push({ from, to });
2036
2047
  }
2037
2048
  });
2038
- return result;
2039
- }
2040
- async function getLastGitTag(delta = 0) {
2041
- const tags = await getTotalGitTags();
2042
- return tags[tags.length + delta - 1];
2049
+ return result.reverse();
2043
2050
  }
2044
2051
  async function getGitMainBranchName() {
2045
2052
  const main = await execCommand("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
@@ -2256,8 +2263,7 @@ function createDefaultOptions() {
2256
2263
  breakingChanges: "\u{1F6A8} Breaking Changes"
2257
2264
  },
2258
2265
  output: "CHANGELOG.md",
2259
- regenerate: false,
2260
- newVersion: ""
2266
+ regenerate: false
2261
2267
  };
2262
2268
  return options;
2263
2269
  }
@@ -2279,21 +2285,20 @@ async function createOptions(options) {
2279
2285
  Object.assign(opts, options);
2280
2286
  const { newVersion } = await getVersionFromPkgJson(opts.cwd);
2281
2287
  (_a = opts.github).repo || (_a.repo = await getGitHubRepo());
2282
- opts.newVersion || (opts.newVersion = `v${newVersion}`);
2283
- opts.from || (opts.from = await getLastGitTag());
2284
- opts.to || (opts.to = await getCurrentGitBranch());
2288
+ const tags = await getTotalGitTags();
2289
+ opts.tags = tags;
2290
+ opts.from || (opts.from = tags[tags.length - 1]);
2291
+ opts.to || (opts.to = `v${newVersion}`);
2285
2292
  if (opts.to === opts.from) {
2286
- const lastTag = await getLastGitTag(-1);
2293
+ const lastTag = tags[tags.length - 2];
2287
2294
  const firstCommit = await getFirstGitCommit();
2288
2295
  opts.from = lastTag || firstCommit;
2289
2296
  }
2290
- opts.tags = await getTotalGitTags();
2291
2297
  opts.tagDateMap = await getTagDateMap();
2292
2298
  opts.prerelease || (opts.prerelease = isPrerelease(opts.to));
2293
2299
  const isFromPrerelease = isPrerelease(opts.from);
2294
2300
  if (!isPrerelease(newVersion) && isFromPrerelease) {
2295
- const nVersion = opts.newVersion;
2296
- const allReleaseTags = opts.tags.filter((tag) => !isPrerelease(tag) && tag !== nVersion);
2301
+ const allReleaseTags = opts.tags.filter((tag) => !isPrerelease(tag) && tag !== opts.to);
2297
2302
  opts.from = allReleaseTags[allReleaseTags.length - 1];
2298
2303
  }
2299
2304
  return opts;
@@ -2405,10 +2410,10 @@ function generateMarkdown(params) {
2405
2410
  const { options, showTitle, contributors } = params;
2406
2411
  const commits = params.commits.filter((commit) => commit.description.match(VERSION_WITH_RELEASE) === null);
2407
2412
  const lines = [];
2408
- const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.newVersion}`;
2413
+ const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.to}`;
2409
2414
  if (showTitle) {
2410
- const date = options.tagDateMap.get(options.newVersion) || (0, import_dayjs2.default)().format("YY-MM-DD");
2411
- let title = `## [${options.newVersion}](${url})`;
2415
+ const date = options.tagDateMap.get(options.to) || (0, import_dayjs2.default)().format("YYYY-MM-DD");
2416
+ let title = `## [${options.to}](${url})`;
2412
2417
  if (date) {
2413
2418
  title += ` (${date})`;
2414
2419
  }
@@ -2484,7 +2489,9 @@ ${md}
2484
2489
  // src/index.ts
2485
2490
  async function getChangelogMarkdown(options, showTitle = true) {
2486
2491
  const opts = await createOptions(options);
2487
- const gitCommits = await getGitCommits(opts.from, opts.to);
2492
+ const current = await getCurrentGitBranch();
2493
+ const to = opts.tags.includes(opts.to) ? opts.to : current;
2494
+ const gitCommits = await getGitCommits(opts.from, to);
2488
2495
  const resolvedLogins = /* @__PURE__ */ new Map();
2489
2496
  const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, opts.github, resolvedLogins);
2490
2497
  const markdown = generateMarkdown({ commits, options: opts, showTitle, contributors });
@@ -2526,7 +2533,7 @@ ${markdown}`;
2526
2533
  }
2527
2534
  async function generateChangelog(options) {
2528
2535
  const opts = await createOptions(options);
2529
- const existContent = await isVersionInMarkdown(opts.newVersion, opts.output);
2536
+ const existContent = await isVersionInMarkdown(opts.to, opts.output);
2530
2537
  if (!opts.regenerate && existContent)
2531
2538
  return;
2532
2539
  const { markdown } = await getChangelogMarkdown(opts);
package/dist/index.d.cts CHANGED
@@ -100,12 +100,6 @@ interface ChangelogOption {
100
100
  * the changelog already exists the content of v0.0.1, but you want to regenerate it
101
101
  */
102
102
  regenerate: boolean;
103
- /**
104
- * Version from package.json, with prefix "v"
105
- *
106
- * If the options "to" is not specified, the version will be used
107
- */
108
- newVersion: string;
109
103
  /** Mark the release as prerelease */
110
104
  prerelease?: boolean;
111
105
  }
package/dist/index.d.ts CHANGED
@@ -100,12 +100,6 @@ interface ChangelogOption {
100
100
  * the changelog already exists the content of v0.0.1, but you want to regenerate it
101
101
  */
102
102
  regenerate: boolean;
103
- /**
104
- * Version from package.json, with prefix "v"
105
- *
106
- * If the options "to" is not specified, the version will be used
107
- */
108
- newVersion: string;
109
103
  /** Mark the release as prerelease */
110
104
  prerelease?: boolean;
111
105
  }
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ var VERSION_WITH_RELEASE = /release\sv\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?/;
68
68
  async function getTotalGitTags() {
69
69
  const tagStr = await execCommand("git", ["--no-pager", "tag", "-l", "--sort=creatordate"]);
70
70
  const tags = tagStr.split("\n");
71
- return tags;
71
+ return tags.filter((tag) => VERSION_REG.test(tag));
72
72
  }
73
73
  async function getTagDateMap() {
74
74
  const tagDateStr = await execCommand("git", [
@@ -94,16 +94,23 @@ async function getTagDateMap() {
94
94
  }
95
95
  function getFromToTags(tags) {
96
96
  const result = [];
97
- tags.forEach((tag, index) => {
98
- if (index < tags.length - 1) {
99
- result.push({ from: tag, to: tags[index + 1] });
97
+ if (tags.length < 2) {
98
+ return result;
99
+ }
100
+ const releaseTags = tags.filter((tag) => !isPrerelease(tag));
101
+ const reversedTags = [...tags].reverse();
102
+ reversedTags.forEach((tag, index) => {
103
+ if (index < reversedTags.length - 1) {
104
+ const to = tag;
105
+ let from = reversedTags[index + 1];
106
+ if (!isPrerelease(to)) {
107
+ const toIndex = releaseTags.indexOf(to);
108
+ from = releaseTags[toIndex - 1];
109
+ }
110
+ result.push({ from, to });
100
111
  }
101
112
  });
102
- return result;
103
- }
104
- async function getLastGitTag(delta = 0) {
105
- const tags = await getTotalGitTags();
106
- return tags[tags.length + delta - 1];
113
+ return result.reverse();
107
114
  }
108
115
  async function getGitMainBranchName() {
109
116
  const main = await execCommand("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
@@ -320,8 +327,7 @@ function createDefaultOptions() {
320
327
  breakingChanges: "\u{1F6A8} Breaking Changes"
321
328
  },
322
329
  output: "CHANGELOG.md",
323
- regenerate: false,
324
- newVersion: ""
330
+ regenerate: false
325
331
  };
326
332
  return options;
327
333
  }
@@ -343,21 +349,20 @@ async function createOptions(options) {
343
349
  Object.assign(opts, options);
344
350
  const { newVersion } = await getVersionFromPkgJson(opts.cwd);
345
351
  (_a = opts.github).repo || (_a.repo = await getGitHubRepo());
346
- opts.newVersion || (opts.newVersion = `v${newVersion}`);
347
- opts.from || (opts.from = await getLastGitTag());
348
- opts.to || (opts.to = await getCurrentGitBranch());
352
+ const tags = await getTotalGitTags();
353
+ opts.tags = tags;
354
+ opts.from || (opts.from = tags[tags.length - 1]);
355
+ opts.to || (opts.to = `v${newVersion}`);
349
356
  if (opts.to === opts.from) {
350
- const lastTag = await getLastGitTag(-1);
357
+ const lastTag = tags[tags.length - 2];
351
358
  const firstCommit = await getFirstGitCommit();
352
359
  opts.from = lastTag || firstCommit;
353
360
  }
354
- opts.tags = await getTotalGitTags();
355
361
  opts.tagDateMap = await getTagDateMap();
356
362
  opts.prerelease || (opts.prerelease = isPrerelease(opts.to));
357
363
  const isFromPrerelease = isPrerelease(opts.from);
358
364
  if (!isPrerelease(newVersion) && isFromPrerelease) {
359
- const nVersion = opts.newVersion;
360
- const allReleaseTags = opts.tags.filter((tag) => !isPrerelease(tag) && tag !== nVersion);
365
+ const allReleaseTags = opts.tags.filter((tag) => !isPrerelease(tag) && tag !== opts.to);
361
366
  opts.from = allReleaseTags[allReleaseTags.length - 1];
362
367
  }
363
368
  return opts;
@@ -468,10 +473,10 @@ function generateMarkdown(params) {
468
473
  const { options, showTitle, contributors } = params;
469
474
  const commits = params.commits.filter((commit) => commit.description.match(VERSION_WITH_RELEASE) === null);
470
475
  const lines = [];
471
- const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.newVersion}`;
476
+ const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.to}`;
472
477
  if (showTitle) {
473
- const date = options.tagDateMap.get(options.newVersion) || dayjs2().format("YY-MM-DD");
474
- let title = `## [${options.newVersion}](${url})`;
478
+ const date = options.tagDateMap.get(options.to) || dayjs2().format("YYYY-MM-DD");
479
+ let title = `## [${options.to}](${url})`;
475
480
  if (date) {
476
481
  title += ` (${date})`;
477
482
  }
@@ -547,7 +552,9 @@ ${md}
547
552
  // src/index.ts
548
553
  async function getChangelogMarkdown(options, showTitle = true) {
549
554
  const opts = await createOptions(options);
550
- const gitCommits = await getGitCommits(opts.from, opts.to);
555
+ const current = await getCurrentGitBranch();
556
+ const to = opts.tags.includes(opts.to) ? opts.to : current;
557
+ const gitCommits = await getGitCommits(opts.from, to);
551
558
  const resolvedLogins = /* @__PURE__ */ new Map();
552
559
  const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, opts.github, resolvedLogins);
553
560
  const markdown = generateMarkdown({ commits, options: opts, showTitle, contributors });
@@ -589,7 +596,7 @@ ${markdown}`;
589
596
  }
590
597
  async function generateChangelog(options) {
591
598
  const opts = await createOptions(options);
592
- const existContent = await isVersionInMarkdown(opts.newVersion, opts.output);
599
+ const existContent = await isVersionInMarkdown(opts.to, opts.output);
593
600
  if (!opts.regenerate && existContent)
594
601
  return;
595
602
  const { markdown } = await getChangelogMarkdown(opts);
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@soybeanjs/changelog",
3
3
  "type": "module",
4
- "version": "0.3.15",
5
- "packageManager": "pnpm@8.14.1",
4
+ "version": "0.3.17",
6
5
  "description": "generate changelog form git tags and commits for github",
7
6
  "author": {
8
7
  "name": "Soybean",
@@ -38,23 +37,23 @@
38
37
  "node": ">=14"
39
38
  },
40
39
  "dependencies": {
41
- "@soybeanjs/eslint-config": "^1.2.3",
40
+ "@soybeanjs/eslint-config": "^1.3.2",
42
41
  "cli-progress": "3.12.0",
43
42
  "convert-gitmoji": "0.1.5",
44
43
  "dayjs": "1.11.10",
45
44
  "execa": "8.0.1",
46
- "ofetch": "1.3.3"
45
+ "ofetch": "1.3.4"
47
46
  },
48
47
  "devDependencies": {
49
- "@soybeanjs/cli": "1.0.8",
48
+ "@soybeanjs/cli": "1.0.11",
50
49
  "@types/cli-progress": "3.11.5",
51
- "@types/node": "20.11.24",
52
- "eslint": "8.57.0",
50
+ "@types/node": "20.12.7",
51
+ "eslint": "9.1.1",
53
52
  "lint-staged": "15.2.2",
54
- "simple-git-hooks": "2.9.0",
53
+ "simple-git-hooks": "2.11.1",
55
54
  "tsup": "^8.0.2",
56
- "tsx": "4.7.1",
57
- "typescript": "5.3.3"
55
+ "tsx": "4.7.2",
56
+ "typescript": "5.4.5"
58
57
  },
59
58
  "simple-git-hooks": {
60
59
  "commit-msg": "pnpm soy git-commit-verify",