sjbarag / brs

An interpreter for the BrightScript language that runs on non-Roku platforms.
MIT License
113 stars 43 forks source link

Add support for <ComponentLibrary> with package-local URIs #589

Closed sjbarag closed 3 years ago

sjbarag commented 3 years ago

RBI's SceneGraph implementation supports a ComponentLibrary component, used to load components from a separately-packaged bundle of code. These can be loaded either via HTTP or via pkg:/-style local URIs (basically the same rules as <Poster/>) and add all .xml components to the list of createObject()-able components in the main channel. Those components must be prefixed by the namespace of the component library.

Useful Resources:

sjbarag commented 3 years ago

I suspect this will require a small modification to ComponentProcessor::parseChildren, looking for child.name === "ComponentLibrary", then adding that URI to a list of component libraries that need to be handled. Each component library appears to be almost a fully-valid channel, so we'll need to go through the normal manifest + preprocessor + lexer + parser process for all .xml and .brs files in that .zip file.

The tricky bit is likely that <script/> tags in the component library are resolved relative to the manifest file of that component library, rather than process.cwd() like we currently assume.

To simplify things for now, let's reject /^https?:\/\/.*/ URIs, to avoid having to load remote resources during parse-time.