2 * @fileoverview `ConfigDependency` class.
4 * `ConfigDependency` class expresses a loaded parser or plugin.
6 * If the parser or plugin was loaded successfully, it has `definition` property
7 * and `filePath` property. Otherwise, it has `error` property.
9 * When `JSON.stringify()` converted a `ConfigDependency` object to a JSON, it
10 * omits `definition` property.
12 * `ConfigArrayFactory` creates `ConfigDependency` objects when it loads parsers
15 * @author Toru Nagashima <https://github.com/mysticatea>
19 const util = require("util");
22 * The class is to store parsers or plugins.
23 * This class hides the loaded object from `JSON.stringify()` and `console.log`.
26 class ConfigDependency {
29 * Initialize this instance.
30 * @param {Object} data The dependency data.
31 * @param {T} [data.definition] The dependency if the loading succeeded.
32 * @param {Error} [data.error] The error object if the loading failed.
33 * @param {string} [data.filePath] The actual path to the dependency if the loading succeeded.
34 * @param {string} data.id The ID of this dependency.
35 * @param {string} data.importerName The name of the config file which loads this dependency.
36 * @param {string} data.importerPath The path to the config file which loads this dependency.
48 * The loaded dependency if the loading succeeded.
51 this.definition = definition;
54 * The error object if the loading failed.
60 * The loaded dependency if the loading succeeded.
63 this.filePath = filePath;
66 * The ID of this dependency.
72 * The name of the config file which loads this dependency.
75 this.importerName = importerName;
78 * The path to the config file which loads this dependency.
81 this.importerPath = importerPath;
84 // eslint-disable-next-line jsdoc/require-description
86 * @returns {Object} a JSON compatible object.
89 const obj = this[util.inspect.custom]();
91 // Display `error.message` (`Error#message` is unenumerable).
92 if (obj.error instanceof Error) {
93 obj.error = { ...obj.error, message: obj.error.message };
99 // eslint-disable-next-line jsdoc/require-description
101 * @returns {Object} an object to display by `console.log()`.
103 [util.inspect.custom]() {
105 definition: _ignore, // eslint-disable-line no-unused-vars
113 /** @typedef {ConfigDependency<import("../../shared/types").Parser>} DependentParser */
114 /** @typedef {ConfigDependency<import("../../shared/types").Plugin>} DependentPlugin */
116 module.exports = { ConfigDependency };