* Given a resolvable module name or path, which can be a directory or file, will * return a located adapter path or will throw.
(inboundAdapterPath)
| 156 | * return a located adapter path or will throw. |
| 157 | */ |
| 158 | function resolveAdapterPath (inboundAdapterPath) { |
| 159 | // Check if inboundAdapterPath is a path or node module name |
| 160 | let parsed = path.parse(inboundAdapterPath); |
| 161 | let isPath = parsed.dir.length > 0 && parsed.dir.charAt(0) !== "@"; |
| 162 | |
| 163 | // Resolve from the root of the git repo if inboundAdapterPath is a path |
| 164 | let absoluteAdapterPath = isPath ? |
| 165 | path.resolve(getGitRootPath(), inboundAdapterPath) : |
| 166 | inboundAdapterPath; |
| 167 | |
| 168 | try { |
| 169 | // try to resolve the given path |
| 170 | return require.resolve(absoluteAdapterPath); |
| 171 | } catch (error) { |
| 172 | error.message = "Could not resolve " + absoluteAdapterPath + ". " + error.message; |
| 173 | throw error; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | function getGitRootPath () { |
| 178 | return childProcess.spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).stdout.trim(); |
no test coverage detected