Skip to content
iambumblehead edited this page Aug 4, 2022 · 6 revisions

resolvewithplus

resolvewithplus( 'koa', '/root/resolvewith/test/' );
// '/root/resolvewith/node_modules/koa/dist/koa.mjs'

resolvewithplus resolves module paths à la the import.meta.resolve node.js function or the import-meta-resolve npm package. resolvewithplus is only ~5.12kB compared to import-meta-resolve's ~182kB size, at this time of writing. resolvewithplus has limited goals and exists mostly to be small and to resolve module paths for esmock,

  • returns a path string or null, doesn't try to follow node.js' error-handling behaviour,
  • locates modules at the local-filesystem only,
  • locates paths with non-standard extensions such as ".tsx",
  • caches module paths it returns, and returns the same paths for subsequent matching calls,
  • still improving and fails to resolve some ESM export patterns, please report any issue you find,
  • is called the same way as import.meta.resolve, with two parameters "specifier" and a "parent"

supported ESM export patterns

More "complicated" ESM export patterns may yet be un-supported, for example "#" sign subpath-patterns are still un-supported. The support chart below shows export patterns currently supported by esmock,

 
{
  "name": "test",
  "exports": "./main.js"
}
top-level exports
 
{
  "name": "test",
  "exports": {
    "types": "./main.ts",
    "require": "./main.js",
    "import": "./main.mjs"
  }
}
subpath exports, simplified
 
{
  "name": "test",
  "exports": {
    "." : {
      "require": "./main.js",
      "import": "./main.mjs"
    }
  }
}
subpath exports, nested
 
{
  "name": "test",
  "exports": {
    "." : [ {
      "import" : "./index.mjs",
      "require" : "./index.cjs"
    }, "./index.cjs" ]
  }
}
subpath exports, nested list
Clone this wiki locally