Skip to content

Commit ed36b9b

Browse files
committed
chore: remove touch as dev dependency
1 parent ee2b70e commit ed36b9b

File tree

3 files changed

+17
-59
lines changed

3 files changed

+17
-59
lines changed

package-lock.json

Lines changed: 0 additions & 48 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
@@ -132,7 +132,6 @@
132132
"sinon": "^9.0.3",
133133
"strip-ansi": "^6.0.0",
134134
"svgo": "^1.3.2",
135-
"touch": "^3.1.0",
136135
"unexpected": "^11.14.0",
137136
"unexpected-eventemitter": "^2.2.0",
138137
"unexpected-map": "^2.0.0",

test/integration/helpers.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
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 fsExtra = require('fs-extra');
67
const {format} = require('util');
78
const path = require('path');
89
const Base = require('../../lib/reporters/base');
910
const debug = require('debug')('mocha:test:integration:helpers');
10-
const touch = require('touch');
1111

1212
/**
1313
* Path to `mocha` executable
@@ -479,15 +479,22 @@ async function runMochaWatchJSONAsync(args, opts, change) {
479479
);
480480
}
481481

482+
const touchRef = new Date();
483+
482484
/**
483485
* Synchronously touch a file. Creates
484486
* the file and all its parent directories if necessary.
485487
*
486488
* @param {string} filepath - Path to file
487489
*/
488490
function touchFile(filepath) {
489-
fs.ensureDirSync(path.dirname(filepath));
490-
touch.sync(filepath);
491+
fsExtra.ensureDirSync(path.dirname(filepath));
492+
try {
493+
fs.utimesSync(filepath, touchRef, touchRef);
494+
} catch (e) {
495+
const fd = fs.openSync(filepath, 'a');
496+
fs.closeSync(fd);
497+
}
491498
}
492499

493500
/**
@@ -499,9 +506,9 @@ function touchFile(filepath) {
499506
* @param {string} replacement - Replacement
500507
*/
501508
function replaceFileContents(filepath, pattern, replacement) {
502-
const contents = fs.readFileSync(filepath, 'utf-8');
509+
const contents = fsExtra.readFileSync(filepath, 'utf-8');
503510
const newContents = contents.replace(pattern, replacement);
504-
fs.writeFileSync(filepath, newContents, 'utf-8');
511+
fsExtra.writeFileSync(filepath, newContents, 'utf-8');
505512
}
506513

507514
/**
@@ -513,21 +520,21 @@ function replaceFileContents(filepath, pattern, replacement) {
513520
*/
514521
function copyFixture(fixtureName, dest) {
515522
const fixtureSource = resolveFixturePath(fixtureName);
516-
fs.ensureDirSync(path.dirname(dest));
517-
fs.copySync(fixtureSource, dest);
523+
fsExtra.ensureDirSync(path.dirname(dest));
524+
fsExtra.copySync(fixtureSource, dest);
518525
}
519526

520527
/**
521528
* Creates a temporary directory
522529
* @returns {Promise<CreateTempDirResult>} Temp dir path and cleanup function
523530
*/
524531
const createTempDir = async () => {
525-
const dirpath = await fs.mkdtemp(path.join(os.tmpdir(), 'mocha-'));
532+
const dirpath = await fsExtra.mkdtemp(path.join(os.tmpdir(), 'mocha-'));
526533
return {
527534
dirpath,
528535
removeTempDir: async () => {
529536
if (!process.env.MOCHA_TEST_KEEP_TEMP_DIRS) {
530-
return fs.remove(dirpath);
537+
return fsExtra.remove(dirpath);
531538
}
532539
}
533540
};

0 commit comments

Comments
 (0)