Skip to content

fix(react-email): files with extension-like suffixes breaking dependency graph #2317

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
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/giant-bottles-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-email": patch
---

fix files with extension-like suffixes (i.e. config, .spec) breaking dependency graph
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ const readAllFilesInsideDirectory = async (directory: string) => {
return allFilePaths;
};

const javascriptExtensions = ['.js', '.ts', '.jsx', '.tsx', '.mjs', '.cjs'];

const isJavascriptModule = (filePath: string) => {
const extensionName = path.extname(filePath);

return ['.js', '.ts', '.jsx', '.tsx', '.mjs', '.cjs'].includes(extensionName);
return javascriptExtensions.includes(extensionName);
};

const checkFileExtensionsUntilItExists = (
Expand Down Expand Up @@ -146,12 +148,17 @@ export const createDependencyGraph = async (directory: string) => {
const pathWithEnsuredExtension = (() => {
if (
extension.length > 0 &&
existsSync(pathToDependencyFromDirectory)
javascriptExtensions.includes(extension)
) {
return pathToDependencyFromDirectory;
if (existsSync(pathToDependencyFromDirectory)) {
return pathToDependencyFromDirectory;
}
return checkFileExtensionsUntilItExists(
pathToDependencyFromDirectory.replace(extension, ''),
);
}
return checkFileExtensionsUntilItExists(
pathToDependencyFromDirectory.replace(extension, ''),
pathToDependencyFromDirectory,
);
})();

Expand Down