@@ -2,6 +2,7 @@ import fs from 'fs';
2
2
import path from 'path' ;
3
3
import postcss from 'postcss' ;
4
4
import getCustomProperties from './get-custom-properties' ;
5
+ import valueParser from 'postcss-values-parser' ;
5
6
6
7
/* Import Custom Properties from CSS AST
7
8
/* ========================================================================== */
@@ -14,8 +15,8 @@ function importCustomPropertiesFromCSSAST(root) {
14
15
/* ========================================================================== */
15
16
16
17
async function importCustomPropertiesFromCSSFile ( from ) {
17
- const css = await readFile ( path . resolve ( from ) ) ;
18
- const root = postcss . parse ( css , { from : path . resolve ( from ) } ) ;
18
+ const css = await readFile ( from ) ;
19
+ const root = postcss . parse ( css , { from } ) ;
19
20
20
21
return importCustomPropertiesFromCSSAST ( root ) ;
21
22
}
@@ -29,14 +30,18 @@ function importCustomPropertiesFromObject(object) {
29
30
Object ( object ) . customProperties || Object ( object ) [ 'custom-properties' ]
30
31
) ;
31
32
33
+ for ( const prop in customProperties ) {
34
+ customProperties [ prop ] = valueParser ( customProperties [ prop ] ) . parse ( ) ;
35
+ }
36
+
32
37
return customProperties ;
33
38
}
34
39
35
40
/* Import Custom Properties from JSON file
36
41
/* ========================================================================== */
37
42
38
43
async function importCustomPropertiesFromJSONFile ( from ) {
39
- const object = await readJSON ( path . resolve ( from ) ) ;
44
+ const object = await readJSON ( from ) ;
40
45
41
46
return importCustomPropertiesFromObject ( object ) ;
42
47
}
@@ -45,7 +50,7 @@ async function importCustomPropertiesFromJSONFile(from) {
45
50
/* ========================================================================== */
46
51
47
52
async function importCustomPropertiesFromJSFile ( from ) {
48
- const object = await import ( path . resolve ( from ) ) ;
53
+ const object = await import ( from ) ;
49
54
50
55
return importCustomPropertiesFromObject ( object ) ;
51
56
}
@@ -70,7 +75,7 @@ export default function importCustomPropertiesFromSources(sources) {
70
75
}
71
76
72
77
// source pathname
73
- const from = String ( opts . from || '' ) ;
78
+ const from = path . resolve ( String ( opts . from || '' ) ) ;
74
79
75
80
// type of file being read from
76
81
const type = ( opts . type || path . extname ( from ) . slice ( 1 ) ) . toLowerCase ( ) ;
0 commit comments