Skip to content

Commit 126464c

Browse files
committed
got the file path lookup logic actually working
1 parent d937730 commit 126464c

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/file-system-loader.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ export default class FileSystemLoader {
99
this.seenPaths = new Set()
1010
}
1111

12-
fetch( newPath, relativeTo ) {
12+
fetch( _newPath, relativeTo ) {
13+
let newPath = _newPath.replace( /^["']|["']$/g, "" )
1314
return new Promise( ( resolve, reject ) => {
14-
let fileRelativePath = path.resolve( path.resolve( this.root, relativeTo), newPath ),
15-
rootRelativePath = path.relative( this.root, fileRelativePath )
16-
console.log(fileRelativePath)
17-
console.log(rootRelativePath)
15+
let rootRelativePath = path.resolve( path.dirname( relativeTo ), newPath ),
16+
fileRelativePath = this.root + rootRelativePath
17+
console.log( newPath )
18+
console.log( relativeTo )
19+
console.log( rootRelativePath )
20+
console.log( fileRelativePath )
1821

1922
fs.readFile( fileRelativePath, "utf-8", ( err, source ) => {
2023
if ( err ) reject( err )

src/parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class Parser {
2020
let imports = []
2121
css.each( node => {
2222
if ( node.type == "rule" && node.selector.match( importRegexp ) ) {
23-
imports.push( this.fetchImport( node ) )
23+
imports.push( this.fetchImport( node, css.source.input.from ) )
2424
}
2525
} )
2626
return imports
@@ -35,10 +35,10 @@ export default class Parser {
3535
exportNode.removeSelf()
3636
}
3737

38-
fetchImport( importNode ) {
38+
fetchImport( importNode, relativeTo ) {
3939
let file = importNode.selector.match( importRegexp )[1]
40-
console.log(file)
41-
return this.pathFetcher(file).then(exports => {
40+
console.log(file, relativeTo)
41+
return this.pathFetcher(file, relativeTo).then(exports => {
4242
console.log(exports)
4343
})
4444
}

test/test-cases.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe( "test-cases", () => {
1717
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, "expected.css" ), "utf-8" ) )
1818
let loader = new FileSystemLoader( testDir )
1919
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, "expected.json" ), "utf-8" ) )
20-
loader.fetch( `${testCase}/source.css`, "./" ).then( tokens => {
20+
loader.fetch( `${testCase}/source.css`, "/" ).then( tokens => {
2121
assert.equal( loader.sources.join( "" ), expected )
2222
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) )
2323
} ).then( done, done )

0 commit comments

Comments
 (0)