Skip to content

Commit 314323c

Browse files
committed
fix: always show warnings for missing files regardless of location
1 parent 39bb3fc commit 314323c

File tree

2 files changed

+6
-70
lines changed

2 files changed

+6
-70
lines changed

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -144,44 +144,4 @@ import {} from './file-b';
144144
).not.toContain(pathToTemporaryFile);
145145
});
146146

147-
it.sequential(
148-
'does not warn when dependency outside the directory is missing an index file',
149-
async () => {
150-
const pathToOutsideDirectory = path.resolve(
151-
testingDiretctory,
152-
'../.temporary-outside-directory',
153-
);
154-
const pathToImporter = path.join(
155-
testingDiretctory,
156-
'.temporary-outside-import.ts',
157-
);
158-
159-
await fs.mkdir(pathToOutsideDirectory, { recursive: true });
160-
await fs.writeFile(
161-
pathToImporter,
162-
`import '../.temporary-outside-directory';\n`,
163-
'utf8',
164-
);
165-
166-
const outsideDirectoryModule: DependencyGraph[number] = {
167-
path: pathToOutsideDirectory,
168-
dependencyPaths: [],
169-
dependentPaths: [],
170-
moduleDependencies: [],
171-
};
172-
173-
dependencyGraph[pathToOutsideDirectory] = outsideDirectoryModule;
174-
175-
try {
176-
await updateDependencyGraph('add', pathToImporter);
177-
} finally {
178-
await updateDependencyGraph('unlink', pathToImporter);
179-
await fs.rm(pathToImporter, { force: true });
180-
delete dependencyGraph[pathToOutsideDirectory];
181-
if (existsSync(pathToOutsideDirectory)) {
182-
await fs.rm(pathToOutsideDirectory, { recursive: true, force: true });
183-
}
184-
}
185-
},
186-
);
187147
});

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

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ const isJavascriptModule = (filePath: string) => {
4242
return javascriptExtensions.includes(extensionName);
4343
};
4444

45-
const isInsideDirectory = (baseDirectory: string, targetPath: string) => {
46-
const relativePath = path.relative(baseDirectory, targetPath);
47-
48-
return (
49-
relativePath === '' ||
50-
(!relativePath.startsWith('..') && !path.isAbsolute(relativePath))
51-
);
52-
};
53-
5445
const checkFileExtensionsUntilItExists = (
5546
pathWithoutExtension: string,
5647
): string | undefined => {
@@ -88,7 +79,6 @@ const checkFileExtensionsUntilItExists = (
8879
* so that it doesn't need to recompute the entire dependency graph but only the parts changed.
8980
*/
9081
export const createDependencyGraph = async (directory: string) => {
91-
const normalizedDirectory = path.resolve(directory);
9282
const filePaths = await readAllFilesInsideDirectory(directory);
9383
const modulePaths = filePaths.filter(isJavascriptModule);
9484
const graph: DependencyGraph = Object.fromEntries(
@@ -146,16 +136,9 @@ export const createDependencyGraph = async (directory: string) => {
146136
if (pathWithExtension) {
147137
pathToDependencyFromDirectory = pathWithExtension;
148138
} else {
149-
if (
150-
isInsideDirectory(
151-
normalizedDirectory,
152-
pathToDependencyFromDirectory,
153-
)
154-
) {
155-
console.warn(
156-
`Could not find index file for directory at ${pathToDependencyFromDirectory}. This is probably going to cause issues with both hot reloading and your code.`,
157-
);
158-
}
139+
console.warn(
140+
`Could not find index file for directory at ${pathToDependencyFromDirectory}. This is probably going to cause issues with both hot reloading and your code.`,
141+
);
159142
}
160143
}
161144

@@ -180,16 +163,9 @@ export const createDependencyGraph = async (directory: string) => {
180163
if (pathWithEnsuredExtension) {
181164
pathToDependencyFromDirectory = pathWithEnsuredExtension;
182165
} else {
183-
if (
184-
isInsideDirectory(
185-
normalizedDirectory,
186-
pathToDependencyFromDirectory,
187-
)
188-
) {
189-
console.warn(
190-
`Could not find file at ${pathToDependencyFromDirectory}`,
191-
);
192-
}
166+
console.warn(
167+
`Could not find file at ${pathToDependencyFromDirectory}`,
168+
);
193169
}
194170

195171
return pathToDependencyFromDirectory;

0 commit comments

Comments
 (0)