Skip to content

feat: per-DependencyType default options under PSDependOptions - #207

Open
HeyItsGilbert wants to merge 1 commit into
mainfrom
feat/per-type-psdependoptions-defaults
Open

HeyItsGilbert wants to merge 1 commit into
mainfrom
feat/per-type-psdependoptions-defaults

Conversation

@HeyItsGilbert

Copy link
Copy Markdown
Member

Summary

Resolve-DependencyOption(Name, DependencyType)
  if Dependency's own value is set
    return it
  else if PSDependOptions[DependencyType][Name] exists   # per-type default
    return it
  else
    return PSDependOptions[Name]                         # global default
PSDependOptions = @{
    Target = 'C:\temp'            # global default (existing)
    Git    = @{ Target = 'C:\temp\git' }   # NEW: per-type default
}

A PSDependOptions key is read as a per-type block only when its value is a
hashtable and its name isn't one of the 9 reserved scalar option names
(Source, Target, Parameters, AddToPath, Tags, DependsOn,
PreScripts, PostScripts, Credential) — so a DependencyType can never
be named one of those.

 PSDepend/Public/Get-Dependency.ps1
-  function Get-GlobalOption { ... }            # global vs per-dependency only
+  function Resolve-DependencyOption { ... }     # + per-type tier, reserved-name guard
+  # Parse-Dependency: tracks $UsedDependencyTypes, warns on typo'd per-type blocks
 docs/adr/0003-per-type-dependency-options.md    # NEW: design record
 CONTEXT.md                                      # + Global default / Per-type default terms
 Tests/PSDepend.Tests.ps1                        # + 6 tests
 CHANGELOG.md                                    # + Unreleased entry

Closes #42.

Evidence

  • Before: no per-type tier existed — PSDependOptions only supported a
    single global default per option, shared across every DependencyType in
    the file (544 tests passing on main).
    After: ./build.ps1 full suite — 550 passed, 0 failed (6 new tests:
    cascade precedence, whole-value override vs. deep merge, the typo warning,
    and per-type Credential resolution for the bare PSGalleryModule syntax).

Merge Danger

Door: Two-way. Purely additive: a PSDependOptions key is only read as a
per-type block when it's a hashtable keyed by an actual DependencyType
name, so every existing .depend.psd1/requirements.psd1 file parses
identically to before. The Get-GlobalOption → Resolve-DependencyOption
rename is a private, unexported function (verified with a repo-wide grep)
with no external callers.

Blast Radius: Core. Get-Dependency is the entry point every public
cmdlet (Invoke-PSDepend, Install-Dependency, lock resolution, etc.) goes
through, so a resolution bug here would be widely felt — mitigated by the
cascade only activating on the new nested-hashtable syntax and the full
regression suite passing unchanged.

- Adds a 3-tier option cascade: a Dependency's own value overrides a
  per-type default (a nested hashtable under PSDependOptions keyed by
  DependencyType) overrides the existing global default.
- Renames the private Get-GlobalOption helper to Resolve-DependencyOption
  to reflect its widened responsibility.
- Warns (non-fatal) when a per-type block names a DependencyType no
  Dependency in the file uses.
- No lock-format change needed: resolution happens before a parsed
  Dependency reaches Resolve-PSDependLock/Merge-PSDependLock.
- Adds docs/adr/0003-per-type-dependency-options.md, merges the new
  Global default / Per-type default terms into CONTEXT.md, updates
  comment-based help and about_PSDepend_Definitions.help.txt, and adds
  a CHANGELOG entry.
- 6 new Pester tests covering the cascade, whole-value override (not a
  deep merge), the typo warning, and per-type Credential resolution.

Fixes #42
Copilot AI balanced review requested due to automatic review settings November 25, 2026 22:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Explicit dependency syntax drops configured credentials, breaking authenticated repository requests, and an explicit AddToPath=false is ignored when the per-type default is true.

2 open issues
What changed in this PR

Adds per-DependencyType defaults to PSDependOptions, addressing #42 by introducing a middle tier between global defaults and dependency-specific values in the core parser.

Changes:

  • Adds per-type option resolution and warnings for unused per-type blocks.
  • Adds six tests covering precedence, whole-value overrides, warnings, and credential resolution.
  • Documents the syntax, reserved option names, and design decisions.
File Description
Tests/​PSDepend.Tests.ps1 Adds six tests for per-type defaults.
PSDepend/​Public/​Get-Dependency.ps1 Implements the resolution tier and unused-block warnings.
PSDepend/​en-US/​about_PSDepend_Definitions.help.txt Documents per-type syntax and reserved names.
docs/​adr/​0003-per-type-dependency-options.md Records cascade and whole-value override decisions.
CONTEXT.md Defines global and per-type default terminology.
CHANGELOG.md Announces the feature under Unreleased.

Review effort: Balanced

Tags = Resolve-DependencyOption -Name Tags -DependencyType $SplitDependencyType
DependsOn = Resolve-DependencyOption -Name DependsOn -DependencyType $SplitDependencyType
PreScripts = Resolve-DependencyOption -Name PreScripts -DependencyType $SplitDependencyType
PostScripts = Resolve-DependencyOption -Name PostScripts -DependencyType $SplitDependencyType
Parameters = Resolve-DependencyOption -Name Parameters -DependencyType $DependencyType -Prefer $DependencyHash.Parameters
Source = Resolve-DependencyOption -Name Source -DependencyType $DependencyType -Prefer $DependencyHash.Source
Target = Resolve-DependencyOption -Name Target -DependencyType $DependencyType -Prefer $DependencyHash.Target
AddToPath = Resolve-DependencyOption -Name AddToPath -DependencyType $DependencyType -Prefer $DependencyHash.AddToPath
@github-actions

Copy link
Copy Markdown

Test Results

    3 files     90 suites   2m 23s ⏱️
1 343 tests 1 283 ✅ 60 💤 0 ❌
1 848 runs  1 778 ✅ 70 💤 0 ❌

Results for commit 4e6ad6c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Per-DependencyType default options

2 participants