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

git-ls-files

v1.1.0

Published

Package to list all files tracked in the git repository

Downloads

11

Readme

git-ls-files Build Status Coverage Status

The package uses the git ls-files command to list all the files that are in your version control system. It will give three default groups:

{
  all: []. // all the files that are in git
  js: [], // list of all JavasScript files
  test: [], // files that end with .test.js
}

Why?

Why is this package interesting or how it came to be?

Its a simple thing: grunt + jshint / jscs or any other js hinter. So all projects needs a linter/hinter, but the issue with grunt and the most popular hinters, is that they get very-very-very slow, when a project has a lot of files in it and the pattern to match them isn't efficient enough.

They get slow as grunt will traverse on all the directories, even on the ones that are ignored and then starts to check the files.

An example from stackoverflow: https://stackoverflow.com/questions/24803046/grunt-js-how-to-efficiently-ignore-black-list-node-modules-folder

Here the fellow developer would have liked to ignore all that is in the node_modules folder, but check all .js files in the repository, hence they added the !node_modules/** pattern for jshint. However grunt will still scan all the files in that black hole called node_modules and while it wont hint the JavasScript files within that folder it will still be extremely slow.

So with this little package one can list and group all the important files in a project and simply give that short list to the grunt task.

Following the example from stackoverflow, one with this package can do the following:

const gitLsFiles = require('git-ls-files');
const files = gitLsFiles();
const config = {
    jshint: {
        scripts: files.js
    },
    watch: {
        files: files.js,
        tasks: ['jshint']
    }
};

Of course the above can be used for build or for zipping together deployment packages.

API

Example usage

const gitLsFiles = require('git-ls-files');
const files = gitLsFiles({
  cwd: './',
  groups: {
    myCustomGroup: /.*awesomeFiles.js$/,
    myBestGroup: function (fileName) {
      return Math.floor(Math.random() * 10) > 5;
    }
  },
});

cwd [string]

Current Working Directory - this will tell the method, in which directory it should check.

groups [object]

For each key defined in the groups, the lib will try to find matching files. The value for they hey should either be a method or a regexp.

staged [boolean]

List only files staged for next commit

Result

It will be an object with list of files at the keys. For example I got the following, when ran the above example against this repo:

{
  myCustomGroup: [],
  myBestGroup: ['src/index.js'],
  js: [
    'Gruntfile.js',
    'src/index.js',
    'src/index.test.js',
    'test/test-common.js'
  ],
  test: ['src/index.test.js'],
  all: [
    '.gitignore',
    '.jscsrc',
    '.jshintrc',
    'Gruntfile.js',
    'package.json',
    'src/index.js',
    'src/index.test.js',
    'test/test-common.js'
  ]
}