Skip to content

Discover RSG 2.0 SDK anchor nodes - #1960

Draft
chrisdp wants to merge 4 commits into
v1from
feature/rsg2-anchor-nodes
Draft

chrisdp wants to merge 4 commits into
v1from
feature/rsg2-anchor-nodes

Conversation

@chrisdp

@chrisdp chrisdp commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Refs #1895

Prototype for finding the anchor nodes an RSG 2.0 SDK app declares in TypeScript. The goal is to make them part of the BrightScript type system. This PR covers discovery only.

How it works

Add the app's roku-config.ts to bsconfig.json:

{
    "rootDir": "pkg",
    "rokuConfig": "./roku-config.ts"
}
  1. roku-config.ts is read statically; it is never executed. Only app.entryPoint and brsOnly are read, and both are string/boolean literals in practice.
  2. Relative imports are followed from the entry point: import, export … from, import() and require(), with .js → .ts and index resolution. Only files the app can reach are read, so node_modules and unused files cost nothing.
  3. Anchor node descriptors are found by shape rather than by call site: an object with a componentName string plus extends, inputFields or outputFields. This covers defineAnchorNode, the deprecated declareTsComponent, and descriptors imported from another file.
  4. FieldType.*() values map to the field type the device creates. Number becomes integer, Float float, Object/Null assocarray, Array array, String string and Boolean boolean, matching declareTsComponent in @roku-sdk/ts-core.

The result is exposed as program.rsgProject: source files, imported XML components, and anchor nodes with their file and position. The CLI logs Found N anchor node(s) in M TypeScript file(s).

Results against the SDK examples

Running discovery from each example's own roku-config.ts found 33 anchor nodes in 32 apps, at 0–77 ms per app. That covers every descriptor in the examples except:

  • the slideshow focus/pooled/virtual variants, which have their own roku-config-*.ts, and each resolves its own SlideshowApp;
  • reactive-focus-pitfalls.tsx, which nothing imports.

Raw parser throughput is about 14 MB/s. A quick text check skips about 97% of files before parsing.

Not done yet

  • Anchor nodes are not in the type system yet. The first commit registers them through generated XML components that are excluded from output. The plan is to replace that with direct registration in Program, so no generated files are involved.
  • Discovery runs once at project load. It needs to run before validation and on TypeScript changes (watch mode and the language server).
  • Path aliases and package imports aren't followed, so bases such as FocusBoundaryBase from @roku-sdk/navigation don't resolve. Imported XML components are collected but not loaded.
  • Possible diagnostics later:
    • an anchor field that collides with a base field of a different type, which is fatal on device and which the SDK doesn't check;
    • non-Group extends against minFirmwareVersion.

Other changes

  • Program.build() now honors excludeFromOutput. It was declared on BscFile but never read.
  • Program.getFile() now resolves virtual:/ files from URIs, so comment flags such as bs:disable work in virtual files.

Generated by Claude Code

Scan .ts/.tsx/.mts files for `registerAnchorNode(declaration, ...)` calls and
register each declaration as a virtual component (excluded from output), so
anchor nodes get component types, field types, and CreateObject validation.

- Honor `excludeFromOutput` during build
- Fix `getFile()` lookup of `virtual:/` files from uris so comment flags apply

Refs #1895

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3izbnpnJn45fWn4Q9WiRF
Detect RSG 2.0 SDK descriptors wherever they are declared rather than only at
registerAnchorNode call sites, so defineAnchorNode, declareTsComponent and
descriptors imported from other files are all found. Map FieldType to the
field types the device creates, include libraryName and position, and make
sure the scanner always makes progress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3izbnpnJn45fWn4Q9WiRF
Add a `rokuConfig` bsconfig option pointing at an RSG 2.0 SDK app's
roku-config.ts. The config is read statically for `app.entryPoint` and
`app.staticAssetsDir`, then relative imports are followed from the entry point
to find the app's TypeScript sources, the XML components they import, and the
anchor nodes they declare. The result is exposed as `program.rsgProject`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3izbnpnJn45fWn4Q9WiRF
Discovery only follows imports from `app.entryPoint`, so the static assets
folder was read but never used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3izbnpnJn45fWn4Q9WiRF

This branch has not been deployed

No deployments
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.

2 participants