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

Add support for Moddable XS #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cmidgley
Copy link

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 a manifest.json file at the root to specify the rules for the build, conceptually similar to a package.json file.

The following changes are proposed in this pull request:

  • Translate frozen maps to be writable: Maps have been moved into a object called writeableDiContainerMaps to centralize all maps into a single managed object. The maps are retrieved when needed using diContainerMaps 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.
  • Adjust build process to support git-based installs: A minor change to package.json was made to allow builds via prepare (shifting away from just preversion).
  • Added a Moddable manifest.json file: To support Moddable builds, a simple manifest.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 using Object.isFrozen. It has been tested on Node and Moddable (on ESP32 and their Windows-based simulator).

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

None yet

1 participant