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

Exclude node_modules folders from Spotlight indexing #6453

Open
as-com opened this issue Sep 30, 2018 · 10 comments

Comments

Projects
None yet
10 participants
@as-com
Copy link
Contributor

commented Sep 30, 2018

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
node_modules folders are indexed by Spotlight on macOS

What is the expected behavior?
node_modules folders are (possibly optionally) excluded from indexing

This can be done by putting a .metadata_never_index in node_modules whenever the folder is created.

This may not work (it didn't work for me?)
Another way is to create node_modules.noindex, and symlink node_modules to it. Alternatively, figure out a way to programmatically add to the list of Spotlight exclusions.
Looks like I was holding it wrong.

@ghost ghost assigned rally25rs Sep 30, 2018

@ghost ghost added the triaged label Sep 30, 2018

@rally25rs rally25rs added cat-feature and removed triaged labels Sep 30, 2018

@burkeshartsis

This comment has been minimized.

Copy link

commented Oct 12, 2018

It seems like this only just became an issue when updating macOS to Mojave 🤷‍♂️

@as-com

This comment has been minimized.

Copy link
Contributor Author

commented Oct 12, 2018

@burkeshartsis I thought node_modules polluting spotlight search results and high CPU usage from indexing always been an issue.

@tcrossland

This comment has been minimized.

Copy link

commented Oct 30, 2018

See also npm/npm#15346

@jrz

This comment has been minimized.

Copy link

commented Mar 11, 2019

15346 says the "true" solution is add folder names to the index. This is pure nonsense. It should be possible to add the metadata_never_index, OR to set a file attribute.
It's either this, or having a global repository and better module loading (and only have spotlight index the files once).

@chrisbull

This comment has been minimized.

Copy link

commented Mar 25, 2019

Found this quick script to add .metadat_never_index to your node_modules folders.

find . -type d -name "node_modules" -exec touch "{}/.metadata_never_index" \;

I added it as a bash alias, so I can use apply quickly.

alias fix-spotlight='find . -type d -name "node_modules" -exec touch "{}/.metadata_never_index" \;'

Just thought I'd share here, for anyone else that is looking. :)

@kiddyfurby

This comment has been minimized.

Copy link

commented May 9, 2019

I am sorry but will yarn consider this feature?

@dicksonhk

This comment has been minimized.

Copy link

commented Jun 3, 2019

Based on @chrisbull 's idea, this script does the same thing faster by not going inside any node_modules directories found (coz the whole node_modules directory had already been ignored)

find . -type d  -path '*node_modules/*' -prune -o -type d -name 'node_modules' -exec touch '{}/.metadata_never_index' \;

For myself, I run it on the home directory, so I exclude hidden directories and Library directory to speed things up

find . -type d -path './.*' -prune -o -path './Pictures*' -prune -o -path './Library*' -prune -o -path '*node_modules/*' -prune -o -type d -name 'node_modules' -exec touch '{}/.metadata_never_index' \; -print

I also use the -print option so I know which folder is affected

@justin808

This comment has been minimized.

Copy link

commented Jun 14, 2019

For those using @dicksonhk's answer (thanks!) on MacOS, you have to have a dot or other directory after the command "find".

Maybe the same for other linux.

I agree that yarn should automatically add this file, although this is MacOS specific. Maybe some hook is better?

@dicksonhk

This comment has been minimized.

Copy link

commented Jun 25, 2019

For those using @dicksonhk's answer (thanks!) on MacOS, you have to have a dot or other directory after the command "find".

Maybe the same for other linux.

I agree that yarn should automatically add this file, although this is MacOS specific. Maybe some hook is better?

@justin808 You're right! I edited my answer to add . -type d and it should work fine!
Also, if you are running the command in the home directory like me you should take a look at the second command which excludes unnecessary directories :)

@joaomnb

This comment has been minimized.

Copy link

commented Jun 29, 2019

My Spotlight seems to ignore these .metadata_never_index files, every node_modules folder is still indexed... I'm running macOS Mojave. Anyone had the same problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.