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

Use separate workers for webpackBuildWorker #46666

Merged
merged 5 commits into from
Mar 2, 2023
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
17 changes: 17 additions & 0 deletions packages/next/src/build/build-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@ import type { __ApiPreviewProps } from '../server/api-utils'
import type { NextConfigComplete } from '../server/config-shared'
import type { Span } from '../trace'
import type getBaseWebpackConfig from './webpack-config'
import { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
import type { TelemetryPlugin } from './webpack/plugins/telemetry-plugin'

// a global object to store context for the current build
// this is used to pass data between different steps of the build without having
// to pass it through function arguments.
// Not exhaustive, but should be extended to as needed whilst refactoring
export const NextBuildContext: Partial<{
compilerIdx?: number
serializedFlightMaps?: {
injectedClientEntries?: any
serverModuleIds?: any
edgeServerModuleIds?: any
asyncClientModules?: any
serverActions?: any
serverCSSManifest?: any
edgeServerCSSManifest?: any
}
serializedPagesManifestEntries: {
edgeServerPages?: PagesManifest
nodeServerPages?: PagesManifest
edgeServerAppPaths?: PagesManifest
nodeServerAppPaths?: PagesManifest
}
// core fields
dir: string
buildId: string
Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,9 @@ export default async function build(
if (filesTracedFromEntries.length) {
// The turbo trace doesn't provide the traced file type and reason at present
// let's write the traced files into the first [entry].nft.json
// @ts-expect-error types
const [[, entryName]] = Array.from(entryNameMap.entries()).filter(
// @ts-expect-error types
([k]) => k.startsWith(turbotraceContextAppDir)
)
const traceOutputPath = path.join(
Expand All @@ -1085,7 +1087,7 @@ export default async function build(
}
if (chunksTrace) {
const { action, outputPath } = chunksTrace
action.input = action.input.filter((f) => {
action.input = action.input.filter((f: any) => {
const outputPagesPath = path.join(outputPath, '..', 'pages')
return (
!f.startsWith(outputPagesPath) ||
Expand Down
11 changes: 9 additions & 2 deletions packages/next/src/build/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const ArchName = arch()
const PlatformName = platform()
const triples = platformArchTriples[PlatformName][ArchName] || []

const infoLog = (...args: any[]) => {
if (process.env.NEXT_PRIVATE_BUILD_WORKER) {
return
}
Log.info(...args)
}

// Allow to specify an absolute path to the custom turbopack binary to load.
// If one of env variables is set, `loadNative` will try to use any turbo-* interfaces from specified
// binary instead. This will not affect existing swc's transform, or other interfaces. This is thin,
Expand Down Expand Up @@ -213,7 +220,7 @@ async function loadWasm(importPath = '') {
if (pkg === '@next/swc-wasm-web') {
bindings = await bindings.default()
}
Log.info('Using wasm build of next-swc')
infoLog('Using wasm build of next-swc')

// Note wasm binary does not support async intefaces yet, all async
// interface coereces to sync interfaces.
Expand Down Expand Up @@ -292,7 +299,7 @@ function loadNative(isCustomTurbopack = false) {
for (const triple of triples) {
try {
bindings = require(`@next/swc/native/next-swc.${triple.platformArchABI}.node`)
Log.info('Using locally built binary of @next/swc')
infoLog('Using locally built binary of @next/swc')
break
} catch (e) {}
}
Expand Down
Loading