Skip to content

Commit

Permalink
feat: add support for reading the mapping of loaded imports (#2484)
Browse files Browse the repository at this point in the history
  • Loading branch information
mac-alves committed Apr 27, 2024
1 parent 3a5f73f commit a9e092a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/features/import-maps.js
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions test/system-core.mjs
Expand Up @@ -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')
);
})
});
});

Expand Down

0 comments on commit a9e092a

Please sign in to comment.