From a9e092a1b0abfbdc67b4309af12a04b2d9056a7d Mon Sep 17 00:00:00 2001 From: Mauricio Alves Date: Sat, 27 Apr 2024 18:57:54 -0300 Subject: [PATCH] feat: add support for reading the mapping of loaded imports (#2484) --- src/features/import-maps.js | 5 +++++ test/system-core.mjs | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/features/import-maps.js b/src/features/import-maps.js index 3d6a66e2..130ba851 100644 --- a/src/features/import-maps.js +++ b/src/features/import-maps.js @@ -19,6 +19,11 @@ systemJSPrototype.prepareImport = function (doProcessScripts) { } return importMapPromise; }; + +systemJSPrototype.getImportMap = function () { + return JSON.parse(JSON.stringify(importMap)); +}; + if (hasDocument) { processScripts(); window.addEventListener('DOMContentLoaded', processScripts); diff --git a/test/system-core.mjs b/test/system-core.mjs index 4e3d96f4..e6556810 100644 --- a/test/system-core.mjs +++ b/test/system-core.mjs @@ -272,6 +272,17 @@ describe('Core API', function () { assert([...loader.entries()].some(entry => entry[0] === 'http://i' && entry[1].a === 'b')); }) + + it('Supports System.getImportMap', function () { + const importMap = loader.getImportMap(); + + assert( + Object.hasOwn(importMap, 'imports') && + Object.hasOwn(importMap, 'scopes') && + Object.hasOwn(importMap, 'depcache') && + Object.hasOwn(importMap, 'integrity') + ); + }) }); });