keepchanges 1.0.1 → 1.0.2

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
@@ -50,7 +50,7 @@ npx keepchanges <version> [options]
50
50
  | Argument or option | Default | Description |
51
51
  | --- | --- | --- |
52
52
  | `<version>` | Required | Version to generate. Accepts `1.1.0` or `v1.1.0`. A version containing `-`, such as `1.1.0-beta.1`, is treated as a prerelease. |
53
- | `--from <ref>` | Latest matching tag | Overrides the starting Git ref used to read commits. A version such as `1.0.0` uses the configured tag prefix. |
53
+ | `--from <ref>` | Inferred from target | Overrides the exclusive starting Git ref used to read commits. Without it, the latest matching tag is used for `HEAD`, or the previous matching tag relative to an explicit `--to`. If no previous tag exists, history starts at the first commit. A version such as `1.0.0` uses the configured tag prefix. |
54
54
  | `--to <ref>` | `HEAD` | Sets the ending Git ref. A version such as `1.1.0` uses the configured tag prefix. It cannot be combined with `--release`, and must resolve to the current `HEAD` when used with `--commit`. |
55
55
  | `--repository <source>` | Auto-detected | Sets a GitHub `owner/repo` slug or a complete GitHub/Gitea URL. It takes precedence over `package.json` and `origin`. |
56
56
  | `--output <path>` | `CHANGELOG.md` | Sets the changelog file path. Relative paths are resolved from the current working directory. |
@@ -113,6 +113,12 @@ Use a package-specific tag prefix:
113
113
  npx keepchanges 1.1.0 --tag-prefix 'package@'
114
114
  ```
115
115
 
116
+ Rebuild a historical release without specifying its previous tag:
117
+
118
+ ```bash
119
+ npx keepchanges 1.0.0 --to 1.0.0 --dry
120
+ ```
121
+
116
122
  Preview a Release without writing, committing, tagging, pushing, or calling the
117
123
  release API:
118
124
 
@@ -146,6 +152,9 @@ new tags, existing-tag lookup, version-shaped `--from` and `--to` values,
146
152
  comparison links, and repository Release names. Branch names, commit hashes,
147
153
  `HEAD`, and other non-version refs are used unchanged. Tag lookup only considers
148
154
  the configured prefix, so independent tag sequences do not affect each other.
155
+ When `--to` is provided without `--from`, the CLI finds the previous matching
156
+ tag relative to that target instead of the current `HEAD`. For the first tag in
157
+ a sequence, it reads all commits reachable from the target.
149
158
 
150
159
  Entries use Git author names by default and include `Co-Authored-By`
151
160
  participants. Bot accounts are omitted. With the corresponding provider token,
package/README.zh-CN.md CHANGED
@@ -49,7 +49,7 @@ npx keepchanges <version> [options]
49
49
  | 参数 | 默认值 | 说明 |
50
50
  | --- | --- | --- |
51
51
  | `<version>` | 必填 | 要生成的版本号。可以传入 `1.1.0` 或 `v1.1.0`。包含 `-` 的版本会作为预发布版本,例如 `1.1.0-beta.1`。 |
52
- | `--from <ref>` | 匹配前缀的最近 tag | 指定读取 commit 的起始 Git ref,并覆盖自动选择结果。`1.0.0` 这类版本会自动应用配置的 tag 前缀。 |
52
+ | `--from <ref>` | 根据目标推断 | 指定读取 commit 时不包含在结果中的起始 Git ref,并覆盖自动选择结果。省略时,目标为 `HEAD` 会使用匹配前缀的最近 tag;显式传入 `--to` 会查找该目标之前匹配前缀的 tag。如果不存在前一个 tag,则从首个 commit 开始读取。`1.0.0` 这类版本会自动应用配置的 tag 前缀。 |
53
53
  | `--to <ref>` | `HEAD` | 指定读取 commit 的结束 Git ref。`1.1.0` 这类版本会自动应用配置的 tag 前缀。不能与 `--release` 一起使用;与 `--commit` 一起使用时必须指向当前 `HEAD`。 |
54
54
  | `--repository <source>` | 自动检测 | 指定 `owner/repo` 格式的 GitHub 仓库或 GitHub/Gitea 完整 URL。优先级高于 `package.json` 和 `origin`。 |
55
55
  | `--output <path>` | `CHANGELOG.md` | 指定 changelog 文件路径。相对路径以当前工作目录为基准。 |
@@ -112,6 +112,12 @@ npx keepchanges 1.1.0 --no-tag-prefix
112
112
  npx keepchanges 1.1.0 --tag-prefix 'package@'
113
113
  ```
114
114
 
115
+ 不指定前一个 tag,重新生成历史版本:
116
+
117
+ ```bash
118
+ npx keepchanges 1.0.0 --to 1.0.0 --dry
119
+ ```
120
+
115
121
  预览 Release,不写文件、不提交、不创建 tag、不推送且不调用发布 API:
116
122
 
117
123
  ```bash
@@ -141,6 +147,9 @@ GitHub 和 Gitea 均支持作者解析和 Release 发布;Gitea 使用 `GITEA_T
141
147
  版本形式的 `--from` 和 `--to`、比较链接及仓库 Release 名称。分支名、commit
142
148
  hash、`HEAD` 等非版本 ref 保持不变。自动查找 tag 时只考虑配置的前缀,因此
143
149
  彼此独立的 tag 序列不会相互影响。
150
+ 省略 `--from` 并传入 `--to` 时,CLI 会相对于该目标查找匹配前缀的前一个 tag,
151
+ 而不是使用当前 `HEAD` 的最近 tag。如果目标是该序列中的首个 tag,则读取该目标
152
+ 可达的全部 commit。
144
153
 
145
154
  默认使用 Git 提交中的作者名,并将 `Co-Authored-By` 参与者一起写入记录,bot
146
155
  账号会被忽略。提供对应平台的 token 后,会尝试将邮箱解析为用户名。
package/dist/cli.mjs CHANGED
@@ -8,7 +8,7 @@ import { resolve } from "node:path";
8
8
  import ansis from "ansis";
9
9
  import { x } from "tinyexec";
10
10
  //#region package.json
11
- var version = "1.0.1";
11
+ var version = "1.0.2";
12
12
  //#endregion
13
13
  //#region src/git.ts
14
14
  function versionTagPattern(tagPrefix) {
@@ -43,7 +43,9 @@ async function getPreviousTag(cwd, tag, releaseRef, tagPrefix) {
43
43
  if (releaseVersion && !releaseVersion.includes("-")) {
44
44
  const previousStable = (await git(cwd, "tag", "--merged", releaseRef, "--sort=-version:refname")).trim().split("\n").find((candidate) => {
45
45
  if (candidate === tag || !candidate.startsWith(tagPrefix)) return false;
46
- const version = normalizeFull(candidate.slice(tagPrefix.length));
46
+ const versionTag = candidate.slice(tagPrefix.length);
47
+ if (!/^\d/.test(versionTag)) return false;
48
+ const version = normalizeFull(versionTag);
47
49
  return Boolean(version && !version.includes("-"));
48
50
  });
49
51
  if (previousStable) return previousStable;
@@ -353,10 +355,11 @@ async function createChanges(options, environment) {
353
355
  taggedCommit = await getTagCommit(environment.cwd, tag);
354
356
  releaseRef = tag;
355
357
  }
356
- const from = options.from ?? (taggedCommit ? await getPreviousTag(environment.cwd, tag, releaseRef, options.tagPrefix) : await getLatestTag(environment.cwd, options.tagPrefix));
357
358
  const to = releaseRef || options.to;
358
- const resolvedFrom = from ? await resolveVersionRef(environment.cwd, from, options.tagPrefix) : "";
359
359
  const resolvedTo = await resolveVersionRef(environment.cwd, to, options.tagPrefix);
360
+ const inferFromTarget = releaseRef !== void 0 || options.to !== defaultConfig.cli.to;
361
+ const from = options.from ?? (inferFromTarget ? await getPreviousTag(environment.cwd, tag, resolvedTo, options.tagPrefix) : await getLatestTag(environment.cwd, options.tagPrefix));
362
+ const resolvedFrom = from ? await resolveVersionRef(environment.cwd, from, options.tagPrefix) : "";
360
363
  const comparisonFrom = resolvedFrom || (repository ? await git(environment.cwd, "rev-list", "--max-parents=0", resolvedTo).then((value) => value.trim()) : "");
361
364
  const commits = parseCommits(await readGitCommits(environment.cwd, resolvedFrom, resolvedTo));
362
365
  if (token && repository) await repository.provider.resolveAuthors?.(commits, repository, token, environment.fetch ?? globalThis.fetch);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "keepchanges",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "description": "Generate and maintain CHANGELOG.md from Conventional Commits.",
6
6
  "author": "edram",
7
7
  "license": "MIT",