From 70f7fd27b94907703c757c74fdf2a6a019c043f2 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Wed, 21 Oct 2020 23:44:31 -0400 Subject: [PATCH] fix(isDirectory): handle non-existent relativePath --- src/index.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4ce81ab..73fa702 100644 --- a/src/index.ts +++ b/src/index.ts @@ -416,7 +416,22 @@ abstract class Filter extends Plugin { return false; } - return (entry || this.input.lstatSync(relativePath)).isDirectory(); + if (entry !== undefined) { + return entry.isDirectory(); + } else { + try { + // wrap this in try/catch in case `relativePath` doesn't exist + const stat = this.input.lstatSync(relativePath); + return stat.isDirectory(); + } catch (error) { + // if we get any other error, we really don't know what is going on so we need to rethrow + if (error.code === 'ENOENT') { + return false; + } + throw error; + } + } + return entry ? entry.isDirectory() : this.input.existsSync(relativePath) && this.input.lstatSync(relativePath).isDirectory(); } getDestFilePath(relativePath: string, entry: Entry) {