Unverified Commit 2cea3f70 authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

feat(next-swc): support env var for --experimental-turbo (#52841)



### What?

Minor update to next-swc to support `__INTERNAL_CUSTOM_TURBOPACK_BINDINGS` for the --experimental-turbo entrypoint as same as current --turbo.
parent 5bf2bbb3
...@@ -832,6 +832,9 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { ...@@ -832,6 +832,9 @@ function loadNative(isCustomTurbopack = false, importPath?: string) {
return nativeBindings return nativeBindings
} }
const customBindings = !!__INTERNAL_CUSTOM_TURBOPACK_BINDINGS
? require(__INTERNAL_CUSTOM_TURBOPACK_BINDINGS)
: null
let bindings: any let bindings: any
let attempts: any[] = [] let attempts: any[] = []
...@@ -1027,13 +1030,13 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { ...@@ -1027,13 +1030,13 @@ function loadNative(isCustomTurbopack = false, importPath?: string) {
}, },
nextBuild: (options: unknown) => { nextBuild: (options: unknown) => {
initHeapProfiler() initHeapProfiler()
const ret = bindings.nextBuild(options) const ret = (customBindings ?? bindings).nextBuild(options)
return ret return ret
}, },
startTrace: (options = {}, turboTasks: unknown) => { startTrace: (options = {}, turboTasks: unknown) => {
initHeapProfiler() initHeapProfiler()
const ret = bindings.runTurboTracing( const ret = (customBindings ?? bindings).runTurboTracing(
toBuffer({ exact: true, ...options }), toBuffer({ exact: true, ...options }),
turboTasks turboTasks
) )
...@@ -1049,7 +1052,7 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { ...@@ -1049,7 +1052,7 @@ function loadNative(isCustomTurbopack = false, importPath?: string) {
pageExtensions: string[], pageExtensions: string[],
fn: (entrypoints: any) => void fn: (entrypoints: any) => void
) => { ) => {
return bindings.streamEntrypoints( return (customBindings ?? bindings).streamEntrypoints(
turboTasks, turboTasks,
rootDir, rootDir,
applicationDir, applicationDir,
...@@ -1063,7 +1066,7 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { ...@@ -1063,7 +1066,7 @@ function loadNative(isCustomTurbopack = false, importPath?: string) {
applicationDir: string, applicationDir: string,
pageExtensions: string[] pageExtensions: string[]
) => { ) => {
return bindings.getEntrypoints( return (customBindings ?? bindings).getEntrypoints(
turboTasks, turboTasks,
rootDir, rootDir,
applicationDir, applicationDir,
...@@ -1071,7 +1074,7 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { ...@@ -1071,7 +1074,7 @@ function loadNative(isCustomTurbopack = false, importPath?: string) {
) )
}, },
}, },
createProject: bindingToApi(bindings, false), createProject: bindingToApi(customBindings ?? bindings, false),
}, },
mdx: { mdx: {
compile: (src: string, options: any) => compile: (src: string, options: any) =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment