[
  {
    "path": ".gitignore",
    "content": "# Logs\nlogs\n*.log\n\n# Runtime data\npids\n*.pid\n*.seed\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# Compiled binary addons (http://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directory\n# Commenting this out is preferred by some people, see\n# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-\nnode_modules\n\n# Users Environment Variables\n.lock-wscript\n\n# Elm stuff\nelm-stuff\n\ntest/fixtures/index.html\n\n# Compiled files\ndist"
  },
  {
    "path": ".npmignore",
    "content": "# Logs\nlogs\n*.log\n\n# Runtime data\npids\n*.pid\n*.seed\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# node-waf configuration\n.lock-wscript\n\nbuild\n\n# Dependency directory\n# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git\nnode_modules\nelm-stuff\ntmp\n\n# Specific to .npmignore\n.travis.yml\nREADME.md\n\ntests\ntest\n\n# Do not distribute TypeScript and source files\nsrc\ntsconfig.json"
  },
  {
    "path": ".travis.yml",
    "content": "sudo: false\n\nlanguage: node_js\nnode_js:\n  - \"8\"\n  - \"10\"\n  - \"12\"\n\nos:\n  - linux\n  - osx\n\nenv:\n  matrix:\n    - ELM_VERSION=0.19.0-no-deps\n\nbefore_install:\n  - rm -rf ~/.elm\n\ninstall:\n  - node --version\n  - npm --version\n  - npm install -g elm@$ELM_VERSION\n  - npm install\n\nscript:\n  - npm test\n"
  },
  {
    "path": "LICENSE",
    "content": "Copyright (c) 2015, Richard Feldman\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this\n  list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice,\n  this list of conditions and the following disclaimer in the documentation\n  and/or other materials provided with the distribution.\n\n* Neither the name of elm-stylesheets nor the names of its\n  contributors may be used to endorse or promote products derived from\n  this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n"
  },
  {
    "path": "README.md",
    "content": "# 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)\n\nWraps [Elm](https://elm-lang.org) and exposes a [Node](https://nodejs.org) API to compile Elm 0.19 sources.\n\n# Example\n\n```bash\n$ npm install\n$ cd examples\n$ node compileHelloWorld.js\n```\n\n# Releases\n\n## 5.0.5\n\nUpgrade find-elm-dependencies and lodash dependencies to fix CVE-2020-8203 vulnerability.\n\n## 5.0.2\n\nUpgrade lodash dependency to fix security audit warning. ([#93](https://github.com/rtfeldman/node-elm-compiler/pull/93))\n\n## 5.0.1\n\nAdd helpful errors if you use the obsolete `warn` and `pathToMake` flags. ([#75](https://github.com/rtfeldman/node-elm-compiler/pull/75))\n\n## 5.0.0\n\nAdd 0.19 support. Remove `yes` option. Add `optimize` option. Throw exceptions instead of emitting warnings or using process.exit.\n\n## 4.5.0\n\nAdd `runtimeOptions`\n\n## 4.4.0\n\nAdd `compileToStringSync`\n\n## 4.3.1\n\nUpgrade `findAllDependencies` dependency to correctly report all dependencies within a multi-source-directory project.\n\n## 4.3.0\n\nAdd `compileSync` via @yormi\n\n## 4.2.1\n\nEpic perf improvements from @eeue56\n\n## 4.2.0\n\nAdd support for `--debug` flag.\n\n## 4.1.5\n\nClean up temporary directories more safely.\n\n## 4.1.4\n\n`findAllDependencies` now supports `port module` files.\n\n## 4.1.3\n\nUse utf-8 encoding for `compileToString`\n\n## 4.1.2\n\nSupport checking dependencies for modules with no module declaration.\n\n## 4.1.1\n\nFix bug in dependency searches beginning with a non-root `Main` module.\n\n## 4.1.0\n\nLog elm-make output in verbose mode.\n\n## 4.0.1\n\nFix missing `temp` dependency.\n\n## 4.0.0\n\nUse an `Error` object for result errors instead of a string.\n\n## 3.0.0\n\nPassing the `warn` option now passes `--warn` to `elm-make`, and `emitWarning` now controls warning logging.\n\n## 2.3.3\n\nFix bug where nonzero exit codes were not rejecting promises.\n\n## 2.3.2\n\nFix bug related to converting module dots to directories in nested dependency\nresolution.\n\n## 2.3.1\n\nMove `temp` dependency out of `devDependencies`\n\n## 2.3.0\n\nAdded #compileToString\n\n## 2.2.0\n\nAdded `cwd` to `options` and fixed a bug where Windows couldn't find `elm-make`.\n\n## 2.1.0\n\nAdded #findAllDependencies\n\n## 2.0.0\n\nNo longer searches `node_modules/.bin` for `elm-make` - now if you don't specify\na `pathToMake` option, only the one on PATH will be used as a fallback.\n\n## 1.0.0\n\nInitial release.\n"
  },
  {
    "path": "appveyor.yml",
    "content": "environment:\n  ELM_VERSION: \"0.19.0-bugfix6\"\n  matrix:\n  - nodejs_version: \"12.0\"\n  - nodejs_version: \"10.0\"\n  - nodejs_version: \"8.0\"\n\nplatform:\n  - x64\n\nmatrix:\n  fast_finish: true\n\ninstall:\n  - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:Platform\n  - node --version\n  - npm --version\n  - npm install\n  - npm install -g elm@%ELM_VERSION%\n\ntest_script:\n  - npm test\n\nbuild: off\n"
  },
  {
    "path": "examples/.gitignore",
    "content": "compiled-hello-world.js\n\n"
  },
  {
    "path": "examples/HelloWorld.elm",
    "content": "module Main exposing (..)\n\nimport Html exposing (Html, text)\n\n\nmain : Html msg\nmain =\n    Html.text \"Hello, World!\"\n"
  },
  {
    "path": "examples/compileHelloWorld.js",
    "content": "var compile = require(\"../index.js\").compile;\nvar compileToString = require(\"../index.js\").compileToString;\n\ncompile([\"./HelloWorld.elm\"], {\n  output: \"compiled-hello-world.js\"\n}).on('close', function(exitCode) {\n  console.log(\"Finished with exit code\", exitCode);\n});\n\n\ncompileToString([\"./HelloWorld.elm\"], {}).then(function(data){\n    console.log(\"compileToString produced a string with this length:\", data.toString().length);\n});\n\ncompileToString([\"./HelloWorld.elm\"], { output: \"index.html\" }).then(function(data){\n    console.log(\"compileToString --output index.html produced a string with this length:\", data.toString().length);\n});\n"
  },
  {
    "path": "examples/elm.json",
    "content": "{\n    \"type\": \"application\",\n    \"source-directories\": [\n        \".\"\n    ],\n    \"elm-version\": \"0.19.0\",\n    \"dependencies\": {\n        \"direct\": {\n            \"elm/browser\": \"1.0.0\",\n            \"elm/core\": \"1.0.0\",\n            \"elm/html\": \"1.0.0\"\n        },\n        \"indirect\": {\n            \"elm/json\": \"1.0.0\",\n            \"elm/time\": \"1.0.0\",\n            \"elm/url\": \"1.0.0\",\n            \"elm/virtual-dom\": \"1.0.0\"\n        }\n    },\n    \"test-dependencies\": {\n        \"direct\": {},\n        \"indirect\": {}\n    }\n}"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"node-elm-compiler\",\n  \"version\": \"5.0.6\",\n  \"description\": \"A Node.js interface to the Elm compiler binaries.\",\n  \"main\": \"dist/index.js\",\n  \"scripts\": {\n    \"prepack\": \"npm run build\",\n    \"build\": \"rm -rf dist/ && tsc\",\n    \"test\": \"rm -rf test/fixtures/elm-stuff && mocha test/**/*.ts --require ts-node/register --watch-extensions ts\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"https://github.com/rtfeldman/node-elm-compiler.git\"\n  },\n  \"engines\": {\n    \"node\": \">=4.0.0\"\n  },\n  \"keywords\": [\n    \"elm\",\n    \"compiler\",\n    \"node\"\n  ],\n  \"author\": \"Richard Feldman\",\n  \"license\": \"BSD-3-Clause\",\n  \"bugs\": {\n    \"url\": \"https://github.com/rtfeldman/node-elm-compiler/issues\"\n  },\n  \"homepage\": \"https://github.com/rtfeldman/node-elm-compiler\",\n  \"dependencies\": {\n    \"cross-spawn\": \"6.0.5\",\n    \"find-elm-dependencies\": \"^2.0.4\",\n    \"lodash\": \"^4.17.19\",\n    \"temp\": \"^0.9.0\"\n  },\n  \"devDependencies\": {\n    \"@types/mocha\": \"^5.2.7\",\n    \"@types/node\": \"^12.6.8\",\n    \"chai\": \"4.2.0\",\n    \"glob\": \"7.1.4\",\n    \"mocha\": \"6.2.0\",\n    \"ts-node\": \"^8.3.0\",\n    \"typescript\": \"^3.5.3\"\n  }\n}\n"
  },
  {
    "path": "src/index.ts",
    "content": "'use strict';\n\nvar spawn = require(\"cross-spawn\");\nvar _ = require(\"lodash\");\nvar elmBinaryName = \"elm\";\nvar fs = require(\"fs\");\nvar path = require(\"path\");\nvar temp = require(\"temp\").track();\nvar findAllDependencies = require(\"find-elm-dependencies\").findAllDependencies;\n\nvar defaultOptions = {\n  spawn: spawn,\n  cwd: undefined,\n  pathToElm: undefined,\n  help: undefined,\n  output: undefined,\n  report: undefined,\n  debug: undefined,\n  verbose: false,\n  processOpts: undefined,\n  docs: undefined,\n  optimize: undefined,\n};\n\nvar supportedOptions = _.keys(defaultOptions);\n\nfunction prepareSources(sources) {\n  if (!(sources instanceof Array || typeof sources === \"string\")) {\n    throw \"compile() received neither an Array nor a String for its sources argument.\";\n  }\n\n  return typeof sources === \"string\" ? [sources] : sources;\n}\n\nfunction prepareOptions(options, spawnFn) {\n  return _.defaults({ spawn: spawnFn }, options, defaultOptions);\n}\n\nfunction prepareProcessArgs(sources, options) {\n  var preparedSources = prepareSources(sources);\n  var compilerArgs = compilerArgsFromOptions(options);\n\n  return [\"make\"].concat(preparedSources ? preparedSources.concat(compilerArgs) : compilerArgs);\n}\n\nfunction prepareProcessOpts(options) {\n  var env = _.merge({ LANG: 'en_US.UTF-8' }, process.env);\n  return _.merge({ env: env, stdio: \"inherit\", cwd: options.cwd }, options.processOpts);\n\n}\n\nfunction runCompiler(sources, options, pathToElm) {\n  if (typeof options.spawn !== \"function\") {\n    throw \"options.spawn was a(n) \" + (typeof options.spawn) + \" instead of a function.\";\n  }\n\n  var processArgs = prepareProcessArgs(sources, options);\n  var processOpts = prepareProcessOpts(options);\n\n  if (options.verbose) {\n    console.log([\"Running\", pathToElm].concat(processArgs).join(\" \"));\n  }\n\n  return options.spawn(pathToElm, processArgs, processOpts);\n}\n\nfunction compilerErrorToString(err, pathToElm) {\n  if ((typeof err === \"object\") && (typeof err.code === \"string\")) {\n    switch (err.code) {\n      case \"ENOENT\":\n        return \"Could not find Elm compiler \\\"\" + pathToElm + \"\\\". Is it installed?\";\n\n      case \"EACCES\":\n        return \"Elm compiler \\\"\" + pathToElm + \"\\\" did not have permission to run. Do you need to give it executable permissions?\";\n\n      default:\n        return \"Error attempting to run Elm compiler \\\"\" + pathToElm + \"\\\":\\n\" + err;\n    }\n  } else if ((typeof err === \"object\") && (typeof err.message === \"string\")) {\n    return JSON.stringify(err.message);\n  } else {\n    return \"Exception thrown when attempting to run Elm compiler \" + JSON.stringify(pathToElm);\n  }\n}\n\nfunction compileSync(sources, options) {\n  var optionsWithDefaults = prepareOptions(options, options.spawn || spawn.sync);\n  var pathToElm = options.pathToElm || elmBinaryName;\n\n  try {\n    return runCompiler(sources, optionsWithDefaults, pathToElm);\n  } catch (err) {\n    throw compilerErrorToString(err, pathToElm);\n  }\n}\n\nfunction compile(sources, options) {\n  var optionsWithDefaults = prepareOptions(options, options.spawn || spawn);\n  var pathToElm = options.pathToElm || elmBinaryName;\n\n\n  try {\n    return runCompiler(sources, optionsWithDefaults, pathToElm)\n      .on('error', function (err) { throw (err); });\n  } catch (err) {\n    throw compilerErrorToString(err, pathToElm);\n  }\n}\n\nfunction getSuffix(outputPath, defaultSuffix) {\n  if (outputPath) {\n    return path.extname(outputPath) || defaultSuffix;\n  } else {\n    return defaultSuffix;\n  }\n}\n\n// write compiled Elm to a string output\n// returns a Promise which will contain a Buffer of the text\n// If you want html instead of js, use options object to set\n// output to a html file instead\n// creates a temp file and deletes it after reading\nfunction compileToString(sources, options) {\n  const suffix = getSuffix(options.output, '.js');\n\n  return new Promise(function (resolve, reject) {\n    temp.open({ suffix }, function (err, info) {\n      if (err) {\n        return reject(err);\n      }\n\n      options.output = info.path;\n      options.processOpts = { stdio: 'pipe' }\n\n      var compiler;\n\n      try {\n        compiler = compile(sources, options);\n      } catch (compileError) {\n        return reject(compileError);\n      }\n\n      compiler.stdout.setEncoding(\"utf8\");\n      compiler.stderr.setEncoding(\"utf8\");\n\n      var output = '';\n      compiler.stdout.on('data', function (chunk) {\n        output += chunk;\n      });\n      compiler.stderr.on('data', function (chunk) {\n        output += chunk;\n      });\n\n      compiler.on(\"close\", function (exitCode) {\n        if (exitCode !== 0) {\n          return reject(new Error('Compilation failed\\n' + output));\n        } else if (options.verbose) {\n          console.log(output);\n        }\n\n        fs.readFile(info.path, { encoding: \"utf8\" }, function (err, data) {\n          return err ? reject(err) : resolve(data);\n        });\n      });\n    });\n  });\n}\n\nfunction compileToStringSync(sources, options) {\n  const suffix = getSuffix(options.output, '.js');\n\n  const file = temp.openSync({ suffix });\n  options.output = file.path;\n  let compileProcess = compileSync(sources, options);\n\n  if (compileProcess.status == 0) {\n    return fs.readFileSync(file.path, { encoding: \"utf8\" });\n  }\n  else {\n    // Throw a simple error. We already let elm output to stdout/stderr\n    throw 'Compilation failed.';\n  }\n}\n\n// Converts an object of key/value pairs to an array of arguments suitable\n// to be passed to child_process.spawn for elm-make.\nfunction compilerArgsFromOptions(options) {\n  return _.flatten(_.map(options, function (value, opt) {\n    if (value) {\n      switch (opt) {\n        case \"help\": return [\"--help\"];\n        case \"output\": return [\"--output\", value];\n        case \"report\": return [\"--report\", value];\n        case \"debug\": return [\"--debug\"];\n        case \"docs\": return [\"--docs\", value];\n        case \"optimize\": return [\"--optimize\"];\n        case \"runtimeOptions\": return [].concat([\"+RTS\"], value, [\"-RTS\"]);\n        default:\n          if (supportedOptions.indexOf(opt) === -1) {\n            if (opt === \"yes\") {\n              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.');\n            } else if (opt === \"warn\") {\n              throw new Error('node-elm-compiler received the `warn` option, but that was removed in Elm 0.19. Try re-running without passing the `warn` option.');\n            } else if (opt === \"pathToMake\") {\n              throw new Error('node-elm-compiler received the `pathToMake` option, but that was renamed to `pathToElm` in Elm 0.19. Try re-running after renaming the parameter to `pathToElm`.');\n            } else {\n              throw new Error('node-elm-compiler was given an unrecognized Elm compiler option: ' + opt);\n            }\n          }\n\n          return [];\n      }\n    } else {\n      return [];\n    }\n  }));\n}\n\nmodule.exports = {\n  compile: compile,\n  compileSync: compileSync,\n  compileWorker: require(\"./worker\")(compile),\n  compileToString: compileToString,\n  compileToStringSync: compileToStringSync,\n  findAllDependencies: findAllDependencies,\n  _prepareProcessArgs: prepareProcessArgs\n};\n"
  },
  {
    "path": "src/worker.ts",
    "content": "var temp = require(\"temp\").track();\nvar path = require(\"path\");\nvar jsEmitterFilename = \"emitter.js\";\n\nvar KNOWN_MODULES =\n  [\n    \"fullscreen\",\n    \"embed\",\n    \"worker\",\n    \"Basics\",\n    \"Maybe\",\n    \"List\",\n    \"Array\",\n    \"Char\",\n    \"Color\",\n    \"Transform2D\",\n    \"Text\",\n    \"Graphics\",\n    \"Debug\",\n    \"Result\",\n    \"Task\",\n    \"Signal\",\n    \"String\",\n    \"Dict\",\n    \"Json\",\n    \"Regex\",\n    \"VirtualDom\",\n    \"Html\",\n    \"Css\"\n  ];\n\n\n// elmModuleName is optional, and is by default inferred based on the filename.\nmodule.exports = function (compile) {\n  return function (projectRootDir, modulePath, moduleName, workerArgs) {\n    var originalWorkingDir = process.cwd();\n    process.chdir(projectRootDir);\n\n    return createTmpDir()\n      .then(function (tmpDirPath) {\n        var dest = path.join(tmpDirPath, jsEmitterFilename);\n\n        return compileEmitter(compile, modulePath, { output: dest })\n          .then(function () { return runWorker(dest, moduleName, workerArgs) });\n      })\n      .then(function (worker) {\n        process.chdir(originalWorkingDir);\n        return worker;\n      })\n      .catch(function (err) {\n        process.chdir(originalWorkingDir);\n        throw Error(err);\n      });\n  };\n};\n\nfunction createTmpDir() {\n  return new Promise(function (resolve, reject) {\n    temp.mkdir(\"node-elm-compiler\", function (err, tmpDirPath) {\n      if (err) {\n        reject(err);\n      } else {\n        resolve(tmpDirPath);\n      }\n    });\n  });\n}\n\nfunction suggestModulesNames(Elm) {\n  return Object.keys(Elm).filter(function (key) {\n    return KNOWN_MODULES.indexOf(key) === -1;\n  })\n}\n\nfunction missingEntryModuleMessage(moduleName, Elm) {\n  var errorMessage = \"I couldn't find the entry module \" + moduleName + \".\\n\";\n  var suggestions = suggestModulesNames(Elm);\n\n  if (suggestions.length > 1) {\n    errorMessage += \"\\nMaybe you meant one of these: \" + suggestions.join(\",\");\n  } else if (suggestions.length === 1) {\n    errorMessage += \"\\nMaybe you meant: \" + suggestions;\n  }\n\n  errorMessage += \"\\nYou can pass me a different module to use with --module=<moduleName>\";\n\n  return errorMessage;\n}\n\nfunction noPortsMessage(moduleName) {\n  var errorMessage = \"The module \" + moduleName + \" doesn't expose any ports!\\n\";\n\n  errorMessage += \"\\n\\nTry adding something like\";\n  errorMessage += \"port foo : Value\\nport foo =\\n    someValue\\n\\nto \" + moduleName + \"!\";\n\n  return errorMessage.trim();\n}\n\nfunction runWorker(jsFilename, moduleName, workerArgs) {\n  return new Promise(function (resolve, reject) {\n    var Elm = require(jsFilename).Elm;\n\n    if (!(moduleName in Elm)) {\n      return reject(missingEntryModuleMessage(moduleName, Elm));\n    }\n\n    var worker = Elm[moduleName].init(workerArgs);\n\n    if (Object.keys(worker.ports).length === 0) {\n      return reject(noPortsMessage(moduleName));\n    }\n\n    return resolve(worker);\n  });\n}\n\nfunction compileEmitter(compile, src, options) {\n  return new Promise(function (resolve, reject) {\n    compile(src, options)\n      .on(\"close\", function (exitCode) {\n        if (exitCode === 0) {\n          resolve(exitCode);\n        } else {\n          reject(\"Errored with exit code \" + exitCode);\n        }\n      })\n  });\n}\n"
  },
  {
    "path": "test/compile.ts",
    "content": "var chai = require(\"chai\")\nvar path = require(\"path\");\nvar compiler = require(path.join(__dirname, \"../src\"));\nvar childProcess = require(\"child_process\");\nvar _ = require(\"lodash\");\nvar temp = require(\"temp\");\n\nvar expect = chai.expect;\n\nvar fixturesDir = path.join(__dirname, \"fixtures\");\n\nfunction prependFixturesDir(filename) {\n  return path.join(fixturesDir, filename);\n}\n\ndescribe(\"#compile\", function () {\n  // Use a timeout of 5 minutes because Travis on Linux can be SUPER slow.\n  this.timeout(300000);\n\n  it(\"reports errors on bad source\", function (done) {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir\n    };\n    var compileProcess = compiler.compile(prependFixturesDir(\"Bad.elm\"), opts);\n\n    compileProcess.on(\"exit\", function (exitCode) {\n      var desc = \"Expected elm make to have exit code 1\";\n      expect(exitCode, desc).to.equal(1);\n      done();\n    });\n  });\n\n  it(\"throws when given an unrecognized argument\", function () {\n    var opts = {\n      foo: \"bar\",\n      output: \"/dev/null\",\n      verbose: true,\n      cwd: fixturesDir\n    };\n\n    expect(function () {\n      var compileProcess = compiler.compile(prependFixturesDir(\"Parent.elm\"), opts);\n\n    }).to.throw();\n  });\n});\n\ndescribe(\"#compileToString\", function () {\n  // Use an epic timeout because Travis on Linux can be SUPER slow.\n  this.timeout(600000);\n\n  it(\"adds runtime options as arguments\", function () {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir,\n      runtimeOptions: [\"-A128M\", \"-H128M\", \"-n8m\"]\n    };\n\n    return expect(compiler\n      ._prepareProcessArgs(\"a.elm\", opts)\n      .join(\" \")).to.equal(\"make a.elm +RTS -A128M -H128M -n8m -RTS\");\n  });\n\n  it(\"reports errors on bad syntax\", function () {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir\n    };\n    var compilePromise = compiler.compileToString(prependFixturesDir(\"Bad.elm\"), opts);\n\n    return compilePromise.catch(function (err) {\n      expect(err).to.be.an('error');\n      expect(String(err))\n        .to.contain(\"Compilation failed\")\n        .and.contain(\"PARSE ERROR\");\n    });\n  });\n\n  it(\"reports type errors\", function () {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir\n    };\n    var compilePromise = compiler.compileToString(prependFixturesDir(\"TypeError.elm\"), opts);\n\n    return compilePromise.catch(function (err) {\n      expect(err).to.be.an('error');\n      expect(String(err))\n        .to.contain(\"Compilation failed\")\n        .and.contain(\"TYPE MISMATCH\");\n    });\n  });\n\n  it(\"Rejects the Promise when given an unrecognized argument like `yes`\", function () {\n    var opts = {\n      foo: \"bar\",\n      verbose: true,\n      cwd: fixturesDir\n    };\n\n    var compilePromise = compiler.compileToString(prependFixturesDir(\"Parent.elm\"), opts);\n\n    return new Promise(function (resolve, reject) {\n      return compilePromise.then(function () {\n        reject(\"Expected the compilation promise to be rejected due to the unrecognized compiler argument.\");\n      }).catch(function () {\n        resolve();\n      });\n    });\n  });\n\n\n  it(\"works when run multiple times\", function () {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir\n    };\n\n    var runCompile = function () {\n      var compilePromise = compiler.compileToString(prependFixturesDir(\"Parent.elm\"), opts)\n\n      return compilePromise.then(function (result) {\n        var desc = \"Expected elm make to return the result of the compilation\";\n        expect(result.toString(), desc).to.be.a('string');\n      });\n    };\n\n    // Compiling in parallel leads to issues with the cache. Therefore we chain\n    // the compilations instead. For details, see https://github.com/elm/compiler/issues/1853.\n    // This issue is tracked as https://github.com/rtfeldman/node-elm-compiler/issues/86.\n    let promiseChain = Promise.resolve();\n    for (var i = 0; i < 10; i++) {\n      promiseChain = promiseChain.then(() => runCompile());\n    }\n    return promiseChain;\n  });\n\n  it(\"handles output suffix correctly\", function () {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir,\n      output: prependFixturesDir(\"compiled.html\"),\n    };\n\n    return compiler.compileToString(prependFixturesDir(\"Parent.elm\"), opts)\n      .then(function (result) {\n        var desc = \"Expected elm make to return the result of the compilation\";\n        expect(result.toString(), desc).to.be.a('string');\n      });\n  });\n});\n\ndescribe(\"#compileWorker\", function () {\n  // Use a timeout of 5 minutes because Travis on Linux can be SUPER slow.\n  this.timeout(300000);\n\n  it(\"works with BasicWorker.elm\", function () {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir\n    };\n    var compilePromise = compiler.compileWorker(\n      prependFixturesDir(\"\"),\n      prependFixturesDir(\"BasicWorker.elm\"),\n      \"BasicWorker\"\n    );\n\n    return compilePromise.then(function (app) {\n      app.ports.reportFromWorker.subscribe(function (str) {\n        expect(str).to.equal(\"it's alive!\");\n      });\n    })\n  });\n});\n"
  },
  {
    "path": "test/compileSync.ts",
    "content": "var chai = require(\"chai\")\nvar path = require(\"path\");\nvar compiler = require(path.join(__dirname, \"../src\"));\n\nvar expect = chai.expect;\n\nvar fixturesDir = path.join(__dirname, \"fixtures\");\n\nfunction prependFixturesDir(filename) {\n  return path.join(fixturesDir, filename);\n}\n\ndescribe(\"#compileSync\", function () {\n  // Use a timeout of 5 minutes because Travis on Linux can be SUPER slow.\n  this.timeout(300000);\n\n  it(\"succeeds on SimplestMain\", function () {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir\n    };\n    var compileProcess = compiler.compileSync(prependFixturesDir(\"SimplestMain.elm\"), opts);\n\n    var exitCode = compileProcess.status;\n    var desc = \"Expected elm make to have exit code 0\";\n    expect(exitCode, desc).to.equal(0);\n  });\n\n  it(\"reports errors on bad source\", function () {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir\n    };\n    var compileProcess = compiler.compileSync(prependFixturesDir(\"Bad.elm\"), opts);\n\n    var exitCode = compileProcess.status;\n    var desc = \"Expected elm make to have exit code 1\";\n    expect(exitCode, desc).to.equal(1);\n  });\n\n  it(\"throws when given an unrecognized argument like `yes`\", function () {\n    var opts = {\n      yes: true,\n      output: \"/dev/null\",\n      verbose: true,\n      cwd: fixturesDir\n    };\n\n    expect(function () {\n      var compileProcess = compiler.compileSync(prependFixturesDir(\"Parent.elm\"), opts);\n    }).to.throw();\n  });\n});\n"
  },
  {
    "path": "test/compileToStringSync.ts",
    "content": "var chai = require(\"chai\");\nvar path = require(\"path\");\nvar compiler = require(path.join(__dirname, \"../src\"));\n\nvar expect = chai.expect;\n\nvar fixturesDir = path.join(__dirname, \"fixtures\");\n\nfunction prependFixturesDir(filename) {\n  return path.join(fixturesDir, filename);\n}\n\ndescribe(\"#compileToStringSync\", function () {\n  it('returns string JS output of the given elm file', function () {\n    var opts = { verbose: true, cwd: fixturesDir };\n    var result = compiler.compileToStringSync(prependFixturesDir(\"Parent.elm\"), opts);\n\n    expect(result).to.include(\"_Platform_export\");\n  });\n\n  it('returns html output given \"html\" output option', function () {\n    var opts = {\n      verbose: true,\n      cwd: fixturesDir,\n      output: prependFixturesDir('compiled.html'),\n    };\n    var result = compiler.compileToStringSync(prependFixturesDir(\"Parent.elm\"), opts);\n\n    expect(result).to.include('<!DOCTYPE HTML>');\n    expect(result).to.include('<title>Parent</title>');\n    expect(result).to.include(\"_Platform_export\");\n  });\n  it('throws on compilation errors', function () {\n    var opts = { verbose: false, cwd: fixturesDir };\n\n    expect(function () {\n      compiler.compileToStringSync(prependFixturesDir(\"Bad.elm\"), opts);\n    }).to.throw();\n  });\n});\n"
  },
  {
    "path": "test/fixtures/Bad.elm",
    "content": "module Bad\n\n\nmain =\n   hello! I am a syntax error! :D\n"
  },
  {
    "path": "test/fixtures/BasicWorker.elm",
    "content": "port module BasicWorker exposing (..)\n\nimport Platform\n\n\nmain : Program () String msg\nmain =\n    Platform.worker\n        { init = \\_ -> ( \"\", reportFromWorker \"it's alive!\" )\n        , update = \\_ _ -> ( \"\", Cmd.none )\n        , subscriptions = \\_ -> Sub.none\n        }\n\n\nport reportFromWorker : String -> Cmd a\n"
  },
  {
    "path": "test/fixtures/Nested/Child.elm",
    "content": "module Nested.Child exposing (..)\n\nimport Test.ChildB\nimport Html\n\n\nmain =\n    Html.text \"I am child A\"\n"
  },
  {
    "path": "test/fixtures/Nested/Parent/Test.elm",
    "content": "module Nested.Parent.Test exposing (..)\n\nimport Test.ChildA\nimport Nested.Child\nimport Nested.Test.Child\n\n\n-- This is a comment in between two import statements.\n\nimport Test.Sample.NestedChild exposing (..)\n\n\nmain =\n    \"Hello, World!\"\n"
  },
  {
    "path": "test/fixtures/Nested/Test/Child.elm",
    "content": "module Nested.Test.Child exposing (..)\n\nimport Test.ChildA\nimport Nested.Child\n\n\n-- This is a comment in between two import statements.\n\nimport Test.Sample.NestedChild exposing (..)\n\n\nmain =\n    \"Hello, World!\"\n"
  },
  {
    "path": "test/fixtures/Parent.elm",
    "content": "module Parent exposing (..)\n\nimport Test.ChildA\n\n\n-- This is a comment in between two import statements.\n\nimport Test.ChildB exposing (..)\nimport Html\n\n\nmain =\n    Html.text \"Hello, World!\"\n"
  },
  {
    "path": "test/fixtures/ParentWithNestedDeps.elm",
    "content": "module Parent exposing (..)\n\nimport Test.ChildA\n\n\n-- This is a comment in between two import statements.\n\nimport Test.Sample.NestedChild exposing (..)\n\n\nmain =\n    \"Hello, World!\"\n"
  },
  {
    "path": "test/fixtures/ParentWithPort.elm",
    "content": "port module ParentWithPort exposing (..)\n\nimport Test.ChildA\n\n\n-- This is a comment in between two import statements.\n\nimport Test.ChildB exposing (..)\nimport Html\n\n\nmain =\n    Html.text \"Hello, World!\"\n"
  },
  {
    "path": "test/fixtures/ParentWithUnindentedMultilineComment.elm",
    "content": "module ParentWithUnindentedMultilineComment exposing (..)\n\n{-| This is a comment in between two import statements.\nsometimes I write things here because I like to watch the world burn\n-}\nimport Test.ChildA\n\n\nimport Test.ChildB exposing (..)\n{- this comment will end before an import\n-}\nimport Html\n\n\nmain =\n    Html.text \"Hello, World!\"\n"
  },
  {
    "path": "test/fixtures/SimplestMain.elm",
    "content": "import Html\n\nmain =\n    Html.text \"Hello, World!\"\n"
  },
  {
    "path": "test/fixtures/Test/ChildA.elm",
    "content": "module Test.ChildA exposing (..)\n\nimport Html\n\n\nmain =\n    Html.text \"I am child A\"\n"
  },
  {
    "path": "test/fixtures/Test/ChildB.elm",
    "content": "module Test.ChildB exposing (..)\n\nimport Html\n\n\nmain =\n    Html.text \"I am child B\"\n"
  },
  {
    "path": "test/fixtures/Test/Sample/NestedChild.elm",
    "content": "module Test.Sample.NestedChild exposing (..)\n\nimport Test.ChildB\n\n\nmain =\n    \"Hello, World!\"\n"
  },
  {
    "path": "test/fixtures/TypeError.elm",
    "content": "module TypeError exposing (..)\n\nimport Html\n\n\nmain =\n    Html.text (1 ++ \"2\")\n"
  },
  {
    "path": "test/fixtures/elm.json",
    "content": "{\n    \"type\": \"application\",\n    \"source-directories\": [\n        \".\"\n    ],\n    \"elm-version\": \"0.19.0\",\n    \"dependencies\": {\n        \"direct\": {\n            \"elm/browser\": \"1.0.0\",\n            \"elm/core\": \"1.0.0\",\n            \"elm/html\": \"1.0.0\"\n        },\n        \"indirect\": {\n            \"elm/json\": \"1.0.0\",\n            \"elm/time\": \"1.0.0\",\n            \"elm/url\": \"1.0.0\",\n            \"elm/virtual-dom\": \"1.0.0\"\n        }\n    },\n    \"test-dependencies\": {\n        \"direct\": {},\n        \"indirect\": {}\n    },\n    \"do-not-edit-this-by-hand\": {\n        \"transitive-dependencies\": {\n            \"elm-lang/json\": \"1.0.0\",\n            \"elm-lang/virtual-dom\": \"3.0.0\"\n        }\n    }\n}"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n    \"compilerOptions\": {\n        \"outDir\": \"./dist\",\n        \"allowJs\": true,\n        \"target\": \"es5\",\n        \"lib\": [\n            \"es2015\"\n        ]\n    },\n    \"include\": [\n        \"./src/**/*\"\n    ]\n}"
  }
]