Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 4.2.0 to 4.2.1

dependencies.js

6

examples/elm-package.json

@@ -11,6 +11,6 @@ {

"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/html": "1.0.0 <= v < 2.0.0"
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
"elm-version": "0.18.0 <= v < 0.19.0"
}

@@ -10,2 +10,4 @@ 'use strict';

var firstline = require("firstline");
var depsLoader = require('./dependencies.js');
var glob = require("glob");

@@ -111,3 +113,3 @@ var defaultOptions = {

// Elm file depends on, based on the modules it loads via `import`.
function findAllDependencies(file, knownDependencies, baseDir) {
function findAllDependencies(file, knownDependencies, baseDir, knownFiles) {
if (!knownDependencies) {

@@ -117,75 +119,105 @@ knownDependencies = [];

if (typeof knownFiles === "undefined"){
knownFiles = [];
} else if (knownFiles.indexOf(file) > -1){
return knownDependencies;
}
if (baseDir) {
return findAllDependenciesHelp(file, knownDependencies, baseDir);
return findAllDependenciesHelp(file, knownDependencies, baseDir, knownFiles).then(function(thing){
return thing.knownDependencies;
});
} else {
return getBaseDir(file).then(function(newBaseDir) {
return findAllDependenciesHelp(file, knownDependencies, newBaseDir);
});
return findAllDependenciesHelp(file, knownDependencies, newBaseDir, knownFiles).then(function(thing){
return thing.knownDependencies;
});
})
}
}
function findAllDependenciesHelp(file, knownDependencies, baseDir) {
function findAllDependenciesHelp(file, knownDependencies, baseDir, knownFiles) {
return new Promise(function(resolve, reject) {
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) {
// if we already know the file, return known deps since we won't learn anything
if (knownFiles.indexOf(file) !== -1){
return resolve({
file: file,
error: false,
knownDependencies: knownDependencies
});
}
// read the imports then parse each of them
depsLoader.readImports(file).then(function(lines){
// when lines is null, the file was not read so we just return what we know
// and flag the error state
if (lines === null){
return resolve({
file: file,
error: true,
knownDependencies: knownDependencies
});
}
var newImports = _.compact(lines.map(function(line) {
var matches = line.match(/^import\s+([^\s]+)/);
if (matches) {
// e.g. Css.Declarations
var moduleName = matches[1];
// if the line is not actually an import line
if (!matches) {
return null;
}
// e.g. Css/Declarations
var dependencyLogicalName = moduleName.replace(/\./g, "/");
// e.g. Css.Declarations
var moduleName = matches[1];
// e.g. ~/code/elm-css/src/Css/Declarations.elm
var result = path.join(baseDir, dependencyLogicalName)
// e.g. Css/Declarations
var dependencyLogicalName = moduleName.replace(/\./g, "/");
return _.includes(knownDependencies, result) ? null : result;
} else {
return null;
// all non-native modules are .elm
var extension = ".elm";
// all native modules are .js
if (moduleName.startsWith("Native.")){
extension = ".js";
}
// e.g. ~/code/elm-css/src/Css/Declarations.elm
var result = path.join(baseDir, dependencyLogicalName + extension);
return _.includes(knownDependencies, result) ? null : result;
}));
var promises = newImports.map(function(newImport) {
var elmFile = newImport + ".elm";
knownFiles.push(file);
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);
}
});
var validDependencies = _.flatten(newImports);
var newDependencies = knownDependencies.concat(validDependencies);
var recursePromises = _.compact(validDependencies.map(function(dependency) {
return path.extname(dependency) === ".elm" ?
findAllDependenciesHelp(dependency, newDependencies, baseDir, knownFiles) : null;
}));
Promise.all(recursePromises).then(function(extraDependencies) {
// keep track of files that weren't found in our src directory
var externalPackageFiles = [];
var justDeps = extraDependencies.map(function(thing){
// if we had an error, we flag the file as a bad thing
if (thing.error){
externalPackageFiles.push(thing.file)
return [];
}
return thing.knownDependencies;
});
});
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" ?
findAllDependenciesHelp(dependency, newDependencies, baseDir) : null;
}));
var flat = _.uniq(_.flatten(knownDependencies.concat(justDeps))).filter(function(file){
return externalPackageFiles.indexOf(file) === -1;
});
Promise.all(recursePromises).then(function(extraDependencies) {
resolve(_.uniq(_.flatten(newDependencies.concat(extraDependencies))));
}).catch(reject);
resolve({
file: file,
error: false,
knownDependencies: flat
});
}).catch(reject);
}
});
}).catch(reject);
});

@@ -241,16 +273,2 @@ }

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) {

@@ -257,0 +275,0 @@ if (err.code === "ENOENT") {

{
"name": "node-elm-compiler",
"version": "4.2.0",
"version": "4.2.1",
"description": "A Node.js interface to the Elm compiler binaries. Supports Elm version 0.17",

@@ -14,3 +14,3 @@ "main": "index.js",

"engines": {
"node": ">=0.12.0"
"node": ">=4.0.0"
},

@@ -17,0 +17,0 @@ "keywords": [

@@ -17,2 +17,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)

## 4.2.1
Epic perf improvements from @eeue56
## 4.2.0

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

@@ -27,2 +27,10 @@ var expect = require("chai").expect;

it("works for a module with comments between lines with three dependencies", function () {
return compiler.findAllDependencies(prependFixturesDir("ParentWithUnindentedMultilineComment.elm")).then(function(results) {
expect(results).to.deep.equal(
[ "Test/ChildA.elm", "Test/ChildB.elm", "Native/Child.js" ].map(prependFixturesDir)
);
});
});
it("works for a non-port module with three dependencies", function () {

@@ -29,0 +37,0 @@ return compiler.findAllDependencies(prependFixturesDir("Parent.elm")).then(function(results) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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