@adrifer/winix 0.2.3 → 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 (36) hide show
  1. package/README.md +364 -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/switch.d.ts +6 -0
  20. package/dist/cli/commands/switch.js +53 -13
  21. package/dist/cli/commands/update.d.ts +6 -1
  22. package/dist/cli/commands/update.js +41 -10
  23. package/dist/cli/index.js +33 -2
  24. package/dist/cli/windows-state.d.ts +56 -0
  25. package/dist/cli/windows-state.js +341 -0
  26. package/dist/helpers/index.d.ts +1 -1
  27. package/dist/helpers/utils.d.ts +1 -0
  28. package/dist/helpers/utils.js +8 -0
  29. package/dist/helpers/windows.d.ts +53 -7
  30. package/dist/helpers/windows.js +351 -28
  31. package/dist/index.d.ts +4 -2
  32. package/dist/skill.js +114 -5
  33. package/dist/types/windows.d.ts +82 -1
  34. package/package.json +3 -1
  35. package/scripts/bootstrap-nixos.sh +51 -0
  36. package/scripts/bootstrap-windows.ps1 +216 -0
package/dist/skill.js CHANGED
@@ -266,12 +266,118 @@ Resources return handles that can be passed through \`dependsOn\`.
266
266
  - \`windows.path.add()\` and \`windows.path.remove()\` manage PATH entries.
267
267
  - \`windows.file.text()\`, \`windows.file.symlink()\`,
268
268
  \`windows.file.copy()\`, and \`windows.file.remove()\` manage files.
269
+ - \`windows.startup.command(name, spec)\` manages a named current-user Startup
270
+ shortcut, without running it during apply. Supply executable and optional argv
271
+ arguments, workingDirectory, windowStyle (normal/minimized/maximized),
272
+ dependsOn, backup, and force. Executables may be application names on PATH or
273
+ absolute/environment/known-folder paths. Arguments are literal strings or
274
+ known-folder paths; the default working directory is the user profile.
275
+ Executable and working directory must exist during activation. Replacement
276
+ requires backup or force; backup collisions fail. This is sign-in startup,
277
+ not a service, scheduled task, elevated launch, or all-users startup.
278
+ Native Windows switch tracks created/replaced shortcut ownership and removes
279
+ unchanged owned entries when declarations disappear. Matching pre-existing
280
+ shortcuts remain externally owned.
281
+ - \`windows.knownFolder.documents()\`, \`windows.knownFolder.desktop()\`,
282
+ \`windows.knownFolder.localAppData()\`, \`windows.knownFolder.appData()\`, and
283
+ \`windows.knownFolder.userProfile()\` build typed file targets resolved during
284
+ activation. Each accepts an optional relative child path. File copy/symlink
285
+ sources resolve relative to the directory containing winix.config.ts;
286
+ absolute paths, environment-variable paths, and file URLs are also supported.
287
+ - \`windows.powershell.module()\` declares a current-user PowerShell 7 module
288
+ by name, with optional repository (default PSGallery) and dependsOn.
289
+ Versions are recorded in the modules section of winix-windows.lock, not
290
+ handwritten declarations. PowerShell 7 with PSResourceGet is required for
291
+ resolution and installation.
269
292
  - \`windows.dsc()\` declares an arbitrary DSC resource.
293
+ - \`windows.optionalFeature()\` enables/disables a named Windows optional feature;
294
+ enabled defaults to true. Changes require elevation, never reboot automatically.
295
+ - \`windows.wsl()\` enables the WSL and Virtual Machine Platform features.
296
+ Options are config, backup, force, and dependsOn. The optional config manages
297
+ the full current-user .wslconfig with file overwrite protections; omitting it
298
+ leaves the file untouched. The returned handle covers the complete setup.
299
+ If a reboot is needed, restart Windows manually and rerun switch.
300
+ It never shuts down WSL; restart WSL manually when configuration changes.
301
+ - \`windows.wsl.distro()\` registers a named distro with source "nixos-wsl",
302
+ installLocation, optional default and dependsOn. Declare windows.wsl() and the
303
+ Microsoft.WSL package in the same host; features, config, and runtime become
304
+ automatic dependencies.
305
+ Images for x64/ARM64 are verified against winix-windows.lock wslImages pins.
306
+ Update with winix update --windows nixos-wsl. Updates never reinstall an
307
+ existing distro. Conflicting/unrecorded distros are refused, not adopted.
308
+ Removing a declaration never unregisters a distro or deletes its data.
309
+ Optional setup opts into trusted first-run Linux provisioning:
310
+ { repository: "https://github.com/example/dotfiles.git", ref: "main",
311
+ configDirectory: "winix", host: "wsl-work", user: "alice",
312
+ checkout: "/home/alice/dotfiles" }.
313
+ Repository URLs must be HTTPS without credentials; authentication must already
314
+ work inside Linux. Commit package.json, package-lock.json and flake.lock in
315
+ configDirectory and use a released SDK supporting setup. The Linux host must
316
+ explicitly enable/import NixOS-WSL, declare system.stateVersion, and match the
317
+ distro architecture. user selects a declared normal account (inferred from
318
+ Home Manager or the sole normal account when omitted); checkout defaults to
319
+ its home/dotfiles and must remain inside that home. Home Manager identity/home
320
+ must agree. Git/npm/config evaluation run unprivileged; root activates the
321
+ account-only bootstrap, assigns checkout ownership, then activates the full
322
+ Linux host, which must set wsl.defaultUser to that account. No password or
323
+ sudo policy is supplied. Missing external account secrets fail explicitly.
324
+ wslRepositories locks repository commits; refresh with
325
+ winix update --windows wsl-setup. Completed setup is never reapplied or updated;
326
+ in-progress setup retains its original commit. Failures are resumable; dirty
327
+ or occupied checkouts/changed settings are refused, never reset or adopted.
328
+ State lives at /var/lib/winix/wsl-setup. Inspect stale run.lock and its PID
329
+ before manual recovery; never remove a live coordinator's lock.
330
+ No shutdown/reboot is automatic. Fresh-image activation remains unverified.
331
+ Omit setup to retain separate manual Linux activation.
270
332
  - \`windows.raw()\` runs a command on every apply. It is not idempotent, so use
271
- a typed helper or \`windows.dsc()\` when possible.
272
-
273
- Floating Windows packages are resolved into \`winix-windows.lock\`. Keep that
274
- file in version control for deterministic, offline applies.
333
+ a typed helper or \`windows.dsc()\` when possible. String commands default to
334
+ PowerShell 7 (\`pwsh\`); explicit executables are preserved.
335
+
336
+ File, PATH, startup, and module scripts use Microsoft.DSC.Transitional/PowerShellScript,
337
+ not Windows PowerShell 5.1. Install PowerShell 7 and put pwsh on PATH before DSC
338
+ resource discovery; declaring its package dependency is not sufficient for
339
+ bootstrap. Set scripts guard their own changes independently of test scripts.
340
+
341
+ Floating Windows packages, PowerShell modules, NixOS-WSL images and setup commits are resolved into
342
+ \`winix-windows.lock\` on first apply; existing pins are reused without a
343
+ resolution query. \`winix update --windows [names...]\` refreshes selected
344
+ package/module/image/repository pins (all when omitted, nixos-wsl for images,
345
+ wsl-setup for setup commits); --dry reports without writing.
346
+ Keep the lock in version control. Installation still requires network access
347
+ when the locked package/module is not installed.
348
+
349
+ Native Windows \`winix switch\` keeps a separate per-user/machine applied-state
350
+ inventory in LocalAppData/Winix, shared across recorded workspace/host activations.
351
+ Only packages absent before a successful activation become uninstall-owned.
352
+ Pre-existing packages are never automatically adopted. Unused owned packages
353
+ are automatically uninstalled after successful activation; always preview
354
+ with \`winix switch --dry\`. Other recorded owners prevent removal.
355
+ Switches with package/startup removals prompt before activation; declining cancels
356
+ the entire switch. Use \`--yes\`/\`-y\` for automation; noninteractive runs with
357
+ removals require it. Dry runs and switches without removals do not prompt.
358
+ External shortcut edits/package-version drift block reconciliation.
359
+ \`winix state forget startup <name>\` or
360
+ \`winix state forget package <winget|msstore> <id>\` releases removal ownership
361
+ without deleting the resource; --dry previews. Do not copy applied state to a
362
+ new machine or infer ownership from version locks. Direct DSC/script activation
363
+ bypasses this tracking. Files, modules, env and PATH cleanup are not tracked.
364
+
365
+ For fresh Windows prerequisites, \`scripts/bootstrap-windows.ps1\` runs in built-in
366
+ Windows PowerShell 5.1 or PowerShell 7. App Installer/WinGet is the initial
367
+ prerequisite. \`-Check\` is read-only; install mode confirms missing/outdated
368
+ Git/Node/PowerShell/DSC installation and enables WinGet configuration support.
369
+ \`-UseNvm\` chooses NVM for Windows instead of standalone Node; \`-Yes\` accepts
370
+ bootstrap changes. It never installs Winix globally, activates a host, provisions
371
+ WSL, reboots, or changes execution policy persistently. Prepare the config and
372
+ compatible SDK separately, then review \`switch --dry\` before activation.
373
+
374
+ On existing NixOS/NixOS-WSL, \`bash bootstrap-nixos.sh\` (from
375
+ \`scripts/bootstrap-nixos.sh\` or a reviewed release asset) opens a temporary
376
+ Git/Node.js 24/npm/Bash environment using pinned nixpkgs. Nix must already be
377
+ available. Flakes are enabled only in the child session; the script never edits
378
+ profiles/system configuration, clones repos, installs npm dependencies/Winix,
379
+ or activates hosts. Nix may download store paths. Users handle their configs
380
+ and declare permanent tools/settings themselves; \`exit\` leaves the environment.
275
381
 
276
382
  ## Nix values and escape hatches
277
383
 
@@ -334,7 +440,10 @@ callers may need arguments or \`.isActive\`.
334
440
  effects.
335
441
  - \`winix check [--strict] [--escape-report]\` validates the project.
336
442
  - \`winix apply [--host NAME] [--dry] [--diff]\` generates backend output.
337
- - \`winix switch [--host NAME] [--dry]\` generates and activates one host.
443
+ - \`winix switch [--host NAME] [--dry] [--yes]\` generates and activates one host, automatically cleaning up unused owned Windows packages and startup commands.
444
+ Prune is Windows-only and uninstalls unused Winix-owned packages.
445
+ - \`winix state forget startup <name>\` / \`winix state forget package <source> <id>\`
446
+ releases Windows removal ownership without deleting anything; accepts --dry.
338
447
  - \`winix update [INPUTS...] [--dry] [--windows]\` updates Nix inputs or
339
448
  Windows package locks.
340
449
  - \`winix inspect\` prints host composition and fragment information.
@@ -1,4 +1,61 @@
1
1
  import type { ResourceRef } from "../core/types.js";
2
+ export type WinKnownFolderName = "documents" | "desktop" | "localAppData" | "appData" | "userProfile";
3
+ export interface WinKnownFolder {
4
+ kind: "knownFolder";
5
+ folder: WinKnownFolderName;
6
+ path: string;
7
+ }
8
+ export type WinFilePath = string | WinKnownFolder;
9
+ export type WinStartupWindowStyle = "normal" | "minimized" | "maximized";
10
+ export interface WinStartupCommand {
11
+ /** Absolute/environment-variable path, known-folder path, or application name on PATH. */
12
+ executable: WinFilePath;
13
+ /** Literal arguments; known-folder arguments are resolved during activation. */
14
+ arguments?: WinFilePath[];
15
+ /** Defaults to the current user's home directory. Must exist during activation. */
16
+ workingDirectory?: WinFilePath;
17
+ windowStyle?: WinStartupWindowStyle;
18
+ }
19
+ export interface WinPowerShellModule {
20
+ name: string;
21
+ repository: string;
22
+ }
23
+ export interface WinWslDistro {
24
+ name: string;
25
+ source: "nixos-wsl";
26
+ installLocation: WinFilePath;
27
+ default: boolean;
28
+ setup?: WinWslSetup;
29
+ }
30
+ export interface WinWslSetup {
31
+ /** Opts into executing trusted repository/npm code inside the distro. HTTPS only; never embed credentials. */
32
+ repository: string;
33
+ /** Branch, tag, full ref, or immutable commit; resolved into winix-windows.lock. Defaults to HEAD. */
34
+ ref?: string;
35
+ configDirectory: string;
36
+ host: string;
37
+ /** Absolute path inside the selected account's home. Defaults to <home>/dotfiles. */
38
+ checkout?: string;
39
+ /** Selects a normal account declared by the Linux host; inferred when unambiguous. */
40
+ user?: string;
41
+ }
42
+ export interface WinWslConfig {
43
+ wsl2?: {
44
+ memory?: string;
45
+ processors?: number;
46
+ swap?: string;
47
+ localhostForwarding?: boolean;
48
+ networkingMode?: "nat" | "mirrored" | "none" | "virtioproxy";
49
+ dnsTunneling?: boolean;
50
+ firewall?: boolean;
51
+ autoProxy?: boolean;
52
+ guiApplications?: boolean;
53
+ };
54
+ experimental?: {
55
+ autoMemoryReclaim?: "disabled" | "gradual" | "dropCache";
56
+ sparseVhd?: boolean;
57
+ };
58
+ }
2
59
  /**
3
60
  * A winget package source. MVP supports the two first-party catalogues.
4
61
  * Additional sources (chocolatey, scoop) can plug in later without changing
@@ -68,7 +125,7 @@ export interface WinRawCommand {
68
125
  *
69
126
  * Typed helpers (env/path) construct native DSC resources internally:
70
127
  * `Microsoft.Windows/Registry` for env and
71
- * `Microsoft.DSC.Transitional/WindowsPowerShellScript` for PATH/files.
128
+ * `Microsoft.DSC.Transitional/PowerShellScript` for PATH/files/modules.
72
129
  */
73
130
  export interface WinDscResource {
74
131
  /**
@@ -112,6 +169,16 @@ export interface WinDscResource {
112
169
  dependsOn?: ResourceRef[];
113
170
  }
114
171
  export type WinDscMetadata = {
172
+ kind: "optional-features";
173
+ names: string[];
174
+ enabled: boolean;
175
+ } | {
176
+ kind: "wsl-distro";
177
+ distro: WinWslDistro;
178
+ } | {
179
+ kind: "startup";
180
+ name: string;
181
+ } | {
115
182
  kind: "env";
116
183
  action: "set" | "remove";
117
184
  name: string;
@@ -124,6 +191,20 @@ export type WinDscMetadata = {
124
191
  scope: "user" | "machine";
125
192
  } | {
126
193
  kind: "setting";
194
+ } | {
195
+ kind: "powershell-module";
196
+ module: WinPowerShellModule;
197
+ } | {
198
+ kind: "file";
199
+ action: "text" | "symlink" | "copy" | "remove";
200
+ target: WinFilePath;
201
+ source?: string;
202
+ content?: string;
203
+ encoding: "utf8" | "utf8bom" | "ascii";
204
+ force: boolean;
205
+ backup: boolean;
206
+ recursive: boolean;
207
+ wslConfig?: boolean;
127
208
  };
128
209
  export type WinColorMode = "Light" | "Dark";
129
210
  export type WinTaskbarAlignment = "Left" | "Center";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adrifer/winix",
3
- "version": "0.2.3",
3
+ "version": "0.2.4-preview.0",
4
4
  "description": "TypeScript-first system configuration for NixOS, nix-darwin, and Home Manager",
5
5
  "license": "MIT",
6
6
  "author": "Adrian Fernandez",
@@ -43,6 +43,8 @@
43
43
  "winix": "dist/cli/index.js"
44
44
  },
45
45
  "files": [
46
+ "scripts/bootstrap-windows.ps1",
47
+ "scripts/bootstrap-nixos.sh",
46
48
  "dist",
47
49
  "types",
48
50
  "index.d.ts",
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ winix_require_nixos() {
5
+ if [[ ! -r /etc/os-release ]] || ! (source /etc/os-release; [[ "${ID:-}" == nixos ]]); then
6
+ printf '%s\n' 'Winix bootstrap requires an existing NixOS installation (including NixOS-WSL).' >&2
7
+ return 1
8
+ fi
9
+ }
10
+
11
+ winix_bootstrap_nixos() {
12
+ if [[ $# -gt 0 ]]; then
13
+ if [[ $# -eq 1 && ( "$1" == --help || "$1" == -h ) ]]; then
14
+ printf '%s\n' \
15
+ 'Usage: bash bootstrap-nixos.sh' \
16
+ 'Open a temporary Git, Node.js 24/npm, and Bash environment on NixOS.' \
17
+ 'Nix downloads may populate the store; no profile or system configuration is changed.' \
18
+ 'Clone your configuration, install its npm dependencies, and run Winix yourself.' \
19
+ 'Type exit to leave the environment. No Winix installation or activation is performed.'
20
+ return
21
+ fi
22
+ printf '%s\n' 'Usage: bash bootstrap-nixos.sh [--help]' >&2
23
+ return 2
24
+ fi
25
+
26
+ winix_require_nixos || return
27
+ if ! command -v nix >/dev/null 2>&1; then
28
+ printf '%s\n' 'Nix is unavailable. Restore the NixOS Nix installation/PATH before running this bootstrap.' >&2
29
+ return 1
30
+ fi
31
+
32
+ # Keep the bootstrap independent of mutable registries and user channels.
33
+ local nixpkgs='github:NixOS/nixpkgs/0bb2eedc20e4739f29e8045034f2828ad7054f8f'
34
+ export NIX_CONFIG="${NIX_CONFIG:+$NIX_CONFIG$'\n'}extra-experimental-features = nix-command flakes"
35
+ printf '%s\n' \
36
+ 'Opening the Winix prerequisite shell (Git, Node.js 24/npm, Bash).' \
37
+ 'The first run may download packages to the Nix store.' \
38
+ 'No repositories are cloned, npm dependencies installed, or hosts activated.' \
39
+ 'Clone your config into a permanent location and run npm install and Winix yourself.' \
40
+ 'Type exit to leave. Declare permanent tools/Nix settings in your own configuration.'
41
+
42
+ exec nix shell --no-write-lock-file \
43
+ "$nixpkgs#git" \
44
+ "$nixpkgs#nodejs_24" \
45
+ "$nixpkgs#bashInteractive" \
46
+ --command bash --noprofile --norc -i
47
+ }
48
+
49
+ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
50
+ winix_bootstrap_nixos "$@"
51
+ fi
@@ -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
+ }