import fs from 'fs' ; import path from 'path' ; async function resolveConfig ( ) { const configContextPath = process . argv [ 2 ] || process . cwd ( ) ; if ( fs . existsSync ( configContextPath ) ) { const stat = await fs . promises . stat ( configContextPath ) ; if ( ! stat . isDirectory ( ) ) { return configContextPath ; } } async function findConfig ( configPath ) { try { return require . resolve ( `${ configPath }/sanity-codegen.config` ) ; } catch { const currentFolder = path . resolve ( './' , configPath ) ; const parentFolder = path . resolve ( '../' , configPath ) ; if ( currentFolder === parentFolder ) { return null ; } return await findConfig ( parentFolder ) ; } } return await findConfig ( configContextPath ) ; } export default resolveConfig ;