Skip to content

Commit

Permalink
add unstable prefix to persistent caching option and force to provide…
Browse files Browse the repository at this point in the history
… an expected level of stability
  • Loading branch information
sokra committed Oct 10, 2024
1 parent 075ee01 commit 547e3a7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ import {
handlePagesErrorRoute,
formatIssue,
isRelevantWarning,
isPersistentCachingEnabled,
} from '../server/dev/turbopack-utils'
import { TurbopackManifestLoader } from '../server/dev/turbopack/manifest-loader'
import type { Entrypoints } from '../server/dev/turbopack/types'
Expand Down Expand Up @@ -1409,7 +1410,7 @@ export default async function build(
browserslistQuery: supportedBrowsers.join(', '),
},
{
persistentCaching: config.experimental.turbo?.persistentCaching,
persistentCaching: isPersistentCachingEnabled(config),
memoryLimit: config.experimental.turbo?.memoryLimit,
}
)
Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
resolveExtensions: z.array(z.string()).optional(),
useSwcCss: z.boolean().optional(),
treeShaking: z.boolean().optional(),
persistentCaching: z.boolean().optional(),
persistentCaching: z
.union([z.number(), z.literal(false)])
.optional(),
memoryLimit: z.number().optional(),
moduleIdStrategy: z.enum(['named', 'deterministic']).optional(),
})
Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ export interface ExperimentalTurboOptions {

/**
* Enable persistent caching for the turbopack dev server and build.
* Need to provide the expected level of stability, otherwise it will fail.
* Currently stability level: 1
*/
persistentCaching?: boolean
unstablePersistentCaching?: number | false

/**
* Enable tree shaking for the turbopack dev server and build.
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
isWellKnownError,
printNonFatalIssue,
normalizedPageToTurbopackStructureRoute,
isPersistentCachingEnabled,
} from './turbopack-utils'
import {
propagateServerField,
Expand Down Expand Up @@ -176,7 +177,7 @@ export async function createHotReloaderTurbopack(
browserslistQuery: supportedBrowsers.join(', '),
},
{
persistentCaching: opts.nextConfig.experimental.turbo?.persistentCaching,
persistentCaching: isPersistentCachingEnabled(opts.nextConfig),
memoryLimit: opts.nextConfig.experimental.turbo?.memoryLimit,
}
)
Expand Down
12 changes: 12 additions & 0 deletions packages/next/src/server/dev/turbopack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1157,3 +1157,15 @@ export function normalizedPageToTurbopackStructureRoute(
}
return entrypointKey
}

export function isPersistentCachingEnabled(
config: NextConfigComplete
): boolean {
const unstableValue = config.experimental.turbo?.unstablePersistentCaching
if (typeof unstableValue === 'number' && unstableValue > 1) {
throw new Error(
'Persistent caching in this version of Turbopack is not as stable as expected. Upgrade to a newer version of Turbopack to use this feature with the expected stability.'
)
}
return !!unstableValue
}

0 comments on commit 547e3a7

Please sign in to comment.