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 1.1.0 to 1.1.1

.istanbul.yml

16

lib/index.js

@@ -112,2 +112,3 @@ /*

/*istanbul ignore else*/
if (to && typeof to === 'string') {

@@ -145,5 +146,13 @@ fs.stat(to, stack.add(function(err, s) {

err,
called = false,
cb = function(e) {
if (!called) {
callback(e);
called = true;
}
},
onError = function (e) {
/*istanbul ignore next*/
err = e;
cb(e);
};

@@ -154,3 +163,3 @@

fromFile.once('end', function() {
callback(err);
cb(err);
});

@@ -167,2 +176,3 @@ fromFile.pipe(toFile);

check = function() {
/*istanbul ignore else - Shouldn't need this if graceful-fs does it's job*/
if (count === complete) {

@@ -214,3 +224,4 @@ callback();

}
/*istanbul ignore else - filtered should be an array, but just in case*/
if (filtered.length) {

@@ -232,2 +243,3 @@ filtered.forEach(function(file) {

stack.done(function() {
/*istanbul ignore next */
callback(((errors.length) ? errors : null), f.sort());

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

10

package.json

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

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

@@ -16,4 +16,4 @@ "graceful-fs": "~4.1.2",

"istanbul": "~0.4.0",
"jenkins-mocha": "^2.6.0",
"jshint": "~2.8.0",
"vows": "~0.8.1",
"yui-lint": "~0.2.0"

@@ -39,5 +39,5 @@ },

"pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/",
"windows-test": "vows --spec ./tests/full.js",
"test": "istanbul cover --print both -- vows --spec ./tests/full.js",
"posttest": "istanbul check-coverage --statement 98 --branch 95 --function 95 --line 98"
"windows-test": "jenkins-mocha ./tests/full.js",
"test": "jenkins-mocha ./tests/full.js",
"posttest": "istanbul check-coverage"
},

@@ -44,0 +44,0 @@ "bugs": {

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

var vows = require('vows'),
assert = require('assert'),
var assert = require('assert'),
path = require('path'),
fs = require('fs'),
rimraf = require('rimraf'),
mkdirp = require('mkdirp'),
cpr = require('../lib'),

@@ -11,90 +11,230 @@ exec = require('child_process').exec,

var tests = {
'should be loaded': {
topic: function () {
describe('cpr test suite', function() {
this.timeout(55000);
describe('loading', function() {
before(function() {
rimraf.sync(to);
return cpr;
},
'should export raw method': function (topic) {
assert.isFunction(topic);
},
'and should export cpr method too': function (topic) {
assert.isFunction(topic.cpr);
},
'and should copy node_modules': {
topic: function() {
var out = path.join(to, '0'),
self = this;
});
it('should export raw method', function () {
assert.equal(typeof cpr, 'function');
});
it('should export cpr method too', function () {
assert.equal(typeof cpr.cpr, 'function');
});
});
describe('should copy node_modules', function() {
var out = path.join(to, '0');
var data = {};
before(function(done) {
cpr(from, out, function(err, status) {
data = {
from: fs.readdirSync(from).sort(),
to: fs.readdirSync(out).sort()
};
done();
});
});
it('has ./out/0', function() {
var stat = fs.statSync(out);
assert.ok(stat.isDirectory());
});
this.outDir = out;
cpr(from, out, function(err, status) {
var t = {
status: status,
dirs: {
from: fs.readdirSync(from).sort(),
to: fs.readdirSync(out).sort()
}
it('dirs are equal', function() {
assert.deepEqual(data.to, data.from);
});
it('from directory has graceful-fs dir', function() {
var fromHasGFS = data.from.some(function(item) {
return (item === 'graceful-fs');
});
assert.equal(true, fromHasGFS);
});
it('to directory has graceful-fs dir', function() {
var toHasGFS = data.to.some(function(item) {
return (item === 'graceful-fs');
});
assert.equal(true, toHasGFS);
});
});
describe('should NOT copy node_modules', function() {
var out = path.join(to, '1'),
data;
before(function(done) {
cpr(from, out, {
filter: /node_modules/
}, function(err) {
fs.stat(out, function(e, stat) {
data = {
err: err,
stat: e
};
self.callback(err, t);
done();
});
},
'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);
}
},
'and should NOT copy node_modules': {
topic: function() {
var out = path.join(to, '1'),
self = this;
});
});
it('does not have ./out/1', function() {
assert.ok(data.stat); // Should be an error
});
it('threw an error', function() {
assert(data.err instanceof Error); // Should be an error
assert.equal(data.err.message, 'No files to copy');
});
});
this.outDir = out;
cpr(from, out, {
filter: /node_modules/
}, function(err) {
fs.stat(out, function(e, stat) {
var t = {
err: err,
stat: e
};
self.callback(null, t);
});
});
},
'does not have ./out/1': function(topic) {
assert.ok(topic.stat); // Should be an error
},
'and threw an error': function(topic) {
assert(topic.err instanceof Error); // Should be an error
assert.equal(topic.err.message, 'No files to copy');
}
},
'and should not copy yui-lint from regex': {
topic: function() {
var out = path.join(to, '2'),
self = this;
describe('should not copy yui-lint from regex', function() {
var out = path.join(to, '2'),
data;
this.outDir = out;
before(function(done) {
cpr(from, out, {
confirm: true,
overwrite: true,
filter: /yui-lint/
}, function(err, status) {
data = {
status: status,
dirs: {
from: fs.readdirSync(from).sort(),
to: fs.readdirSync(out).sort()
}
};
done();
});
});
it('returns files array with confirm', function() {
assert.ok(Array.isArray(data.status));
assert.ok(data.status.length > 0);
});
it('has ./out/2', function() {
var stat = fs.statSync(out);
assert.ok(stat.isDirectory());
});
it('dirs are not equal', function() {
assert.notDeepEqual(data.dirs.to, data.dirs.from);
});
it('from directory has yui-lint dir', function() {
var fromHasLint = data.dirs.from.some(function(item) {
return (item === 'yui-lint');
});
assert.equal(true, fromHasLint);
});
it('to directory does not have yui-lint dir', function() {
var toHasLint = data.dirs.to.some(function(item) {
return (item === 'yui-lint');
});
assert.equal(false, toHasLint);
});
});
describe('should not copy directory from function', function() {
var out = path.join(to, '3'),
data;
before(function(done) {
cpr(from, out, {
confirm: true,
deleteFirst: true,
filter: function (item) {
return !(/data/.test(item));
}
}, function(err, status) {
data = {
status: status,
dirs: {
from: fs.readdirSync(path.join(from, 'jshint/')).sort(),
to: fs.readdirSync(path.join(out, 'jshint/')).sort()
}
};
done();
});
});
it('has ./out/3', function() {
var stat = fs.statSync(out);
assert.ok(stat.isDirectory());
});
it('dirs are not equal', function() {
assert.notDeepEqual(data.dirs.to, data.dirs.from);
});
it('from directory has data dir', function() {
var fromHas = data.dirs.from.some(function(item) {
return (item === 'data');
});
assert.equal(true, fromHas);
});
it('to directory does not have data dir', function() {
var toHas = data.dirs.to.some(function(item) {
return (item === 'data');
});
assert.equal(false, toHas);
});
});
describe('should copy minimatch from bad filter', function() {
var out = path.join(to, '4'),
data;
before(function(done) {
cpr(from, out, {
confirm: true,
deleteFirst: true,
filter: 'bs content'
}, function(err, status) {
data = {
status: status,
dirs: {
from: fs.readdirSync(path.join(from, 'jshint/node_modules')).sort(),
to: fs.readdirSync(path.join(out, 'jshint/node_modules')).sort()
}
};
done();
});
});
it('has ./out/4', function() {
var stat = fs.statSync(out);
assert.ok(stat.isDirectory());
});
it('dirs are not equal', function() {
assert.deepEqual(data.dirs.to, data.dirs.from);
});
it('from directory has minimatch dir', function() {
var fromHasGFS = data.dirs.from.some(function(item) {
return (item === 'minimatch');
});
assert.equal(true, fromHasGFS);
});
it('to directory does have minimatch dir', function() {
var toHasGFS = data.dirs.to.some(function(item) {
return (item === 'minimatch');
});
assert.equal(true, toHasGFS);
});
});
describe('should copy node_modules with overwrite flag', function() {
var out = path.join(to, '4'),
data;
before(function(done) {
cpr(from, out, function() {
cpr(from, out, {
confirm: true,
overwrite: true,
filter: /yui-lint/
confirm: true
}, function(err, status) {
var t = {
data = {
status: status,

@@ -106,306 +246,166 @@ dirs: {

};
self.callback(err, t);
done();
});
},
'returns files array with confirm': function(topic) {
assert.isArray(topic.status);
assert.ok(topic.status.length > 0);
},
'and has ./out/2': function(topic) {
var stat = fs.statSync(this.outDir);
assert.ok(stat.isDirectory());
},
'and dirs are not equal': function(topic) {
assert.notDeepEqual(topic.dirs.to, topic.dirs.from);
},
'and from directory has yui-lint dir': function(topic) {
var fromHasLint = topic.dirs.from.some(function(item) {
return (item === 'yui-lint');
});
assert.isTrue(fromHasLint);
},
'and to directory does not have yui-lint dir': function(topic) {
var toHasLint = topic.dirs.to.some(function(item) {
return (item === 'yui-lint');
});
assert.isFalse(toHasLint);
}
},
'and should not copy minimatch from function': {
topic: function() {
var out = path.join(to, '3'),
self = this;
});
});
this.outDir = out;
cpr(from, out, {
confirm: true,
deleteFirst: true,
filter: function (item) {
return !(/minimatch/.test(item));
}
}, function(err, status) {
var t = {
status: status,
dirs: {
from: fs.readdirSync(path.join(from, 'jshint/node_modules')).sort(),
to: fs.readdirSync(path.join(out, 'jshint/node_modules')).sort()
}
};
self.callback(err, t);
});
},
'and has ./out/3': function(topic) {
var stat = fs.statSync(this.outDir);
assert.ok(stat.isDirectory());
},
'and dirs are not equal': function(topic) {
assert.notDeepEqual(topic.dirs.to, topic.dirs.from);
},
'and from directory has minimatch dir': function(topic) {
var fromHasGFS = topic.dirs.from.some(function(item) {
return (item === 'minimatch');
});
assert.isTrue(fromHasGFS);
},
'and to directory does not have minimatch dir': function(topic) {
var toHasGFS = topic.dirs.to.some(function(item) {
return (item === 'minimatch');
});
assert.isFalse(toHasGFS);
}
},
'and should copy minimatch from bad filter': {
topic: function() {
var out = path.join(to, '4'),
self = this;
it('should return files array', function() {
assert.ok(Array.isArray(data.status));
assert.ok(data.status.length > 0);
});
it('has ./out/0', function() {
var stat = fs.statSync(out);
assert.ok(stat.isDirectory());
});
it('dirs are equal', function() {
assert.deepEqual(data.dirs.to, data.dirs.from);
});
it('from directory has graceful-fs dir', function() {
var fromHasGFS = data.dirs.from.some(function(item) {
return (item === 'graceful-fs');
});
assert.equal(true, fromHasGFS);
});
it('to directory has graceful-fs dir', function() {
var toHasGFS = data.dirs.to.some(function(item) {
return (item === 'graceful-fs');
});
assert.equal(true, toHasGFS);
});
});
this.outDir = out;
cpr(from, out, {
confirm: true,
deleteFirst: true,
filter: 'bs content'
}, function(err, status) {
var t = {
status: status,
dirs: {
from: fs.readdirSync(path.join(from, 'jshint/node_modules')).sort(),
to: fs.readdirSync(path.join(out, 'jshint/node_modules')).sort()
}
};
self.callback(err, t);
});
},
'and has ./out/4': function(topic) {
var stat = fs.statSync(this.outDir);
assert.ok(stat.isDirectory());
},
'and dirs are not equal': function(topic) {
assert.deepEqual(topic.dirs.to, topic.dirs.from);
},
'and from directory has minimatch dir': function(topic) {
var fromHasGFS = topic.dirs.from.some(function(item) {
return (item === 'minimatch');
});
assert.isTrue(fromHasGFS);
},
'and to directory does have minimatch dir': function(topic) {
var toHasGFS = topic.dirs.to.some(function(item) {
return (item === 'minimatch');
});
assert.isTrue(toHasGFS);
}
},
'and should copy node_modules with overwrite flag': {
topic: function() {
var out = path.join(to, '4'),
self = this;
this.outDir = out;
cpr(from, out, function() {
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);
});
});
},
'should return files array': function(topic) {
assert.isArray(topic.status);
assert.ok(topic.status.length > 0);
},
'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;
describe('error handling', function() {
it('should fail on non-existant from dir', function(done) {
cpr('./does/not/exist', path.join(to, 'does/not/matter'), function(err, status) {
self.callback(null, {
err: err,
status: status
});
assert.equal(undefined, status);
assert(err instanceof Error);
assert.equal('From should be a file or directory', err.message);
done();
});
},
"should return an error in the callback": function(topic) {
assert.isUndefined(topic.status);
assert(topic.err instanceof Error);
assert.equal('From should be a file or directory', topic.err.message);
}
},
"should fail on non-file": {
topic: function() {
var self = this;
});
it('should fail on non-file', function(done) {
cpr('/dev/null', path.join(to, 'does/not/matter'), function(err, status) {
self.callback(null, {
err: err,
status: status
});
assert.equal(undefined, status);
assert(err instanceof Error);
assert.equal('From should be a file or directory', err.message);
done();
});
},
"should return an error in the callback": function(topic) {
assert.isUndefined(topic.status);
assert(topic.err instanceof Error);
assert.equal('From should be a file or directory', topic.err.message);
}
},
"should copy empty directory": {
topic: function() {
var mkdirp = require('mkdirp');
mkdirp.sync(path.join(to, 'empty-src'));
cpr(path.join(to, 'empty-src'), path.join(to, 'empty-dest'), this.callback);
},
'has ./out/empty-dest': function(topic) {
var stat = fs.statSync(path.join(to, 'empty-dest'));
assert.ok(stat.isDirectory());
}
},
"should not delete existing folders in out dir": {
topic: function() {
var mkdirp = require('mkdirp');
mkdirp.sync(path.join(to, 'empty-src', 'a'));
mkdirp.sync(path.join(to, 'empty-dest', 'b'));
cpr(path.join(to, 'empty-src'), path.join(to, 'empty-dest'), { overwrite: true }, this.callback);
},
'has ./out/empty-dest': function(topic) {
var stat = fs.statSync(path.join(to, 'empty-dest'));
assert.ok(stat.isDirectory());
var dirs = fs.readdirSync(path.join(to, 'empty-dest'));
assert.equal(dirs[0], 'a');
assert.equal(dirs[1], 'b');
}
},
"should return an error if a directory is to write over an existing file with the same name": {
topic: function() {
var mkdirp = require('mkdirp');
});
it('should return an error if a directory is to write over an existing file with the same name', function(done) {
mkdirp.sync(path.join(to, 'empty-src2', 'a'));
mkdirp.sync(path.join(to, 'empty-dest2'));
fs.writeFileSync(path.join(to, 'empty-dest2', 'a'), 'FILE');
cpr(path.join(to, 'empty-src2'), path.join(to, 'empty-dest2'), { overwrite: true }, function(e, d) {
this.callback(null, {
errs: e,
data: d
});
}.bind(this));
},
'has ./out/empty-dest': function(topic) {
var stat = fs.statSync(path.join(to, 'empty-dest2'));
assert.ok(stat.isDirectory());
assert.ok(topic.errs);
assert.ok(topic.errs.list);
assert.ok(topic.errs.list[0]);
assert.ok(topic.errs.list[0].message.match(/exists and is not a directory, can not create/));
}
},
"should copy one file": {
topic: function() {
cpr(__filename, path.join(to, 'one-file-test/'), { overwrite: true }, this.callback);
},
"should copy one file": function(topic) {
assert.isUndefined(topic);
},
'has ./out/one-file-test/full.js': function(topic) {
var stat = fs.statSync(path.join(to, 'one-file-test/full.js'));
assert.ok(stat.isFile());
},
"and should not copy because file exists": {
topic: function() {
var self = this
cpr(__filename, path.join(to, 'one-file-test/'), function(err, status) {
self.callback(null, {err: err, status: status});
});
},
"should return an error in the callback": function(topic) {
assert.isUndefined(topic.status);
assert(topic.err instanceof Error);
assert.ok(/^File .* exists$/.test(topic.err.message));
}
}
},
"should work as a standalone bin": {
"and should copy node_modules": {
topic: function() {
var out = path.join(to, '4'),
self = this;
cpr(path.join(to, 'empty-src2'), path.join(to, 'empty-dest2'), { overwrite: true }, function(errs) {
var stat = fs.statSync(path.join(to, 'empty-dest2'));
assert.ok(stat.isDirectory());
assert.ok(errs);
assert.ok(errs.list);
assert.ok(errs.list[0]);
assert.ok(errs.list[0].message.match(/exists and is not a directory, can not create/));
done();
});
});
this.outDir = out;
exec('node ./bin/cpr ' + from + ' ' + out, function(err) {
var t = {
dirs: {
from: fs.readdirSync(from).sort(),
to: fs.readdirSync(out).sort()
}
};
self.callback(err, t);
});
},
'has ./out/4': function(topic) {
var stat = fs.statSync(this.outDir);
it('should fail without write permissions', function(done) {
var baddir = path.join(to, 'readonly');
mkdirp.sync(baddir);
fs.chmodSync(baddir, '555');
cpr(from, baddir, function(errs, status) {
assert.ok(errs);
assert.ok(errs.list);
assert.ok(errs.list[0]);
assert.ok(errs.message.match(/Unable to copy directory entirely/));
done();
});
});
});
describe('validations', function() {
it('should copy empty directory', function(done) {
mkdirp.sync(path.join(to, 'empty-src'));
cpr(path.join(to, 'empty-src'), path.join(to, 'empty-dest'), function() {
var stat = fs.statSync(path.join(to, 'empty-dest'));
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);
}
}
}
};
done();
});
});
it('should not delete existing folders in out dir', function(done) {
mkdirp.sync(path.join(to, 'empty-src', 'a'));
mkdirp.sync(path.join(to, 'empty-dest', 'b'));
cpr(path.join(to, 'empty-src'), path.join(to, 'empty-dest'), { overwrite: true }, function() {
var stat = fs.statSync(path.join(to, 'empty-dest'));
assert.ok(stat.isDirectory());
var dirs = fs.readdirSync(path.join(to, 'empty-dest'));
assert.equal(dirs[0], 'a');
assert.equal(dirs[1], 'b');
done();
});
});
it('should copy one file', function(done) {
cpr(__filename, path.join(to, 'one-file-test/'), { overwrite: true }, function(err) {
assert.equal(undefined, err);
var stat = fs.statSync(path.join(to, 'one-file-test/full.js'));
assert.ok(stat.isFile());
done();
});
});
vows.describe('CPR Tests').addBatch(tests).export(module);
it('should not copy because file exists', function(done) {
cpr(__filename, path.join(to, 'one-file-test/'), function(err, status) {
assert.equal(undefined, status);
assert(err instanceof Error);
assert.ok(/^File .* exists$/.test(err.message));
done();
});
});
});
describe('should work as a standalone bin', function() {
var out = path.join(to, '4'),
data;
before(function(done) {
exec('node ./bin/cpr ' + from + ' ' + out, function(err) {
data = {
dirs: {
from: fs.readdirSync(from).sort(),
to: fs.readdirSync(out).sort()
}
};
done();
});
});
it('has ./out/4', function() {
var stat = fs.statSync(out);
assert.ok(stat.isDirectory());
});
it('dirs are equal', function() {
assert.deepEqual(data.dirs.to, data.dirs.from);
});
it('from directory has graceful-fs dir', function() {
var fromHasGFS = data.dirs.from.some(function(item) {
return (item === 'graceful-fs');
});
assert.equal(true, fromHasGFS);
});
it('to directory has graceful-fs dir', function() {
var toHasGFS = data.dirs.to.some(function(item) {
return (item === 'graceful-fs');
});
assert.equal(true, toHasGFS);
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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