Use string contains and nodeModulesPathPart const for "/node_modules/"

This commit is contained in:
Sheetal Nandi 2018-08-15 11:47:16 -07:00
parent 1dd3cd288e
commit fea1667002
3 changed files with 6 additions and 5 deletions

View file

@ -769,7 +769,7 @@ namespace ts {
const loader: ResolutionKindSpecificLoader = (extensions, candidate, failedLookupLocations, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, /*considerPackageJson*/ true);
const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loader, failedLookupLocations, state);
if (resolved) {
return toSearchResult({ resolved, isExternalLibraryImport: resolved.path.indexOf("/node_modules/") !== -1 });
return toSearchResult({ resolved, isExternalLibraryImport: stringContains(resolved.path, nodeModulesPathPart) });
}
if (!isExternalModuleNameRelative(moduleName)) {
@ -843,7 +843,8 @@ namespace ts {
return loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, considerPackageJson);
}
const nodeModulesPathPart = "/node_modules/";
/*@internal*/
export const nodeModulesPathPart = "/node_modules/";
/**
* This will be called on the successfully resolved path from `loadModuleFromFile`.

View file

@ -401,7 +401,7 @@ namespace ts.moduleSpecifiers {
partEnd = fullPath.indexOf("/", partStart + 1);
switch (state) {
case States.BeforeNodeModules:
if (fullPath.indexOf("/node_modules/", partStart) === partStart) {
if (fullPath.indexOf(nodeModulesPathPart, partStart) === partStart) {
topLevelNodeModulesIndex = partStart;
topLevelPackageNameIndex = partEnd;
state = States.NodeModules;
@ -418,7 +418,7 @@ namespace ts.moduleSpecifiers {
}
break;
case States.PackageContent:
if (fullPath.indexOf("/node_modules/", partStart) === partStart) {
if (fullPath.indexOf(nodeModulesPathPart, partStart) === partStart) {
state = States.NodeModules;
}
else {

View file

@ -419,7 +419,7 @@ namespace ts {
function getDirectoryToWatchFromFailedLookupLocationDirectory(dir: string, dirPath: Path) {
// If directory path contains node module, get the most parent node_modules directory for watching
while (stringContains(dirPath, "/node_modules/")) {
while (stringContains(dirPath, nodeModulesPathPart)) {
dir = getDirectoryPath(dir);
dirPath = getDirectoryPath(dirPath);
}