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

drun

v0.0.4

Published

containerized run of scripts

Downloads

6

Readme

DRun

Run your npm scripts within an specified environment. It requires docker ( see how to install it here).

Easily define runtimes so your project run always in the environment you defined. Useful for:

  • running tests always within the same environment (the runtime environment, not the developer machine, deterministics tests)
  • easily watch and restart server and long running processes with no extra effort/development (for example, a replace for nodemon)
  • forget about being cross platform on your npm scripts! (you may stop using cross-env or shelljs everywhere)

Often you will run in similar environments. Cross-platform is not always a requirement, and even if it is, it will be better tested if it's controlled. Why not just use docker directly? Because it can be cumbersome to remember runtimes for each one of your projects. With drun you can put that within your project.

Features

  • Configurable via package.json
  • Default behavior right out of the box
  • Define a default image
  • Define N images
  • NPM default support
  • Piped colorful terminal

Installation

npm install --save-dev drun

Minimal configutation

This is just a local installation shortcut:

{
  // ... the rest of the package json
  "scripts": {
    // your other scripts,
    "drun": "drun"
  }
  // ... the rest of the package json
}

And that's it, if you run npm run drun you'll get an alpine based node js running your tests!

Example configuration

/// ... package.json
{
  "drun": {
    "default": {
      "image": "node"
    }
  },
  "scripts": {
    "test": "mocha",
    "build": "babel src -d dist",
    "start": "node server.js",
    "drun": "drun",
    "drun:start:watch": "watch 'drun start' server.js"
  }
}
// ...

Then, if you run npm run drun it will execute npm run test within the latest node image on the docker hub. Also, if you run npm run drun build it will execute npm run build instead (test is just the default).

In a more complex example, if you run npm run drun:start:watch it will execute npm start and, with the help of the watch package for example (you can use whatever you want), it will kill the container and lift a brand new npm start.

Note that you don't need to create dirty long complex commands within your actual scripts.

Using different containers

The above example is using the default container with a custom image. However drun supports using N containers within your package.json. For example, you can have this:

/// ... package.json
{
  "drun": {
    "default": {
      "image": "node"
    },
    "building": {
      "image": "node:alpine"
    }
  },
  "scripts": {
    "test": "mocha",
    "build": "babel src -d dist",
    "start": "node server.js",
    "drun": "drun",
    "drun:start:watch": "watch 'drun start' server.js"
  }
}
// ...

Note the new building object with a different image. Now, if you run npm run drun build building it will execute npm run build with the node:alpine image. The general command is npm run drun <command> <container>.

Considerations

  • You can use your own images, but the building process is on you, that's by design.

Available options

Drun configuration may have 1..N containers defined within it. The default configuration is

{
  "drun": {
    "default": {
      "image": "node:alpine",
      "ports": {}, // this means random, execute docker port drun-default
      "volumes": {
        "./:/src" // drun will convert this to an absolute path atuomatically to make docker happy
      },
      "workingDirectory": "/src",
      "commandType": "raw" // if raw is specified it does not prefix commands with `npm run`
      "interactive": true, // useful for some ci environments
      "tty": true // useful for some ci environments
    }
  }
}

A more complex command: npm run drun "npm i" default This will execute the npm i command as a raw command in the default container

Custom options

You may use more options:

{
  "drun": {
    "custom": {
      "image": "node:alpine",
      "ports": {
        "8080": "8080"
      },
      "volumes": {
        "./": "/src",
        "/home": "/home"
      },
      "workingDirectory": "/src",
      "commandType": "raw"
    }
  }
}

MIT

nicosommi