Skip to content

Commit

Permalink
Move cacheDir logic to getCacheDir
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Jan 2, 2024
1 parent 145a0c0 commit e82e3f8
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,22 @@ function pageToRoute(page: string) {
}
}

function getCacheDir(distDir: string): string {
const cacheDir = path.join(distDir, 'cache')
if (ciEnvironment.isCI && !ciEnvironment.hasNextSupport) {
const hasCache = existsSync(cacheDir)

if (!hasCache) {
// Intentionally not piping to stderr which is what `Log.warn` does in case people fail in CI when
// stderr is detected.
console.log(
`${Log.prefixes.warn} No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache`
)
}
}
return cacheDir
}

export default async function build(
dir: string,
reactProductionProfiling = false,
Expand Down Expand Up @@ -427,18 +443,7 @@ export default async function build(
NextBuildContext.originalRewrites = config._originalRewrites
NextBuildContext.originalRedirects = config._originalRedirects

const cacheDir = path.join(distDir, 'cache')
if (ciEnvironment.isCI && !ciEnvironment.hasNextSupport) {
const hasCache = existsSync(cacheDir)

if (!hasCache) {
// Intentionally not piping to stderr in case people fail in CI when
// stderr is detected.
console.log(
`${Log.prefixes.warn} No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache`
)
}
}
const cacheDir = getCacheDir(distDir)

const telemetry = new Telemetry({ distDir })

Expand Down

0 comments on commit e82e3f8

Please sign in to comment.