Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cpr

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

cpr - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

59

lib/index.js

@@ -147,14 +147,3 @@ var fs = require('graceful-fs');

var to = options.toHash[file];
fs.stat(to, stack.add(function(err, s) {
if (s && s.isFile()) {
if (options.overwrite) {
fs.unlink(to, stack.add(function() {
copy(file, to, stack.add(function() {}));
}));
}
} else {
copy(file, to, stack.add(function() {}));
}
}));
copy(file, to, stack.add(function() {}));
});

@@ -167,21 +156,34 @@

var confirm = function(files, callback) {
var confirm = function(files, options, callback) {
var stack = new Stack(),
errors = [],
f = [];
f = [],
filtered = [];
files.forEach(function(file) {
fs.stat(file, stack.add(function(err, stat) {
if (err) {
errors.push(err);
} else {
if (stat && (stat.isFile() || stat.isDirectory())) {
f.push(file);
if (options.filter) {
if (typeof options.filter === 'function') {
filtered = files.filter(options.filter);
} else if (options.filter instanceof RegExp) {
filtered = files.filter(function(item) {
return !options.filter.test(item);
});
}
}
if (filtered.length) {
filtered.forEach(function(file) {
fs.stat(file, stack.add(function(err, stat) {
if (err) {
errors.push(err);
} else {
if (stat && (stat.isFile() || stat.isDirectory())) {
f.push(file);
}
}
}
}));
});
}));
});
}
stack.done(function() {
callback(errors, f.sort());
callback(((errors.length) ? errors : null), f.sort());
});

@@ -221,3 +223,3 @@ };

if (options.confirm) {
confirm(out, callback);
confirm(out, options, callback);
} else {

@@ -240,6 +242,3 @@ err = options.errors.length ? options.errors : null;

if (options.deleteFirst) {
rimraf(to, function(err) {
if (err) {
return callback(err);
}
rimraf(to, function() {
proc();

@@ -246,0 +245,0 @@ });

@@ -5,3 +5,3 @@ {

"author": "Dav Glass <davglass@gmail.com>",
"version": "0.0.4",
"version": "0.0.5",
"dependencies": {

@@ -16,3 +16,3 @@ "graceful-fs": "~1.1.14",

"yui-lint": "~0.1.0",
"istanbul": "https://github.com/gotwarlost/istanbul/tarball/textreport",
"istanbul": "~0.1.8",
"vows": "*"

@@ -25,3 +25,3 @@ },

"pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/*.js",
"test": "istanbul cover --console both -- vows --spec ./tests/*.js"
"test": "istanbul cover --print both -- vows --spec ./tests/*.js"
},

@@ -28,0 +28,0 @@ "bugs": { "url" : "http://github.com/davglass/cpr/issues" },

@@ -90,2 +90,4 @@ var vows = require('vows'),

cpr.cpr(from, out, {
confirm: true,
overwrite: true,
filter: /yui-lint/

@@ -130,2 +132,4 @@ }, function(err, status) {

cpr.cpr(from, out, {
confirm: true,
deleteFirst: true,
filter: function (item) {

@@ -164,2 +168,61 @@ return !(/graceful-fs/.test(item));

}
},
'and should copy node_modules with overwrite flag': {
topic: function() {
var out = path.join(to, '4'),
self = this;
this.outDir = out;
cpr.cpr(from, out, function() {
cpr.cpr(from, out, {
overwrite: true,
confirm: true
}, function(err, status) {
var t = {
status: status,
dirs: {
from: fs.readdirSync(from).sort(),
to: fs.readdirSync(out).sort()
}
};
self.callback(err, t);
});
});
},
'has ./out/0': function(topic) {
var stat = fs.statSync(this.outDir);
assert.ok(stat.isDirectory());
},
'and dirs are equal': function(topic) {
assert.deepEqual(topic.dirs.to, topic.dirs.from);
},
'and from directory has graceful-fs dir': function(topic) {
var fromHasGFS = topic.dirs.from.some(function(item) {
return (item === 'graceful-fs');
});
assert.isTrue(fromHasGFS);
},
'and to directory has graceful-fs dir': function(topic) {
var toHasGFS = topic.dirs.to.some(function(item) {
return (item === 'graceful-fs');
});
assert.isTrue(toHasGFS);
}
},
},
"should fail on non-existant from dir": {
topic: function() {
var self = this;
cpr.cpr('./does/not/exist', path.join(to, 'does/not/matter'), function(err, status) {
self.callback(null, {
err: err,
status: status
});
});
},
"should return an error in the callback": function(topic) {
assert.isUndefined(topic.status);
assert.ok(topic.err);
assert.equal('From should be a directory', topic.err);
}

@@ -166,0 +229,0 @@ }

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