Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
ignore-walk
Advanced tools
The ignore-walk npm package is a Node.js library used to create a list of files in a directory tree while honoring .ignore rules, similar to how tools like git and npm ignore files based on .gitignore or .npmignore files. It is particularly useful for applications that need to process file trees while excluding files that should be ignored according to specified patterns.
Walking a directory while respecting .ignore files
This feature allows you to walk through a directory and list all files that are not excluded by the ignore rules specified in .ignore files such as .gitignore. The function returns a promise that resolves with the list of files.
const IgnoreWalk = require('ignore-walk');
IgnoreWalk({
path: './path/to/directory',
ignoreFiles: ['.gitignore']
}).then(files => {
console.log('Files:', files);
}).catch(err => {
console.error('Error:', err);
});
The 'glob' package provides functionality to match files using the patterns the shell uses, like stars and stuff. It can be configured to ignore files based on patterns, which is similar to ignore-walk, but glob is more focused on pattern matching rather than strictly interpreting .ignore files.
Findit is another Node.js module that walks the file system recursively. It can be used to find files and directories, but unlike ignore-walk, it does not natively support ignoring files based on .ignore files, requiring manual handling of such functionality.
Nested/recursive .gitignore
/.npmignore
parsing and filtering.
Walk a directory creating a list of entries, parsing any .ignore
files met along the way to exclude files.
const walk = require('ignore-walk')
// All options are optional, defaults provided.
// this function returns a promise, but you can also pass a cb
// if you like that approach better.
walk({
path: '...', // root dir to start in. defaults to process.cwd()
ignoreFiles: [ '.gitignore' ], // list of filenames. defaults to ['.ignore']
includeEmpty: true|false, // true to include empty dirs, default false
follow: true|false // true to follow symlink dirs, default false
}, callback)
// to walk synchronously, do it this way:
const result = walk.sync({ path: '/wow/such/filepath' })
If you want to get at the underlying classes, they're at walk.Walker
and walk.WalkerSync
.
path
The path to start in. Defaults to process.cwd()
ignoreFiles
Filenames to treat as ignore files. The default is
['.ignore']
. (This is where you'd put .gitignore
or
.npmignore
or whatever.) If multiple ignore files are in a
directory, then rules from each are applied in the order that the
files are listed.
includeEmpty
Set to true
to include empty directories, assuming
they are not excluded by any of the ignore rules. If not set, then
this follows the standard git
behavior of not including
directories that are empty.
Note: this will cause an empty directory to be included if it would contain an included entry, even if it would have otherwise been excluded itself.
For example, given the rules *
(ignore everything) and !/a/b/c
(re-include the entry at /a/b/c
), the directory /a/b
will be
included if it is empty.
follow
Set to true
to treat symbolically linked directories as
directories, recursing into them. There is no handling for nested
symlinks, so ELOOP
errors can occur in some cases when using this
option. Defaults to false
.
6.0.5 (2024-05-04)
c3ed705
#127 bump @npmcli/template-oss to 4.22.0 (@lukekarrys)477a720
#121 chore: chore: postinstall for dependabot template-oss PR (@lukekarrys)f5919cc
#114 template-oss-apply (@dependabot[bot])ce00723
#127 postinstall for dependabot template-oss PR (@lukekarrys)f77a3dc
#126 bump @npmcli/template-oss from 4.21.3 to 4.21.4 (@dependabot[bot])FAQs
Nested/recursive `.gitignore`/`.npmignore` parsing and filtering.
We found that ignore-walk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.