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

runtil

v1.0.0

Published

Run a command until the target string has been printed

Downloads

2

Readme

RunTil

RunTil is a simple command line tool that runs a command until a target string is found in the output. If the child process exits before finding the target string, runtil will exit with the same code as the child process unless it would be 0, in which case runtil will exit with 1 to indicate a failing state.

There are a few use cases for something like this:

  • Troubleshooting e2e tests, where a later test may overwrite the state of a previous test on disk that you need to be able to debug a failure
  • Starting a service in the background and waiting for it to be ready to accept connections before proceeding with the next step in a script

Usage

Basic Usage

This is useful when you need to debug a state on disk after a test failure, especially if a later test may overwrite the state. There are other use cases, but the important bit is that the command will be killed once the target string has been found.

> npx runtil --target-string "Error: test failed" -- npx jest

Leave Alive

Sometimes you may want to execute more commands after the first command has output a certain string, but leave the first command running in the background. A common example may be running e2e tests or another process that depends on a background server. Passing --leave-alive to runtil tells it to detach from the child process and leave it alive once the target string is found.

> npx runtil --target-string --leave-alive "Server is listening" -- node server.js --port 3000 && curl http://localhost:3000

Programmatic API

runtil exports its backing mechanism via a promise based function. It can be used in the following manners:

import { runUntil } from "runtil";

// Start the server, then kill it after it starts listening
await runUntil("Server is listening", ["node", "server.js", "--port", "3000"]);

// Start the server and leave it running, but resolves once it starts listening so
// the next lines can be ran
await runUntil({ targetString: "Server is listening", leaveAlive: true }, [
  "node",
  "server.js",
  "--port",
  "3000",
]);

// Start the server and leave it running, but resolves once it starts listening so
// the next lines can be ran, without printing any output from the child process
await runUntil(
  { targetString: "Server is listening", leaveAlive: true, silent: true },
  ["node", "server.js", "--port", "3000"]
);

In Repo Examples

In this repo there are a few example JS files to play with. You can run runtil via the npm run cli script. The examples look like:

Long Running Task

Write the first 3 files to disk, and then exit.

> npm run cli -- --target-string "Writing file 2" -- node ./examples/long-task

Write all 10 files to disk, but after the first 3 files exit with code 0

> npm run cli -- --target-string "Writing file 2" --leave-alive -- node ./examples/long-task

Server

Start a server on port 3000, and then hit it with curl.

> npm run cli -- --target-string "Server is listening" --leave-alive -- node ./examples/server && curl http://localhost:3000