-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.envrc
More file actions
158 lines (135 loc) · 6.42 KB
/
.envrc
File metadata and controls
158 lines (135 loc) · 6.42 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# ============================================================================
# Mantle Development Environment Setup (.envrc)
# ============================================================================
# This file automatically sets up the development environment when you enter
# the project directory. It ensures Node.js, pnpm, and dependencies are ready.
#
# Prerequisites: direnv must be installed and allowed (`direnv allow`)
# ============================================================================
echo "Starting environment loading…"
START_TIME_MS=$(perl -MTime::HiRes=time -e 'printf "%.0f\n", time * 1000')
# ============================================================================
# DIRENV CONFIGURATION
# ============================================================================
# Disable direnv timeout warnings that can appear during long setup operations
# References:
# - https://github.com/direnv/direnv/issues/419#issuecomment-442005962
# - https://direnv.net/man/direnv.toml.1.html#codewarntimeoutcode
export DIRENV_WARN_TIMEOUT=876000h # 100 years in hours (effectively disabled)
# ============================================================================
# NODE VERSION MANAGER (FNM) SETUP
# ============================================================================
# Fast Node Manager (fnm) handles Node.js version switching based on .nvmrc
# Detect operating system for cross-platform fnm path resolution
OS="$(uname -s)"
case "${OS}" in
MINGW* | Win*) OS="Windows" ;;
esac
# Set FNM_PATH based on OS conventions and user preferences
if [ -d "$HOME/.fnm" ]; then
export FNM_PATH="$HOME/.fnm"
elif [ -n "$XDG_DATA_HOME" ]; then
export FNM_PATH="$XDG_DATA_HOME/fnm"
elif [ "$OS" = "Darwin" ]; then
export FNM_PATH="$HOME/Library/Application Support/fnm"
else
export FNM_PATH="$HOME/.local/share/fnm"
fi
# Auto-install fnm if it's not already installed
if ! command -v fnm &> /dev/null || [ -d "$FNM_PATH" ]; then
echo "fnm is not installed. Installing fnm…"
curl -fsSL https://fnm.vercel.app/install | bash -s -- --skip-shell
else
echo "fnm is already installed."
fi
# Add fnm to PATH so we can use it
export PATH="$FNM_PATH:$PATH"
# Initialize fnm environment (sets up shell integration)
eval "$(fnm env)"
# Install the Node.js version specified in .nvmrc
# This ensures everyone uses the same Node.js version
fnm use --install-if-missing
# =============================================================================
# PACKAGE MANAGER SETUP
# =============================================================================
# Enable pnpm support via corepack (ships with Node.js).
#
# NOTE: We intentionally do NOT run `npm update --global npm` here.
# npm updating itself in-place is inherently unsafe — if the process is
# interrupted (Ctrl+C, broken pipe, direnv timeout), it can leave the fnm
# Node installation in a corrupted state with missing modules like
# `add-rm-pkg-deps.js`. The npm version that ships with the Node version
# specified in .nvmrc is sufficient.
#
# If you need a newer corepack, update it explicitly with:
# npm install -g corepack@latest
# outside of direnv, when you can supervise the process.
yes | corepack enable pnpm
# Install the specific pnpm version defined in package.json#packageManager
# This ensures everyone uses the exact same package manager version
yes | corepack install
# ============================================================================
# TELEMETRY AND PRIVACY SETTINGS
# ============================================================================
# Disable telemetry collection for various tools to improve privacy and performance
export DO_NOT_TRACK=1 # Universal opt-out signal
export TURBO_TELEMETRY_DISABLED=1 # Turborepo telemetry
export VERCEL_TELEMETRY_DISABLED=1 # Vercel CLI telemetry
export TURBO_TEAM="ngrok-frontend" # Set Turborepo team for remote caching
[[ -f .envrc.local ]] && source_env .envrc.local
# =============================================================================
# DEPENDENCY INSTALLATION
# =============================================================================
# Install all workspace dependencies
# This includes all apps and packages in the monorepo
pnpm install
# ============================================================================
# ENVIRONMENT READY CONFIRMATION
# ============================================================================
# Display setup completion status and timing information
pnpm_version=$(pnpm --version)
echo -e "\nEnvironment is ready.\nUsing pnpm version: $pnpm_version\n"
END_TIME_MS=$(perl -MTime::HiRes=time -e 'printf "%.0f\n", time * 1000')
ELAPSED_TIME=$(bc <<< "scale=3; ($END_TIME_MS - $START_TIME_MS) / 1000")
echo -e "direnv environment setup took $ELAPSED_TIME s.\n"
# =============================================================================
# WHAT HAPPENS NEXT
# =============================================================================
# After this completes, you can:
# - `pnpm -w run start` - Start the doc site development server
# - `pnpm -w run build` - Build all packages and apps
# - `pnpm -w run test` - Run all tests
# - See AGENT.md for more commands and workflows
# =============================================================================
# ============================================================================
# FIRST-TIME SETUP GUIDANCE
# ============================================================================
# Show helpful next steps only on the first run
FIRST_RUN_MARKER=".direnv-initialized"
if [ ! -f "$FIRST_RUN_MARKER" ]; then
echo "============================================================================"
echo "🎉 Welcome to Mantle! Here's what you can do next:"
echo "============================================================================"
echo ""
echo "📖 Start the documentation site:"
echo " pnpm -w run start"
echo ""
echo "🔨 Build everything:"
echo " pnpm -w run build"
echo ""
echo "🧪 Run tests:"
echo " pnpm -w run test"
echo ""
echo "📋 Check types:"
echo " pnpm -w run typecheck"
echo ""
echo "✨ Format & lint:"
echo " pnpm -w run fmt"
echo ""
echo "📚 Full documentation: https://mantle.ngrok.com"
echo "📄 See README.md and AGENT.md for more details"
echo ""
echo "============================================================================"
# Create marker file to indicate setup has been completed
touch "$FIRST_RUN_MARKER"
fi