Skip to content

Commit b7948c8

Browse files
tigclaude
andcommitted
build: ship only PSTui + Terminal.Gui closure (29MB -> 9MB) (#6)
The build copied the entire Microsoft.PowerShell.SDK publish closure (67 DLLs/~29MB) into the module, minus 3 named files. All of that (SMA, Markdig, Newtonsoft, System.ServiceModel.*, CodeAnalysis, ...) is provided by the PowerShell host in-process, so it was dead weight and a latent assembly- conflict risk. Derive the keep-list from PSTui.deps.json: PSTui's own assemblies plus Terminal.Gui's transitive runtime closure (Terminal.Gui, ColorHelper, Wcwidth, System.IO.Abstractions + TestableIO/Testably, Markdig, TextMateSharp + Grammars, Onigwrap, Microsoft.Extensions.*.Abstractions, JetBrains.Annotations = 16 assemblies/~9MB). Seeded from Terminal.Gui only, since PSTui/PSTui.Models reference System.Management.Automation (host-provided) and would otherwise re-drag the SDK. Also clear stale DLLs at the start of Build. Verified: clean build packages 16 assemblies; module imports; ocgv/shot, F7 functions, and Get-Help all resolve; Terminal.Gui's 658 types load with 0 unresolved references; xUnit 78/78. Refs #6. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 69f1bd0 commit b7948c8

1 file changed

Lines changed: 42 additions & 9 deletions

File tree

‎PSTui.build.ps1‎

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,52 @@ task Clean {
2020

2121
task Build {
2222
New-Item -ItemType Directory -Force ./module | Out-Null
23+
# Clear stale assemblies so iterative builds don't accumulate dropped deps.
24+
Remove-Item -Force ./module/*.dll -ErrorAction SilentlyContinue
2325

2426
Push-Location src/PSTui
2527
Invoke-BuildExec { & dotnet publish --configuration $Configuration --output publish }
26-
27-
# Copy all DLLs except PowerShell SDK dependencies (those are provided by PowerShell itself)
28-
Get-ChildItem "./publish/*.dll" | Where-Object {
29-
$_.Name -notlike "System.Management.Automation.dll" -and
30-
$_.Name -notlike "Microsoft.PowerShell.Commands.Diagnostics.dll" -and
31-
$_.Name -notlike "Microsoft.Management.Infrastructure.CimCmdlets.dll"
32-
} | ForEach-Object {
33-
Copy-Item -Force -Path $_.FullName -Destination ../../module
28+
29+
# Ship only PSTui's own assemblies plus Terminal.Gui's runtime closure.
30+
# Everything else in publish/ comes from the Microsoft.PowerShell.SDK
31+
# package graph and is already provided by the PowerShell host in-process,
32+
# so shipping it would bloat the package (~67 DLLs/29MB -> ~16/9MB) and
33+
# risk assembly conflicts. The keep-list is derived from PSTui.deps.json so
34+
# it stays correct if Terminal.Gui's dependencies change.
35+
$deps = Get-Content -Raw "./publish/PSTui.deps.json" | ConvertFrom-Json
36+
$target = ($deps.targets.PSObject.Properties | Select-Object -First 1).Value
37+
$libs = @{}
38+
foreach ($p in $target.PSObject.Properties) { $libs[($p.Name -split '/')[0]] = $p.Value }
39+
40+
# Transitive closure of Terminal.Gui (deliberately not seeded from PSTui/*,
41+
# which reference System.Management.Automation and would drag in the SDK).
42+
$closure = [System.Collections.Generic.HashSet[string]]::new()
43+
$queue = [System.Collections.Generic.Queue[string]]::new()
44+
$queue.Enqueue('Terminal.Gui')
45+
while ($queue.Count) {
46+
$name = $queue.Dequeue()
47+
if (-not $closure.Add($name)) { continue }
48+
if ($libs[$name].dependencies) {
49+
foreach ($d in $libs[$name].dependencies.PSObject.Properties.Name) { $queue.Enqueue($d) }
50+
}
51+
}
52+
53+
$shipNames = [System.Collections.Generic.HashSet[string]]::new()
54+
foreach ($name in $closure) {
55+
if ($libs[$name].runtime) {
56+
foreach ($rt in $libs[$name].runtime.PSObject.Properties.Name) {
57+
[void]$shipNames.Add([System.IO.Path]::GetFileName($rt))
58+
}
59+
}
3460
}
35-
61+
# PSTui's own assemblies (their System.Management.Automation dependency is host-provided).
62+
[void]$shipNames.Add('PSTui.dll')
63+
[void]$shipNames.Add('PSTui.Models.dll')
64+
65+
$shipped = Get-ChildItem "./publish/*.dll" | Where-Object { $shipNames.Contains($_.Name) }
66+
$shipped | ForEach-Object { Copy-Item -Force -Path $_.FullName -Destination ../../module }
67+
Write-Build Green "Packaged $($shipped.Count) assemblies (PSTui + Terminal.Gui closure)."
68+
3669
# Copy the module manifest
3770
Copy-Item -Force -Path "./publish/PSTui.psd1" -Destination ../../module
3871

0 commit comments

Comments
 (0)