npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-dockerignore

v0.0.1

Published

node docker ignore

Downloads

27

Readme

dockerignore

dockerignore is a manager, filter and parser which is implemented in pure JavaScript according to the .dockerignore spec and is used in production in now-cli

The .dockerignore spec has a few subtle differences from .gitignore. IF you'd like a great .gitignore file parser, check out ignore. This package is a fork of ignore and follows the exact same API.

What's different from ignore?

  • There are many direct differences between the .gitignore and .dockerignore specifications
    • * in .gitignore matches everything, wheras in .dockerignore it only matches things in the current directory (like glob). This difference is important when whitelisting after a * rule
    • abc in .gitignore matches all abc files and directories, however deeply nested, however .dockerignore specifically matches on ./abc but does not match nested files/directories like ./somedir/abc
    • With .gitignore, when a parent directory is ignored, subdirectories cannot be re-added (using !) since git simply avoids walking through the subtree as an optimization, wheras with .dockerignore a subdirectory can be re-added even if a parent directory has been ignored
    • For a complete list of differences, check out the .gitignore spec and the .dockerignore spec
  • Under the hood, we rewrote the entire matching logic to be much simpler
    • instead of complex Regex rule to replace patterns with regex, we scan through patterns
    • this is also modeled directly from docker's implementation

What's the same as ignore?

  • The entire API (Infate we even reuse the same index.d.ts file for TypeScript definitions)
Tested on
  • Linux + Node: 9.0 (but we use babel and it should work on older version of Node. Accepting PRs if that isn't the case)
  • Windows + Node testing coming soon

Install

yarn add docker-ignore // or npm install --save docker-ignore

Usage

const ignore = require('docker-ignore')
const ig = ignore().add(['.abc/*', '!.abc/d/'])

Filter the given paths

const paths = [
  '.abc/a.js',    // filtered out
  '.abc/d/e.js'   // included
]

ig.filter(paths)        // ['.abc/d/e.js']
ig.ignores('.abc/a.js') // true

As the filter function

paths.filter(ig.createFilter()); // ['.abc/d/e.js']

Win32 paths will be handled

ig.filter(['.abc\\a.js', '.abc\\d\\e.js'])
// if the code above runs on windows, the result will be
// ['.abc\\d\\e.js']

Features

  • Exactly according to the dockerignore spec
  • All test cases are verified on Circle CI by doing an an actual docker build with the test case files and .dockerignore rules to ensure our tests match what happens with the real docker CLI
  • 0 external dependencies which keeps this package very small!

dockerignore vs ignore

Read our blog post about the differences between dockerignore and ignore and why we built this package.

Methods

.add(pattern)

.add(patterns)

  • pattern String|Ignore An ignore pattern string, or the Ignore instance
  • patterns Array.<pattern> Array of ignore patterns.

Adds a rule or several rules to the current manager.

Returns this

Notice that a line starting with '#'(hash) is treated as a comment. Put a backslash ('\') in front of the first hash for patterns that begin with a hash, if you want to ignore a file with a hash at the beginning of the filename.

ignore().add('#abc').ignores('#abc')    // false
ignore().add('\#abc').ignores('#abc')   // true

pattern could either be a line of ignore pattern or a string of multiple ignore patterns, which means we could just ignore().add() the content of a ignore file:

ignore()
.add(fs.readFileSync(filenameOfGitignore).toString())
.filter(filenames)

pattern could also be an ignore instance, so that we could easily inherit the rules of another Ignore instance.

.ignores(pathname)

Returns Boolean whether pathname should be ignored.

ig.ignores('.abc/a.js')    // true

.filter(paths)

Filters the given array of pathnames, and returns the filtered array.

  • paths Array.<path> The array of pathnames to be filtered.

.createFilter()

Creates a filter function which could filter an array of paths with Array.prototype.filter.

Returns function(path) the filter function.

Contributing

Contributions are always welcome and we are fully commited to Open Source.

  1. Fork this repository to your own GitHub account and then clone it to your local device.
  2. Install the dependencies: yarn or npm install
  3. Add a test case (if applicable) and ensure it currently fails
  4. Add code to pass the test
  5. Make a pull request (additional tests will run on CI to ensure that your test case agrees with an actual docker build)

Authors

Most of the initial work on this project was done by Kael Zhang (@kaelzhang) and the collaborators on node-ignore