jkrems / proposal-pkg-exports

Proposal for Bare Module Specifier Resolution in node.js
MIT License
130 stars 14 forks source link

import maps #9

Closed devsnek closed 5 years ago

devsnek commented 6 years ago

is there any plan to have a reconciliation of the import maps proposal and this? having two different formats floating around to do basically the same thing is annoying, especially when we have the opportunity now to fix it.

cc @domenic

jkrems commented 6 years ago

This proposal builds on top of the import maps proposal. On a conceptual level exports is a contribution to the import map. Pseudo code:

imports = {}
for each pkg in packages
  for each exportKey, resolution of pkg.exports
    imports[pkg.name + exportKey] = new URL(resolution, pkg.url).href
// `imports` is now a valid import map
jkrems commented 6 years ago

The explanation above skips scopes and nesting but the general idea is that just using package.json meta data and a rough package mapping, e.g. package-lock.json, you could build a complete in-memory import map and would never have to hit the disk to resolve anything.

jkrems commented 5 years ago

I think the current semantics are aligned with import maps as much as we can (given that import maps aren't 100% finalized yet).