Skip to content

Commit c8f3595

Browse files
committed
[FIX] Variables: improved detection of library variables
1 parent 3d16d5a commit c8f3595

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Builder.prototype.build = function(options) {
191191
// inject the library name as prefix (e.g. "sap.m" as "_sap_m")
192192
if (options.library && typeof options.library.name === "string") {
193193
const libName = config.libName = options.library.name;
194+
config.libPath = libName.replace(/\./g, "/");
194195
config.prefix = "_" + libName.replace(/\./g, "_") + "_";
195196
}
196197

lib/plugin/css-variables-collector.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ CSSVariablesCollectorPlugin.prototype = {
2727
return this.ruleStack.length > 0 && !this.ruleStack[this.ruleStack.length - 1].variable;
2828
},
2929

30-
_isInGlobalOrBaseImport() {
31-
return this.config.libName !== "sap.ui.core" && this.importStack.filter((importNode) => {
32-
return /\/(?:global|base)\.less$/.test(importNode.importedFilename);
33-
}).length > 0;
30+
_isVarInLibrary() {
31+
// the last less file defines the location of the css variable and this must
32+
// be in the path of the current library, otherwise it is an external variable
33+
const regexp = new RegExp(`^/resources/${this.config.libPath}/themes/`);
34+
return this.importStack.length > 0 ? regexp.test(this.importStack[this.importStack.length - 1].importedFilename) : true;
3435
},
3536

3637
_isRelevant() {
@@ -109,7 +110,7 @@ CSSVariablesCollectorPlugin.prototype = {
109110
}
110111
this.calcVars[newName] = {
111112
css: css,
112-
export: !this._isInGlobalOrBaseImport()
113+
export: this._isVarInLibrary()
113114
};
114115
return new less.tree.Call("var", [new less.tree.Anonymous("--" + newName, node.index, node.currentFileInfo, node.mapLines)]);
115116
}
@@ -187,7 +188,7 @@ CSSVariablesCollectorPlugin.prototype = {
187188
// add the variable declaration to the list of vars
188189
this.vars[value.name.substr(1)] = {
189190
css: this._getCSS(value.value),
190-
export: !this._isInGlobalOrBaseImport()
191+
export: this._isVarInLibrary()
191192
};
192193
}
193194
});

0 commit comments

Comments
 (0)