@@ -14,6 +14,20 @@ const CSSVariablesCollectorPlugin = module.exports = function(config) {
14
14
this . importStack = [ ] ;
15
15
} ;
16
16
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
+
17
31
CSSVariablesCollectorPlugin . prototype = {
18
32
19
33
isPreEvalVisitor : true ,
@@ -37,18 +51,6 @@ CSSVariablesCollectorPlugin.prototype = {
37
51
return ! this . _isInMixinOrParen ( ) && this . _isVarInRule ( ) ;
38
52
} ,
39
53
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
-
52
54
toLessVariables ( ) {
53
55
let lessVariables = "" ;
54
56
Object . keys ( this . vars ) . forEach ( ( value , index ) => {
@@ -214,12 +216,18 @@ CSSVariablesCollectorPlugin.prototype = {
214
216
// Create additional _asResolvedUrl variable for runtime resolution of relative urls
215
217
const urlMatch = / u r l [ \s ] * \( ' ? " ? ( [ ^ ' " ) ] * ) ' ? " ? \) / . exec ( variableEntry . css ) ;
216
218
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
+ }
223
231
}
224
232
}
225
233
}
0 commit comments