-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
dependencies.sh
120 lines (102 loc) · 3.01 KB
/
dependencies.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
111
112
113
114
115
116
117
118
119
120
measure_size() {
echo "$((du -s node_modules 2>/dev/null || echo 0) | awk '{print $1}')"
}
list_dependencies() {
local build_dir="$1"
cd "$build_dir"
if $YARN; then
echo ""
(yarn list --depth=0 || true) 2>/dev/null
echo ""
else
(npm ls --depth=0 | tail -n +2 || true) 2>/dev/null
fi
}
run_if_present() {
local script_name=${1:-}
local has_script=$(read_json "$BUILD_DIR/package.json" ".scripts[\"$script_name\"]")
if [ -n "$has_script" ]; then
if $YARN; then
echo "Running $script_name (yarn)"
yarn run "$script_name"
else
echo "Running $script_name"
npm run "$script_name" --if-present
fi
fi
}
log_build_scripts() {
local build=$(read_json "$BUILD_DIR/package.json" ".scripts[\"build\"]")
local heroku_prebuild=$(read_json "$BUILD_DIR/package.json" ".scripts[\"heroku-prebuild\"]")
local heroku_postbuild=$(read_json "$BUILD_DIR/package.json" ".scripts[\"heroku-postbuild\"]")
if [ -n "$build" ]; then
mcount "scripts.build"
if [ -z "$heroku_postbuild" ]; then
mcount "scripts.build-without-heroku-postbuild"
fi
fi
if [ -n "$heroku_prebuild" ]; then
mcount "scripts.heroku-prebuild"
fi
if [ -n "$heroku_postbuild" ]; then
mcount "scripts.heroku-postbuild"
fi
if [ -n "$heroku_postbuild" ] && [ -n "$build" ]; then
mcount "scripts.build-and-heroku-postbuild"
if [ "$heroku_postbuild" != "$build" ]; then
mcount "scripts.different-build-and-heroku-postbuild"
fi
fi
}
yarn_supports_frozen_lockfile() {
local yarn_version="$(yarn --version)"
# Yarn versions lower than 0.19 will crash if passed --frozen-lockfile
if [[ "$yarn_version" =~ ^0\.(16|17|18).*$ ]]; then
mcount "yarn.doesnt-support-frozen-lockfile"
false
else
true
fi
}
yarn_node_modules() {
local build_dir=${1:-}
echo "Installing node modules (yarn.lock)"
cd "$build_dir"
if yarn_supports_frozen_lockfile; then
yarn install --frozen-lockfile --ignore-engines 2>&1
else
yarn install --pure-lockfile --ignore-engines 2>&1
fi
}
npm_node_modules() {
local build_dir=${1:-}
if [ -e $build_dir/package.json ]; then
cd $build_dir
if [ -e $build_dir/package-lock.json ]; then
echo "Installing node modules (package.json + package-lock)"
elif [ -e $build_dir/npm-shrinkwrap.json ]; then
echo "Installing node modules (package.json + shrinkwrap)"
else
echo "Installing node modules (package.json)"
fi
npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
else
echo "Skipping (no package.json)"
fi
}
npm_rebuild() {
local build_dir=${1:-}
if [ -e $build_dir/package.json ]; then
cd $build_dir
echo "Rebuilding any native modules"
npm rebuild 2>&1
if [ -e $build_dir/npm-shrinkwrap.json ]; then
echo "Installing any new modules (package.json + shrinkwrap)"
else
echo "Installing any new modules (package.json)"
fi
npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
else
echo "Skipping (no package.json)"
fi
}