Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for 0.19 #72

Merged
merged 35 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
783bdbb
The binary is now `elm`, not `elm-make`.
Apr 15, 2018
143fc9c
:skull: --yes
Apr 15, 2018
149d60d
Blow up if we get an unknown option.
Apr 15, 2018
6a9f3b0
elm-pacakge.json -> elm.json
Apr 15, 2018
98a9808
Don't print the whole string on the example.
Apr 15, 2018
76acd58
:skull: Native
Apr 15, 2018
fbb37d4
Throw instead of warning.
Apr 15, 2018
f4a1290
Give a custom error for passing the `yes` opt.
Apr 15, 2018
ef5c6f2
Update fixture expectations for 0.19 output.
Apr 15, 2018
1c0c4d5
:skull: Unused chai-spies dependency
Apr 15, 2018
7867ee6
Rename report port to reportFromWorker
Apr 15, 2018
897fd04
Update changelog.
Apr 15, 2018
080c74f
Update test for new compiler error.
Apr 27, 2018
0820ff6
Update worker for 0.19
Apr 27, 2018
262f12b
Fix worker port name.
Apr 27, 2018
bc8b626
Bump to 5.0.0-alpha1
Apr 27, 2018
169a5dd
Support Elm 0.19's --optimize flag
Punie Aug 23, 2018
cad36b5
Update Changelog
Aug 24, 2018
7449d9d
Upgrade find-elm-dependencies to 1.0.3
Aug 25, 2018
b1cb2f9
Upgraded the example to use 0.19
halfzebra Aug 26, 2018
636dd45
Remove unused dependencies, added missing semicolons.
halfzebra Aug 26, 2018
c328738
Fix the tests.
halfzebra Aug 26, 2018
c589ace
Upgrade Travis CI config to run 0.19
halfzebra Aug 26, 2018
2b75716
Added npm install to the install script on Travis CI
halfzebra Aug 26, 2018
aa58cbe
Use 0.19 on th appveyor
halfzebra Aug 26, 2018
06632eb
Merge pull request #73 from halfzebra/0.19-examples
Aug 27, 2018
298a744
Merge pull request #74 from halfzebra/0.19-tests
Aug 27, 2018
64224a8
Merge branch 'master' into 0.19
Aug 27, 2018
92681a6
Upgrade to find-elm-dependencies 2.0.0
Aug 28, 2018
280a595
Add test for compileSync succeeding
Aug 28, 2018
042a9b6
Wipe fixtures/elm-stuff before running tests.
Aug 28, 2018
b5816d5
Have Travis run on more node versions
Aug 28, 2018
e0f6d44
Have Travis clear out ~/.elm before running
Aug 28, 2018
a11ea4c
Update README
Aug 28, 2018
665e6d7
Update Appveyor
Aug 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
sudo: false

cache:
directories:
- test/elm-stuff/build-artifacts
- sysconfcpus

os:
- linux
- osx

env:
matrix:
- ELM_VERSION=0.18.0 TARGET_NODE_VERSION=node
- ELM_VERSION=0.19.0-bugfix2 TARGET_NODE_VERSION=4.0
- ELM_VERSION=0.19.0-bugfix2 TARGET_NODE_VERSION=6.0
- ELM_VERSION=0.19.0-bugfix2 TARGET_NODE_VERSION=8.0
- ELM_VERSION=0.19.0-bugfix2 TARGET_NODE_VERSION=node

before_install:
- rm -rf ~/.elm
- if [ ${TRAVIS_OS_NAME} == "osx" ];
then brew update; brew install nvm; mkdir ~/.nvm; export NVM_DIR=~/.nvm; source $(brew --prefix nvm)/nvm.sh;
fi
- | # epic build time improvement - see https://github.com/elm-lang/elm-compiler/issues/1473#issuecomment-245704142
if [ ! -d sysconfcpus/bin ];
then
git clone https://github.com/obmarg/libsysconfcpus.git;
cd libsysconfcpus;
./configure --prefix=$TRAVIS_BUILD_DIR/sysconfcpus;
make && make install;
cd ..;
fi

install:
- nvm install $TARGET_NODE_VERSION
- nvm use $TARGET_NODE_VERSION
- node --version
- npm --version
- npm install -g elm@$ELM_VERSION
- mv $(npm config get prefix)/bin/elm-make $(npm config get prefix)/bin/elm-make-old
- printf "#\041/bin/bash\n\necho \"Running elm-make with sysconfcpus -n 2\"\n\n$TRAVIS_BUILD_DIR/sysconfcpus/bin/sysconfcpus -n 2 elm-make-old \"\$@\"" > $(npm config get prefix)/bin/elm-make
- chmod +x $(npm config get prefix)/bin/elm-make
- npm install

script:
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# node-elm-compiler [![Version](https://img.shields.io/npm/v/node-elm-compiler.svg)](https://www.npmjs.com/package/node-elm-compiler) [![Travis build Status](https://travis-ci.org/rtfeldman/node-elm-compiler.svg?branch=master)](http://travis-ci.org/rtfeldman/node-elm-compiler) [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/xv83jcomgb81i1iu/branch/master?svg=true)](https://ci.appveyor.com/project/rtfeldman/node-elm-compiler/branch/master)

Wraps [Elm](https://elm-lang.org) and exposes a [Node](https://nodejs.org) API to compile Elm sources.

Supports Elm version 0.17, 0.18
Wraps [Elm](https://elm-lang.org) and exposes a [Node](https://nodejs.org) API to compile Elm 0.19 sources.

# Example

Expand All @@ -14,6 +12,10 @@ $ node compileHelloWorld.js

# Releases

## 5.0.0

Add 0.19 support. Remove `yes` option. Add `optimize` option. Throw exceptions instead of emitting warnings or using process.exit.

## 4.5.0

Add `runtimeOptions`
Expand Down
5 changes: 3 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
environment:
ELM_VERSION: "0.18.0"
ELM_VERSION: "0.19.0-bugfix2"
matrix:
- nodejs_version: "5.0"
- nodejs_version: "8.0"
- nodejs_version: "6.0"
- nodejs_version: "4.0"

platform:
Expand Down
8 changes: 4 additions & 4 deletions examples/compileHelloWorld.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ compile(["./HelloWorld.elm"], {
});


compileToString(["./HelloWorld.elm"], { yes: true }).then(function(data){
console.log("Text", data.toString());
compileToString(["./HelloWorld.elm"], {}).then(function(data){
console.log("compileToString produced a string with this length:", data.toString().length);
});

compileToString(["./HelloWorld.elm"], { yes: true, output: "index.html" }).then(function(data){
console.log("Text", data.toString());
compileToString(["./HelloWorld.elm"], { output: "index.html" }).then(function(data){
console.log("compileToString --output index.html produced a string with this length:", data.toString().length);
});
15 changes: 0 additions & 15 deletions examples/elm-package.json

This file was deleted.

24 changes: 24 additions & 0 deletions examples/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "application",
"source-directories": [
"."
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.0",
"elm/core": "1.0.0",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
88 changes: 43 additions & 45 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@

var spawn = require("cross-spawn");
var _ = require("lodash");
var compilerBinaryName = "elm-make";
var elmBinaryName = "elm";
var fs = require("fs");
var path = require("path");
var temp = require("temp").track();
var findAllDependencies = require("find-elm-dependencies").findAllDependencies;

var defaultOptions = {
emitWarning: console.warn,
spawn: spawn,
cwd: undefined,
pathToMake: undefined,
yes: undefined,
pathToElm: undefined,
help: undefined,
output: undefined,
report: undefined,
warn: undefined,
debug: undefined,
verbose: false,
processOpts: undefined,
docs: undefined,
optimize: undefined,
};

var supportedOptions = _.keys(defaultOptions);
Expand All @@ -40,9 +37,9 @@ function prepareOptions(options, spawnFn) {

function prepareProcessArgs(sources, options) {
var preparedSources = prepareSources(sources);
var compilerArgs = compilerArgsFromOptions(options);

var compilerArgs = compilerArgsFromOptions(options, options.emitWarning);
return preparedSources ? preparedSources.concat(compilerArgs) : compilerArgs;
return ["make"].concat(preparedSources ? preparedSources.concat(compilerArgs) : compilerArgs);
}

function prepareProcessOpts(options) {
Expand All @@ -51,7 +48,7 @@ function prepareProcessOpts(options) {

}

function runCompiler(sources, options, pathToMake) {
function runCompiler(sources, options, pathToElm) {
if (typeof options.spawn !== "function") {
throw "options.spawn was a(n) " + (typeof options.spawn) + " instead of a function.";
}
Expand All @@ -60,48 +57,50 @@ function runCompiler(sources, options, pathToMake) {
var processOpts = prepareProcessOpts(options);

if (options.verbose) {
console.log(["Running", pathToMake].concat(processArgs || []).join(" "));
console.log(["Running", pathToElm].concat(processArgs).join(" "));
}

return options.spawn(pathToMake, processArgs, processOpts);
return options.spawn(pathToElm, processArgs, processOpts);
}

function handleCompilerError(err, pathToMake) {
function compilerErrorToString(err, pathToElm) {
if ((typeof err === "object") && (typeof err.code === "string")) {
handleError(pathToMake, err);
switch (err.code) {
case "ENOENT":
return ("Could not find Elm compiler \"" + pathToElm + "\". Is it installed?")

case "EACCES":
return ("Elm compiler \"" + pathToElm + "\" did not have permission to run. Do you need to give it executable permissions?");

default:
return ("Error attempting to run Elm compiler \"" + pathToElm + "\":\n" + err);
}
} else {
console.error("Exception thrown when attempting to run Elm compiler " + JSON.stringify(pathToMake) + ":\n");
return ("Exception thrown when attempting to run Elm compiler " + JSON.stringify(pathToElm) + ":\n");
}
throw err;

process.exit(1);
}

function compileSync(sources, options) {
var optionsWithDefaults = prepareOptions(options, options.spawn || spawn.sync);
var pathToMake = options.pathToMake || compilerBinaryName;
var pathToElm = options.pathToElm || elmBinaryName;

try {
return runCompiler(sources, optionsWithDefaults, pathToMake);
return runCompiler(sources, optionsWithDefaults, pathToElm);
} catch (err) {
handleCompilerError(err, pathToMake);
throw compilerErrorToString(err, pathToElm);
}
}

function compile(sources, options) {
var optionsWithDefaults = prepareOptions(options, options.spawn || spawn);
var pathToMake = options.pathToMake || compilerBinaryName;
var pathToElm = options.pathToElm || elmBinaryName;


try {
return runCompiler(sources, optionsWithDefaults, pathToMake)
.on('error', function(err) {
handleError(pathToMake, err);

process.exit(1);
});
return runCompiler(sources, optionsWithDefaults, pathToElm)
.on('error', function(err) { throw(err); });
} catch (err) {
handleCompilerError(err, pathToMake);
throw compilerErrorToString(err, pathToElm);
}
}

Expand All @@ -124,7 +123,13 @@ function compileToString(sources, options){
options.output = info.path;
options.processOpts = { stdio: 'pipe' }

var compiler = compile(sources, options);
var compiler;

try {
compiler = compile(sources, options);
} catch(compileError) {
return reject(compileError);
}

compiler.stdout.setEncoding("utf8");
compiler.stderr.setEncoding("utf8");
Expand Down Expand Up @@ -164,33 +169,26 @@ function compileToStringSync(sources, options) {
return fs.readFileSync(file.path, {encoding: "utf8"});
}

function handleError(pathToMake, err) {
if (err.code === "ENOENT") {
console.error("Could not find Elm compiler \"" + pathToMake + "\". Is it installed?")
} else if (err.code === "EACCES") {
console.error("Elm compiler \"" + pathToMake + "\" did not have permission to run. Do you need to give it executable permissions?");
} else {
console.error("Error attempting to run Elm compiler \"" + pathToMake + "\":\n" + err);
}
}

// Converts an object of key/value pairs to an array of arguments suitable
// to be passed to child_process.spawn for elm-make.
function compilerArgsFromOptions(options, emitWarning) {
function compilerArgsFromOptions(options) {
return _.flatten(_.map(options, function(value, opt) {
if (value) {
switch(opt) {
case "yes": return ["--yes"];
case "help": return ["--help"];
case "output": return ["--output", value];
case "report": return ["--report", value];
case "warn": return ["--warn"];
case "debug": return ["--debug"];
case "docs": return ["--docs", value]
case "runtimeOptions": return [].concat(["+RTS"], value ,["-RTS"])
case "docs": return ["--docs", value];
case "optimize": return ["--optimize"];
case "runtimeOptions": return [].concat(["+RTS"], value ,["-RTS"]);
default:
if (supportedOptions.indexOf(opt) === -1) {
emitWarning('Unknown Elm compiler option: ' + opt);
if (opt === "yes") {
throw new Error('node-elm-compiler received the `yes` option, but that was removed in Elm 0.19. Try re-running without passing the `yes` option.');
} else {
throw new Error('node-elm-compiler was given an unrecognized Elm compiler option: ' + opt);
}
}

return [];
Expand Down
Loading