jsenv module resolution
import resolution and remapping.
Introduction
jsenv use its own import resolution mostly because it uses some features not fully available in systemjs and rollup.
It uses resolvePath
function exported here.
Installation
npm install @jsenv/module-resolution
resolvePath
takes { specifier, importer, importMap, defaultExtension } and returns a resolved path.
basic example
import { resolvePath } from "@jsenv/module-resolution"
const resolvePath = resolveImport({
importer: "http://domain.com/folder/file.js",
specifier: "../index.js",
})
console.log(resolvePath)
The code above logs http://domain.com/index.js
.
remapping example
import { resolvePath } from "@jsenv/module-resolution"
const resolvedPath = resolvePath({
importer: "http://domain.com/folder/file.js",
specifier: "../index.js",
importMap: {
imports: {
"/index.js": "/foo.js",
},
},
})
console.log(resolvedPath)
code above logs http://domain.com/foo.js
.
scoped remapping example
import { resolvedPath } from "@jsenv/module-resolution"
const resolvedPath = resolvePath({
importer: "http://domain.com/folder/file.js",
specifier: "../index.js",
importMap: {
imports: {
"/index.js": "/foo.js",
},
scopes: {
"/folder/": {
"/index.js": "/bar.js",
},
},
},
})
console.log(remappedImport)
code above logs http://domain.com/bar.js
.