Skip to content

Add automatic JS binding generation from WinRT metadata#375

Open
lei9444 wants to merge 3 commits intomainfrom
leilzh/generate
Open

Add automatic JS binding generation from WinRT metadata#375
lei9444 wants to merge 3 commits intomainfrom
leilzh/generate

Conversation

@lei9444
Copy link
Copy Markdown
Contributor

@lei9444 lei9444 commented Mar 31, 2026

Description

Add winapp node generate-bindings command that generates typed JS/TS bindings from WinRT metadata using winrt-meta.

  • Interactive setup after winapp init: Detects Node.js projects (package.json), prompts the user to generate bindings and select language (JS or TS), then auto-configures
    winapp.yaml and generates bindings
  • Auto-generate on winapp restore: Silently regenerates bindings if jsBindings is already configured in winapp.yaml
  • Auto-discover all WinAppSDK packages: Scans the NuGet dependency chain to find all packages with .winmd metadata (Foundation, AI, ML, Search, etc.) — no manual package
    configuration needed
  • Smart UI exclusion: Excludes UI-only packages (WinUI, Widgets) and winmd files (Microsoft.UI., Microsoft.Web.WebView2.) from code generation, but uses them as --ref for type
    resolution — zero warnings
  • Works across SDK versions: Handles both the 1.6-style flat layout (lib/uap10.0/) and 1.8+ sub-package structure (metadata/), tested with 1.6, 1.8, and 2.0
  • Auto-installs dynwinrt-js runtime dependency into the user's project
  • Ships winrt-meta as a CLI dependency — users don't need to install it separately

Usage Example

After winapp init in a Node.js project, the CLI prompts the user to optionally
generate JS or TS bindings. If accepted, it:

  1. Adds a jsBindings section to winapp.yaml with the chosen language
  2. Installs dynwinrt-js as a runtime dependency
  3. Auto-discovers WinAppSDK packages and generates bindings

On subsequent winapp restore, bindings are regenerated automatically if configured.

To regenerate manually: npx winapp node generate-bindings

Type of Change

  • ✨ New feature

Checklist

  • Tested locally on Windows
  • docs/usage.md updated (if CLI commands changed)

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

Build Metrics Report

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 25.92 MB N/A N/A
CLI (x64) 26.54 MB N/A N/A
MSIX (ARM64) 11.08 MB N/A N/A
MSIX (x64) 11.79 MB N/A N/A
NPM Package 23.01 MB N/A N/A

Test Results

409 passed, 5 failed out of 414 tests in 445.7s (+38.0s vs. baseline)

Test Coverage

41.9% line coverage, 45.5% branch coverage · ⚠️ -0.4% vs. baseline


Updated 2026-04-01 12:56:40 UTC · commit e89b5bd · workflow run

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.

1 participant