Unverified Commit 54ecdd83 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[dev] Fix Middleware and Proxy file conflict (#84965)

Since the conflict check looked only at the file name 💀, when there's a
`proxy` or `middleware` file inside the app, it also detected a
conflict:

```
Unhandled Rejection: Error: Both "middleware" and "proxy" files are detected. Please use "proxy" instead.
```

CI:
https://github.com/vercel/next.js/actions/runs/18568804746/job/52937138783?pr=84965#step:34:326

Therefore, check for the actual file path of the middleware/proxy file.
parent 65d6ffb7
...@@ -393,34 +393,38 @@ async function startWatcher( ...@@ -393,34 +393,38 @@ async function startWatcher(
let hasMiddlewareFile = false let hasMiddlewareFile = false
let hasProxyFile = false let hasProxyFile = false
for (const fileName of sortedKnownFiles) { for (const fileName of sortedKnownFiles) {
const { name } = path.parse(fileName) if (
if (name === MIDDLEWARE_FILENAME) { !files.includes(fileName) &&
!directories.some((d) => fileName.startsWith(d))
) {
continue
}
const { name: fileBaseName, dir: fileDir } = path.parse(fileName)
const isAtConventionLevel =
fileDir === dir || fileDir === path.join(dir, 'src')
if (isAtConventionLevel && fileBaseName === MIDDLEWARE_FILENAME) {
hasMiddlewareFile = true hasMiddlewareFile = true
} }
if (name === PROXY_FILENAME) { if (isAtConventionLevel && fileBaseName === PROXY_FILENAME) {
hasProxyFile = true hasProxyFile = true
} }
}
if (hasMiddlewareFile) { if (hasMiddlewareFile) {
if (hasProxyFile) { if (hasProxyFile) {
throw new Error( throw new Error(
`Both "${MIDDLEWARE_FILENAME}" and "${PROXY_FILENAME}" files are detected. Please use "${PROXY_FILENAME}" instead.` `Both "${MIDDLEWARE_FILENAME}" and "${PROXY_FILENAME}" files are detected. Please use "${PROXY_FILENAME}" instead.`
)
}
Log.warnOnce(
`The "${MIDDLEWARE_FILENAME}" file convention is deprecated. Please use "${PROXY_FILENAME}" instead.`
) )
} }
Log.warnOnce(
`The "${MIDDLEWARE_FILENAME}" file convention is deprecated. Please use "${PROXY_FILENAME}" instead.`
)
}
for (const fileName of sortedKnownFiles) {
if (
!files.includes(fileName) &&
!directories.some((d) => fileName.startsWith(d))
) {
continue
}
const meta = knownFiles.get(fileName) const meta = knownFiles.get(fileName)
const watchTime = fileWatchTimes.get(fileName) const watchTime = fileWatchTimes.get(fileName)
......
// noop, this file should not picked up as Middleware file and throw error.
// noop, this file should not picked up as Proxy file and throw error.
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