@reelout/core 0.5.3 → 0.6.0

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.
@@ -0,0 +1,44 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { showParsedGitHistory, type ShowGitHistoryOptions } from '#git'
5
+ import type { GitCommit } from '#types'
6
+ import type { ReleaseMarker } from '../committing/isReleaseCommit'
7
+ import { isReleaseCommit } from '../committing/isReleaseCommit'
8
+
9
+ export interface UnreleasedOptions extends ShowGitHistoryOptions {
10
+ marker?: ReleaseMarker | undefined
11
+ }
12
+
13
+ export interface UnreleasedWindow {
14
+ history: GitCommit[]
15
+ stop: GitCommit | null
16
+ }
17
+
18
+ /**
19
+ * Collect unreleased commits from repository history.
20
+ *
21
+ * Walks parsed commit history in order and gathers every commit preceding the
22
+ * first release commit. Exposes the release commit that ended the walk so
23
+ * callers can inspect it, for example to read its release filter trailer.
24
+ *
25
+ * @param cwd Path to the working directory for git commands
26
+ * @param options Options for configuring Git history retrieval
27
+ * @returns The unreleased commits and the release commit that stopped the walk
28
+ */
29
+ export async function collectUnreleased(
30
+ cwd: string,
31
+ options: UnreleasedOptions = {}
32
+ ): Promise<UnreleasedWindow> {
33
+ const history: GitCommit[] = []
34
+
35
+ for await (const commit of showParsedGitHistory(cwd, options)) {
36
+ if (await isReleaseCommit(cwd, commit, options.marker)) {
37
+ return { history, stop: commit }
38
+ }
39
+
40
+ history.push(commit)
41
+ }
42
+
43
+ return { history, stop: null }
44
+ }
@@ -1,10 +1,12 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
+ export * from './collectUnreleased'
4
5
  export * from './deriveChangeReleases'
5
6
  export * from './deriveTransitionReleases'
6
7
  export * from './isCommitForPackage'
7
8
  export * from './promotePrereleaseVersions'
8
9
  export * from './propagateDependencyUpdates'
10
+ export * from './readPackageHistory'
9
11
  export * from './sliceUnreleased'
10
- export * from './streamPackageCommits'
12
+ export * from './sliceUnreleasedForPackage'
@@ -8,7 +8,7 @@ import { isCommitForPackage } from './isCommitForPackage'
8
8
  /**
9
9
  * Yield commits from git history associated with a package.
10
10
  *
11
- * Filters git commit history to stream only entries relevant to the target
11
+ * Filters git commit history to yield only entries relevant to the target
12
12
  * `pkg` directory.
13
13
  *
14
14
  * @param cwd Path to the working directory for git commands
@@ -16,7 +16,7 @@ import { isCommitForPackage } from './isCommitForPackage'
16
16
  * @param options Options for parsing and filtering git history
17
17
  * @yields Commits belonging to the specified package
18
18
  */
19
- export async function* streamPackageCommits(
19
+ export async function* readPackageHistory(
20
20
  cwd: string,
21
21
  pkg: Package,
22
22
  options: ShowGitHistoryOptions = {}
@@ -1,22 +1,14 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
- import { showParsedGitHistory, type ShowGitHistoryOptions } from '#git'
5
4
  import type { GitCommit } from '#types'
6
- import {
7
- isReleaseCommit,
8
- type ReleaseMarker,
9
- } from '../committing/isReleaseCommit'
10
-
11
- export interface SliceUnreleasedOptions extends ShowGitHistoryOptions {
12
- marker?: ReleaseMarker | undefined
13
- }
5
+ import { collectUnreleased, type UnreleasedOptions } from './collectUnreleased'
14
6
 
15
7
  /**
16
8
  * Yield parsed commits from the workspace until a release commit is found.
17
9
  *
18
- * Iterates through parsed commit history and yields unreleased commits in
19
- * order. Stops processing upon reaching the first release commit.
10
+ * Collects unreleased commits ahead of the most recent release commit and
11
+ * yields them in order.
20
12
  *
21
13
  * @param cwd Path to the working directory
22
14
  * @param options Options for configuring Git history retrieval
@@ -24,13 +16,9 @@ export interface SliceUnreleasedOptions extends ShowGitHistoryOptions {
24
16
  */
25
17
  export async function* sliceUnreleased(
26
18
  cwd: string,
27
- options?: SliceUnreleasedOptions
19
+ options?: UnreleasedOptions
28
20
  ): AsyncGenerator<GitCommit> {
29
- for await (const commit of showParsedGitHistory(cwd, options)) {
30
- if (await isReleaseCommit(cwd, commit, options?.marker)) {
31
- break
32
- }
21
+ const { history } = await collectUnreleased(cwd, options)
33
22
 
34
- yield commit
35
- }
23
+ yield* history
36
24
  }
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { GitCommit, Package } from '#types'
5
+ import { isMatch } from '#util'
6
+ import { isReleaseCommit } from '../committing/isReleaseCommit'
7
+ import { readReleaseFilterPatterns } from '../committing/readReleaseFilterPatterns'
8
+ import type { UnreleasedOptions } from './collectUnreleased'
9
+ import { readPackageHistory } from './readPackageHistory'
10
+
11
+ /**
12
+ * Yield unreleased commits from the history of a single package.
13
+ *
14
+ * Streams commits that touch the package files in historical order and stops
15
+ * at the first release commit that released the package. Release commits
16
+ * created by filtered runs that excluded the package are themselves yielded
17
+ * as unreleased changes, so every package keeps its own release boundary
18
+ * instead of sharing the latest repository-wide release commit.
19
+ *
20
+ * @param cwd Path to the working directory for git commands
21
+ * @param pkg Package whose files scope the commit history
22
+ * @param options Options for configuring Git history retrieval
23
+ * @yields Parsed commits up to the package's most recent release commit
24
+ */
25
+ export async function* sliceUnreleasedForPackage(
26
+ cwd: string,
27
+ pkg: Package,
28
+ options: UnreleasedOptions = {}
29
+ ): AsyncGenerator<GitCommit> {
30
+ for await (const commit of readPackageHistory(cwd, pkg, options)) {
31
+ if (await isReleaseCommit(cwd, commit, options.marker)) {
32
+ const patterns = readReleaseFilterPatterns(commit)
33
+
34
+ if (patterns === null || isMatch(pkg.name ?? '', patterns)) {
35
+ break
36
+ }
37
+ }
38
+
39
+ yield commit
40
+ }
41
+ }
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ /**
5
+ * Format filter patterns as a release filter trailer value.
6
+ *
7
+ * Escapes the commas within patterns and joins them with commas, so
8
+ * `readReleaseFilterPatterns` can split the trailer value back into the
9
+ * original patterns.
10
+ *
11
+ * @param patterns Filter patterns to format into a trailer value
12
+ * @returns The comma-joined, escaped trailer value
13
+ */
14
+ export function formatReleaseFilterPatterns(
15
+ patterns: readonly string[]
16
+ ): string {
17
+ return patterns.map((pattern) => pattern.replaceAll(',', '\\,')).join(', ')
18
+ }
@@ -1,5 +1,7 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
+ export * from './formatReleaseFilterPatterns'
4
5
  export * from './generateReleaseCommitMessage'
5
6
  export * from './isReleaseCommit'
7
+ export * from './readReleaseFilterPatterns'
@@ -0,0 +1,38 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { GIT_TRAILER_RELEASE_FILTER } from '#config'
5
+ import type { GitCommit } from '#types'
6
+
7
+ /**
8
+ * Read release filter patterns from a parsed commit.
9
+ *
10
+ * Collects the release filter trailer values and splits them into individual
11
+ * comma-separated filter patterns, unescaping the commas within patterns.
12
+ * Returns `null` when the commit carries no release filter trailer, so
13
+ * callers can treat it as a release of every package.
14
+ *
15
+ * @param commit Parsed commit object or nullish value
16
+ * @returns Filter patterns carried by the trailer, or `null` when absent
17
+ */
18
+ export function readReleaseFilterPatterns(
19
+ commit: GitCommit | null | undefined
20
+ ): string[] | null {
21
+ if (!commit) {
22
+ return null
23
+ }
24
+
25
+ const values = commit.trailers
26
+ .filter((trailer) => trailer.key === GIT_TRAILER_RELEASE_FILTER)
27
+ .map((trailer) => trailer.value)
28
+
29
+ if (values.length === 0) {
30
+ return null
31
+ }
32
+
33
+ return values
34
+ .flatMap((value) => value.split(/(?<!\\),/))
35
+ .map((pattern) => pattern.trim())
36
+ .map((pattern) => pattern.replaceAll('\\,', ','))
37
+ .filter((pattern) => pattern.length > 0)
38
+ }
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { Package } from '#types'
5
+ import { isMatch } from '#util'
6
+
7
+ /**
8
+ * Filter packages by name patterns.
9
+ *
10
+ * Keeps the packages whose names match `patterns`, scoping a release run to
11
+ * a subset of the discovered workspace. Returns a copy of every package when
12
+ * `patterns` is empty.
13
+ *
14
+ * @param packages Workspace packages to filter
15
+ * @param patterns Minimatch patterns to match package names against
16
+ * @returns Packages whose names match the patterns
17
+ */
18
+ export function filterPackages(
19
+ packages: readonly Package[],
20
+ patterns: readonly string[]
21
+ ): Package[] {
22
+ if (patterns.length === 0) {
23
+ return [...packages]
24
+ }
25
+
26
+ return packages.filter((pkg) => isMatch(pkg.name ?? '', patterns))
27
+ }
@@ -3,6 +3,7 @@
3
3
 
4
4
  export * from './buildDependencyGraph'
5
5
  export * from './discoverPackageTag'
6
+ export * from './filterPackages'
6
7
  export * from './resolvePackageStableTag'
7
8
  export * from './resolvePackageTag'
8
9
  export * from './sortPackages'