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

Only show modules that is defined on package.json #52

Open
pveyes opened this issue Oct 12, 2016 · 7 comments
Open

Only show modules that is defined on package.json #52

pveyes opened this issue Oct 12, 2016 · 7 comments

Comments

@pveyes
Copy link

pveyes commented Oct 12, 2016

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?

@nkt
Copy link
Owner

nkt commented Oct 12, 2016

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.

@nkt nkt added the feature label Oct 12, 2016
@pveyes
Copy link
Author

pveyes commented Oct 13, 2016

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

@AsaAyers
Copy link

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.

@ryaninvents
Copy link

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!

@AsaAyers
Copy link

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.

@jonyeezs
Copy link
Collaborator

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.

@vladshcherbin
Copy link

@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. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants