Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: export ConfigurationResult for reusing #76

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@types/parse-json": "^4.0.0",
"@types/ungap__structured-clone": "^0.3.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"prettier": "~3.0.0",
"remark": "^15.0.0",
"remark-cli": "^12.0.0",
"remark-gfm": "^4.0.0",
Expand Down
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
Loading