From 3c3865cad8cae7f3046edf434c2ac76abaec7759 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman <17342435+RyanZim@users.noreply.github.com> Date: Tue, 4 Feb 2020 17:30:40 -0500 Subject: [PATCH] BREAKING: Drop old Node support (#751) * BREAKING: Drop old Node support, require v10+ Update CI configs * Remove references and test fencing for old Node versions * Use object spread properties * Use octal literal notation * Use optional catch bindings --- .travis.yml | 4 +- appveyor.yml | 3 +- .../__tests__/copy-sync-file.test.js | 4 +- .../copy-sync-preserve-timestamp.test.js | 6 +-- lib/copy/__tests__/copy-permissions.test.js | 28 ++++++------- .../__tests__/copy-preserve-timestamp.test.js | 6 +-- lib/copy/__tests__/ncp/ncp-error-perm.test.js | 2 +- lib/empty/index.js | 2 +- lib/ensure/file.js | 2 +- lib/ensure/symlink-type.js | 2 +- lib/fs/__tests__/copyFile.test.js | 34 +++++++--------- lib/fs/__tests__/fs-integration.test.js | 6 +-- lib/fs/__tests__/multi-param.test.js | 6 +-- lib/fs/__tests__/realpath.test.js | 40 +++++++++---------- lib/fs/index.js | 2 - lib/index.js | 29 +++++++------- lib/mkdirs/__tests__/chmod.test.js | 13 ++---- lib/mkdirs/__tests__/clobber.test.js | 4 +- lib/mkdirs/__tests__/issue-209.test.js | 3 +- lib/mkdirs/__tests__/mkdirp.test.js | 10 ++--- lib/mkdirs/__tests__/perm.test.js | 12 ++---- lib/mkdirs/__tests__/perm_sync.test.js | 12 ++---- lib/mkdirs/__tests__/race.test.js | 10 ++--- lib/mkdirs/__tests__/rel.test.js | 10 ++--- lib/mkdirs/__tests__/root.test.js | 4 +- lib/mkdirs/__tests__/sync.test.js | 10 ++--- lib/mkdirs/__tests__/umask.test.js | 6 +-- lib/mkdirs/mkdirs-sync.js | 16 ++++---- lib/mkdirs/mkdirs.js | 4 +- lib/move-sync/__tests__/move-sync.test.js | 2 +- lib/move/__tests__/move.test.js | 2 +- lib/remove/rimraf.js | 2 +- lib/util/buffer.js | 2 +- lib/util/utimes.js | 2 +- package.json | 2 +- test.js | 7 ++-- 36 files changed, 120 insertions(+), 189 deletions(-) diff --git a/.travis.yml b/.travis.yml index 97e446e7..de0378f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,10 @@ os: - linux - osx node_js: - - 6 - - 8 - - 9 - 10 - 11 - 12 + - 13 env: TEST_SUITE=unit matrix: exclude: diff --git a/appveyor.yml b/appveyor.yml index 7b7a0a0b..32db05f9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,9 +2,8 @@ environment: matrix: # node.js - - nodejs_version: "6" - - nodejs_version: "8" - nodejs_version: "10" + - nodejs_version: "12" # Install scripts. (runs after repo cloning) install: diff --git a/lib/copy-sync/__tests__/copy-sync-file.test.js b/lib/copy-sync/__tests__/copy-sync-file.test.js index 5044214e..1218fce8 100644 --- a/lib/copy-sync/__tests__/copy-sync-file.test.js +++ b/lib/copy-sync/__tests__/copy-sync-file.test.js @@ -57,7 +57,7 @@ describe('+ copySync() / file', () => { const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE)) - fs.chmodSync(fileSrc, parseInt('750', 8)) + fs.chmodSync(fileSrc, 0o750) fs.copySync(fileSrc, fileDest) const statSrc = fs.statSync(fileSrc) @@ -187,7 +187,7 @@ describe('+ copySync() / file', () => { describe('> when overwrite is true and dest is readonly', () => { it('should copy the file and not throw an error', () => { try { - fs.chmodSync(dest, parseInt('444', 8)) + fs.chmodSync(dest, 0o444) fs.copySync(src, dest, { overwrite: true }) destData = fs.readFileSync(dest, 'utf8') assert.strictEqual(srcData, destData) diff --git a/lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js b/lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js index 6612b3c9..51e52411 100644 --- a/lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js +++ b/lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js @@ -6,16 +6,12 @@ const path = require('path') const copySync = require('../copy-sync') const utimesSync = require('../../util/utimes').utimesMillisSync const assert = require('assert') -const semver = require('semver') -const nodeVersion = process.version -const nodeVersionMajor = semver.major(nodeVersion) /* global beforeEach, afterEach, describe, it */ if (process.arch === 'ia32') console.warn('32 bit arch; skipping copySync timestamp tests') -if (nodeVersionMajor < 8) console.warn(`old node version (v${nodeVersion}); skipping copySync timestamp tests`) -const describeIfPractical = (process.arch === 'ia32' || nodeVersionMajor < 8) ? describe.skip : describe +const describeIfPractical = process.arch === 'ia32' ? describe.skip : describe describeIfPractical('copySync() - preserveTimestamps option', () => { let TEST_DIR, SRC, DEST, FILES diff --git a/lib/copy/__tests__/copy-permissions.test.js b/lib/copy/__tests__/copy-permissions.test.js index ccc89cd2..dafa7d05 100644 --- a/lib/copy/__tests__/copy-permissions.test.js +++ b/lib/copy/__tests__/copy-permissions.test.js @@ -8,10 +8,6 @@ const assert = require('assert') /* global beforeEach, describe, it */ -const o777 = parseInt('777', 8) -const o666 = parseInt('666', 8) -const o444 = parseInt('444', 8) - describe('copy', () => { let TEST_DIR @@ -27,8 +23,8 @@ describe('copy', () => { // var userid = require('userid') // http://man7.org/linux/man-pages/man2/stat.2.html - const S_IFREG = parseInt('0100000', 8) // regular file - const S_IFDIR = parseInt('0040000', 8) // directory + const S_IFREG = 0o100000 // regular file + const S_IFDIR = 0o40000 // directory // these are Mac specific I think (at least staff), should find Linux equivalent let gidWheel @@ -36,13 +32,13 @@ describe('copy', () => { try { gidWheel = process.getgid() // userid.gid('wheel') - } catch (err) { + } catch { gidWheel = process.getgid() } try { gidStaff = process.getgid() // userid.gid('staff') - } catch (err) { + } catch { gidStaff = process.getgid() } @@ -54,31 +50,31 @@ describe('copy', () => { const f1 = path.join(srcDir, 'f1.txt') fs.writeFileSync(f1, '') - fs.chmodSync(f1, o666) + fs.chmodSync(f1, 0o666) fs.chownSync(f1, process.getuid(), gidWheel) const f1stats = fs.lstatSync(f1) - assert.strictEqual(f1stats.mode - S_IFREG, o666) + assert.strictEqual(f1stats.mode - S_IFREG, 0o666) const d1 = path.join(srcDir, 'somedir') fs.mkdirSync(d1) - fs.chmodSync(d1, o777) + fs.chmodSync(d1, 0o777) fs.chownSync(d1, process.getuid(), gidStaff) const d1stats = fs.lstatSync(d1) - assert.strictEqual(d1stats.mode - S_IFDIR, o777) + assert.strictEqual(d1stats.mode - S_IFDIR, 0o777) const f2 = path.join(d1, 'f2.bin') fs.writeFileSync(f2, '') - fs.chmodSync(f2, o777) + fs.chmodSync(f2, 0o777) fs.chownSync(f2, process.getuid(), gidStaff) const f2stats = fs.lstatSync(f2) - assert.strictEqual(f2stats.mode - S_IFREG, o777) + assert.strictEqual(f2stats.mode - S_IFREG, 0o777) const d2 = path.join(srcDir, 'crazydir') fs.mkdirSync(d2) - fs.chmodSync(d2, o444) + fs.chmodSync(d2, 0o444) fs.chownSync(d2, process.getuid(), gidWheel) const d2stats = fs.lstatSync(d2) - assert.strictEqual(d2stats.mode - S_IFDIR, o444) + assert.strictEqual(d2stats.mode - S_IFDIR, 0o444) const destDir = path.join(permDir, 'dest') fse.copy(srcDir, destDir, err => { diff --git a/lib/copy/__tests__/copy-preserve-timestamp.test.js b/lib/copy/__tests__/copy-preserve-timestamp.test.js index 5447e706..55c391dc 100644 --- a/lib/copy/__tests__/copy-preserve-timestamp.test.js +++ b/lib/copy/__tests__/copy-preserve-timestamp.test.js @@ -6,16 +6,12 @@ const path = require('path') const copy = require('../copy') const utimesSync = require('../../util/utimes').utimesMillisSync const assert = require('assert') -const semver = require('semver') -const nodeVersion = process.version -const nodeVersionMajor = semver.major(nodeVersion) /* global beforeEach, afterEach, describe, it */ if (process.arch === 'ia32') console.warn('32 bit arch; skipping copy timestamp tests') -if (nodeVersionMajor < 8) console.warn(`old node version (v${nodeVersion}); skipping copy timestamp tests`) -const describeIfPractical = (process.arch === 'ia32' || nodeVersionMajor < 8) ? describe.skip : describe +const describeIfPractical = process.arch === 'ia32' ? describe.skip : describe describeIfPractical('copy() - preserve timestamp', () => { let TEST_DIR, SRC, DEST, FILES diff --git a/lib/copy/__tests__/ncp/ncp-error-perm.test.js b/lib/copy/__tests__/ncp/ncp-error-perm.test.js index a31a43dd..49bef1f9 100644 --- a/lib/copy/__tests__/ncp/ncp-error-perm.test.js +++ b/lib/copy/__tests__/ncp/ncp-error-perm.test.js @@ -37,7 +37,7 @@ describe('ncp / error / dest-permission', () => { fse.outputFileSync(someFile, 'hello') fse.mkdirsSync(dest) - fs.chmodSync(dest, parseInt('444', 8)) + fs.chmodSync(dest, 0o444) const subdest = path.join(dest, 'another-dir') diff --git a/lib/empty/index.js b/lib/empty/index.js index 204d53ba..90fb4699 100644 --- a/lib/empty/index.js +++ b/lib/empty/index.js @@ -30,7 +30,7 @@ function emptyDirSync (dir) { let items try { items = fs.readdirSync(dir) - } catch (err) { + } catch { return mkdir.mkdirsSync(dir) } diff --git a/lib/ensure/file.js b/lib/ensure/file.js index b8b2495c..15cc473c 100644 --- a/lib/ensure/file.js +++ b/lib/ensure/file.js @@ -44,7 +44,7 @@ function createFileSync (file) { let stats try { stats = fs.statSync(file) - } catch (e) {} + } catch {} if (stats && stats.isFile()) return const dir = path.dirname(file) diff --git a/lib/ensure/symlink-type.js b/lib/ensure/symlink-type.js index 4f8787c2..42dc0ce7 100644 --- a/lib/ensure/symlink-type.js +++ b/lib/ensure/symlink-type.js @@ -19,7 +19,7 @@ function symlinkTypeSync (srcpath, type) { if (type) return type try { stats = fs.lstatSync(srcpath) - } catch (e) { + } catch { return 'file' } return (stats && stats.isDirectory()) ? 'dir' : 'file' diff --git a/lib/fs/__tests__/copyFile.test.js b/lib/fs/__tests__/copyFile.test.js index 822ed5fe..e61921d4 100644 --- a/lib/fs/__tests__/copyFile.test.js +++ b/lib/fs/__tests__/copyFile.test.js @@ -1,33 +1,29 @@ 'use strict' const os = require('os') -const fs = require('fs') const fse = require('../..') const path = require('path') const assert = require('assert') /* eslint-env mocha */ -// Only availible in Node 8.5+ -if (typeof fs.copyFile === 'function') { - describe('fs.copyFile', () => { - let TEST_DIR +describe('fs.copyFile', () => { + let TEST_DIR - beforeEach(done => { - TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'fs-copyfile') - fse.emptyDir(TEST_DIR, done) - }) + beforeEach(done => { + TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'fs-copyfile') + fse.emptyDir(TEST_DIR, done) + }) - afterEach(done => fse.remove(TEST_DIR, done)) + afterEach(done => fse.remove(TEST_DIR, done)) - it('supports promises', () => { - const src = path.join(TEST_DIR, 'init.txt') - const dest = path.join(TEST_DIR, 'copy.txt') - fse.writeFileSync(src, 'hello') - return fse.copyFile(src, dest).then(() => { - const data = fse.readFileSync(dest, 'utf8') - assert.strictEqual(data, 'hello') - }) + it('supports promises', () => { + const src = path.join(TEST_DIR, 'init.txt') + const dest = path.join(TEST_DIR, 'copy.txt') + fse.writeFileSync(src, 'hello') + return fse.copyFile(src, dest).then(() => { + const data = fse.readFileSync(dest, 'utf8') + assert.strictEqual(data, 'hello') }) }) -} +}) diff --git a/lib/fs/__tests__/fs-integration.test.js b/lib/fs/__tests__/fs-integration.test.js index e8b81f8a..64dd2870 100644 --- a/lib/fs/__tests__/fs-integration.test.js +++ b/lib/fs/__tests__/fs-integration.test.js @@ -26,9 +26,7 @@ describe('native fs', () => { }) it('should have native fs constants', () => { - // Node.js v0.12 / IO.js - if ('F_OK' in fs) { - assert.strictEqual(fse.F_OK, fs.F_OK) - } + assert.strictEqual(fse.constants.F_OK, fs.constants.F_OK) + assert.strictEqual(fse.F_OK, fs.F_OK) // soft deprecated usage, but still available }) }) diff --git a/lib/fs/__tests__/multi-param.test.js b/lib/fs/__tests__/multi-param.test.js index 690a1306..b23efc07 100644 --- a/lib/fs/__tests__/multi-param.test.js +++ b/lib/fs/__tests__/multi-param.test.js @@ -9,8 +9,6 @@ const fs = require('../..') const SIZE = 1000 -// Used for tests on Node 7.2.0+ only -const onNode7it = semver.gte(process.version, '7.2.0') ? it : it.skip // Used for tests on Node 12.9.0+ only const describeNode12 = semver.gte(process.version, '12.9.0') ? describe : describe.skip @@ -102,7 +100,7 @@ describe('fs.write()', () => { }) }) - onNode7it('returns an object when minimal arguments are passed', () => { + it('returns an object when minimal arguments are passed', () => { return fs.write(TEST_FD, TEST_DATA) .then(results => { const bytesWritten = results.bytesWritten @@ -134,7 +132,7 @@ describe('fs.write()', () => { }) }) - onNode7it('works when minimal arguments are passed', done => { + it('works when minimal arguments are passed', done => { fs.write(TEST_FD, TEST_DATA, (err, bytesWritten, buffer) => { assert.ifError(err) assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct') diff --git a/lib/fs/__tests__/realpath.test.js b/lib/fs/__tests__/realpath.test.js index 59ee6fa3..93068593 100644 --- a/lib/fs/__tests__/realpath.test.js +++ b/lib/fs/__tests__/realpath.test.js @@ -1,33 +1,29 @@ 'use strict' -const fs = require('fs') const fse = require('../..') const assert = require('assert') /* eslint-env mocha */ -// fs.realpath.native only available in Node v9.2+ -if (typeof fs.realpath.native === 'function') { - describe('realpath.native', () => { - it('works with callbacks', () => { - fse.realpath.native(__dirname, (err, path) => { - assert.ifError(err) - assert.strictEqual(path, __dirname) - }) +describe('realpath.native', () => { + it('works with callbacks', () => { + fse.realpath.native(__dirname, (err, path) => { + assert.ifError(err) + assert.strictEqual(path, __dirname) }) + }) - it('works with promises', (done) => { - fse.realpath.native(__dirname) - .then(path => { - assert.strictEqual(path, __dirname) - done() - }) - .catch(done) - }) + it('works with promises', (done) => { + fse.realpath.native(__dirname) + .then(path => { + assert.strictEqual(path, __dirname) + done() + }) + .catch(done) + }) - it('works with sync version', () => { - const path = fse.realpathSync.native(__dirname) - assert.strictEqual(path, __dirname) - }) + it('works with sync version', () => { + const path = fse.realpathSync.native(__dirname) + assert.strictEqual(path, __dirname) }) -} +}) diff --git a/lib/fs/index.js b/lib/fs/index.js index fe54a131..101aae9b 100644 --- a/lib/fs/index.js +++ b/lib/fs/index.js @@ -41,8 +41,6 @@ const api = [ ].filter(key => { // Some commands are not available on some systems. Ex: // fs.opendir was added in Node.js v12.12.0 - // fs.copyFile was added in Node.js v8.5.0 - // fs.mkdtemp was added in Node.js v5.10.0 // fs.lchown is not available on at least some Linux return typeof fs[key] === 'function' }) diff --git a/lib/index.js b/lib/index.js index 40e37b18..d9468e69 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,22 +1,21 @@ 'use strict' -module.exports = Object.assign( - {}, +module.exports = { // Export promiseified graceful-fs: - require('./fs'), + ...require('./fs'), // Export extra methods: - require('./copy-sync'), - require('./copy'), - require('./empty'), - require('./ensure'), - require('./json'), - require('./mkdirs'), - require('./move-sync'), - require('./move'), - require('./output'), - require('./path-exists'), - require('./remove') -) + ...require('./copy-sync'), + ...require('./copy'), + ...require('./empty'), + ...require('./ensure'), + ...require('./json'), + ...require('./mkdirs'), + ...require('./move-sync'), + ...require('./move'), + ...require('./output'), + ...require('./path-exists'), + ...require('./remove') +} // Export fs.promises as a getter property so that we don't trigger // ExperimentalWarning before fs.promises is actually accessed. diff --git a/lib/mkdirs/__tests__/chmod.test.js b/lib/mkdirs/__tests__/chmod.test.js index 19cb4019..5496427e 100644 --- a/lib/mkdirs/__tests__/chmod.test.js +++ b/lib/mkdirs/__tests__/chmod.test.js @@ -8,11 +8,6 @@ const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -const o755 = parseInt('755', 8) -const o744 = parseInt('744', 8) -const o777 = parseInt('777', 8) -const o666 = parseInt('666', 8) - describe('mkdirp / chmod', () => { let TEST_DIR let TEST_SUBDIR @@ -35,7 +30,7 @@ describe('mkdirp / chmod', () => { afterEach(done => fse.remove(TEST_DIR, done)) it('chmod-pre', done => { - const mode = o744 + const mode = 0o744 fse.mkdirp(TEST_SUBDIR, mode, err => { assert.ifError(err, 'should not error') fs.stat(TEST_SUBDIR, (err, stat) => { @@ -43,9 +38,9 @@ describe('mkdirp / chmod', () => { assert.ok(stat && stat.isDirectory(), 'should be directory') if (os.platform().indexOf('win') === 0) { - assert.strictEqual(stat && stat.mode & o777, o666, 'windows shit') + assert.strictEqual(stat && stat.mode & 0o777, 0o666, 'windows shit') } else { - assert.strictEqual(stat && stat.mode & o777, mode, 'should be 0744') + assert.strictEqual(stat && stat.mode & 0o777, mode, 'should be 0744') } done() @@ -54,7 +49,7 @@ describe('mkdirp / chmod', () => { }) it('chmod', done => { - const mode = o755 + const mode = 0o755 fse.mkdirp(TEST_SUBDIR, mode, err => { assert.ifError(err, 'should not error') fs.stat(TEST_SUBDIR, (err, stat) => { diff --git a/lib/mkdirs/__tests__/clobber.test.js b/lib/mkdirs/__tests__/clobber.test.js index f359cebf..b932b040 100644 --- a/lib/mkdirs/__tests__/clobber.test.js +++ b/lib/mkdirs/__tests__/clobber.test.js @@ -8,8 +8,6 @@ const assert = require('assert') /* global before, describe, it */ -const o755 = parseInt('755', 8) - describe('mkdirp / clobber', () => { let TEST_DIR let file @@ -42,7 +40,7 @@ describe('mkdirp / clobber', () => { }) it('should clobber', done => { - fse.mkdirp(file, o755, err => { + fse.mkdirp(file, 0o755, err => { assert.ok(err) if (os.platform().indexOf('win') === 0) { assert.strictEqual(err.code, 'EEXIST') diff --git a/lib/mkdirs/__tests__/issue-209.test.js b/lib/mkdirs/__tests__/issue-209.test.js index 7b16b816..bfe40031 100644 --- a/lib/mkdirs/__tests__/issue-209.test.js +++ b/lib/mkdirs/__tests__/issue-209.test.js @@ -30,8 +30,7 @@ describe('mkdirp: issue-209, win32, when bad path, should return a cleaner error try { const file = 'c:\\tmp\foo:moo' fse.mkdirpSync(file) - } catch (err) { - // console.error(err) + } catch { didErr = true } assert(didErr) diff --git a/lib/mkdirs/__tests__/mkdirp.test.js b/lib/mkdirs/__tests__/mkdirp.test.js index 4ec42609..2af572a3 100644 --- a/lib/mkdirs/__tests__/mkdirp.test.js +++ b/lib/mkdirs/__tests__/mkdirp.test.js @@ -8,10 +8,6 @@ const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -const o755 = parseInt('755', 8) -const o777 = parseInt('777', 8) -const o666 = parseInt('666', 8) - describe('mkdirp / mkdirp', () => { let TEST_DIR @@ -29,7 +25,7 @@ describe('mkdirp / mkdirp', () => { const file = path.join(TEST_DIR, x, y, z) - fse.mkdirp(file, o755, err => { + fse.mkdirp(file, 0o755, err => { assert.ifError(err) fse.pathExists(file, (err, ex) => { assert.ifError(err) @@ -38,9 +34,9 @@ describe('mkdirp / mkdirp', () => { assert.ifError(err) if (os.platform().indexOf('win') === 0) { - assert.strictEqual(stat.mode & o777, o666) + assert.strictEqual(stat.mode & 0o777, 0o666) } else { - assert.strictEqual(stat.mode & o777, o755) + assert.strictEqual(stat.mode & 0o777, 0o755) } assert.ok(stat.isDirectory(), 'target not a directory') diff --git a/lib/mkdirs/__tests__/perm.test.js b/lib/mkdirs/__tests__/perm.test.js index 8aa0743b..b883a652 100644 --- a/lib/mkdirs/__tests__/perm.test.js +++ b/lib/mkdirs/__tests__/perm.test.js @@ -8,10 +8,6 @@ const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -const o755 = parseInt('755', 8) -const o777 = parseInt('777', 8) -const o666 = parseInt('666', 8) - describe('mkdirp / perm', () => { let TEST_DIR @@ -25,7 +21,7 @@ describe('mkdirp / perm', () => { it('async perm', done => { const file = path.join(TEST_DIR, (Math.random() * (1 << 30)).toString(16)) - fse.mkdirp(file, o755, err => { + fse.mkdirp(file, 0o755, err => { assert.ifError(err) fse.pathExists(file, (err, ex) => { assert.ifError(err) @@ -34,9 +30,9 @@ describe('mkdirp / perm', () => { assert.ifError(err) if (os.platform().indexOf('win') === 0) { - assert.strictEqual(stat.mode & o777, o666) + assert.strictEqual(stat.mode & 0o777, 0o666) } else { - assert.strictEqual(stat.mode & o777, o755) + assert.strictEqual(stat.mode & 0o777, 0o755) } assert.ok(stat.isDirectory(), 'target not a directory') @@ -47,7 +43,7 @@ describe('mkdirp / perm', () => { }) it('async root perm', done => { - fse.mkdirp(path.join(os.tmpdir(), 'tmp'), o755, err => { + fse.mkdirp(path.join(os.tmpdir(), 'tmp'), 0o755, err => { assert.ifError(err) done() }) diff --git a/lib/mkdirs/__tests__/perm_sync.test.js b/lib/mkdirs/__tests__/perm_sync.test.js index 27b475e8..2c75967c 100644 --- a/lib/mkdirs/__tests__/perm_sync.test.js +++ b/lib/mkdirs/__tests__/perm_sync.test.js @@ -8,10 +8,6 @@ const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -const o755 = parseInt('755', 8) -const o777 = parseInt('777', 8) -const o666 = parseInt('666', 8) - describe('mkdirp / perm_sync', () => { let TEST_DIR @@ -25,7 +21,7 @@ describe('mkdirp / perm_sync', () => { it('sync perm', done => { const file = path.join(TEST_DIR, (Math.random() * (1 << 30)).toString(16) + '.json') - fse.mkdirpSync(file, o755) + fse.mkdirpSync(file, 0o755) fse.pathExists(file, (err, ex) => { assert.ifError(err) assert.ok(ex, 'file created') @@ -33,9 +29,9 @@ describe('mkdirp / perm_sync', () => { assert.ifError(err) if (os.platform().indexOf('win') === 0) { - assert.strictEqual(stat.mode & o777, o666) + assert.strictEqual(stat.mode & 0o777, 0o666) } else { - assert.strictEqual(stat.mode & o777, o755) + assert.strictEqual(stat.mode & 0o777, 0o755) } assert.ok(stat.isDirectory(), 'target not a directory') @@ -46,7 +42,7 @@ describe('mkdirp / perm_sync', () => { it('sync root perm', done => { const file = TEST_DIR - fse.mkdirpSync(file, o755) + fse.mkdirpSync(file, 0o755) fse.pathExists(file, (err, ex) => { assert.ifError(err) assert.ok(ex, 'file created') diff --git a/lib/mkdirs/__tests__/race.test.js b/lib/mkdirs/__tests__/race.test.js index 611d10fc..1d075f46 100644 --- a/lib/mkdirs/__tests__/race.test.js +++ b/lib/mkdirs/__tests__/race.test.js @@ -8,10 +8,6 @@ const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -const o755 = parseInt('755', 8) -const o777 = parseInt('777', 8) -const o666 = parseInt('666', 8) - describe('mkdirp / race', () => { let TEST_DIR let file @@ -42,7 +38,7 @@ describe('mkdirp / race', () => { mk(file, () => --res === 0 ? done() : undefined) function mk (file, callback) { - fse.mkdirp(file, o755, err => { + fse.mkdirp(file, 0o755, err => { assert.ifError(err) fse.pathExists(file, (err, ex) => { assert.ifError(err) @@ -51,9 +47,9 @@ describe('mkdirp / race', () => { assert.ifError(err) if (os.platform().indexOf('win') === 0) { - assert.strictEqual(stat.mode & o777, o666) + assert.strictEqual(stat.mode & 0o777, 0o666) } else { - assert.strictEqual(stat.mode & o777, o755) + assert.strictEqual(stat.mode & 0o777, 0o755) } assert.ok(stat.isDirectory(), 'target not a directory') diff --git a/lib/mkdirs/__tests__/rel.test.js b/lib/mkdirs/__tests__/rel.test.js index 837e1e6b..bb00031e 100644 --- a/lib/mkdirs/__tests__/rel.test.js +++ b/lib/mkdirs/__tests__/rel.test.js @@ -10,10 +10,6 @@ const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -const o755 = parseInt('755', 8) -const o777 = parseInt('777', 8) -const o666 = parseInt('666', 8) - describe('mkdirp / relative', () => { let TEST_DIR let file @@ -39,7 +35,7 @@ describe('mkdirp / relative', () => { it('should make the directory with relative path', done => { process.chdir(TEST_DIR) - fse.mkdirp(file, o755, err => { + fse.mkdirp(file, 0o755, err => { assert.ifError(err) fse.pathExists(file, (err, ex) => { assert.ifError(err) @@ -50,9 +46,9 @@ describe('mkdirp / relative', () => { process.chdir(CWD) if (os.platform().indexOf('win') === 0) { - assert.strictEqual(stat.mode & o777, o666) + assert.strictEqual(stat.mode & 0o777, 0o666) } else { - assert.strictEqual(stat.mode & o777, o755) + assert.strictEqual(stat.mode & 0o777, 0o755) } assert.ok(stat.isDirectory(), 'target not a directory') diff --git a/lib/mkdirs/__tests__/root.test.js b/lib/mkdirs/__tests__/root.test.js index ee49c39d..2d0974de 100644 --- a/lib/mkdirs/__tests__/root.test.js +++ b/lib/mkdirs/__tests__/root.test.js @@ -7,8 +7,6 @@ const assert = require('assert') /* global describe, it */ -const o755 = parseInt('755', 8) - describe('mkdirp / root', () => { // '/' on unix, 'c:/' on windows. const dir = path.normalize(path.resolve(path.sep)).toLowerCase() @@ -17,7 +15,7 @@ describe('mkdirp / root', () => { if (process.platform === 'win32' && (dir.indexOf('c:\\') === -1) && (dir.indexOf('d:\\') === -1)) return it('should', done => { - fse.mkdirp(dir, o755, err => { + fse.mkdirp(dir, 0o755, err => { if (err) throw err fs.stat(dir, (er, stat) => { if (er) throw er diff --git a/lib/mkdirs/__tests__/sync.test.js b/lib/mkdirs/__tests__/sync.test.js index 0652333a..1b7fe092 100644 --- a/lib/mkdirs/__tests__/sync.test.js +++ b/lib/mkdirs/__tests__/sync.test.js @@ -8,10 +8,6 @@ const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -const o755 = parseInt('755', 8) -const o777 = parseInt('777', 8) -const o666 = parseInt('666', 8) - describe('mkdirp / sync', () => { let TEST_DIR let file @@ -35,7 +31,7 @@ describe('mkdirp / sync', () => { it('should', done => { try { - fse.mkdirpSync(file, o755) + fse.mkdirpSync(file, 0o755) } catch (err) { assert.fail(err) } @@ -47,9 +43,9 @@ describe('mkdirp / sync', () => { assert.ifError(err) // http://stackoverflow.com/questions/592448/c-how-to-set-file-permissions-cross-platform if (os.platform().indexOf('win') === 0) { - assert.strictEqual(stat.mode & o777, o666) + assert.strictEqual(stat.mode & 0o777, 0o666) } else { - assert.strictEqual(stat.mode & o777, o755) + assert.strictEqual(stat.mode & 0o777, 0o755) } assert.ok(stat.isDirectory(), 'target not a directory') diff --git a/lib/mkdirs/__tests__/umask.test.js b/lib/mkdirs/__tests__/umask.test.js index 6049dccc..e911dbc5 100644 --- a/lib/mkdirs/__tests__/umask.test.js +++ b/lib/mkdirs/__tests__/umask.test.js @@ -8,8 +8,6 @@ const fse = require('../../') /* global afterEach, beforeEach, describe, it */ -const o777 = parseInt('777', 8) - describe('mkdirp', () => { let TEST_DIR let _rndDir @@ -47,7 +45,7 @@ describe('mkdirp', () => { assert.ok(ex, 'file created') fs.stat(_rndDir, (err, stat) => { assert.ifError(err) - assert.strictEqual(stat.mode & o777, o777 & (~process.umask())) + assert.strictEqual(stat.mode & 0o777, 0o777 & (~process.umask())) assert.ok(stat.isDirectory(), 'target not a directory') done() }) @@ -71,7 +69,7 @@ describe('mkdirp', () => { assert.ok(ex, 'file created') fs.stat(_rndDir, (err, stat) => { assert.ifError(err) - assert.strictEqual(stat.mode & o777, (o777 & (~process.umask()))) + assert.strictEqual(stat.mode & 0o777, (0o777 & (~process.umask()))) assert.ok(stat.isDirectory(), 'target not a directory') done() }) diff --git a/lib/mkdirs/mkdirs-sync.js b/lib/mkdirs/mkdirs-sync.js index a34acb99..decba61a 100644 --- a/lib/mkdirs/mkdirs-sync.js +++ b/lib/mkdirs/mkdirs-sync.js @@ -4,8 +4,6 @@ const fs = require('graceful-fs') const path = require('path') const invalidWin32Path = require('./win32').invalidWin32Path -const o777 = parseInt('0777', 8) - function mkdirsSync (p, opts, made) { if (!opts || typeof opts !== 'object') { opts = { mode: opts } @@ -21,7 +19,7 @@ function mkdirsSync (p, opts, made) { } if (mode === undefined) { - mode = o777 & (~process.umask()) + mode = 0o777 & (~process.umask()) } if (!made) made = null @@ -30,9 +28,9 @@ function mkdirsSync (p, opts, made) { try { xfs.mkdirSync(p, mode) made = made || p - } catch (err0) { - if (err0.code === 'ENOENT') { - if (path.dirname(p) === p) throw err0 + } catch (err) { + if (err.code === 'ENOENT') { + if (path.dirname(p) === p) throw err made = mkdirsSync(path.dirname(p), opts, made) mkdirsSync(p, opts, made) } else { @@ -41,10 +39,10 @@ function mkdirsSync (p, opts, made) { let stat try { stat = xfs.statSync(p) - } catch (err1) { - throw err0 + } catch { + throw err } - if (!stat.isDirectory()) throw err0 + if (!stat.isDirectory()) throw err } } diff --git a/lib/mkdirs/mkdirs.js b/lib/mkdirs/mkdirs.js index 18975337..9c72dc91 100644 --- a/lib/mkdirs/mkdirs.js +++ b/lib/mkdirs/mkdirs.js @@ -4,8 +4,6 @@ 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) { if (typeof opts === 'function') { callback = opts @@ -24,7 +22,7 @@ function mkdirs (p, opts, callback, made) { const xfs = opts.fs || fs if (mode === undefined) { - mode = o777 & (~process.umask()) + mode = 0o777 & (~process.umask()) } if (!made) made = null diff --git a/lib/move-sync/__tests__/move-sync.test.js b/lib/move-sync/__tests__/move-sync.test.js index 8ba0ede3..dca83aab 100644 --- a/lib/move-sync/__tests__/move-sync.test.js +++ b/lib/move-sync/__tests__/move-sync.test.js @@ -281,7 +281,7 @@ describe('moveSync()', () => { // make sure we have permission on device try { fs.writeFileSync(path.join(differentDevice, 'file'), 'hi') - } catch (err) { + } catch { console.log("Can't write to device. Skipping moveSync test.") __skipTests = true } diff --git a/lib/move/__tests__/move.test.js b/lib/move/__tests__/move.test.js index cb39b373..af41b93f 100644 --- a/lib/move/__tests__/move.test.js +++ b/lib/move/__tests__/move.test.js @@ -324,7 +324,7 @@ describe('+ move()', () => { // make sure we have permission on device try { fs.writeFileSync(path.join(differentDevice, 'file'), 'hi') - } catch (err) { + } catch { console.log("Can't write to device. Skipping move test.") __skipTests = true } diff --git a/lib/remove/rimraf.js b/lib/remove/rimraf.js index f287e4e1..1e44c128 100644 --- a/lib/remove/rimraf.js +++ b/lib/remove/rimraf.js @@ -302,7 +302,7 @@ function rmkidsSync (p, options) { try { const ret = options.rmdirSync(p, options) return ret - } catch (er) { } + } catch {} } while (Date.now() - startTime < 500) // give up after 500ms } else { const ret = options.rmdirSync(p, options) diff --git a/lib/util/buffer.js b/lib/util/buffer.js index dabf2885..352164da 100644 --- a/lib/util/buffer.js +++ b/lib/util/buffer.js @@ -4,7 +4,7 @@ module.exports = function (size) { if (typeof Buffer.allocUnsafe === 'function') { try { return Buffer.allocUnsafe(size) - } catch (e) { + } catch { return new Buffer(size) } } diff --git a/lib/util/utimes.js b/lib/util/utimes.js index 8916a1b8..c00d73b3 100644 --- a/lib/util/utimes.js +++ b/lib/util/utimes.js @@ -4,7 +4,7 @@ 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 +// HFS, ext{2,3}, FAT do not function hasMillisResSync () { let tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2)) tmpfile = path.join(os.tmpdir(), tmpfile) diff --git a/package.json b/package.json index 9e702b50..96275eae 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "8.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.", "engines": { - "node": ">=6 <7 || >=8" + "node": ">=10" }, "homepage": "https://github.com/jprichardson/node-fs-extra", "repository": { diff --git a/test.js b/test.js index fec09476..b50b44ec 100644 --- a/test.js +++ b/test.js @@ -7,11 +7,12 @@ const Mocha = require('mocha') const argv = require('minimist')(process.argv.slice(2)) -const mochaOpts = Object.assign({ +const mochaOpts = { ui: 'bdd', reporter: 'dot', - timeout: 30000 -}, argv) + timeout: 30000, + ...argv +} const mocha = new Mocha(mochaOpts) const testExt = '.test.js'