Pathname conventions for node-ignore
masterWhen using methods like .ignores(), .filter(), or .test(), the paths provided must follow these conventions:
- Must be relative paths: Paths should be the result of
path.relative()to the directory containing the ignore rules.- WRONG:
./abc,/abc, or absolute Windows paths likeC:\abcwill throw errors. - RIGHT:
abcorpath.join('abc')(which resolves to a relative path).
- WRONG:
- Files vs Directories:
node-ignoredoes not perform filesystem checks (fs.stat). It relies on the string format to distinguish types:foois treated as a file.foo/is treated as a directory.
To ensure you are passing directory paths correctly when using tools like glob, use the mark: true option to append a trailing slash to directory names.
import glob from 'glob'
import ignore from 'ignore'
glob('**', { mark: true }, (err, files) => {
if (err) return console.error(err)
// 'files' will contain directory names with trailing slashes (e.g., 'config/')
let filtered = ignore().add(['config/']).filter(files)
console.log(filtered)
})