MCPcopy Create free account
hub / github.com/taye/interact.js / getRelativeToRoot

Function getRelativeToRoot

scripts/utils.js:137–153  ·  view source on GitHub ↗
(filename, moduleDirectory, prefix = '/')

Source from the content-addressed store, hash-verified

135}
136
137function getRelativeToRoot(filename, moduleDirectory, prefix = '/') {
138 filename = path.normalize(filename)
139
140 const ret = withBestRoot((root) => {
141 const valid = filename.startsWith(root)
142 const result = valid && path.join(prefix, path.relative(root, filename))
143 const priority = valid && -result.length
144
145 return { valid, result, priority }
146 }, moduleDirectory)
147
148 if (!ret.result) {
149 throw new Error(`Couldn't find module ${filename} in ${moduleDirectory.join(' or')}.`)
150 }
151
152 return ret
153}
154
155/**
156 * use the result of `func` most shallow valid root

Callers 2

fixImportSourceFunction · 0.85
fixImportSourceFunction · 0.85

Calls 1

withBestRootFunction · 0.85

Tested by

no test coverage detected