Skip to content

Commit 37255cb

Browse files
postcss 7 (#6)
* Update dev deps * Update postcss to v6 * add imported files to `result.files` * Add CI * Update standard. * ci: add node 10 * rip node 4 * do filter instead of default, like in main branch
1 parent f7a3e21 commit 37255cb

File tree

5 files changed

+55
-21
lines changed

5 files changed

+55
-21
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- "stable"
4+
- "10"
5+
- "8"
6+
- "6"

index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function transform (filename, source, options, done) {
1414
const plugins = defined(options.plugins, [])
1515
.map(plugin => {
1616
if (typeof plugin === 'string') {
17-
plugin = [ plugin ]
17+
plugin = [plugin]
1818
}
1919

2020
return {
@@ -36,13 +36,27 @@ function transform (filename, source, options, done) {
3636
delete ctx.plugins
3737

3838
postcssrc(ctx, basedir).then(compile, function () {
39-
return compile({options: ctx})
39+
return compile({ options: ctx })
4040
}).then(function (result) {
41-
done(null, result.css)
41+
done(null, result)
4242
}, done)
4343

4444
function compile (config) {
4545
return postcss(plugins.concat(config.plugins).filter(Boolean))
4646
.process(source, config.options)
47+
.then(function (result) {
48+
// Collect imported files for watchify
49+
const files = [filename]
50+
result.messages.forEach(function (msg) {
51+
if (msg.type === 'dependency') {
52+
files.push(msg.file)
53+
}
54+
})
55+
56+
return {
57+
css: result.css,
58+
files: files
59+
}
60+
})
4761
}
4862
}

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@
2222
},
2323
"homepage": "https://github.com/stackcss/sheetify-postcss#readme",
2424
"devDependencies": {
25-
"browserify": "^13.1.0",
26-
"dependency-check": "^2.6.0",
27-
"npm-run-all": "^3.0.0",
28-
"postcss-color-function": "^2.0.1",
25+
"browserify": "^16.0.0",
26+
"dependency-check": "^3.4.1",
27+
"npm-run-all": "^4.1.5",
28+
"postcss-color-function": "^4.0.1",
29+
"postcss-import": "^12.0.1",
2930
"pull-test": "^1.2.3",
30-
"sheetify": "^5.1.0",
31-
"standard": "^8.0.0",
32-
"tape": "^4.5.1"
31+
"sheetify": "^7.2.0",
32+
"standard": "^13.0.2",
33+
"tape": "^4.11.0"
3334
},
3435
"dependencies": {
3536
"defined": "^1.0.0",
36-
"postcss": "^5.1.2",
37-
"postcss-load-config": "^1.2.0",
38-
"resolve": "^1.1.7",
39-
"xtend": "^4.0.1"
37+
"postcss": "^7.0.17",
38+
"postcss-load-config": "^2.1.0",
39+
"resolve": "^1.11.1",
40+
"xtend": "^4.0.2"
4041
}
4142
}

test/index.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,40 @@ test(function (t) {
66
t.test('module should work with postcss plugins without options', function (t) {
77
t.plan(2)
88

9-
sheetifyPostcss('test.css', '.rule {}', { basedir: __dirname, plugins: [ './stubs/postcss-plugin' ] }, (err, css) => {
9+
sheetifyPostcss('test.css', '.rule {}', { basedir: __dirname, plugins: ['./stubs/postcss-plugin'] }, (err, result) => {
1010
t.equal(err, null)
11-
t.equal(css, '.ok {}')
11+
t.equal(result.css, '.ok {}')
1212
})
1313
})
1414

1515
t.test('module should work with postcss plugins and their options', function (t) {
1616
t.plan(2)
1717

18-
sheetifyPostcss('test.css', '.rule {}', { basedir: __dirname, plugins: [ [ './stubs/postcss-plugin', { has: true } ] ] }, (err, css) => {
18+
sheetifyPostcss('test.css', '.rule {}', { basedir: __dirname, plugins: [['./stubs/postcss-plugin', { has: true }]] }, (err, result) => {
1919
t.equal(err, null)
20-
t.equal(css, '.ok-with-options {}')
20+
t.equal(result.css, '.ok-with-options {}')
2121
})
2222
})
2323

2424
t.test('module should respect postcssrc config file', function (t) {
2525
t.plan(2)
2626

27-
sheetifyPostcss('test.css', '.rule {}', { basedir: path.join(__dirname, 'stubs') }, (err, css) => {
27+
sheetifyPostcss('test.css', '.rule {}', { basedir: path.join(__dirname, 'stubs') }, (err, result) => {
2828
t.equal(err, null)
29-
t.equal(css, '.ok-with-postcssrc {}')
29+
t.equal(result.css, '.ok-with-postcssrc {}')
3030
})
3131
})
32-
})
3332

33+
t.test('should report imported files if postcss-import is used', function (t) {
34+
t.plan(3)
35+
36+
sheetifyPostcss(path.join(__dirname, 'test.css'), '@import "./stubs/dep.css"', { basedir: __dirname, plugins: ['postcss-import'] }, (err, result) => {
37+
t.equal(err, null)
38+
t.equal(result.css, '.dependency {}')
39+
t.deepEqual(result.files, [
40+
path.join(__dirname, 'test.css'),
41+
path.join(__dirname, 'stubs/dep.css')
42+
])
43+
})
44+
})
45+
})

test/stubs/dep.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.dependency {}

0 commit comments

Comments
 (0)