Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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.5.1 to 6.6.0

215

dist/commonjs/main.js

@@ -532,6 +532,2 @@ 'use strict';

const normalizeImportMapForProject = (importMap, httpResolutionOrigin = "http://fake_origin_unlikely_to_collide.ext") => {
return normalizeImportMap(importMap, httpResolutionOrigin);
};
const pathnameToExtension = pathname => {

@@ -604,210 +600,2 @@ const slashLastIndex = pathname.lastIndexOf("/");

const startsWithWindowsDriveLetter = string => {
const firstChar = string[0];
if (!/[a-zA-Z]/.test(firstChar)) return false;
const secondChar = string[1];
if (secondChar !== ":") return false;
return true;
};
const isWindowsPath = path => startsWithWindowsDriveLetter(path) && path[2] === "\\";
const replaceBackSlashesWithSlashes = string => string.replace(/\\/g, "/");
const operatingSystemPathToPathname = operatingSystemPath => {
if (typeof operatingSystemPath !== "string") {
throw new TypeError(`operatingSystemPath must be a string, got ${operatingSystemPath}`);
}
if (operatingSystemPath.startsWith("file://")) {
const pathname = operatingSystemPath.slice("file://".length);
if (pathname.endsWith("/")) {
return pathname.slice(0, -1);
}
return pathname;
}
if (isWindowsPath(operatingSystemPath)) {
return `/${replaceBackSlashesWithSlashes(operatingSystemPath)}`;
} // linux and mac operatingSystemFilename === pathname
if (operatingSystemPath.endsWith("/")) {
return operatingSystemPath.slice(0, -1);
}
return operatingSystemPath;
};
const pathnameToRelativePath = (pathname, otherPathname) => pathname.slice(otherPathname.length);
// https://github.com/benjamingr/RegExp.escape/blob/master/polyfill.js
const escapeRegexpSpecialCharacters = string => {
string = String(string);
let i = 0;
let escapedString = "";
while (i < string.length) {
const char = string[i];
i++;
escapedString += isRegExpSpecialChar(char) ? `\\${char}` : char;
}
return escapedString;
};
const isRegExpSpecialChar = char => regexpSpecialChars.indexOf(char) > -1;
const regexpSpecialChars = ["/", "^", "\\", "[", "]", "(", ")", "{", "}", "?", "+", "*", ".", "|", "$"];
const resolveImportForProject = ({
projectPath,
specifier,
importer = projectPathname,
importMap = {},
importDefaultExtension,
httpResolutionForcing = true,
httpResolutionOrigin = "http://fake_origin_unlikely_to_collide.ext",
insideProjectForcing = true
}) => {
if (typeof projectPath !== "string") {
throw new TypeError(`projectPath must be a string, got ${projectPath}`);
}
if (importer && !hasScheme(importer)) {
throw new Error(`importer must have a scheme, got ${importer}`);
}
const projectPathname = operatingSystemPathToPathname(projectPath);
const projectHref = `file://${projectPathname}`;
const importerHref = importer || projectHref;
if (insideProjectForcing && importer !== projectHref && hrefUseFileProtocol(importerHref) && !importerHref.startsWith(`${projectHref}/`)) {
throw new Error(formulateImporterMustBeInsideProject({
projectPath,
importer
}));
}
let importerForProject;
if (httpResolutionForcing) {
if (importerHref === projectHref) {
importerForProject = `${httpResolutionOrigin}`;
} else if (importerHref.startsWith(`${projectHref}/`)) {
const importerPathname = hrefToPathname(importerHref);
const importerRelativePath = pathnameToRelativePath(importerPathname, projectPathname); // 99% of the time importer is an operating system path
// here we ensure / is resolved against project by forcing an url resolution
// prefixing with origin
importerForProject = `${httpResolutionOrigin}${importerRelativePath}`;
} else {
// there is already a scheme (http, https, file), keep it
// it means there is an absolute import starting with file:// or http:// for instance.
importerForProject = importerHref;
}
} else {
importerForProject = importerHref;
}
if (hrefUseFileProtocol(importer) && !isOriginRelativeSpecifier(specifier)) {
const url = resolveUrl(specifier, importer);
if (hrefUseFileProtocol(url)) {
const isOutsideProject = url !== projectHref && !url.startsWith(`${projectHref}/`);
if (isOutsideProject) {
if (insideProjectForcing) {
throw new Error(formulateImportMustBeInsideProject({
projectPath,
specifier,
importer,
importUrl: url
}));
}
return url;
}
}
}
let importUrl;
try {
importUrl = resolveImport({
specifier,
importer: importerForProject,
importMap,
defaultExtension: importDefaultExtension
});
} catch (e) {
const httpResolutionOriginRegExp = new RegExp(escapeRegexpSpecialCharacters(httpResolutionOrigin), "g");
const projectOrigin = `file://${projectPathname}`;
e.stack = e.stack.replace(httpResolutionOriginRegExp, projectOrigin);
e.message = e.message.replace(httpResolutionOriginRegExp, projectOrigin);
throw e;
}
if (insideProjectForcing && // only if use file protocol because
// it's ok to have an external import like "https://cdn.com/jquery.js"
hrefUseFileProtocol(importUrl) && importUrl !== projectHref && !importUrl.startsWith(`${projectHref}/`)) {
throw new Error(formulateImportMustBeInsideProject({
projectPath,
specifier,
importer,
importUrl
}));
}
if (httpResolutionForcing && hrefToOrigin(importUrl) === httpResolutionOrigin) {
const importRelativePath = hrefToPathname(importUrl);
return `${projectHref}${importRelativePath}`;
}
return importUrl;
};
const isOriginRelativeSpecifier = specifier => {
return specifier[0] === "/" && specifier[1] !== "/";
};
const hrefUseFileProtocol = specifier => specifier.startsWith("file://");
const formulateImporterMustBeInsideProject = ({
projectPath,
importer
}) => `importer must be inside project.
--- importer ---
${importer}
--- project path ---
${projectPath}`;
const formulateImportMustBeInsideProject = ({
projectPath,
specifier,
importer,
importUrl
}) => `import must be inside project.
--- import url ---
${importUrl}
--- project path ---
${projectPath}
--- specifier ---
${specifier}
--- importer ---
${importer}`;
const resolveSpecifierForProject = (specifier, projectPathname, httpResolutionOrigin = "http://fake_origin_unlikely_to_collide.ext") => {
const specifierHttpResolved = resolveSpecifier(specifier, httpResolutionOrigin);
if (hrefToOrigin(specifierHttpResolved) === httpResolutionOrigin) {
const specifierRelativePath = hrefToPathname(specifierHttpResolved);
return `file://${projectPathname}${specifierRelativePath}`;
}
return specifierHttpResolved;
};
/**

@@ -1011,7 +799,4 @@ * wrapImportMap can be used to remap all your imports under a folder.

exports.normalizeImportMap = normalizeImportMap;
exports.normalizeImportMapForProject = normalizeImportMapForProject;
exports.resolveImport = resolveImport;
exports.resolveImportForProject = resolveImportForProject;
exports.resolveSpecifier = resolveSpecifier;
exports.resolveSpecifierForProject = resolveSpecifierForProject;
exports.resolveUrl = resolveUrl;

@@ -1018,0 +803,0 @@ exports.sortImportMap = sortImportMap;

export { applyImportMap } from "./src/applyImportMap/applyImportMap.js"
export { composeTwoImportMaps } from "./src/composeTwoImportMaps/composeTwoImportMaps.js"
export { normalizeImportMap } from "./src/normalizeImportMap/normalizeImportMap.js"
export {
normalizeImportMapForProject,
} from "./src/normalizeImportMapForProject/normalizeImportMapForProject.js"
export { resolveImport } from "./src/resolveImport/resolveImport.js"
export { resolveImportForProject } from "./src/resolveImportForProject/resolveImportForProject.js"
export { resolveSpecifier } from "./src/resolveSpecifier/resolveSpecifier.js"
export {
resolveSpecifierForProject,
} from "./src/resolveSpecifierForProject/resolveSpecifierForProject.js"
export { resolveUrl } from "./src/resolveUrl/resolveUrl.js"
export { sortImportMap } from "./src/sortImportMap/sortImportMap.js"
export { wrapImportMap } from "./src/wrapImportMap/wrapImportMap.js"

15

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

@@ -42,14 +42,13 @@ "repository": {

"dependencies": {
"@jsenv/href": "1.2.0",
"@jsenv/operating-system-path": "3.1.0"
"@jsenv/href": "1.2.0"
},
"devDependencies": {
"@dmail/assert": "3.14.0",
"@jsenv/auto-publish": "1.9.0",
"@jsenv/bundling": "7.6.2",
"@jsenv/auto-publish": "2.0.0",
"@jsenv/bundling": "7.7.1",
"@jsenv/codecov-upload": "2.0.0",
"@jsenv/eslint-config": "10.2.0",
"@jsenv/eslint-config": "11.3.0",
"@jsenv/execution": "6.11.0",
"@jsenv/node-launcher": "4.26.0",
"@jsenv/node-module-import-map": "8.2.1",
"@jsenv/node-module-import-map": "8.3.0",
"@jsenv/prettier-config": "1.0.1",

@@ -59,3 +58,3 @@ "@jsenv/prettier-check-project": "3.5.0",

"babel-eslint": "11.0.0-beta.0",
"eslint": "6.5.1",
"eslint": "6.6.0",
"prettier": "1.18.2",

@@ -62,0 +61,0 @@ "rimraf": "3.0.0"

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