Skip to content

Commit 3c3865c

Browse files
authored
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
1 parent 3dac360 commit 3c3865c

36 files changed

+120
-189
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ os:
33
- linux
44
- osx
55
node_js:
6-
- 6
7-
- 8
8-
- 9
96
- 10
107
- 11
118
- 12
9+
- 13
1210
env: TEST_SUITE=unit
1311
matrix:
1412
exclude:

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
environment:
33
matrix:
44
# node.js
5-
- nodejs_version: "6"
6-
- nodejs_version: "8"
75
- nodejs_version: "10"
6+
- nodejs_version: "12"
87

98
# Install scripts. (runs after repo cloning)
109
install:

lib/copy-sync/__tests__/copy-sync-file.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('+ copySync() / file', () => {
5757
const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')
5858
fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE))
5959

60-
fs.chmodSync(fileSrc, parseInt('750', 8))
60+
fs.chmodSync(fileSrc, 0o750)
6161
fs.copySync(fileSrc, fileDest)
6262

6363
const statSrc = fs.statSync(fileSrc)
@@ -187,7 +187,7 @@ describe('+ copySync() / file', () => {
187187
describe('> when overwrite is true and dest is readonly', () => {
188188
it('should copy the file and not throw an error', () => {
189189
try {
190-
fs.chmodSync(dest, parseInt('444', 8))
190+
fs.chmodSync(dest, 0o444)
191191
fs.copySync(src, dest, { overwrite: true })
192192
destData = fs.readFileSync(dest, 'utf8')
193193
assert.strictEqual(srcData, destData)

lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ const path = require('path')
66
const copySync = require('../copy-sync')
77
const utimesSync = require('../../util/utimes').utimesMillisSync
88
const assert = require('assert')
9-
const semver = require('semver')
10-
const nodeVersion = process.version
11-
const nodeVersionMajor = semver.major(nodeVersion)
129

1310
/* global beforeEach, afterEach, describe, it */
1411

1512
if (process.arch === 'ia32') console.warn('32 bit arch; skipping copySync timestamp tests')
16-
if (nodeVersionMajor < 8) console.warn(`old node version (v${nodeVersion}); skipping copySync timestamp tests`)
1713

18-
const describeIfPractical = (process.arch === 'ia32' || nodeVersionMajor < 8) ? describe.skip : describe
14+
const describeIfPractical = process.arch === 'ia32' ? describe.skip : describe
1915

2016
describeIfPractical('copySync() - preserveTimestamps option', () => {
2117
let TEST_DIR, SRC, DEST, FILES

lib/copy/__tests__/copy-permissions.test.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ const assert = require('assert')
88

99
/* global beforeEach, describe, it */
1010

11-
const o777 = parseInt('777', 8)
12-
const o666 = parseInt('666', 8)
13-
const o444 = parseInt('444', 8)
14-
1511
describe('copy', () => {
1612
let TEST_DIR
1713

@@ -27,22 +23,22 @@ describe('copy', () => {
2723
// var userid = require('userid')
2824

2925
// http://man7.org/linux/man-pages/man2/stat.2.html
30-
const S_IFREG = parseInt('0100000', 8) // regular file
31-
const S_IFDIR = parseInt('0040000', 8) // directory
26+
const S_IFREG = 0o100000 // regular file
27+
const S_IFDIR = 0o40000 // directory
3228

3329
// these are Mac specific I think (at least staff), should find Linux equivalent
3430
let gidWheel
3531
let gidStaff
3632

3733
try {
3834
gidWheel = process.getgid() // userid.gid('wheel')
39-
} catch (err) {
35+
} catch {
4036
gidWheel = process.getgid()
4137
}
4238

4339
try {
4440
gidStaff = process.getgid() // userid.gid('staff')
45-
} catch (err) {
41+
} catch {
4642
gidStaff = process.getgid()
4743
}
4844

@@ -54,31 +50,31 @@ describe('copy', () => {
5450

5551
const f1 = path.join(srcDir, 'f1.txt')
5652
fs.writeFileSync(f1, '')
57-
fs.chmodSync(f1, o666)
53+
fs.chmodSync(f1, 0o666)
5854
fs.chownSync(f1, process.getuid(), gidWheel)
5955
const f1stats = fs.lstatSync(f1)
60-
assert.strictEqual(f1stats.mode - S_IFREG, o666)
56+
assert.strictEqual(f1stats.mode - S_IFREG, 0o666)
6157

6258
const d1 = path.join(srcDir, 'somedir')
6359
fs.mkdirSync(d1)
64-
fs.chmodSync(d1, o777)
60+
fs.chmodSync(d1, 0o777)
6561
fs.chownSync(d1, process.getuid(), gidStaff)
6662
const d1stats = fs.lstatSync(d1)
67-
assert.strictEqual(d1stats.mode - S_IFDIR, o777)
63+
assert.strictEqual(d1stats.mode - S_IFDIR, 0o777)
6864

6965
const f2 = path.join(d1, 'f2.bin')
7066
fs.writeFileSync(f2, '')
71-
fs.chmodSync(f2, o777)
67+
fs.chmodSync(f2, 0o777)
7268
fs.chownSync(f2, process.getuid(), gidStaff)
7369
const f2stats = fs.lstatSync(f2)
74-
assert.strictEqual(f2stats.mode - S_IFREG, o777)
70+
assert.strictEqual(f2stats.mode - S_IFREG, 0o777)
7571

7672
const d2 = path.join(srcDir, 'crazydir')
7773
fs.mkdirSync(d2)
78-
fs.chmodSync(d2, o444)
74+
fs.chmodSync(d2, 0o444)
7975
fs.chownSync(d2, process.getuid(), gidWheel)
8076
const d2stats = fs.lstatSync(d2)
81-
assert.strictEqual(d2stats.mode - S_IFDIR, o444)
77+
assert.strictEqual(d2stats.mode - S_IFDIR, 0o444)
8278

8379
const destDir = path.join(permDir, 'dest')
8480
fse.copy(srcDir, destDir, err => {

lib/copy/__tests__/copy-preserve-timestamp.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ const path = require('path')
66
const copy = require('../copy')
77
const utimesSync = require('../../util/utimes').utimesMillisSync
88
const assert = require('assert')
9-
const semver = require('semver')
10-
const nodeVersion = process.version
11-
const nodeVersionMajor = semver.major(nodeVersion)
129

1310
/* global beforeEach, afterEach, describe, it */
1411

1512
if (process.arch === 'ia32') console.warn('32 bit arch; skipping copy timestamp tests')
16-
if (nodeVersionMajor < 8) console.warn(`old node version (v${nodeVersion}); skipping copy timestamp tests`)
1713

18-
const describeIfPractical = (process.arch === 'ia32' || nodeVersionMajor < 8) ? describe.skip : describe
14+
const describeIfPractical = process.arch === 'ia32' ? describe.skip : describe
1915

2016
describeIfPractical('copy() - preserve timestamp', () => {
2117
let TEST_DIR, SRC, DEST, FILES

lib/copy/__tests__/ncp/ncp-error-perm.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('ncp / error / dest-permission', () => {
3737
fse.outputFileSync(someFile, 'hello')
3838

3939
fse.mkdirsSync(dest)
40-
fs.chmodSync(dest, parseInt('444', 8))
40+
fs.chmodSync(dest, 0o444)
4141

4242
const subdest = path.join(dest, 'another-dir')
4343

lib/empty/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function emptyDirSync (dir) {
3030
let items
3131
try {
3232
items = fs.readdirSync(dir)
33-
} catch (err) {
33+
} catch {
3434
return mkdir.mkdirsSync(dir)
3535
}
3636

lib/ensure/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function createFileSync (file) {
4444
let stats
4545
try {
4646
stats = fs.statSync(file)
47-
} catch (e) {}
47+
} catch {}
4848
if (stats && stats.isFile()) return
4949

5050
const dir = path.dirname(file)

lib/ensure/symlink-type.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function symlinkTypeSync (srcpath, type) {
1919
if (type) return type
2020
try {
2121
stats = fs.lstatSync(srcpath)
22-
} catch (e) {
22+
} catch {
2323
return 'file'
2424
}
2525
return (stats && stats.isDirectory()) ? 'dir' : 'file'

lib/fs/__tests__/copyFile.test.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
'use strict'
22

33
const os = require('os')
4-
const fs = require('fs')
54
const fse = require('../..')
65
const path = require('path')
76
const assert = require('assert')
87

98
/* eslint-env mocha */
109

11-
// Only availible in Node 8.5+
12-
if (typeof fs.copyFile === 'function') {
13-
describe('fs.copyFile', () => {
14-
let TEST_DIR
10+
describe('fs.copyFile', () => {
11+
let TEST_DIR
1512

16-
beforeEach(done => {
17-
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'fs-copyfile')
18-
fse.emptyDir(TEST_DIR, done)
19-
})
13+
beforeEach(done => {
14+
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'fs-copyfile')
15+
fse.emptyDir(TEST_DIR, done)
16+
})
2017

21-
afterEach(done => fse.remove(TEST_DIR, done))
18+
afterEach(done => fse.remove(TEST_DIR, done))
2219

23-
it('supports promises', () => {
24-
const src = path.join(TEST_DIR, 'init.txt')
25-
const dest = path.join(TEST_DIR, 'copy.txt')
26-
fse.writeFileSync(src, 'hello')
27-
return fse.copyFile(src, dest).then(() => {
28-
const data = fse.readFileSync(dest, 'utf8')
29-
assert.strictEqual(data, 'hello')
30-
})
20+
it('supports promises', () => {
21+
const src = path.join(TEST_DIR, 'init.txt')
22+
const dest = path.join(TEST_DIR, 'copy.txt')
23+
fse.writeFileSync(src, 'hello')
24+
return fse.copyFile(src, dest).then(() => {
25+
const data = fse.readFileSync(dest, 'utf8')
26+
assert.strictEqual(data, 'hello')
3127
})
3228
})
33-
}
29+
})

lib/fs/__tests__/fs-integration.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ describe('native fs', () => {
2626
})
2727

2828
it('should have native fs constants', () => {
29-
// Node.js v0.12 / IO.js
30-
if ('F_OK' in fs) {
31-
assert.strictEqual(fse.F_OK, fs.F_OK)
32-
}
29+
assert.strictEqual(fse.constants.F_OK, fs.constants.F_OK)
30+
assert.strictEqual(fse.F_OK, fs.F_OK) // soft deprecated usage, but still available
3331
})
3432
})

lib/fs/__tests__/multi-param.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const fs = require('../..')
99

1010
const SIZE = 1000
1111

12-
// Used for tests on Node 7.2.0+ only
13-
const onNode7it = semver.gte(process.version, '7.2.0') ? it : it.skip
1412
// Used for tests on Node 12.9.0+ only
1513
const describeNode12 = semver.gte(process.version, '12.9.0') ? describe : describe.skip
1614

@@ -102,7 +100,7 @@ describe('fs.write()', () => {
102100
})
103101
})
104102

105-
onNode7it('returns an object when minimal arguments are passed', () => {
103+
it('returns an object when minimal arguments are passed', () => {
106104
return fs.write(TEST_FD, TEST_DATA)
107105
.then(results => {
108106
const bytesWritten = results.bytesWritten
@@ -134,7 +132,7 @@ describe('fs.write()', () => {
134132
})
135133
})
136134

137-
onNode7it('works when minimal arguments are passed', done => {
135+
it('works when minimal arguments are passed', done => {
138136
fs.write(TEST_FD, TEST_DATA, (err, bytesWritten, buffer) => {
139137
assert.ifError(err)
140138
assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct')

lib/fs/__tests__/realpath.test.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
'use strict'
22

3-
const fs = require('fs')
43
const fse = require('../..')
54
const assert = require('assert')
65

76
/* eslint-env mocha */
87

9-
// fs.realpath.native only available in Node v9.2+
10-
if (typeof fs.realpath.native === 'function') {
11-
describe('realpath.native', () => {
12-
it('works with callbacks', () => {
13-
fse.realpath.native(__dirname, (err, path) => {
14-
assert.ifError(err)
15-
assert.strictEqual(path, __dirname)
16-
})
8+
describe('realpath.native', () => {
9+
it('works with callbacks', () => {
10+
fse.realpath.native(__dirname, (err, path) => {
11+
assert.ifError(err)
12+
assert.strictEqual(path, __dirname)
1713
})
14+
})
1815

19-
it('works with promises', (done) => {
20-
fse.realpath.native(__dirname)
21-
.then(path => {
22-
assert.strictEqual(path, __dirname)
23-
done()
24-
})
25-
.catch(done)
26-
})
16+
it('works with promises', (done) => {
17+
fse.realpath.native(__dirname)
18+
.then(path => {
19+
assert.strictEqual(path, __dirname)
20+
done()
21+
})
22+
.catch(done)
23+
})
2724

28-
it('works with sync version', () => {
29-
const path = fse.realpathSync.native(__dirname)
30-
assert.strictEqual(path, __dirname)
31-
})
25+
it('works with sync version', () => {
26+
const path = fse.realpathSync.native(__dirname)
27+
assert.strictEqual(path, __dirname)
3228
})
33-
}
29+
})

lib/fs/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ const api = [
4141
].filter(key => {
4242
// Some commands are not available on some systems. Ex:
4343
// fs.opendir was added in Node.js v12.12.0
44-
// fs.copyFile was added in Node.js v8.5.0
45-
// fs.mkdtemp was added in Node.js v5.10.0
4644
// fs.lchown is not available on at least some Linux
4745
return typeof fs[key] === 'function'
4846
})

lib/index.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
'use strict'
22

3-
module.exports = Object.assign(
4-
{},
3+
module.exports = {
54
// Export promiseified graceful-fs:
6-
require('./fs'),
5+
...require('./fs'),
76
// Export extra methods:
8-
require('./copy-sync'),
9-
require('./copy'),
10-
require('./empty'),
11-
require('./ensure'),
12-
require('./json'),
13-
require('./mkdirs'),
14-
require('./move-sync'),
15-
require('./move'),
16-
require('./output'),
17-
require('./path-exists'),
18-
require('./remove')
19-
)
7+
...require('./copy-sync'),
8+
...require('./copy'),
9+
...require('./empty'),
10+
...require('./ensure'),
11+
...require('./json'),
12+
...require('./mkdirs'),
13+
...require('./move-sync'),
14+
...require('./move'),
15+
...require('./output'),
16+
...require('./path-exists'),
17+
...require('./remove')
18+
}
2019

2120
// Export fs.promises as a getter property so that we don't trigger
2221
// ExperimentalWarning before fs.promises is actually accessed.

0 commit comments

Comments
 (0)