diff --git a/src/index.ts b/src/index.ts index 4ce81ab..c3b7bb4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -416,7 +416,21 @@ 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; + } + } } getDestFilePath(relativePath: string, entry: Entry) { diff --git a/test/filter-test.js b/test/filter-test.js index 09407bc..0accb83 100644 --- a/test/filter-test.js +++ b/test/filter-test.js @@ -96,6 +96,16 @@ describe('Filter', function() { expect(filter.canProcessFile('twerp.rs')).to.equal(false); }); + it('getDestFilePath handles non-existent (deleted/moved) files', async function () { + let inputPath = input.path(); + let filter = new MyFilter(inputPath); + + output = createBuilder(filter); + await output.build(); + + expect(filter.getDestFilePath('non/existent/file.js')).to.equal('non/existent/file.js'); + }); + it('getDestFilePath returns null for directories when extensions is null', async function () { let inputPath = input.path(); let filter = new MyFilter(inputPath, { extensions: null });