Skip to content

Commit fea1667

Browse files
committed
Use string contains and nodeModulesPathPart const for "/node_modules/"
1 parent 1dd3cd2 commit fea1667

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/compiler/moduleNameResolver.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ namespace ts {
769769
const loader: ResolutionKindSpecificLoader = (extensions, candidate, failedLookupLocations, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, /*considerPackageJson*/ true);
770770
const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loader, failedLookupLocations, state);
771771
if (resolved) {
772-
return toSearchResult({ resolved, isExternalLibraryImport: resolved.path.indexOf("/node_modules/") !== -1 });
772+
return toSearchResult({ resolved, isExternalLibraryImport: stringContains(resolved.path, nodeModulesPathPart) });
773773
}
774774

775775
if (!isExternalModuleNameRelative(moduleName)) {
@@ -843,7 +843,8 @@ namespace ts {
843843
return loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, considerPackageJson);
844844
}
845845

846-
const nodeModulesPathPart = "/node_modules/";
846+
/*@internal*/
847+
export const nodeModulesPathPart = "/node_modules/";
847848

848849
/**
849850
* This will be called on the successfully resolved path from `loadModuleFromFile`.

src/compiler/moduleSpecifiers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ namespace ts.moduleSpecifiers {
401401
partEnd = fullPath.indexOf("/", partStart + 1);
402402
switch (state) {
403403
case States.BeforeNodeModules:
404-
if (fullPath.indexOf("/node_modules/", partStart) === partStart) {
404+
if (fullPath.indexOf(nodeModulesPathPart, partStart) === partStart) {
405405
topLevelNodeModulesIndex = partStart;
406406
topLevelPackageNameIndex = partEnd;
407407
state = States.NodeModules;
@@ -418,7 +418,7 @@ namespace ts.moduleSpecifiers {
418418
}
419419
break;
420420
case States.PackageContent:
421-
if (fullPath.indexOf("/node_modules/", partStart) === partStart) {
421+
if (fullPath.indexOf(nodeModulesPathPart, partStart) === partStart) {
422422
state = States.NodeModules;
423423
}
424424
else {

src/compiler/resolutionCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ namespace ts {
419419

420420
function getDirectoryToWatchFromFailedLookupLocationDirectory(dir: string, dirPath: Path) {
421421
// If directory path contains node module, get the most parent node_modules directory for watching
422-
while (stringContains(dirPath, "/node_modules/")) {
422+
while (stringContains(dirPath, nodeModulesPathPart)) {
423423
dir = getDirectoryPath(dir);
424424
dirPath = getDirectoryPath(dirPath);
425425
}

0 commit comments

Comments
 (0)