Skip to content

Commit b55e98b

Browse files
committed
feat: getPackageJson增加一个findUp参数
1 parent 4bd6622 commit b55e98b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/package/getPackageJson.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import type { PackageJson } from "type-fest";
22
import { getPackageRootPath } from "./getPackageRootPath";
33
import path from "node:path"
44

5-
6-
export function getPackageJson(entry?:string):PackageJson | undefined{
7-
const packageRoot = getPackageRootPath(entry) as string
5+
/**
6+
*
7+
* @param entry
8+
* @param findUp 是否向上查找package.json,默认为true
9+
* @returns
10+
*/
11+
export function getPackageJson(entry?:string,findUp?:boolean):PackageJson | undefined{
12+
const packageRoot =findUp ? getPackageRootPath(entry) as string : entry || process.cwd()
813
try{
914
return require(path.join(packageRoot,"package.json"))
1015
}catch{

0 commit comments

Comments
 (0)