Skip to content

Commit

Permalink
feat(next-dev): add a new experimental flag (#51895)
Browse files Browse the repository at this point in the history
### What?

WEB-1239. This is mainly for the code paths to not to cause regressions to existing turbopack.
  • Loading branch information
kwonoj committed Jun 27, 2023
1 parent a04a34d commit 73c905d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/next-swc/crates/napi/src/turbopack.rs
Expand Up @@ -181,3 +181,8 @@ impl From<NapiRouteHas> for RouteHas {
pub async fn next_build(ctx: NextBuildContext) -> napi::Result<()> {
turbo_next_build(ctx.try_into()?).await.convert_err()
}

#[napi]
pub async fn experimental_turbo(_unused: Buffer) -> napi::Result<()> {
unimplemented!("__experimental_turbo is not yet implemented");
}
9 changes: 9 additions & 0 deletions packages/next/src/build/swc/index.ts
Expand Up @@ -296,6 +296,9 @@ async function loadWasm(importPath = '', isCustomTurbopack: boolean) {
startTrace: () => {
Log.error('Wasm binding does not support trace yet')
},
experimentalTurbo: () => {
Log.error('Wasm binding does not support this interface')
},
entrypoints: {
stream: (
turboTasks: any,
Expand Down Expand Up @@ -555,6 +558,12 @@ function loadNative(isCustomTurbopack = false) {
)
return ret
},
experimentalTurbo: () => {
initHeapProfiler()

const ret = bindings.experimentalTurbo()
return ret
},
createTurboTasks: (memoryLimit?: number): unknown =>
bindings.createTurboTasks(memoryLimit),
entrypoints: {
Expand Down
8 changes: 8 additions & 0 deletions packages/next/src/cli/next-dev.ts
Expand Up @@ -119,6 +119,7 @@ const nextDev: CliCommand = async (argv) => {
'--port': Number,
'--hostname': String,
'--turbo': Boolean,
'--experimental-turbo': Boolean,

// To align current messages with native binary.
// Will need to adjust subcommand later.
Expand Down Expand Up @@ -209,6 +210,7 @@ const nextDev: CliCommand = async (argv) => {
// We do not set a default host value here to prevent breaking
// some set-ups that rely on listening on other interfaces
const host = args['--hostname']
const experimentalTurbo = args['--experimental-turbo']

const devServerOptions: StartServerOptions = {
dir,
Expand All @@ -218,6 +220,7 @@ const nextDev: CliCommand = async (argv) => {
hostname: host,
// This is required especially for app dir.
useWorkers: true,
isExperimentalTurbo: experimentalTurbo,
}

if (args['--turbo']) {
Expand Down Expand Up @@ -311,6 +314,11 @@ const nextDev: CliCommand = async (argv) => {

return server
} else {
if (experimentalTurbo) {
Log.error('Not supported yet')
process.exit(1)
}

let cleanupFns: (() => Promise<void> | void)[] = []
const runDevServer = async () => {
const oldCleanupFns = cleanupFns
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/lib/start-server.ts
Expand Up @@ -22,6 +22,7 @@ export interface StartServerOptions {
useWorkers: boolean
allowRetry?: boolean
isTurbopack?: boolean
isExperimentalTurbo?: boolean
keepAliveTimeout?: number
onStdout?: (data: any) => void
onStderr?: (data: any) => void
Expand Down

0 comments on commit 73c905d

Please sign in to comment.