Skip to content

Commit

Permalink
BREAKING: Drop old Node support (#751)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
RyanZim authored Feb 4, 2020
1 parent 3dac360 commit 3c3865c
Show file tree
Hide file tree
Showing 36 changed files with 120 additions and 189 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ os:
- linux
- osx
node_js:
- 6
- 8
- 9
- 10
- 11
- 12
- 13
env: TEST_SUITE=unit
matrix:
exclude:
Expand Down
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lib/copy-sync/__tests__/copy-sync-file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 12 additions & 16 deletions lib/copy/__tests__/copy-permissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -27,22 +23,22 @@ 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
let gidStaff

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()
}

Expand All @@ -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 => {
Expand Down
6 changes: 1 addition & 5 deletions lib/copy/__tests__/copy-preserve-timestamp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/copy/__tests__/ncp/ncp-error-perm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion lib/empty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function emptyDirSync (dir) {
let items
try {
items = fs.readdirSync(dir)
} catch (err) {
} catch {
return mkdir.mkdirsSync(dir)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ensure/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/ensure/symlink-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
34 changes: 15 additions & 19 deletions lib/fs/__tests__/copyFile.test.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
}
})
6 changes: 2 additions & 4 deletions lib/fs/__tests__/fs-integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
6 changes: 2 additions & 4 deletions lib/fs/__tests__/multi-param.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
40 changes: 18 additions & 22 deletions lib/fs/__tests__/realpath.test.js
Original file line number Diff line number Diff line change
@@ -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)
})
}
})
2 changes: 0 additions & 2 deletions lib/fs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand Down
29 changes: 14 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading

0 comments on commit 3c3865c

Please sign in to comment.