···11-#!/usr/bin/env bash
22-33-###
44-### This script runs 'nix-build' with ./fetch-source.nix and copies a subset
55-### of the resulting store path into the current working directory.
66-###
77-### To disable running chmod, you may set the environment
88-### variable "FIX_RIGHTS" to "no".
99-###
1010-1111-set -euo pipefail
1212-1313-# 'nix-build' command
1414-NIX_BUILD_BIN="${NIX_BUILD_BIN:-"/usr/bin/env nix-build"}"
1515-1616-# where to place the yarn2nix source
1717-TARGET_DIR="${TARGET_DIR:-"./yarn2nix"}"
1818-1919-# whether to run 'chmod -R u=rwX,g=rX,o-rwx' on copied files in $TARGET_DIR
2020-FIX_RIGHTS="${FIX_RIGHTS:-"yes"}"
2121-2222-fetch_git_source() {
2323- [[ -f ./fetch-source.nix ]] && ret="$($NIX_BUILD_BIN --no-out-link ./fetch-source.nix)" && ec="$?" || ec="$?"
2424- if [[ "$ec" == "0" ]]; then
2525- echo "$ret"
2626- else
2727- printf "error: failed at 'fetch_git_source()' with '%s'" "$ret"
2828- fi
2929-}
3030-3131-result="$(fetch_git_source)"
3232-if [[ "$result" == "/nix/store"* ]]; then
3333- mkdir -p "$TARGET_DIR"
3434- cp -Rv \
3535- "${result}/"{bin,internal,lib,nix,default.nix,package.json,yarn.nix,yarn.lock,LICENSE.txt} \
3636- "$TARGET_DIR"
3737- [[ "$FIX_RIGHTS" = "yes" ]] \
3838- && chmod -v "u=rwX,g=rX,o-rwx" -R \
3939- "$TARGET_DIR/"{bin,internal,lib,nix,default.nix,package.json,yarn.nix,yarn.lock,LICENSE.txt}
4040-fi
···2222 }
23232424 return url
2525- .replace('https://registry.yarnpkg.com/', '') // prevents having long directory names
2626- .replace(/[@/:-]/g, '_') // replace @ and : and - characters with underscore
2525+ .replace(/https:\/\/(.)*(.com)\//g, '') // prevents having long directory names
2626+ .replace(/[@/%:-]/g, '_') // replace @ and : and - and % characters with underscore
2727}
28282929module.exports = urlToName