From 9e89a1002a2261615238b2f0433cbee8a1b9a2b7 Mon Sep 17 00:00:00 2001 From: Cody Olsen Date: Fri, 18 Sep 2020 16:01:47 +0200 Subject: [PATCH] fix: try again to make the filter work --- src/plugin.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/plugin.js b/src/plugin.js index 95ff38e..ef9480d 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -43,13 +43,19 @@ async function fetchImportMaps(urls = []) { } } +// The resolve option in postcss-import doesn't support async functions or promises, +// thus we have to workaround it +const mapping = new Map(); + // @TODO this could be a @eik/import-map-utils package -async function getImportMap({ +async function populateImportMap({ path: eikPath = path.join(process.cwd(), 'eik.json'), urls = [], imports = {}, } = {}) { - const mapping = new Map(); + // Reset the map to avoid pollution + mapping.clear(); + const importmapUrls = await readEikJSONMaps(eikPath); for (const map of importmapUrls) { urls.push(map); @@ -70,20 +76,14 @@ async function getImportMap({ mapping.set(key, value); }); - - return mapping; } -// The resolve option in postcss-import doesn't support async functions or promises, -// thus we have to workaround it -let mapping = new Map(); - export default postcss.plugin( '@eik/postcss-import-map', ({ path, urls, imports } = {}) => { // Work with options here return async (root) => { - mapping = await getImportMap({ path, urls, imports }); + await populateImportMap({ path, urls, imports }); root.walkAtRules('import', (decl) => { let key; // First check if it's possibly using syntax like url()