@adrifer/winix 0.2.2 → 0.2.4-preview.0

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.
Files changed (40) hide show
  1. package/README.md +374 -2
  2. package/dist/backends/windows/index.d.ts +3 -1
  3. package/dist/backends/windows/index.js +99 -7
  4. package/dist/backends/windows/lockfile.d.ts +36 -1
  5. package/dist/backends/windows/lockfile.js +168 -0
  6. package/dist/backends/windows/paths.d.ts +2 -0
  7. package/dist/backends/windows/paths.js +17 -0
  8. package/dist/backends/windows/powershell.d.ts +6 -0
  9. package/dist/backends/windows/powershell.js +51 -0
  10. package/dist/backends/windows/wsl-setup-runtime.d.ts +32 -0
  11. package/dist/backends/windows/wsl-setup-runtime.js +387 -0
  12. package/dist/backends/windows/wsl-setup.d.ts +12 -0
  13. package/dist/backends/windows/wsl-setup.js +108 -0
  14. package/dist/backends/windows/wsl.d.ts +9 -0
  15. package/dist/backends/windows/wsl.js +194 -0
  16. package/dist/cli/commands/apply.d.ts +7 -1
  17. package/dist/cli/commands/apply.js +39 -15
  18. package/dist/cli/commands/check.js +3 -0
  19. package/dist/cli/commands/init.js +2 -0
  20. package/dist/cli/commands/install.d.ts +7 -0
  21. package/dist/cli/commands/install.js +41 -0
  22. package/dist/cli/commands/switch.d.ts +6 -0
  23. package/dist/cli/commands/switch.js +53 -13
  24. package/dist/cli/commands/update.d.ts +6 -1
  25. package/dist/cli/commands/update.js +41 -10
  26. package/dist/cli/index.js +65 -3
  27. package/dist/cli/windows-state.d.ts +56 -0
  28. package/dist/cli/windows-state.js +341 -0
  29. package/dist/helpers/index.d.ts +1 -1
  30. package/dist/helpers/utils.d.ts +1 -0
  31. package/dist/helpers/utils.js +8 -0
  32. package/dist/helpers/windows.d.ts +53 -7
  33. package/dist/helpers/windows.js +351 -28
  34. package/dist/index.d.ts +4 -2
  35. package/dist/skill.d.ts +2 -0
  36. package/dist/skill.js +503 -0
  37. package/dist/types/windows.d.ts +82 -1
  38. package/package.json +3 -1
  39. package/scripts/bootstrap-nixos.sh +51 -0
  40. package/scripts/bootstrap-windows.ps1 +216 -0
@@ -0,0 +1,216 @@
1
+ #Requires -Version 5.1
2
+ <#
3
+ .SYNOPSIS
4
+ Checks or installs the Windows prerequisites for Winix, without activating a host.
5
+ .PARAMETER Check
6
+ Only inspect prerequisites. No installation or configuration enablement is performed.
7
+ .PARAMETER Yes
8
+ Accept prerequisite installation and WinGet configuration enablement without prompting.
9
+ .PARAMETER UseNvm
10
+ Install/select Node LTS through NVM for Windows instead of standalone Node.js.
11
+ #>
12
+ [CmdletBinding()]
13
+ param(
14
+ [switch]$Check,
15
+ [switch]$Yes,
16
+ [switch]$UseNvm
17
+ )
18
+
19
+ function Get-WinixBootstrapApplication {
20
+ param([string]$Name)
21
+ $application = Get-Command $Name -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
22
+ if ($application) { return $application.Source }
23
+ return $null
24
+ }
25
+
26
+ function Invoke-WinixBootstrapNative {
27
+ param([string]$FilePath, [string[]]$Arguments)
28
+ $output = @(& $FilePath @Arguments)
29
+ $code = $LASTEXITCODE
30
+ if ($code -ne 0) {
31
+ if ($code -eq 3010 -or $code -eq 1641) {
32
+ throw 'An installer requires a restart. Restart Windows yourself, then rerun the bootstrap.'
33
+ }
34
+ throw ("Command failed ({0}, exit {1}): {2}`n{3}" -f $FilePath, $code, ($Arguments -join ' '), ($output -join "`n"))
35
+ }
36
+ return $output
37
+ }
38
+
39
+ function Update-WinixBootstrapPath {
40
+ foreach ($name in @('NVM_HOME', 'NVM_SYMLINK')) {
41
+ $value = [Environment]::GetEnvironmentVariable($name, 'User')
42
+ if (-not $value) { $value = [Environment]::GetEnvironmentVariable($name, 'Machine') }
43
+ if ($value) { [Environment]::SetEnvironmentVariable($name, $value, 'Process') }
44
+ }
45
+ $paths = @(
46
+ $env:Path
47
+ [Environment]::GetEnvironmentVariable('Path', 'Machine')
48
+ [Environment]::GetEnvironmentVariable('Path', 'User')
49
+ (Join-Path ([Environment]::GetFolderPath('LocalApplicationData')) 'Microsoft\WindowsApps')
50
+ )
51
+ $env:Path = (($paths -join ';').Split(';') |
52
+ Where-Object { $_ } |
53
+ ForEach-Object { [Environment]::ExpandEnvironmentVariables($_.Trim().Trim('"')) } |
54
+ Select-Object -Unique) -join ';'
55
+ }
56
+
57
+ function Get-WinixBootstrapTools {
58
+ $tools = @(
59
+ @{ Id = 'Git.Git'; Command = 'git.exe'; Minimum = '2.0.0' }
60
+ @{ Id = 'OpenJS.NodeJS.LTS'; Command = 'node.exe'; Minimum = '22.13.0' }
61
+ @{ Id = 'Microsoft.PowerShell'; Command = 'pwsh.exe'; Minimum = '7.4.0' }
62
+ @{ Id = 'Microsoft.DSC'; Command = 'dsc.exe'; Minimum = '3.2.0' }
63
+ )
64
+ foreach ($tool in $tools) {
65
+ $path = Get-WinixBootstrapApplication $tool.Command
66
+ $version = $null
67
+ if ($path) {
68
+ $text = (Invoke-WinixBootstrapNative $path @('--version')) -join "`n"
69
+ if ($text -notmatch '(\d+\.\d+\.\d+)') {
70
+ throw "Cannot parse $($tool.Command) version: $text"
71
+ }
72
+ $version = [version]$Matches[1]
73
+ if ($text -match '(?i)-(preview|rc|alpha|beta)') {
74
+ throw "Prerelease $($tool.Command) is not supported by this bootstrap. Install a stable release."
75
+ }
76
+ }
77
+ [pscustomobject]@{
78
+ Id = $tool.Id
79
+ Command = $tool.Command
80
+ Path = $path
81
+ Version = $version
82
+ Ready = $null -ne $version -and $version -ge [version]$tool.Minimum
83
+ Minimum = $tool.Minimum
84
+ }
85
+ }
86
+ }
87
+
88
+ function Test-WinixBootstrapCapabilities {
89
+ param([string]$WinGet)
90
+ $help = (Invoke-WinixBootstrapNative $WinGet @('configure', '--help')) -join "`n"
91
+ if ($help -notmatch '--enable\b') {
92
+ throw 'Update App Installer from Microsoft Store: this WinGet lacks configuration enablement support.'
93
+ }
94
+ $npm = Get-WinixBootstrapApplication 'npm.cmd'
95
+ if (-not $npm) { throw 'npm.cmd is unavailable. Repair the Node.js installation or open a new terminal, then rerun.' }
96
+ Invoke-WinixBootstrapNative $npm @('--version') | Out-Null
97
+ $node = Get-WinixBootstrapApplication 'node.exe'
98
+ Invoke-WinixBootstrapNative $node @(
99
+ '--experimental-transform-types', '--no-warnings', '--input-type=module', '--eval',
100
+ "import { stripTypeScriptTypes } from 'node:module'; stripTypeScriptTypes('const x: number = 1');"
101
+ ) | Out-Null
102
+ $pwsh = Get-WinixBootstrapApplication 'pwsh.exe'
103
+ $script = @'
104
+ $ErrorActionPreference = 'Stop'
105
+ Get-Command Find-PSResource, Install-PSResource -ErrorAction Stop | Out-Null
106
+ Get-PSResourceRepository -Name PSGallery -ErrorAction Stop | Out-Null
107
+ '@
108
+ $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($script))
109
+ Invoke-WinixBootstrapNative $pwsh @('-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', $encoded) | Out-Null
110
+ $dsc = Get-WinixBootstrapApplication 'dsc.exe'
111
+ foreach ($name in @(
112
+ 'Microsoft.WinGet/Package',
113
+ 'Microsoft.DSC.Transitional/PowerShellScript',
114
+ 'Microsoft.DSC.Transitional/RunCommandOnSet',
115
+ 'Microsoft.Windows/Registry'
116
+ )) {
117
+ $lines = @(Invoke-WinixBootstrapNative $dsc @('resource', 'list', $name, '--output-format', 'json'))
118
+ $found = @($lines | Where-Object { $_.Trim() } | ForEach-Object { $_ | ConvertFrom-Json })
119
+ if ($found.Count -ne 1 -or $found[0].type -ne $name) {
120
+ throw "Required DSC resource is unavailable: $name. Update App Installer/DSC, open a new terminal, and rerun."
121
+ }
122
+ }
123
+ Write-Host 'OK: npm, Node TypeScript support, PSResourceGet/PSGallery, and required DSC resources.'
124
+ }
125
+
126
+ function Invoke-WinixWindowsBootstrap {
127
+ param([switch]$Check, [switch]$Yes, [switch]$UseNvm)
128
+ $ErrorActionPreference = 'Stop'
129
+ if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) {
130
+ throw 'This bootstrap is for native Windows, not WSL. Run it from Windows PowerShell or PowerShell 7.'
131
+ }
132
+ Update-WinixBootstrapPath
133
+ $winget = Get-WinixBootstrapApplication 'winget.exe'
134
+ if (-not $winget) {
135
+ throw @'
136
+ WinGet is unavailable. Install/update App Installer from https://apps.microsoft.com/detail/9nblggh4nns1 and open a new terminal.
137
+ If App Installer is already installed but not registered after first sign-in, run:
138
+ Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
139
+ Then rerun this bootstrap. No prerequisites have been installed.
140
+ '@
141
+ }
142
+ Write-Host ("WinGet: " + ((Invoke-WinixBootstrapNative $winget @('--version')) -join ' '))
143
+ $tools = @(Get-WinixBootstrapTools)
144
+ foreach ($tool in $tools) {
145
+ $installed = if ($tool.Version) { $tool.Version.ToString() } else { 'missing' }
146
+ $status = if ($tool.Ready) { 'OK' } else { 'NEEDED' }
147
+ Write-Host ("{0}: {1} {2} (minimum {3})" -f $status, $tool.Command, $installed, $tool.Minimum)
148
+ }
149
+ $pending = @($tools | Where-Object { -not $_.Ready })
150
+ if ($Check) {
151
+ if ($pending.Count -gt 0) {
152
+ throw 'Prerequisites are missing or too old. Rerun without -Check to install/upgrade the listed packages.'
153
+ }
154
+ } else {
155
+ $node = $pending | Where-Object { $_.Command -eq 'node.exe' }
156
+ $nvm = Get-WinixBootstrapApplication 'nvm.exe'
157
+ if ($node -and $nvm -and -not $UseNvm) {
158
+ throw 'NVM for Windows is already installed. Rerun with -UseNvm; standalone Node would conflict with its symlink.'
159
+ }
160
+ if ($node -and $UseNvm -and $node.Path -and -not $nvm) {
161
+ throw 'Existing Node.js needs upgrading but NVM is absent. Repair/upgrade the existing Node installation or deliberately remove it before choosing -UseNvm.'
162
+ }
163
+ Write-Host 'This will install/upgrade only NEEDED packages and enable WinGet configuration support (requires Store access).'
164
+ if ($node -and $UseNvm) {
165
+ Write-Host 'Node.js will use CoreyButler.NVMforWindows plus nvm install lts / nvm use lts; selecting Node may require elevation.'
166
+ }
167
+ Write-Host 'Installers may request UAC elevation. No host configuration, WSL setup, or reboot is performed.'
168
+ if (-not $Yes) {
169
+ if ([Console]::IsInputRedirected) { throw 'Noninteractive bootstrap requires -Yes; use -Check for inspection only.' }
170
+ $answer = Read-Host 'Continue with bootstrap? [y/N]'
171
+ if ($answer.Trim() -notmatch '^(?i:y|yes)$') { throw 'Bootstrap cancelled. No installation or enablement was performed.' }
172
+ }
173
+ foreach ($tool in $pending) {
174
+ if ($tool.Command -eq 'node.exe' -and $UseNvm) {
175
+ if (-not $nvm) {
176
+ Invoke-WinixBootstrapNative $winget @(
177
+ 'install', '--id', 'CoreyButler.NVMforWindows', '--exact', '--source', 'winget',
178
+ '--silent', '--accept-package-agreements', '--accept-source-agreements', '--disable-interactivity'
179
+ ) | ForEach-Object { Write-Host $_ }
180
+ Update-WinixBootstrapPath
181
+ $nvm = Get-WinixBootstrapApplication 'nvm.exe'
182
+ if (-not $nvm) { throw 'NVM is not on PATH yet. Open a new terminal and rerun with -UseNvm.' }
183
+ }
184
+ Invoke-WinixBootstrapNative $nvm @('install', 'lts') | ForEach-Object { Write-Host $_ }
185
+ Invoke-WinixBootstrapNative $nvm @('use', 'lts') | ForEach-Object { Write-Host $_ }
186
+ } else {
187
+ $operation = if ($tool.Path) { 'upgrade' } else { 'install' }
188
+ Write-Host "$operation $($tool.Id)"
189
+ Invoke-WinixBootstrapNative $winget @(
190
+ $operation, '--id', $tool.Id, '--exact', '--source', 'winget',
191
+ '--silent', '--accept-package-agreements', '--accept-source-agreements', '--disable-interactivity'
192
+ ) | ForEach-Object { Write-Host $_ }
193
+ }
194
+ Update-WinixBootstrapPath
195
+ $updated = @(Get-WinixBootstrapTools | Where-Object { $_.Id -eq $tool.Id })
196
+ if ($updated.Count -ne 1 -or -not $updated[0].Ready) {
197
+ throw "Installation did not make $($tool.Command) ready. Open a new terminal or restart if requested, then rerun."
198
+ }
199
+ }
200
+ Invoke-WinixBootstrapNative $winget @('configure', '--enable', '--disable-interactivity') |
201
+ ForEach-Object { Write-Host $_ }
202
+ Update-WinixBootstrapPath
203
+ }
204
+ Test-WinixBootstrapCapabilities $winget
205
+ Write-Host 'Prerequisite checks passed. No Winix host was activated.'
206
+ Write-Host 'Open a new PowerShell 7 terminal before preparing the Winix/config checkout and running winix check or switch --dry.'
207
+ }
208
+
209
+ if ($MyInvocation.InvocationName -ne '.') {
210
+ try {
211
+ Invoke-WinixWindowsBootstrap -Check:$Check -Yes:$Yes -UseNvm:$UseNvm
212
+ } catch {
213
+ Write-Error $_ -ErrorAction Continue
214
+ exit 1
215
+ }
216
+ }