hot-file-cache
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -0,1 +1,8 @@ | ||
## 0.0.5 | ||
- BREAKING CHANGE: `getFiles` returns absolute paths | ||
- `readFile` throws if pattern does not match | ||
- `fileExists` throws if pattern does not match | ||
- add `isFileWatched` | ||
## 0.0.4 | ||
@@ -2,0 +9,0 @@ |
23
index.js
@@ -29,3 +29,3 @@ var path = require('path'); | ||
watcher.on('add', function (file) { | ||
this.watched.push(file); | ||
this.watched.push(path.join(this.options.cwd, file)); | ||
}.bind(this)); | ||
@@ -51,6 +51,7 @@ watcher.on('unlink', function (file) { | ||
HotFileCache.prototype.fileExists = function (file) { | ||
var relativeFile = path.relative(this.options.cwd, file); | ||
return this.watcher.then(function (watcher) { | ||
var files = watcher.getWatched(); | ||
return files[path.dirname(relativeFile) || '.'].indexOf(path.basename(relativeFile)) !== -1; | ||
if (!this.isFileWatched(file)) { | ||
throw new Error('File ' + file + ' does not match any pattern'); | ||
} | ||
return this.getFiles().then(function (files) { | ||
return files.indexOf(file) !== -1; | ||
}); | ||
@@ -74,4 +75,4 @@ }; | ||
var relativeFile = path.relative(this.options.cwd, file); | ||
if (!globule.isMatch(this.patterns, relativeFile)) { | ||
return Promise.reject('File ' + file + ' does not match any pattern'); | ||
if (!this.isFileWatched(file)) { | ||
throw new Error('File ' + file + ' does not match any pattern'); | ||
} | ||
@@ -96,2 +97,10 @@ return this.watcher.then(function () { | ||
/** | ||
* Returns true if the given file matches the current patterns. | ||
*/ | ||
HotFileCache.prototype.isFileWatched = function (file) { | ||
var relativeFile = path.relative(this.options.cwd, file); | ||
return globule.isMatch(this.patterns, relativeFile); | ||
}; | ||
/** | ||
* invalidate cache | ||
@@ -98,0 +107,0 @@ */ |
{ | ||
"name": "hot-file-cache", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A file cache for development which will invalidate automatically if the source changes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -42,3 +42,7 @@ Hot File Cache | ||
Options: | ||
All options except the `fileProcessor` are equal to [chokidar](https://github.com/paulmillr/chokidar#getting-started). | ||
# Changelog | ||
@@ -45,0 +49,0 @@ |
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
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
6612
101
59