module: add import map support
This PR adds experimental support for import maps behind the --experimental-import-map=<path>
flag. This is a draft as I believe there are still quite a few things to discuss and add:
-
Docs -
More test coverage -
Test on the module tree from some of the bundled deps -
Use web platform tests
-
-
Benchmarks (specifically to see how much adding an import map hits startup) -
Bare specifier remapping: Should we have the ability to remap one bare specifier to another? foo
tobar
and then have default resolution onbar
, for example? This might be against spec, but also seems really helpful.-
This is answered by this WPT -
Tests added for this
-
-
Does it make sense to resolve the import map via esm? Or should we do a more basic file read? -
In the future should we plan to automatically load an import map based on a well known location? (ex node_modules/importmap.json
) -
What types of values do we want for --experimental-import-map
? Right now any module specifier is allowed, but do we want that? This was done to enable http import of import maps, but that is not explicitly a goal, just a starting point for discussion. -
CommonJS support? What do we want to do about that? -
Decided we should hold off on that and deal with it in a follow up PR if we think we should do it.
-
-
https://github.com/nodejs/node/pull/50590#discussion_r1384627793 Do we need to pass the import map reference to loaders? If not, can we remove it from context first to avoid the non-transferable problem?
Helpful links:
- Initial issue from the module/loaders group: https://github.com/nodejs/node/issues/49443
- Import map spec: https://html.spec.whatwg.org/multipage/webappapis.html#import-maps
- Import map wicg repo: https://github.com/WICG/import-maps
- Recent plan issue: https://github.com/nodejs/loaders/issues/168