import { promises as fs } from 'fs';
export default async function loadJsonFile(path) {
    try {
        const json = await fs.readFile(path, {
            encoding: 'utf-8',
        });
        return JSON.parse(json);
    }
    catch (error) {
        if (error instanceof SyntaxError) {
            throw new Error(`Invalid JSON in "${path}": ${error.message}`);
        }
        if (error &&
            typeof error === 'object' &&
            'code' in error &&
            error.code === 'ENOENT') {
            return undefined;
        }
        throw error;
    }
}
