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

revfu

v0.2.0

Published

Assets revision builder

Downloads

4

Readme

Installation

npm install revfu

To use outside Gulp (see Usage with Gulp ) you may also need a Vinyl adapter, most likely (but not limited to):

npm install vinyl-fs

Usage

Warning: this is a very early prototype and API may change significantly

const revfu = require('revfu'),
      path  = require('path'),
      vfs   = require('vinyl-fs');

let workingDir = path.join(__dirname, 'static');

revfu(workingDir).pipe(vfs.dest(workingDir));

Example with options:

revfu(workingDir, {
  exclude: ['uploads/**', 'robots.txt'],
  dontRename: ['bootstrap-4.4.1.{js,css}'],
  dontRewrite: ['bootstrap-4.4.1.js'],
  revision: {
    format: '{hash}-{name}.{ext}',
    hashType: 'sha384',
    hashLength: 10,
    prefix: '/assets',
    baseUrl: 'https://cdn.com/'
  },
  overrides: {
    '**/*.json': {
      prefix: '/data',
      hashType: 'sha1'
    }
  },
  manifest: {
    format: 'rails4',
    absolutePaths: true
  }
}).pipe(vfs.dest('public/'));

Usage with Gulp

Gulp is not only a task runner, but also a good example of modular ecosystem based on well defined abstractions. This tool returns a Readable Vinyl stream therefore is compatible with gulp plugins and Vinyl adapters (see Upload to CDN and Remove original files for example).

function rev() {
  return revfu(workingDir).pipe(gulp.dest(workingDir));
}

exports.rev = rev;

Options

exclude

Type: Array

Default: []

Example: ['uploads/**', 'robots.txt']

Exclude files from search and processing. Takes an array of glob patterns accepted by minimatch

dot

Type: Boolean

Default: false

By default, we exclude any file and directory starting with dot (.git for example). Turning this on may cause some unexpected results, so use with caution

binaryExt

Type: Array

Default: ['.png', '.jpg']

List of file extensions which automatically marks as binary. This allows us to avoid false negative binary detection, so we will not search and replace inside binary files

extensionless

Type: Map

Default: '.js': [['"', "'"], ['"', "'"]]

Example: '.css: [['css!.'], ['"', '"']] - will match and replace css!.styles/app.css"

Some file types may be referenced without extension, for example js files might be required by some nodejs shim require "application". To avoid false positive search, we only replace strings surrounded by boundaries

dontRename

Type: Array

Default: []

Array of glob patterns which should not be renamed

dontRewrite

Type: Array

Default: []

Array of glob patterns. Files matched with this patterns will be kept untouched (references to other files will not be rewritten)

revision

revision.format

Type: String

Default: '{name}-{hash}.{ext}'

Format of revisioned filename

revision.hashType

Type: String

Default: 'sha256'

Any algorithm name accepted by nodejs crypto.createHash

revision.hashLength

Type: Number

Default: 8

The number of first n symbols of hash hex representation applied to filename

revision.transformPath

Type: Function

Default: undefined

Funtion which takes a virtual file representation (see Vinyl and src/file.js) and returns String transformed path. Useful for custom path transformations

revision.prefix

Type: String

Default: undefined

Path prefix. Useful for cases, when working dir is a subdir inside one, configured to serve static files. For example, if static files serves from public/ dir, but working dir is public/assets, this option set to /assets adds an ability to find and replace /assets/** references

revision.baseUrl

Type: URL|String

Default: undefined

Convert references to URLs. Useful with CDN (See Upload to CDN).

overrides

Type: Map

Default: {}

Example: '**/*.js': { prefix: '/javascripts' }

Override revision.* options for particular glob pattern

manifest

manifest.path

Type: String

Default: assets.json

Path to manifest file

manifest.format

Type: String|Function

Default: 'simple'

Format of manifest file. There is some predefined formats: simple, full, rails4

Also, can take function. Docs TBD

manifest.dumper

Type: Object

Default: JSON

Any object which responds to .stringify method and returns serialized string

manifest.dontStream

Type: Boolean

Default: false

Do not include manifest file in main stream

Remove original files

By default, original files remains untouched except the case, when destination folder is the same as source and file is in revision.dontRename option but not in revision.dontRewrite and had references to other files.

To remove original files, you can use gulp-rev-delete-original plugin:

// ...
const revDel = require('gulp-rev-delete-original');

revfu(workingDir).pipe(revDel()).pipe(vfs.dest('public/'));

Upload to CDN

TBD

License

MIT License