import fs from 'node:fs';
import { ManifestParser } from './parser.js';

/**
 * @see {@link ManifestLoaderInterface}
 */ class ManifestLoader {
    /**
     * @inheritdoc
     * @throws Error if manifest file is not found.
     * @throws Error If manifest data is invalid.
     */ load(path) {
        const data = fs.readFileSync(path, {
            encoding: 'utf-8'
        });
        return this.parser.parse(data);
    }
    /**
     * Create new instance of {@link ManifestLoader}.
     *
     * @param parser {@link ManifestParser}.
     */ constructor(parser = new ManifestParser()){
        this.parser = parser;
    }
}

export { ManifestLoader };
