Skip to content

Commit ab68895

Browse files
chore: warn for incorrect _redirects file, and update docs (#1078)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 02053fd commit ab68895

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

docs/release-notes/v4.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ If you previously set these values, they're no longer needed and can be removed:
4242

4343
If you currently use redirects or rewrites on your site, see
4444
[the Rewrites and Redirects guide](https://github.com/netlify/netlify-plugin-nextjs/blob/main/docs/redirects-rewrites.md)
45-
for information on changes to how they are handled in this version.
45+
for information on changes to how they are handled in this version. If you currently have `_redirects` or `_headers`
46+
files in the root of your site, these will need to be moved into "public".
4647

4748
If you want to use Next 12's beta Middleware feature, this will mostly work as expected but please
4849
[read the docs on some caveats and workarounds](https://github.com/netlify/netlify-plugin-nextjs/blob/main/docs/middleware.md)

src/helpers/verification.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-lines */
22
import { existsSync, promises } from 'fs'
3-
import path, { relative } from 'path'
3+
import path, { relative, join } from 'path'
44

55
import { NetlifyConfig, NetlifyPluginUtils } from '@netlify/build'
66
import { yellowBright, greenBright, blueBright, redBright, reset } from 'chalk'
@@ -187,4 +187,14 @@ export const warnForProblematicUserRewrites = ({
187187
`),
188188
)
189189
}
190+
191+
export const warnForRootRedirects = ({ appDir }: { appDir: string }) => {
192+
if (existsSync(join(appDir, '_redirects'))) {
193+
console.log(
194+
yellowBright(
195+
`You have a "_redirects" file in your root directory, which is not deployed and will be ignored. If you want it to be used, please move it into "public".`,
196+
),
197+
)
198+
}
199+
}
190200
/* eslint-enable max-lines */

src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
checkZipSize,
1818
checkForOldFunctions,
1919
warnForProblematicUserRewrites,
20+
warnForRootRedirects,
2021
} from './helpers/verification'
2122

2223
const plugin: NetlifyPlugin = {
@@ -130,8 +131,9 @@ const plugin: NetlifyPlugin = {
130131

131132
await checkForOldFunctions({ functions })
132133
await checkZipSize(join(FUNCTIONS_DIST, `${ODB_FUNCTION_NAME}.zip`))
133-
const { basePath } = await getNextConfig({ publish, failBuild })
134+
const { basePath, appDir } = await getNextConfig({ publish, failBuild })
134135
warnForProblematicUserRewrites({ basePath, redirects })
136+
warnForRootRedirects({ appDir })
135137
await unpatchNextFiles(basePath)
136138
},
137139
}

0 commit comments

Comments
 (0)