1# shellcheck shell=bash
2
3nodejsInstallExecutables() {
4 local -r packageJson="${1-./package.json}"
5
6 local -r packageOut="$out/lib/node_modules/$(@jq@ --raw-output '.name' package.json)"
7
8 # Based on code from Python's buildPythonPackage wrap.sh script, for
9 # supporting both the case when makeWrapperArgs is an array and a
10 # IFS-separated string.
11 #
12 # TODO: remove the string branch when __structuredAttrs are used.
13 if [[ "${makeWrapperArgs+defined}" == "defined" && "$(declare -p makeWrapperArgs)" =~ ^'declare -a makeWrapperArgs=' ]]; then
14 local -a user_args=("${makeWrapperArgs[@]}")
15 else
16 local -a user_args="(${makeWrapperArgs:-})"
17 fi
18
19 while IFS=" " read -ra bin; do
20 mkdir -p "$out/bin"
21 makeWrapper @hostNode@ "$out/bin/${bin[0]}" --add-flags "$packageOut/${bin[1]}" "${user_args[@]}"
22 done < <(@jq@ --raw-output '(.bin | type) as $typ | if $typ == "string" then
23 .name + " " + .bin
24 elif $typ == "object" then .bin | to_entries | map(.key + " " + .value) | join("\n")
25 elif $typ == "null" then empty
26 else "invalid type " + $typ | halt_error end' "$packageJson")
27}