-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(react-email): add email config support #3411
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
Open
itsyoboieltr
wants to merge
14
commits into
resend:canary
Choose a base branch
from
itsyoboieltr:feat/email-config
base: canary
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fc01648
feat: email config
itsyoboieltr 0ecdc4a
fix: minor
itsyoboieltr 2fa8dd5
feat: tests
itsyoboieltr 30c0182
fix: config export
itsyoboieltr e84e8f9
fix: config validation
itsyoboieltr a74524b
fix: emailConfigPath quoting
itsyoboieltr a9f3fe3
fix: getEmailConfigPath return type
itsyoboieltr 9e16701
Create curly-lions-bake.md
itsyoboieltr 3c80930
Merge branch 'canary' into feat/email-config
itsyoboieltr 53a5ff1
Update build.ts
itsyoboieltr 4c418dd
Delete get-env-variables-for-preview-app.spec.ts
itsyoboieltr 78396db
Update tree.spec.ts
itsyoboieltr 7babd59
chore: rerun e2e
itsyoboieltr 4aab66c
Merge upstream/canary into feat/email-config
itsyoboieltr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
| --- | ||
| "react-email": minor | ||
| "@react-email/ui": minor | ||
| --- | ||
|
|
||
| add optional email config support |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
packages/react-email/src/cli/utils/preview/get-env-variables-for-preview-app.spec.ts
This file contains hidden or 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,36 @@ | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { getEnvVariablesForPreviewApp } from './get-env-variables-for-preview-app'; | ||
|
|
||
| describe('getEnvVariablesForPreviewApp()', () => { | ||
| let temporaryDirectory = ''; | ||
|
|
||
| beforeEach(() => { | ||
| temporaryDirectory = fs.mkdtempSync( | ||
| path.join(os.tmpdir(), 'react-email-preview-env-'), | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(temporaryDirectory, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('includes the discovered email config path', () => { | ||
| const emailConfigPath = path.join(temporaryDirectory, 'email.config.cts'); | ||
| fs.writeFileSync(emailConfigPath, 'export default {};\n', 'utf8'); | ||
|
|
||
| expect( | ||
| getEnvVariablesForPreviewApp('emails', '/preview', temporaryDirectory), | ||
| ).toMatchObject({ | ||
| REACT_EMAIL_INTERNAL_EMAIL_CONFIG_PATH: emailConfigPath, | ||
| REACT_EMAIL_INTERNAL_EMAILS_DIR_RELATIVE_PATH: 'emails', | ||
| REACT_EMAIL_INTERNAL_EMAILS_DIR_ABSOLUTE_PATH: path.join( | ||
| temporaryDirectory, | ||
| 'emails', | ||
| ), | ||
| REACT_EMAIL_INTERNAL_PREVIEW_SERVER_LOCATION: '/preview', | ||
| REACT_EMAIL_INTERNAL_USER_PROJECT_LOCATION: temporaryDirectory, | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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
48 changes: 48 additions & 0 deletions
48
packages/react-email/src/config/get-email-config-path.spec.ts
This file contains hidden or 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,48 @@ | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { | ||
| getEmailConfigPath, | ||
| supportedEmailConfigFilenames, | ||
| } from './get-email-config-path'; | ||
|
|
||
| describe('getEmailConfigPath()', () => { | ||
| let temporaryDirectory = ''; | ||
|
|
||
| beforeEach(() => { | ||
| temporaryDirectory = fs.mkdtempSync( | ||
| path.join(os.tmpdir(), 'react-email-config-path-'), | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(temporaryDirectory, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('returns undefined when there is no config file', () => { | ||
| expect(getEmailConfigPath(temporaryDirectory)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it.each( | ||
| supportedEmailConfigFilenames, | ||
| )('detects a %s config file', (filename) => { | ||
| const emailConfigPath = path.join(temporaryDirectory, filename); | ||
| fs.writeFileSync(emailConfigPath, 'export default {};\n', 'utf8'); | ||
|
|
||
| expect(getEmailConfigPath(temporaryDirectory)).toBe(emailConfigPath); | ||
| }); | ||
|
|
||
| it('prefers the first supported filename when multiple configs exist', () => { | ||
| for (const filename of supportedEmailConfigFilenames) { | ||
| fs.writeFileSync( | ||
| path.join(temporaryDirectory, filename), | ||
| 'export default {};\n', | ||
| 'utf8', | ||
| ); | ||
| } | ||
|
|
||
| expect(getEmailConfigPath(temporaryDirectory)).toBe( | ||
| path.join(temporaryDirectory, supportedEmailConfigFilenames[0]!), | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or 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,23 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| export const supportedEmailConfigFilenames = [ | ||
| 'email.config.ts', | ||
| 'email.config.mts', | ||
| 'email.config.cts', | ||
| 'email.config.js', | ||
| 'email.config.mjs', | ||
| 'email.config.cjs', | ||
| ]; | ||
|
|
||
| export const getEmailConfigPath = ( | ||
| userProjectLocation: string, | ||
| ): string | undefined => { | ||
| for (const filename of supportedEmailConfigFilenames) { | ||
| const emailConfigPath = path.join(userProjectLocation, filename); | ||
|
|
||
| if (fs.existsSync(emailConfigPath)) { | ||
| return emailConfigPath; | ||
| } | ||
| } | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think this test is quite useful, as the code is quite simple and just reading it makes it clear if it's right or not. The only effect that this has is making it harder to change the code.
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.
removed the test as per your feedback