Skip to content

Commit 128aaec

Browse files
committed
Add support for an opt-in trigger comment for the node-sass transform.
1 parent 472f9cb commit 128aaec

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

node-sass.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var fs = require('fs');
22
var path = require('path');
33
var postcss = require('postcss');
44

5+
var OPT_IN_TRIGGER = '/* @component-css-ns */';
56
var CLASSNAME_SEARCH = /\.([a-z][a-zA-Z_-]*)/g;
67

78
var transform = postcss.plugin('component-css-ns', function(opts) {
@@ -23,10 +24,15 @@ module.exports = function(url, prev, done) {
2324
if (err) { // for whatever reason, couldn't read the source file (might exist on the --include-path for example)
2425
done({ file: url }); // we wouldn't want to touch it anyway -> let SASS figure it out
2526
} else {
26-
try {
27-
done({ contents: postcss([ transform({ filename: next }) ]).process(data).css });
28-
} catch (e) {
29-
done(e); // PostCSS transform failed
27+
data = data + '';
28+
if (data.indexOf(OPT_IN_TRIGGER) === -1) {
29+
done({ file: url }); // let's not touch this file
30+
} else {
31+
try {
32+
done({ contents: postcss([ transform({ filename: next }) ]).process(data).css });
33+
} catch (e) {
34+
done(e); // PostCSS transform failed
35+
}
3036
}
3137
}
3238
});

test/cases/node-sass/components/MyComponent.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* @component-css-ns */
2+
13
.foo {
24
.bar-x {
35
.baz_y {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* @component-css-ns */
2+
13
.something {
24
color: blue;
35
}

test/cases/node-sass/expected.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
.pretend-sass-lib {
22
content: ''; }
33

4+
/* @component-css-ns */
45
.MyComponent-foo .MyComponent-bar-x .MyComponent-baz_y {
56
color: red; }
67

78
.MyComponent-lib-herp {
89
color: green; }
910

11+
/* @component-css-ns */
1012
.SubComponent-something {
1113
color: blue; }
1214

0 commit comments

Comments
 (0)