Skip to content

Commit

Permalink
refactor: replace fs-extra with newer fs built-ins (#5284)
Browse files Browse the repository at this point in the history
* 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

* Drop 14 and 16 in mocha.yml

---------

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
  • Loading branch information
ericcornelissen and JoshuaKGoldberg authored Jan 2, 2025
1 parent 664e1f4 commit 75dcf8c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mocha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
with:
os: 'ubuntu-latest,windows-latest'
# The 22.11.0 is instead of 22 per /~https://github.com/mochajs/mocha/issues/5278
node-versions: '14,16,18,20,22.11.0'
node-versions: '18,20,22.11.0'
npm-script: test-node:${{ matrix.test-part }}
coverage: ${{ matrix.coverage }}

Expand Down
26 changes: 0 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 7 additions & 6 deletions test/integration/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -519,21 +520,21 @@ 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);
}

/**
* Creates a temporary directory
* @returns {Promise<CreateTempDirResult>} 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 });
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions test/integration/options/watch.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const fs = require('fs-extra');
const fs = require('fs');
const path = require('path');
const {
copyFixture,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 75dcf8c

Please sign in to comment.