From c37e6d971d1bc590195d0c02c489105cc05ce6c4 Mon Sep 17 00:00:00 2001 From: JounQin Date: Tue, 5 Dec 2023 12:48:45 +0000 Subject: [PATCH] chore: export `ConfigurationResult` for reusing related https://github.com/mdx-js/eslint-mdx/pull/486/files/88932f183ddbe6f033a794d921fac08427a58ef5#diff-6c1bdf004fec1432e8c27da2092dbb688eccbf3693501fe64a28ab0e3ec4aa28 --- index.js | 1 + lib/configuration.js | 16 ++++++++-------- lib/ignore.js | 8 ++++---- readme.md | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 6d9d14b..39bd3ed 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ * @typedef {import('./lib/index.js').PresetSupportingSpecifiers} Preset * @typedef {import('./lib/index.js').ResolveFrom} ResolveFrom * @typedef {import('./lib/index.js').VFileReporter} VFileReporter + * @typedef {import('./lib/configuration.js').ConfigurationResult} ConfigurationResult */ // it’s mostly private, but useful for tools like `eslint-mdx`. diff --git a/lib/configuration.js b/lib/configuration.js index e40c711..e302bb9 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -10,7 +10,7 @@ * Callback called when loading a config. * @param {Error | undefined} error * Error if something happened. - * @param {Result | undefined} [result] + * @param {ConfigurationResult | undefined} [result] * Result. * @returns {undefined} * Nothing. @@ -71,7 +71,7 @@ * @property {Settings | undefined} [settings] * Shared settings for parsers and compilers (optional). * - * @typedef Result + * @typedef ConfigurationResult * Resolved configuration. * @property {string | undefined} filePath * File path of found configuration. @@ -184,7 +184,7 @@ export class Configuration { this.given = {plugins: options.plugins, settings: options.settings} this.create = this.create.bind(this) - /** @type {FindUp} */ + /** @type {FindUp} */ this.findUp = new FindUp({ create: this.create, cwd: options.cwd, @@ -228,12 +228,12 @@ export class Configuration { * File value. * @param {string | undefined} filePath * File path. - * @returns {Promise} + * @returns {Promise} * Result. */ async create(buf, filePath) { const options = {cwd: this.cwd, prefix: this.pluginPrefix} - /** @type {Result} */ + /** @type {ConfigurationResult} */ const result = {filePath: undefined, plugins: [], settings: {}} const extname = filePath ? path.extname(filePath) : undefined const loader = @@ -283,7 +283,7 @@ export class Configuration { */ async function loadScriptOrModule(_, filePath) { // Assume it’s a config. - const result = /** @type {Result} */ ( + const result = /** @type {ConfigurationResult} */ ( await loadFromAbsolutePath(pathToFileURL(filePath).href, this.cwd) ) return result @@ -305,7 +305,7 @@ async function loadJson(buf, filePath) { const data = parseJson(String(buf), filePath) // Assume it’s a config. - const result = /** @type {Result} */ ( + const result = /** @type {ConfigurationResult} */ ( this.packageField && path.basename(filePath) === 'package.json' ? data[this.packageField] : data @@ -315,7 +315,7 @@ async function loadJson(buf, filePath) { } /** - * @param {Result} target + * @param {ConfigurationResult} target * Result to merge into. * @param {PresetSupportingSpecifiers} raw * Raw found config. diff --git a/lib/ignore.js b/lib/ignore.js index 4c8b4b2..520a631 100644 --- a/lib/ignore.js +++ b/lib/ignore.js @@ -28,7 +28,7 @@ * @typedef {'cwd' | 'dir'} ResolveFrom * How to resolve. * - * @typedef {IgnorePackageClass & ResultFields} Result + * @typedef {IgnorePackageClass & ResultFields} ConfigurationResult * Result. * * @typedef ResultFields @@ -58,7 +58,7 @@ export class Ignore { /** @type {ResolveFrom | undefined} */ this.ignorePathResolveFrom = options.ignorePathResolveFrom - /** @type {FindUp} */ + /** @type {FindUp} */ this.findUp = new FindUp({ create, cwd: options.cwd, @@ -113,12 +113,12 @@ export class Ignore { * File value. * @param {string} filePath * File path. - * @returns {Result} + * @returns {ConfigurationResult} * Result. */ function create(buf, filePath) { // Cast so we can patch `filePath`. - const result = /** @type {Result} */ (ignore().add(String(buf))) + const result = /** @type {ConfigurationResult} */ (ignore().add(String(buf))) result.filePath = path.dirname(filePath) return result } diff --git a/readme.md b/readme.md index 1ff8025..f281a91 100644 --- a/readme.md +++ b/readme.md @@ -181,7 +181,7 @@ Exposed to build more complex integrations. ###### Fields -* `load(string, (Error?[, Result?]): undefined): undefined` +* `load(string, (Error?[, ConfigurationResult?]): undefined): undefined` — get the config for a file ### `Completer`