From 549d4033f19e06604c1c308a711e2371411371de Mon Sep 17 00:00:00 2001 From: RyanZim Date: Wed, 8 Nov 2017 19:16:19 -0500 Subject: [PATCH] BREAKING: Don't allow copy()/copySync()'s filter option to be a Regex This was deprecated previously, and is now removed. --- docs/copy-sync.md | 2 +- docs/copy.md | 2 +- lib/copy-sync/copy-sync.js | 12 ++++-------- lib/copy/copy.js | 9 +-------- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/docs/copy-sync.md b/docs/copy-sync.md index 8e61c2b6..0a33e474 100644 --- a/docs/copy-sync.md +++ b/docs/copy-sync.md @@ -9,7 +9,7 @@ Copy a file or directory. The directory can have contents. Like `cp -r`. - `errorOnExist` ``: when `overwrite` is `false` and the destination exists, throw an error. Default is `false`. - `dereference` ``: dereference symlinks, default is `false`. - `preserveTimestamps` ``: 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). + - `filter` ``: Function to filter copied files. Return `true` to include, `false` to exclude. ## Example: diff --git a/docs/copy.md b/docs/copy.md index 84407261..df834486 100644 --- a/docs/copy.md +++ b/docs/copy.md @@ -9,7 +9,7 @@ Copy a file or directory. The directory can have contents. Like `cp -r`. - `errorOnExist` ``: when `overwrite` is `false` and the destination exists, throw an error. Default is `false`. - `dereference` ``: dereference symlinks, default is `false`. - `preserveTimestamps` ``: 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). + - `filter` ``: Function to filter copied files. Return `true` to include, `false` to exclude. - `callback` `` ## Example: diff --git a/lib/copy-sync/copy-sync.js b/lib/copy-sync/copy-sync.js index 9d5639c3..22f44fb9 100644 --- a/lib/copy-sync/copy-sync.js +++ b/lib/copy-sync/copy-sync.js @@ -31,21 +31,17 @@ function copySync (src, dest, options) { 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 - 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, dest) + if (!options.filter(src, dest)) return - if (stats.isFile() && performCopy) { + if (stats.isFile()) { if (!destFolderExists) mkdir.mkdirsSync(destFolder) copyFileSync(src, dest, { overwrite: options.overwrite, errorOnExist: options.errorOnExist, preserveTimestamps: options.preserveTimestamps }) - } else if (stats.isDirectory() && performCopy) { + } else if (stats.isDirectory()) { if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest) const contents = fs.readdirSync(src) contents.forEach(content => { @@ -53,7 +49,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() && performCopy) { + } else if (options.recursive && stats.isSymbolicLink()) { const srcPath = fs.readlinkSync(src) fs.symlinkSync(srcPath, dest) } diff --git a/lib/copy/copy.js b/lib/copy/copy.js index 5288dd1c..b0e06cf8 100644 --- a/lib/copy/copy.js +++ b/lib/copy/copy.js @@ -47,14 +47,7 @@ function copy (src, dest, opts, cb) { } function startCopy (src, dest, opts, cb) { - if (opts.filter) { - if (opts.filter instanceof RegExp) { - console.warn('Warning: fs-extra: Passing a RegExp filter is deprecated, use a function') - if (!opts.filter.test(src)) return cb() - } else if (typeof opts.filter === 'function') { - if (!opts.filter(src, dest)) return cb() - } - } + if (opts.filter && !opts.filter(src, dest)) return cb() return getStats(src, dest, opts, cb) }