Skip to content

Commit

Permalink
feat: getPackageJson增加一个findUp参数
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfisher committed Feb 20, 2025
1 parent 4bd6622 commit b55e98b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/package/getPackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import type { PackageJson } from "type-fest";
import { getPackageRootPath } from "./getPackageRootPath";
import path from "node:path"


export function getPackageJson(entry?:string):PackageJson | undefined{
const packageRoot = getPackageRootPath(entry) as string
/**
*
* @param entry
* @param findUp 是否向上查找package.json,默认为true
* @returns
*/
export function getPackageJson(entry?:string,findUp?:boolean):PackageJson | undefined{
const packageRoot =findUp ? getPackageRootPath(entry) as string : entry || process.cwd()
try{
return require(path.join(packageRoot,"package.json"))
}catch{
Expand Down

0 comments on commit b55e98b

Please sign in to comment.