[Pkg-javascript-commits] [node-fs-extra] 01/05: New upstream version 2.0.0
Julien Puydt
julien.puydt at laposte.net
Fri Jan 20 08:31:24 UTC 2017
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-fs-extra.
commit d2f96393ff3a804a878490b2b40305b70487f00b
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Fri Jan 20 09:25:16 2017 +0100
New upstream version 2.0.0
---
.travis.yml | 2 -
CHANGELOG.md | 56 +++
LICENSE | 2 +-
README.md | 428 ++-------------------
appveyor.yml | 1 -
docs/copy.md | 28 ++
docs/emptyDir.md | 18 +
docs/ensureDir.md | 20 +
docs/ensureFile.md | 20 +
docs/ensureLink.md | 19 +
docs/ensureSymlink.md | 19 +
docs/move.md | 17 +
docs/outputFile.md | 21 +
docs/outputJson.md | 24 ++
docs/readJson.md | 33 ++
docs/remove.md | 20 +
docs/writeJson.md | 21 +
lib/copy-sync/__tests__/copy-sync-dir.test.js | 22 +-
lib/copy-sync/__tests__/copy-sync-file.test.js | 68 +++-
lib/copy-sync/copy-file-sync.js | 15 +-
lib/copy-sync/copy-sync.js | 28 +-
lib/copy/__tests__/ncp/ncp.test.js | 41 +-
lib/copy/ncp.js | 18 +-
lib/index.js | 2 -
lib/move/__tests__/fixtures/a-file | 1 -
lib/move/__tests__/fixtures/a-folder/another-file | 1 -
.../fixtures/a-folder/another-folder/file3 | 1 -
lib/move/__tests__/move-clobber.test.js | 68 ----
lib/move/__tests__/move.test.js | 158 ++++++--
lib/move/index.js | 38 +-
lib/remove/__tests__/remove.test.js | 40 ++
lib/walk-sync/__tests__/fixtures/dir1/file1_2 | 0
.../__tests__/fixtures/dir2/dir2_1/file2_1_1 | 0
lib/walk-sync/__tests__/fixtures/file1 | 0
lib/walk-sync/__tests__/walkSync.test.js | 41 --
lib/walk-sync/index.js | 20 -
lib/walk/__tests__/fixtures.json | 7 -
lib/walk/__tests__/walk.test.js | 73 ----
lib/walk/index.js | 5 -
package.json | 6 +-
test.js | 4 +-
41 files changed, 680 insertions(+), 726 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 2cc138c..0cfd6a5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,8 +1,6 @@
sudo: false
language: node_js
node_js:
- - "0.12"
- - "io.js"
- "4"
- "5"
- "6"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43b1f3a..7f810c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,25 @@ Unreleased
### Fixed
+2.0.0 / 2017-01-16
+------------------
+
+### Removed
+- **BREAKING:** Removed support for Node `v0.12`. The Node foundation stopped officially supporting it
+on Jan 1st, 2017.
+- **BREAKING:** Remove `walk()` and `walkSync()`. `walkSync()` was only part of `fs-extra` for a little
+over two months. Use [klaw](https://github.com/jprichardson/node-klaw) instead of `walk()`, in fact, `walk()` was just
+an alias to klaw. For `walkSync()` use [klaw-sync](https://github.com/mawni/node-klaw-sync). See: [#338], [#339]
+
+### Changed
+- **BREAKING:** Renamed `clobber` to `overwrite`. This affects `copy()`, `copySync()`, and `move()`. [#330], [#333]
+- Moved docs, to `docs/`. [#340]
+
+### Fixed
+- Apply filters to directories in `copySync()` like in `copy()`. [#324]
+- A specific condition when disk is under heavy use, `copy()` can fail. [#326]
+
+
1.0.0 / 2016-11-01
------------------
@@ -348,6 +367,43 @@ from `~` to `^`. #67
* Moved tests from Jasmine to Mocha
+[#344]: https://github.com/jprichardson/node-fs-extra/issues/344 "Licence Year"
+[#343]: https://github.com/jprichardson/node-fs-extra/pull/343 "Add klaw-sync link to readme"
+[#342]: https://github.com/jprichardson/node-fs-extra/pull/342 "allow preserveTimestamps when use move"
+[#341]: https://github.com/jprichardson/node-fs-extra/issues/341 "mkdirp(path.dirname(dest) in move() logic needs cleaning up [question]"
+[#340]: https://github.com/jprichardson/node-fs-extra/pull/340 "Move docs to seperate docs folder [documentation]"
+[#339]: https://github.com/jprichardson/node-fs-extra/pull/339 "Remove walk() & walkSync() [feature-walk]"
+[#338]: https://github.com/jprichardson/node-fs-extra/issues/338 "Remove walk() and walkSync() [feature-walk]"
+[#337]: https://github.com/jprichardson/node-fs-extra/issues/337 "copy doesn't return a yieldable value"
+[#336]: https://github.com/jprichardson/node-fs-extra/pull/336 "Docs enhanced walk sync [documentation, feature-walk]"
+[#335]: https://github.com/jprichardson/node-fs-extra/pull/335 "Refactor move() tests [feature-move]"
+[#334]: https://github.com/jprichardson/node-fs-extra/pull/334 "Cleanup lib/move/index.js [feature-move]"
+[#333]: https://github.com/jprichardson/node-fs-extra/pull/333 "Rename clobber to overwrite [feature-copy, feature-move]"
+[#332]: https://github.com/jprichardson/node-fs-extra/pull/332 "BREAKING: Drop Node v0.12 & io.js support"
+[#331]: https://github.com/jprichardson/node-fs-extra/issues/331 "Add support for chmodr [enhancement, future]"
+[#330]: https://github.com/jprichardson/node-fs-extra/pull/330 "BREAKING: Do not error when copy destination exists & clobber: false [feature-copy]"
+[#329]: https://github.com/jprichardson/node-fs-extra/issues/329 "Does .walk() scale to large directories? [question]"
+[#328]: https://github.com/jprichardson/node-fs-extra/issues/328 "Copying files corrupts [feature-copy, needs-confirmed]"
+[#327]: https://github.com/jprichardson/node-fs-extra/pull/327 "Use writeStream 'finish' event instead of 'close' [bug, feature-copy]"
+[#326]: https://github.com/jprichardson/node-fs-extra/issues/326 "fs.copy fails with chmod error when disk under heavy use [bug, feature-copy]"
+[#325]: https://github.com/jprichardson/node-fs-extra/issues/325 "ensureDir is difficult to promisify [enhancement]"
+[#324]: https://github.com/jprichardson/node-fs-extra/pull/324 "copySync() should apply filter to directories like copy() [bug, feature-copy]"
+[#323]: https://github.com/jprichardson/node-fs-extra/issues/323 "Support for `dest` being a directory when using `copy*()`?"
+[#322]: https://github.com/jprichardson/node-fs-extra/pull/322 "Add fs-promise as fs-extra-promise alternative"
+[#321]: https://github.com/jprichardson/node-fs-extra/issues/321 "fs.copy() with clobber set to false return EEXIST error [feature-copy]"
+[#320]: https://github.com/jprichardson/node-fs-extra/issues/320 "fs.copySync: Error: EPERM: operation not permitted, unlink "
+[#319]: https://github.com/jprichardson/node-fs-extra/issues/319 "Create directory if not exists"
+[#318]: https://github.com/jprichardson/node-fs-extra/issues/318 "Support glob patterns [enhancement, future]"
+[#317]: https://github.com/jprichardson/node-fs-extra/pull/317 "Adding copy sync test for src file without write perms"
+[#316]: https://github.com/jprichardson/node-fs-extra/pull/316 "Remove move()'s broken limit option [feature-move]"
+[#315]: https://github.com/jprichardson/node-fs-extra/pull/315 "Fix move clobber tests to work around graceful-fs bug."
+[#314]: https://github.com/jprichardson/node-fs-extra/issues/314 "move() limit option [documentation, enhancement, feature-move]"
+[#313]: https://github.com/jprichardson/node-fs-extra/pull/313 "Test that remove() ignores glob characters."
+[#312]: https://github.com/jprichardson/node-fs-extra/pull/312 "Enhance walkSync() to return items with path and stats [feature-walk]"
+[#311]: https://github.com/jprichardson/node-fs-extra/issues/311 "move() not work when dest name not provided [feature-move]"
+[#310]: https://github.com/jprichardson/node-fs-extra/issues/310 "Edit walkSync to return items like what walk emits [documentation, enhancement, feature-walk]"
+[#309]: https://github.com/jprichardson/node-fs-extra/issues/309 "moveSync support [enhancement, feature-move]"
+[#308]: https://github.com/jprichardson/node-fs-extra/pull/308 "Fix incorrect anchor link"
[#307]: https://github.com/jprichardson/node-fs-extra/pull/307 "Fix coverage"
[#306]: https://github.com/jprichardson/node-fs-extra/pull/306 "Update devDeps, fix lint error"
[#305]: https://github.com/jprichardson/node-fs-extra/pull/305 "Re-add Coveralls"
diff --git a/LICENSE b/LICENSE
index f109d23..93546df 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
(The MIT License)
-Copyright (c) 2011-2016 JP Richardson
+Copyright (c) 2011-2017 JP Richardson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
diff --git a/README.md b/README.md
index 8c53ff2..4805844 100644
--- a/README.md
+++ b/README.md
@@ -11,8 +11,6 @@ Node.js: fs-extra
<a href="https://github.com/feross/standard"><img src="https://cdn.rawgit.com/feross/standard/master/sticker.svg" alt="Standard JavaScript" width="100"></a>
-**NOTE (2016-04-28):** Node v0.10 will be unsupported 2016-10-01. Node v0.12 will be unsupported on 2017-04-01.
-
Why?
----
@@ -87,399 +85,38 @@ try {
Methods
-------
-- [copy](#copy)
-- [copySync](#copy)
-- [emptyDir](#emptydirdir-callback)
-- [emptyDirSync](#emptydirdir-callback)
-- [ensureFile](#ensurefilefile-callback)
-- [ensureFileSync](#ensurefilefile-callback)
-- [ensureDir](#ensuredirdir-callback)
-- [ensureDirSync](#ensuredirdir-callback)
-- [ensureLink](#ensurelinksrcpath-dstpath-callback)
-- [ensureLinkSync](#ensurelinksrcpath-dstpath-callback)
-- [ensureSymlink](#ensuresymlinksrcpath-dstpath-type-callback)
-- [ensureSymlinkSync](#ensuresymlinksrcpath-dstpath-type-callback)
-- [mkdirs](#mkdirsdir-callback)
-- [mkdirsSync](#mkdirsdir-callback)
-- [move](#movesrc-dest-options-callback)
-- [outputFile](#outputfilefile-data-options-callback)
-- [outputFileSync](#outputfilefile-data-options-callback)
-- [outputJson](#outputjsonfile-data-options-callback)
-- [outputJsonSync](#outputjsonfile-data-options-callback)
-- [readJson](#readjsonfile-options-callback)
-- [readJsonSync](#readjsonfile-options-callback)
-- [remove](#removedir-callback)
-- [removeSync](#removedir-callback)
-- [walk](#walk)
-- [walkSync](#walkSyncDir)
-- [writeJson](#writejsonfile-object-options-callback)
-- [writeJsonSync](#writejsonfile-object-options-callback)
+- [copy](docs/copy.md)
+- [copySync](docs/copy.md)
+- [emptyDir](docs/emptyDir.md)
+- [emptyDirSync](docs/emptyDir.md)
+- [ensureFile](docs/ensureFile.md)
+- [ensureFileSync](docs/ensureFile.md)
+- [ensureDir](docs/ensureDir.md)
+- [ensureDirSync](docs/ensureDir.md)
+- [ensureLink](docs/ensureLink.md)
+- [ensureLinkSync](docs/ensureLink.md)
+- [ensureSymlink](docs/ensureSymlink.md)
+- [ensureSymlinkSync](docs/ensureSymlink.md)
+- [mkdirs](docs/ensureDir.md)
+- [mkdirsSync](docs/ensureDir.md)
+- [move](docs/move.md)
+- [outputFile](docs/outputFile.md)
+- [outputFileSync](docs/outputFile.md)
+- [outputJson](docs/outputJson.md)
+- [outputJsonSync](docs/outputJson.md)
+- [readJson](docs/readJson.md)
+- [readJsonSync](docs/readJson.md)
+- [remove](docs/remove.md)
+- [removeSync](docs/remove.md)
+- [writeJson](docs/writeJson.md)
+- [writeJsonSync](docs/writeJson.md)
**NOTE:** You can still use the native Node.js methods. They are copied over to `fs-extra`.
+### What happened to `walk()` and `walkSync()`?
-### copy()
-
-**copy(src, dest, [options], callback)**
-
-
-Copy a file or directory. The directory can have contents. Like `cp -r`.
-
-Options:
-- clobber (boolean): overwrite existing file or directory, default is `true`.
-- dereference (boolean): dereference symlinks, default is `false`.
-- preserveTimestamps (boolean): will set last modification and access times to the ones of the original source files, default is `false`.
-- filter: Function to filter copied files. Return `true` to include, `false` to exclude. This can also be a RegExp, however this is deprecated (See [issue #239](https://github.com/jprichardson/node-fs-extra/issues/239) for background). _Warning: `copySync` currently applies the filter only to files (see [#180](https://github.com/jprichardson/node-fs-extra/issues/180)). This will be fixed in a future release._
-
-Sync: `copySync()`
-
-Example:
-
-```js
-var fs = require('fs-extra')
-
-fs.copy('/tmp/myfile', '/tmp/mynewfile', function (err) {
- if (err) return console.error(err)
- console.log("success!")
-}) // copies file
-
-fs.copy('/tmp/mydir', '/tmp/mynewdir', function (err) {
- if (err) return console.error(err)
- console.log('success!')
-}) // copies directory, even if it has subdirectories or files
-```
-
-
-### emptyDir(dir, [callback])
-
-Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.
-
-Alias: `emptydir()`
-
-Sync: `emptyDirSync()`, `emptydirSync()`
-
-Example:
-
-```js
-var fs = require('fs-extra')
-
-// assume this directory has a lot of files and folders
-fs.emptyDir('/tmp/some/dir', function (err) {
- if (!err) console.log('success!')
-})
-```
-
-
-### ensureFile(file, callback)
-
-Ensures 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**.
-
-Alias: `createFile()`
-
-Sync: `createFileSync()`,`ensureFileSync()`
-
-
-Example:
-
-```js
-var fs = require('fs-extra')
-
-var file = '/tmp/this/path/does/not/exist/file.txt'
-fs.ensureFile(file, function (err) {
- console.log(err) // => null
- // file has now been created, including the directory it is to be placed in
-})
-```
-
-
-### ensureDir(dir, callback)
-
-Ensures that the directory exists. If the directory structure does not exist, it is created.
-
-Sync: `ensureDirSync()`
-
-
-Example:
-
-```js
-var fs = require('fs-extra')
-
-var dir = '/tmp/this/path/does/not/exist'
-fs.ensureDir(dir, function (err) {
- console.log(err) // => null
- // dir has now been created, including the directory it is to be placed in
-})
-```
-
-
-### ensureLink(srcpath, dstpath, callback)
-
-Ensures that the link exists. If the directory structure does not exist, it is created.
-
-Sync: `ensureLinkSync()`
-
-
-Example:
-
-```js
-var fs = require('fs-extra')
-
-var srcpath = '/tmp/file.txt'
-var dstpath = '/tmp/this/path/does/not/exist/file.txt'
-fs.ensureLink(srcpath, dstpath, function (err) {
- console.log(err) // => null
- // link has now been created, including the directory it is to be placed in
-})
-```
-
-
-### ensureSymlink(srcpath, dstpath, [type], callback)
-
-Ensures that the symlink exists. If the directory structure does not exist, it is created.
-
-Sync: `ensureSymlinkSync()`
-
-
-Example:
-
-```js
-var fs = require('fs-extra')
-
-var srcpath = '/tmp/file.txt'
-var dstpath = '/tmp/this/path/does/not/exist/file.txt'
-fs.ensureSymlink(srcpath, dstpath, function (err) {
- console.log(err) // => null
- // symlink has now been created, including the directory it is to be placed in
-})
-```
-
-
-### mkdirs(dir, callback)
-
-Creates a directory. If the parent hierarchy doesn't exist, it's created. Like `mkdir -p`.
-
-Alias: `mkdirp()`
-
-Sync: `mkdirsSync()` / `mkdirpSync()`
-
-
-Examples:
-
-```js
-var fs = require('fs-extra')
-
-fs.mkdirs('/tmp/some/long/path/that/prob/doesnt/exist', function (err) {
- if (err) return console.error(err)
- console.log("success!")
-})
-
-fs.mkdirsSync('/tmp/another/path')
-```
-
-
-### move(src, dest, [options], callback)
-
-Moves a file or directory, even across devices.
-
-Options:
-- clobber (boolean): overwrite existing file or directory
-- limit (number): number of concurrent moves, see ncp for more information
-
-Example:
-
-```js
-var fs = require('fs-extra')
-
-fs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile', function (err) {
- if (err) return console.error(err)
- console.log("success!")
-})
-```
-
-
-### outputFile(file, data, [options], callback)
-
-Almost 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. `options` are what you'd pass to [`fs.writeFile()`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback).
-
-Sync: `outputFileSync()`
-
-
-Example:
-
-```js
-var fs = require('fs-extra')
-var file = '/tmp/this/path/does/not/exist/file.txt'
-
-fs.outputFile(file, 'hello!', function (err) {
- console.log(err) // => null
-
- fs.readFile(file, 'utf8', function (err, data) {
- console.log(data) // => hello!
- })
-})
-```
-
-
-
-### outputJson(file, data, [options], callback)
-
-Almost the same as `writeJson`, except that if the directory does not exist, it's created.
-`options` are what you'd pass to [`jsonFile.writeFile()`](https://github.com/jprichardson/node-jsonfile#writefilefilename-options-callback).
-
-Alias: `outputJSON()`
-
-Sync: `outputJsonSync()`, `outputJSONSync()`
-
-
-Example:
-
-```js
-var fs = require('fs-extra')
-var file = '/tmp/this/path/does/not/exist/file.txt'
-
-fs.outputJson(file, {name: 'JP'}, function (err) {
- console.log(err) // => null
-
- fs.readJson(file, function(err, data) {
- console.log(data.name) // => JP
- })
-})
-```
-
-
-
-### readJson(file, [options], callback)
-
-Reads a JSON file and then parses it into an object. `options` are the same
-that you'd pass to [`jsonFile.readFile`](https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback).
-
-Alias: `readJSON()`
-
-Sync: `readJsonSync()`, `readJSONSync()`
-
-
-Example:
-
-```js
-var fs = require('fs-extra')
-
-fs.readJson('./package.json', function (err, packageObj) {
- console.log(packageObj.version) // => 0.1.3
-})
-```
-
-`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)
-
-Removes a file or directory. The directory can have contents. Like `rm -rf`.
-
-Sync: `removeSync()`
-
-
-Examples:
-
-```js
-var fs = require('fs-extra')
-
-fs.remove('/tmp/myfile', function (err) {
- if (err) return console.error(err)
-
- console.log('success!')
-})
-
-fs.removeSync('/home/jprichardson') //I just deleted my entire HOME directory.
-```
-
-### walk()
-
-**walk(dir, [streamOptions])**
-
-The function `walk()` from the module [`klaw`](https://github.com/jprichardson/node-klaw).
-
-Returns a [Readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) that iterates
-through every file and directory starting with `dir` as the root. Every `read()` or `data` event
-returns an object with two properties: `path` and `stats`. `path` is the full path of the file and
-`stats` is an instance of [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats).
-
-Streams 1 (push) example:
-
-```js
-var fs = require('fs-extra')
-var items = [] // files, directories, symlinks, etc
-fs.walk(TEST_DIR)
- .on('data', function (item) {
- items.push(item.path)
- })
- .on('end', function () {
- console.dir(items) // => [ ... array of files]
- })
-```
-
-Streams 2 & 3 (pull) example:
-
-```js
-var items = [] // files, directories, symlinks, etc
-var fs = require('fs-extra')
-fs.walk(TEST_DIR)
- .on('readable', function () {
- var item
- while ((item = this.read())) {
- items.push(item.path)
- }
- })
- .on('end', function () {
- console.dir(items) // => [ ... array of files]
- })
-```
-
-If you're not sure of the differences on Node.js streams 1, 2, 3 then I'd
-recommend this resource as a good starting point: https://strongloop.com/strongblog/whats-new-io-js-beta-streams3/.
-
-**See [`klaw` documentation](https://github.com/jprichardson/node-klaw) for more detailed usage.**
-
-### walkSync(dir)
-
-Lists all files inside a directory recursively
-
-Examples:
-
-```js
-var fs = require('fs-extra')
-
-var files = fs.walkSync('/home/jprichardson')
-// files = ['/home/jprichardson/file1', '/home/jprichardson/dir1/file2']
-```
-
-### writeJson(file, object, [options], callback)
-
-Writes an object to a JSON file. `options` are the same that
-you'd pass to [`jsonFile.writeFile()`](https://github.com/jprichardson/node-jsonfile#writefilefilename-options-callback).
-
-Alias: `writeJSON()`
-
-Sync: `writeJsonSync()`, `writeJSONSync()`
-
-Example:
-
-```js
-var fs = require('fs-extra')
-fs.writeJson('./package.json', {name: 'fs-extra'}, function (err) {
- console.log(err)
-})
-```
+They were removed from `fs-extra` in v2.0.0. If you need the functionality, `walk` and `walkSync` are available as separate packages, [`klaw`](https://github.com/jprichardson/node-klaw) and [`klaw-sync`](https://github.com/mawni/node-klaw-sync).
Third Party
@@ -495,7 +132,12 @@ var Promise = require('bluebird')
var fs = Promise.promisifyAll(require('fs-extra'))
```
-Or you can use the package [`fs-extra-promise`](https://github.com/overlookmotel/fs-extra-promise) that marries the two together.
+Or you can use a dedicated package:
+
+- [`fs-extra-promise`](https://github.com/overlookmotel/fs-extra-promise) uses Bluebird.
+- [`fs-promise`](https://github.com/kevinbeaty/fs-promise) uses
+ [Any Promise](https://github.com/kevinbeaty/any-promise) and also covers
+ [`mz/fs`](https://github.com/normalize/mz/blob/master/fs.js).
### TypeScript
@@ -527,8 +169,6 @@ What's needed?
- First, take a look at existing issues. Those are probably going to be where the priority lies.
- More tests for edge cases. Specifically on different platforms. There can never be enough tests.
- Improve test coverage. See coveralls output for more info.
-- After the directory walker is integrated, any function that needs to traverse directories like
-`copy`, `remove`, or `mkdirs` should be built on top of it.
Note: If you make any big changes, **you should definitely file an issue for discussion first.**
@@ -595,7 +235,7 @@ License
Licensed under MIT
-Copyright (c) 2011-2016 [JP Richardson](https://github.com/jprichardson)
+Copyright (c) 2011-2017 [JP Richardson](https://github.com/jprichardson)
[1]: http://nodejs.org/docs/latest/api/fs.html
diff --git a/appveyor.yml b/appveyor.yml
index 591f933..8aeb13b 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -2,7 +2,6 @@
environment:
matrix:
# node.js
- - nodejs_version: "0.12"
- nodejs_version: "4"
- nodejs_version: "6"
diff --git a/docs/copy.md b/docs/copy.md
new file mode 100644
index 0000000..617510f
--- /dev/null
+++ b/docs/copy.md
@@ -0,0 +1,28 @@
+# copy(src, dest, [options], callback)
+
+Copy a file or directory. The directory can have contents. Like `cp -r`.
+
+**Sync:** `copySync()`
+
+## Options:
+- overwrite (boolean): overwrite existing file or directory, default is `true`. _Note that the copy operation will silently fail if you set this to `false` and the destination exists._ Use the `errorOnExist` option to change this behavior.
+- errorOnExist (boolean): when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.
+- dereference (boolean): dereference symlinks, default is `false`.
+- preserveTimestamps (boolean): will set last modification and access times to the ones of the original source files, default is `false`.
+- filter: Function to filter copied files. Return `true` to include, `false` to exclude. This can also be a RegExp, however this is deprecated (See [issue #239](https://github.com/jprichardson/node-fs-extra/issues/239) for background).
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+
+fs.copy('/tmp/myfile', '/tmp/mynewfile', function (err) {
+ if (err) return console.error(err)
+ console.log("success!")
+}) // copies file
+
+fs.copy('/tmp/mydir', '/tmp/mynewdir', function (err) {
+ if (err) return console.error(err)
+ console.log('success!')
+}) // copies directory, even if it has subdirectories or files
+```
diff --git a/docs/emptyDir.md b/docs/emptyDir.md
new file mode 100644
index 0000000..d57c151
--- /dev/null
+++ b/docs/emptyDir.md
@@ -0,0 +1,18 @@
+# emptyDir(dir, [callback])
+
+Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.
+
+**Alias:** `emptydir()`
+
+**Sync:** `emptyDirSync()`, `emptydirSync()`
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+
+// assume this directory has a lot of files and folders
+fs.emptyDir('/tmp/some/dir', function (err) {
+ if (!err) console.log('success!')
+})
+```
diff --git a/docs/ensureDir.md b/docs/ensureDir.md
new file mode 100644
index 0000000..ac704e0
--- /dev/null
+++ b/docs/ensureDir.md
@@ -0,0 +1,20 @@
+# ensureDir(dir, callback)
+
+Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`.
+
+**Aliases:** `mkdirs()`, `mkdirp()`
+
+**Sync:** `ensureDirSync()`, `mkdirsSync()`, `mkdirpSync()`
+
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+
+var dir = '/tmp/this/path/does/not/exist'
+fs.ensureDir(dir, function (err) {
+ console.log(err) // => null
+ // dir has now been created, including the directory it is to be placed in
+})
+```
diff --git a/docs/ensureFile.md b/docs/ensureFile.md
new file mode 100644
index 0000000..21fcc8e
--- /dev/null
+++ b/docs/ensureFile.md
@@ -0,0 +1,20 @@
+# ensureFile(file, callback)
+
+Ensures 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**.
+
+**Alias:** `createFile()`
+
+**Sync:** `createFileSync()`,`ensureFileSync()`
+
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+
+var file = '/tmp/this/path/does/not/exist/file.txt'
+fs.ensureFile(file, function (err) {
+ console.log(err) // => null
+ // file has now been created, including the directory it is to be placed in
+})
+```
diff --git a/docs/ensureLink.md b/docs/ensureLink.md
new file mode 100644
index 0000000..25df997
--- /dev/null
+++ b/docs/ensureLink.md
@@ -0,0 +1,19 @@
+# ensureLink(srcpath, dstpath, callback)
+
+Ensures that the link exists. If the directory structure does not exist, it is created.
+
+**Sync:** `ensureLinkSync()`
+
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+
+var srcpath = '/tmp/file.txt'
+var dstpath = '/tmp/this/path/does/not/exist/file.txt'
+fs.ensureLink(srcpath, dstpath, function (err) {
+ console.log(err) // => null
+ // link has now been created, including the directory it is to be placed in
+})
+```
diff --git a/docs/ensureSymlink.md b/docs/ensureSymlink.md
new file mode 100644
index 0000000..a29754b
--- /dev/null
+++ b/docs/ensureSymlink.md
@@ -0,0 +1,19 @@
+# ensureSymlink(srcpath, dstpath, [type], callback)
+
+Ensures that the symlink exists. If the directory structure does not exist, it is created.
+
+**Sync:** `ensureSymlinkSync()`
+
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+
+var srcpath = '/tmp/file.txt'
+var dstpath = '/tmp/this/path/does/not/exist/file.txt'
+fs.ensureSymlink(srcpath, dstpath, function (err) {
+ console.log(err) // => null
+ // symlink has now been created, including the directory it is to be placed in
+})
+```
diff --git a/docs/move.md b/docs/move.md
new file mode 100644
index 0000000..5ff9153
--- /dev/null
+++ b/docs/move.md
@@ -0,0 +1,17 @@
+# move(src, dest, [options], callback)
+
+Moves a file or directory, even across devices.
+
+## Options:
+- overwrite (boolean): overwrite existing file or directory, default is `false`
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+
+fs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile', function (err) {
+ if (err) return console.error(err)
+ console.log("success!")
+})
+```
diff --git a/docs/outputFile.md b/docs/outputFile.md
new file mode 100644
index 0000000..16a96c6
--- /dev/null
+++ b/docs/outputFile.md
@@ -0,0 +1,21 @@
+# outputFile(file, data, [options], callback)
+
+Almost 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. `options` are what you'd pass to [`fs.writeFile()`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback).
+
+**Sync:** `outputFileSync()`
+
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+var file = '/tmp/this/path/does/not/exist/file.txt'
+
+fs.outputFile(file, 'hello!', function (err) {
+ console.log(err) // => null
+
+ fs.readFile(file, 'utf8', function (err, data) {
+ console.log(data) // => hello!
+ })
+})
+```
diff --git a/docs/outputJson.md b/docs/outputJson.md
new file mode 100644
index 0000000..4ef0727
--- /dev/null
+++ b/docs/outputJson.md
@@ -0,0 +1,24 @@
+# outputJson(file, data, [options], callback)
+
+Almost the same as [`writeJson`](writeJson.md), except that if the directory does not exist, it's created.
+`options` are what you'd pass to [`jsonFile.writeFile()`](https://github.com/jprichardson/node-jsonfile#writefilefilename-options-callback).
+
+**Alias:** `outputJSON()`
+
+**Sync:** `outputJsonSync()`, `outputJSONSync()`
+
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+var file = '/tmp/this/path/does/not/exist/file.txt'
+
+fs.outputJson(file, {name: 'JP'}, function (err) {
+ console.log(err) // => null
+
+ fs.readJson(file, function(err, data) {
+ console.log(data.name) // => JP
+ })
+})
+```
diff --git a/docs/readJson.md b/docs/readJson.md
new file mode 100644
index 0000000..8d5e28c
--- /dev/null
+++ b/docs/readJson.md
@@ -0,0 +1,33 @@
+# readJson(file, [options], callback)
+
+Reads a JSON file and then parses it into an object. `options` are the same
+that you'd pass to [`jsonFile.readFile`](https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback).
+
+**Alias:** `readJSON()`
+
+**Sync:** `readJsonSync()`, `readJSONSync()`
+
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+
+fs.readJson('./package.json', function (err, packageObj) {
+ console.log(packageObj.version) // => 0.1.3
+})
+```
+
+---
+
+`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
+```
diff --git a/docs/remove.md b/docs/remove.md
new file mode 100644
index 0000000..785e808
--- /dev/null
+++ b/docs/remove.md
@@ -0,0 +1,20 @@
+# remove(dir, callback)
+
+Removes a file or directory. The directory can have contents. Like `rm -rf`.
+
+**Sync:** `removeSync()`
+
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+
+fs.remove('/tmp/myfile', function (err) {
+ if (err) return console.error(err)
+
+ console.log('success!')
+})
+
+fs.removeSync('/home/jprichardson') //I just deleted my entire HOME directory.
+```
diff --git a/docs/writeJson.md b/docs/writeJson.md
new file mode 100644
index 0000000..04b9345
--- /dev/null
+++ b/docs/writeJson.md
@@ -0,0 +1,21 @@
+# writeJson(file, object, [options], callback)
+
+Writes an object to a JSON file. `options` are the same that
+you'd pass to [`jsonFile.writeFile()`](https://github.com/jprichardson/node-jsonfile#writefilefilename-options-callback).
+
+**Alias:** `writeJSON()`
+
+**Sync:** `writeJsonSync()`, `writeJSONSync()`
+
+## Example:
+
+```js
+var fs = require('fs-extra')
+fs.writeJson('./package.json', {name: 'fs-extra'}, function (err) {
+ console.log(err)
+})
+```
+
+---
+
+**See also:** [`outputJson()`](outputJson.md)
diff --git a/lib/copy-sync/__tests__/copy-sync-dir.test.js b/lib/copy-sync/__tests__/copy-sync-dir.test.js
index f29d49b..d457982 100644
--- a/lib/copy-sync/__tests__/copy-sync-dir.test.js
+++ b/lib/copy-sync/__tests__/copy-sync-dir.test.js
@@ -65,7 +65,8 @@ describe('+ copySync()', function () {
it('should should apply filter recursively', function () {
var FILES = 2
var filter = function (s) {
- return /0$/i.test(s)
+ // Don't match anything that ends with a digit higher than 0:
+ return /(0|\D)$/i.test(s)
}
fs.mkdirsSync(src)
@@ -105,6 +106,25 @@ describe('+ copySync()', function () {
}
})
+ it('should apply the filter to directory names', function () {
+ var IGNORE = 'ignore'
+ var filter = function (p) {
+ return !~p.indexOf(IGNORE)
+ }
+
+ fs.mkdirsSync(src)
+
+ var ignoreDir = path.join(src, IGNORE)
+ fs.mkdirsSync(ignoreDir)
+
+ fs.writeFileSync(path.join(ignoreDir, 'file'), crypto.randomBytes(SIZE))
+
+ fs.copySync(src, dest, filter)
+
+ assert(!fs.existsSync(path.join(dest, IGNORE)), 'directory was not ignored')
+ assert(!fs.existsSync(path.join(dest, IGNORE, 'file')), 'file was not ignored')
+ })
+
describe('> when the destination dir does not exist', function () {
it('should create the destination directory and copy the file', function () {
var src = path.join(TEST_DIR, 'data/')
diff --git a/lib/copy-sync/__tests__/copy-sync-file.test.js b/lib/copy-sync/__tests__/copy-sync-file.test.js
index 3442359..70e2e5c 100644
--- a/lib/copy-sync/__tests__/copy-sync-file.test.js
+++ b/lib/copy-sync/__tests__/copy-sync-file.test.js
@@ -104,7 +104,24 @@ describe('+ copySync()', function () {
})
})
- describe('> when clobber option is passed', function () {
+ describe('> when the source file does not have write permissions', function () {
+ it('should be able to copy contents of file', function () {
+ var fileSrc = path.join(TEST_DIR, 'file.txt')
+ var fileDest = path.join(TEST_DIR, 'file-copy.txt')
+ var data = 'did it copy?'
+
+ fs.writeFileSync(fileSrc, data, 'utf8')
+ fs.chmodSync(fileSrc, '0444')
+
+ fs.copySync(fileSrc, fileDest)
+
+ var data2 = fs.readFileSync(fileDest, 'utf8')
+
+ assert.strictEqual(data, data2)
+ })
+ })
+
+ describe('> when overwrite option is passed', function () {
var src, dest
var srcData = 'some src data'
@@ -117,17 +134,17 @@ describe('+ copySync()', function () {
})
describe('> when destination file does NOT exist', function () {
- describe('> when clobber is true', function () {
+ describe('> when overwrite is true', function () {
it('should copy the file and not throw an error', function () {
- fs.copySync(src, dest, {clobber: true})
+ fs.copySync(src, dest, {overwrite: true})
var destData = fs.readFileSync(dest, 'utf8')
assert.strictEqual(srcData, destData)
})
})
- describe('> when clobber is false', function () {
+ describe('> when overwrite is false', function () {
it('should copy the file and not throw an error', function () {
- fs.copySync(src, dest, {clobber: false})
+ fs.copySync(src, dest, {overwrite: false})
var destData = fs.readFileSync(dest, 'utf8')
assert.strictEqual(srcData, destData)
})
@@ -141,18 +158,25 @@ describe('+ copySync()', function () {
fs.writeFileSync(dest, destData)
})
- describe('> when clobber is true', function () {
+ describe('> when overwrite is true', function () {
it('should copy the file and not throw an error', function () {
- fs.copySync(src, dest, {clobber: true})
+ fs.copySync(src, dest, {overwrite: true})
destData = fs.readFileSync(dest, 'utf8')
assert.strictEqual(srcData, destData)
})
})
- describe('> when clobber is false', function () {
- it('should copy the file and THROW an error', function () {
+ describe('> when overwrite is false', function () {
+ it('should not throw an error', function () {
+ fs.copySync(src, dest, {overwrite: false})
+
+ // copy never happened
+ var destDataNew = fs.readFileSync(dest, 'utf8')
+ assert.strictEqual(destData, destDataNew)
+ })
+ it('should throw an error when errorOnExist is true', function () {
assert.throws(function () {
- fs.copySync(src, dest, {clobber: false})
+ fs.copySync(src, dest, {overwrite: false, errorOnExist: true})
})
// copy never happened
@@ -161,11 +185,11 @@ describe('+ copySync()', function () {
})
})
- describe('> when clobber is true and dest is readonly', function () {
+ describe('> when overwrite is true and dest is readonly', function () {
it('should copy the file and not throw an error', function () {
try {
fs.chmodSync(dest, parseInt('444', 8))
- fs.copySync(src, dest, {clobber: true})
+ fs.copySync(src, dest, {overwrite: true})
destData = fs.readFileSync(dest, 'utf8')
assert.strictEqual(srcData, destData)
} finally {
@@ -176,5 +200,25 @@ describe('+ copySync()', function () {
})
})
})
+ describe('clobber', function () {
+ var src, dest, srcData, destData
+
+ beforeEach(function () {
+ src = path.join(TEST_DIR, 'src-file')
+ dest = path.join(TEST_DIR, 'des-file')
+ srcData = 'some src data'
+ destData = 'some dest data'
+ fs.writeFileSync(src, srcData)
+ fs.writeFileSync(dest, destData)
+ })
+
+ it('is an alias for overwrite', function () {
+ fs.copySync(src, dest, {clobber: false})
+
+ // copy never happened
+ var destDataNew = fs.readFileSync(dest, 'utf8')
+ assert.strictEqual(destData, destDataNew)
+ })
+ })
})
})
diff --git a/lib/copy-sync/copy-file-sync.js b/lib/copy-sync/copy-file-sync.js
index 9cac892..fb9fad6 100644
--- a/lib/copy-sync/copy-file-sync.js
+++ b/lib/copy-sync/copy-file-sync.js
@@ -4,19 +4,16 @@ var BUF_LENGTH = 64 * 1024
var _buff = new Buffer(BUF_LENGTH)
function copyFileSync (srcFile, destFile, options) {
- var clobber = options.clobber
+ var overwrite = options.overwrite
+ var errorOnExist = options.errorOnExist
var preserveTimestamps = options.preserveTimestamps
if (fs.existsSync(destFile)) {
- if (clobber) {
+ if (overwrite) {
fs.unlinkSync(destFile)
- } else {
- var err = new Error('EEXIST: ' + destFile + ' already exists.')
- err.code = 'EEXIST'
- err.errno = -17
- err.path = destFile
- throw err
- }
+ } else if (errorOnExist) {
+ throw new Error(destFile + ' already exists')
+ } else return
}
var fdr = fs.openSync(srcFile, 'r')
diff --git a/lib/copy-sync/copy-sync.js b/lib/copy-sync/copy-sync.js
index 38c8c43..29812f8 100644
--- a/lib/copy-sync/copy-sync.js
+++ b/lib/copy-sync/copy-sync.js
@@ -13,6 +13,8 @@ function copySync (src, dest, options) {
// default to true for now
options.clobber = 'clobber' in options ? !!options.clobber : true
+ // overwrite falls back to clobber
+ options.overwrite = 'overwrite' in options ? !!options.overwrite : options.clobber
options.dereference = 'dereference' in options ? !!options.dereference : false
options.preserveTimestamps = 'preserveTimestamps' in options ? !!options.preserveTimestamps : false
@@ -29,17 +31,19 @@ function copySync (src, dest, options) {
var destFolderExists = fs.existsSync(destFolder)
var performCopy = false
- if (stats.isFile()) {
- if (options.filter instanceof RegExp) {
- console.warn('Warning: fs-extra: Passing a RegExp filter is deprecated, use a function')
- performCopy = options.filter.test(src)
- } else if (typeof options.filter === 'function') performCopy = options.filter(src)
-
- if (performCopy) {
- if (!destFolderExists) mkdir.mkdirsSync(destFolder)
- copyFileSync(src, dest, {clobber: options.clobber, preserveTimestamps: options.preserveTimestamps})
- }
- } else if (stats.isDirectory()) {
+ if (options.filter instanceof RegExp) {
+ console.warn('Warning: fs-extra: Passing a RegExp filter is deprecated, use a function')
+ performCopy = options.filter.test(src)
+ } else if (typeof options.filter === 'function') performCopy = options.filter(src)
+
+ if (stats.isFile() && performCopy) {
+ if (!destFolderExists) mkdir.mkdirsSync(destFolder)
+ copyFileSync(src, dest, {
+ overwrite: options.overwrite,
+ errorOnExist: options.errorOnExist,
+ preserveTimestamps: options.preserveTimestamps
+ })
+ } else if (stats.isDirectory() && performCopy) {
if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest)
var contents = fs.readdirSync(src)
contents.forEach(function (content) {
@@ -47,7 +51,7 @@ function copySync (src, dest, options) {
opts.recursive = true
copySync(path.join(src, content), path.join(dest, content), opts)
})
- } else if (options.recursive && stats.isSymbolicLink()) {
+ } else if (options.recursive && stats.isSymbolicLink() && performCopy) {
var srcPath = fs.readlinkSync(src)
fs.symlinkSync(srcPath, dest)
}
diff --git a/lib/copy/__tests__/ncp/ncp.test.js b/lib/copy/__tests__/ncp/ncp.test.js
index e091306..acb0f42 100644
--- a/lib/copy/__tests__/ncp/ncp.test.js
+++ b/lib/copy/__tests__/ncp/ncp.test.js
@@ -67,7 +67,7 @@ describe('ncp', function () {
})
})
- describe('when using clobber=true', function () {
+ describe('when using overwrite=true', function () {
before(function () {
this.originalCreateReadStream = fs.createReadStream
})
@@ -77,7 +77,7 @@ describe('ncp', function () {
})
it('the copy is complete after callback', function (done) {
- ncp(src, out, {clobber: true}, function (err) {
+ ncp(src, out, {overwrite: true}, function (err) {
fs.createReadStream = function () {
done(new Error('createReadStream after callback'))
}
@@ -87,19 +87,48 @@ describe('ncp', function () {
})
})
- describe('when using clobber=false', function () {
+ describe('when using overwrite=false', function () {
beforeEach(function (done) {
rimraf(out, done)
})
it('works', function (cb) {
- ncp(src, out, {clobber: false}, function (err) {
+ ncp(src, out, {overwrite: false}, function (err) {
assert.ifError(err)
cb()
})
})
- it('errors if files exist', function (cb) {
+ it('should not error if files exist', function (cb) {
ncp(src, out, function () {
- ncp(src, out, {clobber: false}, function (err) {
+ ncp(src, out, {overwrite: false}, function (err) {
+ assert.ifError(err)
+ cb()
+ })
+ })
+ })
+ it('should error if errorOnExist and file exists', function (cb) {
+ ncp(src, out, function () {
+ ncp(src, out, {
+ overwrite: false,
+ errorOnExist: true
+ }, function (err) {
+ assert(err)
+ cb()
+ })
+ })
+ })
+ })
+
+ describe('clobber', function () {
+ beforeEach(function (done) {
+ rimraf(out, done)
+ })
+
+ it('is an alias for overwrite', function (cb) {
+ ncp(src, out, function () {
+ ncp(src, out, {
+ clobber: false,
+ errorOnExist: true
+ }, function (err) {
assert(err)
cb()
})
diff --git a/lib/copy/ncp.js b/lib/copy/ncp.js
index a951004..7137e16 100644
--- a/lib/copy/ncp.js
+++ b/lib/copy/ncp.js
@@ -16,7 +16,11 @@ function ncp (source, dest, options, callback) {
var filter = options.filter
var transform = options.transform
- var clobber = options.clobber !== false // default true
+ var overwrite = options.overwrite
+ // If overwrite is undefined, use clobber, otherwise default to true:
+ if (overwrite === undefined) overwrite = options.clobber
+ if (overwrite === undefined) overwrite = true
+ var errorOnExist = options.errorOnExist
var dereference = options.dereference
var preserveTimestamps = options.preserveTimestamps === true
@@ -77,16 +81,14 @@ function ncp (source, dest, options, callback) {
if (writable) {
copyFile(file, target)
} else {
- if (clobber) {
+ if (overwrite) {
rmFile(target, function () {
copyFile(file, target)
})
+ } else if (errorOnExist) {
+ onError(new Error(target + ' already exists'))
} else {
- var err = new Error('EEXIST: ' + target + ' already exists.')
- err.code = 'EEXIST'
- err.errno = -17
- err.path = target
- onError(err)
+ doneOne()
}
}
})
@@ -107,7 +109,7 @@ function ncp (source, dest, options, callback) {
})
}
- writeStream.once('finish', function () {
+ writeStream.once('close', function () {
fs.chmod(target, file.mode, function (err) {
if (err) return onError(err)
if (preserveTimestamps) {
diff --git a/lib/index.js b/lib/index.js
index 7b874d5..977a75b 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -19,8 +19,6 @@ assign(fs, require('./move'))
assign(fs, require('./empty'))
assign(fs, require('./ensure'))
assign(fs, require('./output'))
-assign(fs, require('./walk'))
-assign(fs, require('./walk-sync'))
module.exports = fs
diff --git a/lib/move/__tests__/fixtures/a-file b/lib/move/__tests__/fixtures/a-file
deleted file mode 100644
index 94a709d..0000000
--- a/lib/move/__tests__/fixtures/a-file
+++ /dev/null
@@ -1 +0,0 @@
-sonic the hedgehog
diff --git a/lib/move/__tests__/fixtures/a-folder/another-file b/lib/move/__tests__/fixtures/a-folder/another-file
deleted file mode 100644
index 31340c7..0000000
--- a/lib/move/__tests__/fixtures/a-folder/another-file
+++ /dev/null
@@ -1 +0,0 @@
-tails
diff --git a/lib/move/__tests__/fixtures/a-folder/another-folder/file3 b/lib/move/__tests__/fixtures/a-folder/another-folder/file3
deleted file mode 100644
index 73a394d..0000000
--- a/lib/move/__tests__/fixtures/a-folder/another-folder/file3
+++ /dev/null
@@ -1 +0,0 @@
-knuckles
diff --git a/lib/move/__tests__/move-clobber.test.js b/lib/move/__tests__/move-clobber.test.js
deleted file mode 100644
index e89b770..0000000
--- a/lib/move/__tests__/move-clobber.test.js
+++ /dev/null
@@ -1,68 +0,0 @@
-var assert = require('assert')
-var fs = require('fs')
-var path = require('path')
-var os = require('os')
-var fse = require(process.cwd())
-
-/* global afterEach, beforeEach, describe, it */
-
-describe('move / clobber', function () {
- var TEST_DIR, FIXTURES_DIR
-
- beforeEach(function (done) {
- TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move')
- fse.emptyDir(TEST_DIR, function (err) {
- assert.ifError(err)
-
- FIXTURES_DIR = path.join(TEST_DIR, 'fixtures')
- fse.remove(FIXTURES_DIR, function (err) {
- assert.ifError(err)
- fse.copy(path.join(__dirname, './fixtures'), FIXTURES_DIR, done)
- })
- })
- })
-
- afterEach(function (done) {
- fse.remove(TEST_DIR, done)
- })
-
- describe('> when clobber = true', function () {
- describe('> when dest is a directory', function () {
- it('should clobber the destination', function (done) {
- // use fixtures dir as dest since it has stuff
- var dest = FIXTURES_DIR
- var paths = fs.readdirSync(dest)
-
- // verify dest has stuff
- assert(paths.indexOf('a-file') >= 0)
- assert(paths.indexOf('a-folder') >= 0)
-
- // create new source dir
- var src = path.join(TEST_DIR, 'src')
- fse.ensureDirSync(src)
- fse.mkdirsSync(path.join(src, 'some-folder'))
- fs.writeFileSync(path.join(src, 'some-file'), 'hi')
-
- // verify source has stuff
- paths = fs.readdirSync(src)
- assert(paths.indexOf('some-file') >= 0)
- assert(paths.indexOf('some-folder') >= 0)
-
- fse.move(src, dest, {clobber: true}, function (err) {
- if (err) return done(err)
-
- // verify dest does not have old stuff
- var paths = fs.readdirSync(dest)
- assert.strictEqual(paths.indexOf('a-file'), -1)
- assert.strictEqual(paths.indexOf('a-folder'), -1)
-
- // verify dest has new stuff
- assert(paths.indexOf('some-file') >= 0)
- assert(paths.indexOf('some-folder') >= 0)
-
- done()
- })
- })
- })
- })
-})
diff --git a/lib/move/__tests__/move.test.js b/lib/move/__tests__/move.test.js
index 67e137d..bdf199f 100644
--- a/lib/move/__tests__/move.test.js
+++ b/lib/move/__tests__/move.test.js
@@ -7,9 +7,6 @@ var fse = require(process.cwd())
/* global afterEach, beforeEach, describe, it */
-var FIXTURES_DIR = ''
-var SRC_FIXTURES_DIR = path.join(__dirname, './fixtures')
-
function createAsyncErrFn (errCode) {
var fn = function () {
fn.callCount++
@@ -45,8 +42,12 @@ describe('move', function () {
fse.emptyDirSync(TEST_DIR)
- FIXTURES_DIR = path.join(TEST_DIR, 'fixtures')
- fse.copySync(SRC_FIXTURES_DIR, FIXTURES_DIR)
+ // Create fixtures:
+ fs.writeFileSync(path.join(TEST_DIR, 'a-file'), 'sonic the hedgehog\n')
+ fs.mkdirSync(path.join(TEST_DIR, 'a-folder'))
+ fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-file'), 'tails\n')
+ fs.mkdirSync(path.join(TEST_DIR, 'a-folder/another-folder'))
+ fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-folder/file3'), 'knuckles\n')
})
afterEach(function (done) {
@@ -54,36 +55,103 @@ describe('move', function () {
})
it('should rename a file on the same device', function (done) {
- var src = FIXTURES_DIR + '/a-file'
- var dest = FIXTURES_DIR + '/a-file-dest'
+ var src = TEST_DIR + '/a-file'
+ var dest = TEST_DIR + '/a-file-dest'
fse.move(src, dest, function (err) {
assert.ifError(err)
fs.readFile(dest, 'utf8', function (err, contents) {
var expected = /^sonic the hedgehog\r?\n$/
assert.ifError(err)
- assert.ok(contents.match(expected), contents + ' match ' + expected)
+ assert.ok(contents.match(expected), `${contents} match ${expected}`)
done()
})
})
})
- it('should not overwrite if clobber = false', function (done) {
- var src = FIXTURES_DIR + '/a-file'
- var dest = FIXTURES_DIR + '/a-folder/another-file'
+ it('should not overwrite the destination by default', function (done) {
+ var src = TEST_DIR + '/a-file'
+ var dest = TEST_DIR + '/a-folder/another-file'
+
+ // verify file exists already
+ assert(fs.existsSync(dest))
+
+ fse.move(src, dest, function (err) {
+ assert.ok(err && err.code === 'EEXIST', 'throw EEXIST')
+ done()
+ })
+ })
+
+ it('should not overwrite if overwrite = false', function (done) {
+ var src = TEST_DIR + '/a-file'
+ var dest = TEST_DIR + '/a-folder/another-file'
// verify file exists already
assert(fs.existsSync(dest))
- fse.move(src, dest, {clobber: false}, function (err) {
+ fse.move(src, dest, {overwrite: false}, function (err) {
assert.ok(err && err.code === 'EEXIST', 'throw EEXIST')
done()
})
})
+ it('should overwrite file if overwrite = true', function (done) {
+ var src = TEST_DIR + '/a-file'
+ var dest = TEST_DIR + '/a-folder/another-file'
+
+ // verify file exists already
+ assert(fs.existsSync(dest))
+
+ fse.move(src, dest, {overwrite: true}, function (err) {
+ assert.ifError(err)
+ fs.readFile(dest, 'utf8', function (err, contents) {
+ var expected = /^sonic the hedgehog\r?\n$/
+ assert.ifError(err)
+ assert.ok(contents.match(expected), `${contents} match ${expected}`)
+ done()
+ })
+ })
+ })
+
+ it('should overwrite the destination directory if overwrite = true', function (done) {
+ // Tests fail on appveyor/Windows due to
+ // https://github.com/isaacs/node-graceful-fs/issues/98.
+ // Workaround by increasing the timeout by a minute (because
+ // graceful times out after a minute).
+ this.timeout(90000)
+
+ // Create src
+ var src = path.join(TEST_DIR, 'src')
+ fse.ensureDirSync(src)
+ fse.mkdirsSync(path.join(src, 'some-folder'))
+ fs.writeFileSync(path.join(src, 'some-file'), 'hi')
+
+ var dest = path.join(TEST_DIR, 'a-folder')
+
+ // verify dest has stuff in it
+ var paths = fs.readdirSync(dest)
+ assert(paths.indexOf('another-file') >= 0)
+ assert(paths.indexOf('another-folder') >= 0)
+
+ fse.move(src, dest, {overwrite: true}, function (err) {
+ assert.ifError(err)
+
+ // verify dest does not have old stuff
+ var paths = fs.readdirSync(dest)
+ assert.strictEqual(paths.indexOf('another-file'), -1)
+ assert.strictEqual(paths.indexOf('another-folder'), -1)
+
+ // verify dest has new stuff
+ assert(paths.indexOf('some-file') >= 0)
+ assert(paths.indexOf('some-folder') >= 0)
+
+ done()
+ })
+ })
+
it('should not create directory structure if mkdirp is false', function (done) {
- var src = FIXTURES_DIR + '/a-file'
- var dest = FIXTURES_DIR + '/does/not/exist/a-file-dest'
+ var src = TEST_DIR + '/a-file'
+ var dest = TEST_DIR + '/does/not/exist/a-file-dest'
// verify dest directory does not exist
assert(!fs.existsSync(path.dirname(dest)))
@@ -95,8 +163,8 @@ describe('move', function () {
})
it('should create directory structure by default', function (done) {
- var src = FIXTURES_DIR + '/a-file'
- var dest = FIXTURES_DIR + '/does/not/exist/a-file-dest'
+ var src = TEST_DIR + '/a-file'
+ var dest = TEST_DIR + '/does/not/exist/a-file-dest'
// verify dest directory does not exist
assert(!fs.existsSync(path.dirname(dest)))
@@ -106,15 +174,15 @@ describe('move', function () {
fs.readFile(dest, 'utf8', function (err, contents) {
var expected = /^sonic the hedgehog\r?\n$/
assert.ifError(err)
- assert.ok(contents.match(expected), contents + ' match ' + expected)
+ assert.ok(contents.match(expected), `${contents} match ${expected}`)
done()
})
})
})
it('should work across devices', function (done) {
- var src = FIXTURES_DIR + '/a-file'
- var dest = FIXTURES_DIR + '/a-file-dest'
+ var src = TEST_DIR + '/a-file'
+ var dest = TEST_DIR + '/a-file-dest'
setUpMockFs('EXDEV')
@@ -125,7 +193,7 @@ describe('move', function () {
fs.readFile(dest, 'utf8', function (err, contents) {
var expected = /^sonic the hedgehog\r?\n$/
assert.ifError(err)
- assert.ok(contents.match(expected), contents + ' match ' + expected)
+ assert.ok(contents.match(expected), `${contents} match ${expected}`)
tearDownMockFs()
done()
@@ -134,8 +202,8 @@ describe('move', function () {
})
it('should move folders', function (done) {
- var src = FIXTURES_DIR + '/a-folder'
- var dest = FIXTURES_DIR + '/a-folder-dest'
+ var src = TEST_DIR + '/a-folder'
+ var dest = TEST_DIR + '/a-folder-dest'
// verify it doesn't exist
assert(!fs.existsSync(dest))
@@ -145,15 +213,15 @@ describe('move', function () {
fs.readFile(dest + '/another-file', 'utf8', function (err, contents) {
var expected = /^tails\r?\n$/
assert.ifError(err)
- assert.ok(contents.match(expected), contents + ' match ' + expected)
+ assert.ok(contents.match(expected), `${contents} match ${expected}`)
done()
})
})
})
- it('should move folders across devices with EISDIR erro', function (done) {
- var src = FIXTURES_DIR + '/a-folder'
- var dest = FIXTURES_DIR + '/a-folder-dest'
+ it('should move folders across devices with EISDIR error', function (done) {
+ var src = TEST_DIR + '/a-folder'
+ var dest = TEST_DIR + '/a-folder-dest'
setUpMockFs('EISDIR')
@@ -164,7 +232,7 @@ describe('move', function () {
fs.readFile(dest + '/another-folder/file3', 'utf8', function (err, contents) {
var expected = /^knuckles\r?\n$/
assert.ifError(err)
- assert.ok(contents.match(expected), contents + ' match ' + expected)
+ assert.ok(contents.match(expected), `${contents} match ${expected}`)
tearDownMockFs('EISDIR')
@@ -173,22 +241,22 @@ describe('move', function () {
})
})
- it('should clobber folders across devices', function (done) {
- var src = FIXTURES_DIR + '/a-folder'
- var dest = FIXTURES_DIR + '/a-folder-dest'
+ it('should overwrite folders across devices', function (done) {
+ var src = TEST_DIR + '/a-folder'
+ var dest = TEST_DIR + '/a-folder-dest'
fs.mkdirSync(dest)
setUpMockFs('EXDEV')
- fse.move(src, dest, {clobber: true}, function (err) {
+ fse.move(src, dest, {overwrite: true}, function (err) {
assert.ifError(err)
assert.strictEqual(fs.rename.callCount, 1)
fs.readFile(dest + '/another-folder/file3', 'utf8', function (err, contents) {
var expected = /^knuckles\r?\n$/
assert.ifError(err)
- assert.ok(contents.match(expected), contents + ' match ' + expected)
+ assert.ok(contents.match(expected), `${contents} match ${expected}`)
tearDownMockFs('EXDEV')
@@ -198,8 +266,8 @@ describe('move', function () {
})
it('should move folders across devices with EXDEV error', function (done) {
- var src = FIXTURES_DIR + '/a-folder'
- var dest = FIXTURES_DIR + '/a-folder-dest'
+ var src = TEST_DIR + '/a-folder'
+ var dest = TEST_DIR + '/a-folder-dest'
setUpMockFs('EXDEV')
@@ -210,7 +278,7 @@ describe('move', function () {
fs.readFile(dest + '/another-folder/file3', 'utf8', function (err, contents) {
var expected = /^knuckles\r?\n$/
assert.ifError(err)
- assert.ok(contents.match(expected), contents + ' match ' + expected)
+ assert.ok(contents.match(expected), `${contents} match ${expected}`)
tearDownMockFs()
@@ -219,6 +287,26 @@ describe('move', function () {
})
})
+ describe('clobber', function () {
+ it('should be an alias for overwrite', function (done) {
+ var src = TEST_DIR + '/a-file'
+ var dest = TEST_DIR + '/a-folder/another-file'
+
+ // verify file exists already
+ assert(fs.existsSync(dest))
+
+ fse.move(src, dest, {overwrite: true}, function (err) {
+ assert.ifError(err)
+ fs.readFile(dest, 'utf8', function (err, contents) {
+ var expected = /^sonic the hedgehog\r?\n$/
+ assert.ifError(err)
+ assert.ok(contents.match(expected), `${contents} match ${expected}`)
+ done()
+ })
+ })
+ })
+ })
+
describe.skip('> when trying to a move a folder into itself', function () {
it('should produce an error', function (done) {
var SRC_DIR = path.join(TEST_DIR, 'test')
diff --git a/lib/move/index.js b/lib/move/index.js
index 1eb2a14..d5fcd70 100644
--- a/lib/move/index.js
+++ b/lib/move/index.js
@@ -17,9 +17,7 @@ function mv (source, dest, options, callback) {
}
var shouldMkdirp = ('mkdirp' in options) ? options.mkdirp : true
- var clobber = ('clobber' in options) ? options.clobber : false
-
- var limit = options.limit || 16
+ var overwrite = options.overwrite || options.clobber || false
if (shouldMkdirp) {
mkdirs()
@@ -35,14 +33,14 @@ function mv (source, dest, options, callback) {
}
function doRename () {
- if (clobber) {
+ if (overwrite) {
fs.rename(source, dest, function (err) {
if (!err) return callback()
if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST') {
remove(dest, function (err) {
if (err) return callback(err)
- options.clobber = false // just clobbered it, no need to do it again
+ options.overwrite = false // just overwriteed it, no need to do it again
mv(source, dest, options, callback)
})
return
@@ -53,7 +51,7 @@ function mv (source, dest, options, callback) {
setTimeout(function () {
remove(dest, function (err) {
if (err) return callback(err)
- options.clobber = false
+ options.overwrite = false
mv(source, dest, options, callback)
})
}, 200)
@@ -61,13 +59,13 @@ function mv (source, dest, options, callback) {
}
if (err.code !== 'EXDEV') return callback(err)
- moveAcrossDevice(source, dest, clobber, limit, callback)
+ moveAcrossDevice(source, dest, overwrite, callback)
})
} else {
fs.link(source, dest, function (err) {
if (err) {
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM') {
- moveAcrossDevice(source, dest, clobber, limit, callback)
+ moveAcrossDevice(source, dest, overwrite, callback)
return
}
callback(err)
@@ -79,7 +77,7 @@ function mv (source, dest, options, callback) {
}
}
-function moveAcrossDevice (source, dest, clobber, limit, callback) {
+function moveAcrossDevice (source, dest, overwrite, callback) {
fs.stat(source, function (err, stat) {
if (err) {
callback(err)
@@ -87,15 +85,15 @@ function moveAcrossDevice (source, dest, clobber, limit, callback) {
}
if (stat.isDirectory()) {
- moveDirAcrossDevice(source, dest, clobber, limit, callback)
+ moveDirAcrossDevice(source, dest, overwrite, callback)
} else {
- moveFileAcrossDevice(source, dest, clobber, limit, callback)
+ moveFileAcrossDevice(source, dest, overwrite, callback)
}
})
}
-function moveFileAcrossDevice (source, dest, clobber, limit, callback) {
- var outFlags = clobber ? 'w' : 'wx'
+function moveFileAcrossDevice (source, dest, overwrite, callback) {
+ var outFlags = overwrite ? 'w' : 'wx'
var ins = fs.createReadStream(source)
var outs = fs.createWriteStream(dest, {flags: outFlags})
@@ -110,7 +108,7 @@ function moveFileAcrossDevice (source, dest, clobber, limit, callback) {
fs.unlink(dest, function () {
// note: `err` here is from the input stream errror
if (err.code === 'EISDIR' || err.code === 'EPERM') {
- moveDirAcrossDevice(source, dest, clobber, limit, callback)
+ moveDirAcrossDevice(source, dest, overwrite, callback)
} else {
callback(err)
}
@@ -132,21 +130,19 @@ function moveFileAcrossDevice (source, dest, clobber, limit, callback) {
}
}
-function moveDirAcrossDevice (source, dest, clobber, limit, callback) {
+function moveDirAcrossDevice (source, dest, overwrite, callback) {
var options = {
- stopOnErr: true,
- clobber: false,
- limit: limit
+ overwrite: false
}
function startNcp () {
- ncp(source, dest, options, function (errList) {
- if (errList) return callback(errList[0])
+ ncp(source, dest, options, function (err) {
+ if (err) return callback(err)
remove(source, callback)
})
}
- if (clobber) {
+ if (overwrite) {
remove(dest, function (err) {
if (err) return callback(err)
startNcp()
diff --git a/lib/remove/__tests__/remove.test.js b/lib/remove/__tests__/remove.test.js
index dd56381..bf4d5de 100644
--- a/lib/remove/__tests__/remove.test.js
+++ b/lib/remove/__tests__/remove.test.js
@@ -80,5 +80,45 @@ describe('remove', function () {
}, 25)
fse.remove(file)
})
+
+ it('shouldn’t delete glob matches', function (done) {
+ var file = path.join(TEST_DIR, 'file?')
+ try {
+ fs.writeFileSync(file, 'hello')
+ } catch (ex) {
+ if (ex.code === 'ENOENT') {
+ return this.skip('Windows does not support filenames with ‘?’ or ‘*’ in them.')
+ }
+ throw ex
+ }
+
+ var wrongFile = path.join(TEST_DIR, 'file1')
+ fs.writeFileSync(wrongFile, 'yo')
+
+ assert(fs.existsSync(file))
+ assert(fs.existsSync(wrongFile))
+ fse.remove(file, function (err) {
+ assert.ifError(err)
+ assert(!fs.existsSync(file))
+ assert(fs.existsSync(wrongFile))
+ done()
+ })
+ })
+
+ it('shouldn’t delete glob matches when file doesn’t exist', function (done) {
+ var nonexistentFile = path.join(TEST_DIR, 'file?')
+
+ var wrongFile = path.join(TEST_DIR, 'file1')
+ fs.writeFileSync(wrongFile, 'yo')
+
+ assert(!fs.existsSync(nonexistentFile))
+ assert(fs.existsSync(wrongFile))
+ fse.remove(nonexistentFile, function (err) {
+ assert.ifError(err)
+ assert(!fs.existsSync(nonexistentFile))
+ assert(fs.existsSync(wrongFile))
+ done()
+ })
+ })
})
})
diff --git a/lib/walk-sync/__tests__/fixtures/dir1/file1_2 b/lib/walk-sync/__tests__/fixtures/dir1/file1_2
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/walk-sync/__tests__/fixtures/dir2/dir2_1/file2_1_1 b/lib/walk-sync/__tests__/fixtures/dir2/dir2_1/file2_1_1
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/walk-sync/__tests__/fixtures/file1 b/lib/walk-sync/__tests__/fixtures/file1
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/walk-sync/__tests__/walkSync.test.js b/lib/walk-sync/__tests__/walkSync.test.js
deleted file mode 100644
index ee3b867..0000000
--- a/lib/walk-sync/__tests__/walkSync.test.js
+++ /dev/null
@@ -1,41 +0,0 @@
-var assert = require('assert')
-var path = require('path')
-
-var fse = require('../../')
-
-/* global describe, it */
-var fixturesDir = path.join(__dirname, 'fixtures')
-
-describe('walk-sync', function () {
- it('should return an error if the source dir does not exist', function (done) {
- try {
- fse.walkSync('dirDoesNotExist/')
- } catch (err) {
- assert.equal(err.code, 'ENOENT')
- } finally {
- done()
- }
- })
-
- it('should return an error if the source is not a dir', function (done) {
- try {
- fse.walkSync(path.join(fixturesDir, 'dir1/file1_2'))
- } catch (err) {
- assert.equal(err.code, 'ENOTDIR')
- } finally {
- done()
- }
- })
-
- it('should return all files successfully for a dir', function (done) {
- var files = fse.walkSync(fixturesDir)
- var expectedFiles = ['dir1/file1_2', 'dir2/dir2_1/file2_1_1', 'file1']
- expectedFiles = expectedFiles.map(function (item) {
- return path.join(fixturesDir, item)
- })
- files.forEach(function (elem, i) {
- assert.equal(elem, expectedFiles[i])
- })
- done()
- })
-})
diff --git a/lib/walk-sync/index.js b/lib/walk-sync/index.js
deleted file mode 100644
index 0ebe56e..0000000
--- a/lib/walk-sync/index.js
+++ /dev/null
@@ -1,20 +0,0 @@
-var fs = require('graceful-fs')
-var path = require('path')
-
-var walkSync = function (dir, filelist) {
- var files = fs.readdirSync(dir)
- filelist = filelist || []
- files.forEach(function (file) {
- var nestedPath = path.join(dir, file)
- if (fs.lstatSync(nestedPath).isDirectory()) {
- filelist = walkSync(nestedPath, filelist)
- } else {
- filelist.push(nestedPath)
- }
- })
- return filelist
-}
-
-module.exports = {
- walkSync: walkSync
-}
diff --git a/lib/walk/__tests__/fixtures.json b/lib/walk/__tests__/fixtures.json
deleted file mode 100644
index 8f5df49..0000000
--- a/lib/walk/__tests__/fixtures.json
+++ /dev/null
@@ -1,7 +0,0 @@
-[
- "a/b/c/d.txt",
- "a/e.jpg",
- "h/i/j/k.txt",
- "h/i/l.txt",
- "h/i/m.jpg"
-]
diff --git a/lib/walk/__tests__/walk.test.js b/lib/walk/__tests__/walk.test.js
deleted file mode 100644
index 5840283..0000000
--- a/lib/walk/__tests__/walk.test.js
+++ /dev/null
@@ -1,73 +0,0 @@
-var assert = require('assert')
-var path = require('path')
-var os = require('os')
-var fse = require('../../')
-var fixtures = require('./fixtures')
-
-/* global afterEach, beforeEach, describe, it */
-// trinity: mocha
-
-describe('walk()', function () {
- var TEST_DIR
-
- beforeEach(function (done) {
- TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'walk')
- fse.emptyDir(TEST_DIR, function (err) {
- if (err) return done(err)
- fixtures.forEach(function (f) {
- f = path.join(TEST_DIR, f)
- fse.outputFileSync(f, path.basename(f, path.extname(f)))
- })
- done()
- })
- })
-
- afterEach(function (done) {
- fse.remove(TEST_DIR, done)
- })
-
- it('should work w/ streams 1', function (done) {
- var items = []
- fse.walk(TEST_DIR)
- .on('data', function (item) {
- assert.strictEqual(typeof item.stats, 'object') // verify that property is there
- items.push(item.path)
- })
- .on('end', function () {
- items.sort()
- var expected = ['a', 'a/b', 'a/b/c', 'a/b/c/d.txt', 'a/e.jpg', 'h', 'h/i', 'h/i/j',
- 'h/i/j/k.txt', 'h/i/l.txt', 'h/i/m.jpg']
- expected = expected.map(function (item) {
- return path.join(path.join(TEST_DIR, item))
- })
- expected.unshift(TEST_DIR)
-
- assert.deepEqual(items, expected)
- done()
- })
- })
-
- it('should work w/ streams 2/3', function (done) {
- var items = []
- fse.walk(TEST_DIR)
- .on('readable', function () {
- var item
- while ((item = this.read())) {
- assert.strictEqual(typeof item.stats, 'object') // verify that property is there
- items.push(item.path)
- }
- })
- .on('end', function () {
- items.sort()
- var expected = ['a', 'a/b', 'a/b/c', 'a/b/c/d.txt', 'a/e.jpg', 'h', 'h/i', 'h/i/j',
- 'h/i/j/k.txt', 'h/i/l.txt', 'h/i/m.jpg']
- expected = expected.map(function (item) {
- return path.join(path.join(TEST_DIR, item))
- })
- expected.unshift(TEST_DIR)
-
- assert.deepEqual(items, expected)
- done()
- })
- })
-})
diff --git a/lib/walk/index.js b/lib/walk/index.js
deleted file mode 100644
index 8626d47..0000000
--- a/lib/walk/index.js
+++ /dev/null
@@ -1,5 +0,0 @@
-var klaw = require('klaw')
-
-module.exports = {
- walk: klaw
-}
diff --git a/package.json b/package.json
index c7e0ac7..8295992 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "fs-extra",
- "version": "1.0.0",
+ "version": "2.0.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": {
@@ -34,12 +34,12 @@
"license": "MIT",
"dependencies": {
"graceful-fs": "^4.1.2",
- "jsonfile": "^2.1.0",
- "klaw": "^1.0.0"
+ "jsonfile": "^2.1.0"
},
"devDependencies": {
"coveralls": "^2.11.2",
"istanbul": "^0.4.5",
+ "klaw": "^1.0.0",
"minimist": "^1.1.1",
"mocha": "^3.1.2",
"proxyquire": "^1.7.10",
diff --git a/test.js b/test.js
index 70c70b1..1877731 100644
--- a/test.js
+++ b/test.js
@@ -2,7 +2,7 @@ var os = require('os')
var path = require('path')
var Mocha = require('mocha')
var assign = require('./lib/util/assign')
-var fs = require('./')
+var klaw = require('klaw')
var argv = require('minimist')(process.argv.slice(2))
@@ -14,7 +14,7 @@ var mochaOpts = assign({
var mocha = new Mocha(mochaOpts)
-fs.walk('./lib').on('readable', function () {
+klaw('./lib').on('readable', function () {
var item
while ((item = this.read())) {
if (!item.stats.isFile()) return
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-fs-extra.git
More information about the Pkg-javascript-commits
mailing list