rtfeldman/grunt-elm

Adding the task in middle of task chain ends the main task at the elm task

Opened this issue · 2 comments

Here is my gruntfile:

module.exports = (grunt) => {
    grunt.initConfig({
        elm: {
            compile: {
                files: {
                    'dist/index.js': `src/Index.elm`
                }
            }
        },
        copy: {
            main: {
                expand: true,
                cwd: 'src/',
                src: [ 'index.html', 'index.css' ],
                dest: 'dist/'
            },
        },
        'http-server': {
            dev: {
                root: 'dist/',
                port: 8000,
                openBrowser: false
            }
        }
    });

    grunt.loadNpmTasks('grunt-elm');
    grunt.loadNpmTasks('grunt-http-server');
    grunt.loadNpmTasks('grunt-contrib-copy');

    grunt.registerTask('default', ['copy', 'elm']);
    grunt.registerTask('build-serve', ['copy:main', 'elm:compile', 'http-server:dev']);
};

When I run the default task, it runs as expected. When I run build-serve task, it reaches the elm:compile but it does not run http-server:dev task. I am doing something wrong?

Same for me, if I add elm task in between of the others, even if it's successful the whole chain is stopped immediately.

I tried to dig into this, and it turned out that grunt-elm plugin fails to propagate custom function spawn to node-elm-compiler

the fix could be exactly this:

function compileSync(sources, options) {
  - var optionsWithDefaults = prepareOptions(options, spawn.sync);
  + var optionsWithDefaults = prepareOptions(options, options.spawn || spawn.sync); // just take spawn from options if it was provided
 ...
}

function compile(sources, options) {
  - var optionsWithDefaults = prepareOptions(options, spawn);
  + var optionsWithDefaults = prepareOptions(options, options.spawn || spawn); // just take spawn from options if it was provided
  ...
}

but the fix is needed to be implemented on the node-elm-compiler project, because there it just takes default spawn func during compilcation

var spawn = require("cross-spawn");

and this default spawn function is set via prepareOptions:

function prepareOptions(options, spawnFn) {
  return _.defaults({ spawn: spawnFn }, options, defaultOptions);
}

For me after modifying those lines with || grunt was happy and successfully run all the remaining steps
Hopefully I explained it nicely, sorry if not :)