fix(hooks): revert per-tool hook execution#7509
Merged
Merged
Conversation
Complete the revert of PR jdx#7311 by removing per-tool hook execution from toolset_install.rs (which was refactored from mod.rs in PR jdx#7371). Removes: - HookToolContext import - Per-tool preinstall hook calls - Per-tool postinstall hook calls This restores the original behavior where hooks run once per session rather than once per tool.
This comment was marked as resolved.
This comment was marked as resolved.
After PR jdx#7371 refactored code from mod.rs to toolset_install.rs, the revert inadvertently added back duplicate functions that should only exist in toolset_install.rs. Removes from mod.rs: - init_request_options() - install_all_versions() - install_some_versions() Also cleans up unused imports in both files.
PR jdx#7311 removed the session-wide preinstall/postinstall hooks and replaced them with per-tool hooks. This commit completes the revert by restoring the original session-wide hooks that run once per installation session. This was missed in the initial revert because PR jdx#7371 moved the code from mod.rs to toolset_install.rs after PR jdx#7311, so the git revert didn't automatically restore the removed hooks.
0160bb7 to
69d878e
Compare
4 tasks
jdx
added a commit
that referenced
this pull request
Dec 30, 2025
## Summary Adds environment variables to postinstall hooks to address the use cases from #7255 and #7489 without changing hook timing (avoiding the regression that led to the revert in #7509). ### Problem - **#7255**: Users wanted `MISE_TOOL_NAME` and `MISE_TOOL_VERSION` in hooks for conditional logic - **#7311**: Fixed this by running hooks per-tool, but broke existing workflows - **#7489**: Reported that hooks now ran BEFORE tools were in PATH, breaking `pnpm install`, `bundle install`, etc. - **#7509**: Reverted #7311 entirely ### Solution: Dual Enhancement This PR provides both capabilities without changing when hooks run: **Tool-level postinstall** (runs per-tool immediately after install): ```toml [tools] node = { version = "20", postinstall = "echo $MISE_TOOL_NAME@$MISE_TOOL_VERSION" } ``` - `MISE_TOOL_NAME`: short name of the tool (e.g., "node") - `MISE_TOOL_VERSION`: version installed (e.g., "20.10.0") - `MISE_TOOL_INSTALL_PATH`: path where tool was installed **Global postinstall hook** (runs once after ALL tools installed): ```toml [hooks] postinstall = "echo $MISE_INSTALLED_TOOLS && pnpm install" ``` - `MISE_INSTALLED_TOOLS`: JSON array of installed tools, e.g., `[{"name":"node","version":"20.10.0"}]` - All tools are in PATH at this point ### Why This Works 1. **No timing changes**: Hooks run at the same times as before the revert 2. **Per-tool context**: Available via tool-level postinstall option 3. **Full PATH access**: Global hook still runs after all tools installed 4. **Both use cases supported**: Users choose which mechanism fits their needs ## Test plan - [x] Added `e2e/config/test_hooks_tool_env` - tests tool-level env vars - [x] Added `e2e/config/test_hooks_installed_tools` - tests global hook JSON - [x] Existing hook tests pass (`test_hooks`, `test_hooks_postinstall_env`) - [x] `mise run lint-fix` passes Closes #7255 Closes #7489 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Enables postinstall hooks to receive precise install context without changing hook timing. > > - Tool-level `postinstall` now runs with `MISE_TOOL_NAME`, `MISE_TOOL_VERSION`, and `MISE_TOOL_INSTALL_PATH` (set in `src/backend/mod.rs`) > - Global `postinstall` receives `MISE_INSTALLED_TOOLS` (JSON array) via new hook context plumbing in `src/hooks.rs` and `src/toolset/toolset_install.rs` > - Updates `docs/hooks.md` with examples and env var descriptions > - Adds e2e tests: `e2e/config/test_hooks_tool_env` and `e2e/config/test_hooks_installed_tools` > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 650d8a0. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #7311 aimed to add
MISE_TOOL_NAMEandMISE_TOOL_VERSIONenvironment variables to preinstall/postinstall hooks (fixing #7255). To support this feature, it changed the hooks to execute once per tool installation rather than once after all tools were installed.Unfortunately, this change broke existing workflows in the wild (see #7489). The problem is that postinstall hooks now run before the newly installed tools are available in the PATH. Users commonly use postinstall hooks to run commands like
pnpm installorbundle install, which depend on tools that were just installed by mise. These commands now fail with "command not found" errors because the hooks fire too early in the installation process.Additionally, having hooks execute multiple times (once per tool) rather than once at the end of the installation session is unexpected and causes commands to run redundantly.
This PR reverts commit a319a87 to restore the previous behavior where hooks run once after all installations complete and tools are available in PATH.