diff --git a/.travis.yml b/.travis.yml index 42589a8..60a2bbe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,21 @@ 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 @@ -33,9 +23,6 @@ install: - 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: diff --git a/README.md b/README.md index ecd4f48..9826a38 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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` diff --git a/appveyor.yml b/appveyor.yml index cc8832e..c6d942b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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: diff --git a/examples/compileHelloWorld.js b/examples/compileHelloWorld.js index b8f0b9b..c5f1156 100644 --- a/examples/compileHelloWorld.js +++ b/examples/compileHelloWorld.js @@ -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); }); diff --git a/examples/elm-package.json b/examples/elm-package.json deleted file mode 100644 index 7905f63..0000000 --- a/examples/elm-package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": "1.0.0", - "summary": "helpful summary of your project, less than 80 characters", - "repository": "https://github.com/rtf/foo.git", - "license": "BSD3", - "source-directories": [ - "." - ], - "exposed-modules": [], - "dependencies": { - "elm-lang/core": "5.0.0 <= v < 6.0.0", - "elm-lang/html": "2.0.0 <= v < 3.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/examples/elm.json b/examples/elm.json new file mode 100644 index 0000000..a587ae1 --- /dev/null +++ b/examples/elm.json @@ -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": {} + } +} \ No newline at end of file diff --git a/index.js b/index.js index 4247d42..94d395d 100644 --- a/index.js +++ b/index.js @@ -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); @@ -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) { @@ -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."; } @@ -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); } } @@ -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"); @@ -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 []; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..0e05a9f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,415 @@ +{ + "name": "node-elm-compiler", + "version": "5.0.0-alpha1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "assertion-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.2.tgz", + "integrity": "sha1-E8pRXYYgbaC6xm6DTdOX2HWBCUw=", + "dev": true + }, + "browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", + "dev": true + }, + "chai": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz", + "integrity": "sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc=", + "dev": true, + "requires": { + "assertion-error": "^1.0.1", + "deep-eql": "^0.1.3", + "type-detect": "^1.0.0" + } + }, + "commander": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", + "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==", + "dev": true + }, + "cross-spawn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.0.tgz", + "integrity": "sha1-glR3SrR4a4xbPPTfumbOVjkywlI=", + "requires": { + "lru-cache": "^4.0.1", + "which": "^1.2.9" + }, + "dependencies": { + "lru-cache": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.0.1.tgz", + "integrity": "sha1-E0OVXtry432bnn7nJB4nxLn7cr4=", + "requires": { + "pseudomap": "^1.0.1", + "yallist": "^2.0.0" + }, + "dependencies": { + "pseudomap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", + "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" + }, + "yallist": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.0.0.tgz", + "integrity": "sha1-MGxUODXwnuGkyyO3vOmrNByRzdQ=" + } + } + }, + "which": { + "version": "1.2.10", + "resolved": "https://registry.npmjs.org/which/-/which-1.2.10.tgz", + "integrity": "sha1-kc2b0HUTIkEbZZtA8FSyHelXqy0=", + "requires": { + "isexe": "^1.1.1" + }, + "dependencies": { + "isexe": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-1.1.2.tgz", + "integrity": "sha1-NvPiLmB1CSD15yQaR2qMakInWtA=" + } + } + } + } + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-eql": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", + "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", + "dev": true, + "requires": { + "type-detect": "0.1.1" + }, + "dependencies": { + "type-detect": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-0.1.1.tgz", + "integrity": "sha1-C6XsKohWQORw6k6FBZcZANrFiCI=", + "dev": true + } + } + }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "find-elm-dependencies": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/find-elm-dependencies/-/find-elm-dependencies-2.0.0.tgz", + "integrity": "sha512-lnLilxwdS3U/CSPoMnfUL1u21MBNolv6NF54y4Yds7WxdRMrTBXrmugrcvIGvakWQ2anYuinmBSUR+jUQy+vpA==", + "requires": { + "firstline": "1.2.0", + "lodash": "4.17.10" + } + }, + "firstline": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/firstline/-/firstline-1.2.0.tgz", + "integrity": "sha1-yfSIbn9/vwr8EtcZQdzgaxkq6gU=" + }, + "glob": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz", + "integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.2", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "dependencies": { + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + } + }, + "growl": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", + "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==", + "dev": true + }, + "has-flag": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", + "dev": true + }, + "he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "dev": true + }, + "lodash": { + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", + "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "mocha": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.1.1.tgz", + "integrity": "sha512-kKKs/H1KrMMQIEsWNxGmb4/BGsmj0dkeyotEvbrAuQ01FcWRLssUNXCEUZk6SZtyJBi6EE7SL0zDDtItw1rGhw==", + "dev": true, + "requires": { + "browser-stdout": "1.3.1", + "commander": "2.11.0", + "debug": "3.1.0", + "diff": "3.5.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.2", + "growl": "1.10.3", + "he": "1.1.1", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "supports-color": "4.4.0" + }, + "dependencies": { + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "supports-color": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", + "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", + "dev": true, + "requires": { + "has-flag": "^2.0.0" + } + }, + "temp": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/temp/-/temp-0.8.3.tgz", + "integrity": "sha1-4Ma8TSa5AxJEEOT+2BEDAU38H1k=", + "requires": { + "os-tmpdir": "^1.0.0", + "rimraf": "~2.2.6" + }, + "dependencies": { + "os-tmpdir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.1.tgz", + "integrity": "sha1-6bQjoe2vR5iCVi6S7XHXdDoHG24=" + }, + "rimraf": { + "version": "2.2.8", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz", + "integrity": "sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI=" + } + } + }, + "type-detect": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-1.0.0.tgz", + "integrity": "sha1-diIXzAbbJY7EiQihKY6LlRIejqI=", + "dev": true + } + } +} diff --git a/package.json b/package.json index 2e75841..b696fe5 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "node-elm-compiler", - "version": "4.5.0", + "version": "5.0.0-alpha1", "description": "A Node.js interface to the Elm compiler binaries. Supports Elm version 0.17, 0.18", "main": "index.js", "scripts": { - "test": "mocha test/*.js" + "test": "rm -rf test/fixtures/elm-stuff; mocha test/*.js" }, "repository": { "type": "git", @@ -26,13 +26,12 @@ "homepage": "https://github.com/rtfeldman/node-elm-compiler", "dependencies": { "cross-spawn": "4.0.0", - "find-elm-dependencies": "1.0.2", + "find-elm-dependencies": "2.0.0", "lodash": "4.17.10", "temp": "^0.8.3" }, "devDependencies": { "chai": "3.5.0", - "chai-spies": "0.7.1", "glob": "7.1.1", "mocha": "5.1.1" } diff --git a/test/compile.js b/test/compile.js index eee4416..274a930 100644 --- a/test/compile.js +++ b/test/compile.js @@ -1,13 +1,10 @@ var chai = require("chai") -var spies = require("chai-spies"); var path = require("path"); var compiler = require(path.join(__dirname, "..")); var childProcess = require("child_process"); var _ = require("lodash"); var temp = require("temp"); -chai.use(spies); - var expect = chai.expect; var fixturesDir = path.join(__dirname, "fixtures"); @@ -20,47 +17,32 @@ describe("#compile", function() { // Use a timeout of 5 minutes because Travis on Linux can be SUPER slow. this.timeout(300000); - it("works with --yes", function (done) { - var opts = {yes: true, output: "/dev/null", verbose: true, cwd: fixturesDir}; - var compileProcess = compiler.compile(prependFixturesDir("Parent.elm"), opts); - - compileProcess.on("exit", function(exitCode) { - expect(exitCode, "Expected elm-make to have exit code 0").to.equal(0); - done(); - }); - }); - it("reports errors on bad source", function (done) { var opts = { - yes: true, verbose: true, cwd: fixturesDir }; var compileProcess = compiler.compile(prependFixturesDir("Bad.elm"), opts); compileProcess.on("exit", function(exitCode) { - var desc = "Expected elm-make to have exit code 1"; + var desc = "Expected elm make to have exit code 1"; expect(exitCode, desc).to.equal(1); done(); }); }); - it("invokes custom `emitWarning`", function (done) { + it("throws when given an unrecognized argument", function () { var opts = { foo: "bar", - emitWarning: chai.spy(), - yes: true, output: "/dev/null", verbose: true, cwd: fixturesDir }; - var compileProcess = compiler.compile(prependFixturesDir("Parent.elm"), opts); - compileProcess.on("exit", function(exitCode) { - var desc = "Expected emitWarning to have been called"; - expect(opts.emitWarning, desc).to.have.been.called(); - done(); - }); + expect(function() { + var compileProcess = compiler.compile(prependFixturesDir("Parent.elm"), opts); + + }).to.throw(); }); }); @@ -68,23 +50,8 @@ describe("#compileToString", function() { // Use an epic timeout because Travis on Linux can be SUPER slow. this.timeout(600000); - it("works with --yes", function () { - var opts = { - yes: true, - verbose: true, - cwd: fixturesDir - }; - var compilePromise = compiler.compileToString(prependFixturesDir("Parent.elm"), opts); - - return compilePromise.then(function(result) { - var desc = "Expected elm-make to return the result of the compilation"; - expect(result.toString(), desc).to.be.a('string'); - }); - }); - it("adds runtime options as arguments", function () { var opts = { - yes: true, verbose: true, cwd: fixturesDir, runtimeOptions: ["-A128M", "-H128M", "-n8m"] @@ -92,12 +59,11 @@ describe("#compileToString", function() { return expect(compiler ._prepareProcessArgs("a.elm", opts) - .join(" ")).to.equal("a.elm --yes +RTS -A128M -H128M -n8m -RTS"); + .join(" ")).to.equal("make a.elm +RTS -A128M -H128M -n8m -RTS"); }); it("reports errors on bad syntax", function () { var opts = { - yes: true, verbose: true, cwd: fixturesDir }; @@ -107,13 +73,12 @@ describe("#compileToString", function() { expect(err).to.be.an('error'); expect(String(err)) .to.contain("Compilation failed") - .and.contain("SYNTAX PROBLEM"); + .and.contain("PARSE ERROR"); }); }); it("reports type errors", function () { var opts = { - yes: true, verbose: true, cwd: fixturesDir }; @@ -127,26 +92,27 @@ describe("#compileToString", function() { }); }); - it("invokes custom `emitWarning`", function () { + it("Rejects the Promise when given an unrecognized argument like `yes`", function () { var opts = { foo: "bar", - emitWarning: chai.spy(), - yes: true, verbose: true, cwd: fixturesDir }; + var compilePromise = compiler.compileToString(prependFixturesDir("Parent.elm"), opts); - return compilePromise.then(function(err) { - var desc = "Expected emitWarning to have been called"; - expect(opts.emitWarning, desc).to.have.been.called(); + return new Promise(function(resolve, reject) { + return compilePromise.then(function() { + reject("Expected the compilation promise to be rejected due to the unrecognized compiler argument."); + }).catch(function() { + resolve(); + }); }); }); it("works when run multiple times", function () { var opts = { - yes: true, verbose: true, cwd: fixturesDir }; @@ -158,7 +124,7 @@ describe("#compileToString", function() { var compilePromise = compiler.compileToString(prependFixturesDir("Parent.elm"), opts) return compilePromise.then(function(result) { - var desc = "Expected elm-make to return the result of the compilation"; + var desc = "Expected elm make to return the result of the compilation"; expect(result.toString(), desc).to.be.a('string'); }); }; @@ -176,7 +142,6 @@ describe("#compileWorker", function() { it("works with BasicWorker.elm", function() { var opts = { - yes: true, verbose: true, cwd: fixturesDir }; @@ -187,7 +152,7 @@ describe("#compileWorker", function() { ); return compilePromise.then(function(app) { - app.ports.report.subscribe(function(str) { + app.ports.reportFromWorker.subscribe(function(str) { expect(str).to.equal("it's alive!"); }); }) diff --git a/test/compileSync.js b/test/compileSync.js index e81a584..04cbd29 100644 --- a/test/compileSync.js +++ b/test/compileSync.js @@ -14,38 +14,40 @@ describe("#compileSync", function() { // Use a timeout of 5 minutes because Travis on Linux can be SUPER slow. this.timeout(300000); - it("works with --yes", function () { - var opts = {yes: true, output: "/dev/null", verbose: true, cwd: fixturesDir}; - var compileProcess = compiler.compileSync(prependFixturesDir("Parent.elm"), opts); + it("succeeds on SimplestMain", function () { + var opts = { + verbose: true, + cwd: fixturesDir + }; + var compileProcess = compiler.compileSync(prependFixturesDir("SimplestMain.elm"), opts); - expect(compileProcess.status, "Expected elm-make to have exit code 0").to.equal(0); + var exitCode = compileProcess.status; + var desc = "Expected elm make to have exit code 0"; + expect(exitCode, desc).to.equal(0); }); it("reports errors on bad source", function () { var opts = { - yes: true, verbose: true, cwd: fixturesDir }; var compileProcess = compiler.compileSync(prependFixturesDir("Bad.elm"), opts); var exitCode = compileProcess.status; - var desc = "Expected elm-make to have exit code 1"; + var desc = "Expected elm make to have exit code 1"; expect(exitCode, desc).to.equal(1); }); - it("invokes custom `emitWarning`", function () { + it("throws when given an unrecognized argument like `yes`", function () { var opts = { - foo: "bar", - emitWarning: chai.spy(), yes: true, output: "/dev/null", verbose: true, cwd: fixturesDir }; - var compileProcess = compiler.compileSync(prependFixturesDir("Parent.elm"), opts); - var desc = "Expected emitWarning to have been called"; - expect(opts.emitWarning, desc).to.have.been.called(); + expect(function() { + var compileProcess = compiler.compileSync(prependFixturesDir("Parent.elm"), opts); + }).to.throw(); }); }); diff --git a/test/compileToStringSync.js b/test/compileToStringSync.js index 1a8b007..5e075cb 100644 --- a/test/compileToStringSync.js +++ b/test/compileToStringSync.js @@ -1,5 +1,4 @@ var chai = require("chai"); -// var spies = require("chia-spies"); var path = require("path"); var compiler = require(path.join(__dirname, "..")); @@ -13,20 +12,18 @@ function prependFixturesDir(filename) { describe("#compileToStringSync", function() { it('returns string JS output of the given elm file', function() { - var opts = {yes: true, verbose: true, cwd: fixturesDir}; + var opts = {verbose: true, cwd: fixturesDir}; var result = compiler.compileToStringSync(prependFixturesDir("Parent.elm"), opts); - expect(result).to.include("globalElm[publicModule] = Elm[publicModule];"); - expect(result).to.include("Elm['Parent'] = Elm['Parent'] || {}"); + expect(result).to.include("_Platform_export"); }); it('returns html output given "html" output option', function() { - var opts = {yes: true, verbose: true, cwd: fixturesDir, output: '.html'}; + var opts = {verbose: true, cwd: fixturesDir, output: '.html'}; var result = compiler.compileToStringSync(prependFixturesDir("Parent.elm"), opts); expect(result).to.include(''); expect(result).to.include('Parent'); - expect(result).to.include("globalElm[publicModule] = Elm[publicModule];"); - expect(result).to.include("Elm['Parent'] = Elm['Parent'] || {}"); + expect(result).to.include("_Platform_export"); }); }); diff --git a/test/fixtures/BasicWorker.elm b/test/fixtures/BasicWorker.elm index ca97691..e915ea2 100644 --- a/test/fixtures/BasicWorker.elm +++ b/test/fixtures/BasicWorker.elm @@ -1,16 +1,15 @@ port module BasicWorker exposing (..) -import Html import Platform -main : Program Never String msg +main : Program () String msg main = - Platform.program - { init = ( "", report "it's alive!" ) + Platform.worker + { init = \_ -> ( "", reportFromWorker "it's alive!" ) , update = \_ _ -> ( "", Cmd.none ) - , subscriptions = (\_ -> Sub.none) + , subscriptions = \_ -> Sub.none } -port report : String -> Cmd a +port reportFromWorker : String -> Cmd a diff --git a/test/fixtures/Native/Child.js b/test/fixtures/Native/Child.js deleted file mode 100644 index b9ca6f3..0000000 --- a/test/fixtures/Native/Child.js +++ /dev/null @@ -1,3 +0,0 @@ -function doNativeStuff() { - console.log("I'm not elm code!") -} diff --git a/test/fixtures/Parent.elm b/test/fixtures/Parent.elm index 1b20aa2..09082d5 100644 --- a/test/fixtures/Parent.elm +++ b/test/fixtures/Parent.elm @@ -6,7 +6,6 @@ import Test.ChildA -- This is a comment in between two import statements. import Test.ChildB exposing (..) -import Native.Child exposing (..) import Html diff --git a/test/fixtures/ParentWithPort.elm b/test/fixtures/ParentWithPort.elm index b21cdf5..84a1e8c 100644 --- a/test/fixtures/ParentWithPort.elm +++ b/test/fixtures/ParentWithPort.elm @@ -6,7 +6,6 @@ import Test.ChildA -- This is a comment in between two import statements. import Test.ChildB exposing (..) -import Native.Child exposing (..) import Html diff --git a/test/fixtures/ParentWithUnindentedMultilineComment.elm b/test/fixtures/ParentWithUnindentedMultilineComment.elm index 8fd819c..425f5b9 100644 --- a/test/fixtures/ParentWithUnindentedMultilineComment.elm +++ b/test/fixtures/ParentWithUnindentedMultilineComment.elm @@ -9,7 +9,6 @@ import Test.ChildA import Test.ChildB exposing (..) {- this comment will end before an import -} -import Native.Child exposing (..) import Html diff --git a/test/fixtures/Test/Sample/NestedChild.elm b/test/fixtures/Test/Sample/NestedChild.elm index ec27820..bdd8f3c 100644 --- a/test/fixtures/Test/Sample/NestedChild.elm +++ b/test/fixtures/Test/Sample/NestedChild.elm @@ -1,7 +1,6 @@ module Test.Sample.NestedChild exposing (..) import Test.ChildB -import Native.Child exposing (..) main = diff --git a/test/fixtures/elm-package.json b/test/fixtures/elm-package.json deleted file mode 100644 index e181c3d..0000000 --- a/test/fixtures/elm-package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "version": "1.0.0", - "summary": "helpful summary of your project, less than 80 characters", - "repository": "https://github.com/foo/bar.git", - "license": "BSD3", - "source-directories": [ - "." - ], - "native-modules": true, - "exposed-modules": [], - "dependencies": { - "elm-lang/core": "5.0.0 <= v < 6.0.0", - "elm-lang/html": "2.0.0 <= v < 3.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/test/fixtures/elm.json b/test/fixtures/elm.json new file mode 100644 index 0000000..ce36fa3 --- /dev/null +++ b/test/fixtures/elm.json @@ -0,0 +1,30 @@ +{ + "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": {} + }, + "do-not-edit-this-by-hand": { + "transitive-dependencies": { + "elm-lang/json": "1.0.0", + "elm-lang/virtual-dom": "3.0.0" + } + } +} \ No newline at end of file diff --git a/worker.js b/worker.js index 78c54b8..3684e65 100644 --- a/worker.js +++ b/worker.js @@ -1,11 +1,9 @@ -var fs = require("fs"); var temp = require("temp").track(); var path = require("path"); var jsEmitterFilename = "emitter.js"; var KNOWN_MODULES = [ - "Native", "fullscreen", "embed", "worker", @@ -42,7 +40,7 @@ module.exports = function(compile) { .then(function (tmpDirPath) { var dest = path.join(tmpDirPath, jsEmitterFilename); - return compileEmitter(compile, modulePath, {output: dest, yes: true}) + return compileEmitter(compile, modulePath, {output: dest}) .then(function() { return runWorker(dest, moduleName, workerArgs) }); }) .then(function(worker) { @@ -54,7 +52,7 @@ module.exports = function(compile) { throw Error(err); }); }; -} +}; function createTmpDir() { return new Promise(function (resolve, reject) { @@ -100,13 +98,13 @@ function noPortsMessage(moduleName){ function runWorker(jsFilename, moduleName, workerArgs) { return new Promise(function (resolve, reject) { - var Elm = require(jsFilename); + var Elm = require(jsFilename).Elm; if (!(moduleName in Elm)){ return reject(missingEntryModuleMessage(moduleName, Elm)); } - var worker = Elm[moduleName].worker(workerArgs); + var worker = Elm[moduleName].init(workerArgs); if (Object.keys(worker.ports).length === 0){ return reject(noPortsMessage(moduleName, portName));