Skip to content

Commit afa9310

Browse files
committed
Merge pull request #30 from css-modules/modules
Modules
2 parents 8be0209 + f1f279a commit afa9310

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

node_modules/awesome-theme/common.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ export default function setup(opts = {}) {
6666
}
6767

6868
/**
69-
* @param {string} _newPath Absolute or relative path. Also can be path to the Node.JS module.
70-
* @param {string} _sourcePath Absolute path (relative to root).
69+
* @param {string} _to Absolute or relative path. Also can be path to the Node.JS module.
70+
* @param {string} _from Absolute path (relative to root).
7171
* @param {string} _trace
7272
* @return {object}
7373
*/
74-
function fetch(_newPath, _sourcePath, _trace) {
74+
function fetch(_to, _from, _trace) {
7575
const trace = _trace || String.fromCharCode(importNr++);
76-
const newPath = removeQuotes(_newPath);
76+
const newPath = removeQuotes(_to);
7777
// getting absolute path to the processing file
7878
const filename = /\w/.test(newPath[0])
7979
? require.resolve(newPath)
80-
: resolve(rootDir + dirname(_sourcePath), newPath);
80+
: resolve(dirname(_from), newPath);
8181

8282
// checking cache
8383
let tokens = tokensByFile[filename];
@@ -88,7 +88,7 @@ function fetch(_newPath, _sourcePath, _trace) {
8888
const rootRelativePath = sep + relative(rootDir, filename);
8989
const CSSSource = preProcess(readFileSync(filename, 'utf8'));
9090

91-
const result = postcss(plugins.concat(new Parser({ fetch, trace })))
91+
const result = postcss(plugins.concat(new Parser({ fetch, filename, trace })))
9292
.process(CSSSource, assign(lazyResultOpts, {from: rootRelativePath}))
9393
.root;
9494

@@ -102,4 +102,4 @@ function fetch(_newPath, _sourcePath, _trace) {
102102
return tokens;
103103
}
104104

105-
hook(filename => fetch(filename, sep + relative(rootDir, filename)));
105+
hook(filename => fetch(filename, filename));

src/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default plugin('parser', function parser(opts = {}) {
99
const fetchImport = (importNode, relativeTo, depNr) => {
1010
const file = importNode.selector.match(importRegexp)[1];
1111
const depTrace = opts.trace + String.fromCharCode(depNr);
12-
const exports = opts.fetch(file, relativeTo, depTrace);
12+
const exports = opts.fetch(file, opts.filename, depTrace);
1313

1414
importNode.each(decl => {
1515
if (decl.type === 'decl') {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"foo": "_compose_node_module_source__foo _node_modules_awesome_theme_oceanic__color"
2+
"foo": "_compose_node_module_source__foo _node_modules_awesome_theme_common__paragraph _node_modules_awesome_theme_oceanic__color"
33
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.foo {
2-
composes: color from "awesome-theme/oceanic.css";
2+
composes: paragraph from "awesome-theme/common.css";
33
}

0 commit comments

Comments
 (0)