* Whether this machine can create a link of `type`. A Windows junction needs no * privilege; a symbolic link there needs Developer Mode or admin rights. Where * one can't be made, its tests are skipped, with the reason in their name.
(type: 'file' | 'dir' | 'junction')
| 158 | * one can't be made, its tests are skipped, with the reason in their name. |
| 159 | */ |
| 160 | function canCreateLink(type: 'file' | 'dir' | 'junction'): boolean { |
| 161 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-link-probe-')); |
| 162 | const target = path.join(dir, 'target'); |
| 163 | const link = path.join(dir, 'link'); |
| 164 | try { |
| 165 | if (type === 'file') fs.writeFileSync(target, ''); |
| 166 | else fs.mkdirSync(target); |
| 167 | fs.symlinkSync(target, link, type); |
| 168 | return true; |
| 169 | } catch { |
| 170 | return false; |
| 171 | } finally { |
| 172 | removeLink(link); |
| 173 | fs.rmSync(dir, { recursive: true, force: true }); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /** A `.codegraph/ui` link can be a junction or a directory symlink on Windows. */ |
| 178 | const DIR_LINKS = (process.platform === 'win32' ? ['junction', 'dir'] : ['dir']) as Array< |
no test coverage detected