Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Drop Node v12 support; require v14.14+ #969

Merged
merged 1 commit into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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