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

download-or-build-purescript

v0.3.4

Published

First try to download a prebuilt PureScript binary, then build from a source if the prebuilt one is unavailable

Downloads

380

Readme

download-or-build-purescript

npm version Build Status Coverage Status

First try to download a prebuilt PureScript binary, then build from a source if the prebuilt one is unavailable

const {readdir} = require('fs').promise;
const {execFile} = require('child_process');
const downloadOrBuildPurescript = require('download-or-build-purescript');

downloadOrBuildPurescript({version: '0.12.3'}).subscribe({
  next(event) {
    if (event.id === 'head:complete') {
      console.log('✓ Prebuilt binary exists.');
      return;
    }

    if (event.id === 'download-binary:complete') {
      console.log('✓ Binary downloaded.');
      return;
    }

    if (event.id === 'check-binary:complete') {
      console.log('✓ Binary works correctly.');
      return;
    }
  }
  async complete() {
    await readdirSync('.').includes('purs'); //=> true
    execFile('./purs', ['--version'], (err, stdout) => {
      stdout.toString(); //=> '0.12.3\n'
    });
  }
});

Installation

Use npm.

npm install download-or-build-purescript

API

const downloadOrBuildPurescript = require('download-or-build-purescript');

downloadOrBuildPurescript([options])

options: Object
Return: Observable (Kevin Smith's implementation)

When the Observable is subscribed,

  1. it downloads a prebuilt PureScript binary from the PureScript release page
  2. if a prebuilt binary is not available, it downloads the PureScript source code and builds a binary form it
  3. it puts the binary at the current working directory

while successively sending events to its Observer.

Events

Each event object has id property with one of these values:

head ------------ x -+- check-stack ----- x -+
 |                   |   |                   |
 o                   |   o                   |
 |                   |   |                   |
download-binary - x -+  download-source - x -+
 |                   |   |                   |
 o                   |   o                   |
 |                   |   |                   |
check-binary ---- x -+  setup ----------- x -+
 |                       |                   |
 |                       o                   |
 |                       |                   |
 |                      build ----------- x -+
 |                       |                   |
 o                       o                   |
 |                       |                   |
*****************       *****************   ^^^^^^^
 Downloaded a            Built a binary      Error
 prebuilt binary         from the source    ^^^^^^^
*****************       *****************
head

Fires when it starts to check if a prebuilt binary is provided for the current platform.

{
  id: 'head'
}
head:fail

Fires when it cannot start downloading the binary, for example no prebuilt ones are provided for the current platform.

{
  id: 'head:fail',
  error: <Error>
}
head:complete

Fires when it confirms that a prebuilt binary is provided for the current platform.

{
  id: 'head:complete'
}
download-binary

Fires many times while downloading and extracting the prebuilt binary.

entry and response properties are derived from dl-tar.

{
  id: 'download-binary',
  entry: <ReadEntry>,
  response: {
    bytes: <number>,
    headers: <Object>,
    url: <string>
  }
}
download-binary:fail

Fires when it fails to download the binary somehow.

{
  id: 'download-binary:fail',
  error: <Error>
}
download-binary:complete

Fires when the prebuilt binary is successfully downloaded.

{
  id: 'download-binary:complete'
}
check-binary

Fires when it starts to verify the downloaded prebuilt binary works correctly, by running purs --version.

{
  id: 'check-binary'
}
check-binary:fail

Fires when the downloaded binary doesn't work correctly.

{
  id: 'check-binary:fail',
  error: <Error>
}
check-binary:complete

Fires when it verifies the downloaded binary works correctly.

{
  id: 'check-binary:complete'
}
check-stack

Fires after one of these events: head:fail download-binary:fail check-binary:fail.

path property is the absolute path of the stack command, and version property is its version.

{
  id: 'check-stack',
  path: <string>,
  version: <string>
}
check-stack:complete

Fires after making sure the stack command is installed in your $PATH.

{
  id: 'check-binary:complete'
}
download-source

Fires many times while downloading and extracting the PureScript source code.

entry and response properties are derived from dl-tar.

{
  id: 'download-source',
  entry: <ReadEntry>,
  response: {
    bytes: <number>,
    headers: <Object>,
    url: <string>
  }
}
download-source:complete

Fires when the source code is successfully downloaded.

{
  id: 'download-source'
}
setup setup:complete build build:complete

Inherited from build-purescript.

Errors

Every error passed to the Observer has id property that indicates which step the error occurred at.

// When the `stack` command is not installed
downloadOrBuildPureScript().subscribe({
  error(err) {
    err.message; //=> '`stack` command is not found in your PATH ...'
    err.id; //=> 'check-stack'
  }
});

// When your machine lose the internet connection while downloading the source
downloadOrBuildPureScript().subscribe({
  error(err) {
    err.message; //=> 'socket hang up'
    err.id; //=> 'download-source'
  }
});

Options

Options are directly passed to download-purescript and build-purescript. Note that,

  • filter option is not supported.
  • revision option is not supported. Use version option instead.

Additionally, you can use the following:

rename

Type: Function
Default: v => v

Receives the original binary name (purs on POSIX, purs.exe on Windows) and modifies the binary name to its return value.

const {extname} = require('path');

downloadOrBuildPurescript('./dest', {
  rename(originalName) {
    const ext = extname(originalName); //=> '' on POSIX, '.exe' on Windows

    return `foo${ext}`;
  }
}).subscribe({
  complete() {
    // Creates a binary to './dest/foo' on POSIX, './dest/foo.exe' on Windows
  }
});

License

ISC License © 2017 - 2019 Shinnosuke Watanabe