Skip to content

Commit

Permalink
postcss 7 (#6)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
goto-bus-stop authored Jul 16, 2019
1 parent f7a3e21 commit 37255cb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- "stable"
- "10"
- "8"
- "6"
20 changes: 17 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function transform (filename, source, options, done) {
const plugins = defined(options.plugins, [])
.map(plugin => {
if (typeof plugin === 'string') {
plugin = [ plugin ]
plugin = [plugin]
}

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

postcssrc(ctx, basedir).then(compile, function () {
return compile({options: ctx})
return compile({ options: ctx })
}).then(function (result) {
done(null, result.css)
done(null, result)
}, done)

function compile (config) {
return postcss(plugins.concat(config.plugins).filter(Boolean))
.process(source, config.options)
.then(function (result) {
// Collect imported files for watchify
const files = [filename]
result.messages.forEach(function (msg) {
if (msg.type === 'dependency') {
files.push(msg.file)
}
})

return {
css: result.css,
files: files
}
})
}
}
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
},
"homepage": "https://github.com/stackcss/sheetify-postcss#readme",
"devDependencies": {
"browserify": "^13.1.0",
"dependency-check": "^2.6.0",
"npm-run-all": "^3.0.0",
"postcss-color-function": "^2.0.1",
"browserify": "^16.0.0",
"dependency-check": "^3.4.1",
"npm-run-all": "^4.1.5",
"postcss-color-function": "^4.0.1",
"postcss-import": "^12.0.1",
"pull-test": "^1.2.3",
"sheetify": "^5.1.0",
"standard": "^8.0.0",
"tape": "^4.5.1"
"sheetify": "^7.2.0",
"standard": "^13.0.2",
"tape": "^4.11.0"
},
"dependencies": {
"defined": "^1.0.0",
"postcss": "^5.1.2",
"postcss-load-config": "^1.2.0",
"resolve": "^1.1.7",
"xtend": "^4.0.1"
"postcss": "^7.0.17",
"postcss-load-config": "^2.1.0",
"resolve": "^1.11.1",
"xtend": "^4.0.2"
}
}
26 changes: 19 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,40 @@ test(function (t) {
t.test('module should work with postcss plugins without options', function (t) {
t.plan(2)

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

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

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

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

sheetifyPostcss('test.css', '.rule {}', { basedir: path.join(__dirname, 'stubs') }, (err, css) => {
sheetifyPostcss('test.css', '.rule {}', { basedir: path.join(__dirname, 'stubs') }, (err, result) => {
t.equal(err, null)
t.equal(css, '.ok-with-postcssrc {}')
t.equal(result.css, '.ok-with-postcssrc {}')
})
})
})

t.test('should report imported files if postcss-import is used', function (t) {
t.plan(3)

sheetifyPostcss(path.join(__dirname, 'test.css'), '@import "./stubs/dep.css"', { basedir: __dirname, plugins: ['postcss-import'] }, (err, result) => {
t.equal(err, null)
t.equal(result.css, '.dependency {}')
t.deepEqual(result.files, [
path.join(__dirname, 'test.css'),
path.join(__dirname, 'stubs/dep.css')
])
})
})
})
1 change: 1 addition & 0 deletions test/stubs/dep.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.dependency {}

0 comments on commit 37255cb

Please sign in to comment.