From 0a4f28c3caf45b2c7ba421cdc08c18afd3e138fb Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Sat, 16 Aug 2014 00:06:02 +0800 Subject: [PATCH] update npm dependency - fs-extra --- node_modules/fs-extra/CHANGELOG.md | 8 +- node_modules/fs-extra/README.md | 14 +- .../node_modules/jsonfile/CHANGELOG.md | 6 + .../fs-extra/node_modules/jsonfile/README.md | 43 ++-- .../node_modules/jsonfile/lib/jsonfile.js | 15 +- .../node_modules/jsonfile/package.json | 17 +- .../mkdirp/node_modules/minimist/package.json | 6 +- .../fs-extra/node_modules/mkdirp/package.json | 6 +- .../fs-extra/node_modules/ncp/.npmignore | 2 +- .../fs-extra/node_modules/ncp/README.md | 5 + .../fs-extra/node_modules/ncp/lib/ncp.js | 29 ++- .../fs-extra/node_modules/ncp/package.json | 12 +- .../node_modules/ncp/test/fixtures/src/a | 1 - .../node_modules/ncp/test/fixtures/src/b | 1 - .../node_modules/ncp/test/fixtures/src/c | 0 .../node_modules/ncp/test/fixtures/src/d | 0 .../node_modules/ncp/test/fixtures/src/e | 0 .../node_modules/ncp/test/fixtures/src/f | 0 .../node_modules/ncp/test/fixtures/src/sub/a | 1 - .../node_modules/ncp/test/fixtures/src/sub/b | 0 .../fs-extra/node_modules/ncp/test/ncp.js | 199 +++++++++++++----- .../fs-extra/node_modules/rimraf/package.json | 6 +- node_modules/fs-extra/package.json | 16 +- 23 files changed, 267 insertions(+), 120 deletions(-) delete mode 100644 node_modules/fs-extra/node_modules/ncp/test/fixtures/src/a delete mode 100644 node_modules/fs-extra/node_modules/ncp/test/fixtures/src/b delete mode 100644 node_modules/fs-extra/node_modules/ncp/test/fixtures/src/c delete mode 100644 node_modules/fs-extra/node_modules/ncp/test/fixtures/src/d delete mode 100644 node_modules/fs-extra/node_modules/ncp/test/fixtures/src/e delete mode 100644 node_modules/fs-extra/node_modules/ncp/test/fixtures/src/f delete mode 100644 node_modules/fs-extra/node_modules/ncp/test/fixtures/src/sub/a delete mode 100644 node_modules/fs-extra/node_modules/ncp/test/fixtures/src/sub/b diff --git a/node_modules/fs-extra/CHANGELOG.md b/node_modules/fs-extra/CHANGELOG.md index 5515c9a56..f1711fa5c 100644 --- a/node_modules/fs-extra/CHANGELOG.md +++ b/node_modules/fs-extra/CHANGELOG.md @@ -1,6 +1,12 @@ +0.11.0 / 2014-08-11 +------------------- +- upgraded `"ncp": "^0.5.1"` to `"ncp": "^0.6.0"` +- upgrade `jsonfile": "^1.2.0"` to `jsonfile": "^2.0.0"` => on write, json files now have `\n` at end. Also adds `options.throws` to `readJsonSync()` +see https://github.com/jprichardson/node-jsonfile#readfilesyncfilename-options for more details. + 0.10.0 / 2014-06-29 ------------------ -* bugfix: upgaded `"jsonfile": "~1.1.0"` to `"jsonfile": "^1.2.0", bumped minor because of `jsonfile` dep change +* bugfix: upgaded `"jsonfile": "~1.1.0"` to `"jsonfile": "^1.2.0"`, bumped minor because of `jsonfile` dep change from `~` to `^`. #67 0.9.1 / 2014-05-22 diff --git a/node_modules/fs-extra/README.md b/node_modules/fs-extra/README.md index bd05be2eb..602106045 100644 --- a/node_modules/fs-extra/README.md +++ b/node_modules/fs-extra/README.md @@ -1,7 +1,7 @@ Node.js: fs-extra ================= -[![build status](https://secure.travis-ci.org/jprichardson/node-fs-extra.png)](http://travis-ci.org/jprichardson/node-fs-extra) +[![build status](https://secure.travis-ci.org/jprichardson/node-fs-extra.svg)](http://travis-ci.org/jprichardson/node-fs-extra) [![downloads per month](http://img.shields.io/npm/dm/fs-extra.svg)](https://www.npmjs.org/package/fs-extra) This module adds a few extra file system methods that aren't included in the native `fs` module. It is a drop in replacement for `fs`. @@ -238,6 +238,18 @@ fs.readJson('./package.json', function(err, packageObj) { }); ``` +`readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example: + +```js +var fs = require('fs-extra') +var file = path.join('/tmp/some-invalid.json') +var data = "{not valid JSON" +fs.writeFileSync(file, data) + +var obj = fs.readJsonSync(file, {throws: false}) +console.log(obj) // => null +``` + ### remove(dir, callback) diff --git a/node_modules/fs-extra/node_modules/jsonfile/CHANGELOG.md b/node_modules/fs-extra/node_modules/jsonfile/CHANGELOG.md index b8f9579a6..271739b02 100644 --- a/node_modules/fs-extra/node_modules/jsonfile/CHANGELOG.md +++ b/node_modules/fs-extra/node_modules/jsonfile/CHANGELOG.md @@ -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 diff --git a/node_modules/fs-extra/node_modules/jsonfile/README.md b/node_modules/fs-extra/node_modules/jsonfile/README.md index fe6249002..0e67ca329 100644 --- a/node_modules/fs-extra/node_modules/jsonfile/README.md +++ b/node_modules/fs-extra/node_modules/jsonfile/README.md @@ -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 diff --git a/node_modules/fs-extra/node_modules/jsonfile/lib/jsonfile.js b/node_modules/fs-extra/node_modules/jsonfile/lib/jsonfile.js index 354e7ec71..a18e2c0c8 100644 --- a/node_modules/fs-extra/node_modules/jsonfile/lib/jsonfile.js +++ b/node_modules/fs-extra/node_modules/jsonfile/lib/jsonfile.js @@ -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 } diff --git a/node_modules/fs-extra/node_modules/jsonfile/package.json b/node_modules/fs-extra/node_modules/jsonfile/package.json index d82fb53bd..0fb2d591f 100644 --- a/node_modules/fs-extra/node_modules/jsonfile/package.json +++ b/node_modules/fs-extra/node_modules/jsonfile/package.json @@ -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 \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 \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" } diff --git a/node_modules/fs-extra/node_modules/mkdirp/node_modules/minimist/package.json b/node_modules/fs-extra/node_modules/mkdirp/node_modules/minimist/package.json index 9952e474b..6dcc5fe61 100644 --- a/node_modules/fs-extra/node_modules/mkdirp/node_modules/minimist/package.json +++ b/node_modules/fs-extra/node_modules/mkdirp/node_modules/minimist/package.json @@ -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" } diff --git a/node_modules/fs-extra/node_modules/mkdirp/package.json b/node_modules/fs-extra/node_modules/mkdirp/package.json index 8e5117fcf..afdb7e6cb 100644 --- a/node_modules/fs-extra/node_modules/mkdirp/package.json +++ b/node_modules/fs-extra/node_modules/mkdirp/package.json @@ -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" } diff --git a/node_modules/fs-extra/node_modules/ncp/.npmignore b/node_modules/fs-extra/node_modules/ncp/.npmignore index 9ecd205c6..3e6a4d798 100644 --- a/node_modules/fs-extra/node_modules/ncp/.npmignore +++ b/node_modules/fs-extra/node_modules/ncp/.npmignore @@ -1,4 +1,4 @@ node_modules .*.sw[op] .DS_Store -test/fixtures/out +test/*fixtures/out diff --git a/node_modules/fs-extra/node_modules/ncp/README.md b/node_modules/fs-extra/node_modules/ncp/README.md index 71dca8fc7..94800324a 100644 --- a/node_modules/fs-extra/node_modules/ncp/README.md +++ b/node_modules/fs-extra/node_modules/ncp/README.md @@ -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. diff --git a/node_modules/fs-extra/node_modules/ncp/lib/ncp.js b/node_modules/fs-extra/node_modules/ncp/lib/ncp.js index f0d9f6d44..fb7930c29 100644 --- a/node_modules/fs-extra/node_modules/ncp/lib/ncp.js +++ b/node_modules/fs-extra/node_modules/ncp/lib/ncp.js @@ -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); } diff --git a/node_modules/fs-extra/node_modules/ncp/package.json b/node_modules/fs-extra/node_modules/ncp/package.json index f88152ab2..69e821ec1 100644 --- a/node_modules/fs-extra/node_modules/ncp/package.json +++ b/node_modules/fs-extra/node_modules/ncp/package.json @@ -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" } diff --git a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/a b/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/a deleted file mode 100644 index 802992c42..000000000 --- a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/a +++ /dev/null @@ -1 +0,0 @@ -Hello world diff --git a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/b b/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/b deleted file mode 100644 index 9f6bb1859..000000000 --- a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/b +++ /dev/null @@ -1 +0,0 @@ -Hello ncp diff --git a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/c b/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/c deleted file mode 100644 index e69de29bb..000000000 diff --git a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/d b/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/d deleted file mode 100644 index e69de29bb..000000000 diff --git a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/e b/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/e deleted file mode 100644 index e69de29bb..000000000 diff --git a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/f b/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/f deleted file mode 100644 index e69de29bb..000000000 diff --git a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/sub/a b/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/sub/a deleted file mode 100644 index cf291b5e2..000000000 --- a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/sub/a +++ /dev/null @@ -1 +0,0 @@ -Hello nodejitsu diff --git a/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/sub/b b/node_modules/fs-extra/node_modules/ncp/test/fixtures/src/sub/b deleted file mode 100644 index e69de29bb..000000000 diff --git a/node_modules/fs-extra/node_modules/ncp/test/ncp.js b/node_modules/fs-extra/node_modules/ncp/test/ncp.js index d9798f9f4..3ddc31027 100644 --- a/node_modules/fs-extra/node_modules/ncp/test/ncp.js +++ b/node_modules/fs-extra/node_modules/ncp/test/ncp.js @@ -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(); + }); }); }); }); diff --git a/node_modules/fs-extra/node_modules/rimraf/package.json b/node_modules/fs-extra/node_modules/rimraf/package.json index ae4f27042..3f10fd637 100644 --- a/node_modules/fs-extra/node_modules/rimraf/package.json +++ b/node_modules/fs-extra/node_modules/rimraf/package.json @@ -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" } diff --git a/node_modules/fs-extra/package.json b/node_modules/fs-extra/package.json index cdb3c2dbb..f4a1a4d65 100755 --- a/node_modules/fs-extra/package.json +++ b/node_modules/fs-extra/package.json @@ -1,6 +1,6 @@ { "name": "fs-extra", - "version": "0.10.0", + "version": "0.11.0", "description": "fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as mkdir -p, cp -r, and rm -rf.", "homepage": "https://github.com/jprichardson/node-fs-extra", "repository": { @@ -41,9 +41,9 @@ } ], "dependencies": { - "ncp": "^0.5.1", + "ncp": "^0.6.0", "mkdirp": "^0.5.0", - "jsonfile": "^1.2.0", + "jsonfile": "^2.0.0", "rimraf": "^2.2.8" }, "devDependencies": { @@ -56,15 +56,15 @@ "scripts": { "test": "mocha test" }, - "readme": "Node.js: fs-extra\n=================\n\n[![build status](https://secure.travis-ci.org/jprichardson/node-fs-extra.png)](http://travis-ci.org/jprichardson/node-fs-extra)\n[![downloads per month](http://img.shields.io/npm/dm/fs-extra.svg)](https://www.npmjs.org/package/fs-extra)\n\nThis module adds a few extra file system methods that aren't included in the native `fs` module. It is a drop in replacement for `fs`.\n\n\n\nWhy?\n----\n\nI got tired of including `mkdirp`, `rimraf`, and `cp -r` in most of my projects. \n\n\n\n\nInstallation\n------------\n\n npm install --save fs-extra\n\n\n\nUsage\n-----\n\n`fs-extra` is a drop in replacement for native `fs`. All methods in `fs` are unmodified and attached to `fs-extra`.\n\nYou don't ever need to include the original `fs` module again:\n\n```javascript\nvar fs = require('fs') //this is no longer necessary\n```\n\nyou can now do this:\n\n```javascript\nvar fs = require('fs-extra'); //var fs = require('fs')\n```\n\nor if you prefer to make it clear that you're using `fs-extra` and not `fs`, you may want \nto do this:\n\n```javascript\n//var fs = require('fs')\nvar fse = require('fs-extra')\n```\n\nyou can also keep both, but it's redundant:\n\n```javascript\nvar fs = require('fs')\nvar fse = require('fs-extra')\n```\n\n\n\nMethods\n-------\n\n**NOTE:** You can still use the native Node.js methods. They are copied over to `fs-extra`.\n\n\n### copy(src, dest, [filter], callback)\n\nCopy a file or directory. The directory can have contents. Like `cp -r`.\n\nSync: `copySync()`\n\n\nExamples:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.copy('/tmp/myfile', '/tmp/mynewfile', function(err){\n if (err) return console.error(err);\n console.log(\"success!\")\n}); //copies file\n\nfs.copy('/tmp/mydir', '/tmp/mynewdir', function(err){\n if (err) return console.error(err);\n console.log(\"success!\")\n}); //copies directory, even if it has subdirectories or files\n```\n\n\n### ensureFile(file, callback) \n\nEnsures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.\n\nAlias: `createFile()`\n\nSync: `createFileSync()`,`ensureFileSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra')\n\nvar file = '/tmp/this/path/does/not/exist/file.txt'\nfs.ensureFile(file, function(err) {\n console.log(err); //null\n //file has now been created, including the directory it is to be placed in\n})\n```\n\n\n### ensureDir(dir, callback) \n\nEnsures that the directory exists. If the directory structure does not exist, it is created.\n\nSync: `ensureDirSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra')\n\nvar dir = '/tmp/this/path/does/not/exist'\nfs.ensureDir(dir, function(err) {\n console.log(err); //null\n //dir has now been created, including the directory it is to be placed in\n})\n```\n\n\n\n### mkdirs(dir, callback) \n\nCreates a directory. If the parent hierarchy doesn't exist, it's created. Like `mkdir -p`.\n\nAlias: `mkdirp()`\n\nSync: `mkdirsSync()` / `mkdirpSync()`\n\n\nExamples:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.mkdirs('/tmp/some/long/path/that/prob/doesnt/exist', function(err){\n if (err) return console.error(err);\n console.log(\"success!\")\n});\n\nfs.mkdirsSync('/tmp/another/path');\n```\n\n\n### move(src, dest, callback)\n\nMoves a file or directory, even across devices.\n\nExample:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile', function(err){\n if (err) return console.error(err);\n console.log(\"success!\")\n});\n```\n\n\n### outputFile(file, data, callback)\n\nAlmost the same as `writeFile` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created.\n\nSync: `outputFileSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra')\nvar file = '/tmp/this/path/does/not/exist/file.txt'\n\nfs.outputFile(file, 'hello!', function(err) {\n console.log(err); //null\n\n fs.readFile(file, 'utf8', function(err, data) {\n console.log(data); //hello!\n })\n})\n```\n\n\n\n### outputJson(file, data, callback)\n\nAlmost the same as `writeJson`, except that if the directory does not exist, it's created.\n\nAlias: `outputJSON()\n\nSync: `outputJsonSync()`, `outputJSONSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra')\nvar file = '/tmp/this/path/does/not/exist/file.txt'\n\nfs.outputJson(file, {name: 'JP'}, function(err) {\n console.log(err); //null\n\n fs.readJson(file, function(err, data) {\n console.log(data.name); //'JP\n })\n})\n```\n\n\n\n### readJson(file, [options], callback) \n\nReads a JSON file and then parses it into an object. `options` are the same that you'd pass to `fs.readFile`.\n\nAlias: `readJSON()`\n\nSync: `readJsonSync()`, `readJSONSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.readJson('./package.json', function(err, packageObj) {\n console.log(packageObj.version); //0.1.3\n});\n```\n\n\n### remove(dir, callback)\n\nRemoves a file or directory. The directory can have contents. Like `rm -rf`.\n\nAlias: `delete()`\n\nSync: `removeSync()` / `deleteSync()`\n\n\nExamples:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.remove('/tmp/myfile', function(err){\n if (err) return console.error(err);\n \n console.log(\"success!\")\n});\n\nfs.removeSync('/home/jprichardson'); //I just deleted my entire HOME directory. \n```\n\n\n\n### writeJson(file, object, [options], callback) \n\nWrites an object to a JSON file. `options` are the same that you'd pass to `fs.readFile`.\n\nAlias: `writeJSON()`\n\nSync: `writeJsonSync()`, `writeJSONSync()`\n\nExample:\n\n```javascript\nvar fs = require('fs-extra');\nfs.writeJson('./package.json', {name: 'fs-extra'}, function(err){\n console.log(err);\n});\n```\n\n\n\nRoadmap\n--------\n\nThis contains items that I'm considering doing. I'd love community feedback.\n\n* File system walker. I really like this one: https://github.com/daaku/nodejs-walker ... this might be adding too much. Thoughts?\n* File/directory tree watcher. There are quite a few. ... this also might be adding too much. I like this one: https://github.com/paulmillr/chokidar, thoughts?\n\n\n\n\nNaming\n------\n\nI put a lot of thought into the naming of these functions. Inspired by @coolaj86's request. So he deserves much of the credit for raising the issue. See discussion(s) here:\n\n* https://github.com/jprichardson/node-fs-extra/issues/2\n* https://github.com/flatiron/utile/issues/11\n* https://github.com/ryanmcgrath/wrench-js/issues/29\n* https://github.com/substack/node-mkdirp/issues/17\n\nFirst, I believe that in as many cases as possible, the [Node.js naming schemes](http://nodejs.org/api/fs.html) should be chosen. However, there are problems with the Node.js own naming schemes.\n\nFor example, `fs.readFile()` and `fs.readdir()`: the **F** is capitalized in *File* and the **d** is not capitalized in *dir*. Perhaps a bit pedantic, but they should still be consistent. Also, Node.js has chosen a lot of POSIX naming schemes, which I believe is great. See: `fs.mkdir()`, `fs.rmdir()`, `fs.chown()`, etc.\n\nWe have a dilemma though. How do you consistently name methods that perform the following POSIX commands: `cp`, `cp -r`, `mkdir -p`, and `rm -rf`?\n\nMy perspective: when in doubt, err on the side of simplicity. A directory is just a hierarchical grouping of directories and files. Consider that for a moment. So when you want to copy it or remove it, in most cases you'll want to copy or remove all of its contents. When you want to create a directory, if the directory that it's suppose to be contained in does not exist, then in most cases you'll want to create that too. \n\nSo, if you want to remove a file or a directory regardless of whether it has contents, just call `fs.remove(path)` or its alias `fs.delete(path)`. If you want to copy a file or a directory whether it has contents, just call `fs.copy(source, destination)`. If you want to create a directory regardless of whether its parent directories exist, just call `fs.mkdirs(path)` or `fs.mkdirp(path)`. \n\n\nCredit\n------\n\n`fs-extra` wouldn't be possible without using the modules from the following authors:\n\n- [Isaac Shlueter](https://github.com/isaacs)\n- [Charlie McConnel](https://github.com/avianflu)\n- [James Halliday](https://github.com/substack)\n- [Andrew Kelley](https://github.com/andrewrk)\n\n\nContributions\n-------------\n\nIf you want to contribute, please add a test. Also, don't change the version in `package.json`.\n\n\n### Contributors\n\n- [*] [JP Richardson](https://github.com/jprichardson)\n- [*] [Mike McNeil](https://github.com/mikermcneil)\n- [*] [Ian Crowther](https://github.com/iancrowther)\n- [*] [Stephen Mathieson](https://github.com/stephenmathieson)\n- [*] [Srirangan](https://github.com/Srirangan)\n- [*] [Uli Köhler](https://github.com/ulikoehler)\n- [1] [Jim Higson](https://github.com/jimhigson)\n- [1] [PatrickJS](https://github.com/gdi2290)\n- [1] [Michael Tiller](https://github.com/xogeny)\n- ``\n\n\n\n\nLicense\n-------\n\n\nLicensed under MIT\n\nCopyright (c) 2011-2014 JP Richardson\n\n[1]: http://nodejs.org/docs/latest/api/fs.html \n\n\n[jsonfile]: https://github.com/jprichardson/node-jsonfile\n\n\n\n\n\n\n\n\n", + "readme": "Node.js: fs-extra\n=================\n\n[![build status](https://secure.travis-ci.org/jprichardson/node-fs-extra.svg)](http://travis-ci.org/jprichardson/node-fs-extra)\n[![downloads per month](http://img.shields.io/npm/dm/fs-extra.svg)](https://www.npmjs.org/package/fs-extra)\n\nThis module adds a few extra file system methods that aren't included in the native `fs` module. It is a drop in replacement for `fs`.\n\n\n\nWhy?\n----\n\nI got tired of including `mkdirp`, `rimraf`, and `cp -r` in most of my projects. \n\n\n\n\nInstallation\n------------\n\n npm install --save fs-extra\n\n\n\nUsage\n-----\n\n`fs-extra` is a drop in replacement for native `fs`. All methods in `fs` are unmodified and attached to `fs-extra`.\n\nYou don't ever need to include the original `fs` module again:\n\n```javascript\nvar fs = require('fs') //this is no longer necessary\n```\n\nyou can now do this:\n\n```javascript\nvar fs = require('fs-extra'); //var fs = require('fs')\n```\n\nor if you prefer to make it clear that you're using `fs-extra` and not `fs`, you may want \nto do this:\n\n```javascript\n//var fs = require('fs')\nvar fse = require('fs-extra')\n```\n\nyou can also keep both, but it's redundant:\n\n```javascript\nvar fs = require('fs')\nvar fse = require('fs-extra')\n```\n\n\n\nMethods\n-------\n\n**NOTE:** You can still use the native Node.js methods. They are copied over to `fs-extra`.\n\n\n### copy(src, dest, [filter], callback)\n\nCopy a file or directory. The directory can have contents. Like `cp -r`.\n\nSync: `copySync()`\n\n\nExamples:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.copy('/tmp/myfile', '/tmp/mynewfile', function(err){\n if (err) return console.error(err);\n console.log(\"success!\")\n}); //copies file\n\nfs.copy('/tmp/mydir', '/tmp/mynewdir', function(err){\n if (err) return console.error(err);\n console.log(\"success!\")\n}); //copies directory, even if it has subdirectories or files\n```\n\n\n### ensureFile(file, callback) \n\nEnsures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.\n\nAlias: `createFile()`\n\nSync: `createFileSync()`,`ensureFileSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra')\n\nvar file = '/tmp/this/path/does/not/exist/file.txt'\nfs.ensureFile(file, function(err) {\n console.log(err); //null\n //file has now been created, including the directory it is to be placed in\n})\n```\n\n\n### ensureDir(dir, callback) \n\nEnsures that the directory exists. If the directory structure does not exist, it is created.\n\nSync: `ensureDirSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra')\n\nvar dir = '/tmp/this/path/does/not/exist'\nfs.ensureDir(dir, function(err) {\n console.log(err); //null\n //dir has now been created, including the directory it is to be placed in\n})\n```\n\n\n\n### mkdirs(dir, callback) \n\nCreates a directory. If the parent hierarchy doesn't exist, it's created. Like `mkdir -p`.\n\nAlias: `mkdirp()`\n\nSync: `mkdirsSync()` / `mkdirpSync()`\n\n\nExamples:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.mkdirs('/tmp/some/long/path/that/prob/doesnt/exist', function(err){\n if (err) return console.error(err);\n console.log(\"success!\")\n});\n\nfs.mkdirsSync('/tmp/another/path');\n```\n\n\n### move(src, dest, callback)\n\nMoves a file or directory, even across devices.\n\nExample:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile', function(err){\n if (err) return console.error(err);\n console.log(\"success!\")\n});\n```\n\n\n### outputFile(file, data, callback)\n\nAlmost the same as `writeFile` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created.\n\nSync: `outputFileSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra')\nvar file = '/tmp/this/path/does/not/exist/file.txt'\n\nfs.outputFile(file, 'hello!', function(err) {\n console.log(err); //null\n\n fs.readFile(file, 'utf8', function(err, data) {\n console.log(data); //hello!\n })\n})\n```\n\n\n\n### outputJson(file, data, callback)\n\nAlmost the same as `writeJson`, except that if the directory does not exist, it's created.\n\nAlias: `outputJSON()\n\nSync: `outputJsonSync()`, `outputJSONSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra')\nvar file = '/tmp/this/path/does/not/exist/file.txt'\n\nfs.outputJson(file, {name: 'JP'}, function(err) {\n console.log(err); //null\n\n fs.readJson(file, function(err, data) {\n console.log(data.name); //'JP\n })\n})\n```\n\n\n\n### readJson(file, [options], callback) \n\nReads a JSON file and then parses it into an object. `options` are the same that you'd pass to `fs.readFile`.\n\nAlias: `readJSON()`\n\nSync: `readJsonSync()`, `readJSONSync()`\n\n\nExample:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.readJson('./package.json', function(err, packageObj) {\n console.log(packageObj.version); //0.1.3\n});\n```\n\n`readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:\n\n```js\nvar fs = require('fs-extra')\nvar file = path.join('/tmp/some-invalid.json')\nvar data = \"{not valid JSON\"\nfs.writeFileSync(file, data)\n\nvar obj = fs.readJsonSync(file, {throws: false})\nconsole.log(obj) // => null\n```\n\n\n### remove(dir, callback)\n\nRemoves a file or directory. The directory can have contents. Like `rm -rf`.\n\nAlias: `delete()`\n\nSync: `removeSync()` / `deleteSync()`\n\n\nExamples:\n\n```javascript\nvar fs = require('fs-extra');\n\nfs.remove('/tmp/myfile', function(err){\n if (err) return console.error(err);\n \n console.log(\"success!\")\n});\n\nfs.removeSync('/home/jprichardson'); //I just deleted my entire HOME directory. \n```\n\n\n\n### writeJson(file, object, [options], callback) \n\nWrites an object to a JSON file. `options` are the same that you'd pass to `fs.readFile`.\n\nAlias: `writeJSON()`\n\nSync: `writeJsonSync()`, `writeJSONSync()`\n\nExample:\n\n```javascript\nvar fs = require('fs-extra');\nfs.writeJson('./package.json', {name: 'fs-extra'}, function(err){\n console.log(err);\n});\n```\n\n\n\nRoadmap\n--------\n\nThis contains items that I'm considering doing. I'd love community feedback.\n\n* File system walker. I really like this one: https://github.com/daaku/nodejs-walker ... this might be adding too much. Thoughts?\n* File/directory tree watcher. There are quite a few. ... this also might be adding too much. I like this one: https://github.com/paulmillr/chokidar, thoughts?\n\n\n\n\nNaming\n------\n\nI put a lot of thought into the naming of these functions. Inspired by @coolaj86's request. So he deserves much of the credit for raising the issue. See discussion(s) here:\n\n* https://github.com/jprichardson/node-fs-extra/issues/2\n* https://github.com/flatiron/utile/issues/11\n* https://github.com/ryanmcgrath/wrench-js/issues/29\n* https://github.com/substack/node-mkdirp/issues/17\n\nFirst, I believe that in as many cases as possible, the [Node.js naming schemes](http://nodejs.org/api/fs.html) should be chosen. However, there are problems with the Node.js own naming schemes.\n\nFor example, `fs.readFile()` and `fs.readdir()`: the **F** is capitalized in *File* and the **d** is not capitalized in *dir*. Perhaps a bit pedantic, but they should still be consistent. Also, Node.js has chosen a lot of POSIX naming schemes, which I believe is great. See: `fs.mkdir()`, `fs.rmdir()`, `fs.chown()`, etc.\n\nWe have a dilemma though. How do you consistently name methods that perform the following POSIX commands: `cp`, `cp -r`, `mkdir -p`, and `rm -rf`?\n\nMy perspective: when in doubt, err on the side of simplicity. A directory is just a hierarchical grouping of directories and files. Consider that for a moment. So when you want to copy it or remove it, in most cases you'll want to copy or remove all of its contents. When you want to create a directory, if the directory that it's suppose to be contained in does not exist, then in most cases you'll want to create that too. \n\nSo, if you want to remove a file or a directory regardless of whether it has contents, just call `fs.remove(path)` or its alias `fs.delete(path)`. If you want to copy a file or a directory whether it has contents, just call `fs.copy(source, destination)`. If you want to create a directory regardless of whether its parent directories exist, just call `fs.mkdirs(path)` or `fs.mkdirp(path)`. \n\n\nCredit\n------\n\n`fs-extra` wouldn't be possible without using the modules from the following authors:\n\n- [Isaac Shlueter](https://github.com/isaacs)\n- [Charlie McConnel](https://github.com/avianflu)\n- [James Halliday](https://github.com/substack)\n- [Andrew Kelley](https://github.com/andrewrk)\n\n\nContributions\n-------------\n\nIf you want to contribute, please add a test. Also, don't change the version in `package.json`.\n\n\n### Contributors\n\n- [*] [JP Richardson](https://github.com/jprichardson)\n- [*] [Mike McNeil](https://github.com/mikermcneil)\n- [*] [Ian Crowther](https://github.com/iancrowther)\n- [*] [Stephen Mathieson](https://github.com/stephenmathieson)\n- [*] [Srirangan](https://github.com/Srirangan)\n- [*] [Uli Köhler](https://github.com/ulikoehler)\n- [1] [Jim Higson](https://github.com/jimhigson)\n- [1] [PatrickJS](https://github.com/gdi2290)\n- [1] [Michael Tiller](https://github.com/xogeny)\n- ``\n\n\n\n\nLicense\n-------\n\n\nLicensed under MIT\n\nCopyright (c) 2011-2014 JP Richardson\n\n[1]: http://nodejs.org/docs/latest/api/fs.html \n\n\n[jsonfile]: https://github.com/jprichardson/node-jsonfile\n\n\n\n\n\n\n\n\n", "readmeFilename": "README.md", "bugs": { "url": "https://github.com/jprichardson/node-fs-extra/issues" }, - "_id": "fs-extra@0.10.0", + "_id": "fs-extra@0.11.0", "dist": { - "shasum": "d63a0ca92629f4d4f4827cd1e725b4d467c44da6" + "shasum": "68241bd6003cbfd61e76fe4e51044de266fe9b9e" }, - "_from": "fs-extra@~0.10.0", - "_resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.10.0.tgz" + "_from": "fs-extra@~0.11", + "_resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.11.0.tgz" }