Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose experimental option to set a memory limit for turbo #66101

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1378,29 +1378,34 @@ export default async function build(
const startTime = process.hrtime()
const bindings = await loadBindings(config?.experimental?.useWasmBinary)
const dev = false
const project = await bindings.turbo.createProject({
projectPath: dir,
rootPath: config.experimental.outputFileTracingRoot || dir,
nextConfig: config,
jsConfig: await getTurbopackJsConfig(dir, config),
watch: false,
dev,
env: process.env as Record<string, string>,
defineEnv: createDefineEnv({
isTurbopack: true,
clientRouterFilters: NextBuildContext.clientRouterFilters,
config,
const project = await bindings.turbo.createProject(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like husky formatted this automatically?

{
projectPath: dir,
rootPath: config.experimental.outputFileTracingRoot || dir,
nextConfig: config,
jsConfig: await getTurbopackJsConfig(dir, config),
watch: false,
dev,
distDir,
fetchCacheKeyPrefix: config.experimental.fetchCacheKeyPrefix,
hasRewrites,
// TODO: Implement
middlewareMatchers: undefined,
}),
buildId: NextBuildContext.buildId!,
encryptionKey: NextBuildContext.encryptionKey!,
previewProps: NextBuildContext.previewProps!,
})
env: process.env as Record<string, string>,
defineEnv: createDefineEnv({
isTurbopack: true,
clientRouterFilters: NextBuildContext.clientRouterFilters,
config,
dev,
distDir,
fetchCacheKeyPrefix: config.experimental.fetchCacheKeyPrefix,
hasRewrites,
// TODO: Implement
middlewareMatchers: undefined,
}),
buildId: NextBuildContext.buildId!,
encryptionKey: NextBuildContext.encryptionKey!,
previewProps: NextBuildContext.previewProps!,
},
{
memoryLimit: config.experimental.turbo?.memoryLimit,
}
)

await fs.mkdir(path.join(distDir, 'server'), { recursive: true })
await fs.mkdir(path.join(distDir, 'static', buildId), {
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
.optional(),
resolveExtensions: z.array(z.string()).optional(),
useSwcCss: z.boolean().optional(),
memoryLimit: z.number().optional(),
})
.optional(),
optimizePackageImports: z.array(z.string()).optional(),
Expand Down
5 changes: 5 additions & 0 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ export interface ExperimentalTurboOptions {
* Use swc_css instead of lightningcss for turbopakc
*/
useSwcCss?: boolean

/**
* A target memory limit for turbo, in bytes.
*/
memoryLimit?: number
}

export interface WebpackConfigContext {
Expand Down
51 changes: 28 additions & 23 deletions packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,35 @@ export async function createHotReloaderTurbopack(
hotReloaderSpan.stop()

const encryptionKey = await generateEncryptionKeyBase64(true)
const project = await bindings.turbo.createProject({
projectPath: dir,
rootPath: opts.nextConfig.experimental.outputFileTracingRoot || dir,
nextConfig: opts.nextConfig,
jsConfig: await getTurbopackJsConfig(dir, nextConfig),
watch: true,
dev: true,
env: process.env as Record<string, string>,
defineEnv: createDefineEnv({
isTurbopack: true,
// TODO: Implement
clientRouterFilters: undefined,
config: nextConfig,
const project = await bindings.turbo.createProject(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same again...

{
projectPath: dir,
rootPath: opts.nextConfig.experimental.outputFileTracingRoot || dir,
nextConfig: opts.nextConfig,
jsConfig: await getTurbopackJsConfig(dir, nextConfig),
watch: true,
dev: true,
distDir,
fetchCacheKeyPrefix: opts.nextConfig.experimental.fetchCacheKeyPrefix,
hasRewrites,
// TODO: Implement
middlewareMatchers: undefined,
}),
buildId,
encryptionKey,
previewProps: opts.fsChecker.prerenderManifest.preview,
})
env: process.env as Record<string, string>,
defineEnv: createDefineEnv({
isTurbopack: true,
// TODO: Implement
clientRouterFilters: undefined,
config: nextConfig,
dev: true,
distDir,
fetchCacheKeyPrefix: opts.nextConfig.experimental.fetchCacheKeyPrefix,
hasRewrites,
// TODO: Implement
middlewareMatchers: undefined,
}),
buildId,
encryptionKey,
previewProps: opts.fsChecker.prerenderManifest.preview,
},
{
memoryLimit: opts.nextConfig.experimental.turbo?.memoryLimit,
}
)
const entrypointsSubscription = project.entrypointsSubscribe()

const currentEntrypoints: Entrypoints = {
Expand Down
Loading