Skip to content

Commit 38a6517

Browse files
committed
More refactor
1 parent ddd917c commit 38a6517

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/compiler/resolutionCache.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ function isInDirectoryPath(dirComponents: Readonly<PathPathComponents>, fileOrDi
262262
}
263263

264264
function canWatchAffectedPackageJsonOrNodeModulesOfAtTypes(fileOrDirPath: Path) {
265-
const fileOrDirPathComponents = getPathComponents(fileOrDirPath);
266-
return fileOrDirPathComponents.length > perceivedOsRootLengthForWatching(fileOrDirPathComponents, fileOrDirPathComponents.length) + 1;
265+
return canWatchDirectoryOrFile(getPathComponents(fileOrDirPath));
267266
}
268267

269268
/** @internal */
@@ -309,17 +308,31 @@ export function getDirectoryToWatchFailedLookupLocation(
309308
);
310309
}
311310

311+
function getDirectoryToWatchFailedLookupLocationNodeModules(
312+
dirPathComponents: Readonly<PathPathComponents>,
313+
) {
314+
// If directory path contains node module, get the most parent node_modules directory for watching
315+
const indexOfNodeModules = dirPathComponents.indexOf("node_modules" as Path);
316+
if (indexOfNodeModules !== -1) {
317+
// If the directory is node_modules use it to watch, always watch it recursively
318+
return canWatchDirectoryOrFile(dirPathComponents, indexOfNodeModules + 1) ?
319+
indexOfNodeModules + 1 :
320+
false;
321+
}
322+
return undefined;
323+
}
324+
312325
function getDirectoryToWatchFromFailedLookupLocationDirectory(
313326
dirComponents: readonly string[],
314327
dirPathComponents: Readonly<PathPathComponents>,
315328
rootPathComponents: Readonly<PathPathComponents>,
316329
): DirectoryOfFailedLookupWatch | undefined {
317330
// If directory path contains node module, get the most parent node_modules directory for watching
318-
const indexOfNodeModules = dirPathComponents.indexOf("node_modules" as Path);
319-
if (indexOfNodeModules !== -1) {
331+
const nodeModulesWatchLength = getDirectoryToWatchFailedLookupLocationNodeModules(dirPathComponents);
332+
if (nodeModulesWatchLength !== undefined) {
320333
// If the directory is node_modules use it to watch, always watch it recursively
321-
return canWatchDirectoryOrFile(dirPathComponents, indexOfNodeModules + 1) ?
322-
getDirectoryOfFailedLookupWatch(dirComponents, dirPathComponents, indexOfNodeModules + 1) :
334+
return nodeModulesWatchLength ?
335+
getDirectoryOfFailedLookupWatch(dirComponents, dirPathComponents, nodeModulesWatchLength) :
323336
undefined;
324337
}
325338
// Use some ancestor of the root directory

0 commit comments

Comments
 (0)