lukeed / resolve.exports

A tiny (952b), correct, general-purpose, and configurable `"exports"` and `"imports"` resolver without file-system reliance
MIT License
368 stars 15 forks source link

Throw on invalid package target #5

Closed paul-soporan closed 3 years ago

paul-soporan commented 3 years ago

Node throws ERR_INVALID_PACKAGE_TARGET when a package target doesn't start with ./.

resolve.exports doesn't throw anything.

const pkgJson = {
  exports: {
    './a': '../b',
    './c': 'd',
  }
};

resolve(pkgJson, './a'); // passes but not allowed by node
resolve(pkgJson, './c'); // passes but not allowed by node

Ref:

lukeed commented 3 years ago

This module is not a validator – it only resolves existing exports mappings & returns what's defined.

Because the value is returned as defined (except subpatterns, which are evaluated), this is trivial to apply on the returned output string.

paul-soporan commented 3 years ago

Thanks for the explanation! Perhaps you could put a non-goals section inside the README so that people know exactly which parts of the Node exports resolution ("resolution" might not be the best word as sometimes resolvers include validation and sometimes they don't) they have to implement themselves.