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-spawned-promise

v0.1.1

Published

Run git command with child_process.spawn

Downloads

6

Readme

git-spawned-promise

Build Status Build Status (win) Coverage bitHound Overall Score

Promisify a git child process, settling once the process exit and its stdio streams and transformers close.

Usage

Operations can ignore stdout (run(...cmd) method), can return it (get(...cmd)method) or can split it while transforming each element (array(...cmd, {sep, map})).

In any case, they capture stderr and reject errors when the exit codes are not zero, which will including sdterr in their messages and as a property:

const gitSpawnedPromise = require('../');

async function init(path = '.') {
  const git = gitPromise();

  // `run()`` ignores stdout.
  await git.run('init', path);
  await git.run('commit', '--allow-empty', '--message', 'chore: first commit');
  await git.run('commit', '--allow-empty', '--message', 'feat: first feature');
  await git.run('commit', '--allow-empty', '--message', 'fix: first fix');
  await git.run('commit', '--allow-empty', '--message', 'feat: second feature');

  const log = ['log', '--format="%s"', '--no-merges', '--grep', 'feat', 'HEAD'];
  const map = msg => msg.slice(5).trim();

  const [hash, feats] = await Promise.all([
    // `get()` resolves with stdout
    git.get('parse-rev', 'HEAD'),

    // `array` splits stdout stream and pipe transform stream.
    git.array(...log, {map, sep: '\n'})
  ]);

  console.log(`Status up to ${hash.slice(0, 7)}...`);
  console.log(feats.map(title => `  ${title}`).join('\n'));
}

// stderr available (when the error is a git error).
init(repo)
  .catch(err => console.log(`${err.stderr} (${err.code})`));

API

  • gitSpawnedPromise: function({gitDir: ?string}): GitClient

    Bound a GitClient to a local repository.

  • GitClient: function(cmd: string[], ?options: ClientOption): Promise<any,Error>

    Run the git command and settle once the git child process exit and the stdout/stderr pipe closes, or when either fail.

  • ClientOption: {ignore: ?boolean, sep: ?string, map: mapper[]}

    • ignore: ignore stdout when set to true (false by default).
    • sep: separator to split the stream (default to \n if a mapper is provided).
    • map: when splitting a stream, apply each element and replace the returned value. If the value is a promise it will resolve it.

    if sep or map are set, the gitCLient Promise will resolve to an Array.

  • Mapper: function(item: any): any

    A handler for a stream.Transformer for stdout. Unlike regular handler async values are passed via a Promise instead of a callback function, and returning null (or Promise<null>) does not close the stream; the Transformer would just skip the value.

    If the mapper throws or reject, the GitClient returned Promise will reject with that error.

  • GitClient.run: function(...cmd: string[]): Promise<void,GitError>

    gitClient.run(...cmd) is equivalent to gitClient(cmd, {capture: true}).

  • GitClient.get: function(...cmd: string[]): Promise<string,GitError>

    gitClient.get(...cmd) is equivalent to gitClient(cmd).

  • GitClient.array: function(...cmd: string[], ?options: ClientOption): Promise<any[],Error>

    gitClient.array(...cmd) is equivalent to gitClient(cmd, {sep: '\n', map: someMapperOrMappperArray}).

Installation

using npm:

npm install git-spawned-promise

License

MIT License

Copyright (c) 2017 Damien Lebrun