purescript-runner

0.1.1 • Public • Published

purescript-runner

This is a small tool that allows the execution of Purescript files directly from Node.js

Dependencies

  • NodeJS
  • Purescript compiler (avaliable in the path)

Installation

npm install purescript-runner

Examples

Simple case (no external dependencies)

Assuming the following Main.purs file

module Main where
  import Debug.Trace

  main = do
    print "Hello world"

When executed in Node.js, the following code will run the Purescript file

var runner = require("purescript-runner");

runner.run("Main.purs", function (err, PS) {
  if(err) {
    console.error("Purescript compilation failed:", err);
    return;
  }

  PS.Main.main();
});

The PS object returned by runner will contain the whole environment generated by Purescript from given files. In addition, the main-module option and dead-code removal module of Purescript compiler are avaliable through additional options object.

To fire and forget the Main.main module of Purescript application, the code above can be shortened to:

var runner = require("purescript-runner");

runner.run("Main.purs", {
    modules: ["Main"],
    main: "Main"
});

Loading scripts with dependencies

Runner accept a single-glob or list of globs as its parameter, allowing to load multiple files:

var runner = require("purescript-runner");

runner.run(["src/**/*.purs", "Main.purs"], ...);

In addition, by default bower_components/**/src/**/*.purs is evaluated and matching files are passed to the Purescript compiler.

Usage

runner.run

runner.run(files, [options, callback])

Compiles all the files and returns the resulting PS object as a second parameter of callback.

  • files - string or array of strings conating path to the Purescript files to be copiled,
  • options - options object, see options section for details,
  • callback - function evalated after compilation. The following parameters are passed to the callback:
    • error - null or error description, if an error occured
    • PS - top-level Purescript object conating all the compiled modules. See here for details

options

Object, with following properties:

  • main - optional main module passed to the Purescript compiler. This module is expected to export main function that will be executed as the program entry point,
  • modules - list of names of the modules which code must be included in the output. When this option is passed it enables Purescript compiler dead-code detection. Modules not mentioned will only export symbols that are necessary for required modules to execute. Passing this options drastically decreses size of compilers output
  • externs - externs passed to the Purescript compiler. See psc --help for details
  • verbose - enables Purescript compiler verbose error reporting. See psc --help for details.
  • noDefaultPaths - stops runner from automatically adding all the files matching ./bower_components/**/src/**/*.purs
  • pscCmd - path to the psc executable. By default the exacutable is assumed to be reachable from the PATH
  • logger - object with the following methods
    • log: function(string) - logs Purescript compiler standard output
    • error: function(string) - logs Purescript compiler error output

Readme

Keywords

none

Package Sidebar

Install

npm i purescript-runner

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • maciejm