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

Fix getDestFilePath behavior for directories #52

Closed
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
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,26 @@ Filter.prototype.canProcessFile =
return !!this.getDestFilePath(relativePath);
};

Filter.prototype.isDirectory = function(relativePath) {
if (this.inputPaths === undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when is this true?

return false;
}

var srcDir = this.inputPaths[0];
var path = srcDir + '/' + relativePath;

return fs.lstatSync(path).isDirectory();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather then stating again, lets pass entry from https://github.com/stefanpenner/broccoli-persistent-filter/blob/master/index.js#L125 to getDestFilePath, that way we can simply ask it entry.isDirectory() etc.

};

Filter.prototype.getDestFilePath = function(relativePath) {
// NOTE: relativePath may have been moved or unlinked
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the above suggestion, i suspect this is no longer required.

if (this.isDirectory(relativePath)) {
return null;
}
} catch(e) {
}

if (this.extensions == null) {
return relativePath;
}
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ describe('Filter', function() {
expect(filter.canProcessFile('twerp.rs')).to.equal(false);
});

it('getDestFilePath returns null for directories when extensions is null', function() {
var inputPath = path.join(rootFixturePath, 'a/dir');
var filter = MyFilter(inputPath, { extensions: null });
filter.inputPaths = [inputPath];

expect(filter.getDestFilePath('a/bar')).to.equal(null);
expect(filter.getDestFilePath('a/bar/bar.js')).to.equal('a/bar/bar.js');
});

it('getDestFilePath returns null for directories with matching extensions', function() {
var inputPath = path.join(rootFixturePath, 'dir-with-extensions');
var filter = MyFilter(inputPath, { extensions: ['js'] });
filter.inputPaths = [inputPath];

expect(filter.getDestFilePath('a/loader.js')).to.equal(null);
expect(filter.getDestFilePath('a/loader.js/loader.js')).to.equal('a/loader.js/loader.js');
});

it('replaces matched extension with targetExtension by default', function() {

var filter = MyFilter('.', {
Expand Down