Comparing version 0.2.2 to 0.2.3
43
index.js
@@ -31,3 +31,7 @@ 'use strict'; | ||
if (err) { | ||
cb(err); | ||
if (err.code === 'ENOENT') { | ||
cb(null, file); | ||
} else { | ||
cb(err); | ||
} | ||
return; | ||
@@ -60,3 +64,7 @@ } | ||
if (err) { | ||
cb(err); | ||
if (err.code === 'ENOENT') { | ||
cb(null, file); | ||
} else { | ||
cb(err); | ||
} | ||
return; | ||
@@ -88,3 +96,5 @@ } | ||
function statSync(file) { | ||
utils.fileExists(file); | ||
var stat; | ||
Object.defineProperty(file, 'stat', { | ||
@@ -96,3 +106,10 @@ configurable: true, | ||
get: function() { | ||
return stat || (stat = utils.fs.statSync(this.path)); | ||
if (stat) { | ||
return stat; | ||
} | ||
if (this.exists) { | ||
stat = utils.fs.statSync(this.path); | ||
return stat; | ||
} | ||
return null; | ||
} | ||
@@ -120,3 +137,5 @@ }); | ||
function lstatSync(file) { | ||
utils.fileExists(file); | ||
var lstat; | ||
Object.defineProperty(file, 'lstat', { | ||
@@ -128,3 +147,10 @@ configurable: true, | ||
get: function() { | ||
return lstat || (lstat = utils.fs.lstatSync(this.path)); | ||
if (lstat) { | ||
return lstat; | ||
} | ||
if (this.exists) { | ||
lstat = utils.fs.lstatSync(this.path); | ||
return lstat; | ||
} | ||
return null; | ||
} | ||
@@ -139,3 +165,10 @@ }); | ||
get: function() { | ||
return lstat || (lstat = utils.fs.lstatSync(this.path)); | ||
if (lstat) { | ||
return lstat; | ||
} | ||
if (this.exists) { | ||
lstat = utils.fs.lstatSync(this.path); | ||
return lstat; | ||
} | ||
return null; | ||
} | ||
@@ -142,0 +175,0 @@ }); |
{ | ||
"name": "file-stat", | ||
"description": "Set the `stat` property on a file object. Abstraction from vinyl-fs to support stream or non-stream usage.", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"homepage": "https://github.com/jonschlinkert/file-stat", | ||
@@ -24,2 +24,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"fs-exists-sync": "^0.1.0", | ||
"graceful-fs": "^4.1.4", | ||
@@ -26,0 +27,0 @@ "lazy-cache": "^2.0.1", |
23
utils.js
@@ -13,8 +13,23 @@ 'use strict'; | ||
require('through2', 'through'); | ||
require('fs-exists-sync', 'exists'); | ||
require = fn; | ||
/** | ||
* Reset require | ||
*/ | ||
utils.fileExists = function(file) { | ||
if ('exists' in file) return; | ||
var exists; | ||
require = fn; | ||
Object.defineProperty(file, 'exists', { | ||
configurable: true, | ||
set: function(val) { | ||
exists = val; | ||
}, | ||
get: function fn() { | ||
if (typeof exists === 'boolean') { | ||
return exists; | ||
} | ||
exists = utils.exists(this.path); | ||
return exists; | ||
} | ||
}); | ||
}; | ||
@@ -21,0 +36,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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
6860
195
4
3
+ Addedfs-exists-sync@^0.1.0
+ Addedfs-exists-sync@0.1.0(transitive)