mirror of
https://github.com/strapi/strapi.git
synced 2025-12-04 19:13:20 +00:00
#13317 Not load unintended files
This commit is contained in:
parent
63da344269
commit
8960bdbfd8
@ -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));
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user