Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 = elmCompiler.compileToString(files, options)
.then(function(v) { runningInstances -= 1; return { kind: 'success', result: v }; })
.catch(function(v) { runningInstances -= 1; return { kind: 'error', error: v }; });
promises.push(compilation);
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);
} else {
output.error.message = 'Compiler process exited with error ' + output.error.message;
callback(output.error);
}
build() {
let options = Object.assign({}, this.options);
let files = this.listFiles();
if (!files.length) {
// Nothing to build
return;
}
return compileToString(files, options)
.then(data => {
// elm-make output
let jsStr = data.toString();
// fix module exports
jsStr =
`
var elmScope = {};
(function() {
${jsStr}
}).call(elmScope)
export default elmScope.Elm;
`;
// build
const dir = path.join(this.outputPath, this.destDir);
var compile = function (filename) {
return compiler.compileToString([filename], {yes: true, cwd: fixturesDir})
.then(function (data) {
return [data.toString(), 'module.exports = Elm;'].join('\n');
});
}
var compile = function (filename) {
return compiler.compileToString([filename], {cwd: fixturesDir})
.then(function (data) {
return data.toString();
});
};
return new Promise((resolve, reject) => {
NodeElmCompiler.compileToString(...args)
.then(data => resolve({ type: 'ok', data }))
.catch(data => resolve({ type: 'error', data }))
})
}