From 8b2bee292066deafe17d83081246844dfa34d14b Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sun, 21 Feb 2021 21:39:11 +0900 Subject: [PATCH 1/2] refactor: do not depend on deprecated constatnts module --- polyfills.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polyfills.js b/polyfills.js index 453f1a9..fd88fa3 100644 --- a/polyfills.js +++ b/polyfills.js @@ -1,4 +1,4 @@ -var constants = require('constants') +var constants = require('fs').constants var origCwd = process.cwd var cwd = null @@ -31,7 +31,7 @@ function patch (fs) { // lchmod, broken prior to 0.6.2 // back-port the fix here. - if (constants.hasOwnProperty('O_SYMLINK') && + if (constants.O_SYMLINK !== undefined && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) { patchLchmod(fs) } @@ -206,7 +206,7 @@ function patch (fs) { } function patchLutimes (fs) { - if (constants.hasOwnProperty("O_SYMLINK") && fs.futimes) { + if (constants.O_SYMLINK !== undefined && fs.futimes) { fs.lutimes = function (path, at, mt, cb) { fs.open(path, constants.O_SYMLINK, function (er, fd) { if (er) { From bfced71f0f5c1dc814a0ec5e465a75cbc3e0cb9b Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Fri, 26 Jul 2024 15:17:02 +0300 Subject: [PATCH 2/2] Use "node:" prefixed imports everywhere, and bump the minimum nodejs version to the ones supporting this feature. --- .github/workflows/ci.yml | 10 ++++++++-- graceful-fs.js | 6 +++--- legacy-streams.js | 2 +- package.json | 3 +++ polyfills.js | 2 +- test.js | 6 +++--- test/chown-er-ok.js | 2 +- test/close.js | 4 ++-- test/monkeypatch-by-accident.js | 2 +- test/read-write-stream.js | 2 +- test/readfile.js | 2 +- test/retry.js | 4 ++-- test/stats-uid-gid.js | 4 ++-- test/stats.js | 2 +- test/windows-rename-polyfill.js | 2 +- test/write-then-read.js | 2 +- test/zzz-avoid-memory-leak.js | 2 +- 17 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 171b7c4..faf1714 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,14 @@ jobs: build: strategy: matrix: - node-version: [10.0.x, 10.x, 12.0.x, 12.x, 14.0.x, 14.x, 15.x] + node-version: [14.8.0, 14, 16.0.0, 16] os: [ubuntu-latest, macOS-latest, windows-latest] + exclude: + # Node 14 is not available on macos anymore + - os: macos-latest + node-version: 14 + - os: macos-latest + node-version: 14.18.0 fail-fast: false runs-on: ${{ matrix.os }} @@ -17,7 +23,7 @@ jobs: uses: actions/checkout@v1.1.0 - name: Use Nodejs ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} diff --git a/graceful-fs.js b/graceful-fs.js index 8d5b89e..ad04108 100644 --- a/graceful-fs.js +++ b/graceful-fs.js @@ -1,9 +1,9 @@ -var fs = require('fs') +var fs = require('node:fs') var polyfills = require('./polyfills.js') var legacy = require('./legacy-streams.js') var clone = require('./clone.js') -var util = require('util') +var util = require('node:util') /* istanbul ignore next - node 0.x polyfill */ var gracefulQueue @@ -84,7 +84,7 @@ if (!fs[gracefulQueue]) { if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) { process.on('exit', function() { debug(fs[gracefulQueue]) - require('assert').equal(fs[gracefulQueue].length, 0) + require('node:assert').equal(fs[gracefulQueue].length, 0) }) } } diff --git a/legacy-streams.js b/legacy-streams.js index d617b50..43c4ce2 100644 --- a/legacy-streams.js +++ b/legacy-streams.js @@ -1,4 +1,4 @@ -var Stream = require('stream').Stream +var Stream = require('node:stream').Stream module.exports = legacy diff --git a/package.json b/package.json index 87babf0..c8b3a3d 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,9 @@ "EACCESS" ], "license": "ISC", + "engines": { + "node": ">=14.18.0 <15 || >=16" + }, "devDependencies": { "import-fresh": "^2.0.0", "mkdirp": "^0.5.0", diff --git a/polyfills.js b/polyfills.js index fd88fa3..943af01 100644 --- a/polyfills.js +++ b/polyfills.js @@ -1,4 +1,4 @@ -var constants = require('fs').constants +var constants = require('node:fs').constants var origCwd = process.cwd var cwd = null diff --git a/test.js b/test.js index a72c04c..b795921 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,8 @@ -var fs = require('fs') +var fs = require('node:fs') var tap = require('tap') var dir = __dirname + '/test' var node = process.execPath -var path = require('path') +var path = require('node:path') var files = fs.readdirSync(dir) var env = Object.keys(process.env).reduce(function (env, k) { @@ -12,7 +12,7 @@ var env = Object.keys(process.env).reduce(function (env, k) { TEST_GRACEFUL_FS_GLOBAL_PATCH: 1 }) -tap.jobs = require('os').cpus().length +tap.jobs = require('node:os').cpus().length var testFiles = files.filter(function (f) { return (/\.js$/.test(f) && fs.statSync(dir + '/' + f).isFile()) }) diff --git a/test/chown-er-ok.js b/test/chown-er-ok.js index aad7815..8343883 100644 --- a/test/chown-er-ok.js +++ b/test/chown-er-ok.js @@ -1,4 +1,4 @@ -var realFs = require('fs') +var realFs = require('node:fs') var methods = ['chown', 'chownSync', 'chmod', 'chmodSync'] methods.forEach(function (method) { diff --git a/test/close.js b/test/close.js index 7210b31..b3fc2dd 100644 --- a/test/close.js +++ b/test/close.js @@ -1,5 +1,5 @@ -var fs = require('fs') -var path = require('path') +var fs = require('node:fs') +var path = require('node:path') var gfsPath = path.resolve(__dirname, '..', 'graceful-fs.js') var gfs = require(gfsPath) var importFresh = require('import-fresh') diff --git a/test/monkeypatch-by-accident.js b/test/monkeypatch-by-accident.js index 51d2b2a..7d21473 100644 --- a/test/monkeypatch-by-accident.js +++ b/test/monkeypatch-by-accident.js @@ -5,7 +5,7 @@ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH) { process.exit(0) } -const fs = require('fs') +const fs = require('node:fs') // Save originals before loading graceful-fs const names = [ diff --git a/test/read-write-stream.js b/test/read-write-stream.js index 876f9f3..b8bdf0b 100644 --- a/test/read-write-stream.js +++ b/test/read-write-stream.js @@ -8,7 +8,7 @@ var t = require('tap') var td = t.testdir({ files: {} }) -var p = require('path').resolve(td, 'files') +var p = require('node:path').resolve(td, 'files') process.chdir(td) diff --git a/test/readfile.js b/test/readfile.js index bb6abe1..649e41e 100644 --- a/test/readfile.js +++ b/test/readfile.js @@ -8,7 +8,7 @@ var t = require('tap') var td = t.testdir({ files: {} }) -var p = require('path').resolve(td, 'files') +var p = require('node:path').resolve(td, 'files') process.chdir(td) diff --git a/test/retry.js b/test/retry.js index f9db714..8408dc2 100644 --- a/test/retry.js +++ b/test/retry.js @@ -1,8 +1,8 @@ 'use strict' var importFresh = require('import-fresh') -var path = require('path') -var realFs = require('fs') +var path = require('node:path') +var realFs = require('node:fs') var test = require('tap').test var EMFILE = Object.assign(new Error('FAKE EMFILE'), { code: 'EMFILE' }) diff --git a/test/stats-uid-gid.js b/test/stats-uid-gid.js index 7422e5d..48e330a 100644 --- a/test/stats-uid-gid.js +++ b/test/stats-uid-gid.js @@ -1,6 +1,6 @@ 'use strict'; -var util = require('util') -var fs = require('fs') +var util = require('node:util') +var fs = require('node:fs') var test = require('tap').test // mock fs.statSync to return signed uids/gids diff --git a/test/stats.js b/test/stats.js index b6c45b9..f75b219 100644 --- a/test/stats.js +++ b/test/stats.js @@ -1,4 +1,4 @@ -var fs = require('fs') +var fs = require('node:fs') var gfs = require('../graceful-fs.js') var test = require('tap').test diff --git a/test/windows-rename-polyfill.js b/test/windows-rename-polyfill.js index 77353b0..c740bd8 100644 --- a/test/windows-rename-polyfill.js +++ b/test/windows-rename-polyfill.js @@ -1,7 +1,7 @@ process.env.GRACEFUL_FS_PLATFORM = 'win32' var t = require('tap') -var fs = require('fs') +var fs = require('node:fs') var ers = ['EPERM', 'EBUSY', 'EACCES'] t.plan(ers.length) diff --git a/test/write-then-read.js b/test/write-then-read.js index a9de291..8d5a0e9 100644 --- a/test/write-then-read.js +++ b/test/write-then-read.js @@ -4,7 +4,7 @@ var mkdirp = require('mkdirp') var t = require('tap') var td = t.testdir({ files: {} }) -var p = require('path').resolve(td, 'files') +var p = require('node:path').resolve(td, 'files') process.chdir(td) diff --git a/test/zzz-avoid-memory-leak.js b/test/zzz-avoid-memory-leak.js index 45cdff0..5726b79 100644 --- a/test/zzz-avoid-memory-leak.js +++ b/test/zzz-avoid-memory-leak.js @@ -2,7 +2,7 @@ var importFresh = require('import-fresh'); var t = require('tap') var v8 try { - v8 = require('v8') + v8 = require('node:v8') } catch (er) {} if (!v8 || !v8.getHeapStatistics || typeof v8.getHeapStatistics().number_of_detached_contexts !== 'number') {