Skip to content

Commit 75dcf8c

Browse files
refactor: replace fs-extra with newer fs built-ins (#5284)
* 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 [email protected], 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 <[email protected]>
1 parent 664e1f4 commit 75dcf8c

File tree

5 files changed

+10
-36
lines changed

5 files changed

+10
-36
lines changed

.github/workflows/mocha.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
with:
6767
os: 'ubuntu-latest,windows-latest'
6868
# The 22.11.0 is instead of 22 per https://github.com/mochajs/mocha/issues/5278
69-
node-versions: '14,16,18,20,22.11.0'
69+
node-versions: '18,20,22.11.0'
7070
npm-script: test-node:${{ matrix.test-part }}
7171
coverage: ${{ matrix.coverage }}
7272

package-lock.json

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
"cross-env": "^7.0.2",
130130
"eslint": "^8.56.0",
131131
"fail-on-errors-webpack-plugin": "^3.0.0",
132-
"fs-extra": "^10.0.0",
133132
"globals": "^13.24.0",
134133
"installed-check": "^9.3.0",
135134
"jsdoc": "^3.6.7",

test/integration/helpers.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
const escapeRegExp = require('escape-string-regexp');
44
const os = require('os');
5-
const fs = require('fs-extra');
5+
const fs = require('fs');
6+
const fsP = require('fs/promises');
67
const {format} = require('util');
78
const path = require('path');
89
const Base = require('../../lib/reporters/base');
@@ -487,7 +488,7 @@ const touchRef = new Date();
487488
* @param {string} filepath - Path to file
488489
*/
489490
function touchFile(filepath) {
490-
fs.ensureDirSync(path.dirname(filepath));
491+
fs.mkdirSync(path.dirname(filepath), { recursive: true });
491492
try {
492493
fs.utimesSync(filepath, touchRef, touchRef);
493494
} catch (e) {
@@ -519,21 +520,21 @@ function replaceFileContents(filepath, pattern, replacement) {
519520
*/
520521
function copyFixture(fixtureName, dest) {
521522
const fixtureSource = resolveFixturePath(fixtureName);
522-
fs.ensureDirSync(path.dirname(dest));
523-
fs.copySync(fixtureSource, dest);
523+
fs.mkdirSync(path.dirname(dest), { recursive: true });
524+
fs.cpSync(fixtureSource, dest);
524525
}
525526

526527
/**
527528
* Creates a temporary directory
528529
* @returns {Promise<CreateTempDirResult>} Temp dir path and cleanup function
529530
*/
530531
const createTempDir = async () => {
531-
const dirpath = await fs.mkdtemp(path.join(os.tmpdir(), 'mocha-'));
532+
const dirpath = await fsP.mkdtemp(path.join(os.tmpdir(), 'mocha-'));
532533
return {
533534
dirpath,
534535
removeTempDir: async () => {
535536
if (!process.env.MOCHA_TEST_KEEP_TEMP_DIRS) {
536-
return fs.remove(dirpath);
537+
return fs.rmSync(dirpath, { recursive: true, force: true });
537538
}
538539
}
539540
};

test/integration/options/watch.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const fs = require('fs-extra');
3+
const fs = require('fs');
44
const path = require('path');
55
const {
66
copyFixture,
@@ -131,7 +131,7 @@ describe('--watch', function () {
131131
[testFile, '--watch-files', 'lib/**/*.xyz'],
132132
tempDir,
133133
() => {
134-
fs.removeSync(watchedFile);
134+
fs.rmSync(watchedFile, { recursive: true, force: true });
135135
}
136136
).then(results => {
137137
expect(results, 'to have length', 2);

0 commit comments

Comments
 (0)