Skip to content
Merged
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
31 changes: 24 additions & 7 deletions packages/next/src/build/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ function rustifyOptionEnv(
}))
}

const normalizePathOnWindows = (p: string) =>
path.sep === '\\' ? p.replace(/\\/g, '/') : p

// TODO(sokra) Support wasm option.
function bindingToApi(
binding: RawBindings,
Expand Down Expand Up @@ -875,23 +878,35 @@ 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.
if (nextConfigSerializable.images.loaderFile) {
nextConfigSerializable.images = {
...nextConfigSerializable.images,
loaderFile:
'./' +
path.relative(projectPath, nextConfigSerializable.images.loaderFile),
normalizePathOnWindows(
path.relative(projectPath, nextConfigSerializable.images.loaderFile)
),
}
}

// cacheHandler can be an absolute path, we need it to be relative for turbopack.
if (nextConfigSerializable.cacheHandler) {
nextConfigSerializable.cacheHandler =
'./' +
(path.isAbsolute(nextConfigSerializable.cacheHandler)
? path.relative(projectPath, nextConfigSerializable.cacheHandler)
: nextConfigSerializable.cacheHandler)
normalizePathOnWindows(
path.isAbsolute(nextConfigSerializable.cacheHandler)
? path.relative(projectPath, nextConfigSerializable.cacheHandler)
: nextConfigSerializable.cacheHandler
)
}
if (nextConfigSerializable.cacheHandlers) {
nextConfigSerializable.cacheHandlers = Object.fromEntries(
Expand All @@ -902,9 +917,11 @@ function bindingToApi(
.map(([key, value]) => [
key,
'./' +
(path.isAbsolute(value)
? path.relative(projectPath, value)
: value),
normalizePathOnWindows(
path.isAbsolute(value)
? path.relative(projectPath, value)
: value
),
])
)
}
Expand Down
Loading