Exclude "extra" files & folders from packages in node_modules

Some npm packages include additional files that are not included in actual code base that's used by a project.

 

An example is the three npm package (for three.js).

 

I was working off one of their examples (from their website), when I noticed that IntelliJ/WebStorm seemed to think that a class already existed in the THREE namespace. 

It turns out that the three npm package includes all of the examples from their site, which WebStorm indexed, unaware of the fact that I wasn't using any of those files in my actual project; I was simply using const THREE = require('three');

 

Normally I'd be able to right click on a directory and select 'Mark as Excluded', but that isn't the case for folders inside node_modules.

 

Is there anyway I can have WebStorm exclude folders that are inside node_modules?

 

While I know that a lot of npm packages tend to have extra things in them, this is the first time to my knowledge that WebStorm has included these in it's indexing. I suspect it might be because the examples assign directly to the THREE namespace (they pollute the namespace, rather than keep it clean).

0
4 comments

Unfortunately WebStorm adds all .js/.ts files from modules listed as direct dependencies in package.json to javascript library, so that they all are added to javascript indexes. And there is no way to mark these files as excluded, as they are already excluded, and this exclusion is overridden by settings them up as a library...

You can try marking these extra files as plain text (Mark as plain text in file right-click menu); or, disable the predefined <project_name>/node_modules library, and create your own library instead, adding only those files that you'd like to be present in index there

0

Is it worth creating an issue/feature request for this?

 

It would be cool if I could tweak the rules WebStorm uses via custom glob-style paths.

 

I know WebStorm already does exclude some things in the node_modules, such as folders named node_modules (that is, node_modules inside packages inside my projects top level node_modules), and folders that start with a dot (I assume that's it's rule; in the aws-sdk the .changes folder is marked as excluded, and in my private package the .idea folder is ignored). The tests folder in less-middleware is also marked as excluded.

0

Please feel free to create a feature request in youtrack, https://youtrack.jetbrains.com/issues/WEB

1

Hi Elena

I've created WEB-31068

I got a bit overzealous on the idea, so I totally understand if it's something you guys feel isn't feasible. As I say at the end of the issue's body; let me know if that's the case, as I'll happily refactor the issue to be about simply supporting a regex/glob setting panel.

I didn't want to create an issue for each idea, since they'd make each other redundant, and at the end of the day the solution is up to you guys, so let me know what you think :)

1

Please sign in to leave a comment.