Merge pull request #19058 from Microsoft/whenWatchesFail

Swallow the directory watcher exceptions and ignore them
This commit is contained in:
Sheetal Nandi
2017-10-10 18:32:22 -07:00
committed by GitHub
14 changed files with 79 additions and 25 deletions

View File

@@ -14012,7 +14012,7 @@ namespace ts {
*/
function isUnhyphenatedJsxName(name: string | __String) {
// - is the only character supported in JSX attribute names that isn't valid in JavaScript identifiers
return (name as string).indexOf("-") < 0;
return !stringContains(name as string, "-");
}
/**

View File

@@ -1648,7 +1648,7 @@ namespace ts {
}
export function isUrl(path: string) {
return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
return path && !isRootedDiskPath(path) && stringContains(path, "://");
}
export function pathIsRelative(path: string): boolean {
@@ -1917,8 +1917,12 @@ namespace ts {
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
}
export function stringContains(str: string, substring: string): boolean {
return str.indexOf(substring) !== -1;
}
export function hasExtension(fileName: string): boolean {
return getBaseFileName(fileName).indexOf(".") >= 0;
return stringContains(getBaseFileName(fileName), ".");
}
export function fileExtensionIs(path: string, extension: string): boolean {

View File

@@ -172,7 +172,7 @@ namespace ts {
function hasInternalAnnotation(range: CommentRange) {
const comment = currentText.substring(range.pos, range.end);
return comment.indexOf("@internal") >= 0;
return stringContains(comment, "@internal");
}
function stripInternal(node: Node) {

View File

@@ -1226,7 +1226,7 @@ namespace ts {
// check if numeric literal is a decimal literal that was originally written with a dot
const text = getLiteralTextOfNode(<LiteralExpression>expression);
return !expression.numericLiteralFlags
&& text.indexOf(tokenToString(SyntaxKind.DotToken)) < 0;
&& !stringContains(text, tokenToString(SyntaxKind.DotToken));
}
else if (isPropertyAccessExpression(expression) || isElementAccessExpression(expression)) {
// check if constant enum value is integer

View File

@@ -1061,7 +1061,7 @@ namespace ts {
export function getPackageNameFromAtTypesDirectory(mangledName: string): string {
const withoutAtTypePrefix = removePrefix(mangledName, "@types/");
if (withoutAtTypePrefix !== mangledName) {
return withoutAtTypePrefix.indexOf(mangledScopedPackageSeparator) !== -1 ?
return stringContains(withoutAtTypePrefix, mangledScopedPackageSeparator) ?
"@" + withoutAtTypePrefix.replace(mangledScopedPackageSeparator, ts.directorySeparator) :
withoutAtTypePrefix;
}

View File

@@ -329,17 +329,14 @@ namespace ts {
let dir = getDirectoryPath(getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory()));
let dirPath = getDirectoryPath(failedLookupLocationPath);
// If the directory is node_modules use it to watch
if (isNodeModulesDirectory(dirPath)) {
return { dir, dirPath };
// If directory path contains node module, get the most parent node_modules directory for watching
while (stringContains(dirPath, "/node_modules/")) {
dir = getDirectoryPath(dir);
dirPath = getDirectoryPath(dirPath);
}
// If directory path contains node module, get the node_modules directory for watching
if (dirPath.indexOf("/node_modules/") !== -1) {
while (!isNodeModulesDirectory(dirPath)) {
dir = getDirectoryPath(dir);
dirPath = getDirectoryPath(dirPath);
}
// If the directory is node_modules use it to watch
if (isNodeModulesDirectory(dirPath)) {
return { dir, dirPath };
}