Skip to content

Commit

Permalink
Fix to not create unneeded vfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 1, 2021
1 parent 96e3f0c commit b166c69
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/util/resolve-file-and-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {md} from './extnames.js'
* @returns {{file: VFile, options: ProcessorOptions}}
*/
export function resolveFileAndOptions(vfileCompatible, options) {
const file = new VFile(vfileCompatible)
const file = looksLikeAVFile(vfileCompatible)
? vfileCompatible
: new VFile(vfileCompatible)
const {format, ...rest} = options || {}
return {
file,
Expand All @@ -31,3 +33,16 @@ export function resolveFileAndOptions(vfileCompatible, options) {
}
}
}

/**
* @param {VFileCompatible} [value]
* @returns {value is VFile}
*/
function looksLikeAVFile(value) {
return Boolean(
value &&
typeof value === 'object' &&
'message' in value &&
'messages' in value
)
}

0 comments on commit b166c69

Please sign in to comment.