Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1# shellcheck shell=bash
2
3pnpmConfigHook() {
4 echo "Executing pnpmConfigHook"
5
6 if [ -n "${pnpmRoot-}" ]; then
7 pushd "$pnpmRoot"
8 fi
9
10 if [ -z "${pnpmDeps-}" ]; then
11 echo "Error: 'pnpmDeps' must be set when using pnpmConfigHook."
12 exit 1
13 fi
14
15 fetcherVersion=1
16 if [[ -e "${pnpmDeps}/.fetcher-version" ]]; then
17 fetcherVersion=$(cat "${pnpmDeps}/.fetcher-version")
18 fi
19
20 echo "Using fetcherVersion: $fetcherVersion"
21
22 echo "Configuring pnpm store"
23
24 export HOME=$(mktemp -d)
25 export STORE_PATH=$(mktemp -d)
26
27 cp -Tr "$pnpmDeps" "$STORE_PATH"
28 chmod -R +w "$STORE_PATH"
29
30
31 # If the packageManager field in package.json is set to a different pnpm version than what is in nixpkgs,
32 # any pnpm command would fail in that directory, the following disables this
33 pushd ..
34 pnpm config set manage-package-manager-versions false
35 popd
36
37 pnpm config set store-dir "$STORE_PATH"
38
39 # Prevent hard linking on file systems without clone support.
40 # See: https://pnpm.io/settings#packageimportmethod
41 pnpm config set package-import-method clone-or-copy
42
43 if [[ -n "$pnpmWorkspace" ]]; then
44 echo "'pnpmWorkspace' is deprecated, please migrate to 'pnpmWorkspaces'."
45 exit 2
46 fi
47
48 echo "Installing dependencies"
49 if [[ -n "$pnpmWorkspaces" ]]; then
50 local IFS=" "
51 for ws in $pnpmWorkspaces; do
52 pnpmInstallFlags+=("--filter=$ws")
53 done
54 fi
55
56 runHook prePnpmInstall
57
58 if ! pnpm install \
59 --offline \
60 --ignore-scripts \
61 "${pnpmInstallFlags[@]}" \
62 --frozen-lockfile
63 then
64 echo
65 echo "ERROR: pnpm failed to install dependencies"
66 echo
67 echo "If you see ERR_PNPM_NO_OFFLINE_TARBALL above this, follow these to fix the issue:"
68 echo '1. Set pnpmDeps.hash to "" (empty string)'
69 echo "2. Build the derivation and wait for it to fail with a hash mismatch"
70 echo "3. Copy the 'got: sha256-' value back into the pnpmDeps.hash field"
71 echo
72
73 exit 1
74 fi
75
76
77 echo "Patching scripts"
78
79 patchShebangs node_modules/{*,.*}
80
81 if [ -n "${pnpmRoot-}" ]; then
82 popd
83 fi
84
85 echo "Finished pnpmConfigHook"
86}
87
88postConfigureHooks+=(pnpmConfigHook)