Skip to content

Commit f28e845

Browse files
committed
chore: wip
1 parent d571f47 commit f28e845

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

.vscode/dictionary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ bunfig
66
bunx
77
changelogen
88
changelogithub
9+
chpwd
910
chrisbbreuer
1011
codecov
1112
commitlint
@@ -24,6 +25,7 @@ openweb
2425
outdir
2526
pausable
2627
Postcardware
28+
precmd
2729
prefetch
2830
preinstall
2931
quickfix

packages/launchpad/src/dev/shellcode.ts

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ __lp_prepend_path() {
5555
# Ensure Launchpad global bin is on PATH early (for globally installed tools)
5656
__lp_prepend_path "$HOME/.local/share/launchpad/global/bin"
5757
58-
# Portable timeout helper: uses timeout, gtimeout (macOS), or no-timeout fallback
59-
lp_timeout() {
60-
local duration="$1"; shift
61-
if command -v timeout >/dev/null 2>&1; then
62-
timeout "$duration" "$@"
63-
elif command -v gtimeout >/dev/null 2>&1; then
64-
gtimeout "$duration" "$@"
65-
else
66-
"$@"
67-
fi
68-
}
69-
7058
# Portable current time in milliseconds
7159
lp_now_ms() {
7260
if [[ -n "$ZSH_VERSION" && -n "$EPOCHREALTIME" ]]; then
@@ -188,10 +176,10 @@ __launchpad_switch_environment() {
188176
printf "⏱️ [0ms] Shell integration started for PWD=%s\\n" "$PWD" >&2
189177
fi
190178
191-
# Step 1: Find project directory using our fast binary (with portable timeout)
179+
# Step 1: Find project directory using our fast binary (no artificial timeout)
192180
local project_dir=""
193-
if lp_timeout 1s ${launchpadBinary} dev:find-project-root "$PWD" >/dev/null 2>&1; then
194-
project_dir=$(LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 lp_timeout 1s ${launchpadBinary} dev:find-project-root "$PWD" 2>/dev/null || echo "")
181+
if ${launchpadBinary} dev:find-project-root "$PWD" >/dev/null 2>&1; then
182+
project_dir=$(LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 ${launchpadBinary} dev:find-project-root "$PWD" 2>/dev/null || echo "")
195183
fi
196184
197185
# Verbose: show project detection result
@@ -278,7 +266,7 @@ __launchpad_switch_environment() {
278266
if [[ -n "$project_dir" ]]; then
279267
local project_basename=$(basename "$project_dir")
280268
# Use proper MD5 hash to match existing environments
281-
local md5hash=$(printf "%s" "$project_dir" | LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 lp_timeout 2s ${launchpadBinary} dev:md5 /dev/stdin 2>/dev/null || echo "00000000")
269+
local md5hash=$(printf "%s" "$project_dir" | LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 ${launchpadBinary} dev:md5 /dev/stdin 2>/dev/null || echo "00000000")
282270
local project_hash="\${project_basename}_$(echo "$md5hash" | cut -c1-8)"
283271
284272
# Check for dependency file to add dependency hash
@@ -292,10 +280,10 @@ __launchpad_switch_environment() {
292280
293281
local env_dir="$HOME/.local/share/launchpad/envs/$project_hash"
294282
if [[ -n "$dep_file" ]]; then
295-
local dep_short=$(LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 lp_timeout 2s ${launchpadBinary} dev:md5 "$dep_file" 2>/dev/null | cut -c1-8 || echo "")
296-
if [[ -n "$dep_short" ]]; then
297-
env_dir="\${env_dir}-d\${dep_short}"
298-
fi
283+
local dep_short=$(LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 ${launchpadBinary} dev:md5 "$dep_file" 2>/dev/null | cut -c1-8 || echo "")
284+
if [[ -n "$dep_short" ]]; then
285+
env_dir="\${env_dir}-d\${dep_short}"
286+
fi
299287
fi
300288
301289
# Check if we're switching projects
@@ -330,28 +318,44 @@ __launchpad_switch_environment() {
330318
printf "✅ Activated environment: %s\n" "$env_dir" >&2
331319
fi
332320
else
333-
# Install dependencies synchronously but with timeout to avoid hanging
334-
# Use LAUNCHPAD_SHELL_INTEGRATION=1 to enable proper progress display
335-
if LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 LAUNCHPAD_SHELL_INTEGRATION=1 lp_timeout 30s ${launchpadBinary} install "$project_dir"; then
336-
if [[ "$verbose_mode" == "true" ]]; then
337-
printf "📦 Installed project dependencies (on-demand)\n" >&2
321+
# Non-blocking on-demand install with retry backoff (no artificial timeout)
322+
local cache_dir="$HOME/.cache/launchpad/shell_cache"
323+
mkdir -p "$cache_dir" 2>/dev/null || true
324+
local backoff_marker="$cache_dir/install_backoff_$(echo "$env_dir" | sed 's/\//_/g')"
325+
326+
local now_s=$(date +%s 2>/dev/null || echo 0)
327+
local retry_after=600 # 10 minutes
328+
local should_attempt=1
329+
if [[ -f "$backoff_marker" ]]; then
330+
local mtime=$(date -r "$backoff_marker" +%s 2>/dev/null || echo 0)
331+
if [[ $(( now_s - mtime )) -lt $retry_after ]]; then
332+
should_attempt=0
338333
fi
339-
# If install succeeded, try to activate the environment
340-
if [[ -d "$env_dir/bin" ]]; then
341-
export LAUNCHPAD_CURRENT_PROJECT="$project_dir"
342-
export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
343-
export PATH="$env_dir/bin:$PATH"
334+
fi
344335
345-
# Show activation message if enabled
346-
if [[ "${showMessages}" == "true" ]]; then
347-
printf "${activationMessage}\\n" >&2
336+
if [[ "$should_attempt" -eq 1 ]]; then
337+
: > "$backoff_marker" 2>/dev/null || true
338+
if LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 LAUNCHPAD_SHELL_INTEGRATION=1 ${launchpadBinary} install "$project_dir"; then
339+
if [[ -d "$env_dir/bin" ]]; then
340+
export LAUNCHPAD_CURRENT_PROJECT="$project_dir"
341+
export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
342+
export PATH="$env_dir/bin:$PATH"
343+
if [[ "${showMessages}" == "true" ]]; then
344+
printf "${activationMessage}\\n" >&2
345+
fi
346+
if [[ "$verbose_mode" == "true" && "$__lp_should_verbose_print" == "1" ]]; then
347+
printf "✅ Activated environment after install: %s\n" "$env_dir" >&2
348+
fi
348349
fi
349-
350-
# Verbose: show activated env path after install
350+
else
351351
if [[ "$verbose_mode" == "true" && "$__lp_should_verbose_print" == "1" ]]; then
352-
printf "✅ Activated environment after install: %s\n" "$env_dir" >&2
352+
printf "⏭️ Deferred on-demand install. Run 'launchpad install %q' manually.\n" "$project_dir" >&2
353353
fi
354354
fi
355+
else
356+
if [[ "$verbose_mode" == "true" && "$__lp_should_verbose_print" == "1" ]]; then
357+
printf "⏳ Install backoff active; not attempting on-demand install.\n" >&2
358+
fi
355359
fi
356360
fi
357361
fi

0 commit comments

Comments
 (0)