junosuarez/find-root

Just because a directory has a package.json doesn't mean it is a root

patrick-steele-idem opened this issue · 4 comments

Just came across this package and noticed that it uses a problematic approach to find the root...

It is not uncommon to create package.json files in a package's nested directories. These intermediate package.json files can be used to set the main for a directory or add extra metadata such as a browser field, but they should not be used to determine the root of the package.

I recommend updating the code to read the package.json to make sure it at least has a name field. Thoughts?

Thanks for bringing these cases to my attention. My goal is to conform to npm's definition of root. I'll mark this as a bug for when I have time to investigate the algorithm that, for example, the npm cli uses to determine the root (e.g., when you run npm install in a child directory). If you (or anyone else) want to contribute, linking to their source in this issue would help speed things along.

Thanks!

I would an an optional argument that would accept a string to match to the 'name' property in package.json

A more comprehensive option is to accept a callback function. find-root would parse the JSON and pass it to the callback function for evaluation. The implementor would need to return a boolean to indicate it the root-test passed or failed.

This can be overloaded with the string option above for simpler situations.

thanks again for the discussion here- this is fixed in find-root@1.1.0 (#5)