Skip to content

Commit

Permalink
chore: export ConfigurationResult for reusing
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Dec 5, 2023
1 parent 992aa2f commit c37e6d9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
16 changes: 8 additions & 8 deletions lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -184,7 +184,7 @@ export class Configuration {
this.given = {plugins: options.plugins, settings: options.settings}
this.create = this.create.bind(this)

/** @type {FindUp<Result>} */
/** @type {FindUp<ConfigurationResult>} */
this.findUp = new FindUp({
create: this.create,
cwd: options.cwd,
Expand Down Expand Up @@ -228,12 +228,12 @@ export class Configuration {
* File value.
* @param {string | undefined} filePath
* File path.
* @returns {Promise<Result | undefined>}
* @returns {Promise<ConfigurationResult | undefined>}
* 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 =
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions lib/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @typedef {'cwd' | 'dir'} ResolveFrom
* How to resolve.
*
* @typedef {IgnorePackageClass & ResultFields} Result
* @typedef {IgnorePackageClass & ResultFields} ConfigurationResult
* Result.
*
* @typedef ResultFields
Expand Down Expand Up @@ -58,7 +58,7 @@ export class Ignore {
/** @type {ResolveFrom | undefined} */
this.ignorePathResolveFrom = options.ignorePathResolveFrom

/** @type {FindUp<Result>} */
/** @type {FindUp<ConfigurationResult>} */
this.findUp = new FindUp({
create,
cwd: options.cwd,
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit c37e6d9

Please sign in to comment.