Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making sure all node modules bin/ dirs are in PATH #92

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,62 @@
# vim: ft=bash

PATH_add bin
PATH_add /opt/homebrew/bin

export VOLTA_HOME=${HOME}/.volta
PATH_add ${VOLTA_HOME}/bin

export brew_prefix="$(brew --prefix)"

pg_pkg="postgresql@$(cat .postgresql-version)"
pg_dir="$(brew --prefix "${pg_pkg}")/bin/"

[[ -d ${pg_dir} ]] && PATH_add "${pg_dir}"
[[ -d ${pg_dir} ]] && PATH_add "${pg_dir}"

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
#———————————————————————————————————————————————————————————
# Add all the node module's bin paths to the $PATH
# Set "export PATH_DEBUG=1" to see what's happening here.
#———————————————————————————————————————————————————————————
declare -a node_bin_paths
export PATH_DEBUG=1

# save old $PATH
previous_path="${PATH}"

for dir in $(find node_modules -type d -name bin); do
PATH_add "${dir}"
done

PATH_add bin
PATH_add /opt/homebrew/bin
PATH_add ${VOLTA_HOME}/bin

# Re-add the old $PATH at the beginning; now we have it duplicated.
PATH_add "${previous_path}"

# Now we unique all the paths, but preserve the order
unique_path_file="/tmp/paths.tmp"
export root_dir="$(pwd -P)"

(
set -e
source ${root_dir}/development/shell-lib.sh
# uniq the paths
array.join ':' $(path.dirs.uniq)
) > "${unique_path_file}"

export NEW_PATH=$(/bin/cat "${unique_path_file}")

[[ -n ${NEW_PATH} ]] && {
# We need to unset $PATH completely, otherwise direnv takes over.
# This is dangerous! If we `
unset PATH
export PATH="${NEW_PATH}"
}
rm -f "${unique_path_file}"

echo -e "\e[1;35mHINT: use bin/print-paths to see the ordering of your \$PATH variable.\e[0;0m"

#———————————————————————————————————————————————————————————
# End of PATH modifications
#———————————————————————————————————————————————————————————

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
export V8HOME=$(brew --prefix [email protected])

export CFLAGS="-Wno-error=implicit-function-declaration -Wno-error=no-compound-token-split-by-macro"
Expand All @@ -25,3 +67,6 @@ export RUBY_CPPFLAGS="$CPPFLAGS"
export RUBY_CFLAGS="$CFLAGS"

[[ -f .envrc.local ]] && source .envrc.local



9 changes: 4 additions & 5 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
web: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: yarn watch:css
browser: sleep 10 && open http://localhost:5000/ && while true; do sleep 100; echo .; done
css: yarn watch:css
web: env RUBY_DEBUG_OPEN=true bin/rails server -p 3000
js: yarn watch:js --verbose
css: yarn watch:css --verbose
browser: sleep 10 && open http://localhost:3000/ && while true; do sleep 100; echo .; done
6 changes: 6 additions & 0 deletions bin/print-paths
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# vim: ft=bash
# Prints current paths in the $PATH variable

source development/shell-lib.sh
path.dirs.by-line
2 changes: 1 addition & 1 deletion bin/shchk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ command -v shellcheck >/dev/null || {
fi
}

shellcheck -a --color -x bin/boot-up bin/start
shellcheck -s bash -a --color -x bin/boot-up bin/start development/*.sh

code=$?

Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module FnF
# rubocop: disable Rails/Output
class Seeds
unless defined?(SITE_ADMIN_PASSWORD)
SITE_ADMIN_PASSWORD = 'fubar'
SITE_ADMIN_PASSWORD = 'fubar!'
SITE_ADMIN_EMAIL = '[email protected]'
DEFAULT_USER_COUNT = 10
DEFAULT_EVENT_COUNT = 2
Expand Down
26 changes: 26 additions & 0 deletions development/shell-lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# vim: ft=bash

declare shell_dir
export shell_dir="${root_dir:=$(pwd -P)}/development"

# shellcheck source=./shell/is-loaded.sh
source "${shell_dir}/shell/is-loaded.sh"

function unload.helpers() {
unload.file utils
unload.file array
unload.file path
}

unload.helpers

# shellcheck source=./shell/utils.sh
source "${shell_dir}/shell/utils.sh"

# shellcheck source=./shell/array.sh
source "${shell_dir}/shell/array.sh"

# shellcheck source=./shell/path.sh
source "${shell_dir}/shell/path.sh"

Loading
Loading