Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

TC-39 Discussion: Seeking input on import options #131

Closed
jasnell opened this issue May 23, 2017 · 14 comments
Closed

TC-39 Discussion: Seeking input on import options #131

jasnell opened this issue May 23, 2017 · 14 comments

Comments

@jasnell
Copy link
Member

jasnell commented May 23, 2017

At TS-39, @domenic led a short discussion around the possibility of attaching options to an import statement or import() function. There are a number of use cases for this that need to be considered and there would definitely be an impact on Node.js if this were to move forward. We need folks here to commit to reviewing the issues and providing feedback.

@domenic's presentation is here: https://docs.google.com/presentation/d/1qfoLTniLUVJ5YNFrha7BaVumAnW0ZgcCfUU8UbyyuYY/edit#slide=id.p

Some additional discussion notes are: https://discourse.wicg.io/t/specifying-nonce-or-integrity-when-importing-modules/1861/4

@jasnell jasnell changed the title TSC Discussion: Seeking input on import options TS-39 Discussion: Seeking input on import options May 23, 2017
@jasnell jasnell changed the title TS-39 Discussion: Seeking input on import options TC-39 Discussion: Seeking input on import options May 23, 2017
@Fishrock123
Copy link

The syntax is awful.

@domenic
Copy link

domenic commented May 24, 2017

And yep, I'm out... Good old Node community, welcoming as always.

@jasnell
Copy link
Member Author

jasnell commented May 24, 2017

@Fishrock123 that's not particularly useful. There are a number of considerations beyond just syntax and it's something that we need to pay attention to. Is there more constructive input you could provide?

@jasnell
Copy link
Member Author

jasnell commented May 24, 2017

I will point out that tc-39 cares a great deal about this stuff working for node. @domenic has taken great pains to include common node use cases and requirements throughout the proposals discussed. It's worth our time to consider these as carefully as tc-39 is doing. This is stuff that will impact our users for a very long time.

@jasnell
Copy link
Member Author

jasnell commented May 24, 2017

Fwiw... The conversation landed today on favoring an out of band (non-syntax) driven approach. That said, the discussion right now should be around the needs an be requirements, not knocking down syntax straw people.

@Fishrock123
Copy link

How does out-of-band work for node?

I very much dislike the single "string" approach and would rather:

import "x" with "options"
import("x", "options")

@Fishrock123
Copy link

@jacktuck ... Yes? I have attempted to clarify my initial feedback. Do let me know what is wrong with it.

@jasnell
Copy link
Member Author

jasnell commented May 24, 2017

@Fishrock123 ... thank you for clarifying.

As this was being discussed, I grokked the use case easily enough but struggled on what would be the most ergonomic approach and unfortunately didn't come up with any really great ideas. One idea that popped in to mind would be to use an options object syntax rather than a string syntax... e.g.

import 'x' with { optionA: 1, optionB: 'abc' };
import('x', {optionA: 1, optionB: 'abc' };

or even...

import { module: 'x', optionA: 1, optionB: 1 };
import({ module: 'x', optionA: 1, optionB: 1 });

In terms of how out of band would work, it would likely be adding to either package.json or having a separate document format.

@Fishrock123
Copy link

I do like the object approach for the import function.

Adding it to package.json poses similar issues as adding the ESM detection mechanism there, IMO.

@mhdawson
Copy link
Member

Even with the object import approach, it would have the same problem with "integrity" right ?

The object syntax does seem nicer but I'd prefer the first 2 variants where the options are in an object of their own:

import 'x' with { optionA: 1, optionB: 'abc' };
import('x', {optionA: 1, optionB: 'abc' };

@benjamingr
Copy link
Member

Is node even interested in "function import"? As far as I know there hasn't been a built-in way to do an asynchronous require for a while now (for at least a few years) and we've been fine with it.

@jasnell
Copy link
Member Author

jasnell commented Jun 22, 2017

If the import function does in fact make it into the language, then it would likely use the same mechanism as regular import. Once we are fully supporting ES6 modules, there won't be a reason not to also support the import function,

@benjamingr
Copy link
Member

Once we are fully supporting ES6 modules, there won't be a reason not to also support the import function

Well, it adds to the API surface, it adds functionality that was formerly rejected in core - and the strong obvious use case in browsers doesn't really exist in Node (lazy loading resources and scripts). Every large single page application does chunking and bundling and loading resources lazily while no node server I've seen does anything similar.

I'm not saying we shouldn't use or implement import, I would love to see a convincing use case for the import function first though.

@Trott
Copy link
Member

Trott commented Sep 8, 2017

I'm going to close this, but feel free to open another issue in a relevant active repository (TSC perhaps?) and include a link back to this issue if this is a subject that should receive continued attention.

@Trott Trott closed this as completed Sep 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants