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

Function exportTargets

src/resolution/workspace-packages.ts:221–228  ·  view source on GitHub ↗

An `exports` value's targets, best first: a string, a fallback array, or (nested) conditions, by key order within each tier.

(value: unknown)

Source from the content-addressed store, hash-verified

219
220/** An `exports` value's targets, best first: a string, a fallback array, or (nested) conditions, by key order within each tier. */
221function exportTargets(value: unknown): string[] {
222 if (typeof value === 'string') return [value];
223 if (Array.isArray(value)) return value.flatMap(exportTargets);
224 if (!value || typeof value !== 'object') return [];
225 const conditions = Object.entries(value as Record<string, unknown>);
226 const tier = (key: string): number => (RESOLVING_CONDITIONS.has(key) ? 0 : TYPE_CONDITIONS.has(key) ? 2 : 1);
227 return [0, 1, 2].flatMap((t) => conditions.filter(([key]) => tier(key) === t).flatMap(([, v]) => exportTargets(v)));
228}
229
230/** What an `exports` value's `browser` condition names, at any depth of its conditions. */
231function browserTargets(value: unknown): string[] {

Callers 2

browserTargetsFunction · 0.85
readPackageEntriesFunction · 0.85

Calls 1

tierFunction · 0.70

Tested by

no test coverage detected