Skip to content

Commit dba4955

Browse files
committed
got the first test actually running (and failing)!
1 parent a41ee4a commit dba4955

File tree

9 files changed

+131
-21
lines changed

9 files changed

+131
-21
lines changed

.eslintrc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"parser": "babel-eslint",
3+
"env": {
4+
"node": true
5+
},
6+
"ecmaFeatures": {
7+
"arrowFunctions": true,
8+
"blockBindings": true,
9+
"classes": true,
10+
"defaultParams": true,
11+
"destructuring": true,
12+
"forOf": true,
13+
"modules": true,
14+
"objectLiteralComputedProperties": true,
15+
"objectLiteralShorthandMethods": true,
16+
"objectLiteralShorthandProperties": true,
17+
"spread": true,
18+
"superInFunctions": true,
19+
"templateStrings": true,
20+
"unicodeCodePointEscapes": true,
21+
"jsx": true
22+
},
23+
"rules": {
24+
"quotes": "single"
25+
}
26+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

file-system-loader.js

-11
This file was deleted.

package.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "css-modules-loader-core",
3+
"version": "0.0.1",
4+
"description": "A loader-agnostic CSS Modules implementation, based on PostCSS",
5+
"main": "lib/index.js",
6+
"directories": {
7+
"test": "test"
8+
},
9+
"dependencies": {
10+
"postcss": "^4.1.11",
11+
"postcss-modules-extract-imports": "0.0.1",
12+
"postcss-modules-local-by-default": "0.0.6",
13+
"postcss-modules-scope": "0.0.1"
14+
},
15+
"devDependencies": {
16+
"babel": "^5.4.7",
17+
"babel-eslint": "^3.1.9",
18+
"babelify": "^6.1.2",
19+
"chokidar-cli": "^0.2.1",
20+
"eslint": "^0.21.2",
21+
"mocha": "^2.2.5",
22+
"postcss": "^4.1.11"
23+
},
24+
"scripts": {
25+
"lint": "eslint src",
26+
"build": "babel --out-dir lib src",
27+
"autotest": "chokidar src test -c 'npm test'",
28+
"test": "mocha --compilers js:babel/register"
29+
},
30+
"repository": {
31+
"type": "git",
32+
"url": "https://github.com/css-modules/css-modules-loader-core.git"
33+
},
34+
"keywords": [
35+
"css-modules",
36+
"postcss",
37+
"loader"
38+
],
39+
"author": "Glen Maddern",
40+
"license": "ISC",
41+
"bugs": {
42+
"url": "https://github.com/css-modules/css-modules-loader-core/issues"
43+
},
44+
"homepage": "https://github.com/css-modules/css-modules-loader-core"
45+
}

src/file-system-loader.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Core from './index.js'
2+
import fs from 'fs'
3+
4+
export default class FileSystemLoader {
5+
constructor() {
6+
this.sources = []
7+
this.seenPaths = new Set()
8+
}
9+
10+
fetch( path ) {
11+
return new Promise( ( resolve, reject ) => {
12+
return fs.readFile( path, ( err, source ) => {
13+
if (err) reject(err)
14+
return Core.load( source, this.fetch.bind(this) ).then( stuff => {
15+
let { injectableSource, exportTokens } = stuff
16+
this.sources.push( injectableSource )
17+
return exportTokens
18+
} )
19+
} )
20+
} )
21+
}
22+
}

src/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import scope from 'postcss-modules-scope'
55

66
import parser from './parser'
77

8-
export default Core = {
8+
export default {
99
// These three plugins are aliased under this package for simplicity.
1010
localByDefault,
1111
extractImports,
@@ -19,14 +19,16 @@ export default Core = {
1919
],
2020

2121
load( sourceString, pathFetcher ) {
22-
let parser = new Parser( pathFetcher )
22+
//let parser = new Parser( pathFetcher )
23+
//
24+
//return postcss( this.plugins.concat( [parser] ) )
25+
// .process( sourceString )
26+
// .then( result => {
27+
//
28+
// } )
2329

24-
return postcss( this.plugins.concat( [parser] ) )
25-
.process( sourceString )
26-
.then( result => {
2730

28-
} )
29-
30-
return
31+
return { injectableSource: "", exportTokens: {} }
3132
}
3233
}
34+

src/parser.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default parse
1+
export default (css, result) => {
2+
3+
}

test/test-cases.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
var assert = require("assert");
4+
var fs = require("fs");
5+
var path = require("path");
6+
var FileSystemLoader = require('../src/file-system-loader')
7+
8+
function normalize(str) {
9+
return str.replace(/\r\n?/g, "\n");
10+
}
11+
12+
describe("test-cases", function() {
13+
var testDir = path.join(__dirname, "test-cases");
14+
fs.readdirSync(testDir).forEach(function(testCase) {
15+
if(fs.existsSync(path.join(testDir, testCase, "source.css"))) {
16+
it("should " + testCase.replace(/-/g, " "), function() {
17+
var expected = normalize(fs.readFileSync(path.join(testDir, testCase, "expected.css"), "utf-8"));
18+
var output = FileSystemLoader('')
19+
assert.equal(pipeline.process(input).css, expected);
20+
});
21+
}
22+
});
23+
});
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export default {
1+
module.exports = {
22
localName: '__globalName'
33
}

0 commit comments

Comments
 (0)