-
Notifications
You must be signed in to change notification settings - Fork 34
falling demo #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
falling demo #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,16 +51,16 @@ export default class Parser { | |
exportNode.removeSelf() | ||
} | ||
|
||
fetchImport( importNode, relativeTo, depNr ) { | ||
fetchImport( importNode, sourcePath, depNr ) { | ||
let file = importNode.selector.match( importRegexp )[1], | ||
depTrace = this.trace + String.fromCharCode(depNr) | ||
return this.pathFetcher( file, relativeTo, depTrace ).then( exports => { | ||
return this.pathFetcher( file, sourcePath, depTrace ).then( exports => { | ||
importNode.each( decl => { | ||
if ( decl.type == 'decl' ) { | ||
this.translations[decl.prop] = exports[decl.value] | ||
} | ||
} ) | ||
importNode.removeSelf() | ||
}, err => console.log( err ) ) | ||
} ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are handling error at the |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ import fs from "fs" | |
import path from "path" | ||
import FileSystemLoader from "../src/file-system-loader" | ||
|
||
import PostcssLocal from "postcss-modules-local-by-default" | ||
import PostcssExtract from "postcss-modules-extract-imports" | ||
import PostcssScope from "postcss-modules-scope" | ||
|
||
let normalize = ( str ) => { | ||
return str.replace( /\r\n?/g, "\n" ); | ||
} | ||
|
@@ -14,16 +18,24 @@ const pipelines = { | |
"cssi": [] | ||
} | ||
|
||
const getPlugins = rootDir => { | ||
return [ | ||
PostcssLocal, | ||
PostcssExtract, | ||
new PostcssScope({rootDir: rootDir}) | ||
]; | ||
} | ||
|
||
Object.keys( pipelines ).forEach( dirname => { | ||
describe( dirname, () => { | ||
let testDir = path.join( __dirname, dirname ) | ||
fs.readdirSync( testDir ).forEach( testCase => { | ||
if ( fs.existsSync( path.join( testDir, testCase, "source.css" ) ) ) { | ||
it( "should " + testCase.replace( /-/g, " " ), done => { | ||
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, "expected.css" ), "utf-8" ) ) | ||
let loader = new FileSystemLoader( testDir, pipelines[dirname] ) | ||
let loader = new FileSystemLoader( testDir, pipelines[dirname] || getPlugins(testDir) ) | ||
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, "expected.json" ), "utf-8" ) ) | ||
loader.fetch( `${testCase}/source.css`, "/" ).then( tokens => { | ||
loader.fetch( path.join( testDir, testCase, "source.css" ) ).then( tokens => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. building absolute paths |
||
assert.equal( loader.finalSource, expected ) | ||
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) ) | ||
} ).then( done, done ) | ||
|
@@ -41,10 +53,10 @@ describe( 'multiple sources', () => { | |
if ( fs.existsSync( path.join( testDir, testCase, "source1.css" ) ) ) { | ||
it( "should " + testCase.replace( /-/g, " " ), done => { | ||
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, "expected.css" ), "utf-8" ) ) | ||
let loader = new FileSystemLoader( testDir, pipelines[dirname] ) | ||
let loader = new FileSystemLoader( testDir, pipelines[dirname] || getPlugins(testDir) ) | ||
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, "expected.json" ), "utf-8" ) ) | ||
loader.fetch( `${testCase}/source1.css`, "/" ).then( tokens1 => { | ||
loader.fetch( `${testCase}/source2.css`, "/" ).then( tokens2 => { | ||
loader.fetch( path.join( testDir, testCase, "source1.css" ) ).then( tokens1 => { | ||
loader.fetch( path.join( testDir, testCase, "source2.css" ) ).then( tokens2 => { | ||
assert.equal( loader.finalSource, expected ) | ||
const tokens = Object.assign({}, tokens1, tokens2); | ||
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) ) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"foo": "_compose_node_module_source__foo _compose_node_module_cool_styles_foo__example" | ||
"foo": "_compose_node_module_source__foo _node_modules_cool_styles_foo__example _node_modules_cool_styles_bar__example" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should put the proper version of the scope plugin, when it will be updated.
css-modules/postcss-modules-scope#15