about summary refs log tree commit diff
path: root/pkgs/by-name/no
diff options
context:
space:
mode:
authorlelgenio2024-08-22 19:35:06 -0300
committerlelgenio2024-08-26 20:43:42 -0300
commit80a2825733fc9fe30a5634370dd60013ef0c2525 (patch)
tree8498d4cc23d776a986e74487c0c4b3c0b4a6a81b /pkgs/by-name/no
parentc1c478cd720249252c91dc38d38acecb52eb62eb (diff)
npmHooks.npmInstallHook: extract npmInstall{Manuals,Executables}
Diffstat (limited to 'pkgs/by-name/no')
-rw-r--r--pkgs/by-name/no/nodejsInstallExecutables/hook.sh27
-rw-r--r--pkgs/by-name/no/nodejsInstallExecutables/package.nix19
-rw-r--r--pkgs/by-name/no/nodejsInstallManuals/hook.sh14
-rw-r--r--pkgs/by-name/no/nodejsInstallManuals/package.nix13
4 files changed, 73 insertions, 0 deletions
diff --git a/pkgs/by-name/no/nodejsInstallExecutables/hook.sh b/pkgs/by-name/no/nodejsInstallExecutables/hook.sh
new file mode 100644
index 000000000000..ab2a8e372da4
--- /dev/null
+++ b/pkgs/by-name/no/nodejsInstallExecutables/hook.sh
@@ -0,0 +1,27 @@
+# shellcheck shell=bash
+
+nodejsInstallExecutables() {
+    local -r packageJson="${1-./package.json}"
+
+    local -r packageOut="$out/lib/node_modules/$(@jq@ --raw-output '.name' package.json)"
+
+    # Based on code from Python's buildPythonPackage wrap.sh script, for
+    # supporting both the case when makeWrapperArgs is an array and a
+    # IFS-separated string.
+    #
+    # TODO: remove the string branch when __structuredAttrs are used.
+    if [[ "${makeWrapperArgs+defined}" == "defined" && "$(declare -p makeWrapperArgs)" =~ ^'declare -a makeWrapperArgs=' ]]; then
+        local -a user_args=("${makeWrapperArgs[@]}")
+    else
+        local -a user_args="(${makeWrapperArgs:-})"
+    fi
+
+    while IFS=" " read -ra bin; do
+        mkdir -p "$out/bin"
+        makeWrapper @hostNode@ "$out/bin/${bin[0]}" --add-flags "$packageOut/${bin[1]}" "${user_args[@]}"
+    done < <(@jq@ --raw-output '(.bin | type) as $typ | if $typ == "string" then
+        .name + " " + .bin
+        elif $typ == "object" then .bin | to_entries | map(.key + " " + .value) | join("\n")
+        elif $typ == "null" then empty
+        else "invalid type " + $typ | halt_error end' "$packageJson")
+}
diff --git a/pkgs/by-name/no/nodejsInstallExecutables/package.nix b/pkgs/by-name/no/nodejsInstallExecutables/package.nix
new file mode 100644
index 000000000000..8403cf8881d6
--- /dev/null
+++ b/pkgs/by-name/no/nodejsInstallExecutables/package.nix
@@ -0,0 +1,19 @@
+{
+  makeSetupHook,
+  installShellFiles,
+  makeWrapper,
+  nodejs,
+  jq,
+}:
+
+makeSetupHook {
+  name = "nodejs-install-executables";
+  propagatedBuildInputs = [
+    installShellFiles
+    makeWrapper
+  ];
+  substitutions = {
+    hostNode = "${nodejs}/bin/node";
+    jq = "${jq}/bin/jq";
+  };
+} ./hook.sh
diff --git a/pkgs/by-name/no/nodejsInstallManuals/hook.sh b/pkgs/by-name/no/nodejsInstallManuals/hook.sh
new file mode 100644
index 000000000000..f0ff209c6226
--- /dev/null
+++ b/pkgs/by-name/no/nodejsInstallManuals/hook.sh
@@ -0,0 +1,14 @@
+# shellcheck shell=bash
+
+nodejsInstallManuals() {
+    local -r packageJson="${1-./package.json}"
+
+    local -r packageOut="$out/lib/node_modules/$(@jq@ --raw-output '.name' package.json)"
+
+    while IFS= read -r man; do
+        installManPage "$packageOut/$man"
+    done < <(@jq@ --raw-output '(.man | type) as $typ | if $typ == "string" then .man
+        elif $typ == "list" then .man | join("\n")
+        elif $typ == "null" then empty
+        else "invalid type " + $typ | halt_error end' "$packageJson")
+}
diff --git a/pkgs/by-name/no/nodejsInstallManuals/package.nix b/pkgs/by-name/no/nodejsInstallManuals/package.nix
new file mode 100644
index 000000000000..9f74cf8538da
--- /dev/null
+++ b/pkgs/by-name/no/nodejsInstallManuals/package.nix
@@ -0,0 +1,13 @@
+{
+  makeSetupHook,
+  installShellFiles,
+  jq,
+}:
+
+makeSetupHook {
+  name = "nodejs-install-manuals";
+  propagatedBuildInputs = [ installShellFiles ];
+  substitutions = {
+    jq = "${jq}/bin/jq";
+  };
+} ./hook.sh