File size: 657 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
export async function generateBuildId(
generate: () => string | null | Promise<string | null>,
fallback: () => string
): Promise<string> {
let buildId = await generate()
// If there's no buildId defined we'll fall back
if (buildId === null) {
// We also create a new buildId if it contains the word `ad` to avoid false
// positives with ad blockers
while (!buildId || /ad/i.test(buildId)) {
buildId = fallback()
}
}
if (typeof buildId !== 'string') {
throw new Error(
'generateBuildId did not return a string. https://nextjs.org/docs/messages/generatebuildid-not-a-string'
)
}
return buildId.trim()
}
|