Skip to content

Commit

Permalink
fix(node-16): avoid deprecation warnings of fs.rmdirSync (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Sep 11, 2021
1 parent fba1827 commit 3a84361
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 33 deletions.
52 changes: 24 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: |
yarn install
yarn build
Expand All @@ -37,7 +37,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.11, 14, 16]
node-version: [12.11, 14, 16.8]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -49,10 +49,10 @@ jobs:
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: |
yarn install
yarn build
Expand All @@ -62,7 +62,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.11, 14, 16]
node-version: [12.11, 14, 16.8]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -74,22 +74,20 @@ jobs:
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: |
yarn install
yarn build
- run: yarn test:integration
env:
NODE_NO_WARNINGS: 1

smoke-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.11, 14, 16]
node-version: [12.11, 14, 16.8]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -101,22 +99,20 @@ jobs:
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: |
yarn install
yarn build
- run: yarn test:smoke
env:
NODE_NO_WARNINGS: 1

repositories-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.11, 14, 16]
node-version: [12.11, 14, 16.8]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -128,10 +124,10 @@ jobs:
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install
name: Install eslint-remote-tester
- run: yarn install
Expand Down
11 changes: 11 additions & 0 deletions lib/file-client/file-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import fs from 'fs';

export function removeDirectorySync(dir: string): void {
// Available in Node 16
if (fs.rmSync != null && typeof fs.rmSync === 'function') {
return fs.rmSync(dir, { recursive: true });
}

// Fallback to older Node versions
return fs.rmdirSync(dir, { recursive: true });
}
3 changes: 2 additions & 1 deletion lib/file-client/repository-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs';
import simpleGit from 'simple-git';

import { removeDirectorySync } from './file-utils';
import { CACHE_LOCATION, URL } from './file-constants';
import config from '@config';

Expand Down Expand Up @@ -69,7 +70,7 @@ export async function removeCachedRepository(
const repoLocation = `${CACHE_LOCATION}/${repository}`;

if (fs.existsSync(repoLocation)) {
fs.rmdirSync(repoLocation, { recursive: true });
removeDirectorySync(repoLocation);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/file-client/results-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isMainThread } from 'worker_threads';
import objectHash from 'object-hash';

import ResultsStore from './results-store';
import { removeDirectorySync } from './file-utils';
import {
CACHE_LOCATION,
RESULTS_COMPARE_LOCATION,
Expand All @@ -27,7 +28,7 @@ const RESULT_EXTENSION = RESULT_PARSER_TO_EXTENSION[config.resultParser];
export function prepareResultsDirectory(): void {
if (isMainThread) {
if (fs.existsSync(RESULTS_LOCATION)) {
fs.rmdirSync(RESULTS_LOCATION, { recursive: true });
removeDirectorySync(RESULTS_LOCATION);
}

fs.mkdirSync(RESULTS_LOCATION);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/file-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Result,
RESULT_PARSER_TO_COMPARE_TEMPLATE,
} from '@file-client/result-templates';
import { removeDirectorySync } from '@file-client/file-utils';
import { mockConfig } from '__mocks__/@config';
import { getComparisonResults } from '../utils';

Expand All @@ -35,7 +36,7 @@ const readComparisonCache = () =>

function removeResultsDirectory(): void {
if (resultsDirectoryExists()) {
fs.rmdirSync(RESULTS_LOCATION, { recursive: true });
removeDirectorySync(RESULTS_LOCATION);
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/unit/repository-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getCacheStatus,
removeCachedRepository,
} from '@file-client/repository-client';
import { removeDirectorySync } from '@file-client/file-utils';
import SimpleGit from '__mocks__/simple-git';

const EXPECTED_CACHE = './node_modules/.cache-eslint-remote-tester';
Expand All @@ -16,7 +17,7 @@ describe('repository-client', () => {

// Clear previous cache
if (fs.existsSync(EXPECTED_CACHE)) {
fs.rmdirSync(EXPECTED_CACHE, { recursive: true });
removeDirectorySync(EXPECTED_CACHE);
}

// Initialize client
Expand Down
3 changes: 2 additions & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
RESULTS_COMPARE_LOCATION,
} from '@file-client';
import { ComparisonTypes } from '@file-client/result-templates';
import { removeDirectorySync } from '@file-client/file-utils';
import { Config, ConfigToValidate } from '@config/types';

declare const console: { log: jest.Mock; error: (...args: any) => void };
Expand Down Expand Up @@ -166,7 +167,7 @@ function parsePtyOutput(output: string[]): string[] {
*/
export function clearRepositoryCache(): void {
if (fs.existsSync(CACHE_LOCATION)) {
fs.rmdirSync(CACHE_LOCATION, { recursive: true });
removeDirectorySync(CACHE_LOCATION);
}
}

Expand Down

0 comments on commit 3a84361

Please sign in to comment.