(
rawName: string,
config: BumpyConfig,
rootDir: string,
opts: { tag?: string; now?: Date } = {},
)
| 67 | * per-run version suffix for `sha`/`timestamp`. `now` is injectable for deterministic tests. |
| 68 | */ |
| 69 | export function resolveSnapshot( |
| 70 | rawName: string, |
| 71 | config: BumpyConfig, |
| 72 | rootDir: string, |
| 73 | opts: { tag?: string; now?: Date } = {}, |
| 74 | ): ResolvedSnapshot { |
| 75 | const name = sanitizeSnapshotName(rawName); |
| 76 | const strategy = config.snapshot.versionStrategy; |
| 77 | |
| 78 | let suffix: string; |
| 79 | if (strategy === 'sha') { |
| 80 | const sha = shortHeadSha(rootDir); |
| 81 | if (!sha) { |
| 82 | throw new Error( |
| 83 | 'Snapshot versionStrategy "sha" needs a git commit to derive the version from, but HEAD could not be resolved.\n' + |
| 84 | ' Commit your changes (or switch `snapshot.versionStrategy` to "timestamp").', |
| 85 | ); |
| 86 | } |
| 87 | suffix = sha; |
| 88 | } else { |
| 89 | suffix = utcTimestamp(opts.now ?? new Date()); |
| 90 | } |
| 91 | |
| 92 | return { rawName, name, tag: opts.tag ?? name, strategy, suffix }; |
| 93 | } |
| 94 | |
| 95 | /** Compose the snapshot version for one target: `<target>-<name>-<suffix>` */ |
| 96 | export function snapshotVersion(target: string, snapshot: ResolvedSnapshot): string { |
no test coverage detected
searching dependent graphs…