Skip to content

Commit

Permalink
BREAKING: Drop Node v12 support; require v14.14+ (#969)
Browse files Browse the repository at this point in the history
Resolves #968
  • Loading branch information
RyanZim committed Oct 31, 2022
1 parent 656545c commit 5623ba3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 339 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -8,7 +8,7 @@ jobs:
test:
strategy:
matrix:
node: [12.x, 13.x, 14.x, 15.x, 16.x, 17.x]
node: [14.x, 16.x, 18.x, 19.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
6 changes: 1 addition & 5 deletions lib/fs/__tests__/multi-param.test.js
Expand Up @@ -4,14 +4,10 @@ const assert = require('assert')
const path = require('path')
const crypto = require('crypto')
const os = require('os')
const atLeastNode = require('at-least-node')
const fs = require('../..')

const SIZE = 1000

// Used for tests on Node 12.9.0+ only
const describeNode12 = atLeastNode('12.9.0') ? describe : describe.skip

describe('fs.read()', () => {
let TEST_FILE
let TEST_DATA
Expand Down Expand Up @@ -153,7 +149,7 @@ describe('fs.write()', () => {
})
})

describeNode12('fs.writev()', () => {
describe('fs.writev()', () => {
let TEST_FILE
let TEST_DATA
let TEST_FD
Expand Down
6 changes: 1 addition & 5 deletions lib/fs/__tests__/rm.test.js
Expand Up @@ -4,14 +4,10 @@ const fse = require('../..')
const os = require('os')
const path = require('path')
const assert = require('assert')
const atLeastNode = require('at-least-node')

/* eslint-env mocha */

// Used for tests on Node 14.14.0+ only
const describeNode14 = atLeastNode('14.14.0') ? describe : describe.skip

describeNode14('fs.rm', () => {
describe('fs.rm', () => {
let TEST_FILE

beforeEach(done => {
Expand Down
30 changes: 13 additions & 17 deletions lib/fs/index.js
Expand Up @@ -41,8 +41,7 @@ const api = [
'writeFile'
].filter(key => {
// 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
return typeof fs[key] === 'function'
})
Expand Down Expand Up @@ -98,23 +97,20 @@ exports.write = function (fd, buffer, ...args) {
})
}

// 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.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 })
})
return new Promise((resolve, reject) => {
fs.writev(fd, buffers, ...args, (err, bytesWritten, buffers) => {
if (err) return reject(err)
resolve({ bytesWritten, buffers })
})
}
})
}

// fs.realpath.native sometimes not available if fs is monkey-patched
Expand Down
9 changes: 2 additions & 7 deletions lib/remove/index.js
Expand Up @@ -2,18 +2,13 @@

const fs = require('graceful-fs')
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 })
}

module.exports = {
Expand Down

0 comments on commit 5623ba3

Please sign in to comment.