-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add support for Moddable XS #12
base: master
Are you sure you want to change the base?
Conversation
- During moddable preload, container registration occurs and is placed into the maps in flash that are frozen - Container maps are refactored to use an interface for containing all maps, and clones all container maps, if and only if the are frozen, so they can become writable in RAM - Change only affects preloaded frozen maps, no meaningful change to Node environments aside from one level of indirection on accessing maps - Added moddable.json file, which is similar to package.json for Moddable XS
- remove build from preversion - add prepare script to do build - This allows a git-based project dependency to build and get dist artifacts
…uilding on npm i. removed /dist/ from gitignore to use that instead.
Hi @cmidgley. Thanks for your contribution. I've been updating the codebase with more modern language features and TypeScript 5.6 compatibility, so there are significant conflicts between the two branches. As I've also mentioned in the past, I would like to help you bring first-class support for Moddable into DI. But, after looking at the code, and the scope of the changes, it does seem like the best approach here is to expose more hooks in the base DIContainer class that can be subclassed, so that in theory you can write a |
I saw some Using hooks is a good strategy if you are willing to invest the time. For background, Moddable XS uses something similar to Secure ECMAScript on the global namespace, which means anything that runs before the first microtask gets frozen (read-only). I've not spent a lot of time thinking about this, but I see two broad-stroke approaches:
Personally, I'd keep it simple / reduce risk, and keep the Thanks! |
The Moddable (github) open-source project is a full JavaScript (2022) implementation for microcontrollers (such as the ESP32 and ESP8266) that supports TypeScript. Since it supports tiny microcontrollers, they do some tricks to keep RAM usage small by freezing objects into flash, including the ability to execute the JavaScript global-executed code during compilation on the host machine (Windows, Mac, Linux) and freezing the results of created objects into flash (called
preload
). The result is that the DI maps used to track registrations that get executed during preload end up freezing the maps and runtime registrations fail.Additionally, Moddable does not support NPM but does support git. However, DI currently cannot be installed using git directly, as the build process that creates the required
dist
output is not getting executed. Also, Modable requires amanifest.json
file at the root to specify the rules for the build, conceptually similar to apackage.json
file.The following changes are proposed in this pull request:
writeableDiContainerMaps
to centralize all maps into a single managed object. The maps are retrieved when needed usingdiContainerMaps
which returns the maps as-is as long as they are not frozen, but if they are it copies the frozen (flash memory) maps into non-frozen (RAM) maps. This translate occurs only once, on the first use of a map at runtime.package.json
was made to allow builds viaprepare
(shifting away from justpreversion
).manifest.json
file: To support Moddable builds, a simplemanifest.json
file has been added to the root.This does not meaningfully affect performance, as the only impact is one redirect via the
diContainerMaps
to get the maps and one runtime check usingObject.isFrozen
. It has been tested on Node and Moddable (on ESP32 and their Windows-based simulator).