Skip to content

Commit

Permalink
feat(compartment-map): Decouple discovery and languages (#2306)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kriskowal authored Jun 4, 2024
2 parents 43d867e + d241fcb commit e74e977
Show file tree
Hide file tree
Showing 49 changed files with 1,588 additions and 1,038 deletions.
9 changes: 9 additions & 0 deletions packages/compartment-mapper/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ User-visible changes to the compartment mapper:
application and the `"parsers"` property in individual `package.json`
descriptors may extend or override using any of the configured or built-in
language parser names.
- Exports `import-lite.js`, `archive-lite.js`, `import-archive-lite.js`,
`import-parsers.js`, `archive-parsers.js`, `import-archive-parsers.js`, and
`node-modules.js`, allowing these to be mixed and matched.
The existing `import.js`, `archive.js`, and `import-archive.js` all entrain
by import their corresponding default behaviors, where the new modules do
not.
For example, `import-parsers.js` does not entrain Babel.
The new `import-lite.js` does not entrain `node-modules.js` and composes
with potential alternative package discovery, storage, and locks.

# 0.9.0 (2023-08-07)

Expand Down
7 changes: 7 additions & 0 deletions packages/compartment-mapper/archive-lite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export {
makeArchiveFromMap,
makeAndHashArchiveFromMap,
writeArchiveFromMap,
mapFromMap,
hashFromMap,
} from './src/archive-lite.js';
1 change: 1 addition & 0 deletions packages/compartment-mapper/archive-parsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { defaultParserForLanguage } from './src/archive-parsers.js';
5 changes: 5 additions & 0 deletions packages/compartment-mapper/import-archive-lite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export {
parseArchive,
loadArchive,
importArchive,
} from './src/import-archive-lite.js';
1 change: 1 addition & 0 deletions packages/compartment-mapper/import-archive-parsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { defaultParserForLanguage } from './src/import-archive-parsers.js';
1 change: 1 addition & 0 deletions packages/compartment-mapper/import-lite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { loadFromMap, importFromMap } from './src/import-lite.js';
1 change: 1 addition & 0 deletions packages/compartment-mapper/import-parsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { defaultParserForLanguage } from './src/import-parsers.js';
1 change: 1 addition & 0 deletions packages/compartment-mapper/node-modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { mapNodeModules } from './src/node-modules.js';
7 changes: 7 additions & 0 deletions packages/compartment-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@
"default": "./index.js"
},
"./import.js": "./import.js",
"./import-lite.js": "./import-lite.js",
"./import-parsers.js": "./import-parsers.js",
"./archive.js": "./archive.js",
"./archive-lite.js": "./archive-lite.js",
"./archive-parsers.js": "./archive-parsers.js",
"./import-archive.js": "./import-archive.js",
"./import-archive-lite.js": "./import-archive-lite.js",
"./import-archive-parsers.js": "./import-archive-parsers.js",
"./bundle.js": "./bundle.js",
"./node-powers.js": "./node-powers.js",
"./node-modules.js": "./node-modules.js",
"./package.json": "./package.json"
},
"scripts": {
Expand Down
Loading

0 comments on commit e74e977

Please sign in to comment.