Use string contains and nodeModulesPathPart const for "/node_modules/"
This commit is contained in:
parent
1dd3cd288e
commit
fea1667002
3 changed files with 6 additions and 5 deletions
|
@ -769,7 +769,7 @@ namespace ts {
|
||||||
const loader: ResolutionKindSpecificLoader = (extensions, candidate, failedLookupLocations, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, /*considerPackageJson*/ true);
|
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);
|
const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loader, failedLookupLocations, state);
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
return toSearchResult({ resolved, isExternalLibraryImport: resolved.path.indexOf("/node_modules/") !== -1 });
|
return toSearchResult({ resolved, isExternalLibraryImport: stringContains(resolved.path, nodeModulesPathPart) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isExternalModuleNameRelative(moduleName)) {
|
if (!isExternalModuleNameRelative(moduleName)) {
|
||||||
|
@ -843,7 +843,8 @@ namespace ts {
|
||||||
return loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, considerPackageJson);
|
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`.
|
* This will be called on the successfully resolved path from `loadModuleFromFile`.
|
||||||
|
|
|
@ -401,7 +401,7 @@ namespace ts.moduleSpecifiers {
|
||||||
partEnd = fullPath.indexOf("/", partStart + 1);
|
partEnd = fullPath.indexOf("/", partStart + 1);
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case States.BeforeNodeModules:
|
case States.BeforeNodeModules:
|
||||||
if (fullPath.indexOf("/node_modules/", partStart) === partStart) {
|
if (fullPath.indexOf(nodeModulesPathPart, partStart) === partStart) {
|
||||||
topLevelNodeModulesIndex = partStart;
|
topLevelNodeModulesIndex = partStart;
|
||||||
topLevelPackageNameIndex = partEnd;
|
topLevelPackageNameIndex = partEnd;
|
||||||
state = States.NodeModules;
|
state = States.NodeModules;
|
||||||
|
@ -418,7 +418,7 @@ namespace ts.moduleSpecifiers {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case States.PackageContent:
|
case States.PackageContent:
|
||||||
if (fullPath.indexOf("/node_modules/", partStart) === partStart) {
|
if (fullPath.indexOf(nodeModulesPathPart, partStart) === partStart) {
|
||||||
state = States.NodeModules;
|
state = States.NodeModules;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -419,7 +419,7 @@ namespace ts {
|
||||||
|
|
||||||
function getDirectoryToWatchFromFailedLookupLocationDirectory(dir: string, dirPath: Path) {
|
function getDirectoryToWatchFromFailedLookupLocationDirectory(dir: string, dirPath: Path) {
|
||||||
// If directory path contains node module, get the most parent node_modules directory for watching
|
// 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);
|
dir = getDirectoryPath(dir);
|
||||||
dirPath = getDirectoryPath(dirPath);
|
dirPath = getDirectoryPath(dirPath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue