fs-extra
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -1,12 +0,18 @@ | ||
Unreleased | ||
---------- | ||
2.1.0 / 2017-03-15 | ||
------------------ | ||
Thanks to [Mani Maghsoudlou (@manidlou)](https://github.com/manidlou) & [Jan Peer Stöcklmair (@JPeer264)](https://github.com/JPeer264) for their extraordinary help with this release! | ||
### Added | ||
- `moveSync()` See [#309], [#381](https://github.com/jprichardson/node-fs-extra/pull/381). ([@manidlou](https://github.com/manidlou)) | ||
- `copy()` and `copySync()`'s `filter` option now gets the destination path passed as the second parameter. [#366](https://github.com/jprichardson/node-fs-extra/pull/366) ([@manidlou](https://github.com/manidlou)) | ||
### Removed | ||
### Changed | ||
- Use `Buffer.alloc()` instead of deprecated `new Buffer()` in `copySync()`. [#380](https://github.com/jprichardson/node-fs-extra/pull/380) ([@manidlou](https://github.com/manidlou)) | ||
- Refactored entire codebase to use ES6 features supported by Node.js v4+ [#355](https://github.com/jprichardson/node-fs-extra/issues/355). [(@JPeer264)](https://github.com/JPeer264) | ||
- Refactored docs. ([@manidlou](https://github.com/manidlou)) | ||
### Fixed | ||
- `move()` shouldn't error out when source and dest are the same. [#377](https://github.com/jprichardson/node-fs-extra/issues/377), [#378](https://github.com/jprichardson/node-fs-extra/pull/378) ([@jdalton](https://github.com/jdalton)) | ||
@@ -13,0 +19,0 @@ 2.0.0 / 2017-01-16 |
@@ -5,25 +5,45 @@ # copy(src, dest, [options], callback) | ||
**Sync:** `copySync()` | ||
- `src` `<String>` | ||
- `dest` `<String>` | ||
- `options` `<Object>` | ||
- `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>`: 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). | ||
- `callback` `<Function>` | ||
## 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') | ||
const fs = require('fs-extra') | ||
fs.copy('/tmp/myfile', '/tmp/mynewfile', function (err) { | ||
fs.copy('/tmp/myfile', '/tmp/mynewfile', err => { | ||
if (err) return console.error(err) | ||
console.log("success!") | ||
console.log('success!') | ||
}) // copies file | ||
fs.copy('/tmp/mydir', '/tmp/mynewdir', function (err) { | ||
fs.copy('/tmp/mydir', '/tmp/mynewdir', err => { | ||
if (err) return console.error(err) | ||
console.log('success!') | ||
}) // copies directory, even if it has subdirectories or files | ||
``` | ||
**Using filter function** | ||
```js | ||
const fs = require('fs-extra') | ||
const filterFunc = (src, dest) => { | ||
// your logic here | ||
// it will be copied if return true | ||
} | ||
fs.copy('/tmp/mydir', '/tmp/mynewdir', { filter: filterFunc }, err => { | ||
if (err) return console.error(err) | ||
console.log('success!') | ||
}) | ||
``` |
@@ -7,3 +7,4 @@ # emptyDir(dir, [callback]) | ||
**Sync:** `emptyDirSync()`, `emptydirSync()` | ||
- `dir` `<String>` | ||
- `callback` `<Function>` | ||
@@ -13,8 +14,10 @@ ## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
const 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!') | ||
fs.emptyDir('/tmp/some/dir', err => { | ||
if (err) return console.error(err) | ||
console.log('success!') | ||
}) | ||
``` |
@@ -7,12 +7,12 @@ # ensureDir(dir, callback) | ||
**Sync:** `ensureDirSync()`, `mkdirsSync()`, `mkdirpSync()` | ||
- `dir` `<String>` | ||
- `callback` `<Function>` | ||
## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
const fs = require('fs-extra') | ||
var dir = '/tmp/this/path/does/not/exist' | ||
fs.ensureDir(dir, function (err) { | ||
const dir = '/tmp/this/path/does/not/exist' | ||
fs.ensureDir(dir, err => { | ||
console.log(err) // => null | ||
@@ -19,0 +19,0 @@ // dir has now been created, including the directory it is to be placed in |
@@ -7,12 +7,12 @@ # ensureFile(file, callback) | ||
**Sync:** `createFileSync()`,`ensureFileSync()` | ||
- `file` `<String>` | ||
- `callback` `<Function>` | ||
## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
const fs = require('fs-extra') | ||
var file = '/tmp/this/path/does/not/exist/file.txt' | ||
fs.ensureFile(file, function (err) { | ||
const file = '/tmp/this/path/does/not/exist/file.txt' | ||
fs.ensureFile(file, err => { | ||
console.log(err) // => null | ||
@@ -19,0 +19,0 @@ // file has now been created, including the directory it is to be placed in |
@@ -5,13 +5,14 @@ # ensureLink(srcpath, dstpath, callback) | ||
**Sync:** `ensureLinkSync()` | ||
- `srcpath` `<String>` | ||
- `dstpath` `<String>` | ||
- `callback` `<Function>` | ||
## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
const 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) { | ||
const srcpath = '/tmp/file.txt' | ||
const dstpath = '/tmp/this/path/does/not/exist/file.txt' | ||
fs.ensureLink(srcpath, dstpath, err => { | ||
console.log(err) // => null | ||
@@ -18,0 +19,0 @@ // link has now been created, including the directory it is to be placed in |
@@ -5,13 +5,15 @@ # ensureSymlink(srcpath, dstpath, [type], callback) | ||
**Sync:** `ensureSymlinkSync()` | ||
- `srcpath` `<String>` | ||
- `dstpath` `<String>` | ||
- `type` `<String>` | ||
- `callback` `<Function>` | ||
## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
const 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) { | ||
const srcpath = '/tmp/file.txt' | ||
const dstpath = '/tmp/this/path/does/not/exist/file.txt' | ||
fs.ensureSymlink(srcpath, dstpath, err => { | ||
console.log(err) // => null | ||
@@ -18,0 +20,0 @@ // symlink has now been created, including the directory it is to be placed in |
@@ -5,4 +5,7 @@ # move(src, dest, [options], callback) | ||
## Options: | ||
- overwrite (boolean): overwrite existing file or directory, default is `false` | ||
- `src` `<String>` | ||
- `dest` `<String>` | ||
- `options` `<Object>` | ||
- `overwrite` `<boolean>`: overwrite existing file or directory, default is `false`. | ||
- `callback` `<Function>` | ||
@@ -12,8 +15,21 @@ ## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
const fs = require('fs-extra') | ||
fs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile', function (err) { | ||
fs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile', err => { | ||
if (err) return console.error(err) | ||
console.log("success!") | ||
console.log('success!') | ||
}) | ||
``` | ||
**Using `overwrite` option** | ||
```js | ||
const fs = require('fs-extra') | ||
fs.move('/tmp/somedir', '/tmp/may/already/existed/somedir', { overwrite: true }, 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). | ||
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. `file` must be a file path (a buffer or a file descriptor is not allowed). `options` are what you'd pass to [`fs.writeFile()`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback). | ||
**Sync:** `outputFileSync()` | ||
- `file` `<String>` | ||
- `data` `<String> | <Buffer> | <Uint8Array>` | ||
- `options` `<Object> | <String>` | ||
- `callback` `<Function>` | ||
## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
var file = '/tmp/this/path/does/not/exist/file.txt' | ||
const fs = require('fs-extra') | ||
fs.outputFile(file, 'hello!', function (err) { | ||
const file = '/tmp/this/path/does/not/exist/file.txt' | ||
fs.outputFile(file, 'hello!', err => { | ||
console.log(err) // => null | ||
fs.readFile(file, 'utf8', function (err, data) { | ||
fs.readFile(file, 'utf8', (err, data) => { | ||
console.log(data) // => hello! | ||
@@ -19,0 +21,0 @@ }) |
@@ -1,2 +0,2 @@ | ||
# outputJson(file, data, [options], callback) | ||
# outputJson(file, object, [options], callback) | ||
@@ -8,15 +8,17 @@ Almost the same as [`writeJson`](writeJson.md), except that if the directory does not exist, it's created. | ||
**Sync:** `outputJsonSync()`, `outputJSONSync()` | ||
- `file` `<String>` | ||
- `object` `<Object>` | ||
- `options` `<Object>` | ||
- `callback` `<Function>` | ||
## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
var file = '/tmp/this/path/does/not/exist/file.txt' | ||
const fs = require('fs-extra') | ||
fs.outputJson(file, {name: 'JP'}, function (err) { | ||
const file = '/tmp/this/path/does/not/exist/file.json' | ||
fs.outputJson(file, {name: 'JP'}, err => { | ||
console.log(err) // => null | ||
fs.readJson(file, function(err, data) { | ||
fs.readJson(file, (err, data) => { | ||
console.log(data.name) // => JP | ||
@@ -23,0 +25,0 @@ }) |
@@ -8,11 +8,14 @@ # readJson(file, [options], callback) | ||
**Sync:** `readJsonSync()`, `readJSONSync()` | ||
- `file` `<String>` | ||
- `options` `<Object>` | ||
- `callback` `<Function>` | ||
## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
const fs = require('fs-extra') | ||
fs.readJson('./package.json', function (err, packageObj) { | ||
fs.readJson('./package.json', (err, packageObj) => { | ||
if (err) console.error(err) | ||
console.log(packageObj.version) // => 0.1.3 | ||
@@ -24,12 +27,16 @@ }) | ||
`readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example: | ||
`readJson()` 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' | ||
const fs = require('fs-extra') | ||
const file = '/tmp/some-invalid.json' | ||
const data = '{not valid JSON' | ||
fs.writeFileSync(file, data) | ||
var obj = fs.readJsonSync(file, {throws: false}) | ||
console.log(obj) // => null | ||
fs.readJson(file, { throws: false }, (err, obj) => { | ||
if (err) console.error(err) | ||
console.log(obj) // => null | ||
}) | ||
``` |
@@ -1,14 +0,15 @@ | ||
# remove(dir, callback) | ||
# remove(path, callback) | ||
Removes a file or directory. The directory can have contents. Like `rm -rf`. | ||
**Sync:** `removeSync()` | ||
- `path` `<String>` | ||
- `callback` `<Function>` | ||
## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
const fs = require('fs-extra') | ||
fs.remove('/tmp/myfile', function (err) { | ||
// remove file | ||
fs.remove('/tmp/myfile', err => { | ||
if (err) return console.error(err) | ||
@@ -19,3 +20,7 @@ | ||
fs.removeSync('/home/jprichardson') //I just deleted my entire HOME directory. | ||
fs.remove('/home/jprichardson', err => { | ||
if (err) return console.error(err) | ||
console.log('success!') // I just deleted my entire HOME directory. | ||
}) | ||
``` |
@@ -8,3 +8,6 @@ # writeJson(file, object, [options], callback) | ||
**Sync:** `writeJsonSync()`, `writeJSONSync()` | ||
- `file` `<String>` | ||
- `object` `<Object>` | ||
- `options` `<Object>` | ||
- `callback` `<Function>` | ||
@@ -14,5 +17,8 @@ ## Example: | ||
```js | ||
var fs = require('fs-extra') | ||
fs.writeJson('./package.json', {name: 'fs-extra'}, function (err) { | ||
console.log(err) | ||
const fs = require('fs-extra') | ||
fs.writeJson('./package.json', {name: 'fs-extra'}, err => { | ||
if (err) return console.error(err) | ||
console.log('success!') | ||
}) | ||
@@ -19,0 +25,0 @@ ``` |
@@ -1,10 +0,12 @@ | ||
var fs = require('graceful-fs') | ||
'use strict' | ||
var BUF_LENGTH = 64 * 1024 | ||
var _buff = new Buffer(BUF_LENGTH) | ||
const fs = require('graceful-fs') | ||
const BUF_LENGTH = 64 * 1024 | ||
const _buff = Buffer.alloc(BUF_LENGTH) | ||
function copyFileSync (srcFile, destFile, options) { | ||
var overwrite = options.overwrite | ||
var errorOnExist = options.errorOnExist | ||
var preserveTimestamps = options.preserveTimestamps | ||
const overwrite = options.overwrite | ||
const errorOnExist = options.errorOnExist | ||
const preserveTimestamps = options.preserveTimestamps | ||
@@ -15,11 +17,11 @@ if (fs.existsSync(destFile)) { | ||
} else if (errorOnExist) { | ||
throw new Error(destFile + ' already exists') | ||
throw new Error(`${destFile} already exists`) | ||
} else return | ||
} | ||
var fdr = fs.openSync(srcFile, 'r') | ||
var stat = fs.fstatSync(fdr) | ||
var fdw = fs.openSync(destFile, 'w', stat.mode) | ||
var bytesRead = 1 | ||
var pos = 0 | ||
const fdr = fs.openSync(srcFile, 'r') | ||
const stat = fs.fstatSync(fdr) | ||
const fdw = fs.openSync(destFile, 'w', stat.mode) | ||
let bytesRead = 1 | ||
let pos = 0 | ||
@@ -26,0 +28,0 @@ while (bytesRead > 0) { |
@@ -1,6 +0,8 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
var copyFileSync = require('./copy-file-sync') | ||
var mkdir = require('../mkdirs') | ||
'use strict' | ||
const fs = require('graceful-fs') | ||
const path = require('path') | ||
const copyFileSync = require('./copy-file-sync') | ||
const mkdir = require('../mkdirs') | ||
function copySync (src, dest, options) { | ||
@@ -25,10 +27,10 @@ if (typeof options === 'function' || options instanceof RegExp) { | ||
if (options.preserveTimestamps && process.arch === 'ia32') { | ||
console.warn('fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n' + | ||
'see https://github.com/jprichardson/node-fs-extra/issues/269') | ||
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n | ||
see https://github.com/jprichardson/node-fs-extra/issues/269`) | ||
} | ||
var stats = (options.recursive && !options.dereference) ? fs.lstatSync(src) : fs.statSync(src) | ||
var destFolder = path.dirname(dest) | ||
var destFolderExists = fs.existsSync(destFolder) | ||
var performCopy = false | ||
const stats = (options.recursive && !options.dereference) ? fs.lstatSync(src) : fs.statSync(src) | ||
const destFolder = path.dirname(dest) | ||
const destFolderExists = fs.existsSync(destFolder) | ||
let performCopy = false | ||
@@ -38,3 +40,3 @@ if (options.filter instanceof RegExp) { | ||
performCopy = options.filter.test(src) | ||
} else if (typeof options.filter === 'function') performCopy = options.filter(src) | ||
} else if (typeof options.filter === 'function') performCopy = options.filter(src, dest) | ||
@@ -50,5 +52,5 @@ if (stats.isFile() && performCopy) { | ||
if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest) | ||
var contents = fs.readdirSync(src) | ||
contents.forEach(function (content) { | ||
var opts = options | ||
const contents = fs.readdirSync(src) | ||
contents.forEach(content => { | ||
const opts = options | ||
opts.recursive = true | ||
@@ -58,3 +60,3 @@ copySync(path.join(src, content), path.join(dest, content), opts) | ||
} else if (options.recursive && stats.isSymbolicLink() && performCopy) { | ||
var srcPath = fs.readlinkSync(src) | ||
const srcPath = fs.readlinkSync(src) | ||
fs.symlinkSync(srcPath, dest) | ||
@@ -61,0 +63,0 @@ } |
@@ -1,6 +0,8 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
var ncp = require('./ncp') | ||
var mkdir = require('../mkdirs') | ||
'use strict' | ||
const fs = require('graceful-fs') | ||
const path = require('path') | ||
const ncp = require('./ncp') | ||
const mkdir = require('../mkdirs') | ||
function copy (src, dest, options, callback) { | ||
@@ -18,18 +20,18 @@ if (typeof options === 'function' && !callback) { | ||
if (options.preserveTimestamps && process.arch === 'ia32') { | ||
console.warn('fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n' + | ||
'see https://github.com/jprichardson/node-fs-extra/issues/269') | ||
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n | ||
see https://github.com/jprichardson/node-fs-extra/issues/269`) | ||
} | ||
// don't allow src and dest to be the same | ||
var basePath = process.cwd() | ||
var currentPath = path.resolve(basePath, src) | ||
var targetPath = path.resolve(basePath, dest) | ||
const basePath = process.cwd() | ||
const currentPath = path.resolve(basePath, src) | ||
const targetPath = path.resolve(basePath, dest) | ||
if (currentPath === targetPath) return callback(new Error('Source and destination must not be the same.')) | ||
fs.lstat(src, function (err, stats) { | ||
fs.lstat(src, (err, stats) => { | ||
if (err) return callback(err) | ||
var dir = null | ||
let dir = null | ||
if (stats.isDirectory()) { | ||
var parts = dest.split(path.sep) | ||
const parts = dest.split(path.sep) | ||
parts.pop() | ||
@@ -41,5 +43,5 @@ dir = parts.join(path.sep) | ||
fs.exists(dir, function (dirExists) { | ||
fs.exists(dir, dirExists => { | ||
if (dirExists) return ncp(src, dest, options, callback) | ||
mkdir.mkdirs(dir, function (err) { | ||
mkdir.mkdirs(dir, err => { | ||
if (err) return callback(err) | ||
@@ -46,0 +48,0 @@ ncp(src, dest, options, callback) |
@@ -44,3 +44,3 @@ // imported from ncp (this is temporary, will rewrite) | ||
} else if (typeof filter === 'function') { | ||
if (!filter(source)) { | ||
if (!filter(source, dest)) { | ||
return doneOne(true) | ||
@@ -47,0 +47,0 @@ } |
@@ -1,14 +0,14 @@ | ||
var fs = require('fs') | ||
var path = require('path') | ||
var mkdir = require('../mkdirs') | ||
var remove = require('../remove') | ||
'use strict' | ||
const fs = require('fs') | ||
const path = require('path') | ||
const mkdir = require('../mkdirs') | ||
const remove = require('../remove') | ||
function emptyDir (dir, callback) { | ||
callback = callback || function () {} | ||
fs.readdir(dir, function (err, items) { | ||
fs.readdir(dir, (err, items) => { | ||
if (err) return mkdir.mkdirs(dir, callback) | ||
items = items.map(function (item) { | ||
return path.join(dir, item) | ||
}) | ||
items = items.map(item => path.join(dir, item)) | ||
@@ -18,5 +18,5 @@ deleteItem() | ||
function deleteItem () { | ||
var item = items.pop() | ||
const item = items.pop() | ||
if (!item) return callback() | ||
remove.remove(item, function (err) { | ||
remove.remove(item, err => { | ||
if (err) return callback(err) | ||
@@ -30,3 +30,3 @@ deleteItem() | ||
function emptyDirSync (dir) { | ||
var items | ||
let items | ||
try { | ||
@@ -38,3 +38,3 @@ items = fs.readdirSync(dir) | ||
items.forEach(function (item) { | ||
items.forEach(item => { | ||
item = path.join(dir, item) | ||
@@ -46,6 +46,6 @@ remove.removeSync(item) | ||
module.exports = { | ||
emptyDirSync: emptyDirSync, | ||
emptyDirSync, | ||
emptydirSync: emptyDirSync, | ||
emptyDir: emptyDir, | ||
emptyDir, | ||
emptydir: emptyDir | ||
} |
@@ -1,8 +0,10 @@ | ||
var path = require('path') | ||
var fs = require('graceful-fs') | ||
var mkdir = require('../mkdirs') | ||
'use strict' | ||
const path = require('path') | ||
const fs = require('graceful-fs') | ||
const mkdir = require('../mkdirs') | ||
function createFile (file, callback) { | ||
function makeFile () { | ||
fs.writeFile(file, '', function (err) { | ||
fs.writeFile(file, '', err => { | ||
if (err) return callback(err) | ||
@@ -13,8 +15,8 @@ callback() | ||
fs.exists(file, function (fileExists) { | ||
fs.exists(file, fileExists => { | ||
if (fileExists) return callback() | ||
var dir = path.dirname(file) | ||
fs.exists(dir, function (dirExists) { | ||
const dir = path.dirname(file) | ||
fs.exists(dir, dirExists => { | ||
if (dirExists) return makeFile() | ||
mkdir.mkdirs(dir, function (err) { | ||
mkdir.mkdirs(dir, err => { | ||
if (err) return callback(err) | ||
@@ -30,3 +32,3 @@ makeFile() | ||
var dir = path.dirname(file) | ||
const dir = path.dirname(file) | ||
if (!fs.existsSync(dir)) { | ||
@@ -40,4 +42,4 @@ mkdir.mkdirsSync(dir) | ||
module.exports = { | ||
createFile: createFile, | ||
createFileSync: createFileSync, | ||
createFile, | ||
createFileSync, | ||
// alias | ||
@@ -44,0 +46,0 @@ ensureFile: createFile, |
@@ -1,5 +0,7 @@ | ||
var file = require('./file') | ||
var link = require('./link') | ||
var symlink = require('./symlink') | ||
'use strict' | ||
const file = require('./file') | ||
const link = require('./link') | ||
const symlink = require('./symlink') | ||
module.exports = { | ||
@@ -6,0 +8,0 @@ // file |
@@ -1,8 +0,10 @@ | ||
var path = require('path') | ||
var fs = require('graceful-fs') | ||
var mkdir = require('../mkdirs') | ||
'use strict' | ||
const path = require('path') | ||
const fs = require('graceful-fs') | ||
const mkdir = require('../mkdirs') | ||
function createLink (srcpath, dstpath, callback) { | ||
function makeLink (srcpath, dstpath) { | ||
fs.link(srcpath, dstpath, function (err) { | ||
fs.link(srcpath, dstpath, err => { | ||
if (err) return callback(err) | ||
@@ -13,5 +15,5 @@ callback(null) | ||
fs.exists(dstpath, function (destinationExists) { | ||
fs.exists(dstpath, destinationExists => { | ||
if (destinationExists) return callback(null) | ||
fs.lstat(srcpath, function (err, stat) { | ||
fs.lstat(srcpath, (err, stat) => { | ||
if (err) { | ||
@@ -22,6 +24,6 @@ err.message = err.message.replace('lstat', 'ensureLink') | ||
var dir = path.dirname(dstpath) | ||
fs.exists(dir, function (dirExists) { | ||
const dir = path.dirname(dstpath) | ||
fs.exists(dir, dirExists => { | ||
if (dirExists) return makeLink(srcpath, dstpath) | ||
mkdir.mkdirs(dir, function (err) { | ||
mkdir.mkdirs(dir, err => { | ||
if (err) return callback(err) | ||
@@ -36,3 +38,3 @@ makeLink(srcpath, dstpath) | ||
function createLinkSync (srcpath, dstpath, callback) { | ||
var destinationExists = fs.existsSync(dstpath) | ||
const destinationExists = fs.existsSync(dstpath) | ||
if (destinationExists) return undefined | ||
@@ -47,4 +49,4 @@ | ||
var dir = path.dirname(dstpath) | ||
var dirExists = fs.existsSync(dir) | ||
const dir = path.dirname(dstpath) | ||
const dirExists = fs.existsSync(dir) | ||
if (dirExists) return fs.linkSync(srcpath, dstpath) | ||
@@ -57,4 +59,4 @@ mkdir.mkdirsSync(dir) | ||
module.exports = { | ||
createLink: createLink, | ||
createLinkSync: createLinkSync, | ||
createLink, | ||
createLinkSync, | ||
// alias | ||
@@ -61,0 +63,0 @@ ensureLink: createLink, |
@@ -1,5 +0,6 @@ | ||
var path = require('path') | ||
// path.isAbsolute shim for Node.js 0.10 support | ||
var fs = require('graceful-fs') | ||
'use strict' | ||
const path = require('path') | ||
const fs = require('graceful-fs') | ||
/** | ||
@@ -29,3 +30,3 @@ * Function that returns two types of paths, one relative to symlink, and one | ||
if (path.isAbsolute(srcpath)) { | ||
return fs.lstat(srcpath, function (err, stat) { | ||
return fs.lstat(srcpath, (err, stat) => { | ||
if (err) { | ||
@@ -41,5 +42,5 @@ err.message = err.message.replace('lstat', 'ensureSymlink') | ||
} else { | ||
var dstdir = path.dirname(dstpath) | ||
var relativeToDst = path.join(dstdir, srcpath) | ||
return fs.exists(relativeToDst, function (exists) { | ||
const dstdir = path.dirname(dstpath) | ||
const relativeToDst = path.join(dstdir, srcpath) | ||
return fs.exists(relativeToDst, exists => { | ||
if (exists) { | ||
@@ -51,3 +52,3 @@ return callback(null, { | ||
} else { | ||
return fs.lstat(srcpath, function (err, stat) { | ||
return fs.lstat(srcpath, (err, stat) => { | ||
if (err) { | ||
@@ -68,3 +69,3 @@ err.message = err.message.replace('lstat', 'ensureSymlink') | ||
function symlinkPathsSync (srcpath, dstpath) { | ||
var exists | ||
let exists | ||
if (path.isAbsolute(srcpath)) { | ||
@@ -78,4 +79,4 @@ exists = fs.existsSync(srcpath) | ||
} else { | ||
var dstdir = path.dirname(dstpath) | ||
var relativeToDst = path.join(dstdir, srcpath) | ||
const dstdir = path.dirname(dstpath) | ||
const relativeToDst = path.join(dstdir, srcpath) | ||
exists = fs.existsSync(relativeToDst) | ||
@@ -99,4 +100,4 @@ if (exists) { | ||
module.exports = { | ||
'symlinkPaths': symlinkPaths, | ||
'symlinkPathsSync': symlinkPathsSync | ||
symlinkPaths, | ||
symlinkPathsSync | ||
} |
@@ -1,3 +0,5 @@ | ||
var fs = require('graceful-fs') | ||
'use strict' | ||
const fs = require('graceful-fs') | ||
function symlinkType (srcpath, type, callback) { | ||
@@ -7,3 +9,3 @@ callback = (typeof type === 'function') ? type : callback | ||
if (type) return callback(null, type) | ||
fs.lstat(srcpath, function (err, stats) { | ||
fs.lstat(srcpath, (err, stats) => { | ||
if (err) return callback(null, 'file') | ||
@@ -16,5 +18,7 @@ type = (stats && stats.isDirectory()) ? 'dir' : 'file' | ||
function symlinkTypeSync (srcpath, type) { | ||
let stats | ||
if (type) return type | ||
try { | ||
var stats = fs.lstatSync(srcpath) | ||
stats = fs.lstatSync(srcpath) | ||
} catch (e) { | ||
@@ -27,4 +31,4 @@ return 'file' | ||
module.exports = { | ||
symlinkType: symlinkType, | ||
symlinkTypeSync: symlinkTypeSync | ||
symlinkType, | ||
symlinkTypeSync | ||
} |
@@ -1,15 +0,17 @@ | ||
var path = require('path') | ||
var fs = require('graceful-fs') | ||
var _mkdirs = require('../mkdirs') | ||
var mkdirs = _mkdirs.mkdirs | ||
var mkdirsSync = _mkdirs.mkdirsSync | ||
'use strict' | ||
var _symlinkPaths = require('./symlink-paths') | ||
var symlinkPaths = _symlinkPaths.symlinkPaths | ||
var symlinkPathsSync = _symlinkPaths.symlinkPathsSync | ||
const path = require('path') | ||
const fs = require('graceful-fs') | ||
const _mkdirs = require('../mkdirs') | ||
const mkdirs = _mkdirs.mkdirs | ||
const mkdirsSync = _mkdirs.mkdirsSync | ||
var _symlinkType = require('./symlink-type') | ||
var symlinkType = _symlinkType.symlinkType | ||
var symlinkTypeSync = _symlinkType.symlinkTypeSync | ||
const _symlinkPaths = require('./symlink-paths') | ||
const symlinkPaths = _symlinkPaths.symlinkPaths | ||
const symlinkPathsSync = _symlinkPaths.symlinkPathsSync | ||
const _symlinkType = require('./symlink-type') | ||
const symlinkType = _symlinkType.symlinkType | ||
const symlinkTypeSync = _symlinkType.symlinkTypeSync | ||
function createSymlink (srcpath, dstpath, type, callback) { | ||
@@ -19,13 +21,13 @@ callback = (typeof type === 'function') ? type : callback | ||
fs.exists(dstpath, function (destinationExists) { | ||
fs.exists(dstpath, destinationExists => { | ||
if (destinationExists) return callback(null) | ||
symlinkPaths(srcpath, dstpath, function (err, relative) { | ||
symlinkPaths(srcpath, dstpath, (err, relative) => { | ||
if (err) return callback(err) | ||
srcpath = relative.toDst | ||
symlinkType(relative.toCwd, type, function (err, type) { | ||
symlinkType(relative.toCwd, type, (err, type) => { | ||
if (err) return callback(err) | ||
var dir = path.dirname(dstpath) | ||
fs.exists(dir, function (dirExists) { | ||
const dir = path.dirname(dstpath) | ||
fs.exists(dir, dirExists => { | ||
if (dirExists) return fs.symlink(srcpath, dstpath, type, callback) | ||
mkdirs(dir, function (err) { | ||
mkdirs(dir, err => { | ||
if (err) return callback(err) | ||
@@ -44,10 +46,10 @@ fs.symlink(srcpath, dstpath, type, callback) | ||
var destinationExists = fs.existsSync(dstpath) | ||
const destinationExists = fs.existsSync(dstpath) | ||
if (destinationExists) return undefined | ||
var relative = symlinkPathsSync(srcpath, dstpath) | ||
const relative = symlinkPathsSync(srcpath, dstpath) | ||
srcpath = relative.toDst | ||
type = symlinkTypeSync(relative.toCwd, type) | ||
var dir = path.dirname(dstpath) | ||
var exists = fs.existsSync(dir) | ||
const dir = path.dirname(dstpath) | ||
const exists = fs.existsSync(dir) | ||
if (exists) return fs.symlinkSync(srcpath, dstpath, type) | ||
@@ -59,4 +61,4 @@ mkdirsSync(dir) | ||
module.exports = { | ||
createSymlink: createSymlink, | ||
createSymlinkSync: createSymlinkSync, | ||
createSymlink, | ||
createSymlinkSync, | ||
// alias | ||
@@ -63,0 +65,0 @@ ensureSymlink: createSymlink, |
@@ -1,12 +0,14 @@ | ||
var assign = require('./util/assign') | ||
'use strict' | ||
var fse = {} | ||
var gfs = require('graceful-fs') | ||
const assign = require('./util/assign') | ||
const fse = {} | ||
const gfs = require('graceful-fs') | ||
// attach fs methods to fse | ||
Object.keys(gfs).forEach(function (key) { | ||
Object.keys(gfs).forEach(key => { | ||
fse[key] = gfs[key] | ||
}) | ||
var fs = fse | ||
const fs = fse | ||
@@ -19,2 +21,3 @@ assign(fs, require('./copy')) | ||
assign(fs, require('./move')) | ||
assign(fs, require('./move-sync')) | ||
assign(fs, require('./empty')) | ||
@@ -27,8 +30,6 @@ assign(fs, require('./ensure')) | ||
// maintain backwards compatibility for awhile | ||
var jsonfile = {} | ||
const jsonfile = {} | ||
Object.defineProperty(jsonfile, 'spaces', { | ||
get: function () { | ||
return fs.spaces // found in ./json | ||
}, | ||
set: function (val) { | ||
get: () => fs.spaces, // found in ./json | ||
set: val => { | ||
fs.spaces = val | ||
@@ -35,0 +36,0 @@ } |
@@ -1,3 +0,5 @@ | ||
var jsonFile = require('./jsonfile') | ||
'use strict' | ||
const jsonFile = require('./jsonfile') | ||
jsonFile.outputJsonSync = require('./output-json-sync') | ||
@@ -4,0 +6,0 @@ jsonFile.outputJson = require('./output-json') |
@@ -1,3 +0,5 @@ | ||
var jsonFile = require('jsonfile') | ||
'use strict' | ||
const jsonFile = require('jsonfile') | ||
module.exports = { | ||
@@ -4,0 +6,0 @@ // jsonfile exports |
@@ -1,8 +0,10 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
var jsonFile = require('./jsonfile') | ||
var mkdir = require('../mkdirs') | ||
'use strict' | ||
const fs = require('graceful-fs') | ||
const path = require('path') | ||
const mkdir = require('../mkdirs') | ||
const jsonFile = require('./jsonfile') | ||
function outputJsonSync (file, data, options) { | ||
var dir = path.dirname(file) | ||
const dir = path.dirname(file) | ||
@@ -9,0 +11,0 @@ if (!fs.existsSync(dir)) { |
@@ -1,6 +0,8 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
var jsonFile = require('./jsonfile') | ||
var mkdir = require('../mkdirs') | ||
'use strict' | ||
const fs = require('graceful-fs') | ||
const path = require('path') | ||
const mkdir = require('../mkdirs') | ||
const jsonFile = require('./jsonfile') | ||
function outputJson (file, data, options, callback) { | ||
@@ -12,8 +14,8 @@ if (typeof options === 'function') { | ||
var dir = path.dirname(file) | ||
const dir = path.dirname(file) | ||
fs.exists(dir, function (itDoes) { | ||
fs.exists(dir, itDoes => { | ||
if (itDoes) return jsonFile.writeJson(file, data, options, callback) | ||
mkdir.mkdirs(dir, function (err) { | ||
mkdir.mkdirs(dir, err => { | ||
if (err) return callback(err) | ||
@@ -20,0 +22,0 @@ jsonFile.writeJson(file, data, options, callback) |
@@ -1,7 +0,9 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
var invalidWin32Path = require('./win32').invalidWin32Path | ||
'use strict' | ||
var o777 = parseInt('0777', 8) | ||
const fs = require('graceful-fs') | ||
const path = require('path') | ||
const invalidWin32Path = require('./win32').invalidWin32Path | ||
const o777 = parseInt('0777', 8) | ||
function mkdirsSync (p, opts, made) { | ||
@@ -12,7 +14,7 @@ if (!opts || typeof opts !== 'object') { | ||
var mode = opts.mode | ||
var xfs = opts.fs || fs | ||
let mode = opts.mode | ||
const xfs = opts.fs || fs | ||
if (process.platform === 'win32' && invalidWin32Path(p)) { | ||
var errInval = new Error(p + ' contains invalid WIN32 path characters.') | ||
const errInval = new Error(p + ' contains invalid WIN32 path characters.') | ||
errInval.code = 'EINVAL' | ||
@@ -44,3 +46,3 @@ throw errInval | ||
default: | ||
var stat | ||
let stat | ||
try { | ||
@@ -47,0 +49,0 @@ stat = xfs.statSync(p) |
@@ -1,7 +0,9 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
var invalidWin32Path = require('./win32').invalidWin32Path | ||
'use strict' | ||
var o777 = parseInt('0777', 8) | ||
const fs = require('graceful-fs') | ||
const path = require('path') | ||
const invalidWin32Path = require('./win32').invalidWin32Path | ||
const o777 = parseInt('0777', 8) | ||
function mkdirs (p, opts, callback, made) { | ||
@@ -16,3 +18,3 @@ if (typeof opts === 'function') { | ||
if (process.platform === 'win32' && invalidWin32Path(p)) { | ||
var errInval = new Error(p + ' contains invalid WIN32 path characters.') | ||
const errInval = new Error(p + ' contains invalid WIN32 path characters.') | ||
errInval.code = 'EINVAL' | ||
@@ -22,4 +24,4 @@ return callback(errInval) | ||
var mode = opts.mode | ||
var xfs = opts.fs || fs | ||
let mode = opts.mode | ||
const xfs = opts.fs || fs | ||
@@ -34,3 +36,3 @@ if (mode === undefined) { | ||
xfs.mkdir(p, mode, function (er) { | ||
xfs.mkdir(p, mode, er => { | ||
if (!er) { | ||
@@ -43,3 +45,3 @@ made = made || p | ||
if (path.dirname(p) === p) return callback(er) | ||
mkdirs(path.dirname(p), opts, function (er, made) { | ||
mkdirs(path.dirname(p), opts, (er, made) => { | ||
if (er) callback(er, made) | ||
@@ -54,3 +56,3 @@ else mkdirs(p, opts, callback, made) | ||
default: | ||
xfs.stat(p, function (er2, stat) { | ||
xfs.stat(p, (er2, stat) => { | ||
// if the stat fails, then that's super weird. | ||
@@ -57,0 +59,0 @@ // let the original error be the failure reason. |
'use strict' | ||
var path = require('path') | ||
const path = require('path') | ||
// get drive on windows | ||
@@ -8,3 +9,3 @@ function getRootPath (p) { | ||
if (p.length > 0) return p[0] | ||
else return null | ||
return null | ||
} | ||
@@ -14,6 +15,6 @@ | ||
// TODO: expand to include the rest | ||
var INVALID_PATH_CHARS = /[<>:"|?*]/ | ||
const INVALID_PATH_CHARS = /[<>:"|?*]/ | ||
function invalidWin32Path (p) { | ||
var rp = getRootPath(p) | ||
const rp = getRootPath(p) | ||
p = p.replace(rp, '') | ||
@@ -24,4 +25,4 @@ return INVALID_PATH_CHARS.test(p) | ||
module.exports = { | ||
getRootPath: getRootPath, | ||
invalidWin32Path: invalidWin32Path | ||
getRootPath, | ||
invalidWin32Path | ||
} |
@@ -0,1 +1,3 @@ | ||
'use strict' | ||
// most of this code was written by Andrew Kelley | ||
@@ -7,9 +9,9 @@ // licensed under the BSD license: see | ||
var fs = require('graceful-fs') | ||
var ncp = require('../copy/ncp') | ||
var path = require('path') | ||
var remove = require('../remove').remove | ||
var mkdirp = require('../mkdirs').mkdirs | ||
const fs = require('graceful-fs') | ||
const ncp = require('../copy/ncp') | ||
const path = require('path') | ||
const remove = require('../remove').remove | ||
const mkdirp = require('../mkdirs').mkdirs | ||
function mv (source, dest, options, callback) { | ||
function move (source, dest, options, callback) { | ||
if (typeof options === 'function') { | ||
@@ -20,4 +22,4 @@ callback = options | ||
var shouldMkdirp = ('mkdirp' in options) ? options.mkdirp : true | ||
var overwrite = options.overwrite || options.clobber || false | ||
const shouldMkdirp = ('mkdirp' in options) ? options.mkdirp : true | ||
const overwrite = options.overwrite || options.clobber || false | ||
@@ -31,3 +33,3 @@ if (shouldMkdirp) { | ||
function mkdirs () { | ||
mkdirp(path.dirname(dest), function (err) { | ||
mkdirp(path.dirname(dest), err => { | ||
if (err) return callback(err) | ||
@@ -39,11 +41,13 @@ doRename() | ||
function doRename () { | ||
if (overwrite) { | ||
fs.rename(source, dest, function (err) { | ||
if (path.resolve(source) === path.resolve(dest)) { | ||
setImmediate(callback) | ||
} else if (overwrite) { | ||
fs.rename(source, dest, err => { | ||
if (!err) return callback() | ||
if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST') { | ||
remove(dest, function (err) { | ||
remove(dest, err => { | ||
if (err) return callback(err) | ||
options.overwrite = false // just overwriteed it, no need to do it again | ||
mv(source, dest, options, callback) | ||
move(source, dest, options, callback) | ||
}) | ||
@@ -55,7 +59,7 @@ return | ||
if (err.code === 'EPERM') { | ||
setTimeout(function () { | ||
remove(dest, function (err) { | ||
setTimeout(() => { | ||
remove(dest, err => { | ||
if (err) return callback(err) | ||
options.overwrite = false | ||
mv(source, dest, options, callback) | ||
move(source, dest, options, callback) | ||
}) | ||
@@ -70,5 +74,5 @@ }, 200) | ||
} else { | ||
fs.link(source, dest, function (err) { | ||
fs.link(source, dest, err => { | ||
if (err) { | ||
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM') { | ||
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') { | ||
moveAcrossDevice(source, dest, overwrite, callback) | ||
@@ -87,3 +91,3 @@ return | ||
function moveAcrossDevice (source, dest, overwrite, callback) { | ||
fs.stat(source, function (err, stat) { | ||
fs.stat(source, (err, stat) => { | ||
if (err) { | ||
@@ -103,7 +107,7 @@ callback(err) | ||
function moveFileAcrossDevice (source, dest, overwrite, callback) { | ||
var outFlags = overwrite ? 'w' : 'wx' | ||
var ins = fs.createReadStream(source) | ||
var outs = fs.createWriteStream(dest, {flags: outFlags}) | ||
const flags = overwrite ? 'w' : 'wx' | ||
const ins = fs.createReadStream(source) | ||
const outs = fs.createWriteStream(dest, { flags }) | ||
ins.on('error', function (err) { | ||
ins.on('error', err => { | ||
ins.destroy() | ||
@@ -116,3 +120,3 @@ outs.destroy() | ||
// don't care about error here | ||
fs.unlink(dest, function () { | ||
fs.unlink(dest, () => { | ||
// note: `err` here is from the input stream errror | ||
@@ -127,3 +131,3 @@ if (err.code === 'EISDIR' || err.code === 'EPERM') { | ||
outs.on('error', function (err) { | ||
outs.on('error', err => { | ||
ins.destroy() | ||
@@ -144,15 +148,8 @@ outs.destroy() | ||
function moveDirAcrossDevice (source, dest, overwrite, callback) { | ||
var options = { | ||
const options = { | ||
overwrite: false | ||
} | ||
function startNcp () { | ||
ncp(source, dest, options, function (err) { | ||
if (err) return callback(err) | ||
remove(source, callback) | ||
}) | ||
} | ||
if (overwrite) { | ||
remove(dest, function (err) { | ||
remove(dest, err => { | ||
if (err) return callback(err) | ||
@@ -164,6 +161,13 @@ startNcp() | ||
} | ||
function startNcp () { | ||
ncp(source, dest, options, err => { | ||
if (err) return callback(err) | ||
remove(source, callback) | ||
}) | ||
} | ||
} | ||
module.exports = { | ||
move: mv | ||
move | ||
} |
@@ -1,5 +0,7 @@ | ||
var path = require('path') | ||
var fs = require('graceful-fs') | ||
var mkdir = require('../mkdirs') | ||
'use strict' | ||
const fs = require('graceful-fs') | ||
const path = require('path') | ||
const mkdir = require('../mkdirs') | ||
function outputFile (file, data, encoding, callback) { | ||
@@ -11,7 +13,7 @@ if (typeof encoding === 'function') { | ||
var dir = path.dirname(file) | ||
fs.exists(dir, function (itDoes) { | ||
const dir = path.dirname(file) | ||
fs.exists(dir, itDoes => { | ||
if (itDoes) return fs.writeFile(file, data, encoding, callback) | ||
mkdir.mkdirs(dir, function (err) { | ||
mkdir.mkdirs(dir, err => { | ||
if (err) return callback(err) | ||
@@ -25,3 +27,3 @@ | ||
function outputFileSync (file, data, encoding) { | ||
var dir = path.dirname(file) | ||
const dir = path.dirname(file) | ||
if (fs.existsSync(dir)) { | ||
@@ -35,4 +37,4 @@ return fs.writeFileSync.apply(fs, arguments) | ||
module.exports = { | ||
outputFile: outputFile, | ||
outputFileSync: outputFileSync | ||
outputFile, | ||
outputFileSync | ||
} |
@@ -1,3 +0,5 @@ | ||
var rimraf = require('./rimraf') | ||
'use strict' | ||
const rimraf = require('./rimraf') | ||
function removeSync (dir) { | ||
@@ -8,3 +10,3 @@ return rimraf.sync(dir, {disableGlob: true}) | ||
function remove (dir, callback) { | ||
var options = {disableGlob: true} | ||
const options = {disableGlob: true} | ||
return callback ? rimraf(dir, options, callback) : rimraf(dir, options, function () {}) | ||
@@ -14,4 +16,4 @@ } | ||
module.exports = { | ||
remove: remove, | ||
removeSync: removeSync | ||
remove, | ||
removeSync | ||
} |
@@ -1,12 +0,11 @@ | ||
module.exports = rimraf | ||
rimraf.sync = rimrafSync | ||
'use strict' | ||
var assert = require('assert') | ||
var path = require('path') | ||
var fs = require('graceful-fs') | ||
const fs = require('graceful-fs') | ||
const path = require('path') | ||
const assert = require('assert') | ||
var isWindows = (process.platform === 'win32') | ||
const isWindows = (process.platform === 'win32') | ||
function defaults (options) { | ||
var methods = [ | ||
const methods = [ | ||
'unlink', | ||
@@ -19,3 +18,3 @@ 'chmod', | ||
] | ||
methods.forEach(function (m) { | ||
methods.forEach(m => { | ||
options[m] = options[m] || fs[m] | ||
@@ -30,2 +29,4 @@ m = m + 'Sync' | ||
function rimraf (p, options, cb) { | ||
let busyTries = 0 | ||
if (typeof options === 'function') { | ||
@@ -44,4 +45,2 @@ cb = options | ||
var busyTries = 0 | ||
rimraf_(p, options, function CB (er) { | ||
@@ -52,7 +51,5 @@ if (er) { | ||
busyTries++ | ||
var time = busyTries * 100 | ||
let time = busyTries * 100 | ||
// try again, with the same exact callback as this one. | ||
return setTimeout(function () { | ||
rimraf_(p, options, CB) | ||
}, time) | ||
return setTimeout(() => rimraf_(p, options, CB), time) | ||
} | ||
@@ -86,3 +83,3 @@ | ||
// so we have to lstat here and make sure it's not a dir. | ||
options.lstat(p, function (er, st) { | ||
options.lstat(p, (er, st) => { | ||
if (er && er.code === 'ENOENT') { | ||
@@ -101,3 +98,3 @@ return cb(null) | ||
options.unlink(p, function (er) { | ||
options.unlink(p, er => { | ||
if (er) { | ||
@@ -129,7 +126,7 @@ if (er.code === 'ENOENT') { | ||
options.chmod(p, 666, function (er2) { | ||
options.chmod(p, 666, er2 => { | ||
if (er2) { | ||
cb(er2.code === 'ENOENT' ? null : er) | ||
} else { | ||
options.stat(p, function (er3, stats) { | ||
options.stat(p, (er3, stats) => { | ||
if (er3) { | ||
@@ -148,2 +145,4 @@ cb(er3.code === 'ENOENT' ? null : er) | ||
function fixWinEPERMSync (p, options, er) { | ||
let stats | ||
assert(p) | ||
@@ -166,3 +165,3 @@ assert(options) | ||
try { | ||
var stats = options.statSync(p) | ||
stats = options.statSync(p) | ||
} catch (er3) { | ||
@@ -194,3 +193,3 @@ if (er3.code === 'ENOENT') { | ||
// raise the original error. | ||
options.rmdir(p, function (er) { | ||
options.rmdir(p, er => { | ||
if (er && (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM')) { | ||
@@ -211,19 +210,16 @@ rmkids(p, options, cb) | ||
options.readdir(p, function (er, files) { | ||
if (er) { | ||
return cb(er) | ||
} | ||
var n = files.length | ||
if (n === 0) { | ||
return options.rmdir(p, cb) | ||
} | ||
var errState | ||
files.forEach(function (f) { | ||
rimraf(path.join(p, f), options, function (er) { | ||
options.readdir(p, (er, files) => { | ||
if (er) return cb(er) | ||
let n = files.length | ||
let errState | ||
if (n === 0) return options.rmdir(p, cb) | ||
files.forEach(f => { | ||
rimraf(path.join(p, f), options, er => { | ||
if (errState) { | ||
return | ||
} | ||
if (er) { | ||
return cb(errState = er) | ||
} | ||
if (er) return cb(errState = er) | ||
if (--n === 0) { | ||
@@ -241,2 +237,4 @@ options.rmdir(p, cb) | ||
function rimrafSync (p, options) { | ||
let st | ||
options = options || {} | ||
@@ -251,3 +249,3 @@ defaults(options) | ||
try { | ||
var st = options.lstatSync(p) | ||
st = options.lstatSync(p) | ||
} catch (er) { | ||
@@ -274,7 +272,5 @@ if (er.code === 'ENOENT') { | ||
return | ||
} | ||
if (er.code === 'EPERM') { | ||
} else if (er.code === 'EPERM') { | ||
return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er) | ||
} | ||
if (er.code !== 'EISDIR') { | ||
} else if (er.code !== 'EISDIR') { | ||
throw er | ||
@@ -298,7 +294,5 @@ } | ||
return | ||
} | ||
if (er.code === 'ENOTDIR') { | ||
} else if (er.code === 'ENOTDIR') { | ||
throw originalEr | ||
} | ||
if (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM') { | ||
} else if (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM') { | ||
rmkidsSync(p, options) | ||
@@ -312,6 +306,7 @@ } | ||
assert(options) | ||
options.readdirSync(p).forEach(function (f) { | ||
rimrafSync(path.join(p, f), options) | ||
}) | ||
options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options)) | ||
options.rmdirSync(p, options) | ||
} | ||
module.exports = rimraf | ||
rimraf.sync = rimrafSync |
@@ -0,7 +1,9 @@ | ||
'use strict' | ||
// simple mutable assign | ||
function assign () { | ||
var args = [].slice.call(arguments).filter(function (i) { return i }) | ||
var dest = args.shift() | ||
args.forEach(function (src) { | ||
Object.keys(src).forEach(function (key) { | ||
const args = [].slice.call(arguments).filter(i => i) | ||
const dest = args.shift() | ||
args.forEach(src => { | ||
Object.keys(src).forEach(key => { | ||
dest[key] = src[key] | ||
@@ -8,0 +10,0 @@ }) |
@@ -1,14 +0,16 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
var os = require('os') | ||
'use strict' | ||
const fs = require('graceful-fs') | ||
const os = require('os') | ||
const path = require('path') | ||
// HFS, ext{2,3}, FAT do not, Node.js v0.10 does not | ||
function hasMillisResSync () { | ||
var tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2)) | ||
let tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2)) | ||
tmpfile = path.join(os.tmpdir(), tmpfile) | ||
// 550 millis past UNIX epoch | ||
var d = new Date(1435410243862) | ||
const d = new Date(1435410243862) | ||
fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141') | ||
var fd = fs.openSync(tmpfile, 'r+') | ||
const fd = fs.openSync(tmpfile, 'r+') | ||
fs.futimesSync(fd, d, d) | ||
@@ -20,16 +22,16 @@ fs.closeSync(fd) | ||
function hasMillisRes (callback) { | ||
var tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2)) | ||
let tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2)) | ||
tmpfile = path.join(os.tmpdir(), tmpfile) | ||
// 550 millis past UNIX epoch | ||
var d = new Date(1435410243862) | ||
fs.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', function (err) { | ||
const d = new Date(1435410243862) | ||
fs.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', err => { | ||
if (err) return callback(err) | ||
fs.open(tmpfile, 'r+', function (err, fd) { | ||
fs.open(tmpfile, 'r+', (err, fd) => { | ||
if (err) return callback(err) | ||
fs.futimes(fd, d, d, function (err) { | ||
fs.futimes(fd, d, d, err => { | ||
if (err) return callback(err) | ||
fs.close(fd, function (err) { | ||
fs.close(fd, err => { | ||
if (err) return callback(err) | ||
fs.stat(tmpfile, function (err, stats) { | ||
fs.stat(tmpfile, (err, stats) => { | ||
if (err) return callback(err) | ||
@@ -56,6 +58,6 @@ callback(null, stats.mtime > 1435410243000) | ||
// if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback) | ||
fs.open(path, 'r+', function (err, fd) { | ||
fs.open(path, 'r+', (err, fd) => { | ||
if (err) return callback(err) | ||
fs.futimes(fd, atime, mtime, function (futimesErr) { | ||
fs.close(fd, function (closeErr) { | ||
fs.futimes(fd, atime, mtime, futimesErr => { | ||
fs.close(fd, closeErr => { | ||
if (callback) callback(futimesErr || closeErr) | ||
@@ -68,6 +70,6 @@ }) | ||
module.exports = { | ||
hasMillisRes: hasMillisRes, | ||
hasMillisResSync: hasMillisResSync, | ||
timeRemoveMillis: timeRemoveMillis, | ||
utimesMillis: utimesMillis | ||
hasMillisRes, | ||
hasMillisResSync, | ||
timeRemoveMillis, | ||
utimesMillis | ||
} |
{ | ||
"name": "fs-extra", | ||
"version": "2.0.0", | ||
"version": "2.1.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.", | ||
@@ -43,2 +43,3 @@ "homepage": "https://github.com/jprichardson/node-fs-extra", | ||
"klaw": "^1.0.0", | ||
"klaw-sync": "^1.1.2", | ||
"minimist": "^1.1.1", | ||
@@ -50,3 +51,2 @@ "mocha": "^3.1.2", | ||
"secure-random": "^1.1.1", | ||
"semver": "^5.3.0", | ||
"standard": "^8.5.0" | ||
@@ -62,3 +62,6 @@ }, | ||
"unit": "node test.js" | ||
}, | ||
"engines": { | ||
"node": ">=4.5.0" | ||
} | ||
} |
@@ -38,3 +38,3 @@ Node.js: fs-extra | ||
```js | ||
var fs = require('fs') // this is no longer necessary | ||
const fs = require('fs') // this is no longer necessary | ||
``` | ||
@@ -45,3 +45,3 @@ | ||
```js | ||
var fs = require('fs-extra') | ||
const fs = require('fs-extra') | ||
``` | ||
@@ -53,3 +53,3 @@ | ||
```js | ||
var fse = require('fs-extra') | ||
const fse = require('fs-extra') | ||
``` | ||
@@ -60,4 +60,4 @@ | ||
```js | ||
var fs = require('fs') | ||
var fse = require('fs-extra') | ||
const fs = require('fs') | ||
const fse = require('fs-extra') | ||
``` | ||
@@ -74,5 +74,5 @@ | ||
```js | ||
var fs = require('fs-extra') | ||
const fs = require('fs-extra') | ||
fs.copy('/tmp/myfile', '/tmp/mynewfile', function (err) { | ||
fs.copy('/tmp/myfile', '/tmp/mynewfile', err => { | ||
if (err) return console.error(err) | ||
@@ -93,29 +93,36 @@ console.log("success!") | ||
------- | ||
### Async | ||
- [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) | ||
### Sync | ||
- [copySync](docs/copy-sync.md) | ||
- [emptyDirSync](docs/emptyDir-sync.md) | ||
- [ensureFileSync](docs/ensureFile-sync.md) | ||
- [ensureDirSync](docs/ensureDir-sync.md) | ||
- [ensureLinkSync](docs/ensureLink-sync.md) | ||
- [ensureSymlinkSync](docs/ensureSymlink-sync.md) | ||
- [mkdirsSync](docs/ensureDir-sync.md) | ||
- [moveSync](docs/move-sync.md) | ||
- [outputFileSync](docs/outputFile-sync.md) | ||
- [outputJsonSync](docs/outputJson-sync.md) | ||
- [readJsonSync](docs/readJson-sync.md) | ||
- [removeSync](docs/remove-sync.md) | ||
- [writeJsonSync](docs/writeJson-sync.md) | ||
**NOTE:** You can still use the native Node.js methods. They are copied over to `fs-extra`. | ||
@@ -125,3 +132,3 @@ | ||
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). | ||
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/manidlou/node-klaw-sync). | ||
@@ -138,4 +145,4 @@ | ||
```js | ||
var Promise = require('bluebird') | ||
var fs = Promise.promisifyAll(require('fs-extra')) | ||
const Promise = require('bluebird') | ||
const fs = Promise.promisifyAll(require('fs-extra')) | ||
``` | ||
@@ -149,2 +156,3 @@ | ||
[`mz/fs`](https://github.com/normalize/mz/blob/master/fs.js). | ||
- [`fs-p`](https://github.com/grammarly/fs-p) - TypeScript-friendly promises implementation | ||
@@ -151,0 +159,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
125611
58
1487
252
1