[M] Mount decimal.js in the sandbox and add a Decimal global - #2
Merged
Merged
Conversation
Collaborator
Author
|
This change is part of the following stack: Change managed by git-spice. |
The host code works with decimal strings. Every embedder had to read the decimal.js source from disk and mount it through the option `nodeModules`. A file read does not work in a bundle or in a vm without a file system. This change vendors the decimal.js source into the package as a string constant. The virtual file system mounts it always, so the guest code runs `import Decimal from 'decimal.js'` without an option. The new option `enableDecimalGlobal` registers the class `Decimal` as a global, which removes the need for an import statement in the guest code. The package exports the source through the subpath `./decimal-source`. An embedder that drives `quickjs-emscripten-core` directly gives the same class to the guest, and needs no bundler rule to turn the file into text. The subpath holds one string constant and imports nothing else, so a bundler does not pull the sandbox and the module memfs into the output. The script `vendor.ts` generates `src/modules/generated/decimal.js` from the dev dependency decimal.js.
evanrichards
force-pushed
the
decimal-by-default
branch
from
September 12, 2026 02:00
1ac1fdd to
2903c98
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 host code works with decimal strings. Every embedder had to read the
decimal.js source from disk and mount it through the option
nodeModules.A file read does not work in a bundle or in a vm without a file system.
This change vendors the decimal.js source into the package as a string
constant. The virtual file system mounts it always, so the guest code runs
import Decimal from 'decimal.js'without an option. The new optionenableDecimalGlobalregisters the classDecimalas a global, whichremoves the need for an import statement in the guest code.
The package also exports the source as
decimalJsSource. An embedder thatdrives
quickjs-emscripten-coredirectly gives the same class to the guest,and needs no bundler rule to turn the file into text.
The script
vendor.tsgeneratessrc/modules/generated/decimal.jsfrom thedev dependency decimal.js.