@esm.sh/import-map 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +16 -0
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -39,6 +39,8 @@ async function addImport(importMap, specifier, noSRI) {
39
39
  const meta = await fetchImportMeta(cdnOrigin, imp, target);
40
40
  const mark = /* @__PURE__ */ new Set();
41
41
  await addImportImpl(importMap, mark, meta, false, void 0, cdnOrigin, target, noSRI ?? false);
42
+ pruneScopeSpecifiersShadowedByImports(importMap);
43
+ pruneEmptyScopes(importMap);
42
44
  }
43
45
  async function addImportImpl(importMap, mark, imp, indirect, targetImports, cdnOrigin, target, noSRI) {
44
46
  const markedSpecifier = `${specifierOf(imp)}${SPECIFIER_MARK_SEPARATOR}${imp.version}`;
@@ -283,6 +285,20 @@ function pruneEmptyScopes(importMap) {
283
285
  }
284
286
  }
285
287
  }
288
+ function pruneScopeSpecifiersShadowedByImports(importMap) {
289
+ for (const [scopeKey, scopedImports] of Object.entries(importMap.scopes)) {
290
+ if (scopeKey.startsWith("https://") || scopeKey.startsWith("http://")) {
291
+ const url = new URL(scopeKey);
292
+ if (url.pathname === "/") {
293
+ for (const specifier of Object.keys(scopedImports)) {
294
+ if (specifier in importMap.imports) {
295
+ delete scopedImports[specifier];
296
+ }
297
+ }
298
+ }
299
+ }
300
+ }
301
+ }
286
302
  function parseEsmPath(pathnameOrUrl) {
287
303
  let pathname;
288
304
  if (pathnameOrUrl.startsWith("https://") || pathnameOrUrl.startsWith("http://")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esm.sh/import-map",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "A import map parser and resolver.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",