(version: string)
| 151 | } |
| 152 | |
| 153 | async function getVersionPaths(version: string) { |
| 154 | const dirs = getBaseDirectories() |
| 155 | |
| 156 | // Create directories, but not the executable path (which is a file) |
| 157 | const dirsToCreate = [dirs.versions, dirs.staging, dirs.locks] |
| 158 | await Promise.all(dirsToCreate.map(dir => mkdir(dir, { recursive: true }))) |
| 159 | |
| 160 | // Ensure parent directory of executable exists |
| 161 | const executableParentDir = dirname(dirs.executable) |
| 162 | await mkdir(executableParentDir, { recursive: true }) |
| 163 | |
| 164 | const installPath = join(dirs.versions, version) |
| 165 | |
| 166 | // Create an empty file if it doesn't exist |
| 167 | try { |
| 168 | await stat(installPath) |
| 169 | } catch { |
| 170 | await writeFile(installPath, '', { encoding: 'utf8' }) |
| 171 | } |
| 172 | |
| 173 | return { |
| 174 | stagingPath: join(dirs.staging, version), |
| 175 | installPath, |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | // Execute a callback while holding a lock on a version file |
| 180 | // Returns false if the file is already locked, true if callback executed |
no test coverage detected