(filename, moduleDirectory, prefix = '/')
| 135 | } |
| 136 | |
| 137 | function 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 |
no test coverage detected