Skip to content

Commit

Permalink
Use fs.accessSync instead of deprecated fs.existsSync
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrucs committed Nov 16, 2023
1 parent 045fc78 commit 64f6bb2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions frontend/src/services/getConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ const fs = require('fs');
const deepmerge = require('deepmerge');
const { getLocales } = require('./getLocales');

function isPathExists(path) {
try {
fs.accessSync(path, fs.R_OK);
return true;
} catch (err) {
return false;
}
}

function getFiles(dir, files = []) {
if (!fs.existsSync(dir)) {
if (!isPathExists(dir)) {
return files;
}
const fileList = fs.readdirSync(dir);
Expand All @@ -19,7 +28,7 @@ function getFiles(dir, files = []) {
}

const getContent = (path, parse) => {
if (fs.existsSync(path)) {
if (isPathExists(path)) {
const content = fs.readFileSync(path).toString();
return parse ? JSON.parse(content) : content;
}
Expand Down

0 comments on commit 64f6bb2

Please sign in to comment.