@jsenv/import-map
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -383,13 +383,3 @@ 'use strict'; | ||
if (scopes) { | ||
scopesForWrapping = {}; | ||
Object.keys(scopes).forEach(function (scopeKey) { | ||
var scopeValue = scopes[scopeKey]; | ||
var scopeKeyPrefixed = wrapSpecifier(scopeKey, into); | ||
if (scopeKeyPrefixed === scopeKey) { | ||
scopesForWrapping[scopeKey] = scopeValue; | ||
} else { | ||
scopesForWrapping[scopeKeyPrefixed] = wrapImports(scopeValue, into); | ||
} | ||
}); | ||
scopesForWrapping = wrapScopes(scopes, into); | ||
} else { | ||
@@ -400,4 +390,4 @@ scopesForWrapping = {}; | ||
if (imports) { | ||
importsForWrapping = wrapImports(imports, into); | ||
scopesForWrapping[into] = wrapImports(imports, into); | ||
importsForWrapping = wrapTopLevelImports(imports, into); | ||
scopesForWrapping[into] = wrapTopLevelImports(imports, into); | ||
} else { | ||
@@ -420,2 +410,56 @@ importsForWrapping = {}; | ||
var wrapScopes = function wrapScopes(scopes, into) { | ||
var scopesKeyWrapped = {}; | ||
var scopesRemaining = {}; | ||
Object.keys(scopes).forEach(function (scopeKey) { | ||
var scopeValue = scopes[scopeKey]; | ||
var scopeKeyWrapped = wrapSpecifier(scopeKey, into); | ||
if (scopeKeyWrapped === scopeKey) { | ||
scopesRemaining[scopeKey] = scopeValue; | ||
} else { | ||
var _wrapImports = wrapImports(scopeValue, into), | ||
importsWithKeyWrapped = _wrapImports.importsWithKeyWrapped, | ||
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(importsWithKeyWrapped).forEach(function (importKeyWrapped) { | ||
if (importKeyWrapped === leadingSlashSpecifier || importKeyWrapped === into) { | ||
return; | ||
} | ||
scopeValueWrapped[importKeyWrapped] = importsWithKeyWrapped[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 = _objectSpread2({}, importsWithKeyWrapped, {}, importsRemaining); | ||
} | ||
scopesKeyWrapped[scopeKeyWrapped] = scopeValueWrapped; | ||
scopesRemaining[scopeKey] = importsRemaining; | ||
} | ||
}); | ||
return _objectSpread2({}, scopesKeyWrapped, {}, scopesRemaining); | ||
}; | ||
var scopeHasLeadingSlashScopedRemapping = function scopeHasLeadingSlashScopedRemapping(scopeImports, scopeKey) { | ||
return scopeKey in scopeImports && scopeImports[scopeKey] === scopeKey && "/" in scopeImports && scopeImports["/"] === scopeKey; | ||
}; | ||
var wrapImports = function wrapImports(imports, into) { | ||
@@ -438,6 +482,14 @@ var importsWithKeyWrapped = {}; | ||
}); | ||
return { | ||
importsWithKeyWrapped: importsWithKeyWrapped, | ||
importsRemaining: importsRemaining | ||
}; | ||
}; | ||
var importsWrapped = _objectSpread2({}, importsWithKeyWrapped, {}, importsRemaining); | ||
var wrapTopLevelImports = function wrapTopLevelImports(imports, into) { | ||
var _wrapImports2 = wrapImports(imports, into), | ||
importsWithKeyWrapped = _wrapImports2.importsWithKeyWrapped, | ||
importsRemaining = _wrapImports2.importsRemaining; | ||
return importsWrapped; | ||
return _objectSpread2({}, importsWithKeyWrapped, {}, importsRemaining); | ||
}; | ||
@@ -444,0 +496,0 @@ |
{ | ||
"name": "@jsenv/import-map", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -30,13 +30,3 @@ /** | ||
if (scopes) { | ||
scopesForWrapping = {} | ||
Object.keys(scopes).forEach((scopeKey) => { | ||
const scopeValue = scopes[scopeKey] | ||
const scopeKeyPrefixed = wrapSpecifier(scopeKey, into) | ||
if (scopeKeyPrefixed === scopeKey) { | ||
scopesForWrapping[scopeKey] = scopeValue | ||
} else { | ||
scopesForWrapping[scopeKeyPrefixed] = wrapImports(scopeValue, into) | ||
} | ||
}) | ||
scopesForWrapping = wrapScopes(scopes, into) | ||
} else { | ||
@@ -47,4 +37,4 @@ scopesForWrapping = {} | ||
if (imports) { | ||
importsForWrapping = wrapImports(imports, into) | ||
scopesForWrapping[into] = wrapImports(imports, into) | ||
importsForWrapping = wrapTopLevelImports(imports, into) | ||
scopesForWrapping[into] = wrapTopLevelImports(imports, into) | ||
} else { | ||
@@ -68,2 +58,63 @@ importsForWrapping = {} | ||
const wrapScopes = (scopes, into) => { | ||
const scopesKeyWrapped = {} | ||
const scopesRemaining = {} | ||
Object.keys(scopes).forEach((scopeKey) => { | ||
const scopeValue = scopes[scopeKey] | ||
const scopeKeyWrapped = wrapSpecifier(scopeKey, into) | ||
if (scopeKeyWrapped === scopeKey) { | ||
scopesRemaining[scopeKey] = scopeValue | ||
} else { | ||
const { importsWithKeyWrapped, importsRemaining } = wrapImports(scopeValue, into) | ||
let scopeValueWrapped | ||
if (scopeHasLeadingSlashScopedRemapping(scopeValue, scopeKey)) { | ||
const leadingSlashSpecifier = `${into}${scopeKey.slice(1)}` | ||
scopeValueWrapped = {} | ||
// put everything except the leading slash remapping | ||
Object.keys(importsWithKeyWrapped).forEach((importKeyWrapped) => { | ||
if (importKeyWrapped === leadingSlashSpecifier || importKeyWrapped === into) { | ||
return | ||
} | ||
scopeValueWrapped[importKeyWrapped] = importsWithKeyWrapped[importKeyWrapped] | ||
}) | ||
Object.keys(importsRemaining).forEach((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 = { | ||
...importsWithKeyWrapped, | ||
...importsRemaining, | ||
} | ||
} | ||
scopesKeyWrapped[scopeKeyWrapped] = scopeValueWrapped | ||
scopesRemaining[scopeKey] = importsRemaining | ||
} | ||
}) | ||
return { | ||
...scopesKeyWrapped, | ||
...scopesRemaining, | ||
} | ||
} | ||
const scopeHasLeadingSlashScopedRemapping = (scopeImports, scopeKey) => { | ||
return ( | ||
scopeKey in scopeImports && | ||
scopeImports[scopeKey] === scopeKey && | ||
"/" in scopeImports && | ||
scopeImports["/"] === scopeKey | ||
) | ||
} | ||
const wrapImports = (imports, into) => { | ||
@@ -88,7 +139,14 @@ const importsWithKeyWrapped = {} | ||
const importsWrapped = { | ||
return { | ||
importsWithKeyWrapped, | ||
importsRemaining, | ||
} | ||
} | ||
const wrapTopLevelImports = (imports, into) => { | ||
const { importsWithKeyWrapped, importsRemaining } = wrapImports(imports, into) | ||
return { | ||
...importsWithKeyWrapped, | ||
...importsRemaining, | ||
} | ||
return importsWrapped | ||
} | ||
@@ -95,0 +153,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106733
784