Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).