From 6456d4ef7627ec51f1a8e3bdce618e0e9ffc21d3 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Sun, 10 Apr 2022 14:59:42 +0530 Subject: [PATCH] Cache cssPath --- scripts/postcss/css-url-processor.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/postcss/css-url-processor.js b/scripts/postcss/css-url-processor.js index c050a898..3ae7c60d 100644 --- a/scripts/postcss/css-url-processor.js +++ b/scripts/postcss/css-url-processor.js @@ -16,6 +16,7 @@ limitations under the License. const valueParser = require("postcss-value-parser"); const resolve = require("path").resolve; +let cssPath; function colorsFromURL(url, colorMap) { const params = new URL(`file://${url}`).searchParams; @@ -44,7 +45,6 @@ function processURL(decl, replacer, colorMap) { } const urlStringNode = node.nodes[0]; const oldURL = urlStringNode.value; - const cssPath = decl.source?.input.file.replace(/[^/]*$/, ""); const oldURLAbsolute = resolve(cssPath, oldURL); const colors = colorsFromURL(oldURLAbsolute, colorMap); if (!colors) { @@ -84,6 +84,7 @@ module.exports = (opts = {}) => { Go through each declaration and if it contains an URL, replace the url with the result of running replacer(url) */ + cssPath = root.source?.input.file.replace(/[^/]*$/, ""); root.walkDecls(decl => processURL(decl, opts.replacer, colorMap)); }, };