diff --git a/.changeset/twelve-hotels-exist.md b/.changeset/twelve-hotels-exist.md new file mode 100644 index 000000000..f26ee8c02 --- /dev/null +++ b/.changeset/twelve-hotels-exist.md @@ -0,0 +1,5 @@ +--- +"@pkgr/core": patch +--- + +feat: support findUp with `includeDir` option diff --git a/packages/core/src/helpers.ts b/packages/core/src/helpers.ts index d1025ef35..ae2dbb41c 100644 --- a/packages/core/src/helpers.ts +++ b/packages/core/src/helpers.ts @@ -33,7 +33,11 @@ export const tryExtensions = (filepath: string, extensions = EXTENSIONS) => { return ext == null ? '' : filepath + ext } -export const findUp = (searchEntry: string, searchFile = 'package.json') => { +export const findUp = ( + searchEntry: string, + searchFileOrIncludeDir?: boolean | string, + includeDir?: boolean, +) => { console.assert(path.isAbsolute(searchEntry)) if ( @@ -49,8 +53,15 @@ export const findUp = (searchEntry: string, searchFile = 'package.json') => { : path.resolve(searchEntry, '..'), ) + const isSearchFile = typeof searchFileOrIncludeDir === 'string' + + const searchFile = isSearchFile ? searchFileOrIncludeDir : 'package.json' + do { - const searched = tryFile(path.resolve(searchEntry, searchFile)) + const searched = tryFile( + path.resolve(searchEntry, searchFile), + isSearchFile && includeDir, + ) if (searched) { return searched }