forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-dependencies.sh
executable file
·84 lines (70 loc) · 2.51 KB
/
update-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
#!/bin/bash
set -euo pipefail
export NODE_OPTIONS="--max-old-space-size=4096 ${NODE_OPTIONS:-}"
#----------------------------------------------------------------------
# PARSE ARGS
mode="semver"
while [[ $# -gt 0 ]]; do
case $1 in
-m|--mode)
mode="$2"
shift
;;
-h|--help)
echo "Usage: update-dependencies [--mode semver|full]" >&2
exit 1
;;
*)
echo "Unrecognized argument: $1" >&2
exit 1
;;
esac
shift
done
if [[ $mode != 'semver' && $mode != 'full' ]]; then
echo "--mode should be 'semver' or 'full'" >&2
exit 1
fi
#----------------------------------------------------------------------
# MAIN
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# Hide all local packages from all package.jsons so nothing is going to touch
# them while updating. Don't do relative URLs because otherwise transitive
# dependencies will be cached in every individual package.
echo ">> Hiding local package.json references."
$script_dir/swizzle-package-json.py hide
restore_package_jsons() {
echo ">> Restoring package.json references."
$script_dir/swizzle-package-json.py restore
}
# If we abort early, don't forget to reset package.jsons
trap restore_package_jsons EXIT
echo "Updating dependencies using --mode $mode"
case $mode in
semver)
# NPM update respects semver
npm update --dev
npx lerna exec -- npm update --dev
;;
full)
# Sometimes package-lock.json and node_modules contains detritus that causes problems.
# Get rid of it them completely.
npx -p npm-check-updates ncu -x @types/node -u && rm -Rf package-lock.json node_modules && npm install && npm install --save-dev @types/node@8 && npm audit fix
npx lerna exec -- npx -p npm-check-updates ncu -x @types/node -u
npx lerna exec -- rm -Rf package-lock.json node_modules
npx lerna exec -- npm install
npx lerna exec -- npm audit fix
;;
esac
# Restore package.jsons to original versioned references, restored removed
# symlinks using lerna.
restore_package_jsons
trap '' EXIT
npx lerna link
echo "DONE. Doing a validating build..."
npx lerna run --stream build
# Doing a full test. Must do it here instead of per-package since our tooling
# makes a number of assumptions on the format of package.json which does not
# include supporting "file:..." references.
echo "DONE. Doing a validation test run..."
npx lerna run --stream test