Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDestFilePath: handle non-existent (deleted/moved) files #207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions test/filter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down