Skip to content

Commit 171dd6c

Browse files
committed
Upgrade postcss-easy-import to 2.0.0
Fixes #72
1 parent 5201f1a commit 171dd6c

File tree

5 files changed

+84
-783
lines changed

5 files changed

+84
-783
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### HEAD
22

33
* Refactor to support Node 4 upwards
4+
* Update `postcss-easy-import` to `2.0.0`
45
* Update `fs-extra` to `2.1.2`
56
* Update `autoprefixer` to `6.7.7`
67
* Update `postcss-apply` to `0.6.1`

lib/index.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const bemLinter = require('postcss-bem-linter');
66
const cssnano = require('cssnano');
77
const difference = require('lodash.difference');
88
const encapsulationPlugins = require('./encapsulation');
9+
const fs = require('fs');
910
const isEmpty = require('lodash.isempty');
11+
const pify = require('pify');
1012
const postcssEasyImport = require('postcss-easy-import');
1113
const reporter = require('postcss-reporter');
1214
const stylelint = require('stylelint');
@@ -37,7 +39,7 @@ const defaults = {
3739
ios > 6, android > 4.3, samsung > 3, chromeandroid > 50`
3840
},
3941
'postcss-easy-import': {
40-
transform: identity,
42+
load: getFileContent,
4143
onImport: noop
4244
},
4345
'postcss-reporter': {
@@ -111,16 +113,17 @@ function mergeOptions(options) {
111113
options = options || {};
112114
const mergedOpts = assign({}, defaults, options);
113115
const easyImportOpts = mergedOpts['postcss-easy-import'];
114-
const origTransform = easyImportOpts.transform;
116+
const origLoad = easyImportOpts.load;
115117
const origOnImport = easyImportOpts.onImport;
116118

117119
if (mergedOpts.root) {
118120
easyImportOpts.root = mergedOpts.root;
119121
}
120122

121-
easyImportOpts.transform = (css, filename) => {
122-
const transformedCss = origTransform(css);
123-
return lintFile(transformedCss, mergedOpts, filename).then(result => result.css);
123+
easyImportOpts.load = filename => {
124+
const transformedCss = origLoad(filename);
125+
return lintFile(transformedCss, mergedOpts, filename)
126+
.then(result => result.css);
124127
};
125128

126129
easyImportOpts.onImport = importedFiles => {
@@ -181,6 +184,10 @@ function isPromise(obj) {
181184

182185
function noop() {}
183186

187+
function getFileContent(filename) {
188+
return pify(fs.readFile)(filename, 'utf8');
189+
}
190+
184191
function identity(x) {
185192
return x;
186193
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lodash.isempty": "^4.1.1",
2222
"object-assign-deep": "0.0.4",
2323
"pad-component": "0.0.1",
24+
"pify": "^2.3.0",
2425
"postcss": "^5.2.17",
2526
"postcss-apply": "^0.6.1",
2627
"postcss-autoreset": "^1.2.0",
@@ -29,7 +30,7 @@
2930
"postcss-color-function": "^3.0.0",
3031
"postcss-custom-media": "^5.0.0",
3132
"postcss-custom-properties": "^5.0.0",
32-
"postcss-easy-import": "^1.0.1",
33+
"postcss-easy-import": "^2.0.0",
3334
"postcss-reporter": "^3.0.0",
3435
"read-file-stdin": "^0.2.1",
3536
"stylelint": "^7.10.1",

test/options.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ describe('using the `onImport` option in postcss-import', () => {
137137
});
138138
});
139139

140-
describe('using the `transform` option in postcss-import', () => {
141-
it('should use a default transform function that just returns the css', done => {
140+
describe('using the `load` option in postcss-import', () => {
141+
it('should use a default load function that just returns the css', done => {
142142
suitcss('@import "./util.css";', {
143143
root: 'test/fixtures',
144144
lint: false
@@ -149,30 +149,30 @@ describe('using the `transform` option in postcss-import', () => {
149149
.catch(done);
150150
});
151151

152-
it('should call a custom transform function with the imported component', done => {
153-
const transformStub = sinon.stub().returns('body { color: blue; }');
152+
it('should call a custom load function with the imported component', done => {
153+
const loadStub = sinon.stub().returns('body { color: blue; }');
154154

155155
suitcss('@import "./util.css";', {
156156
root: 'test/fixtures',
157157
lint: false,
158158
'postcss-easy-import': {
159-
transform: transformStub
159+
load: loadStub
160160
}
161161
}).then(result => {
162-
expect(transformStub.calledOnce).to.be.true;
163-
expect(transformStub.getCall(0).args[0]).to.equal('.u-img {\n border-radius: 50%;\n}\n');
162+
expect(loadStub.calledOnce).to.be.true;
163+
expect(loadStub.getCall(0).args[0]).to.equal('/Users/simonsmith/Sites/suitcss/preprocessor/test/fixtures/util.css');
164164
expect(result.css).to.equal('body { color: blue; }');
165165
done();
166166
})
167167
.catch(done);
168168
});
169169

170-
it('should also work with a promise returned from the custom transform function', done => {
170+
it('should also work with a promise returned from the custom load function', done => {
171171
suitcss('@import "./util.css";', {
172172
root: 'test/fixtures',
173173
lint: false,
174174
'postcss-easy-import': {
175-
transform() {
175+
load() {
176176
return Promise.resolve('body { font: red; }');
177177
}
178178
}

0 commit comments

Comments
 (0)