feat: add JavaScript and TypeScript hook executors#7626
Conversation
There was a problem hiding this comment.
Pull request overview
Adds JavaScript and TypeScript hook execution support to azd’s multi-language hooks system by introducing Node-based executors (JS via node, TS via npx tsx) and wiring them into the IoC container and documentation, along with unit + E2E test coverage.
Changes:
- Add JS/TS hook executors and shared Node preparation/run-args helpers.
- Register new executors in IoC and test containers; expand runner messaging and docs for JS/TS hooks.
- Add comprehensive unit tests for helpers/executors and E2E-style tests for hook pipeline behavior.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| cli/azd/pkg/tools/language/js_executor.go | New JavaScript hook executor (Prepare via Node helper, Execute via node). |
| cli/azd/pkg/tools/language/ts_executor.go | New TypeScript hook executor (Prepare via Node helper, Execute via npx --yes tsx --). |
| cli/azd/pkg/tools/language/node_helpers.go | Shared Node runtime validation + package.json discovery + dependency install + run-args builder. |
| cli/azd/pkg/tools/language/js_executor_test.go | Unit tests for JS executor behavior. |
| cli/azd/pkg/tools/language/ts_executor_test.go | Unit tests for TS executor behavior. |
| cli/azd/pkg/tools/language/node_helpers_test.go | Unit tests for Node shared helper behavior. |
| cli/azd/pkg/tools/language/executor.go | Update HookKind comments now that JS/TS are supported. |
| cli/azd/cmd/container.go | Register JS/TS hook executors in the main IoC container. |
| cli/azd/test/mocks/mocktools/hook_executors.go | Register node CLI + JS/TS executors in mock IoC container for tests. |
| cli/azd/pkg/ext/hooks_runner.go | Update supported hook kinds suggestion text to include js/ts. |
| cli/azd/pkg/ext/js_hooks_e2e_test.go | Add E2E-style tests for JS hooks through HooksRunner pipeline. |
| cli/azd/pkg/ext/ts_hooks_e2e_test.go | Add E2E-style tests for TS hooks through HooksRunner pipeline. |
| cli/azd/docs/language-hooks.md | Document JS/TS hooks, configuration examples, and limitations. |
| cli/azd/.vscode/cspell.yaml | Add “npx” and “tsx” to spelling allowlist. |
| cli/azd/extensions/azure.ai.agents/version.txt | Bump extension version. |
| cli/azd/extensions/azure.ai.agents/extension.yaml | Keep extension.yaml version in sync with version.txt. |
| cli/azd/extensions/azure.ai.agents/CHANGELOG.md | Add changelog entries for the bumped extension version. |
Implements JavaScript (Phase 2) and TypeScript (Phase 3) hook executors for the multi-language hooks system. Both executors follow the HookExecutor interface (Prepare/Execute/Cleanup) and reuse existing node.Cli for package manager detection and dependency installation. - JavaScript executor: auto-detects package.json, runs `node script.js` - TypeScript executor: uses `npx tsx` for zero-config TS execution - Shared Node.js helpers to keep JS/TS DRY - IoC registration for "js" and "ts" hook kinds - Unit and E2E tests for both executors - Documentation updates for JS/TS hooks Closes Azure#7621 Closes Azure#7622 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add Node-specific project discovery to handle mixed-language projects - Preserve rich error context from CheckInstalled (ErrSemver passthrough) - Remove unrelated extension changes from diff Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fff3118 to
cc5de31
Compare
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
jongio
left a comment
There was a problem hiding this comment.
Solid work. The JS/TS executors follow the same Prepare/Execute/Cleanup lifecycle as the Python executor, the nodeTools interface cleanly decouples from concrete node.Cli for testability, and DiscoverNodeProject correctly avoids Python project files shadowing package.json in mixed-language dirs.
The errors.AsType passthrough for rich error context is a nice touch - keeps the upgrade guidance from ErrSemver intact instead of re-wrapping it.
Test coverage is thorough: unit tests for each executor and node helpers, table-driven project discovery tests with boundary cases, and E2E tests through the full HooksRunner pipeline on both JS and TS paths. IoC registration chain verified end-to-end.
- Add language-hooks.md documenting JavaScript and TypeScript hook executor support (Phase 2 and Phase 3). Includes configuration reference, examples for JS/TS hooks with auto-detection, package.json dependency installation, explicit kind, dir overrides, and platform overrides. Also documents the Prepare→Execute→Cleanup lifecycle and known limitations (PR Azure#7626). - Add AZD_DEBUG_MSAL_CACHE debug variable to environment-variables.md. When enabled with --debug, logs MSAL cache metadata to help diagnose stale refresh token issues (PR Azure#7578). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
What Changed
azd hooks now support JavaScript and TypeScript scripts in addition to Python and shell scripts. Users can write
.jsand.tshook scripts that are auto-detected from file extension, with automatic dependency installation frompackage.jsonwhen present. TypeScript scripts execute vianpx tsxfor zero-config execution — no separate compile step ortsconfig.jsonrequired.Before: Only Bash, PowerShell, and Python hooks were supported.
After: Adding a
.jsor.tsfile tohooks/and referencing it inazure.yamljust works:How It Works
Both executors follow the established
HookExecutorinterface (Prepare → Execute → Cleanup) introduced in Phase 1. A sharednodeToolsinterface and helper functions (prepareNodeProject,buildNodeRunArgs) keep the JS and TS implementations DRY — all Node.js runtime validation,package.jsondiscovery, andnpm installlogic lives innode_helpers.goand is composed by both executors. The TypeScript executor usesnpx --yes tsx --for execution, which handles TypeScript natively without requiring a build step. Executors are registered as IoC named transients alongside the existing bash/pwsh/python executors.Issue References
Closes #7621
Closes #7622
Relates to #7435
Notes
hooks_manager.go(validateRuntimes) does not yet check for Node.js — validation occurs during the executor's Prepare phase at execution time.