* Get bind path depending on os platform * @param {object} serverless * @param {string} servicePath * @return {string} The bind path.
(servicePath, pluginInstance)
| 133 | * @return {string} The bind path. |
| 134 | */ |
| 135 | async function getBindPath(servicePath, pluginInstance) { |
| 136 | // Determine bind path |
| 137 | let isWsl1 = isWsl && !os.release().includes('microsoft-standard') |
| 138 | if (process.platform !== 'win32' && !isWsl1) { |
| 139 | return servicePath |
| 140 | } |
| 141 | |
| 142 | // test docker is available |
| 143 | await dockerCommand(['version'], pluginInstance) |
| 144 | |
| 145 | // find good bind path for Windows |
| 146 | let bindPaths = [] |
| 147 | let baseBindPath = servicePath.replace(/\\([^\s])/g, '/$1') |
| 148 | let drive |
| 149 | let path |
| 150 | |
| 151 | bindPaths.push(baseBindPath) |
| 152 | if (baseBindPath.startsWith('/mnt/')) { |
| 153 | // cygwin "/mnt/C/users/..." |
| 154 | baseBindPath = baseBindPath.replace(/^\/mnt\//, '/') |
| 155 | } |
| 156 | if (baseBindPath[1] == ':') { |
| 157 | // normal windows "c:/users/..." |
| 158 | drive = baseBindPath[0] |
| 159 | path = baseBindPath.substring(3) |
| 160 | } else if (baseBindPath[0] == '/' && baseBindPath[2] == '/') { |
| 161 | // gitbash "/c/users/..." |
| 162 | drive = baseBindPath[1] |
| 163 | path = baseBindPath.substring(3) |
| 164 | } else { |
| 165 | throw new Error(`Unknown path format ${baseBindPath.substr(10)}...`) |
| 166 | } |
| 167 | |
| 168 | bindPaths.push(`/${drive.toLowerCase()}/${path}`) // Docker Toolbox (seems like Docker for Windows can support this too) |
| 169 | bindPaths.push(`${drive.toLowerCase()}:/${path}`) // Docker for Windows |
| 170 | // other options just in case |
| 171 | bindPaths.push(`/${drive.toUpperCase()}/${path}`) |
| 172 | bindPaths.push(`/mnt/${drive.toLowerCase()}/${path}`) |
| 173 | bindPaths.push(`/mnt/${drive.toUpperCase()}/${path}`) |
| 174 | bindPaths.push(`${drive.toUpperCase()}:/${path}`) |
| 175 | |
| 176 | const testFile = findTestFile(servicePath, pluginInstance) |
| 177 | |
| 178 | for (let i = 0; i < bindPaths.length; i++) { |
| 179 | const bindPath = bindPaths[i] |
| 180 | if (await tryBindPath(bindPath, testFile, pluginInstance)) { |
| 181 | return bindPath |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | throw new Error('Unable to find good bind path format') |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Find out what uid the docker machine is using |
no test coverage detected
searching dependent graphs…