-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(endo): Add assemble #345
Conversation
c679109
to
9f05f9a
Compare
15c4b0f
to
74e767c
Compare
9f05f9a
to
9613273
Compare
74e767c
to
9349386
Compare
9613273
to
c925316
Compare
a71cc4d
to
84fd542
Compare
4514f0a
to
9e238ea
Compare
7031ca8
to
6af7973
Compare
39d9f6a
to
b096403
Compare
6af7973
to
922c290
Compare
b096403
to
e656cab
Compare
922c290
to
6b0d3c1
Compare
e656cab
to
3a11ffd
Compare
6b0d3c1
to
33a7fe2
Compare
3a11ffd
to
5bec88c
Compare
1dea943
to
6e5f172
Compare
37bbe67
to
fb56681
Compare
I'm guessing this branch pointer needs to be reset to something descending from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only looked at assemble.js
, because I'm assuming this branch needs to be re-sewn into the main sequence of PRs (and the other files are covered by other PRs), but it looks good to me.
// Passes the given endowments and external modules into the root compartment | ||
// only. | ||
export const assemble = ({ | ||
name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name
is the same as packageLocation
in compartmap.js
, right? And it's not the label
from that data structure. And I think it's nominally a URL (although compartments[name].root
, which happens to be a copy of name
, is probably more deserving of an identifier which has "location" in the name since I think that .root
will be used to actually find the code).
If the key of compartments
is not a load-bearing, I mean, location-bearing identifier, then name
is a great parameter name to use. But maybe there's something we could to in compartmap.js
to make that clear. Not sure what, maybe:
const translateGraph = (mainPackagePath, graph) => {
const compartments = {};
for (const [packageLocation, { label, dependencies }] of entries(graph)) {
...
const name = packageLocation; // not used for location properties, just a distinct name for each compartment
...
compartments[name] = {
label, // cosmetic, 'packagename@version'
root: packageLocation, // used to find code for the package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The for purposes of assembling compartments, the names are just internal references and are only obliged to be internally consistent. In practice, if the compartment map is prepared by importLocation, they are locations; if the compartment map is prepared by writeArchive, they are unique identifiers. Both of these mechanisms are free to change independent of the assembler.
I can probably make that more clear in code as you’re suggesting.
throw new Error(`Cannot assemble compartment graph that includes a cycle`); | ||
} | ||
|
||
for (const [inner, outer] of entries(descriptor.modules || {})) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the fallback? compartmap.js
always provides a .module
property, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, but left this affordance against the possibility that compartmap.json might be manually manipulated, or that section automatically omitted if empty.
loaded, | ||
Compartment | ||
}); | ||
modules[inner] = compartment.module(moduleSpecifier); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial caller can pass modules
which will be made available to the top-level Compartment, in addition to modules for all of its dependencies (specifically all of the exported modules for all of its dependency packages). Cool. But the dependency modules will shadow any provided by the caller, so this feature couldn't be used for e.g. dependency injection. Is that intentional? I can imagine there's a good reason to do it one way or the other, or maybe even both, but I don't know what those reasons might be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intent is for this to be usable for dependency injection. I’ll look more closely and will make sure it’s tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked. As written, this is fine for injecting built-in modules that are not declared dependencies, but not for replacing third-party dependencies with overrides.
I think I will land as-is and revisit. I think I want an explicit directive in the compartment map when a package should receive an override. The same mechanism would be used to thread built-in modules expressly to third-party packages and would be driven by policies in package.json or a lavamoat config file.
fb56681
to
c948940
Compare
6e5f172
to
6cfbda9
Compare
c948940
to
681406f
Compare
6cfbda9
to
124bf9b
Compare
8bb4f7b
to
0deea46
Compare
The compartment assembler takes a compartment map and builds the corresponding compartment instances, feeding the modules exported by each dependency into the dependee compartment's module map.
0deea46
to
23ac797
Compare
The compartment assembler takes a compartment map and builds the
corresponding compartment instances, feeding the modules exported by
each dependency into the dependee compartment's module map.