5.3.0 • Published 5 years ago

@jsenv/module-resolution v5.3.0

Weekly downloads
25
License
MIT
Repository
github
Last release
5 years ago

jsenv module resolution

npm package build codecov

import resolution and remapping.

Introduction

This module exports a resolvePath you can use to resolve an import. It is used by jsenv to find every import statement files.

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.

5.3.0

5 years ago

5.2.0

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.0.0

5 years ago

3.7.0

5 years ago

3.6.0

5 years ago

3.5.0

5 years ago

3.4.0

5 years ago

3.3.0

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.5.0

5 years ago

2.4.0

5 years ago

2.3.0

5 years ago

2.0.0

5 years ago

1.0.0

5 years ago