Socket
Socket
Sign inDemoInstall

@jsenv/import-map

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsenv/import-map - npm Package Compare versions

Comparing version 6.6.1 to 6.7.0

180

dist/commonjs/main.js

@@ -329,3 +329,3 @@ 'use strict';

var _defineProperty = (function (obj, key, value) {
var defineProperty = (function (obj, key, value) {
// Shortcircuit the slow defineProperty path when possible.

@@ -357,4 +357,4 @@ // We are trying to avoid issues where setters defined on the

// eslint-disable-next-line no-loop-func
ownKeys(source, true).forEach(function (key) {
_defineProperty(target, key, source[key]);
ownKeys(Object(source), true).forEach(function (key) {
defineProperty(target, key, source[key]);
});

@@ -365,3 +365,3 @@ } else if (Object.getOwnPropertyDescriptors) {

// eslint-disable-next-line no-loop-func
ownKeys(source).forEach(function (key) {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));

@@ -620,173 +620,2 @@ });

var wrapImportMap = function wrapImportMap(importMap, folderRelativeName) {
var ensureInto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
assertImportMap(importMap);
if (typeof folderRelativeName !== "string") {
throw new TypeError(formulateFolderRelativeNameMustBeAString({
folderRelativeName: folderRelativeName
}));
}
var into = "/".concat(folderRelativeName, "/");
var imports = importMap.imports,
scopes = importMap.scopes;
var importsForWrapping;
if (imports) {
importsForWrapping = wrapTopLevelImports(imports, into);
} else {
importsForWrapping = {};
}
var scopesForWrapping;
if (scopes) {
scopesForWrapping = wrapScopes(scopes, into);
} else {
scopesForWrapping = {};
}
if (ensureInto) {
// ensure anything not directly remapped is remapped inside into
importsForWrapping[into] = into;
importsForWrapping["/"] = into; // and when already into, you stay inside
scopesForWrapping[into] = _defineProperty({}, into, into);
}
return {
imports: importsForWrapping,
scopes: scopesForWrapping
};
};
var wrapScopes = function wrapScopes(scopes, into) {
var scopesWrapped = {};
Object.keys(scopes).forEach(function (scopeKey) {
var scopeValue = scopes[scopeKey];
var scopeKeyWrapped = wrapAddress(scopeKey, into);
var _wrapImports = wrapImports(scopeValue, into),
importsWrapped = _wrapImports.importsWrapped,
importsRemaining = _wrapImports.importsRemaining;
var scopeValueWrapped;
if (scopeHasLeadingSlashScopedRemapping(scopeValue, scopeKey)) {
var leadingSlashSpecifier = "".concat(into).concat(scopeKey.slice(1));
scopeValueWrapped = {}; // put everything except the leading slash remapping
Object.keys(importsWrapped).forEach(function (importKeyWrapped) {
if (importKeyWrapped === leadingSlashSpecifier || importKeyWrapped === into) {
return;
}
scopeValueWrapped[importKeyWrapped] = importsWrapped[importKeyWrapped];
});
Object.keys(importsRemaining).forEach(function (importKey) {
if (importKey === scopeKey || importKey === "/") {
return;
}
scopeValueWrapped[importKey] = importsRemaining[importKey];
}); // now put leading slash remapping to ensure it comes last
scopeValueWrapped[leadingSlashSpecifier] = leadingSlashSpecifier;
scopeValueWrapped[scopeKey] = leadingSlashSpecifier;
scopeValueWrapped[into] = leadingSlashSpecifier;
scopeValueWrapped["/"] = leadingSlashSpecifier;
} else {
scopeValueWrapped = _objectSpread({}, importsWrapped, {}, importsRemaining);
}
scopesWrapped[scopeKeyWrapped] = scopeValueWrapped;
if (scopeKeyWrapped !== scopeKey) {
scopesWrapped[scopeKey] = _objectSpread({}, scopeValueWrapped);
}
});
return scopesWrapped;
};
var scopeHasLeadingSlashScopedRemapping = function scopeHasLeadingSlashScopedRemapping(scopeImports, scopeKey) {
return scopeKey in scopeImports && scopeImports[scopeKey] === scopeKey && "/" in scopeImports && scopeImports["/"] === scopeKey;
};
var wrapImports = function wrapImports(imports, into) {
var importsWrapped = {};
var importsRemaining = {};
Object.keys(imports).forEach(function (importKey) {
var importValue = imports[importKey];
var importKeyWrapped = wrapSpecifier(importKey, into);
var importValueWrapped = wrapAddress(importValue, into);
var keyChanged = importKeyWrapped !== importKey;
var valueChanged = importValueWrapped !== importValue;
if (keyChanged || valueChanged) {
importsWrapped[importKeyWrapped] = importValueWrapped;
} else {
importsRemaining[importKey] = importValue;
}
});
return {
importsWrapped: importsWrapped,
importsRemaining: importsRemaining
};
};
var wrapTopLevelImports = function wrapTopLevelImports(imports, into) {
var _wrapImports2 = wrapImports(imports, into),
importsWrapped = _wrapImports2.importsWrapped,
importsRemaining = _wrapImports2.importsRemaining;
return _objectSpread({}, importsWrapped, {}, importsRemaining);
};
var wrapSpecifier = function wrapSpecifier(specifier, into) {
if (specifier.startsWith("//")) {
return specifier;
}
if (specifier[0] === "/") {
return "".concat(into).concat(specifier.slice(1));
}
if (specifier.startsWith("./")) {
return "./".concat(into).concat(specifier.slice(2));
}
return specifier;
};
var wrapAddress = function wrapAddress(string, into) {
if (string.startsWith("//")) {
return string;
}
if (string[0] === "/") {
return "".concat(into).concat(string.slice(1));
}
if (string.startsWith("./")) {
return "./".concat(into).concat(string.slice(2));
}
if (string.startsWith("../")) {
return string;
}
if (hasScheme(string)) {
return string;
} // bare
return "".concat(into).concat(string);
};
var formulateFolderRelativeNameMustBeAString = function formulateFolderRelativeNameMustBeAString(_ref) {
var folderRelativeName = _ref.folderRelativeName;
return "folderRelativeName must be a string.\n--- folder relative name ---\n".concat(folderRelativeName);
};
exports.applyImportMap = applyImportMap;

@@ -799,3 +628,2 @@ exports.composeTwoImportMaps = composeTwoImportMaps;

exports.sortImportMap = sortImportMap;
exports.wrapImportMap = wrapImportMap;
//# sourceMappingURL=main.js.map

@@ -8,2 +8,1 @@ export { applyImportMap } from "./src/applyImportMap.js"

export { sortImportMap } from "./src/sortImportMap.js"
export { wrapImportMap } from "./src/wrapImportMap.js"

40

package.json
{
"name": "@jsenv/import-map",
"description": "Helpers to implement importMap",
"version": "6.6.1",
"version": "6.7.0",
"description": "Helpers to implement importmaps.",
"license": "MIT",

@@ -17,4 +17,9 @@ "repository": {

},
"type": "module",
"exports": {
".": "./index.js",
"./": "./"
},
"module": "index.js",
"main": "dist/commonjs/main.js",
"module": "index.js",
"files": [

@@ -25,5 +30,2 @@ "/dist/",

],
"exports": {
"./": "./"
},
"scripts": {

@@ -33,6 +35,9 @@ "test": "node ./script/test/test.js",

"eslint-check": "eslint .",
"prettier-check": "node ./script/prettier-check/prettier-check.js",
"prettier-format": "node ./script/prettier-format/prettier-format.js",
"prettier-format-stage": "npm run prettier-format -- --staged",
"prettier-check": "npm run prettier-format -- --dry-run",
"upload-coverage": "node ./script/upload-coverage/upload-coverage.js",
"generate-commonjs-bundle": "node ./script/generate-commonjs-bundle/generate-commonjs-bundle.js",
"generate-import-map": "node ./script/generate-import-map/generate-import-map.js",
"install-git-hooks": "node ./script/install-git-hooks/install-git-hooks.js",
"dist": "npm run clean && npm run generate-commonjs-bundle",

@@ -42,16 +47,19 @@ "clean": "rimraf dist && rimraf coverage",

"prepublishOnly": "node ./script/transform-package/remove-postinstall.js && npm run dist",
"postpublish": "node ./script/transform-package/restore-postinstall.js"
"postpublish": "node ./script/transform-package/restore-postinstall.js",
"git-hook-pre-commit": "npm run prettier-format-stage"
},
"dependencies": {},
"devDependencies": {
"@jsenv/assert": "1.1.1",
"@jsenv/codecov-upload": "2.0.0",
"@jsenv/core": "10.0.0-alpha.11",
"@jsenv/eslint-config": "11.3.0",
"@jsenv/assert": "1.2.1",
"@jsenv/codecov-upload": "3.1.0",
"@jsenv/core": "10.5.0",
"@jsenv/eslint-config": "12.1.0",
"@jsenv/git-hooks": "1.2.0",
"@jsenv/github-release-package": "1.1.1",
"@jsenv/node-module-import-map": "8.6.0",
"@jsenv/package-publish": "1.1.0",
"@jsenv/prettier-check-project": "4.0.0",
"@jsenv/node-module-import-map": "10.0.1",
"@jsenv/package-publish": "1.3.1",
"@jsenv/prettier-check-project": "5.2.0",
"@jsenv/prettier-config": "1.1.0",
"eslint": "6.7.2",
"babel-eslint": "11.0.0-beta.0",
"eslint": "6.8.0",
"prettier": "1.19.1",

@@ -58,0 +66,0 @@ "rimraf": "3.0.0"

@@ -1,3 +0,5 @@

# jsenv-import-map
# import-map
Helpers to implement importmaps.
[![github package](https://img.shields.io/github/package-json/v/jsenv/jsenv-import-map.svg?logo=github&label=package)](https://github.com/jsenv/jsenv-import-map/packages)

@@ -8,27 +10,30 @@ [![npm package](https://img.shields.io/npm/v/@jsenv/import-map.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/import-map)

Helpers to implement importMap
# Table of contents
## Table of contents
- [Presentation](#Presentation)
- [Usage](#Usage)
- [Installation](#installation)
- [Documentation](#Usage)
- [composeTwoImportMaps](#composetwoimportmaps)
- [normalizeImportMap](#normalizeimportmap)
- [resolveImport](#resolveimport)
- [Installation](#installation)
## Presentation
# Presentation
`@jsenv/import-map` can be used to implement the behaviour of importMap as described in the specification. It is written using es modules and is compatible with Node.js.<br />
`@jsenv/import-map` can be used to implement the behaviour of importMap as described in the specification. It is written using es modules and is compatible with Node.js.
— see [importMap spec](https://github.com/WICG/import-maps)
## Usage
# Installation
```console
npm install --save-dev @jsenv/import-map@6.7.0
```
# Documentation
`@jsenv/import-map` exports are documented in this section.
### composeTwoImportMaps
## composeTwoImportMaps
> `composeTwoImportMaps` takes two `importMap` and return a single `importMap` being the composition of the two.<br />
> Implemented by [src/composeTwoImportMaps.js](src/composeTwoImportMaps.js)
`composeTwoImportMaps` takes two `importMap` and return a single `importMap` being the composition of the two.

@@ -62,7 +67,8 @@ ```js

### normalizeImportMap
— source code at [src/composeTwoImportMaps.js](./src/composeTwoImportMaps.js).
> `normalizeImportMap` returns an `importMap` resolved against an `url` and sorted.<br />
> Implemented by [src/normalizeImportMap.js](src/normalizeImportMap.js)
## normalizeImportMap
`normalizeImportMap` returns an `importMap` resolved against an `url` and sorted.
```js

@@ -93,7 +99,8 @@ import { normalizeImportMap } from "@jsenv/import-map"

### resolveImport
— source code at [src/normalizeImportMap.js](./src/normalizeImportMap.js).
> `resolveImport` returns an import `url` applying an `importMap` to `specifier` and `importer`.<br />
> Implemented by [src/resolveImport.js](src/resolveImport.js)
## resolveImport
`resolveImport` returns an import `url` applying an `importMap` to `specifier` and `importer`. The provided `importMap` must be resolved and sorted to work as expected. You can use [normalizeImportMap](#normalizeimportmap) to do that.
```js

@@ -119,16 +126,2 @@ import { resolveImport } from "@jsenv/import-map"

The provided `importMap` must be resolved and sorted to work as expected. You can use [normalizeImportMap](#normalizeimportmap) to do that.<br />
## Installation
If you never installed a jsenv package, read [Installing a jsenv package](https://github.com/jsenv/jsenv-core/blob/master/docs/installing-jsenv-package.md#installing-a-jsenv-package) before going further.
This documentation is up-to-date with a specific version so prefer any of the following commands
```console
npm install --save-dev @jsenv/import-map@6.2.0
```
```console
yarn add --dev @jsenv/import-map@6.2.0
```
— source code at [src/resolveImport.js](./src/resolveImport.js).

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc