language

package
v1.23.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package language provides project file discovery and dependency management for multi-language hook scripts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJavaScriptExecutor

func NewJavaScriptExecutor(
	commandRunner exec.CommandRunner,
	nodeCli node.Cli,
) tools.HookExecutor

NewJavaScriptExecutor creates a JavaScript HookExecutor. Takes only IoC-injectable deps.

func NewPythonExecutor

func NewPythonExecutor(
	commandRunner exec.CommandRunner,
	pythonCli *python.Cli,
) tools.HookExecutor

NewPythonExecutor creates a Python HookExecutor. Takes only IoC-injectable deps.

func NewTypeScriptExecutor

func NewTypeScriptExecutor(
	commandRunner exec.CommandRunner,
	nodeCli node.Cli,
) tools.HookExecutor

NewTypeScriptExecutor creates a TypeScript HookExecutor. Takes only IoC-injectable deps.

Types

type HookKind

type HookKind string

HookKind identifies the executor type of a hook script. The string value matches the token users write in the "kind" field of azure.yaml hook configurations.

const (
	// HookKindUnknown indicates the kind could not be
	// determined from the file extension or explicit configuration.
	HookKindUnknown HookKind = ""
	// HookKindBash identifies Bash shell scripts (.sh files).
	HookKindBash HookKind = "sh"
	// HookKindPowerShell identifies PowerShell scripts (.ps1 files).
	HookKindPowerShell HookKind = "pwsh"
	// HookKindJavaScript identifies JavaScript scripts (.js files).
	HookKindJavaScript HookKind = "js"
	// HookKindTypeScript identifies TypeScript scripts (.ts files).
	HookKindTypeScript HookKind = "ts"
	// HookKindPython identifies Python scripts (.py files).
	HookKindPython HookKind = "python"
	// HookKindDotNet identifies .NET (C#) scripts (.cs files).
	// Not yet supported — IoC resolution will fail with a descriptive error.
	HookKindDotNet HookKind = "dotnet"
)

func InferKindFromPath

func InferKindFromPath(path string) HookKind

InferKindFromPath determines the HookKind from the file extension of the given path. Extension matching is case-insensitive. The following extensions are recognized:

Returns HookKindUnknown for unrecognized extensions.

func (HookKind) IsShell

func (k HookKind) IsShell() bool

IsShell reports whether k is one of the built-in shell kinds (Bash or PowerShell). Shell hooks support inline scripts and are executed directly by the OS shell. Non-shell kinds (Python, JS, TS, DotNet) require a file on disk and are executed through dedicated tools.HookExecutor implementations.

type ProjectContext

type ProjectContext struct {
	// ProjectDir is the directory containing the project file.
	ProjectDir string
	// DependencyFile is the absolute path to the dependency file
	// (e.g. requirements.txt, package.json, *.csproj).
	DependencyFile string
	// Language is the hook kind inferred from the project file.
	Language HookKind
}

ProjectContext holds metadata about a discovered project file, used to determine how to install dependencies for a hook script.

func DiscoverNodeProject

func DiscoverNodeProject(
	scriptPath string, boundaryDir string,
) (*ProjectContext, error)

DiscoverNodeProject walks up the directory tree from the directory containing scriptPath, looking specifically for package.json.

Unlike DiscoverProjectFile which searches for all known project files in priority order, this function only matches package.json. This avoids false negatives in mixed-language directories where a Python project file (higher priority in the generic list) would shadow the Node.js project file.

The search stops at boundaryDir. Returns nil without error when no package.json is found.

func DiscoverProjectFile

func DiscoverProjectFile(
	scriptPath string, boundaryDir string,
) (*ProjectContext, error)

DiscoverProjectFile walks up the directory tree from the directory containing scriptPath, looking for known project files to infer the project context for dependency installation.

The search stops at boundaryDir to prevent path traversal outside the project or service root. Returns nil without error when no project file is found — hooks can still run without project context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL