Skip to content

Commit 0fedcba

Browse files
committed
Turbopack: normalize distDir separators
1 parent 6eed9a0 commit 0fedcba

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

packages/next/src/build/swc/index.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ function rustifyOptionEnv(
488488
}))
489489
}
490490

491+
const normalizePathOnWindows = (p: string) =>
492+
path.sep === '\\' ? p.replace(/\\/g, '/') : p
493+
491494
// TODO(sokra) Support wasm option.
492495
function bindingToApi(
493496
binding: RawBindings,
@@ -875,23 +878,35 @@ function bindingToApi(
875878
)
876879
}
877880

881+
// These are relative paths, but might be backslash-separated on Windows
882+
nextConfigSerializable.distDir = normalizePathOnWindows(
883+
nextConfigSerializable.distDir
884+
)
885+
nextConfigSerializable.distDirRoot = normalizePathOnWindows(
886+
nextConfigSerializable.distDirRoot
887+
)
888+
878889
// loaderFile is an absolute path, we need it to be relative for turbopack.
879890
if (nextConfigSerializable.images.loaderFile) {
880891
nextConfigSerializable.images = {
881892
...nextConfigSerializable.images,
882893
loaderFile:
883894
'./' +
884-
path.relative(projectPath, nextConfigSerializable.images.loaderFile),
895+
normalizePathOnWindows(
896+
path.relative(projectPath, nextConfigSerializable.images.loaderFile)
897+
),
885898
}
886899
}
887900

888901
// cacheHandler can be an absolute path, we need it to be relative for turbopack.
889902
if (nextConfigSerializable.cacheHandler) {
890903
nextConfigSerializable.cacheHandler =
891904
'./' +
892-
(path.isAbsolute(nextConfigSerializable.cacheHandler)
893-
? path.relative(projectPath, nextConfigSerializable.cacheHandler)
894-
: nextConfigSerializable.cacheHandler)
905+
normalizePathOnWindows(
906+
path.isAbsolute(nextConfigSerializable.cacheHandler)
907+
? path.relative(projectPath, nextConfigSerializable.cacheHandler)
908+
: nextConfigSerializable.cacheHandler
909+
)
895910
}
896911
if (nextConfigSerializable.cacheHandlers) {
897912
nextConfigSerializable.cacheHandlers = Object.fromEntries(
@@ -902,9 +917,11 @@ function bindingToApi(
902917
.map(([key, value]) => [
903918
key,
904919
'./' +
905-
(path.isAbsolute(value)
906-
? path.relative(projectPath, value)
907-
: value),
920+
normalizePathOnWindows(
921+
path.isAbsolute(value)
922+
? path.relative(projectPath, value)
923+
: value
924+
),
908925
])
909926
)
910927
}

0 commit comments

Comments
 (0)