@@ -14,6 +14,20 @@ const CSSVariablesCollectorPlugin = module.exports = function(config) {
1414 this . importStack = [ ] ;
1515} ;
1616
17+ CSSVariablesCollectorPlugin . getResolvedUrl = function ( { rawUrl, filename} ) {
18+ if ( filename . startsWith ( "/resources/" ) ) {
19+ if ( rawUrl . startsWith ( "/" ) ) {
20+ return rawUrl ;
21+ }
22+ const baseUrl = "ui5://" + filename . substr ( "/resources/" . length ) ;
23+ const url = new URL ( rawUrl , baseUrl ) ;
24+ return url . href ;
25+ } else {
26+ // TODO: Check whether and when this can happen (except within test cases)
27+ return null ;
28+ }
29+ } ,
30+
1731CSSVariablesCollectorPlugin . prototype = {
1832
1933 isPreEvalVisitor : true ,
@@ -37,18 +51,6 @@ CSSVariablesCollectorPlugin.prototype = {
3751 return ! this . _isInMixinOrParen ( ) && this . _isVarInRule ( ) ;
3852 } ,
3953
40- _getResolvedUrl ( rawUrl ) {
41- const parsedUrl = require ( "url" ) . parse ( rawUrl ) ;
42- if ( parsedUrl . protocol || rawUrl . startsWith ( "/" ) ) {
43- return rawUrl ;
44- }
45- let relativePath = parsedUrl . path ;
46- if ( relativePath . startsWith ( "./" ) ) {
47- relativePath = relativePath . substr ( 2 ) ;
48- }
49- return `ui5://TODO-namespace/themes/TODO-themeName/${ relativePath } ` ;
50- } ,
51-
5254 toLessVariables ( ) {
5355 let lessVariables = "" ;
5456 Object . keys ( this . vars ) . forEach ( ( value , index ) => {
@@ -214,12 +216,18 @@ CSSVariablesCollectorPlugin.prototype = {
214216 // Create additional _asResolvedUrl variable for runtime resolution of relative urls
215217 const urlMatch = / u r l [ \s ] * \( ' ? " ? ( [ ^ ' " ) ] * ) ' ? " ? \) / . exec ( variableEntry . css ) ;
216218 if ( urlMatch ) {
217- const resolvedUrlVariableName = `${ variableName } __asResolvedUrl` ;
218- const resolvedUrlVariableEntry = {
219- css : `"${ this . _getResolvedUrl ( urlMatch [ 1 ] ) } "` ,
220- export : true
221- } ;
222- this . vars [ resolvedUrlVariableName ] = resolvedUrlVariableEntry ;
219+ const resolvedUrl = CSSVariablesCollectorPlugin . getResolvedUrl ( {
220+ rawUrl : urlMatch [ 1 ] ,
221+ filename : value . currentFileInfo . filename
222+ } ) ;
223+ if ( resolvedUrl ) {
224+ const resolvedUrlVariableName = `${ variableName } __asResolvedUrl` ;
225+ const resolvedUrlVariableEntry = {
226+ css : `"${ resolvedUrl } "` ,
227+ export : true
228+ } ;
229+ this . vars [ resolvedUrlVariableName ] = resolvedUrlVariableEntry ;
230+ }
223231 }
224232 }
225233 }
0 commit comments