@@ -26,15 +26,20 @@ export default class FileSystemLoader {
26
26
this . importNr = 0
27
27
this . core = new Core ( plugins )
28
28
this . tokensByFile = { } ;
29
+
30
+ Core . scope . generateScopedName = function ( exportedName , unsanitizedPath ) {
31
+ let sanitizedPath = path . relative ( root , unsanitizedPath ) . replace ( / \. [ ^ \. \/ \\ ] + $ / , '' ) . replace ( / [ \W _ ] + / g, '_' ) . replace ( / ^ _ | _ $ / g, '' ) ;
32
+ return `_${ sanitizedPath } __${ exportedName } ` ;
33
+ } ;
34
+
29
35
}
30
36
31
37
fetch ( _newPath , relativeTo , _trace ) {
32
38
let newPath = _newPath . replace ( / ^ [ " ' ] | [ " ' ] $ / g, "" ) ,
33
39
trace = _trace || String . fromCharCode ( this . importNr ++ )
34
40
return new Promise ( ( resolve , reject ) => {
35
41
let relativeDir = path . dirname ( relativeTo ) ,
36
- rootRelativePath = path . resolve ( relativeDir , newPath ) ,
37
- fileRelativePath = path . resolve ( path . join ( this . root , relativeDir ) , newPath )
42
+ fileRelativePath = path . resolve ( path . isAbsolute ( relativeDir ) ? relativeDir : path . join ( this . root , relativeDir ) , newPath )
38
43
39
44
// if the path is not relative or absolute, try to resolve it in node_modules
40
45
if ( newPath [ 0 ] !== '.' && newPath [ 0 ] !== '/' ) {
@@ -49,7 +54,7 @@ export default class FileSystemLoader {
49
54
50
55
fs . readFile ( fileRelativePath , "utf-8" , ( err , source ) => {
51
56
if ( err ) reject ( err )
52
- this . core . load ( source , rootRelativePath , trace , this . fetch . bind ( this ) )
57
+ this . core . load ( source , fileRelativePath , trace , this . fetch . bind ( this ) )
53
58
. then ( ( { injectableSource, exportTokens } ) => {
54
59
this . sources [ trace ] = injectableSource
55
60
this . tokensByFile [ fileRelativePath ] = exportTokens
0 commit comments