From 9f4c3446633852df50be6a515eb69704df5a1caf Mon Sep 17 00:00:00 2001 From: Eric Cornelissen Date: Fri, 6 Dec 2024 20:35:55 +0100 Subject: [PATCH] Replace fs-extra with newer fs built-ins This updates the codebase to remove two uses of fs-extra by newer fs built-in functions. The code changes are based on the implementation of fs-extra@10.1.0, which is the version of fs-extra recorded in the project's lockfile. In particular, for `watch.spec.js`, the changes are based on: https://github.com/jprichardson/node-fs-extra/blob/0220eac966d7d6b9a595d69b1242ab8a397fba7f/lib/remove/index.js#L15 and, also for `helper.js`, the changes are based on: https://github.com/jprichardson/node-fs-extra/blob/0220eac966d7d6b9a595d69b1242ab8a397fba7f/lib/mkdirs/make-dir.js#L23 --- package-lock.json | 26 -------------------------- package.json | 1 - test/integration/helpers.js | 13 +++++++------ test/integration/options/watch.spec.js | 4 ++-- 4 files changed, 9 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2e89d24349..0b27712172 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,6 @@ "cross-env": "^7.0.2", "eslint": "^8.56.0", "fail-on-errors-webpack-plugin": "^3.0.0", - "fs-extra": "^10.0.0", "globals": "^13.24.0", "installed-check": "^9.3.0", "jsdoc": "^3.6.7", @@ -6657,20 +6656,6 @@ "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", "dev": true }, - "node_modules/fs-extra": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", - "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -21380,17 +21365,6 @@ "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", "dev": true }, - "fs-extra": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", - "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", - "dev": true, - "requires": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - } - }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", diff --git a/package.json b/package.json index 7d0d4364a5..559ecde6ed 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,6 @@ "cross-env": "^7.0.2", "eslint": "^8.56.0", "fail-on-errors-webpack-plugin": "^3.0.0", - "fs-extra": "^10.0.0", "globals": "^13.24.0", "installed-check": "^9.3.0", "jsdoc": "^3.6.7", diff --git a/test/integration/helpers.js b/test/integration/helpers.js index 61c6ec01ca..de0d08742e 100644 --- a/test/integration/helpers.js +++ b/test/integration/helpers.js @@ -2,7 +2,8 @@ const escapeRegExp = require('escape-string-regexp'); const os = require('os'); -const fs = require('fs-extra'); +const fs = require('fs'); +const fsP = require('fs/promises'); const {format} = require('util'); const path = require('path'); const Base = require('../../lib/reporters/base'); @@ -487,7 +488,7 @@ const touchRef = new Date(); * @param {string} filepath - Path to file */ function touchFile(filepath) { - fs.ensureDirSync(path.dirname(filepath)); + fs.mkdirSync(path.dirname(filepath), { recursive: true }); try { fs.utimesSync(filepath, touchRef, touchRef); } catch (e) { @@ -519,8 +520,8 @@ function replaceFileContents(filepath, pattern, replacement) { */ function copyFixture(fixtureName, dest) { const fixtureSource = resolveFixturePath(fixtureName); - fs.ensureDirSync(path.dirname(dest)); - fs.copySync(fixtureSource, dest); + fs.mkdirSync(path.dirname(dest), { recursive: true }); + fs.cpSync(fixtureSource, dest); } /** @@ -528,12 +529,12 @@ function copyFixture(fixtureName, dest) { * @returns {Promise} Temp dir path and cleanup function */ const createTempDir = async () => { - const dirpath = await fs.mkdtemp(path.join(os.tmpdir(), 'mocha-')); + const dirpath = await fsP.mkdtemp(path.join(os.tmpdir(), 'mocha-')); return { dirpath, removeTempDir: async () => { if (!process.env.MOCHA_TEST_KEEP_TEMP_DIRS) { - return fs.remove(dirpath); + return fs.rmSync(dirpath, { recursive: true, force: true }); } } }; diff --git a/test/integration/options/watch.spec.js b/test/integration/options/watch.spec.js index 957b4938c3..b0391dfe3b 100644 --- a/test/integration/options/watch.spec.js +++ b/test/integration/options/watch.spec.js @@ -1,6 +1,6 @@ 'use strict'; -const fs = require('fs-extra'); +const fs = require('fs'); const path = require('path'); const { copyFixture, @@ -131,7 +131,7 @@ describe('--watch', function () { [testFile, '--watch-files', 'lib/**/*.xyz'], tempDir, () => { - fs.removeSync(watchedFile); + fs.rmSync(watchedFile, { recursive: true, force: true }); } ).then(results => { expect(results, 'to have length', 2);