Skip to content

Modules #30

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

Merged
merged 2 commits into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions node_modules/awesome-theme/common.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ export default function setup(opts = {}) {
}

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

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

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

Expand All @@ -102,4 +102,4 @@ function fetch(_newPath, _sourcePath, _trace) {
return tokens;
}

hook(filename => fetch(filename, sep + relative(rootDir, filename)));
hook(filename => fetch(filename, filename));
2 changes: 1 addition & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default plugin('parser', function parser(opts = {}) {
const fetchImport = (importNode, relativeTo, depNr) => {
const file = importNode.selector.match(importRegexp)[1];
const depTrace = opts.trace + String.fromCharCode(depNr);
const exports = opts.fetch(file, relativeTo, depTrace);
const exports = opts.fetch(file, opts.filename, depTrace);

importNode.each(decl => {
if (decl.type === 'decl') {
Expand Down
2 changes: 1 addition & 1 deletion test/test-cases/compose-node-module/expected.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"foo": "_compose_node_module_source__foo _node_modules_awesome_theme_oceanic__color"
"foo": "_compose_node_module_source__foo _node_modules_awesome_theme_common__paragraph _node_modules_awesome_theme_oceanic__color"
}
2 changes: 1 addition & 1 deletion test/test-cases/compose-node-module/source.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.foo {
composes: color from "awesome-theme/oceanic.css";
composes: paragraph from "awesome-theme/common.css";
}