Skip to content

Commit b8f976d

Browse files
author
Nathan Reid
committed
Fixed Windows issues: broken class naming (_absolute_path_to_file instead of _relative_path_to_file) and broken path resolution ("composes" didn't work)
1 parent 7a334e7 commit b8f976d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/file-system-loader.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ export default class FileSystemLoader {
2626
this.importNr = 0
2727
this.core = new Core(plugins)
2828
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+
2935
}
3036

3137
fetch( _newPath, relativeTo, _trace ) {
3238
let newPath = _newPath.replace( /^["']|["']$/g, "" ),
3339
trace = _trace || String.fromCharCode( this.importNr++ )
3440
return new Promise( ( resolve, reject ) => {
3541
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 )
3843

3944
// if the path is not relative or absolute, try to resolve it in node_modules
4045
if (newPath[0] !== '.' && newPath[0] !== '/') {
@@ -49,7 +54,7 @@ export default class FileSystemLoader {
4954

5055
fs.readFile( fileRelativePath, "utf-8", ( err, source ) => {
5156
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 ) )
5358
.then( ( { injectableSource, exportTokens } ) => {
5459
this.sources[trace] = injectableSource
5560
this.tokensByFile[fileRelativePath] = exportTokens

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class Core {
1515
let parser = new Parser( pathFetcher, trace )
1616

1717
return postcss( this.plugins.concat( [parser.plugin] ) )
18-
.process( sourceString, { from: "/" + sourcePath } )
18+
.process( sourceString, { from: sourcePath } )
1919
.then( result => {
2020
return { injectableSource: result.css, exportTokens: parser.exportTokens }
2121
} )

0 commit comments

Comments
 (0)