-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
environment.sh
110 lines (94 loc) · 2.76 KB
/
environment.sh
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
get_os() {
uname | tr '[:upper:]' '[:lower:]'
}
get_cpu() {
if [[ "$(uname -p)" = "i686" ]]; then
echo "x86"
else
echo "x64"
fi
}
get_platform() {
os=$(get_os)
cpu=$(get_cpu)
echo "$os-$cpu"
}
create_default_env() {
local YARN=$1
export NPM_CONFIG_LOGLEVEL=${NPM_CONFIG_LOGLEVEL:-error}
export NODE_MODULES_CACHE=${NODE_MODULES_CACHE:-true}
export NODE_ENV=${NODE_ENV:-production}
export NODE_VERBOSE=${NODE_VERBOSE:-false}
if $YARN; then
export USE_YARN_CACHE=${USE_YARN_CACHE:-true}
fi
if [[ -n "$USE_NPM_INSTALL" ]]; then
export USE_NPM_INSTALL=${USE_NPM_INSTALL}
fi
}
create_build_env() {
# if the user hasn't set NODE_OPTIONS, increase the default amount of space
# that a node process can address to match that of the build dynos (2.5GB)
if [[ -z $NODE_OPTIONS ]]; then
export NODE_OPTIONS="--max_old_space_size=2560"
fi
}
list_node_config() {
echo ""
printenv | grep ^NPM_CONFIG_ || true
printenv | grep ^YARN_ || true
printenv | grep ^USE_NPM_ || true
printenv | grep ^USE_YARN_ || true
printenv | grep ^NODE_ || true
if [ "$NPM_CONFIG_PRODUCTION" = "true" ] && [ "$NODE_ENV" != "production" ]; then
echo ""
echo "npm scripts will see NODE_ENV=production (not '${NODE_ENV}')"
echo "https://docs.npmjs.com/misc/config#production"
fi
if [ "$NPM_CONFIG_PRODUCTION" == "true" ]; then
mcount "npm-config-production-true"
elif [ "$NPM_CONFIG_PRODUCTION" == "false" ]; then
mcount "npm-config-production-false"
fi
}
export_env_dir() {
local env_dir=$1
if [ -d "$env_dir" ]; then
local whitelist_regex=${2:-''}
local blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH|LANG|BUILD_DIR)$'}
# shellcheck disable=SC2164
pushd "$env_dir" >/dev/null
for e in *; do
[ -e "$e" ] || continue
echo "$e" | grep -E "$whitelist_regex" | grep -qvE "$blacklist_regex" &&
export "$e=$(cat "$e")"
:
done
# shellcheck disable=SC2164
popd >/dev/null
fi
}
write_profile() {
local bp_dir="$1"
local build_dir="$2"
mkdir -p "$build_dir/.profile.d"
cp "$bp_dir"/profile/* "$build_dir/.profile.d/"
}
write_ci_profile() {
local bp_dir="$1"
local build_dir="$2"
write_profile "$1" "$2"
cp "$bp_dir"/ci-profile/* "$build_dir/.profile.d/"
}
write_export() {
local bp_dir="$1"
local build_dir="$2"
# only write the export script if the buildpack directory is writable.
# this may occur in situations outside of Heroku, such as running the
# buildpacks locally.
if [ -w "$bp_dir" ]; then
echo "export PATH=\"$build_dir/.heroku/node/bin:$build_dir/.heroku/yarn/bin:\$PATH:$build_dir/node_modules/.bin\"" > "$bp_dir/export"
echo "export NODE_HOME=\"$build_dir/.heroku/node\"" >> "$bp_dir/export"
fi
}