import { ParserPreset } from '@commitlint/types' ; function isObjectLike ( obj ) { return Boolean ( obj ) && typeof obj === 'object' ; } function isParserOptsFunction < T extends ParserPreset > ( obj ) { return typeof obj . parserOpts === 'function' ; } export async function loadParserOpts ( pendingParser ) { if ( ! pendingParser || typeof pendingParser !== 'object' ) { return undefined ; } const parser = await pendingParser ; if ( ! parser . parserOpts ) { return parser ; } if ( typeof parser . parserOpts === 'object' ) { parser . parserOpts = await parser . parserOpts ; if ( isObjectLike ( parser . parserOpts ) && isObjectLike ( parser . parserOpts . parserOpts ) ) { parser . parserOpts = parser . parserOpts . parserOpts ; } return parser ; } if ( isParserOptsFunction ( parser ) && typeof parser . name === 'string' && parser . name . startsWith ( 'conventional-changelog-' ) ) { return new Promise ( ( resolve ) => { const result = parser . parserOpts ( ( _ , opts ) => { resolve ( { ... parser , parserOpts : opts ?. parserOpts , } ) ; } ) ; if ( result ) { Promise . resolve ( result ) . then ( ( opts ) => { resolve ( { ... parser , parserOpts : opts ?. parserOpts , } ) ; } ) ; } return ; } ) ; } return parser ; }