glob-fs-gitignore

raw JSON →
0.1.6 verified Sat Apr 25 auth: no javascript maintenance

Middleware for glob-fs that automatically ignores files and directories specified in .gitignore patterns. Version 0.1.6, last updated in 2017. Built by Jon Schlinkert as part of the glob-fs ecosystem. It integrates seamlessly with glob-fs to provide gitignore-aware file globbing. The package is stable but minimally maintained. It differs from alternatives like ignore by being a middleware for glob-fs rather than a standalone library. Works with Node.js >=0.12.0.

error TypeError: gitignore is not a function
cause Importing incorrectly in CommonJS, e.g., const { gitignore } = require('glob-fs-gitignore') when the module exports a function directly.
fix
Use const gitignore = require('glob-fs-gitignore');
error Cannot find module 'glob-fs-gitignore'
cause The package is not installed or is missing from node_modules. Also ensure glob-fs is installed as a peer dependency.
fix
Run npm install glob-fs-gitignore glob-fs
deprecated Note: glob-fs-gitignore is built-in to glob-fs as default middleware. Only use this package if you have disabled the default middleware stack in glob-fs.
fix Use glob-fs without disabling defaults; it includes gitignore handling automatically.
gotcha The middleware must be called as a function (gitignore()) when passed to .use(). Omitting parentheses yields an error or unexpected behavior.
fix Ensure to invoke gitignore() as a function: glob.use(gitignore())
npm install glob-fs-gitignore
yarn add glob-fs-gitignore
pnpm add glob-fs-gitignore

Demonstrates using glob-fs-gitignore middleware to ignore .gitignore patterns while globbing.

const glob = require('glob-fs')({ dotfiles: true });
const gitignore = require('glob-fs-gitignore');

glob.use(gitignore())
  .readdir('**/*', function(err, files) {
    if (err) throw err;
    console.log(files);
  });