#13317 Not load unintended files

This commit is contained in:
DanieleAurilio 2022-06-19 15:14:54 +02:00
parent 63da344269
commit 8960bdbfd8
2 changed files with 3 additions and 5 deletions

View File

@ -4,12 +4,14 @@ const path = require('path');
const fs = require('fs');
const loadFile = require('./load-config-file');
const VALID_EXTENSIONS = ['.js', '.json', '.ts'];
module.exports = dir => {
if (!fs.existsSync(dir)) return {};
return fs
.readdirSync(dir, { withFileTypes: true })
.filter(file => file.isFile())
.filter(file => file.isFile() && VALID_EXTENSIONS.includes(path.extname(file.name)))
.reduce((acc, file) => {
const key = path.basename(file.name, path.extname(file.name));

View File

@ -30,10 +30,6 @@ const loadJSONFile = file => {
const loadFile = file => {
const ext = path.extname(file);
if(ext !== '.js' && ext !== '.json' && ext !== '.ts') {
throw new Error(`Remove an invalid config file: ${file}`);
}
switch (ext) {
case '.js':
return loadJsFile(file);