refactor(ls): greatly simplify ls implimentation#369
Conversation
|
@ariporad does this work for Also, this breaks some additional tests, so those should be resolved first. |
|
@nfischer: So, we appear to have some inconsistent ls behavior. If your pass in a file/pattern with no matches, should it have an error, or just return an array with nothing in it? |
|
@ariporad I accounted for this in $ ls this*file*doesnt*exist.txt
ls: cannot access this*file*doesnt*exist.txt: No such file or directory
# bash passes a literal 'this*file*doesnt*exist.txt' to the ls executable |
|
@nfischer: So if it can't find the file it should error? |
|
That's what |
|
|
|
@ariporad pinging this to see if there's any work being done to re-add support for |
|
@nfischer: Sorry, I've been sick. I'll work on that ASAP. |
01dd466 to
9fe3d1e
Compare
|
@nfischer: Both |
9fe3d1e to
949615f
Compare
shell.js
Outdated
| //@include ./src/ls | ||
| var _ls = require('./src/ls'); | ||
| exports.ls = common.wrap('ls', _ls, {idx: 1}); | ||
| exports.ls = common.wrap('ls', _ls, {noGlob: true}); |
There was a problem hiding this comment.
Why was this taken out? Also, does noGlob even do anything here?
There was a problem hiding this comment.
We don't want to glob in common.wrap, we want to do it in late itself, because we want to optionally pass different opts to common.expand depending on the flags passed in.
There was a problem hiding this comment.
I don't think noGlob is a real option (no idx value will have the same effect)
Also, would it be possible to modify common.expand() to take all as an argument? It might be cleaner to keep glob inside common.js
There was a problem hiding this comment.
It's a real option.
Moving the all option into wrap would be really complex, and probobly not that useful. ls needs to do some weird stuff with common.expand, so I think we should just keep it in ls.
There was a problem hiding this comment.
config.noGlob is real, options.noGlob isn't. You're specifying options.noGlob here (just like how idx is really options.index here)
|
@ariporad I'm going to make some adjustments to this branch and see if I can fix some of the errors we're seeing. |
|
Ok, thanks! If not, I'll try to look into it tomorrow or when I get back. |
216f996 to
5df3ee2
Compare
|
@ariporad Take a look now. I fixed the bug you had for Windows (you forgot I tested performance and saw that this was very very slow... So I did my best to squeeze out some more performance. This is about 2x faster than your initial revision (and about 2x uglier...). This is still slower (also about 2x...) than the master branch, but it should be a lot cleaner. So it's a tradeoff. More maintainable and a bit slower, or we can stick with the tried and true method and get faster. As for the tests, only one of them needed to change (the one you changed for I also fixed a but where |
|
@ariporad This should be rebased off master. If you can, see if you find ways to improve performance (or refactor things into a function), since we're still taking a performance hit for the normal use case, which isn't ideal. |
|
@nfischer: I'm going to try something, give me a second. |
|
@nfischer: Actually, let me talk this through with you first. Personally I vote for slower and more maintainable, it's not like It also might be better to try to hijack function wrap(cmd, fn, options) {
return function() {
var oldStat = fs.stat;
var statResults = {};
fs.stat = function (file) {
if (!statResults[file]) statResults[file] = oldStat.apply(this, arguments);
return statResults[file];
}
// Whatever common.wrap used to do
fs.stat = oldStat;
};
}I bet this would speed things up a bit. |
|
Nope, no it wouldn't. But I did learn how to benchmark node things. |
|
@ariporad I just pushed another unit test to |
|
LGTM! |
|
Oh, wait, I have to rebase this off master. |
|
LGTM |
refactor(ls): greatly simplify ls implimentation
This greatly simplifies the implementation of
ls, and probably makes it a good deal more performant.