feat: add pre/post lifecycle hooks for package.json scripts#231
Merged
branchseer merged 3 commits intomainfrom Mar 12, 2026
Merged
feat: add pre/post lifecycle hooks for package.json scripts#231branchseer merged 3 commits intomainfrom
branchseer merged 3 commits intomainfrom
Conversation
When a package.json script `X` is run, automatically expand `preX` and `postX` scripts (if they exist in the same package) as inline execution items — matching npm's lifecycle hook behavior. - Hooks are expanded at plan time, not as graph dependency edges - Only applies to `PackageJsonScript` tasks; `TaskConfig` tasks are excluded - Extra CLI args are not forwarded to hook scripts - Configurable via `enablePrePostScripts` in the workspace root `vite-task.json` (defaults to `true`) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fengmk2
approved these changes
Mar 12, 2026
When `vt run test` triggers `pretest` as a hook, `pretest` itself does not look for `prepretest`. This matches npm's behavior where lifecycle hooks are always one level deep. Implemented via an `expand_hooks: bool` flag on `PlanContext` that is set to `false` when planning any hook script. Added `prepretest` to the script-hooks test fixture to prove that `vt run test` correctly produces [pretest, test, posttest] without `prepretest`, while `vt run pretest` directly does expand `prepretest`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When a hook script's command is `vt run someScript`, `someScript`'s own pre/post hooks should still be expanded. Previously, the `expand_hooks` flag (which suppresses recursive hook expansion) incorrectly propagated into nested `plan_query_request` calls, preventing `prescriptInHook` from being found when `scriptInHook` was called via `vt run` from a hook. The flag is now a `with_hooks: bool` parameter of `plan_task_as_execution_node` rather than a field on `PlanContext`. `plan_query_request` always passes `true`, correctly scoping the one-level-deep restriction to the single hook call rather than its entire subtree. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.

Summary
Adds npm-style pre/post lifecycle hooks for package.json scripts.
If you have a script named
test, you can now definepretestandposttestscripts that automatically run before and after it — no extra configuration needed:{ "scripts": { "pretest": "docker compose up -d", "test": "vitest run", "posttest": "docker compose down" } }Running
vt run testwill execute all three in order.Behavior
vite-task.jsonvt run test --coverage) are passed to the main script only, not the hookstestrunspretestas a hook,pretestdoes not also runprepretest— matching npm's behaviorenablePrePostScripts: falsein the rootvite-task.jsonTest plan
script-hooks: pre/post hooks run in correct order; extra args not forwarded to hooks; runningpretestdirectly does expandprepretest, butprepretestis not included whenpretestruns as a hook oftestscript-hooks-disabled:enablePrePostScripts: falsesuppresses hooksscript-hooks-task-no-hook: task configs are not expanded with hooks🤖 Generated with Claude Code