Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack: add/build RTI target #409

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft

Conversation

kungfooman
Copy link
Contributor

I'm excited to introduce RuntimeTypeInspector.js, which I believe will benefit Transformers.js as a whole and our debugging workflows in specific. RTI is designed to type-check the arguments of every function and method. It detects type errors while the engine is running in a way that goes beyond the capabilities of TypeScript, as demonstrated in this video (there is another one on the website debugging the Microsoft Holometric Video PC project).

During the development of RTI it already helped me to understand and fix things, for example various JSDoc types and this NaN bug: #390

I believe that RTI will help improve productivity and efficiency, by catching errors early on and reporting them in detail.

Runtime Type Inspector is implemented using Babel AST traversal with custom JSDoc parsing (powered by TypeScript itself for highest compatibility).

TLDR: It adds type assertions for runtime type checking, for example:

image

Being able to set breakpoints exactly where the errors are happening for the first time helps to track down problems that are otherwise difficult to pinpoint (and saves a lot of time 😅).

Try for yourself: https://pc.runtimetypeinspector.org/#/animation/blend-trees-2d-cartesian

Just make sure to pick the right JS context - the exampleIframe:

image

I'm working on this for quite some time by now, a mix of fun and frustration - rewriting code on the AST level first seemed tricky, but given enough time, it was a rather straightforward way to automate type validations. I'm excited to read feedback and suggestions. 🙏

@kungfooman kungfooman marked this pull request as draft November 22, 2023 11:59
@kungfooman kungfooman mentioned this pull request Nov 25, 2023
@kungfooman
Copy link
Contributor Author

I wanted the examples to be build-free while also being able to use RTI type checking on each of them. Because that was quite a challenge in the beginning, I decided to make a custom repo for it: https://github.com/kungfooman/transformers-examples.js

The first main challenge was loading a worker containing ESM code depending on import map resolution... I found some brittle solutions, but ended up making my own NPM package for it: https://github.com/kungfooman/worker-with-import-map/

Still working on some examples and making everything easier to use, but most of them already work build-free and with RTI 🙈

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