fix: handle unknown config property (#141)
This commit is contained in:
@@ -5,6 +5,9 @@ import ini from 'ini';
|
|||||||
import { fileExists } from './fs.js';
|
import { fileExists } from './fs.js';
|
||||||
import { KnownError } from './error.js';
|
import { KnownError } from './error.js';
|
||||||
|
|
||||||
|
const { hasOwnProperty } = Object.prototype;
|
||||||
|
const hasOwn = (object: unknown, key: PropertyKey) => hasOwnProperty.call(object, key);
|
||||||
|
|
||||||
const parseAssert = (
|
const parseAssert = (
|
||||||
name: string,
|
name: string,
|
||||||
condition: any,
|
condition: any,
|
||||||
@@ -51,16 +54,17 @@ export const getConfig = async (): Promise<ConfigType> => {
|
|||||||
const configString = await fs.readFile(configPath, 'utf8');
|
const configString = await fs.readFile(configPath, 'utf8');
|
||||||
const config = ini.parse(configString);
|
const config = ini.parse(configString);
|
||||||
for (const key of Object.keys(config)) {
|
for (const key of Object.keys(config)) {
|
||||||
const parsed = configParsers[key as ValidKeys](config[key]);
|
if (hasOwn(configParsers, key)) {
|
||||||
config[key as ValidKeys] = parsed;
|
const parsed = configParsers[key as ValidKeys](config[key]);
|
||||||
|
config[key as ValidKeys] = parsed;
|
||||||
|
} else {
|
||||||
|
console.warn(`\n⚠️ Unknown config property "${key}" found in ${configPath}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
const { hasOwnProperty } = Object.prototype;
|
|
||||||
const hasOwn = (object: unknown, key: PropertyKey) => hasOwnProperty.call(object, key);
|
|
||||||
|
|
||||||
export const setConfigs = async (
|
export const setConfigs = async (
|
||||||
keyValues: [key: string, value: string][],
|
keyValues: [key: string, value: string][],
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user