We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4bd6622 commit b55e98bCopy full SHA for b55e98b
src/package/getPackageJson.ts
@@ -2,9 +2,14 @@ import type { PackageJson } from "type-fest";
2
import { getPackageRootPath } from "./getPackageRootPath";
3
import path from "node:path"
4
5
-
6
-export function getPackageJson(entry?:string):PackageJson | undefined{
7
- const packageRoot = getPackageRootPath(entry) as string
+/**
+ *
+ * @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()
13
try{
14
return require(path.join(packageRoot,"package.json"))
15
}catch{
0 commit comments