Add support for `package.json` `exports` field
If a module package.json specifies exports, GraalJs will now read them and prefer exports over standard resolution; export types can be registered by the developer as preferred. In lieu of these types (and as a default), the following export types are preferred, in order:
-
graaljs -
import(in ESM) -
require -
default
Fixes and closes oracle/graaljs#903
This is quick and dirty and probably not mergeable as expressed, but we are using it effectively downstream.
cc / @woess
I don't know how to add tests to GraalJs yet. I'm happy to figure it out and add tests if there is any desire to merge this
Happy to accept contributions in that area. The commonjs support has been a bit neglected tbh...
We will need some test coverage for it.
I think you can find most of the tests here: graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/builtins/CommonJSRequireTest.java graal-js/src/com.oracle.truffle.js.test/commonjs graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/builtins/CommonJSWithCustomFsTest.java
@woess Thanks for the review. I'll take a look at adding some tests
This is great, especially Conditional exports support. Could also support patterns
"exports": {
"./features/*.js": "./src/features/*.js"
},
for
import featureX from 'es-module-package/features/x.js';