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

hot-reloader-turbopack refactors #61929

Merged
merged 9 commits into from
Feb 12, 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
48 changes: 42 additions & 6 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ import { isEdgeRuntime } from '../lib/is-edge-runtime'
import { recursiveCopy } from '../lib/recursive-copy'
import { recursiveReadDir } from '../lib/recursive-readdir'
import {
loadBindings,
lockfilePatchPromise,
teardownTraceSubscriber,
teardownHeapProfiler,
createDefineEnv,
} from './swc'
import { getNamedRouteRegex } from '../shared/lib/router/utils/route-regex'
import { getFilesInDir } from '../lib/get-files-in-dir'
Expand Down Expand Up @@ -164,6 +166,7 @@ import { hasCustomExportOutput } from '../export/utils'
import { interopDefault } from '../lib/interop-default'
import { formatDynamicImportPath } from '../lib/format-dynamic-import-path'
import { isInterceptionRouteAppPath } from '../server/future/helpers/interception-routes'
import { getTurbopackJsConfig } from '../server/dev/turbopack-utils'
import { buildCustomRoute } from '../lib/build-custom-route'

interface ExperimentalBypassForInfo {
Expand Down Expand Up @@ -720,6 +723,13 @@ export default async function build(
.traceAsyncFn(() => loadCustomRoutes(config))

const { headers, rewrites, redirects } = customRoutes
const combinedRewrites: Rewrite[] = [
...rewrites.beforeFiles,
...rewrites.afterFiles,
...rewrites.fallback,
]
const hasRewrites = combinedRewrites.length > 0

NextBuildContext.originalRewrites = config._originalRewrites
NextBuildContext.originalRedirects = config._originalRedirects

Expand Down Expand Up @@ -1132,12 +1142,6 @@ export default async function build(
}
}

const combinedRewrites: Rewrite[] = [
...rewrites.beforeFiles,
...rewrites.afterFiles,
...rewrites.fallback,
]

if (config.experimental.clientRouterFilter) {
const nonInternalRedirects = (config._originalRedirects || []).filter(
(r: any) => !r.internal
Expand Down Expand Up @@ -1306,6 +1310,38 @@ export default async function build(
})

async function turbopackBuild(): Promise<never> {
if (!process.env.TURBOPACK || !process.env.TURBOPACK_BUILD) {
throw new Error("next build doesn't support turbopack yet")
}
const bindings = await loadBindings(config?.experimental?.useWasmBinary)
const project = await bindings.turbo.createProject({
projectPath: dir,
rootPath: config.experimental.outputFileTracingRoot || dir,
nextConfig: config.nextConfig,
jsConfig: await getTurbopackJsConfig(dir, config),
watch: false,
env: process.env as Record<string, string>,
defineEnv: createDefineEnv({
isTurbopack: true,
allowedRevalidateHeaderKeys: undefined,
clientRouterFilters: undefined,
config,
dev: false,
distDir,
fetchCacheKeyPrefix: undefined,
hasRewrites,
middlewareMatchers: undefined,
previewModeId: undefined,
}),
// TODO: fix
// serverAddr: `127.0.0.1:${opts.port}`,
serverAddr: `127.0.0.1:3000`,
})

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const iter = project.entrypointsSubscribe()
Copy link
Member

Choose a reason for hiding this comment

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

We should expose a non-subscribing method here

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this was just to get to the point where it can be called 👍

// for await (const entrypoints of iter) {
// }
throw new Error("next build doesn't support turbopack yet")
}
let buildTraceContext: undefined | BuildTraceContext
Expand Down
Loading