hot-reload
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -9,2 +9,6 @@ // third-party dependencies | ||
function resolveFilename(filename) { | ||
if (filename.constructor !== String) { | ||
return filename; | ||
} | ||
if ((filename.charAt(0) !== '.') && (filename.charAt(0) !== '/')) { | ||
@@ -26,3 +30,3 @@ return filename; | ||
this.include(config.include); | ||
console.log('[Hot Reload] Watched directories: ' + JSON.stringify(this._includes)); | ||
console.log('[Hot Reload] Watched directories/files: ' + JSON.stringify(this._includes)); | ||
} | ||
@@ -59,3 +63,3 @@ | ||
self.emit('beforeReload'); | ||
var reloadableModules = []; | ||
@@ -68,3 +72,3 @@ | ||
if (self.isModuleReloadable(module)) { | ||
console.log('[Hot Reload] Unloading ' + module.filename); | ||
//console.log('[Hot Reload] Unloading ' + module.filename); | ||
// delete the cache entry only in first pass | ||
@@ -75,5 +79,9 @@ delete require.cache[key]; | ||
reloadableModules.push(module); | ||
} else { | ||
//console.log('[Hot Reload] Not unloading ' + module.filename); | ||
} | ||
} | ||
console.log('[Hot Reload] ' + reloadableModules.length + ' modules removed from cache.'); | ||
if (!config || (config.autoReload !== false)) { | ||
@@ -95,2 +103,16 @@ // SECOND PASS: Now trigger a reload of all of the modules since their cache entry was removed | ||
function matches(filter, name) { | ||
if (filter.constructor === RegExp) { | ||
// see if name matches regex | ||
if (filter.test(name)) { | ||
return true; | ||
} | ||
} else { | ||
// see if name starts with given filter value | ||
if (name.indexOf(filter) === 0) { | ||
return true; | ||
} | ||
} | ||
} | ||
HotReloader.prototype.isModuleReloadable = function(module) { | ||
@@ -103,3 +125,3 @@ | ||
var exclude = this._excludes[i]; | ||
if (filename.indexOf(exclude) === 0) { | ||
if (matches(exclude, filename)) { | ||
return false; | ||
@@ -113,3 +135,3 @@ } | ||
var exclude = this._neverReload[i]; | ||
if (filename.indexOf(exclude) === 0) { | ||
if (matches(exclude, filename)) { | ||
return false; | ||
@@ -123,3 +145,3 @@ } | ||
var include = this._alwaysReload[i]; | ||
if (filename.indexOf(include) === 0) { | ||
if (matches(include, filename)) { | ||
return true; | ||
@@ -133,3 +155,3 @@ } | ||
var include = this._includes[i]; | ||
if (filename.indexOf(include) === 0) { | ||
if (matches(include, filename)) { | ||
return true; | ||
@@ -158,2 +180,3 @@ } | ||
delete require.cache[module.filename]; | ||
var newModule = require(module.filename); | ||
@@ -168,3 +191,3 @@ | ||
} | ||
this.emit('afterModuleReload', module); | ||
@@ -188,3 +211,4 @@ } | ||
* for changes. Also, all Node.js modules within these directories | ||
* will automatically be reloaded if a file is changed. | ||
* will automatically be reloaded if a file is changed | ||
* (unless they are explicitly excluded). | ||
*/ | ||
@@ -252,3 +276,3 @@ HotReloader.prototype.include = function(includes) { | ||
// store the file path of the modulePaths that should always be reloaded | ||
// store the file path of the modulePaths that should never be reloaded | ||
this._neverReload.push(resolveFilename(modulePath)); | ||
@@ -267,11 +291,2 @@ } | ||
onFile : function(file) { | ||
console.log('[Hot Reload] Watching file: ' + file); | ||
fs.watch(file, | ||
function(event, changedFile) { | ||
console.log('[Hot Reload] File changed: ' + (changedFile || file)); | ||
self._scheduleReload(); | ||
}); | ||
}, | ||
onDirectory : function(directory) { | ||
@@ -281,3 +296,3 @@ console.log('[Hot Reload] Watching directory: ' + directory); | ||
function(event, file) { | ||
console.log('[Hot Reload] Directory changed: ' + file); | ||
console.log('[Hot Reload] Changed: ' + file); | ||
self._scheduleReload(); | ||
@@ -284,0 +299,0 @@ }); |
{ | ||
"name": "hot-reload", | ||
"description": "Triggers reloading of Node.js modules", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"homepage": "https://github.com/philidem/node-hot-reload", | ||
@@ -14,4 +14,4 @@ "authors": [ | ||
"dependencies": { | ||
"directory-walker" : "1.1.0" | ||
"directory-walker" : "1.2.x" | ||
} | ||
} |
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
43675
5
249
0
+ Addeddirectory-walker@1.2.5(transitive)
+ Addedpath-filters@1.0.6(transitive)
- Removeddirectory-walker@1.1.0(transitive)
Updateddirectory-walker@1.2.x