Skip to content

Commit

Permalink
Remove maxInstances and cache options.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinheghan committed Aug 26, 2020
1 parent e3a1598 commit d4ec59a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 78 deletions.
40 changes: 0 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
59 changes: 21 additions & 38 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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);
});
}


Expand Down

0 comments on commit d4ec59a

Please sign in to comment.