Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newer not working properly with watch #8

Merged
merged 1 commit into from
Sep 21, 2013
Merged

newer not working properly with watch #8

merged 1 commit into from
Sep 21, 2013

Conversation

tschaub
Copy link
Owner

@tschaub tschaub commented Sep 21, 2013

hello,

It seems that the first time newer runs from the watch, it calls grunt.config.set([name, [target], config). here config has the newer files. After that, in all repeat runs, grunt.config.get([name, target]) gets the above set config with only the newer files. Now, if I change any other files that affect this particular task, newer won't pick it up. Please let me know if you need me to send an example grunt config.

Thanks,

Nachiket

@tschaub
Copy link
Owner

tschaub commented Sep 19, 2013

To use grunt-newer and grunt-contrib-watch together, you should prepend the tasks that you watch with newer instead of prepending watch itself with newer. Here is an example configuration:

  var srcFiles = 'src/**/*.js';

  grunt.initConfig({
    jshint: {
      all: {
        src: srcFiles
      }
    },
    watch: {
      all: {
        files: srcFiles,
        tasks: ['newer:jshint:all']
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-newer');

Above, the watch:all target is configured to watch all src/**/*.js. When a file that matches that pattern changes, jshint:all is configured to run with just the modified files. But the watch:all target configuration is not changed.

Is this similar to what you are trying to accomplish?

@johnyb
Copy link

johnyb commented Sep 19, 2013

We just ran into (may be another) problem with watch and newer. Our config looked something like:

  grunt.initConfig({
    jshint: {
      all: {
        src: ['Gruntfile.js', 'apps/**/*.js']
      }
    },
    watch: {
      all: {
        files: ['<%= jshint.all.src %>'],
        tasks: ['newer:jshint:all']
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-newer');

So basically the same as yours, but without the use of an external variable, but use of the internal grunt templating system. Any hint on how to fix this? (For now, we might stick with the extra variable, but we’d like to avoid it.)

@tschaub
Copy link
Owner

tschaub commented Sep 19, 2013

@johnyb can you provide more detail on the issue that you're seeing with this config? I'm seeing the same behavior when I use a variable or the template syntax. And you can grunt --verbose watch:all for additional output on the file configuration before each task is run.

@tschaub
Copy link
Owner

tschaub commented Sep 20, 2013

Ok, I've been able to reproduce this with a new task that composes the above tasks:

    grunt.registerTask('lint-then-watch', ['newer:jshint', 'watch']);

To support template syntax for the files configuration in this case, the jshint:all configuration would have to be reset after a successful run. I can work up a fix for this.

@johnyb
Copy link

johnyb commented Sep 20, 2013

I’m very new to grunt (we just started porting a larger app this week), so I’m not quite sure what exactly is happening. Anyway, thanks for taking a look! :)

This allows tasks to be created that compose newer-prefixed tasks with other tasks that might be configured with Grunt's template syntax to use the same config.  For example a task called `lint-then-watch` might be registered that composes `newer:jshint` and `watch`.  If the `watch` targets use template syntax to get the file config from the `jshint` targets, the `jshint` targets must be reconfigured after being run with a modified configuration.
tschaub added a commit that referenced this pull request Sep 21, 2013
Reconfigure modified targets after successful runs.  This allows composed tasks to use template syntax for files config.
@tschaub tschaub merged commit a3955c1 into master Sep 21, 2013
@tschaub tschaub deleted the reconfig branch September 21, 2013 15:58
@tschaub
Copy link
Owner

tschaub commented Sep 21, 2013

Released as [email protected]. Please open another issue if you find issues with that version.

@johnyb
Copy link

johnyb commented Sep 23, 2013

Works like a charm, now :) 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants