-
Notifications
You must be signed in to change notification settings - Fork 25
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 #25 : add support for a custom mount function... #26
base: master
Are you sure you want to change the base?
Conversation
… desired output + tests
'../a.js', | ||
'../a.md', | ||
'../a.txt', | ||
'../b.txt', | ||
'../child' | ||
// '../child' is in fact resolved to '' related to himself ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was working as expected. Pretty sure that's how other glob implementations works, including bash
and other JS packages like node-glob
. Instead of returning an empty string it should return the name of the folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so too
Thanks for the PR. I'll check it out. What do you think @lukeed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd much rather see this approach, if any is to be taken, which is what this PR boils down to:
// rename "mount" -> "transform"
opts.transform = (opts.transform || opts.absolute && resolve || relative).bind(null, cwd);
return await walk(matches, glob.base, path, opts, '.', 0);
Current PR trades 3 extra function calls per file (always) in the place of one conditional loop, that only executed one 1 function per file. Not actually a good trade 😬
@terkelg @lukeed : Hi, congrats ! And thanks for the quick review ! :) Well.. Is there a benchmark somewhere with some serious file hierarchy to scan ? Because, in fact, i believe that the whole point of my PR was to state the fact that returning (very fast) an array of relative paths is great, but not so usefull in the end, because usually, people will want to do something with these paths : like loading stats, examining content.. whatever... So, i would be really interested by a benchmark with thousands of files that would compare these 2 approaches : glob('whatever').map(path => toVfile(path)) // return paths then map to vfiles
vs
glob('whatever', { transform: toVfile }) // build vfile at the creation NB : i think i could have done better with my PR if the name and usage of the vars in the walk method were more obvious because i think that calling |
Well, conceptually, running 3 functions instead of 1 function is slower -- there's no disputing that. I don't disagree with your idea for a custom transformer; I'm just saying that it's not up to me whether or not the feature is added. However, if it is to be, my snippet is how we'd want to go about it. It applies the ability to transform each file with the desired effect using one function call per file instead of three per file. The benchmark you're interested in is just comparing a for loop to a |
I think it could be cool with the option to do a custom |
The |
…to build the desired output.
Principle :
If the user provides a custom function with
opts.mount
,the absolute or relative path of matched files is given to that function to return whatever the user really needs.
Test has been added to show how to create a pseudo VFile object in one pass.
NB : the test
'glob: options.cwd'
has been corrected as it incorrectly expected'../child'
as a result for a path relative to himself. The correct response is in fact''
(empty path!) as shown by :