nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 79 lines 2.3 kB view raw
1# shellcheck shell=bash 2 3yarnInstallHook() { 4 echo "Executing yarnInstallHook" 5 6 runHook preInstall 7 8 local -r packageOut="$out/lib/node_modules/$(@jq@ --raw-output '.name' ./package.json)" 9 mkdir -p "$packageOut" 10 11 local -ar yarnArgs=( 12 --ignore-engines 13 --ignore-platform 14 --ignore-scripts 15 --no-progress 16 --non-interactive 17 --offline 18 ) 19 20 local -r tmpDir="$(mktemp -d)" 21 22 # yarn pack does not work at all with bundleDependencies. 23 # Since we are imediately unpacking, we can just remove them from package.json 24 # This will NOT be fixed in yarn v1: https://github.com/yarnpkg/yarn/issues/6794 25 mv ./package.json "$tmpDir/package.json.orig" 26 # Note: two spellings are accepted, 'bundleDependencies' and 'bundledDependencies' 27 @jq@ 'del(.bundleDependencies)|del(.bundledDependencies)' "$tmpDir/package.json.orig" > ./package.json 28 29 # TODO: figure out a way to avoid redundant compress/decompress steps 30 yarn pack \ 31 --filename "$tmpDir/yarn-pack.tgz" \ 32 "${yarnArgs[@]}" 33 34 tar xzf "$tmpDir/yarn-pack.tgz" \ 35 -C "$packageOut" \ 36 --strip-components 1 \ 37 package/ 38 39 mv "$tmpDir/package.json.orig" ./package.json 40 41 nodejsInstallExecutables ./package.json 42 43 nodejsInstallManuals ./package.json 44 45 local -r nodeModulesPath="$packageOut/node_modules" 46 47 if [ ! -d "$nodeModulesPath" ]; then 48 if [ -z "${yarnKeepDevDeps-}" ]; then 49 # Yarn has a 'prune' command, but it's only a stub that directs you to use install 50 if ! yarn install \ 51 --frozen-lockfile \ 52 --force \ 53 --production=true \ 54 "${yarnArgs[@]}" 55 then 56 echo 57 echo 58 echo "ERROR: yarn prune step failed" 59 echo 60 echo 'If yarn tried to download additional dependencies above, try setting `yarnKeepDevDeps = true`.' 61 echo 62 63 exit 1 64 fi 65 fi 66 67 find node_modules -maxdepth 1 -type d -empty -delete 68 69 cp -r node_modules "$nodeModulesPath" 70 fi 71 72 runHook postInstall 73 74 echo "Finished yarnInstallHook" 75} 76 77if [ -z "${dontYarnInstall-}" ] && [ -z "${installPhase-}" ]; then 78 installPhase=yarnInstallHook 79fi