Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
support for sass specific import syntax (#1335)
* support for sass specific import syntax

* use test

* fix

* Test new and old behaviour
  • Loading branch information
Jasper De Moor committed May 22, 2018
1 parent 83907d8 commit 099a98e
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/assets/SASSAsset.js
Expand Up @@ -43,6 +43,11 @@ class SASSAsset extends Asset {
opts.importer.push((url, prev, done) => {
let resolved;
try {
if (!/^(~|\.\/|\/)/.test(url)) {
url = './' + url;
} else if (!/^(~\/|\.\/|\/)/.test(url)) {
url = url.substring(1);
}
resolved = syncPromise(
resolver.resolve(url, prev === 'stdin' ? this.name : prev)
).path;
Expand Down
2 changes: 2 additions & 0 deletions test/integration/sass-advanced-import/bar.sass
@@ -0,0 +1,2 @@
.bar
color: green;
2 changes: 2 additions & 0 deletions test/integration/sass-advanced-import/foo.sass
@@ -0,0 +1,2 @@
.foo
color: blue;
2 changes: 0 additions & 2 deletions test/integration/sass-advanced-import/hello.sass

This file was deleted.

5 changes: 3 additions & 2 deletions test/integration/sass-advanced-import/index.sass
@@ -1,5 +1,6 @@
@import '~/hello.sass';
@import '~/foo';
@import '~/bar.sass';

.index
background: #ffffff;
color: #000000;
color: #000000;
5 changes: 5 additions & 0 deletions test/integration/scss-import/bar.scss
@@ -0,0 +1,5 @@
$bar: #f8a93b;

.bar {
color: $bar;
}
5 changes: 0 additions & 5 deletions test/integration/scss-import/base.scss

This file was deleted.

5 changes: 5 additions & 0 deletions test/integration/scss-import/foo.scss
@@ -0,0 +1,5 @@
$foo: #f938ab;

.foo {
color: $foo;
}
6 changes: 4 additions & 2 deletions test/integration/scss-import/index.scss
@@ -1,5 +1,7 @@
@import './base.scss';
@import 'foo';
@import './bar.scss';

.index {
color: $base;
color: $foo;
background-color: $bar;
}
10 changes: 7 additions & 3 deletions test/sass.js
Expand Up @@ -79,7 +79,8 @@ describe('sass', function() {

let css = fs.readFileSync(__dirname + '/dist/index.css', 'utf8');
assert(css.includes('.index'));
assert(css.includes('.base'));
assert(css.includes('.foo'));
assert(css.includes('.bar'));
});

it('should support requiring empty scss files', async function() {
Expand Down Expand Up @@ -183,7 +184,10 @@ describe('sass', function() {
assets: ['index.sass']
});

let css = fs.readFileSync(__dirname + '/dist/index.css', 'utf8');
assert(css.includes('color: blue;'));
let css = fs
.readFileSync(__dirname + '/dist/index.css', 'utf8')
.replace(/\s+/g, ' ');
assert(css.includes('.foo { color: blue;'));
assert(css.includes('.bar { color: green;'));
});
});

0 comments on commit 099a98e

Please sign in to comment.