Skip to content

Commit

Permalink
refactor: use fs.readdirSync
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Dec 26, 2021
1 parent 6b0a7b8 commit 82e5329
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions scripts/load-perf-config.js
@@ -1,12 +1,12 @@
const fs = require('fs');
const { accessSync, constants } = require('fs');
const path = require('path');
const rollup = require('../dist/rollup.js');

exports.targetDir = path.resolve(__dirname, '..', 'perf');
const configFile = path.resolve(exports.targetDir, 'rollup.config.js');

try {
fs.accessSync(configFile, fs.constants.R_OK);
accessSync(configFile, constants.R_OK);
} catch (e) {
console.error(
`No valid "rollup.config.js" in ${exports.targetDir}. Did you "npm run perf:init"?`
Expand Down
4 changes: 2 additions & 2 deletions scripts/perf-init.js
@@ -1,6 +1,6 @@
/* eslint-disable no-console */

const fs = require('fs');
const { accessSync, constants } = require('fs');
const path = require('path');
const execa = require('execa');
const sander = require('sander');
Expand Down Expand Up @@ -43,7 +43,7 @@ async function setupNewRepo(repo, branch) {
gitArgs.push(`https://github.com/${repo}.git`, TARGET_DIR);
await execWithOutput('git', gitArgs);
try {
fs.accessSync(path.resolve(TARGET_DIR, 'rollup.config.js'), fs.constants.R_OK);
accessSync(path.resolve(TARGET_DIR, 'rollup.config.js'), constants.R_OK);
} catch (e) {
throw new Error('The repository needs to have a file "rollup.config.js" at the top level.');
}
Expand Down
3 changes: 2 additions & 1 deletion test/hooks/index.js
@@ -1,4 +1,5 @@
const assert = require('assert');
const { readdirSync } = require('fs');
const path = require('path');
const sander = require('sander');
const rollup = require('../../dist/rollup.js');
Expand Down Expand Up @@ -33,7 +34,7 @@ describe('hooks', () => {
})
)
.then(() => {
const fileNames = sander.readdirSync(TEMP_DIR).sort();
const fileNames = readdirSync(TEMP_DIR).sort();
assert.deepStrictEqual(fileNames, ['chunk.js', 'input.js']);
return sander.rimraf(TEMP_DIR);
}));
Expand Down
8 changes: 4 additions & 4 deletions test/utils.js
@@ -1,5 +1,5 @@
const assert = require('assert');
const { unlinkSync } = require('fs');
const { readdirSync, unlinkSync } = require('fs');
const path = require('path');
const fixturify = require('fixturify');
const sander = require('sander');
Expand Down Expand Up @@ -120,8 +120,8 @@ function runSamples(samplesDir, runTest, onTeardown) {
if (onTeardown) {
afterEach(onTeardown);
}
sander
.readdirSync(samplesDir)

readdirSync(samplesDir)
.filter(name => name[0] !== '.')
.sort()
.forEach(fileName => runTestsInDir(path.join(samplesDir, fileName), runTest));
Expand All @@ -146,7 +146,7 @@ function runTestsInDir(dir, runTest) {

function getFileNamesAndRemoveOutput(dir) {
try {
return sander.readdirSync(dir).filter(fileName => {
return readdirSync(dir).filter(fileName => {
if (fileName === '_actual') {
sander.rimrafSync(path.join(dir, '_actual'));
return false;
Expand Down
11 changes: 9 additions & 2 deletions test/watch/index.js
@@ -1,5 +1,12 @@
const assert = require('assert');
const { existsSync, promises, readFileSync, unlinkSync, writeFileSync } = require('fs');
const {
existsSync,
promises,
readdirSync,
readFileSync,
unlinkSync,
writeFileSync
} = require('fs');
const path = require('path');
const sander = require('sander');
const rollup = require('../../dist/rollup');
Expand Down Expand Up @@ -1150,7 +1157,7 @@ describe('rollup.watch', () => {
'BUNDLE_END',
'END',
() => {
[dynamicName, staticName, chunkName] = sander.readdirSync('test/_tmp/output').sort();
[dynamicName, staticName, chunkName] = readdirSync('test/_tmp/output').sort();
sander.rimrafSync('test/_tmp/output');

// this should only update the hash of that particular entry point
Expand Down

0 comments on commit 82e5329

Please sign in to comment.