Skip to content

Commit

Permalink
New plugin options argument, and other fixes
Browse files Browse the repository at this point in the history
  * Removed deprecated usages of `new Buffer()`
  * Accepts a new third `pluginOptions` parameter with `handleResult`, which
    allows us to handle the results from PostCSS. (For example: handling messages
    from PostCSS plugins.)
  * Declared the supported node version in package.json
  • Loading branch information
ZeeCoder committed Jan 27, 2019
1 parent d1197f8 commit e65e130
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 129 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ npm-debug.log
.DS_Store
.nyc_output/
coverage/
.idea
package-lock.json
yarn.lock
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ npm-debug.log*
pids
test
test.js
.idea
yarn.lock
116 changes: 116 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
## Changelog

* 8.1.0
* Removed deprecated usages of `new Buffer()`
* Accepts a new third `pluginOptions` parameter with `handleResult`, which
allows us to handle the results from PostCSS. (For example: handling messages
from PostCSS plugins.)
* Declared the supported node version in package.json

* 8.0.0
* Bump PostCSS to 7.0
* Drop Node 4 support

* 7.0.1
* Drop dependency on gulp-util

* 7.0.0
* Bump PostCSS to 6.0
* Smaller module size
* Use eslint instead of jshint

* 6.4.0
* Add more details to `PluginError` object

* 6.3.0
* Integrated with postcss-load-config
* Added a callback to configure postcss on per-file-basis
* Dropped node 0.10 support

* 6.2.0
* Fix syntax error message for PostCSS 5.2 compatibility

* 6.1.1
* Fixed the error output

* 6.1.0
* Support for `null` files
* Updated dependencies

* 6.0.1
* Added an example and a test to pass options to PostCSS (e.g. `syntax` option)
* Updated vinyl-sourcemaps-apply to 0.2.0

* 6.0.0
* Updated PostCSS to version 5.0.0

* 5.1.10
* Use autoprefixer in README

* 5.1.9
* Prevent unhandled exception of the following pipes from being suppressed by Promise

* 5.1.8
* Prevent stream’s unhandled exception from being suppressed by Promise

* 5.1.7
* Updated direct dependencies

* 5.1.6
* Updated `CssSyntaxError` check

* 5.1.4
* Simplified error handling
* Simplified postcss execution with object plugins

* 5.1.3 Updated travis banner

* 5.1.2 Transferred repo into postcss org on github

* 5.1.1
* Allow override of `to` option

* 5.1.0 PostCSS Runner Guidelines
* Set `from` and `to` processing options
* Don't output js stack trace for `CssSyntaxError`
* Display `result.warnings()` content

* 5.0.1
* Fix to support object plugins

* 5.0.0
* Use async API

* 4.0.3
* Fixed bug with relative source map

* 4.0.2
* Made PostCSS a simple dependency, because peer dependency is deprecated

* 4.0.1
* Made PostCSS 4.x a peer dependency

* 4.0.0
* Updated PostCSS to 4.0

* 3.0.0
* Updated PostCSS to 3.0 and fixed tests

* 2.0.1
* Added Changelog
* Added example for a custom processor in README

* 2.0.0
* Disable source map by default
* Test source map
* Added Travis support
* Use autoprefixer-core in README

* 1.0.2
* Improved README

* 1.0.1
* Don't add source map comment if used with gulp-sourcemaps

* 1.0.0
* Initial release
110 changes: 2 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,112 +167,6 @@ module.exports = function (ctx) {
})
```

## Changelog
## License

* 8.0.0
* Bump PostCSS to 7.0
* Drop Node 4 support

* 7.0.1
* Drop dependency on gulp-util

* 7.0.0
* Bump PostCSS to 6.0
* Smaller module size
* Use eslint instead of jshint

* 6.4.0
* Add more details to `PluginError` object

* 6.3.0
* Integrated with postcss-load-config
* Added a callback to configure postcss on per-file-basis
* Dropped node 0.10 support

* 6.2.0
* Fix syntax error message for PostCSS 5.2 compatibility

* 6.1.1
* Fixed the error output

* 6.1.0
* Support for `null` files
* Updated dependencies

* 6.0.1
* Added an example and a test to pass options to PostCSS (e.g. `syntax` option)
* Updated vinyl-sourcemaps-apply to 0.2.0

* 6.0.0
* Updated PostCSS to version 5.0.0

* 5.1.10
* Use autoprefixer in README

* 5.1.9
* Prevent unhandled exception of the following pipes from being suppressed by Promise

* 5.1.8
* Prevent stream’s unhandled exception from being suppressed by Promise

* 5.1.7
* Updated direct dependencies

* 5.1.6
* Updated `CssSyntaxError` check

* 5.1.4
* Simplified error handling
* Simplified postcss execution with object plugins

* 5.1.3 Updated travis banner

* 5.1.2 Transferred repo into postcss org on github

* 5.1.1
* Allow override of `to` option

* 5.1.0 PostCSS Runner Guidelines
* Set `from` and `to` processing options
* Don't output js stack trace for `CssSyntaxError`
* Display `result.warnings()` content

* 5.0.1
* Fix to support object plugins

* 5.0.0
* Use async API

* 4.0.3
* Fixed bug with relative source map

* 4.0.2
* Made PostCSS a simple dependency, because peer dependency is deprecated

* 4.0.1
* Made PostCSS 4.x a peer dependency

* 4.0.0
* Updated PostCSS to 4.0

* 3.0.0
* Updated PostCSS to 3.0 and fixed tests

* 2.0.1
* Added Changelog
* Added example for a custom processor in README

* 2.0.0
* Disable source map by default
* Test source map
* Added Travis support
* Use autoprefixer-core in README

* 1.0.2
* Improved README

* 1.0.1
* Don't add source map comment if used with gulp-sourcemaps

* 1.0.0
* Initial release
MIT
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ module.exports = withConfigLoader(function (loadConfig) {
}
return postcss(config.plugins || [])
.process(file.contents, options)
.then(function(result){
var options = config.pluginOptions || {}
if (options.handleResult) {
options.handleResult(result)
}

return result
})
})
.then(handleResult, handleError)

function handleResult (result) {
var map
var warnings = result.warnings().join('\n')

file.contents = new Buffer(result.css)
file.contents = Buffer.from(result.css)

// Apply source map to the chain
if (file.sourceMap) {
Expand Down Expand Up @@ -101,12 +109,13 @@ module.exports = withConfigLoader(function (loadConfig) {


function withConfigLoader(cb) {
return function (plugins, options) {
return function (plugins, postcssOptions, pluginOptions) {
if (Array.isArray(plugins)) {
return cb(function () {
return Promise.resolve({
plugins: plugins,
options: options
options: postcssOptions,
pluginOptions: pluginOptions
})
})
} else if (typeof plugins === 'function') {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
"all": true,
"check-coverage": true
},
"version": "8.0.0",
"version": "8.1.0",
"description": "PostCSS gulp plugin",
"main": "index.js",
"engines": {
"node": ">=6"
},
"scripts": {
"coveralls": "coveralls < coverage/lcov.info",
"pretest": "eslint *.js",
Expand Down
Loading

0 comments on commit e65e130

Please sign in to comment.