From d36636fe9aec5449bf185c0700d33cecd03e601a Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Fri, 2 Jun 2017 23:26:29 -0400 Subject: [PATCH 1/3] Learn how to rename a node after installation The rename_node function is part of node-build that way the build definitions simply need to define their after_install_package function to invoke rename_node. The function accepts a specific name as the new name, but defaults the name to the actual response from `node --version`. PREFIX_PATH must be updated after the move such that the rest of node-build knows about the new location. After moving the installed node, a symlink is created at the original location pointing to the new location. This allows end users to set their selected node using the same name as the build definition. Further, this "hack" allows any other plugins that hook into after-install to continue operating unchanged. Without the symlink, `PREFIX` and `NODENV_VERSION` would be incorrect for all after-install hooks. However, as they now refer to an existing directory (symlink), the hooks will operate on the newly installed node correctly. TODO: handle the "new name" already existing --- bin/node-build | 11 +++++++++++ share/node-build/nightly | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/bin/node-build b/bin/node-build index 10bd26e38..0282ebaf0 100755 --- a/bin/node-build +++ b/bin/node-build @@ -713,6 +713,17 @@ after_install_package() { local stub=1 } +rename_node() { + local name=${1:-$(./bin/node --version)} + local prefix=$(dirname "$PREFIX_PATH") + local new_path=${prefix:?not set}/${name#v} + + #TODO check for preexisting + mv -f "$PREFIX_PATH" "$new_path" + ln -s "$(basename $new_path)" "$PREFIX_PATH" + PREFIX_PATH=$new_path +} + fix_jxcore_directory_structure() { { mkdir -p "$PREFIX_PATH/bin" diff --git a/share/node-build/nightly b/share/node-build/nightly index 80216376b..9bf599a05 100644 --- a/share/node-build/nightly +++ b/share/node-build/nightly @@ -1,3 +1,7 @@ +after_install_package() { + rename_node +} + downloads="https://nodejs.org/download/nightly" read -ra manifest < <(http get "${downloads}/index.tab" | grep src | sort -rn -t $'\t' -k2,2 -k1,1 | head -1) From 8413e5b0c6871046187b0dd1be5769213b35d53c Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Mon, 3 Jul 2017 17:20:04 -0400 Subject: [PATCH 2/3] Better function name --- bin/node-build | 2 +- share/node-build/nightly | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/node-build b/bin/node-build index 0282ebaf0..0402561e2 100755 --- a/bin/node-build +++ b/bin/node-build @@ -713,7 +713,7 @@ after_install_package() { local stub=1 } -rename_node() { +alias_version_name() { local name=${1:-$(./bin/node --version)} local prefix=$(dirname "$PREFIX_PATH") local new_path=${prefix:?not set}/${name#v} diff --git a/share/node-build/nightly b/share/node-build/nightly index 9bf599a05..121d06ebd 100644 --- a/share/node-build/nightly +++ b/share/node-build/nightly @@ -1,5 +1,5 @@ after_install_package() { - rename_node + alias_version_name } downloads="https://nodejs.org/download/nightly" From fb7393a46cfa5099cc59ea089788baaf1138085c Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Mon, 3 Jul 2017 17:20:26 -0400 Subject: [PATCH 3/3] Exit if new path already exists --- bin/node-build | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/node-build b/bin/node-build index 0402561e2..87ec5f635 100755 --- a/bin/node-build +++ b/bin/node-build @@ -718,8 +718,12 @@ alias_version_name() { local prefix=$(dirname "$PREFIX_PATH") local new_path=${prefix:?not set}/${name#v} - #TODO check for preexisting - mv -f "$PREFIX_PATH" "$new_path" + if [ -d "$new_path" ]; then + echo "node-build: $new_path already exists" >&2 + return 1 + fi + + mv "$PREFIX_PATH" "$new_path" ln -s "$(basename $new_path)" "$PREFIX_PATH" PREFIX_PATH=$new_path }