MCPcopy Create free account
hub / github.com/arktypeio/arktype / dependencyOf

Function dependencyOf

ark/aot/host.ts:225–239  ·  view source on GitHub ↗
(
	file: string
)

Source from the content-addressed store, hash-verified

223
224// from the innermost node_modules the file names a package in
225export const dependencyOf = (
226 file: string
227): [root: string, name: string] | undefined => {
228 const starts = [...file.matchAll(nodeModulesSegment)]
229 for (let i = starts.length - 1; i >= 0; i--) {
230 packageInNodeModules.lastIndex = starts[i].index
231 const match = packageInNodeModules.exec(file)
232 if (match) {
233 return [
234 file.slice(0, packageInNodeModules.lastIndex),
235 match[1].replace("\\", "/")
236 ]
237 }
238 }
239}
240
241// a leading .* would backtrack across a long path once per character
242const nodeModulesSegment = /[/\\]node_modules(?=[/\\])/g

Callers 15

answerFromProgramFunction · 0.90
loadedOfFunction · 0.90
readDependencyFunction · 0.90
untransformedProblemOfFunction · 0.90
builtOfFunction · 0.90
externalPackageOfFunction · 0.90
untransformedProblemOfFunction · 0.90
mayReadMethod · 0.90
followFieldMethod · 0.90
readCopiesMethod · 0.90
readDependencyMethod · 0.90

Calls 2

execMethod · 0.80
replaceMethod · 0.80

Tested by

no test coverage detected