If you're using a library to ignore gitignored files, it probably doesn't do it right! Use this library to be match git behavior 100%.
Determine if any file is gitignored. This is intended to be a complete implementation of the gitignore spec, including $GIT_DIR
, $GIT_DIR/info/excludes
, and the core.excludesFile
configuration variable.
Requires Node >= 8.
npm install --save gitignore-fs
const Gitignore = require('gitignore-fs')
const gitignore = new Gitignore()
console.log(gitignore.ignoresSync('node_modules')) // true or false depending on your config
Each instance of this class keeps a separate cache of gitignore rules.
Creates a new Gitignore instance.
These rules will be applied at lowest precedence (lower than rules from core.excludesFile
).
Paths with a slash in the beginning or middle are relative to the closest enclosing git directory.
These rules will be applied at highest precedence (higher than .gitignore
files).
Paths with a slash in the beginning or middle are relative to the closest enclosing git directory.
Determines if the given path
is gitignored asynchronously.
The path to test. Must end with / if it is a directory!
A promise that will resolve to true
if path
is gitignored, false
otherwise
Determines if the given path
is gitignored synchronously.
The path to test. Must end with / if it is a directory!
true
if path
is gitignored, false
otherwise
Clears the entire gitignore rule cache.