Skip to content

Commit

Permalink
refactor: use fs-extra.removeSync
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Dec 26, 2021
1 parent 82e5329 commit 8461d20
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 29 deletions.
53 changes: 41 additions & 12 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -88,6 +88,7 @@
"eslint-plugin-prettier": "^4.0.0",
"execa": "^5.1.1",
"fixturify": "^2.1.1",
"fs-extra": "^10.0.0",
"hash.js": "^1.1.7",
"husky": "^7.0.4",
"is-reference": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions scripts/perf-init.js
Expand Up @@ -3,7 +3,7 @@
const { accessSync, constants } = require('fs');
const path = require('path');
const execa = require('execa');
const sander = require('sander');
const { removeSync } = require('fs-extra');
const repoWithBranch = process.argv[2];

const TARGET_DIR = path.resolve(__dirname, '..', 'perf');
Expand All @@ -17,7 +17,7 @@ if (process.argv.length !== 3 || !VALID_REPO.test(repoWithBranch)) {
process.exit(1);
}
console.error(`Cleaning up '${TARGET_DIR}'...`);
sander.rimrafSync(TARGET_DIR);
removeSync(TARGET_DIR);

const [, repo, , branch] = VALID_REPO.exec(repoWithBranch);

Expand Down
6 changes: 3 additions & 3 deletions test/hooks/index.js
@@ -1,7 +1,7 @@
const assert = require('assert');
const { readdirSync } = require('fs');
const path = require('path');
const sander = require('sander');
const { removeSync } = require('fs-extra');
const rollup = require('../../dist/rollup.js');
const { loader } = require('../utils.js');

Expand Down Expand Up @@ -36,7 +36,7 @@ describe('hooks', () => {
.then(() => {
const fileNames = readdirSync(TEMP_DIR).sort();
assert.deepStrictEqual(fileNames, ['chunk.js', 'input.js']);
return sander.rimraf(TEMP_DIR);
return removeSync(TEMP_DIR);
}));

it('supports buildStart and buildEnd hooks', () => {
Expand Down Expand Up @@ -575,7 +575,7 @@ describe('hooks', () => {
.then(bundle => bundle.write({ format: 'es', file }))
.then(() => {
assert.strictEqual(callCount, 1);
return sander.rimraf(TEMP_DIR);
return removeSync(TEMP_DIR);
});
});

Expand Down
6 changes: 3 additions & 3 deletions test/utils.js
Expand Up @@ -2,7 +2,7 @@ const assert = require('assert');
const { readdirSync, unlinkSync } = require('fs');
const path = require('path');
const fixturify = require('fixturify');
const sander = require('sander');
const { removeSync } = require('fs-extra');

exports.compareError = compareError;
exports.compareWarnings = compareWarnings;
Expand Down Expand Up @@ -133,7 +133,7 @@ function runTestsInDir(dir, runTest) {
loadConfigAndRunTest(dir, runTest);
} else if (fileNames.length === 0) {
console.warn(`Removing empty test directory ${dir}`);
sander.rmdirSync(dir);
removeSync(dir);
} else {
describe(path.basename(dir), () => {
fileNames
Expand All @@ -148,7 +148,7 @@ function getFileNamesAndRemoveOutput(dir) {
try {
return readdirSync(dir).filter(fileName => {
if (fileName === '_actual') {
sander.rimrafSync(path.join(dir, '_actual'));
removeSync(path.join(dir, '_actual'));
return false;
}
if (fileName === '_actual.js') {
Expand Down
17 changes: 8 additions & 9 deletions test/watch/index.js
Expand Up @@ -8,6 +8,7 @@ const {
writeFileSync
} = require('fs');
const path = require('path');
const { removeSync } = require('fs-extra');
const sander = require('sander');
const rollup = require('../../dist/rollup');

Expand All @@ -24,7 +25,7 @@ describe('rollup.watch', () => {

beforeEach(() => {
process.chdir(cwd);
return sander.rimraf('test/_tmp');
return removeSync('test/_tmp');
});

afterEach(() => {
Expand Down Expand Up @@ -1158,7 +1159,7 @@ describe('rollup.watch', () => {
'END',
() => {
[dynamicName, staticName, chunkName] = readdirSync('test/_tmp/output').sort();
sander.rimrafSync('test/_tmp/output');
removeSync('test/_tmp/output');

// this should only update the hash of that particular entry point
writeFileSync(
Expand All @@ -1171,10 +1172,9 @@ describe('rollup.watch', () => {
'BUNDLE_END',
'END',
() => {
const [newDynamicName, newStaticName, newChunkName] = sander
.readdirSync('test/_tmp/output')
.sort();
sander.rimrafSync('test/_tmp/output');
const [newDynamicName, newStaticName, newChunkName] =
readdirSync('test/_tmp/output').sort();
removeSync('test/_tmp/output');
assert.notEqual(newStaticName, staticName);
assert.strictEqual(newDynamicName, dynamicName);
assert.strictEqual(newChunkName, chunkName);
Expand All @@ -1188,9 +1188,8 @@ describe('rollup.watch', () => {
'BUNDLE_END',
'END',
() => {
const [newDynamicName, newStaticName, newChunkName] = sander
.readdirSync('test/_tmp/output')
.sort();
const [newDynamicName, newStaticName, newChunkName] =
readdirSync('test/_tmp/output').sort();
assert.notEqual(newStaticName, staticName);
assert.notEqual(newDynamicName, dynamicName);
assert.notEqual(newChunkName, chunkName);
Expand Down

0 comments on commit 8461d20

Please sign in to comment.