MCPcopy Create free account
hub / github.com/dmno-dev/bumpy / resolveSnapshot

Function resolveSnapshot

packages/bumpy/src/core/snapshot.ts:69–93  ·  view source on GitHub ↗
(
  rawName: string,
  config: BumpyConfig,
  rootDir: string,
  opts: { tag?: string; now?: Date } = {},
)

Source from the content-addressed store, hash-verified

67 * per-run version suffix for `sha`/`timestamp`. `now` is injectable for deterministic tests.
68 */
69export 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>` */
96export function snapshotVersion(target: string, snapshot: ResolvedSnapshot): string {

Callers 2

snapshot.test.tsFile · 0.90
publishSnapshotFunction · 0.90

Calls 3

sanitizeSnapshotNameFunction · 0.85
shortHeadShaFunction · 0.85
utcTimestampFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…