about summary refs log tree commit diff
path: root/pkgs/build-support/node/build-npm-package/hooks/npm-build-hook.sh
blob: b99c9d94faffca34613e6093c6b8704508f5a6f6 (plain) (blame)
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
# shellcheck shell=bash

npmBuildHook() {
    echo "Executing npmBuildHook"

    runHook preBuild

    if [ -z "${npmBuildScript-}" ]; then
        echo
        echo "ERROR: no build script was specified"
        echo 'Hint: set `npmBuildScript`, override `buildPhase`, or set `dontNpmBuild = true`.'
        echo

        exit 1
    fi

    if ! npm run "$npmBuildScript" $npmBuildFlags "${npmBuildFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}"; then
        echo
        echo 'ERROR: `npm build` failed'
        echo
        echo "Here are a few things you can try, depending on the error:"
        echo "1. Make sure your build script ($npmBuildScript) exists"
        echo '2. If the error being thrown is something similar to "error:0308010C:digital envelope routines::unsupported", add `NODE_OPTIONS = "--openssl-legacy-provider"` to your derivation'
        echo "  See https://github.com/webpack/webpack/issues/14532 for more information."
        echo

        exit 1
    fi

    runHook postBuild

    echo "Finished npmBuildHook"
}

if [ -z "${dontNpmBuild-}" ] && [ -z "${buildPhase-}" ]; then
    buildPhase=npmBuildHook
fi