Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compartment-mapper): support for dynamic requires
This change adds support for _dynamic requires_, where a Node.js script does something like this: ```js const someModuleSpecifier = getSpecifier(); const idk = require(someModuleSpecifier); ``` This behavior is not enabled by default; specific options and Powers are required. See the signature of `loadFromMap()` in `import-lite.js` for more information. Dynamic loading of exit modules (e.g., if `someModuleSpecifier` was `node:fs`) is handled by a user-provided "exit module import hook". Policy applies. Dynamic requires work as you'd probably expected _except_: - A compartment may dynamically require from its *dependee*, since this is a common pattern in the ecosystem (see [node-gyp-build](https://npm.im/node-gyp-build)). - The special "attenuators" compartment may not be dynamically required. Horsefeathers! Some relevant bits, if you're mining history: - All internal parsers are now _synchronous_, which was made possible by the introduction of `evadeCensorSync` in `@endo/evasive-transform`. - Async parsers are still supported, but they would only be user-defined. Async parsers are incompatible with dynamic requires. - Added property `{Set<string>} compartments` to `CompartmentDescriptor`. This is essentially a view into the compartment names within `CompartmentDescriptor.scopes`. - The `mapParsers()` function has moved into `map-parser.js`. - `@endo/trampoline` is leveraged in a couple places (`import-hook.js`, `map-parser.js`) to avoid code duplication. - Introduced `FsInterface`, `UrlInterface`, `CryptoInterface` and `PathInterface` (and their ilk) for use with `makeReadPowers()` and the new `makeReadNowPowers()`.
- Loading branch information