Unverified Commit 2cd70dfe authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: normalize distDir separators (#86697)

Closes #86652
Closes PACK-6023

Previously, `dist_dir` contained backslashes on Windows which broke various things (among them, relative paths for the externals symlinks):

https://github.com/vercel/next.js/blob/6eed9a05450f2c179b951c97350e305973a09e6f/crates/next-api/src/project.rs#L765
parent ba8a94d2
...@@ -488,6 +488,9 @@ function rustifyOptionEnv( ...@@ -488,6 +488,9 @@ function rustifyOptionEnv(
})) }))
} }
const normalizePathOnWindows = (p: string) =>
path.sep === '\\' ? p.replace(/\\/g, '/') : p
// TODO(sokra) Support wasm option. // TODO(sokra) Support wasm option.
function bindingToApi( function bindingToApi(
binding: RawBindings, binding: RawBindings,
...@@ -875,13 +878,23 @@ function bindingToApi( ...@@ -875,13 +878,23 @@ function bindingToApi(
) )
} }
// These are relative paths, but might be backslash-separated on Windows
nextConfigSerializable.distDir = normalizePathOnWindows(
nextConfigSerializable.distDir
)
nextConfigSerializable.distDirRoot = normalizePathOnWindows(
nextConfigSerializable.distDirRoot
)
// loaderFile is an absolute path, we need it to be relative for turbopack. // loaderFile is an absolute path, we need it to be relative for turbopack.
if (nextConfigSerializable.images.loaderFile) { if (nextConfigSerializable.images.loaderFile) {
nextConfigSerializable.images = { nextConfigSerializable.images = {
...nextConfigSerializable.images, ...nextConfigSerializable.images,
loaderFile: loaderFile:
'./' + './' +
path.relative(projectPath, nextConfigSerializable.images.loaderFile), normalizePathOnWindows(
path.relative(projectPath, nextConfigSerializable.images.loaderFile)
),
} }
} }
...@@ -889,9 +902,11 @@ function bindingToApi( ...@@ -889,9 +902,11 @@ function bindingToApi(
if (nextConfigSerializable.cacheHandler) { if (nextConfigSerializable.cacheHandler) {
nextConfigSerializable.cacheHandler = nextConfigSerializable.cacheHandler =
'./' + './' +
(path.isAbsolute(nextConfigSerializable.cacheHandler) normalizePathOnWindows(
? path.relative(projectPath, nextConfigSerializable.cacheHandler) path.isAbsolute(nextConfigSerializable.cacheHandler)
: nextConfigSerializable.cacheHandler) ? path.relative(projectPath, nextConfigSerializable.cacheHandler)
: nextConfigSerializable.cacheHandler
)
} }
if (nextConfigSerializable.cacheHandlers) { if (nextConfigSerializable.cacheHandlers) {
nextConfigSerializable.cacheHandlers = Object.fromEntries( nextConfigSerializable.cacheHandlers = Object.fromEntries(
...@@ -902,9 +917,11 @@ function bindingToApi( ...@@ -902,9 +917,11 @@ function bindingToApi(
.map(([key, value]) => [ .map(([key, value]) => [
key, key,
'./' + './' +
(path.isAbsolute(value) normalizePathOnWindows(
? path.relative(projectPath, value) path.isAbsolute(value)
: value), ? path.relative(projectPath, value)
: value
),
]) ])
) )
} }
......
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