jql: 8.0.0 -> 8.0.2 (#362884)
[NixPkgs.git] / pkgs / build-support / node / fetch-yarn-deps / yarn-install-hook.sh
blob240879ad7182f3b3c15a1631753419b9d8aee0c9
1 # shellcheck shell=bash
3 yarnInstallHook() {
4 echo "Executing yarnInstallHook"
6 runHook preInstall
8 local -r packageOut="$out/lib/node_modules/$(@jq@ --raw-output '.name' ./package.json)"
9 mkdir -p "$packageOut"
11 local -ar yarnArgs=(
12 --ignore-engines
13 --ignore-platform
14 --ignore-scripts
15 --no-progress
16 --non-interactive
17 --offline
20 local -r tmpDir="$(mktemp -d)"
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
29 # TODO: figure out a way to avoid redundant compress/decompress steps
30 yarn pack \
31 --filename "$tmpDir/yarn-pack.tgz" \
32 "${yarnArgs[@]}"
34 tar xzf "$tmpDir/yarn-pack.tgz" \
35 -C "$packageOut" \
36 --strip-components 1 \
37 package/
39 mv "$tmpDir/package.json.orig" ./package.json
41 nodejsInstallExecutables ./package.json
43 nodejsInstallManuals ./package.json
45 local -r nodeModulesPath="$packageOut/node_modules"
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
63 exit 1
67 find node_modules -maxdepth 1 -type d -empty -delete
69 cp -r node_modules "$nodeModulesPath"
72 runHook postInstall
74 echo "Finished yarnInstallHook"
77 if [ -z "${dontYarnInstall-}" ] && [ -z "${installPhase-}" ]; then
78 installPhase=yarnInstallHook