MCPcopy
hub / github.com/vercel/next.js / checkBuildFreshness

Function checkBuildFreshness

test/lib/check-build-freshness.js:14–57  ·  view source on GitHub ↗

* Check if the Next.js build is fresh (matches current git HEAD). * Prints warnings to console if build is missing or stale. * @returns {Promise<void>}

()

Source from the content-addressed store, hash-verified

12 * @returns {Promise<void>}
13 */
14async function checkBuildFreshness() {
15 const distPath = path.join(__dirname, '../../packages/next/dist')
16 const buildCommitPath = path.join(distPath, '.build-commit')
17
18 if (!existsSync(distPath)) {
19 console.warn(`${YELLOW}⚠️ WARNING: No build found!${RESET}`)
20 console.warn(
21 `${YELLOW} The packages/next/dist directory does not exist.${RESET}`
22 )
23 console.warn(
24 `${YELLOW} Run \`pnpm build\` before running tests.\n${RESET}`
25 )
26 return
27 }
28
29 if (!existsSync(buildCommitPath)) {
30 console.warn(`${YELLOW}⚠️ WARNING: Build may be stale!${RESET}`)
31 console.warn(
32 `${YELLOW} Unable to verify build freshness (no .build-commit marker).${RESET}`
33 )
34 console.warn(`${YELLOW} Run \`pnpm build\` to rebuild.\n${RESET}`)
35 return
36 }
37
38 try {
39 const buildCommit = (await fsp.readFile(buildCommitPath, 'utf8')).trim()
40 const currentCommit = execSync('git rev-parse HEAD', {
41 encoding: 'utf8',
42 }).trim()
43
44 if (buildCommit !== currentCommit) {
45 console.warn(`${YELLOW}⚠️ WARNING: Build is stale!${RESET}`)
46 console.warn(
47 `${YELLOW} Build was compiled at commit: ${buildCommit.slice(0, 8)}${RESET}`
48 )
49 console.warn(
50 `${YELLOW} Current HEAD is at commit: ${currentCommit.slice(0, 8)}${RESET}`
51 )
52 console.warn(`${YELLOW} Run \`pnpm build\` to rebuild.\n${RESET}`)
53 }
54 } catch (err) {
55 // Ignore errors (e.g., git not available)
56 }
57}
58
59module.exports = { checkBuildFreshness }

Callers 2

globalSetupFunction · 0.90
mainFunction · 0.85

Calls 5

trimMethod · 0.80
joinMethod · 0.45
warnMethod · 0.45
readFileMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected