From 6d724e27e70cd547e5d87cde06a8165d77765ad9 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 5 Apr 2022 15:26:00 +0530 Subject: [PATCH] No need to check if icons are already written --- scripts/postcss/css-url-to-variables.js | 10 +--------- scripts/postcss/tests/css-url-to-variables.test.js | 5 ++++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/scripts/postcss/css-url-to-variables.js b/scripts/postcss/css-url-to-variables.js index 4480a2b8..1d4666f4 100644 --- a/scripts/postcss/css-url-to-variables.js +++ b/scripts/postcss/css-url-to-variables.js @@ -56,15 +56,7 @@ function addResolvedVariablesToRootSelector(root, { Rule, Declaration }) { function populateMapWithIcons(map, cssFileLocation) { const location = cssFileLocation.match(/(.+)\/.+\.css/)?.[1]; const sharedObject = map.get(location); - if (sharedObject?.["icon"]) { - /** - * This postcss plugin is going to run on all theme variants of a single theme. - * But we only really need to populate the map once since theme variants only differ - * by the values of the base-variables and we don't care about values here. - */ - return; - } - map.set(location, { ...sharedObject, "icon": Object.fromEntries(urlVariables) }); + sharedObject["icon"] = Object.fromEntries(urlVariables); } /* * diff --git a/scripts/postcss/tests/css-url-to-variables.test.js b/scripts/postcss/tests/css-url-to-variables.test.js index e298599d..f406a38a 100644 --- a/scripts/postcss/tests/css-url-to-variables.test.js +++ b/scripts/postcss/tests/css-url-to-variables.test.js @@ -50,6 +50,7 @@ module.exports.tests = function tests() { }, "map is populated with icons": async (assert) => { const compiledVariables = new Map(); + compiledVariables.set("/foo/bar", { "derived-variables": ["background-color--darker-20", "accent-color--lighter-15"] }); const inputCSS = `div { background: no-repeat center/80% url("../img/image.svg?primary=main-color--darker-20"); } @@ -61,7 +62,9 @@ module.exports.tests = function tests() { "icon-url-1": "/home/foo/bar/cool.svg?primary=blue&secondary=green", }; await postcss([plugin({compiledVariables})]).process(inputCSS, { from: "/foo/bar/test.css", }); - assert.deepEqual(expectedObject, compiledVariables.get("/foo/bar")["icon"]); + const sharedVariable = compiledVariables.get("/foo/bar"); + assert.deepEqual(["background-color--darker-20", "accent-color--lighter-15"], sharedVariable["derived-variables"]); + assert.deepEqual(expectedObject, sharedVariable["icon"]); } }; };