Comparing version 10.1.0 to 11.1.1
@@ -29,6 +29,2 @@ 'use strict' | ||
stat.checkParentPathsSync(src, srcStat, dest, 'copy') | ||
return handleFilterAndCopy(destStat, src, dest, opts) | ||
} | ||
function handleFilterAndCopy (destStat, src, dest, opts) { | ||
if (opts.filter && !opts.filter(src, dest)) return | ||
@@ -40,7 +36,2 @@ const destParent = path.dirname(dest) | ||
function startCopy (destStat, src, dest, opts) { | ||
if (opts.filter && !opts.filter(src, dest)) return | ||
return getStats(destStat, src, dest, opts) | ||
} | ||
function getStats (destStat, src, dest, opts) { | ||
@@ -126,4 +117,5 @@ const statSync = opts.dereference ? fs.statSync : fs.lstatSync | ||
const destItem = path.join(dest, item) | ||
if (opts.filter && !opts.filter(srcItem, destItem)) return | ||
const { destStat } = stat.checkPathsSync(srcItem, destItem, 'copy', opts) | ||
return startCopy(destStat, srcItem, destItem, opts) | ||
return getStats(destStat, srcItem, destItem, opts) | ||
} | ||
@@ -160,3 +152,3 @@ | ||
// and therefore a broken symlink would be created. | ||
if (fs.statSync(dest).isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) { | ||
if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) { | ||
throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`) | ||
@@ -163,0 +155,0 @@ } |
@@ -38,4 +38,8 @@ 'use strict' | ||
if (err) return cb(err) | ||
if (opts.filter) return handleFilter(checkParentDir, destStat, src, dest, opts, cb) | ||
return checkParentDir(destStat, src, dest, opts, cb) | ||
runFilter(src, dest, opts, (err, include) => { | ||
if (err) return cb(err) | ||
if (!include) return cb() | ||
checkParentDir(destStat, src, dest, opts, cb) | ||
}) | ||
}) | ||
@@ -57,14 +61,8 @@ }) | ||
function handleFilter (onInclude, destStat, src, dest, opts, cb) { | ||
Promise.resolve(opts.filter(src, dest)).then(include => { | ||
if (include) return onInclude(destStat, src, dest, opts, cb) | ||
return cb() | ||
}, error => cb(error)) | ||
function runFilter (src, dest, opts, cb) { | ||
if (!opts.filter) return cb(null, true) | ||
Promise.resolve(opts.filter(src, dest)) | ||
.then(include => cb(null, include), error => cb(error)) | ||
} | ||
function startCopy (destStat, src, dest, opts, cb) { | ||
if (opts.filter) return handleFilter(getStats, destStat, src, dest, opts, cb) | ||
return getStats(destStat, src, dest, opts, cb) | ||
} | ||
function getStats (destStat, src, dest, opts, cb) { | ||
@@ -183,8 +181,13 @@ const stat = opts.dereference ? fs.stat : fs.lstat | ||
const destItem = path.join(dest, item) | ||
stat.checkPaths(srcItem, destItem, 'copy', opts, (err, stats) => { | ||
runFilter(srcItem, destItem, opts, (err, include) => { | ||
if (err) return cb(err) | ||
const { destStat } = stats | ||
startCopy(destStat, srcItem, destItem, opts, err => { | ||
if (!include) return copyDirItems(items, src, dest, opts, cb) | ||
stat.checkPaths(srcItem, destItem, 'copy', opts, (err, stats) => { | ||
if (err) return cb(err) | ||
return copyDirItems(items, src, dest, opts, cb) | ||
const { destStat } = stats | ||
getStats(destStat, srcItem, destItem, opts, err => { | ||
if (err) return cb(err) | ||
return copyDirItems(items, src, dest, opts, cb) | ||
}) | ||
}) | ||
@@ -222,3 +225,3 @@ }) | ||
// and therefore a broken symlink would be created. | ||
if (destStat.isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) { | ||
if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) { | ||
return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)) | ||
@@ -225,0 +228,0 @@ } |
@@ -44,4 +44,3 @@ 'use strict' | ||
// Some commands are not available on some systems. Ex: | ||
// fs.opendir was added in Node.js v12.12.0 | ||
// fs.rm was added in Node.js v14.14.0 | ||
// fs.cp was added in Node.js v16.7.0 | ||
// fs.lchown is not available on at least some Linux | ||
@@ -70,3 +69,3 @@ return typeof fs[key] === 'function' | ||
// fs.read(), fs.write(), & fs.writev() need special treatment due to multiple callback args | ||
// fs.read(), fs.write(), fs.readv(), & fs.writev() need special treatment due to multiple callback args | ||
@@ -103,19 +102,32 @@ exports.read = function (fd, buffer, offset, length, position, callback) { | ||
// fs.writev only available in Node v12.9.0+ | ||
if (typeof fs.writev === 'function') { | ||
// Function signature is | ||
// s.writev(fd, buffers[, position], callback) | ||
// We need to handle the optional arg, so we use ...args | ||
exports.writev = function (fd, buffers, ...args) { | ||
if (typeof args[args.length - 1] === 'function') { | ||
return fs.writev(fd, buffers, ...args) | ||
} | ||
// Function signature is | ||
// s.readv(fd, buffers[, position], callback) | ||
// We need to handle the optional arg, so we use ...args | ||
exports.readv = function (fd, buffers, ...args) { | ||
if (typeof args[args.length - 1] === 'function') { | ||
return fs.readv(fd, buffers, ...args) | ||
} | ||
return new Promise((resolve, reject) => { | ||
fs.writev(fd, buffers, ...args, (err, bytesWritten, buffers) => { | ||
if (err) return reject(err) | ||
resolve({ bytesWritten, buffers }) | ||
}) | ||
return new Promise((resolve, reject) => { | ||
fs.readv(fd, buffers, ...args, (err, bytesRead, buffers) => { | ||
if (err) return reject(err) | ||
resolve({ bytesRead, buffers }) | ||
}) | ||
}) | ||
} | ||
// Function signature is | ||
// s.writev(fd, buffers[, position], callback) | ||
// We need to handle the optional arg, so we use ...args | ||
exports.writev = function (fd, buffers, ...args) { | ||
if (typeof args[args.length - 1] === 'function') { | ||
return fs.writev(fd, buffers, ...args) | ||
} | ||
return new Promise((resolve, reject) => { | ||
fs.writev(fd, buffers, ...args, (err, bytesWritten, buffers) => { | ||
if (err) return reject(err) | ||
resolve({ bytesWritten, buffers }) | ||
}) | ||
}) | ||
} | ||
@@ -122,0 +134,0 @@ |
@@ -48,3 +48,4 @@ 'use strict' | ||
overwrite, | ||
errorOnExist: true | ||
errorOnExist: true, | ||
preserveTimestamps: true | ||
} | ||
@@ -51,0 +52,0 @@ copySync(src, dest, opts) |
@@ -67,3 +67,4 @@ 'use strict' | ||
overwrite, | ||
errorOnExist: true | ||
errorOnExist: true, | ||
preserveTimestamps: true | ||
} | ||
@@ -70,0 +71,0 @@ copy(src, dest, opts, err => { |
@@ -5,14 +5,9 @@ 'use strict' | ||
const u = require('universalify').fromCallback | ||
const rimraf = require('./rimraf') | ||
function remove (path, callback) { | ||
// Node 14.14.0+ | ||
if (fs.rm) return fs.rm(path, { recursive: true, force: true }, callback) | ||
rimraf(path, callback) | ||
fs.rm(path, { recursive: true, force: true }, callback) | ||
} | ||
function removeSync (path) { | ||
// Node 14.14.0+ | ||
if (fs.rmSync) return fs.rmSync(path, { recursive: true, force: true }) | ||
rimraf.sync(path) | ||
fs.rmSync(path, { recursive: true, force: true }) | ||
} | ||
@@ -19,0 +14,0 @@ |
{ | ||
"name": "fs-extra", | ||
"version": "10.1.0", | ||
"version": "11.1.1", | ||
"description": "fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as recursive mkdir, copy, and remove.", | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14.14" | ||
}, | ||
@@ -45,13 +45,16 @@ "homepage": "https://github.com/jprichardson/node-fs-extra", | ||
"devDependencies": { | ||
"at-least-node": "^1.0.0", | ||
"klaw": "^2.1.1", | ||
"klaw-sync": "^3.0.2", | ||
"minimist": "^1.1.1", | ||
"mocha": "^5.0.5", | ||
"mocha": "^10.1.0", | ||
"nyc": "^15.0.0", | ||
"proxyquire": "^2.0.1", | ||
"read-dir-files": "^0.1.1", | ||
"standard": "^16.0.3" | ||
"standard": "^17.0.0" | ||
}, | ||
"main": "./lib/index.js", | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./esm": "./lib/esm.mjs" | ||
}, | ||
"files": [ | ||
@@ -64,6 +67,7 @@ "lib/", | ||
"test-find": "find ./lib/**/__tests__ -name *.test.js | xargs mocha", | ||
"test": "npm run lint && npm run unit", | ||
"unit": "nyc node test.js" | ||
"test": "npm run lint && npm run unit && npm run unit-esm", | ||
"unit": "nyc node test.js", | ||
"unit-esm": "node test.mjs" | ||
}, | ||
"sideEffects": false | ||
} |
@@ -8,3 +8,3 @@ Node.js: fs-extra | ||
[![License](https://img.shields.io/npm/l/fs-extra.svg)](https://github.com/jprichardson/node-fs-extra/blob/master/LICENSE) | ||
[![build status](https://img.shields.io/github/workflow/status/jprichardson/node-fs-extra/Node.js%20CI/master)](https://github.com/jprichardson/node-fs-extra/actions/workflows/ci.yml?query=branch%3Amaster) | ||
[![build status](https://img.shields.io/github/actions/workflow/status/jprichardson/node-fs-extra/ci.yml?branch=master)](https://github.com/jprichardson/node-fs-extra/actions/workflows/ci.yml?query=branch%3Amaster) | ||
[![downloads per month](http://img.shields.io/npm/dm/fs-extra.svg)](https://www.npmjs.org/package/fs-extra) | ||
@@ -31,2 +31,4 @@ [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
### CommonJS | ||
`fs-extra` is a drop in replacement for native `fs`. All methods in `fs` are attached to `fs-extra`. All `fs` methods return promises if the callback isn't passed. | ||
@@ -60,2 +62,27 @@ | ||
### ESM | ||
There is also an `fs-extra/esm` import, that supports both default and named exports. However, note that `fs` methods are not included in `fs-extra/esm`; you still need to import `fs` and/or `fs/promises` seperately: | ||
```js | ||
import { readFileSync } from 'fs' | ||
import { readFile } from 'fs/promises' | ||
import { outputFile, outputFileSync } from 'fs-extra/esm' | ||
``` | ||
Default exports are supported: | ||
```js | ||
import fs from 'fs' | ||
import fse from 'fs-extra/esm' | ||
// fse.readFileSync is not a function; must use fs.readFileSync | ||
``` | ||
but you probably want to just use regular `fs-extra` instead of `fs-extra/esm` for default exports: | ||
```js | ||
import fs from 'fs-extra' | ||
// both fs and fs-extra methods are defined | ||
``` | ||
Sync vs Async vs Async/Await | ||
@@ -203,5 +230,8 @@ ------------- | ||
- `npm run unit`: runs the unit tests | ||
- `npm test`: runs both the linter and the tests | ||
- `npm run unit-esm`: runs tests for `fs-extra/esm` exports | ||
- `npm test`: runs the linter and all tests | ||
When running unit tests, set the environment variable `CROSS_DEVICE_PATH` to the absolute path of an empty directory on another device (like a thumb drive) to enable cross-device move tests. | ||
### Windows | ||
@@ -208,0 +238,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
293
59493
1348