grunt-contrib-watch
Advanced tools
Comparing version 0.5.3 to 0.6.0
{ | ||
"name": "grunt-contrib-watch", | ||
"description": "Run predefined tasks whenever watched file patterns are added, changed or deleted.", | ||
"version": "0.5.3", | ||
"version": "0.6.0", | ||
"homepage": "https://github.com/gruntjs/grunt-contrib-watch", | ||
@@ -23,3 +23,2 @@ "author": { | ||
], | ||
"main": "Gruntfile.js", | ||
"engines": { | ||
@@ -32,10 +31,13 @@ "node": ">= 0.8.0" | ||
"dependencies": { | ||
"gaze": "~0.4.0", | ||
"tiny-lr": "0.0.4" | ||
"gaze": "~0.5.1", | ||
"tiny-lr-fork": "0.0.5", | ||
"lodash": "~2.4.1", | ||
"async": "~0.2.9" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.4.0", | ||
"grunt-contrib-jshint": "~0.4.3", | ||
"grunt-contrib-nodeunit": "~0.1.2", | ||
"grunt-contrib-internal": "~0.4.6" | ||
"grunt-contrib-jshint": "~0.8.0", | ||
"grunt-contrib-nodeunit": "~0.3.3", | ||
"grunt-contrib-internal": "~0.4.7", | ||
"underscore.string": "~2.3.3" | ||
}, | ||
@@ -48,3 +50,7 @@ "peerDependencies": { | ||
"watch" | ||
], | ||
"files": [ | ||
"tasks", | ||
"LICENSE-MIT" | ||
] | ||
} |
@@ -1,2 +0,2 @@ | ||
# grunt-contrib-watch v0.5.3 [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-watch.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-watch) | ||
# grunt-contrib-watch v0.6.0 [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-watch.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-watch) | ||
@@ -127,2 +127,22 @@ > Run predefined tasks whenever watched file patterns are added, changed or deleted. | ||
#### options.reload | ||
Type: `Boolean` | ||
Default: `false` | ||
By default, if `Gruntfile.js` is being watched, then changes to it will trigger the watch task to restart, and reload the `Gruntfile.js` changes. | ||
When `reload` is set to `true`, changes to *any* of the watched files will trigger the watch task to restart. | ||
This is especially useful if your `Gruntfile.js` is dependent on other files. | ||
```js | ||
watch: { | ||
configFiles: { | ||
files: [ 'Gruntfile.js', 'config/*.js' ], | ||
options: { | ||
reload: true | ||
} | ||
} | ||
} | ||
``` | ||
#### options.forever | ||
@@ -181,2 +201,35 @@ Type: `Boolean` | ||
It's possible to get livereload working over https connections. To do this, pass an object to `livereload` with a `key` and `cert` paths specified. | ||
Example: | ||
```js | ||
watch: { | ||
css: { | ||
files: '**/*.sass', | ||
tasks: ['sass'], | ||
options: { | ||
livereload: { | ||
port: 9000, | ||
key: grunt.file.read('path/to/ssl.key'), | ||
cert: grunt.file.read('path/to/ssl.crt') | ||
// you can pass in any other options you'd like to the https server, as listed here: http://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener | ||
} | ||
}, | ||
}, | ||
}, | ||
``` | ||
#### options.cwd | ||
Type: `String|Object` | ||
Default: `process.cwd()` | ||
Ability to set the current working directory. Defaults to `process.cwd()`. Can either be a string to set the cwd to match files and spawn tasks. Or an object to set each independently. Such as `options: { cwd: { files: 'match/files/from/here', spawn: 'but/spawn/files/from/here' } }`. | ||
#### options.livereloadOnError | ||
Type: `Boolean` | ||
Default: `true` | ||
Option to prevent the livereload if the executed tasks encountered an error. If set to `false`, the livereload will only be triggered if all tasks completed successfully. | ||
### Examples | ||
@@ -247,3 +300,5 @@ | ||
jshint: { | ||
all: ['lib/*.js'], | ||
all: { | ||
src: ['lib/*.js'], | ||
}, | ||
}, | ||
@@ -254,3 +309,3 @@ }); | ||
grunt.event.on('watch', function(action, filepath) { | ||
grunt.config(['jshint', 'all'], filepath); | ||
grunt.config('jshint.all.src', filepath); | ||
}); | ||
@@ -266,3 +321,3 @@ ``` | ||
var onChange = grunt.util._.debounce(function() { | ||
grunt.config(['jshint', 'all'], Object.keys(changedFiles)); | ||
grunt.config('jshint.all.src', Object.keys(changedFiles)); | ||
changedFiles = Object.create(null); | ||
@@ -328,3 +383,3 @@ }, 200); | ||
```html | ||
<script src="http://localhost:35729/livereload.js"></script> | ||
<script src="//localhost:35729/livereload.js"></script> | ||
``` | ||
@@ -393,3 +448,3 @@ | ||
#### Can I use this with Grunt v0.3? | ||
Yes. Although `grunt-contrib-watch` is a replacement watch task for Grunt v0.4, version `grunt-contrib-watch@0.1.x` is compatible with Grunt v0.3. `grunt-contrib-watch >= 0.2.x` is **only* compatible and recommended to use with Grunt v0.4. | ||
`grunt-contrib-watch@0.1.x` is compatible with Grunt v0.3 but it is highly recommended to upgrade Grunt instead. | ||
@@ -411,2 +466,3 @@ #### Why is the watch devouring all my memory/cpu? | ||
* 2014-03-11 v0.6.0 Clear changed files after triggering live reload to ensure they're only triggered once. cwd option now accepts separate settings for files and spawn. Fix to make interrupt work more than once. Enable live reload over HTTPS. Print newline after initial 'Waiting...' Remove deprecated grunt.util libs Add reload option to specify files other than Gruntfile files to reload. Update to gaze@0.5.1 Use fork of tiny-lr (which has quiter operation, support for HTTPS and windows path fixes) Add livereloadOnError, which if set to false will not trigger live reload if there is an error. | ||
* 2013-08-25 v0.5.3 Fixed for live reload missing files. | ||
@@ -437,2 +493,2 @@ * 2013-08-16 v0.5.2 Fixed issue running tasks after gruntfile is reloaded. Ignores empty file paths. | ||
*This file was generated on Sun Aug 25 2013 17:29:57.* | ||
*This file was generated on Tue Mar 11 2014 22:38:20.* |
@@ -5,3 +5,3 @@ /* | ||
* | ||
* Copyright (c) 2013 "Cowboy" Ben Alman, contributors | ||
* Copyright (c) 2014 "Cowboy" Ben Alman, contributors | ||
* Licensed under the MIT license. | ||
@@ -12,3 +12,4 @@ */ | ||
var tinylr = require('tiny-lr'); | ||
var tinylr = require('tiny-lr-fork'); | ||
var _ = require('lodash'); | ||
@@ -28,3 +29,3 @@ // Holds the servers out of scope in case watch is reloaded | ||
} else { | ||
options = grunt.util._.defaults(options, defaults); | ||
options = _.defaults(options, defaults); | ||
} | ||
@@ -34,3 +35,3 @@ if (servers[options.port]) { | ||
} else { | ||
this.server = tinylr(); | ||
this.server = tinylr(options); | ||
this.server.server.removeAllListeners('error'); | ||
@@ -37,0 +38,0 @@ this.server.server.on('error', function(err) { |
@@ -5,3 +5,3 @@ /* | ||
* | ||
* Copyright (c) 2013 "Cowboy" Ben Alman, contributors | ||
* Copyright (c) 2014 "Cowboy" Ben Alman, contributors | ||
* Licensed under the MIT license. | ||
@@ -24,3 +24,2 @@ */ | ||
this.files = target.files || []; | ||
this.tasks = target.tasks || []; | ||
this.options = target.options; | ||
@@ -30,7 +29,17 @@ this.startedAt = false; | ||
this.changedFiles = Object.create(null); | ||
if (typeof this.tasks === 'string') { | ||
this.tasks = [this.tasks]; | ||
this.spawnTaskFailure = false; | ||
this.livereloadOnError = true; | ||
if (typeof this.options.livereloadOnError !== 'undefined') { | ||
this.livereloadOnError = this.options.livereloadOnError; | ||
} | ||
} | ||
var getErrorCount = function(){ | ||
if (typeof grunt.fail.forever_warncount !== 'undefined') { | ||
return grunt.fail.forever_warncount + grunt.fail.forever_errorcount; | ||
} else { | ||
return grunt.fail.warncount + grunt.fail.errorcount; | ||
} | ||
}; | ||
// Run it | ||
@@ -46,2 +55,12 @@ TaskRun.prototype.run = function(done) { | ||
//reset before each run | ||
self.spawnTaskFailure = false; | ||
self.errorsAndWarningsCount = getErrorCount(); | ||
//pull the tasks here in case they were changed by a watch event listener | ||
self.tasks = grunt.config('watch' + (this.name === 'default' ? '' : '.' + this.name) + '.tasks') || []; | ||
if (typeof this.tasks === 'string') { | ||
self.tasks = [self.tasks]; | ||
} | ||
// If no tasks just call done to trigger potential livereload | ||
@@ -59,3 +78,3 @@ if (self.tasks.length < 1) { return done(); } | ||
opts: { | ||
cwd: self.options.cwd, | ||
cwd: self.options.cwd.spawn, | ||
stdio: 'inherit', | ||
@@ -66,5 +85,8 @@ }, | ||
}, function(err, res, code) { | ||
// Spawn is done | ||
self.spawned = null; | ||
done(); | ||
self.spawnTaskFailure = (code !== 0); | ||
if (self.options.interrupt !== true || (code !== 130 && code !== 1)) { | ||
// Spawn is done | ||
self.spawned = null; | ||
done(); | ||
} | ||
}); | ||
@@ -82,5 +104,10 @@ } | ||
} | ||
// Trigger livereload if set | ||
if (this.livereload) { | ||
var taskFailed = this.spawnTaskFailure || (getErrorCount() > this.errorsAndWarningsCount); | ||
this.errorsAndWarningsCount = getErrorCount(); | ||
// Trigger livereload if necessary | ||
if (this.livereload && (this.livereloadOnError || !taskFailed)) { | ||
this.livereload.trigger(Object.keys(this.changedFiles)); | ||
this.changedFiles = Object.create(null); | ||
} | ||
@@ -87,0 +114,0 @@ return time; |
@@ -5,3 +5,3 @@ /* | ||
* | ||
* Copyright (c) 2013 "Cowboy" Ben Alman, contributors | ||
* Copyright (c) 2014 "Cowboy" Ben Alman, contributors | ||
* Licensed under the MIT license. | ||
@@ -15,2 +15,4 @@ */ | ||
var util = require('util'); | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
@@ -59,2 +61,7 @@ // Track which targets to run after reload | ||
// Normalize cwd option | ||
if (typeof self.options.cwd === 'string') { | ||
self.options.cwd = { files: self.options.cwd, spawn: self.options.cwd }; | ||
} | ||
// Function to call when closing the task | ||
@@ -145,3 +152,3 @@ self.done = done || grunt.task.current.async(); | ||
// Additional cli args to append when spawning | ||
cliArgs: grunt.util._.without.apply(null, [[].slice.call(process.argv, 2)].concat(grunt.cli.tasks)), | ||
cliArgs: _.without.apply(null, [[].slice.call(process.argv, 2)].concat(grunt.cli.tasks)), | ||
interrupt: false, | ||
@@ -154,7 +161,7 @@ nospawn: false, | ||
}); | ||
return grunt.util._.defaults.apply(grunt.util._, args); | ||
return _.defaults.apply(_, args); | ||
}; | ||
// Run the current queue of task runs | ||
Runner.prototype.run = grunt.util._.debounce(function run() { | ||
Runner.prototype.run = _.debounce(function run() { | ||
var self = this; | ||
@@ -196,3 +203,3 @@ if (self.queue.length < 1) { | ||
var shouldComplete = true; | ||
grunt.util.async.forEachSeries(self.queue, function(name, next) { | ||
async.forEachSeries(self.queue, function(name, next) { | ||
var tr = self.targets[name]; | ||
@@ -294,3 +301,6 @@ if (!tr) { return next(); } | ||
} | ||
grunt.fail.forever_warncount = 0; | ||
grunt.fail.forever_errorcount = 0; | ||
grunt.warn = grunt.fail.warn = function(e) { | ||
grunt.fail.forever_warncount ++; | ||
var message = typeof e === 'string' ? e : e.message; | ||
@@ -303,2 +313,3 @@ grunt.log.writeln(('Warning: ' + message).yellow); | ||
grunt.fatal = grunt.fail.fatal = function(e) { | ||
grunt.fail.forever_errorcount ++; | ||
var message = typeof e === 'string' ? e : e.message; | ||
@@ -314,3 +325,3 @@ grunt.log.writeln(('Fatal error: ' + message).red); | ||
// each filepath is passed individually. | ||
var filepaths = typeof arguments[0] !== 'string' ? arguments[0] : grunt.util.toArray(arguments); | ||
var filepaths = typeof arguments[0] !== 'string' ? arguments[0] : Array.prototype.slice(arguments); | ||
// For each filepath, clear the require cache, if necessary. | ||
@@ -317,0 +328,0 @@ filepaths.forEach(function(filepath) { |
@@ -5,3 +5,3 @@ /* | ||
* | ||
* Copyright (c) 2013 "Cowboy" Ben Alman, contributors | ||
* Copyright (c) 2014 "Cowboy" Ben Alman, contributors | ||
* Licensed under the MIT license. | ||
@@ -12,2 +12,3 @@ */ | ||
var Gaze = require('gaze').Gaze; | ||
var _ = require('lodash'); | ||
var waiting = 'Waiting...'; | ||
@@ -34,3 +35,2 @@ var changedFiles = Object.create(null); | ||
taskrun.on('start', function() { | ||
grunt.log.ok(); | ||
Object.keys(changedFiles).forEach(function(filepath) { | ||
@@ -40,3 +40,2 @@ // Log which file has changed, and how. | ||
}); | ||
grunt.log.writeln(); | ||
// Reset changedFiles | ||
@@ -85,3 +84,3 @@ changedFiles = Object.create(null); | ||
if (taskrun.running === false) { grunt.log.write(waiting); } | ||
if (taskrun.running === false) { grunt.log.writeln(waiting); } | ||
@@ -95,3 +94,3 @@ // initialize taskrun | ||
// Process into raw patterns | ||
var patterns = grunt.util._.chain(target.files).flatten().map(function(pattern) { | ||
var patterns = _.chain(target.files).flatten().map(function(pattern) { | ||
return grunt.config.process(pattern); | ||
@@ -105,2 +104,7 @@ }).value(); | ||
// Set cwd if options.cwd.file is set | ||
if (typeof target.options.cwd !== 'string' && target.options.cwd.files) { | ||
target.options.cwd = target.options.cwd.files; | ||
} | ||
// Create watcher per target | ||
@@ -129,4 +133,4 @@ watchers.push(new Gaze(patterns, target.options, function(err) { | ||
// Skip events not specified | ||
if (!grunt.util._.contains(target.options.event, 'all') && | ||
!grunt.util._.contains(target.options.event, status)) { | ||
if (!_.contains(target.options.event, 'all') && | ||
!_.contains(target.options.event, status)) { | ||
return; | ||
@@ -143,3 +147,3 @@ } | ||
// If Gruntfile.js changed, reload self task | ||
if (/gruntfile\.(js|coffee)/i.test(filepath)) { | ||
if (target.options.reload || /gruntfile\.(js|coffee)/i.test(filepath)) { | ||
taskrun.reload = true; | ||
@@ -146,0 +150,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
486
0
1
43670
5
5
7
594
+ Addedasync@~0.2.9
+ Addedlodash@~2.4.1
+ Addedtiny-lr-fork@0.0.5
+ Addedasync@0.2.10(transitive)
+ Addedgaze@0.5.2(transitive)
+ Addedtiny-lr-fork@0.0.5(transitive)
- Removedtiny-lr@0.0.4
- Removedgaze@0.4.3(transitive)
- Removedtiny-lr@0.0.4(transitive)
Updatedgaze@~0.5.1