Skip to content

Add packageManager config to JS/TS hook executors #7692

@wbreza

Description

@wbreza

Add packageManager config to JS/TS hook executors

Background & Motivation
Users running JS/TS hooks need to use the same package manager as their project (pnpm, yarn). Today the hook executor auto-detects from lock files but provides no override, unlike the framework service which supports ServiceConfig.Config["packageManager"]. This creates a parity gap between service configuration and hook configuration.

User Story
As a developer using pnpm/yarn, I want to specify packageManager in my hook config so that my JS/TS hooks use the correct package manager without relying on lock file detection.

Solution Approach

  • Read Config["packageManager"] in JS/TS executor Prepare() phase via execCtx.Config
  • Reuse existing packageManagerFromConfig() validation pattern from framework_service_node.go
  • Pass override to node.NewCliWithPackageManager() instead of auto-detecting
  • Applies to both js_executor.go and ts_executor.go (shared via node_helpers.go)
  • Define a strongly-typed nodeHookConfig struct and unmarshal from execCtx.Config:
    type nodeHookConfig struct {
        PackageManager string `json:"packageManager"` // npm, pnpm, yarn
    }
  • Accepted values: npm, pnpm, yarn (same as ServiceConfig)

Example azure.yaml

hooks:
  postprovision:
    run: ./hooks/setup.ts
    kind: ts
    config:
      packageManager: pnpm

Acceptance Criteria

  • config.packageManager: pnpm causes JS/TS hooks to use pnpm for install
  • config.packageManager: yarn causes JS/TS hooks to use yarn for install
  • Omitting packageManager preserves current auto-detection behavior (lock file → default npm)
  • Invalid values (e.g., bun) produce a clear error message
  • Config is unmarshalled into a strongly-typed struct (not raw map access)
  • Unit tests covering override, fallback, and invalid value cases

Default when omitted: Auto-detect from lock files (existing behavior)

Out of Scope

  • Custom install flags (e.g., --no-audit) — future enhancement
  • TypeScript runtime selection (tsRuntime) — separate P1 issue
  • Bun or Deno support — not currently supported in azd

Testing Expectations

  • Unit tests: table-driven tests for config unmarshalling, validation, and CLI selection
  • Test that override beats auto-detection when both are present
  • Test invalid/malformed config values

Constraints

  • Must match the same packageManager values accepted by ServiceConfig.Config for consistency

Related Issues

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions