Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor redirects file path logic #2592

Merged
merged 1 commit into from Jun 8, 2021
Merged

Conversation

ehmicky
Copy link
Contributor

@ehmicky ehmicky commented Jun 8, 2021

Part of netlify/build#2889

This is a small clarification of the logic used to find the files containing redirect rules.

@ehmicky ehmicky added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Jun 8, 2021
@ehmicky ehmicky requested a review from erezrokah June 8, 2021 16:19
@ehmicky ehmicky self-assigned this Jun 8, 2021
@ehmicky ehmicky requested a review from a team as a code owner June 8, 2021 16:19
@github-actions github-actions bot added the type: chore work needed to keep the product and development running smoothly label Jun 8, 2021
const configFiles = [
...new Set(
[path.resolve(distDir, '_redirects'), path.resolve(projectDir, '_redirects'), configPath].filter(
(configFile) => configFile && configFile !== projectDir,
Copy link
Contributor Author

@ehmicky ehmicky Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me configFile can never equal projectDir. Both are returned by @netlify/config as configPath (which can be undefined) and buildDir (which is never undefined) respectively. The first is always a regular file, the second is always a directory.

Therefore, I removed configFile !== projectDir.

),
),
]
const redirectsFiles = [...new Set([path.resolve(distDir, '_redirects'), path.resolve(projectDir, '_redirects')])]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In production, I believe only the publish directory (named distDir here) can be used for _redirects. That's at least what my manual test + the documentation website indicate.
projectDir is the build directory. do we have a reason why netlify dev allows _redirects in that directory, even though it is not valid in production?

@ehmicky ehmicky enabled auto-merge (squash) June 8, 2021 16:28
@ehmicky ehmicky disabled auto-merge June 8, 2021 16:39
@ehmicky ehmicky merged commit add2467 into main Jun 8, 2021
@ehmicky ehmicky deleted the chore/remove-dead-code branch June 8, 2021 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: chore work needed to keep the product and development running smoothly type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants