2023-08-10 19:34:38 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Run a command with our local yarn install, rather than any globally installed
|
|
|
|
# instance.
|
2022-07-22 01:58:50 +01:00
|
|
|
|
2023-08-10 19:34:38 +01:00
|
|
|
set -euo pipefail
|
2022-07-22 01:58:50 +01:00
|
|
|
|
2023-08-10 19:34:38 +01:00
|
|
|
if [[ "${CI:-}" == "true" ]]; then
|
|
|
|
set -x
|
2022-07-22 01:58:50 +01:00
|
|
|
fi
|
|
|
|
|
2023-08-10 19:34:38 +01:00
|
|
|
(
|
|
|
|
if [[ "${CI:-}" == "true" ]]; then
|
|
|
|
set -x
|
|
|
|
fi
|
2022-07-22 01:58:50 +01:00
|
|
|
|
2023-08-10 19:34:38 +01:00
|
|
|
repo_root="${BASH_SOURCE%/*}/../"
|
|
|
|
cd "$repo_root"
|
2022-07-22 01:58:50 +01:00
|
|
|
|
2023-08-10 19:34:38 +01:00
|
|
|
./tool/node --version >/dev/null # Ensure node is unpacked and ready
|
2022-07-22 01:58:50 +01:00
|
|
|
|
2023-08-10 19:34:38 +01:00
|
|
|
cachedir="$HOME/.cache/tailscale-yarn"
|
|
|
|
tarball="${cachedir}.tar.gz"
|
2022-07-22 01:58:50 +01:00
|
|
|
|
2023-08-22 00:37:54 +01:00
|
|
|
read -r want_rev < "./tool/yarn.rev"
|
2022-07-22 01:58:50 +01:00
|
|
|
|
2023-08-10 19:34:38 +01:00
|
|
|
got_rev=""
|
|
|
|
if [[ -x "${cachedir}/bin/yarn" ]]; then
|
|
|
|
got_rev=$(PATH="$HOME/.cache/tailscale-node/bin:$PATH" "${cachedir}/bin/yarn" --version)
|
2022-07-22 01:58:50 +01:00
|
|
|
fi
|
|
|
|
|
2023-08-10 19:34:38 +01:00
|
|
|
if [[ "$want_rev" != "$got_rev" ]]; then
|
|
|
|
rm -rf "$cachedir" "$tarball"
|
|
|
|
mkdir -p "$cachedir"
|
|
|
|
curl -f -L -o "$tarball" "https://github.com/yarnpkg/yarn/releases/download/v${want_rev}/yarn-v${want_rev}.tar.gz"
|
|
|
|
(cd "$cachedir" && tar --strip-components=1 -xf "$tarball")
|
|
|
|
rm -f "$tarball"
|
|
|
|
fi
|
|
|
|
)
|
2022-07-22 01:58:50 +01:00
|
|
|
|
2023-08-10 19:34:38 +01:00
|
|
|
# Deliberately not using cachedir here, to keep the environment
|
|
|
|
# completely pristine for execution of yarn.
|
|
|
|
export PATH="$HOME/.cache/tailscale-node/bin:$HOME/.cache/tailscale-yarn/bin:$PATH"
|
|
|
|
exec "$HOME/.cache/tailscale-yarn/bin/yarn" "$@"
|