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

postinstall

v0.10.3

Published

Deploy files from modules after npm install

Downloads

71,347

Readme

postinstall

Transform files of Node.js modules with simple and powerful package.json configurations. Meant to be used by packages lifecycle events:

  • prepare use it to transform devDependencies, while developing or before publishing
  • postinstall use it to deploy dependencies.

How

Depend on this package: npm install postinstall --save

Configure and run postinstall in package.json:

{
  "name": "mypkg",
  "version": "1.0.0",
  "dependencies": {
    "postinstall": "*"
  },
  "scripts": {
    "postinstall": "postinstall",
    "prepare": "postinstall"
  },
  "prepare": {
    "<modulename>/path": "browserify lib/"
  },
  "postinstall": {
    "<othermodule>/file": "link lib/"
  }
}

From there, more dependencies and commands can be added:

{
  "dependencies": {
    "jquery": "3",
    "postinstall": "*"
  },
  "postinstall": {
    "jquery/dist/jquery.slim.min.js": "link public/js/jquery.min.js",
    "jquery/dist/jquery.slim.min.map": "link public/js/jquery.min.js.map"
  },
  "scripts": {
    "postinstall": "postinstall"
  }
}

It is also possible to configure postinstall in another json file:

{
  "scripts": {
    "postinstall": "postinstall myconfig.json"
  }
}

Here myconfig.json contains:

"postinstall": {
  "jquery/dist/jquery.slim.min.js": "link public/js/jquery.min.js",
  "jquery/dist/jquery.slim.min.map": "link public/js/jquery.min.js.map"
}

Options

  • --allow, -a an array of allowed commands. postinstall -a link -a copy. When unset, all commands are allowed. Available since version 0.3.0.

Syntax

Short form

postinstall: {
  "<module>/<input>": "<command> --<option>=<value> <output>"
}

Long form

postinstall: {
 "<module>/<input>": {
  "command": "<command>",
  "output": "<output>",
  "<option>": "<value>"
 }
}

Array form

 "<module>/<input>": [<shortForm | longForm>, ...]

input can be a path, with an optional star in its filename.

output can be a path, with an optional star in its filename.

This allows commands to receive multiple files for one output.

List option

If a command needs to process files in a specific order, the list of files can be given in the long form option list, like this:

"src/": {
 "command": "concat",
 "output": "dest/bundle.js",
 "list": ["two.js", "one.js"]
}

This calls concat(["src/two.js", "src/one.js"], "dest/bundle.js").

Renaming

If a star is present in both input and output file names, it is interpreted as renaming the input file(s) name(s):

"postinstall": {
  "jquery/dist/*.slim.min.js": "link public/js/*.min.js"
}

This will produce the same inputs/outputs as the first example.

Command

New commands can be added to postinstall and they just need to be available as postinstall-<command> modules exporting a single function:

module.exports = function(inputs, output, options) {
 // inputs is an array of paths
 // output is a path
 // options is an object (possibly empty)
 // can return promise
};

Bundled commands: link, copy, concat.

Supported commands:

  • zero-config compilers/minifiers: js, css (postinstall-js, postinstall-css)
  • browserify (postinstall-browserify)

Using as a module

opts accepts the same options as the cli options and also:

  • cwd resolves paths and modules relative to this directory. Defaults to process.cwd(). Cannot be set from cli. Available since version 0.4.0.
var postinstall = require('postinstall');
postinstall.process(config, {
  allow: ['copy']
}).then(function() {
  // done
}).catch(function(err) {
  console.error(err);
});

// or call manually
postinstall.command(name, input, output, options);

debugging in vscode

To stop on breakpoints the script must be run directly, e.g.

cd test/tmp/whitelist
npm_lifecycle_event=postinstall ../../../bin/postinstall.js