From e2e5b71df99fc88905f82db55e915df25fa8bb02 Mon Sep 17 00:00:00 2001 From: Michael Mok Date: Mon, 7 Oct 2024 06:48:37 +0200 Subject: [PATCH] Require Node.js 18 and update dependencies (#161) Co-authored-by: Sindre Sorhus --- .github/workflows/main.yml | 6 +++--- benchmark.js | 4 ++-- index.js | 29 +++++------------------------ package.json | 25 +++++++++---------------- test.js | 31 +++++++++++++++++-------------- 5 files changed, 36 insertions(+), 59 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 08bdbd5..a6368d5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,16 +10,16 @@ jobs: fail-fast: false matrix: node-version: + - 22 - 20 - 18 - - 16 os: - ubuntu-latest - macos-latest - windows-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/benchmark.js b/benchmark.js index 4f74d6e..6b45567 100644 --- a/benchmark.js +++ b/benchmark.js @@ -1,7 +1,7 @@ +import fs from 'node:fs'; import path from 'node:path'; import process from 'node:process'; import Benchmark from 'benchmark'; -import makeDir from 'make-dir'; import {temporaryDirectory} from 'tempy'; import {deleteAsync, deleteSync} from './index.js'; @@ -13,7 +13,7 @@ const fixtures = Array.from({length: 2000}, (_, index) => path.resolve(temporary function createFixtures() { for (const fixture of fixtures) { - makeDir.sync(path.resolve(temporaryDirectoryPath, fixture)); + fs.mkdirSync(path.resolve(temporaryDirectoryPath, fixture), {recursive: true}); } } diff --git a/index.js b/index.js index dd5b8d0..1f31596 100644 --- a/index.js +++ b/index.js @@ -1,32 +1,13 @@ -import {promisify} from 'node:util'; +import fs from 'node:fs'; +import fsPromises from 'node:fs/promises'; import path from 'node:path'; import process from 'node:process'; import {globby, globbySync} from 'globby'; import isGlob from 'is-glob'; -import slash from 'slash'; -import gracefulFs from 'graceful-fs'; import isPathCwd from 'is-path-cwd'; import isPathInside from 'is-path-inside'; -import rimraf from 'rimraf'; import pMap from 'p-map'; - -const rimrafP = promisify(rimraf); - -const rimrafOptions = { - glob: false, - unlink: gracefulFs.unlink, - unlinkSync: gracefulFs.unlinkSync, - chmod: gracefulFs.chmod, - chmodSync: gracefulFs.chmodSync, - stat: gracefulFs.stat, - statSync: gracefulFs.statSync, - lstat: gracefulFs.lstat, - lstatSync: gracefulFs.lstatSync, - rmdir: gracefulFs.rmdir, - rmdirSync: gracefulFs.rmdirSync, - readdir: gracefulFs.readdir, - readdirSync: gracefulFs.readdirSync, -}; +import slash from 'slash'; function safeCheck(file, cwd) { if (isPathCwd(file)) { @@ -84,7 +65,7 @@ export async function deleteAsync(patterns, {force, dryRun, cwd = process.cwd(), } if (!dryRun) { - await rimrafP(file, rimrafOptions); + await fsPromises.rm(file, {recursive: true, force: true}); } deletedCount += 1; @@ -128,7 +109,7 @@ export function deleteSync(patterns, {force, dryRun, cwd = process.cwd(), ...opt } if (!dryRun) { - rimraf.sync(file, rimrafOptions); + fs.rmSync(file, {recursive: true, force: true}); } return file; diff --git a/package.json b/package.json index d4e8d25..0e31f7e 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "exports": "./index.js", "types": "./index.d.ts", "engines": { - "node": ">=14.16" + "node": ">=18" }, "scripts": { "test": "xo && ava && tsd", @@ -49,30 +49,23 @@ "filesystem" ], "dependencies": { - "globby": "^13.1.2", - "graceful-fs": "^4.2.10", + "globby": "^14.0.1", "is-glob": "^4.0.3", "is-path-cwd": "^3.0.0", "is-path-inside": "^4.0.0", - "p-map": "^5.5.0", - "rimraf": "^3.0.2", - "slash": "^4.0.0" + "p-map": "^7.0.2", + "rimraf": "^5.0.7", + "slash": "^5.1.0" }, "devDependencies": { - "ava": "^4.3.1", + "ava": "^6.1.3", "benchmark": "^2.1.4", - "make-dir": "^3.1.0", - "tempy": "^3.0.0", - "tsd": "^0.22.0", - "xo": "^0.56.0" + "tempy": "^3.1.0", + "tsd": "^0.31.0", + "xo": "^0.58.0" }, "ava": { "serial": true, "workerThreads": false - }, - "xo": { - "rules": { - "unicorn/prefer-string-replace-all": "off" - } } } diff --git a/test.js b/test.js index a2a5016..98b1c48 100644 --- a/test.js +++ b/test.js @@ -1,10 +1,9 @@ -import {fileURLToPath} from 'node:url'; import fs from 'node:fs'; import path from 'node:path'; import process from 'node:process'; +import {fileURLToPath} from 'node:url'; import test from 'ava'; import {temporaryDirectory} from 'tempy'; -import makeDir from 'make-dir'; import {deleteAsync, deleteSync} from './index.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -34,7 +33,7 @@ test.beforeEach(t => { t.context.tmp = temporaryDirectory(); for (const fixture of fixtures) { - makeDir.sync(path.join(t.context.tmp, fixture)); + fs.mkdirSync(path.join(t.context.tmp, fixture), {recursive: true}); } }); @@ -125,7 +124,7 @@ test('does not throw EINVAL - async', async t => { let count = 0; while (count !== totalAttempts) { - makeDir.sync(nestedFile); + fs.mkdirSync(nestedFile, {recursive: true}); // eslint-disable-next-line no-await-in-loop const removed = await deleteAsync('**/*', { @@ -160,7 +159,7 @@ test('does not throw EINVAL - sync', t => { let count = 0; while (count !== totalAttempts) { - makeDir.sync(nestedFile); + fs.mkdirSync(nestedFile, {recursive: true}); const removed = deleteSync('**/*', { cwd: t.context.tmp, @@ -337,7 +336,7 @@ test('windows can pass absolute paths with "\\" - sync', t => { test('windows can pass relative paths with "\\" - async', async t => { const nestedFile = path.resolve(t.context.tmp, 'a/b/c/nested.js'); - makeDir.sync(nestedFile); + fs.mkdirSync(nestedFile, {recursive: true}); const removeFiles = await deleteAsync([nestedFile], {cwd: t.context.tmp, dryRun: true}); @@ -346,7 +345,7 @@ test('windows can pass relative paths with "\\" - async', async t => { test('windows can pass relative paths with "\\" - sync', t => { const nestedFile = path.resolve(t.context.tmp, 'a/b/c/nested.js'); - makeDir.sync(nestedFile); + fs.mkdirSync(nestedFile, {recursive: true}); const removeFiles = deleteSync([nestedFile], {cwd: t.context.tmp, dryRun: true}); @@ -356,9 +355,11 @@ test('windows can pass relative paths with "\\" - sync', t => { test('onProgress option - progress of non-existent file', async t => { let report; - await deleteAsync('non-existent-directory', {onProgress(event) { - report = event; - }}); + await deleteAsync('non-existent-directory', { + onProgress(event) { + report = event; + }, + }); t.deepEqual(report, { totalCount: 0, @@ -370,9 +371,11 @@ test('onProgress option - progress of non-existent file', async t => { test('onProgress option - progress of single file', async t => { let report; - await deleteAsync(t.context.tmp, {cwd: __dirname, force: true, onProgress(event) { - report = event; - }}); + await deleteAsync(t.context.tmp, { + cwd: __dirname, force: true, onProgress(event) { + report = event; + }, + }); t.deepEqual(report, { totalCount: 1, @@ -385,7 +388,7 @@ test('onProgress option - progress of single file', async t => { test('onProgress option - progress of multiple files', async t => { const reports = []; - const sourcePath = process.platform === 'win32' ? path.resolve(`${t.context.tmp}/*`).replace(/\\/g, '/') : `${t.context.tmp}/*`; + const sourcePath = process.platform === 'win32' ? path.resolve(`${t.context.tmp}/*`).replaceAll('\\', '/') : `${t.context.tmp}/*`; await deleteAsync(sourcePath, { cwd: __dirname,