fix: handle unknown config property (#141)

This commit is contained in:
hiroki osame
2023-03-09 04:02:00 -05:00
committed by GitHub
parent 5fe127d377
commit 4876e8d966

View File

@@ -5,6 +5,9 @@ import ini from 'ini';
import { fileExists } from './fs.js';
import { KnownError } from './error.js';
const { hasOwnProperty } = Object.prototype;
const hasOwn = (object: unknown, key: PropertyKey) => hasOwnProperty.call(object, key);
const parseAssert = (
name: string,
condition: any,
@@ -51,16 +54,17 @@ export const getConfig = async (): Promise<ConfigType> => {
const configString = await fs.readFile(configPath, 'utf8');
const config = ini.parse(configString);
for (const key of Object.keys(config)) {
const parsed = configParsers[key as ValidKeys](config[key]);
config[key as ValidKeys] = parsed;
if (hasOwn(configParsers, key)) {
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;
};
const { hasOwnProperty } = Object.prototype;
const hasOwn = (object: unknown, key: PropertyKey) => hasOwnProperty.call(object, key);
export const setConfigs = async (
keyValues: [key: string, value: string][],
) => {