Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@jsenv/import-map
Advanced tools
importMap programmatic implementation
jsenv-import-map
is a javasScript implementation of the importMap specification. It is written using es modules and is compatible with Node.js.
I made this project because jsenv uses importMap but they are not yet available in browsers.
— see importMap spec
@jsenv/import-map
has the following exports:
takes {
importMap
,href
,importerHref
} and returns either thehref
remapped byimportMap
or the originalhref
.
import { applyImportMap } from "@jsenv/import-map"
const href = "http://domain.com/foo"
const importMap = {
imports: {
"http://domain.com/foo": "http://domain.com/bar",
},
}
const hrefRemapped = applyImportMap({
href,
importMap,
})
console.log(hrefRemapped)
The code above logs "http://domain.com/bar"
.
The provided importMap
specifiers must be absolute and sorted to work as expected.
You can use normalizeImportMap to do that.
— see applyImportMap source code
takes (
leftImportMap
,rightImportMap
) and returns an importMap being the composition of the two.
import { composeTwoImportMaps } from "@jsenv/import-map"
const leftImportMap = {
imports: {
foo: "bar",
},
}
const rightImportMap = {
imports: {
foo: "whatever",
},
}
const importMap = composeTwoImportMaps(leftImportMap, rightImportMap)
console.log(importMap.imports.foo)
The code above logs "whatever"
.
— see composeTwoImportMaps source code
takes (
importMap
,href
) and returns an importMap where relative specifier are resolved againsthref
and sorted.
import { normalizeImportMap } from "@jsenv/import-map"
const importMap = {
imports: {
foo: "http://cdndomain.com/bar",
},
}
const href = "http://mydomain.com"
const importMapNormalized = normalizeImportMap(importMap, href)
console.log(importMapNormalized.imports["http://mydomain.com/foo"])
The code above logs "http://cdndomain.com/bar"
.
— see normalizeImportMap source code
takes {
specifier
,importer
,importMap
,defaultExtension
} and returns a url.
import { resolveImport } from "@jsenv/import-map"
const importUrl = resolveImport({
specifier: "../index.js",
importer: "http://domain.com/folder/file.js",
importMap: {
imports: {
"http://domain.com/index.js": "http://domain.com/main.js",
},
},
})
console.log(importUrl)
The code above logs "http://domain.com/main.js"
.
— see resolveImport source code
takes (
specifier
,importer
) and returnsspecifier
resolved againstimporter
.
import { resolveSpecifier } from "@jsenv/import-map"
const specifier = "../file.js"
const importer = "http://mydomain.com/folder/index.js"
const specifierResolved = resolveSpecifier(specifier, importer)
console.log(specifierResolved)
The code above logs "http://mydomain.com/file.js"
.
— see resolveSpecifier source code
takes (
importMap
,folderRelativeName
) and returns an importMap wrapped insidefolderRelativeName
.
import { wrapImportMap } from "@jsenv/import-map"
const importMap = {
imports: {
foo: "bar",
},
}
const folderRelativeName = "/dist"
const importMapWrapped = wrapImportMap(specifier, importer)
console.log(importMapWrapped.imports.foo)
The code above logs "/dist/bar"
.
This feature is not part of the spec but is usefull to redirect your imports inside a given folder.
— see wrapImportMap source code
To install @jsenv/import-map
you need to configure npm to use github registry for this package.
Github registry requires an authentification token. If you haven't configured it already, read how in the documentation below.
— see Authenticating to GitHub Package Registry documentation on GitHub
For the record, you can save your token with this command
npm config set '//npm.pkg.github.com/:_authToken' 'personal-access-token'
Run the command below to use github registry for @jsenv/import-map
npm config set @jsenv:registry https://npm.pkg.github.com
npm install @jsenv/import-map@5.2.0
Same steps as Installation using npm replacing step 3 by
yarn add @jsenv/import-map@5.2.0
FAQs
Helpers to implement importmaps.
The npm package @jsenv/import-map receives a total of 349 weekly downloads. As such, @jsenv/import-map popularity was classified as not popular.
We found that @jsenv/import-map demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.