tschaub / grunt-newer

Configure Grunt tasks to run with newer files only.
https://npmjs.org/package/grunt-newer
MIT License
944 stars 53 forks source link

Run "compass" from "watch" through "newer" when '@import'-ed file has changed #55

Open numediaweb opened 10 years ago

numediaweb commented 10 years ago

in my Grunt file I have:

..

        compass: {
            dest: {
                outputStyle: 'compact',
                relativeAssets: true,
                files: {
                    '<%= destFolder %>/assets/css/main.css': "src/assets/scss/main.scss",
                }
            }
        },
        watch: {
            compass: {
                files: ['src/assets/scss/**/*.scss'],
                tasks: ['newer:compass:dest']
            }
        }
..

When I edit a partial *.scss, the "watch" task detects the changes but the "newer" task thinks nothing has changed so it doesn't run the compass on "main.scss".

I have seen an issue here #35 similar but with less.. is there any fix for sass?

numediaweb commented 10 years ago

I think newer is not suitable for compass in this case; I have only one main file "main.scss" that imports the rest of partials.. Which means I need to "compass" it all the time!

numediaweb commented 10 years ago

I also tested it with Assemble and seems not working either; Assemble uses partials and layouts (the same way SASS uses imports) to compile pages.. when I update a partial, the watch task detects the change but "grunt-newer" ignores to run the assemble command because the layout didn't change.. So not really suitable for Assemble and SASS! (unless I'm missing something!)

grayghostvisuals commented 10 years ago

:+1:

jzaefferer commented 9 years ago

The documentation mentions an "override" option to check for partials: https://github.com/tschaub/grunt-newer#optionsoverride

Unfortunately implementing that checkForModifiedImports function is left as a non-trivial exercise for the reader. I'm wondering if there's a reference implementation somewhere.

eush77 commented 9 years ago

Just encountered the same problem with Browserify.

@jzaefferer checkForModifiedImports is a placeholder.

According to the docs, override function is called with the file that is being considered “older” and can force it to be included anyways.

The default value for this option is the following. It won't affect anything.

function nullOverride(details, include) {
  include(false);
}

The simplest non-trivial thing is to include all files for the task no matter what.

grunt.config('newer', {
  options: {
    override: function (detail, include) {
      if (detail.task == 'browserify') {
        include(true);
      }
      else {
        include(false);
      }
    }
  }
});

Of course it is the same as not using grunt-newer for this task at all.

You can include some files in every build but still use grunt-newer to deal with the rest.

grunt.config('newer', {
  options: {
    override: function (detail, include) {
      if (detail.task == 'browserify') {
        if (detail.path.match('^lib/')) {
          include(true);
        }
        else {
          include(false);
        }
      }
      else {
        include(false);
      }
    }
  }
});

Important thing to remember is that grunt-newer will fire this function only for those files that are listed in the src config field for the task.

JoshBeveridge commented 9 years ago

Has anyone come up with a solution for this? I'm trying to use grunt-newer in a similar capacity with PostCSS where I have imported partials compiling the parent files by default. I suppose it would be difficult to check which files import the edited partial and then have grunt-newer check against those parents instead.

tfrommen commented 8 years ago

Hi there,

I just posted something over here, which might be of interest to you.

@eush77 @grayghostvisuals @joshdrink @jzaefferer

CodySchaaf commented 8 years ago

All these work arounds seem to just be doing newers job twice (like checking the mtime). Are the changed files not available to just pass into the override method?

ConeyIsland commented 6 years ago

Are we going to enter in 2018 with this feature (bug)? Solution with override is awful I think. It should be option with true/false value.

tschaub commented 6 years ago

@MonoStas - I think the answer to your question is yes. Unless someone contributes a solution.

tschaub commented 6 years ago

(Unintentionally closed after leaving that comment.)