@adrifer/winix 0.3.0-preview.5 → 0.3.0-preview.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ import { powerShellLiteral } from "../../helpers/utils.js";
2
+ export function npmRegistryProperties(entries) {
3
+ const prelude = `
4
+ $ErrorActionPreference = 'Stop'
5
+ $entries = ConvertFrom-Json -AsHashtable ${powerShellLiteral(JSON.stringify(entries))}
6
+ $path = if ($env:NPM_CONFIG_USERCONFIG) {
7
+ [Environment]::ExpandEnvironmentVariables($env:NPM_CONFIG_USERCONFIG)
8
+ } else { Join-Path ([Environment]::GetFolderPath('UserProfile')) '.npmrc' }
9
+ if (-not [IO.Path]::IsPathFullyQualified($path)) { throw 'npm userconfig must be an absolute path' }
10
+ if (Test-Path -LiteralPath $path) {
11
+ if ((Get-Item -LiteralPath $path -Force).Attributes -band [IO.FileAttributes]::ReparsePoint) {
12
+ throw 'npm userconfig is a symlink; configure its source file explicitly instead'
13
+ }
14
+ }
15
+ function Read-WinixNpmConfig {
16
+ if (-not (Test-Path -LiteralPath $path)) { return '' }
17
+ return [IO.File]::ReadAllText($path, [Text.UTF8Encoding]::new($false, $true))
18
+ }
19
+ function Get-WinixNpmKey([string]$line) {
20
+ if ($line -match '^\\s*([^#;=\\s]+)\\s*=') { return $Matches[1] }
21
+ return ''
22
+ }
23
+ function Test-WinixNpmConfig([string]$text) {
24
+ foreach ($key in $entries.Keys) {
25
+ $matching = @($text -split '\\r?\\n' | Where-Object { (Get-WinixNpmKey $_) -ceq $key })
26
+ if ($matching.Count -ne 1) { return $false }
27
+ if (($matching[0] -split '=', 2)[1].Trim() -cne $entries[$key]) { return $false }
28
+ }
29
+ return $true
30
+ }`;
31
+ return {
32
+ getScript: `${prelude}\n@{ InDesiredState = (Test-WinixNpmConfig (Read-WinixNpmConfig)) }`,
33
+ testScript: `${prelude}\nTest-WinixNpmConfig (Read-WinixNpmConfig)`,
34
+ setScript: `${prelude}
35
+ $original = Read-WinixNpmConfig
36
+ if (Test-WinixNpmConfig $original) { return }
37
+ $newline = if ($original.Contains("\`r\`n")) { "\`r\`n" } else { "\`n" }
38
+ $lines = [Collections.Generic.List[string]]::new()
39
+ foreach ($line in ($original -split '\\r?\\n')) {
40
+ if (-not $entries.ContainsKey((Get-WinixNpmKey $line))) { $lines.Add($line) }
41
+ }
42
+ if ($lines.Count -gt 0 -and $lines[$lines.Count - 1] -eq '') { $lines.RemoveAt($lines.Count - 1) }
43
+ foreach ($key in ($entries.Keys | Sort-Object)) { $lines.Add("$key=$($entries[$key])") }
44
+ $next = ($lines -join $newline) + $newline
45
+ $parent = [IO.Path]::GetDirectoryName($path)
46
+ [IO.Directory]::CreateDirectory($parent) | Out-Null
47
+ $temporary = Join-Path $parent ('.winix-npm-' + [guid]::NewGuid().ToString() + '.tmp')
48
+ try {
49
+ [IO.File]::WriteAllText($temporary, $next, [Text.UTF8Encoding]::new($false))
50
+ if ((Read-WinixNpmConfig) -cne $original) { throw 'npm userconfig changed during activation; rerun' }
51
+ if (Test-Path -LiteralPath $path) {
52
+ if ((Get-Item -LiteralPath $path -Force).Attributes -band [IO.FileAttributes]::ReparsePoint) { throw 'npm userconfig became a link' }
53
+ [IO.File]::Replace($temporary, $path, [NullString]::Value)
54
+ } else { [IO.File]::Move($temporary, $path, $false) }
55
+ } finally {
56
+ if (Test-Path -LiteralPath $temporary) { Remove-Item -LiteralPath $temporary -Force }
57
+ }
58
+ if (-not (Test-WinixNpmConfig (Read-WinixNpmConfig))) { throw 'npm registry configuration verification failed' }`,
59
+ };
60
+ }
@@ -0,0 +1,4 @@
1
+ import type { WinDscProperties, WinWallpaper } from "../../types/windows.js";
2
+ import type { PersonalizationRegistryValue } from "../../helpers/windows-personalization.js";
3
+ export declare function personalizationProperties(values: PersonalizationRegistryValue[], autoHide?: boolean): WinDscProperties;
4
+ export declare function wallpaperProperties(wallpaper: WinWallpaper, configDir?: string): WinDscProperties;
@@ -0,0 +1,125 @@
1
+ import { powerShellLiteral as quote } from "../../helpers/utils.js";
2
+ import { filePathExpression, filePathPrelude, resolveWindowsSource } from "../../helpers/windows.js";
3
+ import { windowsSourcePath } from "./paths.js";
4
+ export function personalizationProperties(values, autoHide) {
5
+ const appBar = autoHide === undefined ? "" : `
6
+ if (-not ('WinixAppBarNative' -as [type])) {
7
+ Add-Type @'
8
+ using System;
9
+ using System.Runtime.InteropServices;
10
+ public static class WinixAppBarNative {
11
+ [StructLayout(LayoutKind.Sequential)]
12
+ public struct Data { public uint size; public IntPtr hwnd; public uint message; public uint edge;
13
+ public int left; public int top; public int right; public int bottom; public IntPtr param; }
14
+ [DllImport("shell32.dll")] public static extern UIntPtr SHAppBarMessage(uint message, ref Data data);
15
+ }
16
+ '@
17
+ }
18
+ $appBar = [WinixAppBarNative+Data]::new()
19
+ $appBar.size = [Runtime.InteropServices.Marshal]::SizeOf($appBar)
20
+ `;
21
+ const prelude = `
22
+ $ErrorActionPreference = 'Stop'
23
+ $values = ConvertFrom-Json ${quote(JSON.stringify(values))}
24
+ ${appBar}
25
+ function Test-WinixPersonalization {
26
+ ${autoHide === undefined ? "" : `if ((([WinixAppBarNative]::SHAppBarMessage(4, [ref]$appBar).ToUInt64() -band 1) -ne 0) -ne $${autoHide}) { return $false }`}
27
+ foreach ($item in $values) {
28
+ $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($item.path)
29
+ if ($null -eq $key) { return $false }
30
+ try {
31
+ if ($key.GetValueNames() -notcontains $item.name -or
32
+ $key.GetValueKind($item.name) -ne [Microsoft.Win32.RegistryValueKind]::DWord -or
33
+ ([long]$key.GetValue($item.name) -band 0xffffffffL) -ne [long]$item.value) { return $false }
34
+ } finally { $key.Dispose() }
35
+ }
36
+ return $true
37
+ }`;
38
+ return {
39
+ getScript: `${prelude}\n@{ InDesiredState = (Test-WinixPersonalization) }`,
40
+ testScript: `${prelude}\nTest-WinixPersonalization`,
41
+ setScript: `${prelude}
42
+ if (Test-WinixPersonalization) { return }
43
+ ${autoHide === undefined ? "" : `
44
+ $state = [WinixAppBarNative]::SHAppBarMessage(4, [ref]$appBar).ToUInt64()
45
+ $appBar.param = [IntPtr](($state -band 2) -bor ${autoHide ? 1 : 0})
46
+ [WinixAppBarNative]::SHAppBarMessage(10, [ref]$appBar) | Out-Null
47
+ `}
48
+ foreach ($item in $values) {
49
+ $key = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey($item.path)
50
+ try {
51
+ $signed = [BitConverter]::ToInt32([BitConverter]::GetBytes([uint32]$item.value), 0)
52
+ $key.SetValue($item.name, $signed, [Microsoft.Win32.RegistryValueKind]::DWord)
53
+ } finally { $key.Dispose() }
54
+ }
55
+ if (-not (Test-WinixPersonalization)) { throw 'Windows personalization verification failed' }
56
+ Write-Warning 'Some Explorer/taskbar/theme preferences take effect after signing out. Winix will not restart Explorer.'`,
57
+ };
58
+ }
59
+ export function wallpaperProperties(wallpaper, configDir) {
60
+ const source = typeof wallpaper.source === "string"
61
+ ? resolveWindowsSource(wallpaper.source, configDir, windowsSourcePath) : wallpaper.source;
62
+ const styles = { Fill: [10, 0], Fit: [6, 0], Stretch: [2, 0], Tile: [0, 1], Center: [0, 0], Span: [22, 0] };
63
+ const [style, tile] = styles[wallpaper.style ?? "Fill"];
64
+ const prelude = `${filePathPrelude().join("\n")}
65
+ $ErrorActionPreference = 'Stop'
66
+ $source = ${filePathExpression(source)}
67
+ if (-not (Test-Path -LiteralPath $source -PathType Leaf)) { throw "Wallpaper image does not exist: $source" }
68
+ $hash = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash
69
+ $cache = Join-Path $env:LOCALAPPDATA 'Winix\\wallpapers'
70
+ $target = Join-Path $cache ($hash + [IO.Path]::GetExtension($source))
71
+ $desktop = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Control Panel\\Desktop')
72
+ function Test-WinixWallpaper {
73
+ if ($null -eq $desktop) { return $false }
74
+ $image = [string]$desktop.GetValue('WallPaper', '')
75
+ return (Test-Path -LiteralPath $target -PathType Leaf) -and
76
+ (Get-FileHash -LiteralPath $target -Algorithm SHA256).Hash -eq $hash -and
77
+ $image -eq $target -and
78
+ [string]$desktop.GetValue('WallpaperStyle', '') -eq '${style}' -and
79
+ [string]$desktop.GetValue('TileWallpaper', '') -eq '${tile}'
80
+ }`;
81
+ const dispose = "if ($null -ne $desktop) { $desktop.Dispose() }";
82
+ return {
83
+ getScript: `${prelude}\ntry { @{ InDesiredState = (Test-WinixWallpaper) } } finally { ${dispose} }`,
84
+ testScript: `${prelude}\ntry { Test-WinixWallpaper } finally { ${dispose} }`,
85
+ setScript: `${prelude}
86
+ try { $matches = Test-WinixWallpaper } finally { ${dispose} }
87
+ if ($matches) { return }
88
+ Add-Type -AssemblyName System.Drawing
89
+ $image = [System.Drawing.Image]::FromFile($source)
90
+ try {
91
+ if ($image.Width -lt 1 -or $image.Height -lt 1) { throw 'Invalid wallpaper image' }
92
+ } finally { $image.Dispose() }
93
+ New-Item -ItemType Directory -Path $cache -Force | Out-Null
94
+ if (-not (Test-Path -LiteralPath $target)) { [IO.File]::Copy($source, $target, $false) }
95
+ if ((Get-FileHash -LiteralPath $target -Algorithm SHA256).Hash -ne $hash) { throw 'Wallpaper changed or its cache is corrupt' }
96
+ if (-not ('WinixWallpaperNative' -as [type])) {
97
+ Add-Type @'
98
+ using System;
99
+ using System.Runtime.InteropServices;
100
+ public static class WinixWallpaperNative {
101
+ [DllImport("user32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
102
+ public static extern bool SystemParametersInfo(uint action, uint param, string value, uint flags);
103
+ }
104
+ '@
105
+ }
106
+ $key = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Control Panel\\Desktop')
107
+ try {
108
+ $previousStyle = $key.GetValue('WallpaperStyle', $null)
109
+ $previousTile = $key.GetValue('TileWallpaper', $null)
110
+ $key.SetValue('WallpaperStyle', '${style}', [Microsoft.Win32.RegistryValueKind]::String)
111
+ $key.SetValue('TileWallpaper', '${tile}', [Microsoft.Win32.RegistryValueKind]::String)
112
+ } finally { $key.Dispose() }
113
+ if (-not [WinixWallpaperNative]::SystemParametersInfo(20, 0, $target, 3)) {
114
+ $failure = [System.ComponentModel.Win32Exception]::new([Runtime.InteropServices.Marshal]::GetLastWin32Error())
115
+ $key = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Control Panel\\Desktop')
116
+ try {
117
+ if ($null -eq $previousStyle) { $key.DeleteValue('WallpaperStyle', $false) }
118
+ else { $key.SetValue('WallpaperStyle', $previousStyle, [Microsoft.Win32.RegistryValueKind]::String) }
119
+ if ($null -eq $previousTile) { $key.DeleteValue('TileWallpaper', $false) }
120
+ else { $key.SetValue('TileWallpaper', $previousTile, [Microsoft.Win32.RegistryValueKind]::String) }
121
+ } finally { $key.Dispose() }
122
+ throw $failure
123
+ }`,
124
+ };
125
+ }
@@ -3,7 +3,9 @@ import { type WindowsLock, type WindowsPackageVersionResolver, type WindowsModul
3
3
  import { type WindowsWslImageResolver } from "../../backends/windows/wsl.js";
4
4
  import { type WindowsWslRepositoryResolver } from "../../backends/windows/wsl-setup.js";
5
5
  import { type ActivationPlatform } from "../activation.js";
6
+ import { type WindowsFontResolver } from "../../backends/windows/fonts.js";
6
7
  interface ApplyOptions {
8
+ resolveWindowsFont?: WindowsFontResolver;
7
9
  /** Activation-only overrides; the committed lock and inline declarations remain unchanged. */
8
10
  windowsPackageVersions?: (hosts: ReturnType<typeof evaluate>, lock: WindowsLock) => Promise<Record<string, string>>;
9
11
  host?: string;
@@ -12,6 +12,7 @@ import { resolvePowerShellModuleVersion } from "../../backends/windows/powershel
12
12
  import { resolveNixosWslImage } from "../../backends/windows/wsl.js";
13
13
  import { resolveWslRepository } from "../../backends/windows/wsl-setup.js";
14
14
  import { platformForEvaluatedHost } from "../activation.js";
15
+ import { collectFontSources, resolveWindowsFonts, resolveFontSource } from "../../backends/windows/fonts.js";
15
16
  export async function applyWorkspace(cwd, opts) {
16
17
  const { workspace, configDir } = await loadWorkspace(cwd);
17
18
  let evaluated = evaluate(workspace);
@@ -29,7 +30,7 @@ export async function applyWorkspace(cwd, opts) {
29
30
  for (const host of windowsHosts)
30
31
  validateWindowsWslResources(host.windows);
31
32
  const windowsLock = windowsHosts.length > 0
32
- ? await prepareWindowsLock(configDir, windowsHosts, opts.dry || opts.windowsLockDry === true, opts.resolveWindowsPackageVersion ?? resolveWingetVersion, opts.resolveWindowsModuleVersion ?? resolvePowerShellModuleVersion, opts.resolveWindowsWslImage ?? resolveNixosWslImage, opts.resolveWindowsWslRepository ?? resolveWslRepository)
33
+ ? await prepareWindowsLock(configDir, windowsHosts, opts.dry || opts.windowsLockDry === true, opts.resolveWindowsPackageVersion ?? resolveWingetVersion, opts.resolveWindowsModuleVersion ?? resolvePowerShellModuleVersion, opts.resolveWindowsWslImage ?? resolveNixosWslImage, opts.resolveWindowsWslRepository ?? resolveWslRepository, opts.resolveWindowsFont ?? resolveFontSource)
33
34
  : undefined;
34
35
  const nixOutput = nixHosts.length > 0 ? generateNix(workspace, nixHosts) : undefined;
35
36
  const runtimeVersions = windowsLock && opts.windowsPackageVersions
@@ -91,7 +92,7 @@ export async function applyWorkspace(cwd, opts) {
91
92
  export async function apply(cwd, opts) {
92
93
  await applyWorkspace(cwd, opts);
93
94
  }
94
- async function prepareWindowsLock(configDir, windowsHosts, dry, resolveVersion, resolveModuleVersion, resolveWslImage, resolveRepository) {
95
+ async function prepareWindowsLock(configDir, windowsHosts, dry, resolveVersion, resolveModuleVersion, resolveWslImage, resolveRepository, resolveFont) {
95
96
  const now = new Date();
96
97
  const lock = readWindowsLock(configDir) ?? emptyWindowsLock(now);
97
98
  const reconciled = reconcileInlinePins(lock, windowsHosts, now);
@@ -101,9 +102,10 @@ async function prepareWindowsLock(configDir, windowsHosts, dry, resolveVersion,
101
102
  ? await resolveWindowsWslImages(modules.lock, resolveWslImage, now, true)
102
103
  : { lock: modules.lock, changed: false };
103
104
  const repositories = resolveWindowsWslRepositories(images.lock, windowsHosts, resolveRepository, now, true);
104
- const changed = windowsLockChanged(lock, repositories.lock);
105
+ const fonts = await resolveWindowsFonts(repositories.lock, collectFontSources(windowsHosts).values(), resolveFont, now, true);
106
+ const changed = windowsLockChanged(lock, fonts.lock);
105
107
  if (!changed)
106
- return repositories.lock;
108
+ return fonts.lock;
107
109
  if (dry) {
108
110
  if (windowsLockChanged(lock, resolved.lock))
109
111
  printWindowsLockDryRun(resolved.resolutions);
@@ -113,9 +115,11 @@ async function prepareWindowsLock(configDir, windowsHosts, dry, resolveVersion,
113
115
  console.warn("Would pin verified NixOS-WSL images for x64/arm64 in winix-windows.lock");
114
116
  if (repositories.changed)
115
117
  console.warn("Would pin WSL setup repository commits in winix-windows.lock");
116
- return repositories.lock;
118
+ if (fonts.changed)
119
+ console.warn("Would pin verified font sources in winix-windows.lock");
120
+ return fonts.lock;
117
121
  }
118
- writeWindowsLock(configDir, repositories.lock);
122
+ writeWindowsLock(configDir, fonts.lock);
119
123
  if (windowsLockChanged(lock, resolved.lock))
120
124
  printWindowsLockUpdate(resolved.resolutions);
121
125
  for (const entry of modules.resolutions)
@@ -124,7 +128,9 @@ async function prepareWindowsLock(configDir, windowsHosts, dry, resolveVersion,
124
128
  console.log("✓ Pinned verified NixOS-WSL images for x64/arm64 in winix-windows.lock");
125
129
  if (repositories.changed)
126
130
  console.log("✓ Pinned WSL setup repository commits in winix-windows.lock");
127
- return repositories.lock;
131
+ if (fonts.changed)
132
+ console.log("✓ Pinned verified font sources in winix-windows.lock");
133
+ return fonts.lock;
128
134
  }
129
135
  function printWindowsLockDryRun(resolutions) {
130
136
  if (resolutions.length === 0) {
@@ -1,7 +1,9 @@
1
1
  import { type WindowsPackageVersionResolver, type WindowsModuleVersionResolver } from "../../backends/windows/lockfile.js";
2
2
  import { type WindowsWslImageResolver } from "../../backends/windows/wsl.js";
3
3
  import { type WindowsWslRepositoryResolver } from "../../backends/windows/wsl-setup.js";
4
+ import { type WindowsFontResolver } from "../../backends/windows/fonts.js";
4
5
  interface UpdateOptions {
6
+ resolveWindowsFont?: WindowsFontResolver;
5
7
  inputs: string[];
6
8
  dry: boolean;
7
9
  windows?: boolean;
@@ -12,6 +12,7 @@ import { platformForEvaluatedHost } from "../activation.js";
12
12
  import { loadWorkspace } from "../loader.js";
13
13
  import { runCommand } from "../run.js";
14
14
  import { applyWorkspace } from "./apply.js";
15
+ import { collectFontSources, resolveWindowsFonts, resolveFontSource } from "../../backends/windows/fonts.js";
15
16
  export async function update(cwd, opts) {
16
17
  if (opts.windows) {
17
18
  await updateWindowsLock(cwd, opts);
@@ -75,11 +76,13 @@ async function updateWindowsLock(cwd, opts) {
75
76
  const pinned = collectInlinePinnedPackages(windowsHosts);
76
77
  const floating = collectFloatingPackages(windowsHosts, pinned);
77
78
  const modules = collectWindowsModules(windowsHosts);
79
+ const fonts = collectFontSources(windowsHosts);
78
80
  const wslImages = hasWindowsWslDistros(windowsHosts);
79
81
  const wslSetup = windowsHosts.some((host) => host.windows.dsc?.some((resource) => resource.winix?.kind === "wsl-distro" && resource.winix.distro.setup));
80
82
  for (const id of opts.inputs) {
81
83
  if (!floating.has(id) && !pinned.has(id) &&
82
84
  ![...modules.values()].some((module) => module.name.toLowerCase() === id.toLowerCase()) &&
85
+ !(id === "fonts" && fonts.size > 0) &&
83
86
  !(id === "nixos-wsl" && wslImages) && !(id === "wsl-setup" && wslSetup)) {
84
87
  throw new Error(`Windows package, PowerShell module, WSL image or setup repository "${id}" is not declared in this workspace.`);
85
88
  }
@@ -116,6 +119,12 @@ async function updateWindowsLock(cwd, opts) {
116
119
  changed = changed || repositories.changed;
117
120
  console.log(` ${repositories.changed ? "resolved" : "up to date"} WSL setup repository commits (first-run only)`);
118
121
  }
122
+ if (fonts.size > 0 && (opts.inputs.length === 0 || opts.inputs.includes("fonts"))) {
123
+ const result = await resolveWindowsFonts(lock, fonts.values(), opts.resolveWindowsFont ?? resolveFontSource, now);
124
+ lock = result.lock;
125
+ changed = changed || result.changed;
126
+ console.log(` ${result.changed ? "resolved" : "up to date"} font sources`);
127
+ }
119
128
  for (const resolution of resolved.resolutions) {
120
129
  if (resolution.status === "up-to-date") {
121
130
  console.log(` up to date ${resolution.id} ${resolution.source} ${resolution.version}`);
package/dist/cli/index.js CHANGED
@@ -13,6 +13,7 @@ import { renderSkill } from "../skill.js";
13
13
  import { bootstrapCheckout, runCheckout } from "./commands/bootstrap.js";
14
14
  import { forgetWindowsResource, windowsStatePath, listWindowsOwners, migrateWindowsOwner, windowsStateOwner, } from "./windows-state.js";
15
15
  import { findConfig } from "./loader.js";
16
+ import { nerdFontsCatalog } from "../backends/windows/fonts.js";
16
17
  if (process.argv[2] === "run") {
17
18
  try {
18
19
  await runCheckout(process.cwd(), process.argv.slice(3));
@@ -27,6 +28,7 @@ const { positionals, values } = parseArgs({
27
28
  allowPositionals: true,
28
29
  options: {
29
30
  host: { type: "string" },
31
+ provider: { type: "string" },
30
32
  dry: { type: "boolean", default: false },
31
33
  yes: { type: "boolean", short: "y", default: false },
32
34
  diff: { type: "boolean", default: false },
@@ -67,6 +69,7 @@ Commands:
67
69
  switch Generate output and run the host activation command
68
70
  update Update generated flake.lock and copy it to project root
69
71
  inspect Print host composition and fragment graph
72
+ fonts search [query] --provider nerd-fonts Search official font release IDs
70
73
  state forget Release Windows removal ownership without deleting a resource
71
74
  state owners List Windows applied-state owners and their migration IDs
72
75
  state migrate-owner <id> Transfer an old owner's requirements to this checkout/--host
@@ -110,6 +113,25 @@ if (values.yes && command !== "switch" && command !== "bootstrap" &&
110
113
  process.exit(2);
111
114
  }
112
115
  switch (command) {
116
+ case "fonts":
117
+ try {
118
+ if (positionals[1] !== "search" || positionals.length > 3 || values.provider !== "nerd-fonts") {
119
+ throw new Error("Usage: winix fonts search [query] --provider nerd-fonts");
120
+ }
121
+ const catalog = await nerdFontsCatalog();
122
+ const query = positionals[2]?.toLowerCase() ?? "";
123
+ const fonts = catalog.fonts.filter((font) => font.family.toLowerCase().includes(query));
124
+ if (!fonts.length)
125
+ throw new Error(`No Nerd Fonts IDs match "${query}"`);
126
+ console.log(`Nerd Fonts ${catalog.version} (download IDs, not installed family names):`);
127
+ for (const font of fonts)
128
+ console.log(` ${font.family}`);
129
+ }
130
+ catch (error) {
131
+ console.error(`Error: ${error.message}`);
132
+ process.exit(1);
133
+ }
134
+ break;
113
135
  case "bootstrap":
114
136
  try {
115
137
  await bootstrapCheckout(cwd, {
@@ -0,0 +1,3 @@
1
+ import type { WinNpmRegistryPolicy } from "../types/windows.js";
2
+ export declare function npmRegistryUri(value: string): string;
3
+ export declare function npmRegistryEntries(policy: WinNpmRegistryPolicy): Record<string, string>;
@@ -0,0 +1,52 @@
1
+ export function npmRegistryUri(value) {
2
+ let url;
3
+ try {
4
+ url = new URL(value);
5
+ }
6
+ catch {
7
+ throw new Error("npm registry URI must be an HTTPS URL");
8
+ }
9
+ if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash ||
10
+ /[\0\r\n]/.test(value)) {
11
+ throw new Error("npm registry URI must be HTTPS without credentials, query or fragment");
12
+ }
13
+ return url.href.replace(/\/+$/, "") + "/";
14
+ }
15
+ export function npmRegistryEntries(policy) {
16
+ if (!policy || typeof policy !== "object" || Array.isArray(policy) ||
17
+ !policy.registries || typeof policy.registries !== "object" || Array.isArray(policy.registries) ||
18
+ typeof policy.default !== "string") {
19
+ throw new Error("npm registry policy requires registries and a default registry name");
20
+ }
21
+ for (const key of Object.keys(policy)) {
22
+ if (!["registries", "default", "scopes"].includes(key))
23
+ throw new Error(`Unknown npm registry policy option: ${key}`);
24
+ }
25
+ const registries = new Map();
26
+ for (const [name, entry] of Object.entries(policy.registries)) {
27
+ if (!/^[a-z0-9][a-z0-9._-]*$/i.test(name) || registries.has(name.toLowerCase())) {
28
+ throw new Error(`Invalid or duplicate npm registry name: ${name}`);
29
+ }
30
+ if (!entry || typeof entry.uri !== "string")
31
+ throw new Error(`npm registry "${name}" requires a URI`);
32
+ registries.set(name.toLowerCase(), npmRegistryUri(entry.uri));
33
+ }
34
+ const resolve = (name) => {
35
+ const uri = typeof name === "string" ? registries.get(name.toLowerCase()) : undefined;
36
+ if (!uri)
37
+ throw new Error(`npm registry "${String(name)}" is not declared`);
38
+ return uri;
39
+ };
40
+ const entries = { registry: resolve(policy.default) };
41
+ if (policy.scopes !== undefined) {
42
+ if (!policy.scopes || typeof policy.scopes !== "object" || Array.isArray(policy.scopes)) {
43
+ throw new Error("npm registry scopes must be an object");
44
+ }
45
+ for (const [scope, registry] of Object.entries(policy.scopes)) {
46
+ if (!/^@[a-z0-9][a-z0-9._-]*$/.test(scope))
47
+ throw new Error(`Invalid npm scope: ${scope}`);
48
+ entries[`${scope}:registry`] = resolve(registry);
49
+ }
50
+ }
51
+ return entries;
52
+ }
@@ -0,0 +1,10 @@
1
+ import type { WinFontSource, WinPersonalization, WinWallpaper } from "../types/windows.js";
2
+ export declare function fontHttpsUrl(value: string): string;
3
+ export declare function validateFontSources(sources: WinFontSource[]): void;
4
+ export declare function validateWallpaper(wallpaper: WinWallpaper): void;
5
+ export interface PersonalizationRegistryValue {
6
+ path: string;
7
+ name: string;
8
+ value: number;
9
+ }
10
+ export declare function personalizationValues(options: WinPersonalization): PersonalizationRegistryValue[];
@@ -0,0 +1,140 @@
1
+ export function fontHttpsUrl(value) {
2
+ let url;
3
+ try {
4
+ url = new URL(value);
5
+ }
6
+ catch {
7
+ throw new Error("Font source must be an absolute HTTPS URL");
8
+ }
9
+ if (url.protocol !== "https:" || url.username || url.password || url.hash) {
10
+ throw new Error("Font sources require HTTPS without credentials or fragments");
11
+ }
12
+ return url.href;
13
+ }
14
+ export function validateFontSources(sources) {
15
+ if (!Array.isArray(sources) || sources.length === 0)
16
+ throw new Error("windows.fonts requires nonempty sources");
17
+ for (const source of sources) {
18
+ if (typeof source === "string") {
19
+ if (!source.trim() || /[\0\r\n]/.test(source) || !/\.(ttf|otf)$/i.test(source) || /^https?:/i.test(source)) {
20
+ throw new Error("Local font sources must be TTF/OTF file paths; use { url } for downloads");
21
+ }
22
+ }
23
+ else if (source && typeof source === "object" && "url" in source) {
24
+ fontHttpsUrl(source.url);
25
+ if (source.sha256 !== undefined && !/^[a-f0-9]{64}$/i.test(source.sha256)) {
26
+ throw new Error("Font sha256 must contain 64 hexadecimal characters");
27
+ }
28
+ if (source.files !== undefined && (!Array.isArray(source.files) || source.files.length === 0 ||
29
+ source.files.some((file) => typeof file !== "string" ||
30
+ (!/^\*\*\/\*\.(ttf|otf)$/i.test(file) &&
31
+ (!/^[^:*?\\\0]+?\.(ttf|otf)$/i.test(file) || file.startsWith("/") ||
32
+ file.split("/").some((part) => !part || part === "." || part === "..")))))) {
33
+ throw new Error("Font files must be safe ZIP member names or **/*.ttf / **/*.otf selectors");
34
+ }
35
+ if (!/\.(zip|ttf|otf)$/i.test(new URL(source.url).pathname)) {
36
+ throw new Error("Remote fonts must be a .zip, .ttf or .otf URL");
37
+ }
38
+ if (source.files !== undefined && !/\.zip$/i.test(new URL(source.url).pathname)) {
39
+ throw new Error("Font file selectors are only supported for ZIP sources");
40
+ }
41
+ }
42
+ else if (source && typeof source === "object" && "provider" in source &&
43
+ source.provider === "nerd-fonts") {
44
+ if (!/^[a-z0-9][a-z0-9_-]*$/i.test(source.family) ||
45
+ (source.version !== undefined && !/^v\d+\.\d+\.\d+$/.test(source.version))) {
46
+ throw new Error("Nerd Fonts requires a catalog family ID and an optional vX.Y.Z release tag");
47
+ }
48
+ }
49
+ else {
50
+ throw new Error("Unsupported font source/provider");
51
+ }
52
+ }
53
+ }
54
+ export function validateWallpaper(wallpaper) {
55
+ if (!wallpaper || typeof wallpaper !== "object")
56
+ throw new Error("windows.wallpaper requires an object");
57
+ const source = wallpaper.source;
58
+ if (typeof source === "string") {
59
+ if (!source.trim() || /[\0\r\n]/.test(source) || /^https?:/i.test(source)) {
60
+ throw new Error("Wallpaper requires a local image path");
61
+ }
62
+ }
63
+ else if (!source || source.kind !== "knownFolder" ||
64
+ !["documents", "desktop", "localAppData", "appData", "userProfile"].includes(source.folder) ||
65
+ typeof source.path !== "string" || /[\0\r\n]/.test(source.path) ||
66
+ /^[\\/]|^[a-z]:/i.test(source.path) || source.path.split(/[\\/]/).includes("..")) {
67
+ throw new Error("Wallpaper requires a valid known-folder or local image path");
68
+ }
69
+ if (wallpaper.style !== undefined &&
70
+ !["Fill", "Fit", "Stretch", "Tile", "Center", "Span"].includes(wallpaper.style)) {
71
+ throw new Error("Unsupported wallpaper style");
72
+ }
73
+ }
74
+ export function personalizationValues(options) {
75
+ if (!options || typeof options !== "object" || Array.isArray(options)) {
76
+ throw new Error("windows.personalization requires an object");
77
+ }
78
+ const values = [];
79
+ const advanced = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced";
80
+ const add = (path, name, value) => values.push({ path, name, value });
81
+ for (const key of Object.keys(options)) {
82
+ if (!["accentColor", "explorer", "taskbar"].includes(key))
83
+ throw new Error(`Unknown personalization option ${key}`);
84
+ }
85
+ if (options.accentColor !== undefined) {
86
+ if (!/^#[a-f0-9]{6}$/i.test(options.accentColor))
87
+ throw new Error("accentColor must be #RRGGBB");
88
+ const rgb = options.accentColor.slice(1);
89
+ const bgr = parseInt(`${rgb.slice(4)}${rgb.slice(2, 4)}${rgb.slice(0, 2)}`, 16);
90
+ add("Software\\Microsoft\\Windows\\DWM", "AccentColor", (0xff000000 + bgr) >>> 0);
91
+ add("Software\\Microsoft\\Windows\\DWM", "ColorizationColor", (0xff000000 + parseInt(rgb, 16)) >>> 0);
92
+ add("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", "AccentColorMenu", (0xff000000 + bgr) >>> 0);
93
+ add("Control Panel\\Desktop", "AutoColorization", 0);
94
+ }
95
+ if (options.explorer !== undefined) {
96
+ if (!options.explorer || typeof options.explorer !== "object" || Array.isArray(options.explorer)) {
97
+ throw new Error("explorer personalization must be an object");
98
+ }
99
+ for (const [key, value] of Object.entries(options.explorer)) {
100
+ if (key === "openTo") {
101
+ if (value !== "ThisPC" && value !== "Home")
102
+ throw new Error("explorer.openTo must be ThisPC or Home");
103
+ add(advanced, "LaunchTo", value === "ThisPC" ? 1 : 2);
104
+ }
105
+ else {
106
+ if (!["showExtensions", "showHiddenFiles"].includes(key) || typeof value !== "boolean") {
107
+ throw new Error(`Invalid explorer personalization ${key}`);
108
+ }
109
+ add(advanced, key === "showExtensions" ? "HideFileExt" : "Hidden", key === "showExtensions" ? (value ? 0 : 1) : (value ? 1 : 2));
110
+ }
111
+ }
112
+ }
113
+ if (options.taskbar !== undefined) {
114
+ if (!options.taskbar || typeof options.taskbar !== "object" || Array.isArray(options.taskbar)) {
115
+ throw new Error("taskbar personalization must be an object");
116
+ }
117
+ for (const [key, value] of Object.entries(options.taskbar)) {
118
+ if (key === "autoHide") {
119
+ if (typeof value !== "boolean")
120
+ throw new Error("taskbar.autoHide must be boolean");
121
+ continue;
122
+ }
123
+ if (key === "search") {
124
+ const modes = ["Hidden", "Icon", "Box", "IconAndLabel"];
125
+ if (typeof value !== "string" || !modes.includes(value))
126
+ throw new Error("Invalid taskbar.search mode");
127
+ add("Software\\Microsoft\\Windows\\CurrentVersion\\Search", "SearchboxTaskbarMode", modes.indexOf(value));
128
+ }
129
+ else {
130
+ if (!["taskView", "widgets"].includes(key) || typeof value !== "boolean") {
131
+ throw new Error(`Invalid taskbar personalization ${key}`);
132
+ }
133
+ add(advanced, key === "taskView" ? "ShowTaskViewButton" : "TaskbarDa", value ? 1 : 0);
134
+ }
135
+ }
136
+ }
137
+ if (!values.length && options.taskbar?.autoHide === undefined)
138
+ throw new Error("windows.personalization requires at least one setting");
139
+ return values;
140
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Fragment, ResourceHandle } from "../core/types.js";
2
- import type { WinDscProperties, WinDscResource, WinPackageSource, WinSettings, WinFilePath, WinKnownFolder, WinKnownFolderName, WinStartupCommand, WinWslConfig, WinWslDistro, WinWslSetup, WinPowerShellRepositoryPolicy } from "../types/index.js";
2
+ import type { WinDscProperties, WinDscResource, WinPackageSource, WinSettings, WinFilePath, WinKnownFolder, WinKnownFolderName, WinStartupCommand, WinWslConfig, WinWslDistro, WinWslSetup, WinPowerShellRepositoryPolicy, WinFontSource, WinWallpaper, WinPersonalization } from "../types/index.js";
3
+ import type { WinNpmRegistryPolicy } from "../types/windows.js";
3
4
  /**
4
5
  * Accepted call shapes for `windows.package(...)`.
5
6
  *
@@ -99,6 +100,7 @@ export interface WinFileOpts {
99
100
  }
100
101
  /** Rebuild scripts after the emitter supplies the config directory. */
101
102
  export declare function resolveWindowsFileProperties(resource: WinDscResource, configDir?: string, sourcePath?: (path: string) => string): WinDscProperties | undefined;
103
+ export declare function resolveWindowsSource(original: string, configDir?: string, sourcePath?: (path: string) => string): string;
102
104
  export declare function filePathPrelude(): string[];
103
105
  export interface WinEnvNamespace {
104
106
  set(name: string, value: string, opts?: WinEnvOpts): ResourceHandle;
@@ -115,6 +117,17 @@ export interface WinFileNamespace {
115
117
  remove(target: WinFilePath, opts?: WinFileOpts): ResourceHandle;
116
118
  }
117
119
  export interface WindowsHelper {
120
+ npm: {
121
+ registries(policy: WinNpmRegistryPolicy): Fragment;
122
+ };
123
+ fonts(spec: {
124
+ sources: WinFontSource[];
125
+ dependsOn?: ResourceHandle | ResourceHandle[];
126
+ }): ResourceHandle;
127
+ wallpaper(spec: WinWallpaper & {
128
+ dependsOn?: ResourceHandle | ResourceHandle[];
129
+ }): ResourceHandle;
130
+ personalization(options: WinPersonalization, opts?: WinSettingOpts): ResourceHandle;
118
131
  optionalFeature(name: string, opts?: WinOptionalFeatureOpts): ResourceHandle;
119
132
  wsl: WinWslNamespace;
120
133
  /** Manage named current-user Startup shortcuts without running the commands during apply. */