MCPcopy Create free account
hub / github.com/backnotprop/plannotator / resolveOpenInTarget

Function resolveOpenInTarget

packages/shared/html-assets-node.ts:100–130  ·  view source on GitHub ↗
(
  filePath: string,
  base: string | null,
  resolveRoot?: () => string | string[],
)

Source from the content-addressed store, hash-verified

98 * Returns the absolute path, or null when it escapes every allowed root.
99 */
100export function resolveOpenInTarget(
101 filePath: string,
102 base: string | null,
103 resolveRoot?: () => string | string[],
104): string | null {
105 const provided = resolveRoot?.();
106 const roots = (
107 provided == null
108 ? [
109 base
110 ? resolvePath(base)
111 : isAbsolute(filePath)
112 ? dirname(resolvePath(filePath))
113 : resolvePath(process.cwd()),
114 ]
115 : Array.isArray(provided)
116 ? provided
117 : [provided]
118 )
119 .filter((r): r is string => !!r)
120 .map((r) => resolvePath(r));
121 // Resolve against each root and return the first that contains its own
122 // resolution. For an absolute filePath the resolution is identical for every
123 // root (a pure containment check); for a relative filePath this avoids the
124 // duplicate-basename trap of resolving only against roots[0].
125 for (const root of roots) {
126 const abs = resolvePath(root, filePath);
127 if (isWithinDirectory(abs, root)) return abs;
128 }
129 return null;
130}

Callers 4

handleOpenInFunction · 0.90
open-in.test.tsFile · 0.90
startReviewServerFunction · 0.85
startAnnotateServerFunction · 0.85

Calls 2

dirnameFunction · 0.85
isWithinDirectoryFunction · 0.85

Tested by

no test coverage detected