-
Notifications
You must be signed in to change notification settings - Fork 43
import:
urls in Node
#222
Comments
/cc @domenic
…On Sat, Nov 10, 2018, 1:38 PM Guy Bedford ***@***.*** wrote:
The current directions of import name maps are to bring these maps to
other resources on the web as well, such as CSS and asset loads, using an
import: URL. These URLs would be bare specifiers which would then be
looked up in the package map themselves.
Node.js could in theory also support these. And where this might come in
useful is all of our current use cases around fs.readFile(new URL('./x',
import.meta.url)) where instead one might write fs.readFile(new
URL('import:x')). Similarly this could be useful for new Worker, if this
constructor were to be extended to support a URL input.
Is this something we want to consider? If so, perhaps we should explore
some of these use cases further and ensure that Node is also represented in
these discussions on the import name maps spec.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#222>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAecV7nhLV28-71i3H4-dlsAu2gfvF0Sks5utsjagaJpZM4YX99m>
.
|
Ideally Node.js could follow in implementing |
Is there a good argument for just allowing arbitrary URL protocol handlers to be registered for the |
@weswigham it couldn't be done at an application level, because it would compromise the integrity of other modules using fs. |
Not for |
This gets into context sensitive URLs, passing these URLs to different modules/locations could alter where they are located (similar to relative URL strings). Any APIs we use should be context aware, which means hanging them off I personally would rather hold off on this while the spec for |
@bmeck the current implementation being suggested for import name maps is for the URL parser itself to do a check of the contextual script running the code. Now in Node.js we have the issue that URL is itself a module, but it should in theory still be possible in v8 to have this check walk the stack and thus filter to the right module code context. At least that's what would be needed in HTML, and it would be nice if Node could follow to get these benefits for eg |
I recall people balking at the idea of a global |
@guybedford we could make the URL parser context dependent but then we still get into some issues when passing these around: // app
import MyWorker from 'custom_worker';
new MyWorker('import:foo'); // custom_worker
import {Worker} from 'worker_threads';
export default class MyWorker extends Worker {
constructor(url) {
super(url);
}
} Where would the context of the parser be applied? |
See also: WICG/import-maps#75 I think adding |
Seems it is currently being considered to reduce this down to an HTML-based URL scheme only, in which case this issue would no longer apply apart from for use cases like JSDom I believe. |
Can we close this and leave it to userland situations like JSDom which are creating their own realms through vm.Context to do work already? |
Closing this as there has been no movement in a while, please feel free to re-open or ask me to do so if you are unable to. |
I think this relates to the |
The current directions of import name maps are to bring these maps to other resources on the web as well, such as CSS and asset loads, using an
import:
URL. These URLs would be bare specifiers which would then be looked up in the package map themselves.Node.js could in theory also support these. And where this might come in useful is all of our current use cases around
fs.readFile(new URL('./x', import.meta.url))
where instead one might writefs.readFile(new URL('import:x'))
. Similarly this could be useful fornew Worker
, if this constructor were to be extended to support a URL input.Is this something we want to consider? If so, perhaps we should explore some of these use cases further and ensure that Node is also represented in these discussions on the import name maps spec.
The text was updated successfully, but these errors were encountered: