From d0545ffee85bf35accc839777065d85d032f51a7 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Thu, 24 Mar 2016 14:16:38 -0700 Subject: [PATCH 1/2] Explicitly exclude . and .. for fs.readdirSync --- src/compiler/sys.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 0bb87cc5a40fd..3f243b41d0217 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -495,7 +495,9 @@ namespace ts { visitDirectory(path); return result; function visitDirectory(path: string) { - const files = _fs.readdirSync(path || ".").sort(); + // This filtering is necessary because on some file system node fails to exclude + // "." and "..". See https://github.com/nodejs/node/issues/4002 + const files = filter(_fs.readdirSync(path || "."), f => f !== "." && f !== "..").sort(); const directories: string[] = []; for (const current of files) { const name = combinePaths(path, current); From ddbfb7b961dfb4489ca71866a5e1d7878824ae67 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Thu, 24 Mar 2016 15:56:13 -0700 Subject: [PATCH 2/2] refactor --- src/compiler/sys.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 3f243b41d0217..1ced01fb3497e 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -495,11 +495,14 @@ namespace ts { visitDirectory(path); return result; function visitDirectory(path: string) { - // This filtering is necessary because on some file system node fails to exclude - // "." and "..". See https://github.com/nodejs/node/issues/4002 - const files = filter(_fs.readdirSync(path || "."), f => f !== "." && f !== "..").sort(); + const files = _fs.readdirSync(path || ".").sort(); const directories: string[] = []; for (const current of files) { + // This is necessary because on some file system node fails to exclude + // "." and "..". See https://github.com/nodejs/node/issues/4002 + if (current === "." || current === "..") { + continue; + } const name = combinePaths(path, current); if (!contains(exclude, getCanonicalPath(name))) { const stat = _fs.statSync(name);