MCPcopy Index your code
hub / github.com/rollup/plugins / findPackageJson

Function findPackageJson

packages/node-resolve/src/package/utils.ts:11–24  ·  view source on GitHub ↗
(base: string, moduleDirs: readonly string[])

Source from the content-addressed store, hash-verified

9}
10
11export async function findPackageJson(base: string, moduleDirs: readonly string[]) {
12 const { root } = path.parse(base);
13 let current = base;
14
15 while (current !== root && !isModuleDir(current, moduleDirs)) {
16 const pkgJsonPath = path.join(current, 'package.json');
17 if (await fileExists(pkgJsonPath)) {
18 const pkgJsonString = fs.readFileSync(pkgJsonPath, 'utf-8');
19 return { pkgJson: JSON.parse(pkgJsonString), pkgPath: current, pkgJsonPath };
20 }
21 current = path.resolve(current, '..');
22 }
23 return null;
24}
25
26export function isUrl(str: string) {
27 try {

Callers 2

getPackageJsonFunction · 0.90
resolvePackageImportsFunction · 0.90

Calls 2

fileExistsFunction · 0.90
isModuleDirFunction · 0.85

Tested by

no test coverage detected