Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1const path = require('path')
2
3// This has to match the logic in pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/urlToName.js
4// so that fixup_yarn_lock produces the same paths
5const urlToName = url => {
6 const isCodeloadGitTarballUrl = url.startsWith('https://codeload.github.com/') && url.includes('/tar.gz/')
7
8 if (url.startsWith('file:')) {
9 return url
10 } else if (url.startsWith('git+') || isCodeloadGitTarballUrl) {
11 return path.basename(url)
12 } else {
13 return url
14 .replace(/https:\/\/(.)*(.com)\//g, '') // prevents having long directory names
15 .replace(/[@/%:-]/g, '_') // replace @ and : and - and % characters with underscore
16 }
17}
18
19module.exports = { urlToName };