endojs / endo

Endo is a distributed secure JavaScript sandbox, based on SES
Apache License 2.0
761 stars 68 forks source link

feat(compartment-map): Decouple discovery and languages #2306

Closed kriskowal closed 4 weeks ago

kriskowal commented 4 weeks ago

Refs: #400 and #2294

Description

In this change, we carve and export -lite.js and -parsers.js out of import.js, archive.js, and import-archive.js, as well revealing mapNodeModules through @endo/compartment-mapper/node-modules.js revealing hidden flexibility already present in the Compartment Mapper. This allows the Compartment Mapper to mix and match “language behaviors” with different workflows (e.g., using import-parsers.js with archive-lite.js instead of archive-parsers.js generates archives with original sources instead of precompiled sources.) We also decouple the process of discovering the physical compartments such that node-modules.js can be substituted for alternate compartment exploration algorithms, e.g., combining a custom lockfile and package cache from a specific package management solution.

Security Considerations

Does not cross security considerations.

Scaling Considerations

Exporting more narrowly scoped modules allows consumers to be avoid entraining Babel in a greater variety of scenarios.

Documentation Considerations

Evolution of the reference documentation should suffice, though another pass at README.md to dig into these more surgical and composable APIs may be worthwhile.

Testing Considerations

The existing scenarios are extensive and fully cover the behaviors that we’ve factored out. I expect #2294 tests to cover the new scenarios.

Compatibility Considerations

This change takes great care to preserve the existing behavior of the composite import.js, archive.js, and import-archive.js interfaces, only revealing existing behaviors that were previously internal, allowing more expressible scenarios.

Upgrade Considerations

This change will not affect upgrade and paves a migration path forward for preserving backward-compatibility for bundleSource and importBundle as we draw closer to supporting XS native compartments.

kriskowal commented 4 weeks ago

Advise reviewing commits individually. I took some care to rename and edit in separate steps.