Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-contrib-watch

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-contrib-watch - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

8

docs/watch-examples.md

@@ -37,3 +37,3 @@ # Examples

## Using the `watch` event
This task will emit a `watch` event when watched files are modified. This is useful if you would like a simple notification when files are edited or if you're using this task in tandem with another task, for example a live reload task. Here is a simple example using the `watch` event:
This task will emit a `watch` event when watched files are modified. This is useful if you would like a simple notification when files are edited or if you're using this task in tandem with another task. Here is a simple example using the `watch` event:

@@ -45,3 +45,2 @@ ```js

files: ['lib/*.js'],
tasks: [''],
},

@@ -148,2 +147,4 @@ },

Feel free to add this script to your template situation and toggle with some sort of `dev` flag.
### Using Live Reload with the Browser Extension

@@ -154,2 +155,5 @@ Instead of adding a script tag to your page, you can live reload your page by installing a browser extension. Please visit [how do I install and use the browser extensions](http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-) for help installing an extension for your browser.

### Using Connect Middleware
Since live reloading is used when developing, you may want to disable building for production (and are not using the browser extension). One method is to use Connect middleware to inject the script tag into your page. Try the [connect-livereload](https://github.com/intesso/connect-livereload) middleware for injecting the live reload script into your page.
# FAQs

@@ -156,0 +160,0 @@

{
"name": "grunt-contrib-watch",
"description": "Run predefined tasks whenever watched file patterns are added, changed or deleted.",
"version": "0.4.0",
"version": "0.4.1",
"homepage": "https://github.com/gruntjs/grunt-contrib-watch",

@@ -6,0 +6,0 @@ "author": {

@@ -188,3 +188,3 @@ # grunt-contrib-watch [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-watch.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-watch)

#### Using the `watch` event
This task will emit a `watch` event when watched files are modified. This is useful if you would like a simple notification when files are edited or if you're using this task in tandem with another task, for example a live reload task. Here is a simple example using the `watch` event:
This task will emit a `watch` event when watched files are modified. This is useful if you would like a simple notification when files are edited or if you're using this task in tandem with another task. Here is a simple example using the `watch` event:

@@ -196,3 +196,2 @@ ```js

files: ['lib/*.js'],
tasks: [''],
},

@@ -299,2 +298,4 @@ },

Feel free to add this script to your template situation and toggle with some sort of `dev` flag.
##### Using Live Reload with the Browser Extension

@@ -305,2 +306,5 @@ Instead of adding a script tag to your page, you can live reload your page by installing a browser extension. Please visit [how do I install and use the browser extensions](http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-) for help installing an extension for your browser.

##### Using Connect Middleware
Since live reloading is used when developing, you may want to disable building for production (and are not using the browser extension). One method is to use Connect middleware to inject the script tag into your page. Try the [connect-livereload](https://github.com/intesso/connect-livereload) middleware for injecting the live reload script into your page.
### FAQs

@@ -327,2 +331,3 @@

* 2013-05-09   v0.4.1   Removed "beep" notification. Tasks now optional with livereload option. Reverted "run again" with interrupt off to fix infinite recursion issue. Watchers now close more properly on task run.
* 2013-05-03   v0.4.0   Option livereload to start live reload servers. Will reload a Gruntfile before running tasks if Gruntfile is modified. Option event to only trigger watch on certain events. Refactor watch task into separate task runs per target. Option forever to override grunt.fatal/warn to help keeping the watch alive with nospawn enabled. Emit a beep upon complete. Logs all watched files with verbose flag set. If interrupt is off, will run the tasks once more if watch triggered during a previous task run. tasks property is optional for use with watch event. Watchers properly closed when exiting.

@@ -345,2 +350,2 @@ * 2013-02-28   v0.3.1   Fix for top level options.

*This file was generated on Fri May 03 2013 10:06:32.*
*This file was generated on Thu May 09 2013 08:56:33.*

@@ -32,2 +32,11 @@ /*

this.server = tinylr();
this.server.server.removeAllListeners('error');
this.server.server.on('error', function(err) {
if (err.code === 'EADDRINUSE') {
grunt.fatal('Port ' + options.port + ' is already in use by another process.');
} else {
grunt.fatal(err);
}
process.exit(1);
});
this.server.listen(options.port, function(err) {

@@ -34,0 +43,0 @@ if (err) { return grunt.fatal(err); }

@@ -37,3 +37,8 @@ /*

// Start this task run
self.startedAt = Date.now();
// If no tasks just call done to trigger potential livereload
if (self.tasks.length < 1) { return done(); }
if (self.options.nospawn === true) {

@@ -40,0 +45,0 @@ grunt.task.run(self.tasks);

@@ -45,4 +45,2 @@ /*

this.changedFiles = Object.create(null);
// Flag to set if interrupt is false and a change happened during a task run
this.needsAnotherRun = false;
}

@@ -154,3 +152,2 @@ util.inherits(Runner, EE);

// Dont interrupt the tasks running
self.needsAnotherRun = true;
return;

@@ -223,3 +220,2 @@ }

self.running = false;
var time = 0;

@@ -231,15 +227,11 @@ self._queue.forEach(function(name, i) {

time += target.complete();
if (self.needsAnotherRun !== true) {
self._queue[i] = null;
self._queue[i] = null;
// if we're just livereloading and no tasks
// it can happen too fast and we dont report it
if (target.options.livereload && target.tasks.length < 1) {
time += 0.0001;
}
}
});
// If it needs another run
if (self.needsAnotherRun === true) {
self.needsAnotherRun = false;
self.run();
return;
}
var elapsed = (time > 0) ? Number(time / 1000) : 0;

@@ -246,0 +238,0 @@ self.changedFiles = Object.create(null);

@@ -27,2 +27,3 @@ /*

});
grunt.log.writeln();
taskrun.changedFiles = changedFiles;

@@ -36,4 +37,3 @@ // Reset changedFiles

if (time > 0) {
var beep = (!grunt.option('no-color')) ? '\x07' : '';
grunt.log.writeln(beep).write(String(
grunt.log.writeln(String(
'Completed in ' +

@@ -60,7 +60,3 @@ time.toFixed(3) +

process.on('SIGINT', function() {
grunt.log.writeln('').write('Shutting down the watch task...');
watchers.forEach(function(watcher) {
watcher.close();
});
grunt.log.ok();
grunt.log.writeln('').write('Shutting down the watch task...').ok();
process.exit();

@@ -73,2 +69,8 @@ });

// Close any previously opened watchers
watchers.forEach(function(watcher, i) {
watcher.close();
watchers.splice(i, 1);
});
// Never gonna give you up, never gonna let you down

@@ -142,8 +144,6 @@ if (grunt.config([name, 'options', 'forever']) !== false) {

// Run tasks if any have been specified
if (target.tasks) {
changedFiles[filepath] = status;
taskrun.queue(target.name);
taskrun.run();
}
// Run tasks
changedFiles[filepath] = status;
taskrun.queue(target.name);
taskrun.run();
});

@@ -150,0 +150,0 @@

@@ -24,7 +24,15 @@ module.exports = function(grunt) {

grunt.registerTask('warn', function() {
grunt.warn('This task should warn!');
var done = this.async();
setTimeout(function() {
grunt.warn('This task should warn!');
done();
}, 1);
});
grunt.registerTask('fatal', function() {
grunt.fatal('This task should be fatal!');
var done = this.async();
setTimeout(function() {
grunt.fatal('This task should be fatal!');
done();
}, 1);
});
};

@@ -30,2 +30,5 @@ module.exports = function(grunt) {

},
notasks: {
files: ['lib/*.js'],
},
},

@@ -32,0 +35,0 @@ });

@@ -5,3 +5,3 @@ /*

*
* Copyright (c) 2013 "Cowboy" Ben Alman, contributors
* Copyright (c) 2012 "Cowboy" Ben Alman, contributors
* Licensed under the MIT license.

@@ -14,3 +14,3 @@ */

var msg = this.data.message || 'I do absolutely nothing.';
var wait = this.data.wait || grunt.option('wait') || 0;
var wait = this.data.wait || 0;
var fail = this.data.fail || false;

@@ -17,0 +17,0 @@ var done = this.async();

@@ -101,3 +101,3 @@ 'use strict';

test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
test.ok(result.indexOf('Live reload server started on port: 1337') !== -1, 'live reload server should have been started on port 35729.');
test.ok(result.indexOf('Live reload server started on port: 1337') !== -1, 'live reload server should have been started on port 1337.');
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');

@@ -109,2 +109,22 @@ resultData = JSON.parse(resultData);

},
notasks: function(test) {
test.expect(3);
var resultData = '';
var cwd = path.resolve(fixtures, 'livereload');
var assertWatch = helper.assertTask(['watch:notasks', '-v'], {cwd: cwd});
assertWatch([function() {
request(35729, function(data) {
resultData += data;
grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;');
});
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('Live reload server started on port: 35729') !== -1, 'live reload server should have been started on port 35729.');
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
resultData = JSON.parse(resultData);
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
test.done();
});
},
};

@@ -128,21 +128,3 @@ 'use strict';

});
},
runAgainNotInterrupted: function(test) {
test.expect(1);
var cwd = path.resolve(fixtures, 'multiTargets');
var assertWatch = helper.assertTask(['watch:one', '--wait=4000'], {cwd:cwd});
assertWatch([function() {
grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var test = true;');
setTimeout(function() {
grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var test = true;');
}, 2000);
setTimeout(function() {
grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var test = true;');
}, 3000);
}], function(result) {
helper.verboseLog(result);
test.equal(grunt.util._(result).count('one has changed'), 2, 'Should have ran the one task twice.');
test.done();
});
},
}
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc