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

install-purescript

v0.8.0-0

Published

Install PureScript to a given directory

Downloads

173

Readme

install-purescript

npm version Build Status codecov

Install PureScript to a given directory

cconst {execFile} = require('child_process');
const installPurescript = require('install-purescript');

installPurescript({version: '0.13.0'}).subscribe({
  next(event) {
    if (event.id === 'search-cache' && event.found) {
      console.log('✓ Found a cache.');
      return;
    }

    if (event.id === 'restore-cache:complete') {
      console.log('✓ Cached binary restored.');
      return;
    }

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

Installation

Use npm.

npm install install-purescript

API

const installPurescript = require('install-purescript');

installPurescript([options])

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

When the Observable is subscribed,

  1. it searches the standard cache directory for an already cached PureScript binary, and restores the cache if available
  2. if a cached binary is not available, it downloads a prebuilt binary from the PureScript release page
  3. if a prebuilt binary is not available, it downloads the PureScript source code and builds a binary form it
  4. Cache the downloaded or built binary to the npm cache directory

while successively sending events to its Observer.

Events

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

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

Fires when it checks if a tgz archive of the required PureScript binary exists in the cache directory.

{
  id: 'search-cache',
  path: <string>, // path to the cache file
  found: <boolean> // whether a cache is found or not
}
restore-cache

Fires when it starts to extract a binary from the cached tgz archive.

{
  id: 'restore-cache'
}
restore-cache:fail

Fires when it fails to restore the binary from cache.

{
  id: 'restore-cache:fail',
  error: <Error>
}
restore-cache:complete

Fires when the cached binary is successfully restored.

{
  id: 'restore-cache:complete'
}
check-binary

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

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

Fires when the cached or downloaded binary doesn't work correctly.

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

Fires when it verifies the cached or downloaded binary works correctly.

{
  id: 'check-binary:complete'
}
head head:fail head:complete download-binary download-binary:fail download-binary:complete check-stack check-stack:complete download-source download-source:complete

Inherited from download-or-build-purescript.

setup setup:complete build build:complete

Inherited from build-purescript.

write-cache

Fires when it starts to create a cache. The cache is compressed with Brotli.

{
  id: 'write-cache',
  originalSize: <integer> // the size of the binary before compression in bytes
}
write-cache:fail

Fires when it fails to create the cache.

{
  id: 'write-cache:fail',
  error: <Error>
}
write-cache:complete

Fires when the cache is successfully created.

{
  id: 'write-cache:complete'
}

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
installPurescript('.').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
installPurescript('.').subscribe({
  error(err) {
    err.message; //=> 'socket hang up'
    err.id; //=> 'download-source'
  }
});

Options

Options are directly passed to download-or-build-purescript.

Additionally, you can use the following:

forceReinstall

Type: boolean
Default: false

Force reinstalling a binary even if an appropriate cache already exists.

Related projects

License

ISC License © 2017 - 2019 Watanabe Shinnosuke