-
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(ses): Support importHook alias returns #432
Conversation
3a12559
to
68f2852
Compare
09d86bc
to
53caadf
Compare
68f2852
to
e140f2c
Compare
53caadf
to
40fd429
Compare
e140f2c
to
ec31d51
Compare
a34836d
to
e5e6609
Compare
4f9b18a
to
cf22857
Compare
e5e6609
to
89c12b5
Compare
cf22857
to
abc3697
Compare
89c12b5
to
7dd6f96
Compare
abc3697
to
ef542c7
Compare
7dd6f96
to
ade51a6
Compare
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.
LGTM
packages/ses/README.md
Outdated
and return a module that has a different "response specifier" than the original | ||
"request specifier". |
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 really like the terminology "request specifier" and "response specifier"
packages/ses/README.md
Outdated
|
||
```js | ||
const importHook = async specifier => { | ||
const candidates = [specifier, specifier + ".js", specifier + "/index.js"]; |
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.
const candidates = [specifier, specifier + ".js", specifier + "/index.js"]; | |
const candidates = [specifier, `${specifier}.js`, `${specifier}/index.js`]; |
Only if you agree it is at least as clear.
packages/ses/README.md
Outdated
const importHook = async specifier => { | ||
const candidates = [specifier, specifier + ".js", specifier + "/index.js"]; | ||
for (const candidate of candidates) { | ||
const record = wrappedImportHook(candidate).catch(_ => undefined); |
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.
Do you need an await
?
packages/ses/README.md
Outdated
The `importHook` may return an "alias" envelope with `alias`, `compartment`, | ||
and `module` properties. |
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 example code below instead returns a record with alias
and specifier
properties?
What does "envelope" mean here?
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.
Revised to avoid “envelope” term.
packages/ses/README.md
Outdated
const moduleMapHook = moduleSpecifier => { | ||
if (moduleSpecifier === 'even') { | ||
return even.module('./index.js'); | ||
} else if (moduleSpecifier === 'odd') { | ||
return odd.module('./index.js'); | ||
} | ||
}; |
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.
Our old even/odd friend, I missed you.
packages/ses/src/module-load.js
Outdated
// Await all dependencies to load, recursively. | ||
await Promise.all( | ||
values(resolvedImports).map(fullSpecifier => | ||
// Behold: recursion. |
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 wish "Behold: recursion." was the eslint directive ;)
Actually, I'll take this opportunity to ask: Do you think the Agoric style should turn this warning off by default?
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’s a rare enough problem that it doesn’t bother me.
I don’t think I’ve ever used recursion accidentally, though.
The directive does force an opinionated order. In this particular case, these functions tend to tail-recur so they’re actually clearer to read in reverse declaration order.
I have no strong feelings.
packages/ses/test/import.test.js
Outdated
|
||
const makeImportHook = makeNodeImporter({ | ||
'https://example.com/main/index.js': ` | ||
export const unique = {n: Math.random()}; |
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.
Really vivid way to test this. I like it.
packages/ses/test/import.test.js
Outdated
|
||
// TODO The following commented test does not pass, and might not be valid. | ||
// Web browsers appear to have taken the stance that they will load a static | ||
// module record once per *response url* and create unique a unique module |
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.
// module record once per *response url* and create unique a unique module | |
// module record once per *response url* and create a unique module |
cf7b21e
to
8b4bee3
Compare
This change enables importHook to return a record for a module that has a different specifier than the requested module specifier. This enables the Node.js pattern of redirecting `name` to `name/index.js` and respecting the latter name as the referrer for its own imports.
2bdad74
to
aa7871e
Compare
8b4bee3
to
93a7f21
Compare
This change enables importHook to return a record for a module that has a different specifier than the requested module specifier. This enables the Node.js pattern of redirecting `name` to `name/index.js` and respecting the latter name as the referrer for its own imports.
This change enables importHook to return a record for a module that has a different specifier than the requested module specifier. This enables the Node.js pattern of redirecting
name
toname/index.js
and respecting the latter name as the referrer for its own imports.