tc39 / proposal-import-attributes

Proposal for syntax to import ES modules with assertions
https://tc39.es/proposal-import-attributes/
Apache License 2.0
599 stars 26 forks source link

Module Import Headers #61

Closed Randy-Buchholz closed 4 months ago

Randy-Buchholz commented 4 years ago

I have a related item on the WICG Discourse. https://discourse.wicg.io/t/proposal-module-import-headers/4467/1

I'm proposing adding headers to the request when the request is for a module. This helps when building handlers on the request pipeline on the server. Though not directly related, this seems to be a case whose implementation could benfit from headers specific to modules.

littledan commented 4 years ago

This is a good topic to discuss, and we're discussing it in some other issues here, such as #24, e.g., https://github.com/tc39/proposal-module-attributes/issues/24#issuecomment-627096878. Ultimately, ECMA-262 isn't going to say which headers are sent to the server--this is up to host environments, like HTML. I'm proposing that we come to a good conclusion on how some of those environments would work before Stage 3, but ultimately, that we will leave it up to them to make these calls. What do you think?

Randy-Buchholz commented 4 years ago

I'm generally of the same mind about which headers should be sent, and that it should be up to the implementers since in the simplest form (just adding a "import" header item) it isn't something that would show up in the language proper. But I think if a client is expecting a module it would be good manners to let the server know lol.

What I would propose is that in Section 15.2.2 we add an optional "with" clause:

import ImportClause FromClause [WithClause];

This would provide a standardized hook for implementers, and a node for additional specification.

I'm new to the ECMA-262 language specification world and took a look at the specification. To me it reads much like an abstract design. Is there a corresponding "requirements" document? By that I mean something in a form similar to "The language shall...", The language may...". That would be a place to put "recommendations" on what to do with the WithClause.

littledan commented 4 years ago

The standardized hook for implementers to provide their header is called HostResolveImportedModule . It's where the fetching happens, and the module attributes are passed to it.

xtuc commented 4 years ago

To help reach a decision we opened a discussion against the HTML spec https://github.com/whatwg/html/issues/5640.

nicolo-ribaudo commented 4 months ago

This is done