-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix(babel): Improved message for error relating to multiple files ending in Page.{js,jsx,ts,tsx}
in page directories
#9329
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a minor comment but works locally and looks good
// ending in Page in the individual page directories. This will cause an error upstream. | ||
// Here we check for duplicates and throw a more helpful error message. | ||
const duplicatePageImports = new Set<string>() | ||
const sortedPageImports = pages.map((page) => page.importName).sort() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggesiton to improve the naming of this variable here cause it's not import statements its just an array of strings like ['AboutPage', 'AboutPage', 'FatalErrorPage']
const sortedPageImports = pages.map((page) => page.importName).sort() | |
const sortedPageImportNames = pages.map((page) => page.importName).sort() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Updating in ce11673
…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.
…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.
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 inPage.{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:In comparison to after this change:

Changes
processPagesDir
function and produces a more specific error message in the case where duplicates exist.Page.{js,jsx,ts,tsx}
within a page directory.Fixes
Notes
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.processPagesDir
function should be doing internally.