Repository navigation
Expand file tree
/
Copy path.bb-env-setup.sh
More file actions
executable file
·66 lines (57 loc) · 1.69 KB
/
Copy path.bb-env-setup.sh
File metadata and controls
executable file
·66 lines (57 loc) · 1.69 KB
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
#!/usr/bin/env sh
set -u
log() {
printf '%s\n' "[bb-env-setup] $*"
}
run_step() {
step_name="$1"
shift
log "Running: ${step_name}"
if "$@"; then
log "Completed: ${step_name}"
return 0
else
exit_code=$?
log "Warning: ${step_name} failed (exit ${exit_code}); continuing provisioning"
return 1
fi
}
# Hash of the inputs that decide what `pnpm install` would do. Stored inside
# node_modules so it travels with an installed tree (copy-on-write
# environments) and disappears with it (fresh worktrees).
INSTALL_STAMP="node_modules/.bb-env-setup-install-hash"
INSTALL_INPUTS="pnpm-lock.yaml pnpm-workspace.yaml package.json .npmrc"
install_inputs_hash() {
if command -v sha256sum >/dev/null 2>&1; then
hash_cmd="sha256sum"
elif command -v shasum >/dev/null 2>&1; then
hash_cmd="shasum -a 256"
else
return 1
fi
for input in ${INSTALL_INPUTS}; do
if [ -f "${input}" ]; then
printf '%s\n' "${input}"
${hash_cmd} < "${input}"
fi
done | ${hash_cmd} | cut -d ' ' -f 1
}
if ! command -v pnpm >/dev/null 2>&1; then
log "Warning: pnpm is not available; skipping install/build"
exit 0
fi
if [ ! -f package.json ]; then
log "Warning: package.json not found; skipping install/build"
exit 0
fi
current_hash="$(install_inputs_hash 2>/dev/null || true)"
if [ -n "${current_hash}" ] && [ -f "${INSTALL_STAMP}" ] && [ -d node_modules/.pnpm ]; then
if [ "$(cat "${INSTALL_STAMP}" 2>/dev/null)" = "${current_hash}" ]; then
log "Skipping pnpm install: node_modules already matches the lockfile"
exit 0
fi
fi
if run_step "pnpm install" pnpm install && [ -n "${current_hash}" ]; then
printf '%s\n' "${current_hash}" > "${INSTALL_STAMP}"
fi
exit 0