feat: Add common package * Add isEdge, safeTry and dataCache to new common package * Add eslint and move prettier config * Fix yarn lock * Clean up tests * Add lint-staged config to common * Add missing dependencies Approved-by: Joakim Jäderberg
23 lines
561 B
TypeScript
23 lines
561 B
TypeScript
import { getPrefix } from "./getPrefix"
|
|
|
|
export function generateCacheKey(
|
|
key: string | string[],
|
|
options?: { includeGitHashInKey?: boolean }
|
|
): string {
|
|
const includeGitHashInKey = options?.includeGitHashInKey ?? true
|
|
const keyArray = (Array.isArray(key) ? key : [key]).filter(Boolean)
|
|
|
|
if (keyArray.length === 0) {
|
|
throw new Error("No keys provided")
|
|
}
|
|
|
|
const prefix = getPrefix({
|
|
includeGitHashInKey,
|
|
includeBranchPrefix: true,
|
|
})
|
|
|
|
const keyTokens = [prefix, keyArray.join("_")].filter(Boolean).join(":")
|
|
|
|
return keyTokens
|
|
}
|