diff options
Diffstat (limited to 'nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/urlToName.js')
-rw-r--r-- | nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/urlToName.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/urlToName.js b/nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/urlToName.js new file mode 100644 index 000000000000..81feaaf3a659 --- /dev/null +++ b/nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/urlToName.js @@ -0,0 +1,21 @@ +const path = require('path') + +// String -> String + +// @url examples: +// - https://registry.yarnpkg.com/acorn-es7-plugin/-/acorn-es7-plugin-1.1.7.tgz +// - https://registry.npmjs.org/acorn-es7-plugin/-/acorn-es7-plugin-1.1.7.tgz +// - git+https://github.com/srghma/node-shell-quote.git +// - git+https://1234user:1234pass@git.graphile.com/git/users/1234user/postgraphile-supporter.git + +function urlToName(url) { + if (url.startsWith('git+')) { + return path.basename(url) + } + + return url + .replace('https://registry.yarnpkg.com/', '') // prevents having long directory names + .replace(/[@/:-]/g, '_') // replace @ and : and - characters with underscore +} + +module.exports = urlToName |