MCPcopy Create free account
hub / github.com/QwikDev/qwik / findDepPkgJsonPath

Function findDepPkgJsonPath

packages/qwik/src/optimizer/src/plugins/utils.ts:3–23  ·  view source on GitHub ↗
(sys: OptimizerSystem, dep: string, parent: string)

Source from the content-addressed store, hash-verified

1import type { OptimizerSystem } from '../types';
2
3export async function findDepPkgJsonPath(sys: OptimizerSystem, dep: string, parent: string) {
4 const fs: typeof import('fs') = await sys.dynamicImport('node:fs');
5 let root = parent;
6 while (root) {
7 const pkg = sys.path.join(root, 'node_modules', dep, 'package.json');
8 try {
9 await fs.promises.access(pkg);
10 // use 'node:fs' version to match 'vite:resolve' and avoid realpath.native quirk
11 // https://github.com/sveltejs/vite-plugin-svelte/issues/525#issuecomment-1355551264
12 return fs.promises.realpath(pkg);
13 } catch {
14 //empty
15 }
16 const nextRoot = sys.path.dirname(root);
17 if (nextRoot === root) {
18 break;
19 }
20 root = nextRoot;
21 }
22 return undefined;
23}

Callers 2

findQwikRootsFunction · 0.90

Calls 2

joinMethod · 0.65
dirnameMethod · 0.65

Tested by

no test coverage detected