Search code examples
node.jsgrepnode-modulesack

ack|grep|whatnot special ignore folders pattern node_modules/dir/node_modules


I have recently discovered ack and ack -ir --ignore-dir={node_modules,dist,.git} <search-term> works great for most things but this

---node_modules/
---------------project1/
-----------------------node_modules/
---------------project2/
-----------------------node_modules/

I would like to search all files under the "root" node_modules and excluding all internal ones.

Note: if I run find . -type f | ack -v 'node_modules|.git|dist' under the root node_modules folder, I get a proper file list. this happen because find . gives out relative paths. Any way to feed this list to ack ?


Solution

  • ack -i <search-term> ./node_modules/*
    

    should do what you want. If you want to include hidden files and folders too, set shopt -s dotglob (assumes Bash) first.


    Background information:

    ack has many rules for ignoring files that you don't typically want to be searched built in.

    As of at least version 2.14, this includes directories named .git and node_modules, at whatever level of the hierarchy (ack searches recursively by default, though you may add -r / -R / --recursive to make that explicit).
    To see the complete list of directories / files that are ignored by default, run ack --dump.

    By using globbing (pathname expansion) to let the shell expand pattern ./node_modules/* to a list of actual items inside ./node_modules, the ignore rule for node_modules is bypassed for those explicitly passed items.