From d4ec59a9cb2ed153d7752eba06b11c88ea9095b7 Mon Sep 17 00:00:00 2001 From: Robin Heggelund Hansen Date: Wed, 26 Aug 2020 16:15:19 +0200 Subject: [PATCH] Remove maxInstances and cache options. --- README.md | 40 ------------------------------------- index.js | 59 ++++++++++++++++++++----------------------------------- 2 files changed, 21 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 29c83e4..7a0141c 100644 --- a/README.md +++ b/README.md @@ -59,46 +59,6 @@ will cause the compiler to look for **all** elm source files in the specified di approach is recommended as it allows the compile to watch elm.json as well as every file in the source directories. -#### maxInstances (default 1) - -You can add `maxInstances=8` to the loader: - -```js - ... - use: { - loader: 'elm-webpack-loader', - options: { - maxInstances: 8 - } - } - ... -``` - -Set a limit to the number of maxInstances of elm that can spawned. This should be set to a number -less than the number of cores your machine has. The ideal number is 1, as it will prevent Elm -instances causing deadlocks. - -#### Cache (default false) - -You can add `cache=true` to the loader: - -```js - ... - use: { - loader: 'elm-webpack-loader', - options: { - cache: true - } - } - ... -``` - -If you add this, when using watch mode, the loader will only load the dependencies at startup. -This could be performance improvement, but know that new files won't be picked up and so won't be -watched until you restart webpack. - -This flag doesn't matter if you don't use watch mode. - #### ForceWatch (default false) This loader will infer if you are running webpack in watch mode by checking the webpack arguments. diff --git a/index.js b/index.js index fed938d..c13ab89 100644 --- a/index.js +++ b/index.js @@ -7,11 +7,9 @@ var loaderUtils = require('loader-utils'); var elmCompiler = require('node-elm-compiler'); var yargs = require('yargs'); -var runningInstances = 0; var alreadyCompiledFiles = []; var defaultOptions = { - cache: false, forceWatch: false, optimize: false }; @@ -154,53 +152,38 @@ module.exports = function() { delete options.forceWatch - var maxInstances = options.maxInstances; - - if (typeof maxInstances === "undefined"){ - maxInstances = 1; - } else { - delete options.maxInstances; + // If we are running in watch mode, and we have previously compiled + // the current file, then let the user know that `elm make` is running + // and can be slow + if (alreadyCompiledFiles.indexOf(resourcePath) > -1){ + console.log('Started compiling Elm...'); } - var intervalId = setInterval(function(){ - if (runningInstances >= maxInstances) return; - runningInstances += 1; - clearInterval(intervalId); - - // If we are running in watch mode, and we have previously compiled - // the current file, then let the user know that `elm make` is running - // and can be slow - if (alreadyCompiledFiles.indexOf(resourcePath) > -1){ - console.log('Started compiling Elm..'); - } - - var compilation = compile(files, options) - .then(function(v) { runningInstances -= 1; return { kind: 'success', result: v }; }) - .catch(function(v) { runningInstances -= 1; return { kind: 'error', error: v }; }); + var compilation = compile(files, options) + .then(function(v) { return { kind: 'success', result: v }; }) + .catch(function(v) { return { kind: 'error', error: v }; }); - promises.push(compilation); + promises.push(compilation); - Promise.all(promises) - .then(function(results) { + Promise.all(promises) + .then(function(results) { var output = results[results.length - 1]; // compilation output is always last if (output.kind === 'success') { - alreadyCompiledFiles.push(resourcePath); - callback(null, output.result); + alreadyCompiledFiles.push(resourcePath); + callback(null, output.result); } else { - if (typeof output.error === 'string') { - output.error = new Error(output.error); - } + if (typeof output.error === 'string') { + output.error = new Error(output.error); + } - output.error.message = 'Compiler process exited with error ' + output.error.message; - output.error.stack = null; - callback(output.error); + output.error.message = 'Compiler process exited with error ' + output.error.message; + output.error.stack = null; + callback(output.error); } - }).catch(function(err){ + }).catch(function(err){ callback(err); - }); - - }, 200); + }); }