Unverified Commit e6bf5f69 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Turbopack: Only patch lockfile when bindings fails to load (#91379)

## What?

Currently the lockfile patching is always triggered eagerly but it's
only awaited when it fails to load. The patching still affects builds
that don't need it. This changes that.

---------
Co-authored-by: 's avatarVercel <vercel[bot]@users.noreply.github.com>
parent 382dbb82
......@@ -229,16 +229,6 @@ export async function loadBindings(
}
pendingBindings = new Promise(async (resolve, reject) => {
if (!lockfilePatchPromise.cur) {
// always run lockfile check once so that it gets patched
// even if it doesn't fail to load locally
lockfilePatchPromise.cur = (
require('../../lib/patch-incorrect-lockfile') as typeof import('../../lib/patch-incorrect-lockfile')
)
.patchIncorrectLockfile(process.cwd())
.catch(console.error)
}
let attempts: any[] = []
const disableWasmFallback = process.env.NEXT_DISABLE_SWC_WASM
const unsupportedPlatform = triples.some(
......@@ -428,7 +418,14 @@ async function logLoadFailure(attempts: any, triedWasm = false) {
wasm: triedWasm ? 'failed' : undefined,
nativeBindingsErrorCode: lastNativeBindingsLoadErrorCode,
})
await (lockfilePatchPromise.cur || Promise.resolve())
if (!lockfilePatchPromise.cur) {
lockfilePatchPromise.cur = (
require('../../lib/patch-incorrect-lockfile') as typeof import('../../lib/patch-incorrect-lockfile')
)
.patchIncorrectLockfile(process.cwd())
.catch(console.error)
}
await lockfilePatchPromise.cur
Log.error(
`Failed to load SWC binary for ${PlatformName}/${ArchName}, see more info here: https://nextjs.org/docs/messages/failed-loading-swc`
......
import { promises } from 'fs'
import { readFileSync, writeFileSync } from 'fs'
import * as Log from '../build/output/log'
import findUp from 'next/dist/compiled/find-up'
// @ts-ignore no-json types
......@@ -46,7 +46,7 @@ export async function patchIncorrectLockfile(dir: string) {
// if no lockfile present there is no action to take
return
}
const content = await promises.readFile(lockfilePath, 'utf8')
const content = readFileSync(lockfilePath, 'utf8')
// maintain current line ending
const endingNewline = content.endsWith('\r\n')
? '\r\n'
......@@ -161,7 +161,7 @@ export async function patchIncorrectLockfile(dir: string) {
}
}
await promises.writeFile(
writeFileSync(
lockfilePath,
JSON.stringify(lockfileParsed, null, 2) + endingNewline
)
......
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