-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(babel): Improved message for error relating to multiple files end…
…ing in `Page.{js,jsx,ts,tsx}` in page directories (#9329) **Problem** The route auto import babel plugin currently generates duplicate import statements if you have multiple files which end in `Page.{js,jsx,ts,tsx}` within the same page directory. This causes an error later in the build/dev process. This currently imposes the restriction that only one file end in `Page.{js,jsx,ts,tsx}` inside the individual page directories. The error message which you get when this issue occurs is rather obscure and does not easily point users to the source of the problem. This was highlighted in #9165. The error produced from `yarn rw dev` without this change: <img width="931" alt="image" src="https://github.com/redwoodjs/redwood/assets/56300765/9e7abda6-d42e-477c-8506-b9caea2f1fc8"> In comparison to after this change: <img width="931" alt="image" src="https://github.com/redwoodjs/redwood/assets/56300765/964ca266-338d-4fbb-af0f-b75c8f6647ac"> **Changes** 1. Checks for duplicate pages as returned from the `processPagesDir` function and produces a more specific error message in the case where duplicates exist. 2. Adds a test which covers the case of duplicate files ending in `Page.{js,jsx,ts,tsx}` within a page directory. **Fixes** * fixes #9165 **Notes** 1. The `processPagesDir` function is marked as deprecated and is awaiting a new implementation. I did not think doing that now for this issue was wise. I also did not want to alter the logic of that function here as that could introduce side effects of its own. 2. Happy to change the error message to be even clearer. 3. We could attempt to trim out the duplicate entries directly where I perform this new check - I'm not against this. I didn't do this immediately because it felt like I would be doing additional work which the `processPagesDir` function should be doing internally.
- Loading branch information
1 parent
616b4d6
commit a6b54be
Showing
6 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...es/babel-config/src/plugins/__tests__/__fixtures__/route-auto-loader/failure/redwood.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[web] | ||
port = 8910 | ||
apiProxyPath = "/api/functions" | ||
|
||
[api] | ||
port = 8911 | ||
[api.paths] | ||
functions = './api/src/functions' | ||
graphql = './api/src/graphql' | ||
generated = './api/generated' |
11 changes: 11 additions & 0 deletions
11
...el-config/src/plugins/__tests__/__fixtures__/route-auto-loader/failure/web/src/Routes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Router, Route } from '@redwoodjs/router' | ||
|
||
const Routes = () => { | ||
return ( | ||
<Router> | ||
<Route path="/" page={HomePage} name="home"/> | ||
</Router> | ||
) | ||
} | ||
|
||
export default Routes |
9 changes: 9 additions & 0 deletions
9
...gins/__tests__/__fixtures__/route-auto-loader/failure/web/src/pages/HomePage/HomePage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const HomePage = () => { | ||
return ( | ||
<div> | ||
<h1>HomePage</h1> | ||
</div> | ||
) | ||
} | ||
|
||
export default HomePage |
5 changes: 5 additions & 0 deletions
5
...s/__tests__/__fixtures__/route-auto-loader/failure/web/src/pages/HomePage/useHomePage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const useHomePage = () => { | ||
return 'useHomePage' | ||
} | ||
|
||
export default useHomePage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters