Skip to content

Commit c6f2a00

Browse files
committed
Add a pass-thru implementation of the node-sass importer.
Still failing tests, but @import path resolution etc works.
1 parent 24a83e6 commit c6f2a00

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

node-sass.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
4+
// @see https://www.npmjs.com/package/node-sass#importer-v2-0-0-experimental
5+
// @see https://github.com/sass/node-sass/issues/671 (random console.log(), which is why can't really use --stdout)
6+
module.exports = function(url, prev, done) {
7+
var expectedExtension = path.extname(url) === '' ? path.extname(prev) : ''; // if the import had an extension (e.g. ".scss"), use that; if not, use the extension of the importing file
8+
var next = path.join(path.dirname(prev), url + expectedExtension); // construct import path relative to current file // TODO: Solve https://github.com/sass/node-sass/issues/762
9+
fs.readFile(next, function(err, data) {
10+
if (err) done(err);
11+
else done({ contents: data + '' });
12+
});
13+
};

test/cases/node-sass/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/entrypoint.css

test/cases/node-sass/entrypoint.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'components/MyComponent.scss'; // imports with explicit file extension should work as well

test/cases/node-sass/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"scripts": {
3-
"test": "node-sass --stdout --output-style=expanded MyComponent.scss"
3+
"test": "node-sass --importer=$(pwd)/node_modules/component-css-ns/node-sass.js entrypoint.scss > /dev/null 2>&1 && cat entrypoint.css"
44
}
55
}

0 commit comments

Comments
 (0)