Skip to content

Commit

Permalink
Use correct flags for rmdir/mkdir functions (#2886)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jan 18, 2021
1 parent 34ddf38 commit f0502f9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 24 deletions.
8 changes: 4 additions & 4 deletions benchmark/benchmark.js
Expand Up @@ -31,10 +31,10 @@ function exec(command, options = {}) {
// and returns path to its 'dist' directory.
function prepareBenchmarkProjects(revisionList) {
const tmpDir = path.join(os.tmpdir(), 'graphql-js-benchmark');
fs.mkdirSync(tmpDir, { recursive: true });
fs.mkdirSync(tmpDir);

const setupDir = path.join(tmpDir, 'setup');
fs.rmdirSync(setupDir, { recursive: true });
fs.rmdirSync(setupDir, { recursive: true, force: true });
fs.mkdirSync(setupDir);

return revisionList.map((revision) => {
Expand Down Expand Up @@ -72,12 +72,12 @@ function prepareBenchmarkProjects(revisionList) {
}

const repoDir = path.join(tmpDir, hash);
fs.rmdirSync(repoDir, { recursive: true });
fs.rmdirSync(repoDir, { recursive: true, force: true });
fs.mkdirSync(repoDir);
exec(`git archive "${hash}" | tar -xC "${repoDir}"`);
exec('npm --quiet ci', { cwd: repoDir });
fs.renameSync(buildNPMArchive(repoDir), archivePath);
fs.rmdirSync(repoDir, { recursive: true });
fs.rmdirSync(repoDir, { recursive: true, force: true });
return archivePath;
}

Expand Down
2 changes: 1 addition & 1 deletion integrationTests/integration-test.js
Expand Up @@ -17,7 +17,7 @@ function exec(command, options = {}) {

describe('Integration Tests', () => {
const tmpDir = path.join(os.tmpdir(), 'graphql-js-integrationTmp');
fs.rmdirSync(tmpDir, { recursive: true });
fs.rmdirSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir);

const distDir = path.resolve('./npmDist');
Expand Down
4 changes: 2 additions & 2 deletions resources/build-deno.js
Expand Up @@ -5,10 +5,10 @@ const path = require('path');

const babel = require('@babel/core');

const { rmdirRecursive, readdirRecursive, showDirStats } = require('./utils');
const { readdirRecursive, showDirStats } = require('./utils');

if (require.main === module) {
rmdirRecursive('./denoDist');
fs.rmdirSync('./denoDist', { recursive: true, force: true });
fs.mkdirSync('./denoDist');

const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ });
Expand Down
4 changes: 2 additions & 2 deletions resources/build-npm.js
Expand Up @@ -6,10 +6,10 @@ const assert = require('assert');

const babel = require('@babel/core');

const { rmdirRecursive, readdirRecursive, showDirStats } = require('./utils');
const { readdirRecursive, showDirStats } = require('./utils');

if (require.main === module) {
rmdirRecursive('./npmDist');
fs.rmdirSync('./npmDist', { recursive: true, force: true });
fs.mkdirSync('./npmDist');

const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ });
Expand Down
15 changes: 0 additions & 15 deletions resources/utils.js
Expand Up @@ -32,20 +32,6 @@ function removeTrailingNewLine(str) {
return str.split('\n').slice(0, -1).join('\n');
}

function rmdirRecursive(dirPath) {
if (fs.existsSync(dirPath)) {
for (const dirent of fs.readdirSync(dirPath, { withFileTypes: true })) {
const fullPath = path.join(dirPath, dirent.name);
if (dirent.isDirectory()) {
rmdirRecursive(fullPath);
} else {
fs.unlinkSync(fullPath);
}
}
fs.rmdirSync(dirPath);
}
}

function readdirRecursive(dirPath, opts = {}) {
const { ignoreDir } = opts;
const result = [];
Expand Down Expand Up @@ -116,7 +102,6 @@ function showDirStats(dirPath) {
module.exports = {
exec,
execAsync,
rmdirRecursive,
readdirRecursive,
showDirStats,
};

0 comments on commit f0502f9

Please sign in to comment.