MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / loadWorkspacePackages

Function loadWorkspacePackages

src/resolution/workspace-packages.ts:55–84  ·  view source on GitHub ↗
(projectRoot: string)

Source from the content-addressed store, hash-verified

53 * the same way it does {@link loadProjectAliases} / {@link loadGoModule}.
54 */
55export function loadWorkspacePackages(projectRoot: string): WorkspacePackages | null {
56 const byName = new Map<string, string>();
57
58 const patterns = readWorkspaceGlobs(projectRoot);
59 for (const pattern of patterns) {
60 for (const dir of expandWorkspaceGlob(projectRoot, pattern)) {
61 const pkgName = readPackageName(path.join(projectRoot, dir));
62 // First declaration wins — workspace patterns are tried in order.
63 if (pkgName && !byName.has(pkgName)) byName.set(pkgName, dir);
64 }
65 }
66
67 // HarmonyOS/OpenHarmony (ArkTS) modular projects: every module's
68 // oh-package.json5 declares its local siblings as `"data": "file:../../
69 // core/data"` dependencies, and code then imports the bare name
70 // (`import { CartRepository } from "data"`). Same monorepo problem as npm
71 // workspaces, different manifest.
72 const entryByName = new Map<string, string>();
73 for (const [name, dir] of collectOhpmFileDeps(projectRoot)) {
74 if (byName.has(name)) continue;
75 byName.set(name, dir);
76 const entry = readOhpmMain(projectRoot, dir);
77 if (entry) entryByName.set(name, entry);
78 }
79
80 if (byName.size === 0) return null;
81
82 logDebug('workspace packages loaded', { count: byName.size });
83 return { byName, entryByName: entryByName.size > 0 ? entryByName : undefined };
84}
85
86/**
87 * Read an ohpm member's declared entry file: `<dir>/oh-package.json5`'s

Callers 1

createContextMethod · 0.90

Calls 9

logDebugFunction · 0.90
readWorkspaceGlobsFunction · 0.85
expandWorkspaceGlobFunction · 0.85
readPackageNameFunction · 0.85
collectOhpmFileDepsFunction · 0.85
readOhpmMainFunction · 0.85
hasMethod · 0.80
joinMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected