Skip to content

Commit 2aea166

Browse files
committed
Add ConfigResult type export
Co-authored-by: JounQin <admin@1stg.me> Closes GH-76.
1 parent 992aa2f commit 2aea166

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
coverage/
22
test/fixtures/malformed-rc-yaml/.foorc.yaml
3+
test/fixtures/malformed-package-file/one.txt
4+
test/fixtures/malformed-package-file/package.json
35
*.md

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
2+
* @typedef {import('./lib/configuration.js').ConfigResult} ConfigResult
23
* @typedef {import('./lib/file-set.js').Completer} Completer
34
* @typedef {import('./lib/index.js').Callback} Callback
45
* @typedef {import('./lib/index.js').ConfigTransform} ConfigTransform

lib/configuration.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@
1010
* Callback called when loading a config.
1111
* @param {Error | undefined} error
1212
* Error if something happened.
13-
* @param {Result | undefined} [result]
13+
* @param {ConfigResult | undefined} [result]
1414
* Result.
1515
* @returns {undefined}
1616
* Nothing.
1717
*
18+
* @typedef ConfigResult
19+
* Resolved configuration.
20+
* @property {string | undefined} filePath
21+
* File path of found configuration.
22+
* @property {Array<PluginTuple>} plugins
23+
* Resolved plugins.
24+
* @property {Settings} settings
25+
* Resolved settings.
26+
*
1827
* @callback ConfigTransform
1928
* Transform arbitrary configs to our format.
2029
* @param {any} config
@@ -70,16 +79,6 @@
7079
* List of plugins and presets (optional).
7180
* @property {Settings | undefined} [settings]
7281
* Shared settings for parsers and compilers (optional).
73-
*
74-
* @typedef Result
75-
* Resolved configuration.
76-
* @property {string | undefined} filePath
77-
* File path of found configuration.
78-
* @property {Settings} settings
79-
* Resolved settings.
80-
* @property {Array<PluginTuple>} plugins
81-
* Resolved plugins.
82-
*
8382
*/
8483

8584
import assert from 'node:assert/strict'
@@ -184,7 +183,7 @@ export class Configuration {
184183
this.given = {plugins: options.plugins, settings: options.settings}
185184
this.create = this.create.bind(this)
186185

187-
/** @type {FindUp<Result>} */
186+
/** @type {FindUp<ConfigResult>} */
188187
this.findUp = new FindUp({
189188
create: this.create,
190189
cwd: options.cwd,
@@ -228,12 +227,12 @@ export class Configuration {
228227
* File value.
229228
* @param {string | undefined} filePath
230229
* File path.
231-
* @returns {Promise<Result | undefined>}
230+
* @returns {Promise<ConfigResult | undefined>}
232231
* Result.
233232
*/
234233
async create(buf, filePath) {
235234
const options = {cwd: this.cwd, prefix: this.pluginPrefix}
236-
/** @type {Result} */
235+
/** @type {ConfigResult} */
237236
const result = {filePath: undefined, plugins: [], settings: {}}
238237
const extname = filePath ? path.extname(filePath) : undefined
239238
const loader =
@@ -283,7 +282,7 @@ export class Configuration {
283282
*/
284283
async function loadScriptOrModule(_, filePath) {
285284
// Assume it’s a config.
286-
const result = /** @type {Result} */ (
285+
const result = /** @type {ConfigResult} */ (
287286
await loadFromAbsolutePath(pathToFileURL(filePath).href, this.cwd)
288287
)
289288
return result
@@ -305,7 +304,7 @@ async function loadJson(buf, filePath) {
305304
const data = parseJson(String(buf), filePath)
306305

307306
// Assume it’s a config.
308-
const result = /** @type {Result} */ (
307+
const result = /** @type {ConfigResult} */ (
309308
this.packageField && path.basename(filePath) === 'package.json'
310309
? data[this.packageField]
311310
: data
@@ -315,7 +314,7 @@ async function loadJson(buf, filePath) {
315314
}
316315

317316
/**
318-
* @param {Result} target
317+
* @param {ConfigResult} target
319318
* Result to merge into.
320319
* @param {PresetSupportingSpecifiers} raw
321320
* Raw found config.

readme.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* [`Configuration`](#configuration)
2222
* [`Completer`](#completer)
2323
* [`Callback`](#callback)
24+
* [`ConfigResult`](#configresult)
2425
* [`ConfigTransform`](#configtransform)
2526
* [`Context`](#context)
2627
* [`FileSet`](#fileset)
@@ -181,7 +182,7 @@ Exposed to build more complex integrations.
181182

182183
###### Fields
183184

184-
* `load(string, (Error?[, Result?]): undefined): undefined`
185+
* `load(string, (Error?[, ConfigResult?]): undefined): undefined`
185186
— get the config for a file
186187

187188
### `Completer`
@@ -220,6 +221,20 @@ incorrect configuration), or a status code and the processing context.
220221
221222
Nothing (`undefined`).
222223
224+
### `ConfigResult`
225+
226+
Resolved configuration from [`Configuration`][api-configuration] (TypeScript
227+
type).
228+
229+
###### Fields
230+
231+
* `filePath` (`string`)
232+
— file path of found configuration
233+
* `plugins` (`Array<PluginTuple>` from `unified`)
234+
— resolved plugins
235+
* `settings` ([`Settings` from `unified`][unified-settings])
236+
— resolved settings
237+
223238
### `ConfigTransform`
224239
225240
Transform arbitrary configs to our format (TypeScript type).
@@ -1521,6 +1536,7 @@ This package is fully typed with [TypeScript][].
15211536
It exports the additional types
15221537
[`Completer`][api-completer],
15231538
[`Callback`][api-callback],
1539+
[`ConfigResult`][api-config-result],
15241540
[`ConfigTransform`][api-config-transform],
15251541
[`Context`][api-context],
15261542
[`FileSet`][api-file-set],
@@ -1659,6 +1675,8 @@ abide by its terms.
16591675
16601676
[api-callback]: #callback
16611677
1678+
[api-config-result]: #configresult
1679+
16621680
[api-config-transform]: #configtransform
16631681
16641682
[api-context]: #context

0 commit comments

Comments
 (0)