Skip to content

Commit 5c6150d

Browse files
authored
fix(react-email): JSON import support on dependency graph (#2094)
1 parent f5ef6b3 commit 5c6150d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

.changeset/big-dots-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-email": patch
3+
---
4+
5+
Add .json import support for hot reloading

packages/react-email/src/cli/utils/preview/hot-reloading/create-dependency-graph.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export const createDependencyGraph = async (directory: string) => {
9494
const getDependencyPaths = async (filePath: string) => {
9595
const contents = await fs.readFile(filePath, 'utf8');
9696

97-
const importedPaths = getImportedModules(contents);
97+
const importedPaths = isJavascriptModule(filePath)
98+
? getImportedModules(contents)
99+
: [];
98100
const importedPathsRelativeToDirectory = importedPaths.map(
99101
(dependencyPath) => {
100102
const isModulePath = !dependencyPath.startsWith('.');
@@ -112,7 +114,7 @@ export const createDependencyGraph = async (directory: string) => {
112114
/*
113115
path.resolve resolves paths differently from what imports on javascript do.
114116
115-
So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependecy path of "./other-email"
117+
So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependency path of "./other-email"
116118
would end up going into /path/to/email.tsx/other-email instead of /path/to/other-email which is the
117119
one the import is meant to go to
118120
*/
@@ -122,7 +124,7 @@ export const createDependencyGraph = async (directory: string) => {
122124

123125
let isDirectory = false;
124126
try {
125-
// will throw if the the file is not existant
127+
// will throw if the the file is not existent
126128
isDirectory = statSync(pathToDependencyFromDirectory).isDirectory();
127129
} catch (_) {}
128130
if (isDirectory) {
@@ -145,9 +147,10 @@ export const createDependencyGraph = async (directory: string) => {
145147
for it being a javascript module fails, then we can assume it has the same as the `filePath`
146148
*/
147149
if (!isJavascriptModule(pathToDependencyFromDirectory)) {
148-
const pathWithExtension = checkFileExtensionsUntilItExists(
149-
pathToDependencyFromDirectory,
150-
);
150+
const pathWithExtension =
151+
path.extname(pathToDependencyFromDirectory).length > 0
152+
? pathToDependencyFromDirectory
153+
: checkFileExtensionsUntilItExists(pathToDependencyFromDirectory);
151154

152155
if (pathWithExtension) {
153156
pathToDependencyFromDirectory = pathWithExtension;

0 commit comments

Comments
 (0)