Only show modules that is defined on package.json
Currently autocomplete-modules list all packages inside node_modules directory. Using npm 3 will make autocomplete list all packages because of flat hierarchy.
I think the default behavior should only list packages that is native in nodejs and packages that is explicitly defined in package.json. We can probably add another setting to include all packages inside node_modules if we want implicit import
What do you think?
I guess you're right, but there is another problem. Some people develop monorepo projects, which could contain multiple package.json files.
You're welcome to contribute this functionality under the onlyPackage flag, or something like that.
Yes, I have a monorepo myself (using lerna). What do you think the best approach, walk up directory tree until it's a root directory, then for every package.json found, add it to the list of available deps?
Lerna itself only has $ROOT/packages/modules directory structure so we can simply check $ROOT/package.json and the module package.json itself, but I don't know if anyone has different directory structure on their monorepo.
Also, do you think making explicit package only as default behavior is preferable? because this is kind of breaking change
Filtering node_modules by package.json seems like the right default to me, because you really shouldn't be importing transitive dependencies. If it were up to me, this is how I would design this. Any time I encounter a node_modules with a sibling package.json, the package.json would be used and node_modules would be ignored.
Since everything resolves node_modules I don't use custom resolvers in my projects. Instead, I have committed code to a 2nd node_modules that isn't managed by a package.json. Those would need the current behavior of including everything.
What if the packages were simply sorted based on their presence in a package.json? This way, the packages you intentionally installed will rise to the top of the list.
I've been working with Gulp plugins, and the plugin has dutifully been suggesting through in place of through2. Sorting by inclusion in dependencies would greatly help!
What is the use case for importing a module that you did not install? A module that is not managed by you, but is managed by and can be upgraded and replaced at any time by a different project you depend on? I'm pretty sure this is something you should never do, so offering it as an option is just another way to help people shoot themselves in the foot.
I really like the idea of filtering by package.json. This could also reduce the lookup time (ie less dependencies to filter through the node_modules folder).
We will consider this if it raises more support.
@jonyeezs hey, not sure why you need more opinions on this issue, it's the most upvoted opened issue.
I'm also waiting for this feature and actually surprised this package doesn't work this way by default. 😉