From b98d406731313a141ae943a01a1cd672e3973016 Mon Sep 17 00:00:00 2001 From: OJ Kwon <1210596+kwonoj@users.noreply.github.com> Date: Tue, 18 Jul 2023 09:58:53 -0700 Subject: [PATCH] feat(next-swc): support env var for --experimental-turbo --- packages/next/src/build/swc/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/next/src/build/swc/index.ts b/packages/next/src/build/swc/index.ts index c2c757fd70a9e..722a1a5d7811d 100644 --- a/packages/next/src/build/swc/index.ts +++ b/packages/next/src/build/swc/index.ts @@ -832,6 +832,9 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { return nativeBindings } + const customBindings = !!__INTERNAL_CUSTOM_TURBOPACK_BINDINGS + ? require(__INTERNAL_CUSTOM_TURBOPACK_BINDINGS) + : null let bindings: any let attempts: any[] = [] @@ -1027,13 +1030,13 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { }, nextBuild: (options: unknown) => { initHeapProfiler() - const ret = bindings.nextBuild(options) + const ret = (customBindings ?? bindings).nextBuild(options) return ret }, startTrace: (options = {}, turboTasks: unknown) => { initHeapProfiler() - const ret = bindings.runTurboTracing( + const ret = (customBindings ?? bindings).runTurboTracing( toBuffer({ exact: true, ...options }), turboTasks ) @@ -1049,7 +1052,7 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { pageExtensions: string[], fn: (entrypoints: any) => void ) => { - return bindings.streamEntrypoints( + return (customBindings ?? bindings).streamEntrypoints( turboTasks, rootDir, applicationDir, @@ -1063,7 +1066,7 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { applicationDir: string, pageExtensions: string[] ) => { - return bindings.getEntrypoints( + return (customBindings ?? bindings).getEntrypoints( turboTasks, rootDir, applicationDir, @@ -1071,7 +1074,7 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { ) }, }, - createProject: bindingToApi(bindings, false), + createProject: bindingToApi(customBindings ?? bindings, false), }, mdx: { compile: (src: string, options: any) =>