Socket
Socket
Sign inDemoInstall

node-elm-compiler

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-elm-compiler - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

.travis.yml

97

index.js
'use strict';
var childProcess = require("child_process");
var _ = require('lodash');
var _ = require("lodash");
var compilerBinaryName = "elm-make";
var fs = require("fs");
var path = require("path");

@@ -63,2 +65,92 @@ var defaultOptions = {

// Returns a Promise that returns a flat list of all the Elm files the given
// Elm file depends on, based on the modules it loads via `import`.
function findAllDependencies(file, knownDependencies) {
if (!knownDependencies) {
knownDependencies = [];
}
return new Promise(function(resolve, reject) {
var baseDir = path.dirname(file);
fs.readFile(file, {encoding: "utf8"}, function(err, lines) {
if (err) {
reject(err);
} else {
// Turn e.g. ~/code/elm-css/src/Css.elm
// into just ~/code/elm-css/src/
var newImports = _.compact(lines.split("\n").map(function(line) {
var matches = line.match(/^import\s+([^\s]+)/);
if (matches) {
// e.g. Css.Declarations
var moduleName = matches[1];
// e.g. Css/Declarations
var dependencyLogicalName = moduleName.replace(/\./g, "/");
// e.g. ~/code/elm-css/src/Css/Declarations.elm
// TODO need to handle Native .js files in here...
var result = path.join(baseDir, dependencyLogicalName)
return _.contains(knownDependencies, result) ? null : result;
} else {
return null;
}
}));
var promises = newImports.map(function(newImport) {
var elmFile = newImport + ".elm";
return new Promise(function(resolve, reject) {
return checkIsFile(newImport + ".elm").then(resolve).catch(function(firstErr) {
if (firstErr.code === "ENOENT") {
// If we couldn't find the import as a .elm file, try as .js
checkIsFile(newImport + ".js").then(resolve).catch(function(secondErr) {
if (secondErr.code === "ENOENT") {
// If we don't find the dependency in our filesystem, assume it's because
// it comes in through a third-party package rather than our sources.
resolve([]);
} else {
reject(secondErr);
}
})
} else {
reject(firstErr);
}
});
});
});
Promise.all(promises).then(function(nestedValidDependencies) {
var validDependencies = _.flatten(nestedValidDependencies);
var newDependencies = knownDependencies.concat(validDependencies);
var recursePromises = _.compact(validDependencies.map(function(dependency) {
return path.extname(dependency) === ".elm" ?
findAllDependencies(dependency, newDependencies) : null;
}));
Promise.all(recursePromises).then(function(extraDependencies) {
resolve(_.uniq(_.flatten(newDependencies.concat(extraDependencies))));
}).catch(reject);
}).catch(reject);
}
});
});
}
function checkIsFile(file) {
return new Promise(function(resolve, reject) {
fs.stat(file, function(err, stats) {
if (err) {
reject(err);
} else if (stats.isFile()) {
resolve([file]);
} else {
resolve([]);
}
});
});
}
function handleError(pathToMake, err) {

@@ -101,3 +193,4 @@ if (err.code === "ENOENT") {

module.exports = {
compile: compile
compile: compile,
findAllDependencies: findAllDependencies
};
{
"name": "node-elm-compiler",
"version": "2.0.0",
"version": "2.1.0",
"description": "A Node.js interface to the Elm compiler binaries. Supports Elm versions 0.15 - 0.16.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha test/dependencies.js"
},

@@ -13,2 +13,5 @@ "repository": {

},
"engines": {
"node": ">=0.12.0"
},
"keywords": [

@@ -27,3 +30,7 @@ "elm",

"lodash": "3.10.1"
},
"devDependencies": {
"chai": "3.4.1",
"mocha": "2.3.4"
}
}

@@ -1,2 +0,2 @@

# node-elm-compiler
# 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)

@@ -17,2 +17,6 @@ Wraps [Elm](https://elm-lang.org) and exposes a [Node](https://nodejs.org) API to compile Elm sources.

## 2.1.0
Added #findAllDependencies
## 2.0.0

@@ -19,0 +23,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc