summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/node/fetch-yarn-deps/yarn-config-hook.sh
blob: 1d81aad62e60cd27c8cd9bd0557ecfb6961f2a03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
yarnConfigHook() {
    echo "Executing yarnConfigHook"

    # Use a constant HOME directory
    export HOME=$(mktemp -d)
    if [[ -n "$yarnOfflineCache" ]]; then
        offlineCache="$yarnOfflineCache"
    fi
    if [[ -z "$offlineCache" ]]; then
        echo yarnConfigHook: No yarnOfflineCache or offlineCache were defined\! >&2
        exit 2
    fi

    local -r cacheLockfile="$offlineCache/yarn.lock"
    local -r srcLockfile="$PWD/yarn.lock"

    echo "Validating consistency between $srcLockfile and $cacheLockfile"

    if ! @diff@ "$srcLockfile" "$cacheLockfile"; then
      # If the diff failed, first double-check that the file exists, so we can
      # give a friendlier error msg.
      if ! [ -e "$srcLockfile" ]; then
        echo
        echo "ERROR: Missing yarn.lock from src. Expected to find it at: $srcLockfile"
        echo "Hint: You can copy a vendored yarn.lock file via postPatch."
        echo

        exit 1
      fi

      if ! [ -e "$cacheLockfile" ]; then
        echo
        echo "ERROR: Missing lockfile from cache. Expected to find it at: $cacheLockfile"
        echo

        exit 1
      fi

      echo
      echo "ERROR: fetchYarnDeps hash is out of date"
      echo
      echo "The yarn.lock in src is not the same as the in $offlineCache."
      echo
      echo "To fix the issue:"
      echo '1. Use `lib.fakeHash` as the fetchYarnDeps hash value'
      echo "2. Build the derivation and wait for it to fail with a hash mismatch"
      echo "3. Copy the 'got: sha256-' value back into the fetchYarnDeps hash field"
      echo

      exit 1
    fi

    yarn config --offline set yarn-offline-mirror "$offlineCache"
    fixup-yarn-lock yarn.lock
    yarn install \
        --frozen-lockfile \
        --force \
        --production=false \
        --ignore-engines \
        --ignore-platform \
        --ignore-scripts \
        --no-progress \
        --non-interactive \
        --offline

    # TODO: Check if this is really needed
    patchShebangs node_modules

    echo "finished yarnConfigHook"
}

if [[ -z "${dontYarnInstallDeps-}" ]]; then
    postConfigureHooks+=(yarnConfigHook)
fi