update npm dependency - fs-extra

This commit is contained in:
Peter Dave Hello
2014-08-16 00:06:02 +08:00
parent e6ada46e95
commit 0a4f28c3ca
23 changed files with 267 additions and 120 deletions
+6
View File
@@ -1,3 +1,9 @@
2.0.0 / 2014-07-28
------------------
* added `\n` to end of file on write. [#14](https://github.com/jprichardson/node-jsonfile/pull/14)
* added `options.throws` to `readFileSync()`
* dropped support for Node v0.8
1.2.0 / 2014-06-29
------------------
* removed semicolons
+23 -20
View File
@@ -26,38 +26,40 @@ API
### readFile(filename, [options], callback)
```javascript
var jf = require('jsonfile');
var util = require('util');
var jf = require('jsonfile')
var util = require('util')
var file = '/tmp/data.json';
var file = '/tmp/data.json'
jf.readFile(file, function(err, obj) {
console.log(util.inspect(obj));
});
console.log(util.inspect(obj))
})
```
### readFileSync(filename, [options])
```javascript
var jf = require('jsonfile');
var util = require('util');
var jf = require('jsonfile')
var util = require('util')
var file = '/tmp/data.json';
var file = '/tmp/data.json'
console.log(util.inspect(jf.readFileSync(file)));
console.log(util.inspect(jf.readFileSync(file)))
```
**options**: `throws`. Set to `false` if you don't ever want this method to throw on invalid JSON. Will return `null` instead. Defaults to `true`. Others passed directly to `fs.readFileSync`.
### writeFile(filename, [options], callback)
```javascript
var jf = require('jsonfile')
var file = '/tmp/data.json';
var obj = {name: 'JP'};
var file = '/tmp/data.json'
var obj = {name: 'JP'}
jf.writeFile(file, obj, function(err) {
console.log(err);
console.log(err)
})
```
@@ -66,10 +68,10 @@ jf.writeFile(file, obj, function(err) {
```javascript
var jf = require('jsonfile')
var file = '/tmp/data.json';
var obj = {name: 'JP'};
var file = '/tmp/data.json'
var obj = {name: 'JP'}
jf.writeFileSync(file, obj);
jf.writeFileSync(file, obj)
```
@@ -80,16 +82,16 @@ Number of spaces to indent JSON files.
**default:** 2
```
var jf = require('jsonfile');
var jf = require('jsonfile')
jf.spaces = 4;
var file = '/tmp/data.json';
var obj = {name: 'JP'};
var file = '/tmp/data.json'
var obj = {name: 'JP'}
jf.writeFile(file, obj, function(err) { //json file has four space indenting now
console.log(err);
});
console.log(err)
})
```
@@ -108,6 +110,7 @@ If you contribute to this library, please don't change the version numbers in yo
- [1] [Federico Fissore](https://github.com/ffissore)
- [1] [Ivan McCarthy](https://github.com/imcrthy)
- [1] [Pablo Vallejo](https://github.com/PabloVallejo)
- [1] [Miroslav Bajtoš](https://github.com/bajtos)
License
+12 -3
View File
@@ -25,7 +25,16 @@ me.readFile = function(file, options, callback) {
}
me.readFileSync = function(file, options) {
return JSON.parse(fs.readFileSync(file, options))
var noThrow = options && !options.throws
if (!noThrow) //i.e. throw on invalid JSON
return JSON.parse(fs.readFileSync(file, options))
else
try {
return JSON.parse(fs.readFileSync(file, options))
} catch (err) {
return null
}
}
me.writeFile = function(file, obj, options, callback) {
@@ -36,7 +45,7 @@ me.writeFile = function(file, obj, options, callback) {
var str = ''
try {
str = JSON.stringify(obj, null, me.spaces)
str = JSON.stringify(obj, null, me.spaces) + '\n';
} catch (err) {
if (callback) return callback(err, null)
}
@@ -45,6 +54,6 @@ me.writeFile = function(file, obj, options, callback) {
}
me.writeFileSync = function(file, obj, options) {
var str = JSON.stringify(obj, null, me.spaces)
var str = JSON.stringify(obj, null, me.spaces) + '\n';
return fs.writeFileSync(file, str, options) //not sure if fs.writeFileSync returns anything, but just in case
}
+9 -8
View File
@@ -1,6 +1,6 @@
{
"name": "jsonfile",
"version": "1.2.0",
"version": "2.0.0",
"description": "Easily read/write JSON files.",
"repository": {
"type": "git",
@@ -24,22 +24,23 @@
],
"dependencies": {},
"devDependencies": {
"testutil": "~0.5.1",
"mocha": "*"
"testutil": "^0.7.0",
"mocha": "*",
"terst": "^0.2.0"
},
"main": "./lib/jsonfile.js",
"scripts": {
"test": "mocha test"
},
"readme": "[![build status](https://secure.travis-ci.org/jprichardson/node-jsonfile.png)](http://travis-ci.org/jprichardson/node-jsonfile)\n\nNode.js - jsonfile\n================\n\nEasily read/write JSON files. \n\n\nWhy?\n----\n\nWriting `JSON.stringify()` and then `fs.writeFile()` and `JSON.parse()` with `fs.readFile()` enclosed in `try/catch` blocks became annoying.\n\n\n\nInstallation\n------------\n\n npm install jsonfile --save\n\n\n\nAPI\n---\n\n### readFile(filename, [options], callback)\n\n```javascript\nvar jf = require('jsonfile');\nvar util = require('util');\n\nvar file = '/tmp/data.json';\njf.readFile(file, function(err, obj) {\n console.log(util.inspect(obj)); \n});\n```\n\n\n### readFileSync(filename, [options])\n\n```javascript\nvar jf = require('jsonfile');\nvar util = require('util');\n\nvar file = '/tmp/data.json';\n\nconsole.log(util.inspect(jf.readFileSync(file)));\n```\n\n\n### writeFile(filename, [options], callback)\n\n```javascript\nvar jf = require('jsonfile')\n\nvar file = '/tmp/data.json';\nvar obj = {name: 'JP'};\n\njf.writeFile(file, obj, function(err) {\n console.log(err);\n})\n```\n\n### writeFileSync(filename, [options])\n\n```javascript\nvar jf = require('jsonfile')\n\nvar file = '/tmp/data.json';\nvar obj = {name: 'JP'};\n\njf.writeFileSync(file, obj);\n```\n\n\n### spaces\n\nNumber of spaces to indent JSON files. \n\n**default:** 2\n\n```\nvar jf = require('jsonfile');\n\njf.spaces = 4;\n\nvar file = '/tmp/data.json';\nvar obj = {name: 'JP'};\n\njf.writeFile(file, obj, function(err) { //json file has four space indenting now\n console.log(err);\n});\n```\n\n\nContributions\n-------------\n\nIf you contribute to this library, please don't change the version numbers in your pull request.\n\n\n### Contributors\n\n(You can add your name, or I'll add it if you forget)\n\n- [*] [JP Richardson](https://github.com/jprichardson)\n- [2] [Sean O'Dell](https://github.com/seanodell)\n- [1] [Federico Fissore](https://github.com/ffissore)\n- [1] [Ivan McCarthy](https://github.com/imcrthy)\n- [1] [Pablo Vallejo](https://github.com/PabloVallejo)\n\n\nLicense\n-------\n\n(MIT License)\n\nCopyright 2012-2014, JP Richardson <jprichardson@gmail.com>\n\n\n\n\n\n",
"readme": "[![build status](https://secure.travis-ci.org/jprichardson/node-jsonfile.png)](http://travis-ci.org/jprichardson/node-jsonfile)\n\nNode.js - jsonfile\n================\n\nEasily read/write JSON files. \n\n\nWhy?\n----\n\nWriting `JSON.stringify()` and then `fs.writeFile()` and `JSON.parse()` with `fs.readFile()` enclosed in `try/catch` blocks became annoying.\n\n\n\nInstallation\n------------\n\n npm install jsonfile --save\n\n\n\nAPI\n---\n\n### readFile(filename, [options], callback)\n\n```javascript\nvar jf = require('jsonfile')\nvar util = require('util')\n\nvar file = '/tmp/data.json'\njf.readFile(file, function(err, obj) {\n console.log(util.inspect(obj))\n})\n```\n\n\n### readFileSync(filename, [options])\n\n```javascript\nvar jf = require('jsonfile')\nvar util = require('util')\n\nvar file = '/tmp/data.json'\n\nconsole.log(util.inspect(jf.readFileSync(file)))\n```\n\n**options**: `throws`. Set to `false` if you don't ever want this method to throw on invalid JSON. Will return `null` instead. Defaults to `true`. Others passed directly to `fs.readFileSync`. \n\n\n### writeFile(filename, [options], callback)\n\n```javascript\nvar jf = require('jsonfile')\n\nvar file = '/tmp/data.json'\nvar obj = {name: 'JP'}\n\njf.writeFile(file, obj, function(err) {\n console.log(err)\n})\n```\n\n### writeFileSync(filename, [options])\n\n```javascript\nvar jf = require('jsonfile')\n\nvar file = '/tmp/data.json'\nvar obj = {name: 'JP'}\n\njf.writeFileSync(file, obj)\n```\n\n\n### spaces\n\nNumber of spaces to indent JSON files. \n\n**default:** 2\n\n```\nvar jf = require('jsonfile')\n\njf.spaces = 4;\n\nvar file = '/tmp/data.json'\nvar obj = {name: 'JP'}\n\njf.writeFile(file, obj, function(err) { //json file has four space indenting now\n console.log(err)\n})\n```\n\n\nContributions\n-------------\n\nIf you contribute to this library, please don't change the version numbers in your pull request.\n\n\n### Contributors\n\n(You can add your name, or I'll add it if you forget)\n\n- [*] [JP Richardson](https://github.com/jprichardson)\n- [2] [Sean O'Dell](https://github.com/seanodell)\n- [1] [Federico Fissore](https://github.com/ffissore)\n- [1] [Ivan McCarthy](https://github.com/imcrthy)\n- [1] [Pablo Vallejo](https://github.com/PabloVallejo)\n- [1] [Miroslav Bajtoš](https://github.com/bajtos)\n\n\nLicense\n-------\n\n(MIT License)\n\nCopyright 2012-2014, JP Richardson <jprichardson@gmail.com>\n\n\n\n\n\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/jprichardson/node-jsonfile/issues"
},
"_id": "jsonfile@1.2.0",
"_id": "jsonfile@2.0.0",
"dist": {
"shasum": "2912bf5eeefa5517209bb10e79ad2dbac6f2b5c0"
"shasum": "3c9ea0f1f6d5c7a87c9d95791b18b89a9c9c9905"
},
"_from": "jsonfile@^1.2.0",
"_resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-1.2.0.tgz"
"_from": "jsonfile@^2.0.0",
"_resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.0.0.tgz"
}
@@ -46,5 +46,9 @@
"url": "https://github.com/substack/minimist/issues"
},
"_id": "minimist@0.0.8",
"_from": "minimist@0.0.8"
"dist": {
"shasum": "cee380cb5fb912eb0b67f1a963040faf95702487"
},
"_from": "minimist@0.0.8",
"_resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz"
}
+5 -1
View File
@@ -36,5 +36,9 @@
"url": "https://github.com/substack/node-mkdirp/issues"
},
"_id": "mkdirp@0.5.0",
"_from": "mkdirp@^0.5.0"
"dist": {
"shasum": "eb04467607da1644eb52eda7b774fdcd60f1f39a"
},
"_from": "mkdirp@^0.5.0",
"_resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz"
}
+1 -1
View File
@@ -1,4 +1,4 @@
node_modules
.*.sw[op]
.DS_Store
test/fixtures/out
test/*fixtures/out
+5
View File
@@ -49,6 +49,11 @@ You can also call ncp like `ncp(source, destination, options, callback)`.
* `options.clobber` - boolean=true. if set to false, `ncp` will not overwrite
destination files that already exist.
* `options.dereference` - boolean=false. If set to true, `ncp` will follow symbolic
links. For example, a symlink in the source tree pointing to a regular file
will become a regular file in the destination tree. Broken symlinks will result in
errors.
* `options.stopOnErr` - boolean=false. If set to true, `ncp` will behave like `cp -r`,
and stop on the first error it encounters. By default, `ncp` continues copying, logging all
errors and returning an array.
+19 -10
View File
@@ -1,6 +1,8 @@
var fs = require('fs'),
path = require('path');
const modern = /^v0\.1\d\.\d+$/.test(process.version);
module.exports = ncp;
ncp.ncp = ncp;
@@ -16,10 +18,13 @@ function ncp (source, dest, options, callback) {
currentPath = path.resolve(basePath, source),
targetPath = path.resolve(basePath, dest),
filter = options.filter,
rename = options.rename,
transform = options.transform,
clobber = options.clobber !== false,
dereference = options.dereference,
errs = null,
eventName = /^v0\.10\.\d+$/.test(process.version) ? 'finish' : 'close',
eventName = modern ? 'finish' : 'close',
defer = modern ? setImmediate : process.nextTick,
started = 0,
finished = 0,
running = 0,
@@ -46,20 +51,15 @@ function ncp (source, dest, options, callback) {
return getStats(source);
}
function defer(fn) {
if (typeof(setImmediate) === 'function')
return setImmediate(fn);
return process.nextTick(fn);
}
function getStats(source) {
var stat = dereference ? fs.stat : fs.lstat;
if (running >= limit) {
return defer(function () {
getStats(source);
});
}
running++;
fs.lstat(source, function (err, stats) {
stat(source, function (err, stats) {
var item = {};
if (err) {
return onError(err);
@@ -84,6 +84,9 @@ function ncp (source, dest, options, callback) {
function onFile(file) {
var target = file.name.replace(currentPath, targetPath);
if(rename) {
target = rename(target);
}
isWritable(target, function (writable) {
if (writable) {
return copyFile(file, target);
@@ -101,10 +104,16 @@ function ncp (source, dest, options, callback) {
function copyFile(file, target) {
var readStream = fs.createReadStream(file.name),
writeStream = fs.createWriteStream(target, { mode: file.mode });
readStream.on('error', onError);
writeStream.on('error', onError);
if(transform) {
transform(readStream, writeStream,file);
transform(readStream, writeStream, file);
} else {
readStream.pipe(writeStream);
writeStream.on('open', function() {
readStream.pipe(writeStream);
});
}
writeStream.once(eventName, cb);
}
+8 -4
View File
@@ -1,6 +1,6 @@
{
"name": "ncp",
"version": "0.5.1",
"version": "0.6.0",
"author": {
"name": "AvianFlu",
"email": "charlie@charlieistheman.com"
@@ -30,11 +30,15 @@
"scripts": {
"test": "mocha -R spec"
},
"readme": "# ncp - Asynchronous recursive file & directory copying\n\n[![Build Status](https://secure.travis-ci.org/AvianFlu/ncp.png)](http://travis-ci.org/AvianFlu/ncp)\n\nThink `cp -r`, but pure node, and asynchronous. `ncp` can be used both as a CLI tool and programmatically.\n\n## Command Line usage\n\nUsage is simple: `ncp [source] [dest] [--limit=concurrency limit]\n[--filter=filter] --stopOnErr`\n\nThe 'filter' is a Regular Expression - matched files will be copied.\n\nThe 'concurrency limit' is an integer that represents how many pending file system requests `ncp` has at a time.\n\n'stoponerr' is a boolean flag that will tell `ncp` to stop immediately if any\nerrors arise, rather than attempting to continue while logging errors. The default behavior is to complete as many copies as possible, logging errors along the way.\n\nIf there are no errors, `ncp` will output `done.` when complete. If there are errors, the error messages will be logged to `stdout` and to `./ncp-debug.log`, and the copy operation will attempt to continue.\n\n## Programmatic usage\n\nProgrammatic usage of `ncp` is just as simple. The only argument to the completion callback is a possible error. \n\n```javascript\nvar ncp = require('ncp').ncp;\n\nncp.limit = 16;\n\nncp(source, destination, function (err) {\n if (err) {\n return console.error(err);\n }\n console.log('done!');\n});\n```\n\nYou can also call ncp like `ncp(source, destination, options, callback)`. \n`options` should be a dictionary. Currently, such options are available:\n\n * `options.filter` - a `RegExp` instance, against which each file name is\n tested to determine whether to copy it or not, or a function taking single\n parameter: copied file name, returning `true` or `false`, determining\n whether to copy file or not.\n\n * `options.transform` - a function: `function (read, write) { read.pipe(write) }`\n used to apply streaming transforms while copying.\n\n * `options.clobber` - boolean=true. if set to false, `ncp` will not overwrite \n destination files that already exist.\n\n * `options.stopOnErr` - boolean=false. If set to true, `ncp` will behave like `cp -r`,\n and stop on the first error it encounters. By default, `ncp` continues copying, logging all\n errors and returning an array.\n\n * `options.errs` - stream. If `options.stopOnErr` is `false`, a stream can be provided, and errors will be written to this stream.\n\nPlease open an issue if any bugs arise. As always, I accept (working) pull requests, and refunds are available at `/dev/null`.\n",
"readme": "# ncp - Asynchronous recursive file & directory copying\n\n[![Build Status](https://secure.travis-ci.org/AvianFlu/ncp.png)](http://travis-ci.org/AvianFlu/ncp)\n\nThink `cp -r`, but pure node, and asynchronous. `ncp` can be used both as a CLI tool and programmatically.\n\n## Command Line usage\n\nUsage is simple: `ncp [source] [dest] [--limit=concurrency limit]\n[--filter=filter] --stopOnErr`\n\nThe 'filter' is a Regular Expression - matched files will be copied.\n\nThe 'concurrency limit' is an integer that represents how many pending file system requests `ncp` has at a time.\n\n'stoponerr' is a boolean flag that will tell `ncp` to stop immediately if any\nerrors arise, rather than attempting to continue while logging errors. The default behavior is to complete as many copies as possible, logging errors along the way.\n\nIf there are no errors, `ncp` will output `done.` when complete. If there are errors, the error messages will be logged to `stdout` and to `./ncp-debug.log`, and the copy operation will attempt to continue.\n\n## Programmatic usage\n\nProgrammatic usage of `ncp` is just as simple. The only argument to the completion callback is a possible error. \n\n```javascript\nvar ncp = require('ncp').ncp;\n\nncp.limit = 16;\n\nncp(source, destination, function (err) {\n if (err) {\n return console.error(err);\n }\n console.log('done!');\n});\n```\n\nYou can also call ncp like `ncp(source, destination, options, callback)`. \n`options` should be a dictionary. Currently, such options are available:\n\n * `options.filter` - a `RegExp` instance, against which each file name is\n tested to determine whether to copy it or not, or a function taking single\n parameter: copied file name, returning `true` or `false`, determining\n whether to copy file or not.\n\n * `options.transform` - a function: `function (read, write) { read.pipe(write) }`\n used to apply streaming transforms while copying.\n\n * `options.clobber` - boolean=true. if set to false, `ncp` will not overwrite \n destination files that already exist.\n\n * `options.dereference` - boolean=false. If set to true, `ncp` will follow symbolic\n links. For example, a symlink in the source tree pointing to a regular file\n will become a regular file in the destination tree. Broken symlinks will result in\n errors.\n\n * `options.stopOnErr` - boolean=false. If set to true, `ncp` will behave like `cp -r`,\n and stop on the first error it encounters. By default, `ncp` continues copying, logging all\n errors and returning an array.\n\n * `options.errs` - stream. If `options.stopOnErr` is `false`, a stream can be provided, and errors will be written to this stream.\n\nPlease open an issue if any bugs arise. As always, I accept (working) pull requests, and refunds are available at `/dev/null`.\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/AvianFlu/ncp/issues"
},
"_id": "ncp@0.5.1",
"_from": "ncp@^0.5.1"
"_id": "ncp@0.6.0",
"dist": {
"shasum": "26a76da43f373aa15ba45839656ae170559452b6"
},
"_from": "ncp@^0.6.0",
"_resolved": "https://registry.npmjs.org/ncp/-/ncp-0.6.0.tgz"
}
-1
View File
@@ -1 +0,0 @@
Hello world
-1
View File
@@ -1 +0,0 @@
Hello ncp
View File
View File
View File
View File
-1
View File
@@ -1 +0,0 @@
Hello nodejitsu
View File
+141 -58
View File
@@ -1,86 +1,169 @@
var assert = require('assert'),
fs = require('fs'),
path = require('path'),
rimraf = require('rimraf'),
readDirFiles = require('read-dir-files'),
ncp = require('../').ncp;
var fixtures = path.join(__dirname, 'fixtures'),
src = path.join(fixtures, 'src'),
out = path.join(fixtures, 'out');
describe('ncp', function () {
before(function (cb) {
rimraf(out, function() {
ncp(src, out, cb);
});
});
describe('regular files and directories', function () {
var fixtures = path.join(__dirname, 'regular-fixtures'),
src = path.join(fixtures, 'src'),
out = path.join(fixtures, 'out');
describe('when copying a directory of files', function () {
it('files are copied correctly', function (cb) {
readDirFiles(src, 'utf8', function (srcErr, srcFiles) {
readDirFiles(out, 'utf8', function (outErr, outFiles) {
assert.ifError(srcErr);
assert.deepEqual(srcFiles, outFiles);
cb();
});
});
});
});
describe('when copying files using filter', function () {
before(function (cb) {
var filter = function(name) {
return name.substr(name.length - 1) != 'a';
};
rimraf(out, function () {
ncp(src, out, {filter: filter}, cb);
rimraf(out, function() {
ncp(src, out, cb);
});
});
it('files are copied correctly', function (cb) {
readDirFiles(src, 'utf8', function (srcErr, srcFiles) {
function filter(files) {
for (var fileName in files) {
var curFile = files[fileName];
if (curFile instanceof Object)
return filter(curFile);
if (fileName.substr(fileName.length - 1) == 'a')
delete files[fileName];
describe('when copying a directory of files', function () {
it('files are copied correctly', function (cb) {
readDirFiles(src, 'utf8', function (srcErr, srcFiles) {
readDirFiles(out, 'utf8', function (outErr, outFiles) {
assert.ifError(srcErr);
assert.deepEqual(srcFiles, outFiles);
cb();
});
});
});
});
describe('when copying files using filter', function () {
before(function (cb) {
var filter = function(name) {
return name.substr(name.length - 1) != 'a';
};
rimraf(out, function () {
ncp(src, out, {filter: filter}, cb);
});
});
it('files are copied correctly', function (cb) {
readDirFiles(src, 'utf8', function (srcErr, srcFiles) {
function filter(files) {
for (var fileName in files) {
var curFile = files[fileName];
if (curFile instanceof Object)
return filter(curFile);
if (fileName.substr(fileName.length - 1) == 'a')
delete files[fileName];
}
}
}
filter(srcFiles);
readDirFiles(out, 'utf8', function (outErr, outFiles) {
assert.ifError(outErr);
assert.deepEqual(srcFiles, outFiles);
cb();
filter(srcFiles);
readDirFiles(out, 'utf8', function (outErr, outFiles) {
assert.ifError(outErr);
assert.deepEqual(srcFiles, outFiles);
cb();
});
});
});
});
describe('when using clobber=false', function () {
it('the copy is completed successfully', function (cb) {
ncp(src, out, function() {
ncp(src, out, {clobber: false}, function(err) {
assert.ifError(err);
cb();
});
});
});
});
describe('when using transform', function () {
it('file descriptors are passed correctly', function (cb) {
ncp(src, out, {
transform: function(read,write,file) {
assert.notEqual(file.name, undefined);
assert.strictEqual(typeof file.mode,'number');
read.pipe(write);
}
}, cb);
});
});
describe('when using rename', function() {
it('output files are correctly redirected', function(cb) {
ncp(src, out, {
rename: function(target) {
if(path.basename(target) == 'a') return path.resolve(path.dirname(target), 'z');
return target;
}
}, function(err) {
if(err) return cb(err);
readDirFiles(src, 'utf8', function (srcErr, srcFiles) {
readDirFiles(out, 'utf8', function (outErr, outFiles) {
assert.ifError(srcErr);
assert.deepEqual(srcFiles.a, outFiles.z);
cb();
});
});
});
});
});
});
describe('when using clobber=false', function () {
it('the copy is completed successfully', function (cb) {
ncp(src, out, function() {
ncp(src, out, {clobber: false}, function(err) {
assert.ifError(err);
cb();
});
describe('symlink handling', function () {
var fixtures = path.join(__dirname, 'symlink-fixtures'),
src = path.join(fixtures, 'src'),
out = path.join(fixtures, 'out');
beforeEach(function (cb) {
rimraf(out, cb);
});
it('copies symlinks by default', function (cb) {
ncp(src, out, function (err) {
if (err) return cb(err);
assert.equal(fs.readlinkSync(path.join(out, 'file-symlink')), 'foo');
assert.equal(fs.readlinkSync(path.join(out, 'dir-symlink')), 'dir');
cb();
})
});
it('copies file contents when dereference=true', function (cb) {
ncp(src, out, { dereference: true }, function (err) {
var fileSymlinkPath = path.join(out, 'file-symlink');
assert.ok(fs.lstatSync(fileSymlinkPath).isFile());
assert.equal(fs.readFileSync(fileSymlinkPath), 'foo contents');
var dirSymlinkPath = path.join(out, 'dir-symlink');
assert.ok(fs.lstatSync(dirSymlinkPath).isDirectory());
assert.deepEqual(fs.readdirSync(dirSymlinkPath), ['bar']);
cb();
});
});
});
describe('when using transform', function () {
it('file descriptors are passed correctly', function (cb) {
ncp(src, out, {
transform: function(read,write,file) {
assert.notEqual(file.name, undefined);
assert.strictEqual(typeof file.mode,'number');
read.pipe(write);
}
}, cb);
describe('broken symlink handling', function () {
var fixtures = path.join(__dirname, 'broken-symlink-fixtures'),
src = path.join(fixtures, 'src'),
out = path.join(fixtures, 'out');
beforeEach(function (cb) {
rimraf(out, cb);
});
it('copies broken symlinks by default', function (cb) {
ncp(src, out, function (err) {
if (err) return cb(err);
assert.equal(fs.readlinkSync(path.join(out, 'broken-symlink')), 'does-not-exist');
cb();
})
});
it('returns an error when dereference=true', function (cb) {
ncp(src, out, {dereference: true}, function (err) {
assert.equal(err.length, 1);
assert.equal(err[0].code, 'ENOENT');
cb();
});
});
});
});
+5 -1
View File
@@ -51,5 +51,9 @@
"url": "https://github.com/isaacs/rimraf/issues"
},
"_id": "rimraf@2.2.8",
"_from": "rimraf@^2.2.8"
"dist": {
"shasum": "5ce7bd309fa25cf1b5ad7ee2e2986239b2e2aa8d"
},
"_from": "rimraf@^2.2.8",
"_resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz"
}