Socket
Socket
Sign inDemoInstall

wrench

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrench - npm Package Compare versions

Comparing version 1.5.1 to 1.5.3

152

lib/wrench.js

@@ -17,3 +17,2 @@ /* wrench.js

/* wrench.readdirSyncRecursive("directory_path");

@@ -125,2 +124,4 @@ *

/* wrench.rmdirSyncRecursive("directory_path", forceDelete, failSilent);

@@ -161,2 +162,51 @@ *

function isFileIncluded(opts, dir, filename) {
function isMatch(filter) {
if (typeof filter === 'function') {
return filter(filename, dir) === true;
}
else {
// Maintain backwards compatibility and use just the filename
return filename.match(filter);
}
}
if (opts.include || opts.exclude) {
if (opts.exclude) {
if (isMatch(opts.exclude)) {
return false;
}
}
if (opts.include) {
if (isMatch(opts.include)) {
return true;
}
else {
return false;
}
}
return true;
}
else if (opts.filter) {
var filter = opts.filter;
if (!opts.whitelist) {
// if !opts.whitelist is false every file or directory
// which does match opts.filter will be ignored
return isMatch(filter) ? false : true;
} else {
// if opts.whitelist is true every file or directory
// which doesn't match opts.filter will be ignored
return !isMatch(filter) ? false : true;
}
}
return true;
}
/* wrench.copyDirSyncRecursive("directory_to_copy", "new_directory_location", opts);

@@ -171,10 +221,12 @@ *

exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
opts = opts || {};
try {
if(fs.statSync(newDirLocation).isDirectory()) {
if(typeof opts !== 'undefined' && opts.forceDelete) {
exports.rmdirSyncRecursive(newDirLocation);
} else {
return new Error('You are trying to delete a directory that already exists. Specify forceDelete in the opts argument to override this. Bailing~');
}
}
if(fs.statSync(newDirLocation).isDirectory()) {
if(typeof opts !== 'undefined' && opts.forceDelete) {
exports.rmdirSyncRecursive(newDirLocation);
} else {
return new Error('You are trying to delete a directory that already exists. Specify forceDelete in the opts argument to override this. Bailing~');
}
}
} catch(e) { }

@@ -192,9 +244,14 @@

var files = fs.readdirSync(sourceDir);
var hasFilter = opts.filter || opts.include || opts.exclude;
var preserveFiles = opts.preserveFiles === true;
for(var i = 0; i < files.length; i++) {
// ignores all files or directories which match the RegExp in opts.filter
if(typeof opts !== 'undefined') {
if(!opts.whitelist && opts.filter && files[i].match(opts.filter)) continue;
// if opts.whitelist is true every file or directory which doesn't match opts.filter will be ignored
if(opts.whitelist && opts.filter && !files[i].match(opts.filter)) continue;
if(typeof opts !== 'undefined') {
if (hasFilter) {
if (!isFileIncluded(opts, sourceDir, files[i])) {
continue;
}
}
if (opts.excludeHiddenUnix && /^\./.test(files[i])) continue;

@@ -210,2 +267,4 @@ }

fs.writeFileSync(destFile, contents);
var stat = fs.lstatSync(srcFile);
fs.chmodSync(destFile, stat.mode);
};

@@ -298,25 +357,33 @@

exports.rmdirRecursive = function rmdirRecursive(dir, failSilent, clbk){
fs.readdir(dir, function(err, files){
if(clbk === null || typeof clbk == 'undefined')
clbk = function(err) {};
fs.readdir(dir, function(err, files) {
if(err && typeof failSilent === 'boolean' && !failSilent)
return clbk(err);
return clbk(err);
if(typeof failSilent === 'function')
clbk = failSilent;
<<<<<<< HEAD
if(typeof failSilent === 'function')
clbk = failSilent;
=======
if(typeof failSilent === 'function')
clbk = failSilent;
>>>>>>> 7827a700ff8cb8b742e401e9876e86a63ae0c68a
(function rmFile(err){
if (err) return clbk(err);
(function rmFile(err){
if (err) return clbk(err);
var filename = files.shift();
if (filename === null || typeof filename == 'undefined')
return fs.rmdir(dir, clbk);
var filename = files.shift();
if (filename === null || typeof filename == 'undefined')
return fs.rmdir(dir, clbk);
var file = dir+'/'+filename;
fs.lstat(file, function(err, stat){
if (err) return clbk(err);
if (stat.isDirectory())
rmdirRecursive(file, rmFile);
else
fs.unlink(file, rmFile);
});
})();
var file = dir+'/'+filename;
fs.lstat(file, function(err, stat){
if (err) return clbk(err);
if (stat.isDirectory())
rmdirRecursive(file, rmFile);
else
fs.unlink(file, rmFile);
});
})();
});

@@ -333,8 +400,13 @@ };

exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, opts, clbk) {
var originalArguments = Array.prototype.slice.apply(arguments);
srcDir = _path.normalize(srcDir);
newDir = _path.normalize(newDir);
fs.stat(newDir, function(err, newDirStat){
if(!err) {
<<<<<<< HEAD
if(typeof opts !== 'undefined' && typeof opts !== 'function' && opts.forceDelete)
return exports.rmdirRecursive(newDir, function(err){
copyDirRecursive.apply(this, arguments);
});
return exports.rmdirRecursive(newDir, function(err) {
copyDirRecursive.apply(this, originalArguments);
});
else

@@ -346,3 +418,15 @@ return clbk(new Error('You are trying to delete a directory that already exists. Specify forceDelete in an options object to override this.'));

clbk = opts;
=======
if(typeof opts !== 'undefined' && typeof opts !== 'function' && opts.forceDelete)
return exports.rmdirRecursive(newDir, function(err){
copyDirRecursive.apply(this, arguments);
});
else
return clbk(new Error('You are trying to delete a directory that already exists. Specify forceDelete in an options object to override this.'));
}
if(typeof opts === 'function')
clbk = opts;
>>>>>>> 7827a700ff8cb8b742e401e9876e86a63ae0c68a
fs.stat(srcDir, function(err, srcDirStat){

@@ -446,3 +530,3 @@ if (err) return clbk(err);

var lineEnd = this.buffer.indexOf("\n"),
result = this.buffer.substring(0, lineEnd ? lineEnd : this.buffer.length);
result = this.buffer.substring(0, lineEnd != -1 ? lineEnd : this.buffer.length);

@@ -449,0 +533,0 @@ this.buffer = this.buffer.substring(result.length + 1, this.buffer.length);

{
"name": "wrench",
"description": "Recursive filesystem (and other) operations that Node *should* have.",
"version": "1.5.1",
"version": "1.5.3",
"author": "Ryan McGrath <ryan@venodesigns.net>",

@@ -6,0 +6,0 @@

@@ -69,6 +69,12 @@ wrench.js - Recursive file operations in Node.js

inflateSymlinks: bool, // Whether to follow symlinks or not when copying files
filter: regexp, // A filter to match files against; if matches, do nothing (exclude).
filter: regexpOrFunction, // A filter to match files against; if matches, do nothing (exclude).
whitelist: bool, // if true every file or directory which doesn't match filter will be ignored
include: regexpOrFunction, // An include filter (either a regexp or a function)
exclude: regexpOrFunction // An exclude filter (either a regexp or a function)
});
// Note: If a RegExp is provided then then it will be matched against the filename. If a function is
// provided then the signature should be the following:
// function(filename, dir) { return result; }
// Read lines in from a file until you hit the end

@@ -75,0 +81,0 @@ var f = new wrench.LineReader('x.txt');

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