node.jsregexglobchokidar

how to ignore files within subdirectories using chokidar


I have this directory structure

├── components
│   ├── quarks
│   │   └── index.js
│   │   └── ...
│   ├── bosons
│   │   └── index.js
│   │   └── GridLayout.vue
│   │   └── ...
│   ├── atoms
│   │   └── ButtonStyle.vue
│   │   └── InputStyle.vue
│   │   └── index.js
│   │   └── ...
│   ├── .......
└─────

I'd like to ignore the index.js within each folder, but I'm not getting it, I've tried it in several ways

const path = require('path')
const chokidar = require('chokidar')
const ROOT_PATH = path.resolve('components')

const watcher = chokidar.watch(ROOT_PATH, {
  ignored: ROOT_PATH + '/*/index.js', //does not work
  ignoreInitial: true
})

already tried: './components/**/index.js', './components/*/index.js', 'components/*/index.js', 'components/**/index.js', 'ROOT_PATH + '/**/index.js'

Anyone have any idea how to make it work?


Solution

  • Chokidar seems bugged, defective to ignore files on MacOS, that's the impression I have.

    So before running my action, I'm checking to see if the file is the same one I want to ignore.

    chokidar
      .watch('components', { ignoreInitial: true })
      .on('all', (event, filename) => {
        filename !== 'index.js'
        // action here
      })